@pithy-sh/core 0.9.0 → 0.10.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 (162) hide show
  1. package/dist/asyncapi/document.d.ts +46 -0
  2. package/dist/asyncapi/document.d.ts.map +1 -0
  3. package/dist/asyncapi/document.js +115 -0
  4. package/dist/capability/capability.d.ts +7 -0
  5. package/dist/capability/capability.d.ts.map +1 -1
  6. package/dist/capability/composition.d.ts.map +1 -1
  7. package/dist/capability/composition.js +5 -1
  8. package/dist/capability/settings.d.ts +10 -2
  9. package/dist/capability/settings.d.ts.map +1 -1
  10. package/dist/capability/settings.js +5 -3
  11. package/dist/cli/command.d.ts +364 -0
  12. package/dist/cli/command.d.ts.map +1 -0
  13. package/dist/cli/command.js +418 -0
  14. package/dist/cli/commandCatalog.generated.d.ts +2275 -0
  15. package/dist/cli/commandCatalog.generated.d.ts.map +1 -0
  16. package/dist/cli/commandCatalog.generated.js +2390 -0
  17. package/dist/cli/commandFacts.d.ts +164 -0
  18. package/dist/cli/commandFacts.d.ts.map +1 -0
  19. package/dist/cli/commandFacts.js +215 -0
  20. package/dist/controlPlane/error/errors.d.ts.map +1 -1
  21. package/dist/controlPlane/error/errors.js +4 -3
  22. package/dist/controlPlane/http/guard.d.ts.map +1 -1
  23. package/dist/controlPlane/http/guard.js +11 -1
  24. package/dist/controlPlane/http/routes.d.ts +1 -1
  25. package/dist/controlPlane/http/routes.d.ts.map +1 -1
  26. package/dist/controlPlane/http/routes.js +34 -7
  27. package/dist/createBackend.d.ts +7 -0
  28. package/dist/createBackend.d.ts.map +1 -1
  29. package/dist/createBackend.js +34 -4
  30. package/dist/entitlement/require.js +1 -1
  31. package/dist/error/cause.d.ts +16 -116
  32. package/dist/error/cause.d.ts.map +1 -1
  33. package/dist/error/cause.js +19 -153
  34. package/dist/error/http.d.ts +40 -0
  35. package/dist/error/http.d.ts.map +1 -1
  36. package/dist/error/payload.d.ts +80 -0
  37. package/dist/error/payload.d.ts.map +1 -1
  38. package/dist/error/payload.js +26 -0
  39. package/dist/error/pithyError.d.ts +44 -0
  40. package/dist/error/pithyError.d.ts.map +1 -1
  41. package/dist/error/pithyError.js +56 -1
  42. package/dist/error/unresolved.d.ts +265 -0
  43. package/dist/error/unresolved.d.ts.map +1 -0
  44. package/dist/error/unresolved.js +599 -0
  45. package/dist/error/wire.d.ts +20 -0
  46. package/dist/error/wire.d.ts.map +1 -0
  47. package/dist/error/wire.js +19 -0
  48. package/dist/http/oidcWebhook.d.ts +3 -3
  49. package/dist/http/oidcWebhook.js +3 -3
  50. package/dist/http/routeContract.js +1 -1
  51. package/dist/http/routeSpec.d.ts +66 -0
  52. package/dist/http/routeSpec.d.ts.map +1 -0
  53. package/dist/http/routeSpec.js +40 -0
  54. package/dist/http/sameOrigin.d.ts +1 -1
  55. package/dist/http/sameOrigin.js +1 -1
  56. package/dist/http/signedWebhook.d.ts +3 -3
  57. package/dist/http/signedWebhook.js +3 -3
  58. package/dist/http/socket.d.ts +52 -0
  59. package/dist/http/socket.d.ts.map +1 -0
  60. package/dist/http/socket.js +2 -0
  61. package/dist/http/subprotocol.d.ts +29 -0
  62. package/dist/http/subprotocol.d.ts.map +1 -0
  63. package/dist/http/subprotocol.js +37 -0
  64. package/dist/http/validation.d.ts +40 -8
  65. package/dist/http/validation.d.ts.map +1 -1
  66. package/dist/http/validation.js +25 -1
  67. package/dist/index.js +2 -2
  68. package/dist/logger/record.d.ts +23 -0
  69. package/dist/logger/record.d.ts.map +1 -1
  70. package/dist/migrations/bookkeeping.d.ts +21 -0
  71. package/dist/migrations/bookkeeping.d.ts.map +1 -1
  72. package/dist/migrations/bookkeeping.js +32 -3
  73. package/dist/migrations/groups.d.ts +140 -0
  74. package/dist/migrations/groups.d.ts.map +1 -0
  75. package/dist/migrations/groups.js +191 -0
  76. package/dist/migrations/migrateStep.d.ts +13 -0
  77. package/dist/migrations/migrateStep.d.ts.map +1 -0
  78. package/dist/migrations/migrateStep.js +20 -0
  79. package/dist/migrations/owner.d.ts +7 -0
  80. package/dist/migrations/owner.d.ts.map +1 -1
  81. package/dist/migrations/owner.js +11 -7
  82. package/dist/migrations/retained.js +2 -2
  83. package/dist/migrations/runner.d.ts +76 -5
  84. package/dist/migrations/runner.d.ts.map +1 -1
  85. package/dist/migrations/runner.js +130 -19
  86. package/dist/naming/domains.d.ts +17 -0
  87. package/dist/naming/domains.d.ts.map +1 -1
  88. package/dist/naming/domains.js +62 -4
  89. package/dist/naming/environment.d.ts.map +1 -1
  90. package/dist/naming/environment.js +2 -1
  91. package/dist/naming/packageName.d.ts +17 -0
  92. package/dist/naming/packageName.d.ts.map +1 -0
  93. package/dist/naming/packageName.js +22 -0
  94. package/dist/naming/provisionScope.d.ts.map +1 -1
  95. package/dist/naming/provisionScope.js +2 -1
  96. package/dist/openapi/document.d.ts +106 -0
  97. package/dist/openapi/document.d.ts.map +1 -0
  98. package/dist/openapi/document.js +314 -0
  99. package/dist/openapi/routeGroups.d.ts +8 -0
  100. package/dist/openapi/routeGroups.d.ts.map +1 -0
  101. package/dist/openapi/routeGroups.js +23 -0
  102. package/dist/text/comments.js +66 -4
  103. package/dist/text/literals.d.ts +43 -0
  104. package/dist/text/literals.d.ts.map +1 -0
  105. package/dist/text/literals.js +293 -0
  106. package/dist/version.generated.d.ts +1 -1
  107. package/dist/version.generated.d.ts.map +1 -1
  108. package/dist/version.generated.js +1 -1
  109. package/dist/workflow/dispatchRoute.d.ts.map +1 -1
  110. package/dist/workflow/dispatchRoute.js +12 -6
  111. package/dist/workflow/faults.d.ts.map +1 -1
  112. package/dist/workflow/faults.js +2 -3
  113. package/dist/workflow/hostEnv.d.ts +1 -0
  114. package/dist/workflow/hostEnv.d.ts.map +1 -1
  115. package/dist/workflow/hostEnv.js +4 -2
  116. package/dist/workflow/loopback.d.ts.map +1 -1
  117. package/dist/workflow/loopback.js +2 -1
  118. package/package.json +3 -3
  119. package/src/asyncapi/document.ts +164 -0
  120. package/src/capability/capability.ts +7 -0
  121. package/src/capability/composition.ts +2 -1
  122. package/src/capability/settings.ts +19 -2
  123. package/src/cli/command.ts +865 -0
  124. package/src/cli/commandCatalog.generated.ts +2533 -0
  125. package/src/cli/commandFacts.ts +219 -0
  126. package/src/controlPlane/error/errors.ts +10 -3
  127. package/src/controlPlane/http/guard.ts +14 -2
  128. package/src/controlPlane/http/routes.ts +57 -9
  129. package/src/createBackend.ts +35 -2
  130. package/src/entitlement/require.ts +1 -1
  131. package/src/error/cause.ts +18 -181
  132. package/src/error/payload.ts +59 -0
  133. package/src/error/pithyError.ts +76 -0
  134. package/src/error/unresolved.ts +853 -0
  135. package/src/error/wire.ts +40 -0
  136. package/src/http/oidcWebhook.ts +3 -3
  137. package/src/http/routeContract.ts +1 -1
  138. package/src/http/routeSpec.ts +81 -0
  139. package/src/http/sameOrigin.ts +1 -1
  140. package/src/http/signedWebhook.ts +3 -3
  141. package/src/http/socket.ts +55 -0
  142. package/src/http/subprotocol.ts +47 -0
  143. package/src/http/validation.ts +50 -8
  144. package/src/migrations/bookkeeping.ts +39 -2
  145. package/src/migrations/groups.ts +295 -0
  146. package/src/migrations/migrateStep.ts +19 -0
  147. package/src/migrations/owner.ts +10 -6
  148. package/src/migrations/retained.ts +2 -2
  149. package/src/migrations/runner.ts +214 -22
  150. package/src/naming/domains.ts +75 -16
  151. package/src/naming/environment.ts +2 -1
  152. package/src/naming/packageName.ts +20 -0
  153. package/src/naming/provisionScope.ts +2 -1
  154. package/src/openapi/document.ts +412 -0
  155. package/src/openapi/routeGroups.ts +25 -0
  156. package/src/text/comments.ts +56 -4
  157. package/src/text/literals.ts +294 -0
  158. package/src/version.generated.ts +1 -1
  159. package/src/workflow/dispatchRoute.ts +13 -6
  160. package/src/workflow/faults.ts +5 -3
  161. package/src/workflow/hostEnv.ts +9 -1
  162. package/src/workflow/loopback.ts +2 -1
@@ -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;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,gGAAgG;AAChG,eAAO,MAAM,oBAAoB;;;;iBAUkE,CAAC;AACpG,MAAM,MAAM,oBAAoB,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAWzE,0FAA0F;AAC1F,MAAM,WAAW,cAAc;IAC7B,gEAAgE;IAChE,KAAK,EAAE,MAAM,CAAC;IACd;;;OAGG;IACH,SAAS,EAAE,IAAI,CAAC;IAChB,0FAA0F;IAC1F,UAAU,EAAE,MAAM,EAAE,CAAC;CACtB;AAED;;;;;;;GAOG;AACH,MAAM,MAAM,aAAa,GACrB;IAAE,KAAK,EAAE,QAAQ,CAAA;CAAE,GACnB;IACE,mEAAmE;IACnE,KAAK,EAAE,KAAK,CAAC;IACb,+DAA+D;IAC/D,UAAU,EAAE,MAAM,EAAE,CAAC;CACtB,GACD;IACE,wDAAwD;IACxD,KAAK,EAAE,QAAQ,CAAC;IAChB;;;OAGG;IACH,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB;;;;OAIG;IACH,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB;;;;OAIG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;CACd,CAAC;AAEN,sFAAsF;AACtF,MAAM,WAAW,kBAAkB;IACjC,gEAAgE;IAChE,KAAK,EAAE,MAAM,CAAC;IACd,iFAAiF;IACjF,UAAU,EAAE,SAAS,MAAM,EAAE,CAAC;IAC9B,wGAAwG;IACxG,EAAE,CAAC,EAAE,IAAI,CAAC;CACX;AAED;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,CAAC,GAAG,GAAE,IAAiB,GAAG,MAAM,CAEtE;AA2BD;;;;GAIG;AACH,wBAAsB,oBAAoB,CAAC,QAAQ,EAAE,UAAU,EAAE,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC,CAsB3G;AAED;;;;GAIG;AACH,wBAAsB,mBAAmB,CAAC,QAAQ,EAAE,UAAU,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC,CAqBzF;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAsB,iBAAiB,CAAC,QAAQ,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC,CAwBnG;AAwBD;;;;GAIG;AACH,wBAAsB,qBAAqB,CAAC,QAAQ,EAAE,UAAU,EAAE,UAAU,EAAE,SAAS,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAQ9G"}
@@ -0,0 +1,191 @@
1
+ // SPDX-FileCopyrightText: 2026 Pithy
2
+ // SPDX-License-Identifier: MIT
3
+ import { SQLiteDate } from "../data/codecs.js";
4
+ import { chunkByBoundParameters, chunkRowsByBoundParameters } from "../data/boundParameters.js";
5
+ import { MIGRATION_GROUP_TABLE, appliedMigrationChain, migrationKysely } from "./bookkeeping.js";
6
+ import { z } from "zod";
7
+ import { sql } from "kysely";
8
+ //#region src/migrations/groups.ts
9
+ /**
10
+ * **Which run applied each migration — the group a rollback names (#694).**
11
+ *
12
+ * `pithy migrate --rollback` used to step back one migration in every database the environment binds, and
13
+ * nothing recorded what a single run had applied. So reversing a deploy that moved three migrations was
14
+ * three invocations and the count came from outside the tool — a human's memory, or a CI log read under
15
+ * pressure. Every run belongs to a group now: the caller's own `--group <value>`, or a generated ISO-8601
16
+ * timestamp, recorded here against every migration the run applies, in every database it touches.
17
+ *
18
+ * **It cannot live in the ledger.** `pithy_migrations` is Kysely's own table, renamed off its default
19
+ * (`./bookkeeping`); Kysely creates it and its insert sets `name` and `timestamp` only. So the group sits
20
+ * in a table *beside* it, written by the runner from the `MigrationResult[]` Kysely hands back — the same
21
+ * placement, and the same reasoning, as `pithy_migrations_owner`: it is not a migration, so no capability
22
+ * ships it, `--rollback` cannot step it back, and `pithy seed --redo`'s full reset cannot wipe it. What a
23
+ * reversal removes is the reversed migrations' own rows, which is bookkeeping catching up with the ledger.
24
+ *
25
+ * **The rows say which run; the ledger says which order.** Every applied migration is recorded here as it
26
+ * applies and forgotten as it is reversed, so these rows are the membership. Where a group *sits* is a
27
+ * question about the ledger, though, because the ledger is what Kysely steps down from — so {@link
28
+ * readGroupPosition} reads both (`appliedMigrationChain`) and compares the group against the chain's tail.
29
+ * Reading the group table alone would answer from the order this table happened to be written in, and the
30
+ * two differ in exactly the cases that matter: a migration applied with no group row at all.
31
+ *
32
+ * **What it cannot see, it names.** A migration applied before this table existed carries no row, and so
33
+ * does one a `seed --redo` reset reapplied or one whose group write failed. Such a migration over a group
34
+ * buries it — reversing the group would reverse a migration nobody recorded — and the position says so by
35
+ * name rather than calling the group reversible. Reading is cheap and additive: one group row per applied
36
+ * migration, and the table is created on the first run that applies anything.
37
+ */
38
+ /** One applied migration and the run that applied it. The three columns are the whole table. */
39
+ const MigrationGroupRecord = z.object({
40
+ groupKey: z.string().describe("The group this migration was applied under — the caller's `--group` value, or the generated ISO-8601 timestamp of the run. Not `group`: that is SQL's own word, and an operator reading this table by hand should not have to quote a column."),
41
+ migration: z.string().describe("The composed migration name, exactly as the ledger records it."),
42
+ appliedAt: SQLiteDate.describe("When this migration was applied — the moment the run recorded it.")
43
+ }).describe("One applied migration's membership of a migration group, recorded beside the ledger.");
44
+ /**
45
+ * The group a run with no `--group` belongs to: an **ISO-8601 timestamp**, `2026-10-03T19:52:47.611Z`.
46
+ *
47
+ * A timestamp rather than a date, because one run is one group. Date-only would silently merge two
48
+ * unrelated runs on a busy day into one group, and reversing it would then undo more than the caller did.
49
+ * The precision costs nothing, it sorts lexicographically into chronological order, and it tells an
50
+ * operator *when* without their having named anything.
51
+ */
52
+ function generatedMigrationGroup(now = /* @__PURE__ */ new Date()) {
53
+ return now.toISOString();
54
+ }
55
+ /** Whether the group table has been created yet — a plain `sqlite_master` select, which D1 permits. */
56
+ async function groupTableExists(db) {
57
+ const { rows } = await sql`select name from sqlite_master where type = 'table' and name = ${MIGRATION_GROUP_TABLE}`.execute(db);
58
+ return rows.length > 0;
59
+ }
60
+ /** Every row, in the order it was written — which is the order the migrations applied. */
61
+ async function groupRows(db) {
62
+ if (!await groupTableExists(db)) return [];
63
+ return (await db.selectFrom("pithy_migrations_groups").select([
64
+ "groupKey",
65
+ "migration",
66
+ "appliedAt"
67
+ ]).orderBy("id").execute()).map((row) => MigrationGroupRecord.parse(row));
68
+ }
69
+ /**
70
+ * How many parameters one group row binds — derived from the schema, so a fourth column re-derives the
71
+ * chunk size instead of silently taking the insert back over D1's cap.
72
+ */
73
+ const GROUP_ROW_COLUMNS = Object.keys(MigrationGroupRecord.shape).length;
74
+ /**
75
+ * Record a group against the migrations a run just applied, creating the table on demand. Idempotent in
76
+ * the only sense that matters: a migration applies once, so a name arrives here once — and a second call
77
+ * under the same group **extends** it, which is the retry case a release whose migrate half-failed needs.
78
+ */
79
+ async function recordMigrationGroup(database, options) {
80
+ if (options.migrations.length === 0) return;
81
+ const db = migrationKysely(database);
82
+ await db.schema.createTable(MIGRATION_GROUP_TABLE).ifNotExists().addColumn("id", "integer", (column) => column.primaryKey().autoIncrement()).addColumn("groupKey", "text", (column) => column.notNull()).addColumn("migration", "text", (column) => column.notNull()).addColumn("appliedAt", "integer", (column) => column.notNull()).execute();
83
+ const appliedAt = options.at ?? /* @__PURE__ */ new Date();
84
+ const rows = options.migrations.map((migration) => MigrationGroupRecord.encode({
85
+ groupKey: options.group,
86
+ migration,
87
+ appliedAt
88
+ }));
89
+ for (const chunk of chunkRowsByBoundParameters(rows, GROUP_ROW_COLUMNS)) await db.insertInto("pithy_migrations_groups").values(chunk).execute();
90
+ }
91
+ /**
92
+ * Every group this database records, oldest first by when each last applied something — and so the last
93
+ * entry is the newest group, which is what a rollback with no `--group` names. Empty for a database
94
+ * nothing has grouped, and reading creates nothing.
95
+ */
96
+ async function readMigrationGroups(database) {
97
+ const rows = await groupRows(migrationKysely(database));
98
+ const byGroup = /* @__PURE__ */ new Map();
99
+ for (const [index, row] of rows.entries()) {
100
+ const existing = byGroup.get(row.groupKey);
101
+ if (existing) {
102
+ existing.migrations.push(row.migration);
103
+ existing.appliedAt = row.appliedAt > existing.appliedAt ? row.appliedAt : existing.appliedAt;
104
+ existing.order = index;
105
+ continue;
106
+ }
107
+ byGroup.set(row.groupKey, {
108
+ group: row.groupKey,
109
+ appliedAt: row.appliedAt,
110
+ migrations: [row.migration],
111
+ order: index
112
+ });
113
+ }
114
+ return [...byGroup.values()].sort((left, right) => left.order - right.order).map(({ group, appliedAt, migrations }) => ({
115
+ group,
116
+ appliedAt,
117
+ migrations
118
+ }));
119
+ }
120
+ /**
121
+ * Where `group` sits in this database's chain — see {@link GroupPosition}.
122
+ *
123
+ * The test is *is this group the tail of the **ledger***, not *is it the newest by timestamp*: a group
124
+ * extended after another run has the later timestamp and still has that run's migration inside it, so
125
+ * reversing it would reverse the other group's work. Hence the two halves of one rule — nothing applied
126
+ * over the group's newest migration, and nothing applied inside it between two of its own.
127
+ *
128
+ * **Against the ledger, because the ledger is what comes down.** `migrateDown()` steps the ledger's tip,
129
+ * so a group whose rows are the tail of the *group table* is still buried when an ungrouped migration sits
130
+ * over it in the ledger — and that state is reachable from the ordinary dev loop, where `seed --redo`'s
131
+ * reset reapplies a pending migration under no group at all. Asked of the group table alone, this returned
132
+ * `top`, the `down` reversed a migration nobody asked about, and the refusal arrived after the damage.
133
+ */
134
+ async function readGroupPosition(database, group) {
135
+ const db = migrationKysely(database);
136
+ const groupOf = new Map((await groupRows(db)).map((row) => [row.migration, row.groupKey]));
137
+ const chain = await appliedMigrationChain(db);
138
+ const held = (name) => groupOf.get(name) === group;
139
+ const first = chain.findIndex(held);
140
+ if (first === -1) return { state: "absent" };
141
+ const last = chain.length - 1 - [...chain].reverse().findIndex(held);
142
+ const span = chain.slice(first, last + 1);
143
+ const over = chain.slice(last + 1);
144
+ const inside = span.filter((name) => !held(name));
145
+ if (over.length === 0 && inside.length === 0) return {
146
+ state: "top",
147
+ migrations: span.filter(held).reverse()
148
+ };
149
+ const blocking = [...[...over].reverse(), ...[...inside].reverse()];
150
+ const above = [...new Set(blocking.map((name) => groupOf.get(name)).filter(isGroupKey))];
151
+ const ungrouped = blocking.filter((name) => !groupOf.has(name));
152
+ const top = contiguousTipGroup(chain, groupOf);
153
+ return {
154
+ state: "buried",
155
+ above,
156
+ ungrouped,
157
+ ...top === void 0 ? {} : { top }
158
+ };
159
+ }
160
+ /** A `groupOf` lookup that found a group, for narrowing the `above` list. */
161
+ function isGroupKey(key) {
162
+ return key !== void 0;
163
+ }
164
+ /**
165
+ * The group whose own migrations are the contiguous tip of `chain`, if any.
166
+ *
167
+ * What it is for is the refusals: *reverse the group on top first* is only advice if such a group exists,
168
+ * and after a group was extended over another one none does — each is inside the other, so naming either
169
+ * prints a command that refuses in its turn and the operator is sent in a circle (#694). The candidate can
170
+ * only be the group holding the tip migration, so there is one to test, not a search.
171
+ */
172
+ function contiguousTipGroup(chain, groupOf) {
173
+ const tip = chain.at(-1);
174
+ const candidate = tip === void 0 ? void 0 : groupOf.get(tip);
175
+ if (candidate === void 0) return void 0;
176
+ const held = chain.filter((name) => groupOf.get(name) === candidate).length;
177
+ return chain.slice(chain.length - held).every((name) => groupOf.get(name) === candidate) ? candidate : void 0;
178
+ }
179
+ /**
180
+ * Forget the group rows of migrations that are no longer applied — what a reversal writes once the `down`
181
+ * has run. By migration name alone, because the ledger's name is unique: one applied migration, one row.
182
+ * A database with no group table has nothing to forget.
183
+ */
184
+ async function forgetMigrationGroups(database, migrations) {
185
+ if (migrations.length === 0) return;
186
+ const db = migrationKysely(database);
187
+ if (!await groupTableExists(db)) return;
188
+ for (const chunk of chunkByBoundParameters(migrations, 0)) await db.deleteFrom("pithy_migrations_groups").where("migration", "in", chunk).execute();
189
+ }
190
+ //#endregion
191
+ export { MigrationGroupRecord, forgetMigrationGroups, generatedMigrationGroup, readGroupPosition, readMigrationGroups, recordMigrationGroup };
@@ -0,0 +1,13 @@
1
+ // SPDX-FileCopyrightText: 2026 Pithy
2
+ // SPDX-License-Identifier: MIT
3
+ import { type AmbientEnv } from "../env/ambient";
4
+ /**
5
+ * **The step that migrates the environment a Worker runs in**, as a sentence ends with it: `then ${step}.`
6
+ *
7
+ * `pithy migrate` defaults to `dev`, so a line that names it bare sends a staging Worker's operator to migrate
8
+ * their laptop (#711). A Worker knows its environment when the composition stamped one (`ENVIRONMENT`), and then
9
+ * the command names it; when it does not, the line says which flag to name rather than naming a command that
10
+ * would act on the wrong database.
11
+ */
12
+ export declare function migrateStep(env: AmbientEnv): string;
13
+ //# sourceMappingURL=migrateStep.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migrateStep.d.ts","sourceRoot":"","sources":["../../src/migrations/migrateStep.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,UAAU,EAA0B,MAAM,gBAAgB,CAAC;AAEzE;;;;;;;GAOG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,UAAU,GAAG,MAAM,CAInD"}
@@ -0,0 +1,20 @@
1
+ // SPDX-FileCopyrightText: 2026 Pithy
2
+ // SPDX-License-Identifier: MIT
3
+ import { commandName, pithyCommand } from "../cli/command.js";
4
+ import { compositionEnvironment } from "../env/ambient.js";
5
+ //#region src/migrations/migrateStep.ts
6
+ /**
7
+ * **The step that migrates the environment a Worker runs in**, as a sentence ends with it: `then ${step}.`
8
+ *
9
+ * `pithy migrate` defaults to `dev`, so a line that names it bare sends a staging Worker's operator to migrate
10
+ * their laptop (#711). A Worker knows its environment when the composition stamped one (`ENVIRONMENT`), and then
11
+ * the command names it; when it does not, the line says which flag to name rather than naming a command that
12
+ * would act on the wrong database.
13
+ */
14
+ function migrateStep(env) {
15
+ const environment = compositionEnvironment(env);
16
+ if (environment === void 0) return `migrate this environment with ${commandName("migrate")}, naming it with --env`;
17
+ return `run ${pithyCommand("migrate", { flags: { "--env": environment } })}`;
18
+ }
19
+ //#endregion
20
+ export { migrateStep };
@@ -2,6 +2,7 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
  import type { D1Database } from "@cloudflare/workers-types";
4
4
  import { z } from "zod";
5
+ import { ConflictError } from "../error/pithyError";
5
6
  /** The recorded owner of a database: who stamped it, and when. */
6
7
  export declare const MigrationOwner: z.ZodObject<{
7
8
  project: z.ZodString;
@@ -26,6 +27,12 @@ export interface ClaimOwnershipOptions {
26
27
  /** The binding this database is reached by (`DB`), so a refusal names it. Optional. */
27
28
  binding?: string;
28
29
  }
30
+ /**
31
+ * The refusal for a database another project owns: both project names in the problem line, both remedies in the
32
+ * action line. Exported so a reader that only checks the claim — `pithy migrate --dry-run`, which stamps nothing —
33
+ * refuses in the words the claim refuses with, rather than a copy of them (#697).
34
+ */
35
+ export declare function foreignOwnerRefusal(owner: string, project: string, binding: string | undefined): ConflictError;
29
36
  /**
30
37
  * The project recorded as this database's owner, or `undefined` when none is — read-only, creating
31
38
  * nothing. `pithy doctor` and any other reporter reads the stamp through this; only
@@ -1 +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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;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;AAqBD;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,SAAS,GAAG,aAAa,CAM9G;AAED;;;;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"}
@@ -42,11 +42,15 @@ async function currentOwner(db) {
42
42
  const row = await db.selectFrom("pithy_migrations_owner").select(["project", "stampedAt"]).where("id", "=", OWNER_ROW_ID).executeTakeFirst();
43
43
  return row ? MigrationOwner.parse(row) : void 0;
44
44
  }
45
- /** The refusal: both project names in the problem line, both remedies in the action line. */
46
- function foreignDatabase(owner, project, binding) {
45
+ /**
46
+ * The refusal for a database another project owns: both project names in the problem line, both remedies in the
47
+ * action line. Exported so a reader that only checks the claim — `pithy migrate --dry-run`, which stamps nothing —
48
+ * refuses in the words the claim refuses with, rather than a copy of them (#697).
49
+ */
50
+ function foreignOwnerRefusal(owner, project, binding) {
47
51
  return new ConflictError({
48
52
  message: `${binding ?? "This database"} belongs to project "${owner}", not "${project}".`,
49
- action: `Bind ${project} to its own database, or set the project name back to ${owner}. Run pithy migrate again.`,
53
+ action: `Bind ${project} to its own database, or set the project name back to ${owner}. Then run this again.`,
50
54
  detail: `Recorded owner "${owner}" in ${MIGRATION_OWNER_TABLE}.`
51
55
  });
52
56
  }
@@ -74,7 +78,7 @@ async function claimMigrationOwnership(database, options) {
74
78
  const db = migrationKysely(database);
75
79
  const existing = await currentOwner(db);
76
80
  if (existing) {
77
- if (existing.project !== project) throw foreignDatabase(existing.project, project, options.binding);
81
+ if (existing.project !== project) throw foreignOwnerRefusal(existing.project, project, options.binding);
78
82
  return {
79
83
  project,
80
84
  outcome: "confirmed",
@@ -93,10 +97,10 @@ async function claimMigrationOwnership(database, options) {
93
97
  const settled = await currentOwner(db);
94
98
  if (!settled) throw new ConflictError({
95
99
  message: `${options.binding ?? "This database"} could not be stamped as "${project}".`,
96
- action: "Check the database is writable. Run pithy migrate again.",
100
+ action: "Check the database is writable, then run this again.",
97
101
  detail: `No row in ${MIGRATION_OWNER_TABLE} after the claim insert.`
98
102
  });
99
- if (settled.project !== project) throw foreignDatabase(settled.project, project, options.binding);
103
+ if (settled.project !== project) throw foreignOwnerRefusal(settled.project, project, options.binding);
100
104
  return {
101
105
  project,
102
106
  outcome: "adopted",
@@ -104,4 +108,4 @@ async function claimMigrationOwnership(database, options) {
104
108
  };
105
109
  }
106
110
  //#endregion
107
- export { MigrationOwner, claimMigrationOwnership, readMigrationOwner };
111
+ export { MigrationOwner, claimMigrationOwnership, foreignOwnerRefusal, readMigrationOwner };
@@ -9,8 +9,8 @@ import { CamelCasePlugin } from "kysely";
9
9
  *
10
10
  * A migration's `down` is the tested inverse of its `up`, and for schema that is exactly right. For a
11
11
  * vault it is a `drop table` on the only copy of a credential Google issued. `0100_secrets_0001_init` is
12
- * the whole history of the secrets database, so one `pithy migrate --rollback` — which steps back one
13
- * migration in every composed database — emptied it in place, on staging, with nothing said first.
12
+ * the whole history of the secrets database, so one `pithy migrate --rollback` — which then stepped back
13
+ * one migration in every composed database — emptied it in place, on staging, with nothing said first.
14
14
  *
15
15
  * So a capability **declares** a table retained, beside the migrations that create it
16
16
  * (`DatabaseSpec.retained`), and the declaration is recorded on those migrations' own `down` functions
@@ -30,8 +30,30 @@ export interface RetainedConsent {
30
30
  */
31
31
  budget?: RetainedBudget;
32
32
  }
33
- /** Run every pending migration to latest. An empty provider resolves to `[]`. */
34
- export declare function runMigrations(database: D1Database, provider: MigrationProvider, target?: MigrationTarget): Promise<MigrationResult[]>;
33
+ /**
34
+ * What a forward run records about itself (#694) — see `./groups`.
35
+ *
36
+ * Optional, and absent still records: a run with no group named is a group of its own, stamped with the
37
+ * moment it ran. There is always a group, so a rollback never has to fall back to counting migrations.
38
+ */
39
+ export interface RunGroupOptions {
40
+ /**
41
+ * The group every migration this run applies is recorded under. Absent, a generated ISO-8601 timestamp
42
+ * is used — per run, by construction. A caller spanning several databases passes **one** value to all
43
+ * of them, so one run is one group however many databases it touches.
44
+ */
45
+ group?: string;
46
+ }
47
+ /**
48
+ * Run every pending migration to latest, recording the run's group against each one. An empty provider
49
+ * resolves to `[]` and records nothing.
50
+ *
51
+ * **The group is written from what Kysely hands back, and before the failure is raised.** A run that
52
+ * half-applies is retried with the key it already has, so the migrations that stuck have to be in the
53
+ * group — otherwise the retry's group would sit on top of an ungrouped migration, and reversing the
54
+ * retry would leave half a release applied with nothing recording it.
55
+ */
56
+ export declare function runMigrations(database: D1Database, provider: MigrationProvider, target?: MigrationTarget, options?: RunGroupOptions): Promise<MigrationResult[]>;
35
57
  /** One database's ledger beside the declaration it is supposed to match — see {@link readMigrationLedger}. */
36
58
  export interface MigrationLedger {
37
59
  /** Declared and not yet applied, in the order they would run. */
@@ -61,11 +83,50 @@ export interface MigrationLedger {
61
83
  */
62
84
  export declare function readMigrationLedger(database: D1Database, provider: MigrationProvider): Promise<MigrationLedger>;
63
85
  /**
64
- * Step this database's latest applied migration back — one step, per database. `pithy migrate --rollback`
65
- * calls it once for **every** database in its fan-out. Refused while a retained table here holds rows the
66
- * caller has not counted in `consent` (#588).
86
+ * Step this database's latest applied migration back — **one** step, in **one** database.
87
+ *
88
+ * It is no longer what `pithy migrate --rollback` runs: a rollback names a group and reverses that
89
+ * group's portion of each database ({@link reverseMigrationGroup}, #694). What this is, is the single
90
+ * step underneath — the primitive every capability's "its `down` is the inverse of its `up`" suite
91
+ * reverses one migration with, and the honest answer for a caller holding one migration rather than a
92
+ * release.
93
+ *
94
+ * It forgets the reversed migration's group row, so the group bookkeeping follows the ledger whichever
95
+ * way a migration came down. Refused while a retained table here holds rows the caller has not counted in
96
+ * `consent` (#588).
67
97
  */
68
98
  export declare function rollbackMigration(database: D1Database, provider: MigrationProvider, target?: MigrationTarget, consent?: RetainedConsent): Promise<MigrationResult[]>;
99
+ /** What one database reverses of a group: the group, and its migrations newest first. */
100
+ export interface MigrationGroupStep {
101
+ /** The group being reversed — what the caller passed to `--group`. */
102
+ group: string;
103
+ /**
104
+ * This database's portion of it, in the order it comes down: newest first. The caller reads it from
105
+ * `readGroupPosition`, which is also what proves the group is the top of this database's chain. It says
106
+ * **whether** there is anything to reverse here; what comes down is read from the ledger again below, so
107
+ * a step that named a migration from the group underneath could not reverse it on the caller's word.
108
+ */
109
+ migrations: readonly string[];
110
+ }
111
+ /**
112
+ * **Reverse one group's portion of one database — the operation behind `pithy migrate --rollback
113
+ * --group` (#694).**
114
+ *
115
+ * Kysely steps down from the tip, so this is `migrateDown()` once per migration in the group, in reverse
116
+ * chain order, and **nothing outside it**. Both halves of that are read from the ledger here, not taken on
117
+ * the caller's word: the group has to be the ledger's own tail before the first `down`, and what each step
118
+ * brings down has to be one of the migrations that read said the group holds — anything else is an
119
+ * internal fault and throws rather than carrying on. **And a migration with no `down` stops the group**:
120
+ * Kysely reports one as `NotExecuted` and leaves it applied, so counting it as reversed is how a group
121
+ * reported itself fully rolled back with half of it still in the database. The caller's pre-flight is what
122
+ * makes a group reverse completely or not at all across databases; this is the floor under it.
123
+ *
124
+ * **One migrator for the whole group**, so the retained guard clears once and the caller's budget is spent
125
+ * once across every `down` it covers (#588). Each migration's group row is forgotten as it comes down —
126
+ * before the step's failure is raised — so a group reversal that dies partway can be re-run under the
127
+ * same group and reverses what is left.
128
+ */
129
+ export declare function reverseMigrationGroup(database: D1Database, provider: MigrationProvider, step: MigrationGroupStep, target?: MigrationTarget, consent?: RetainedConsent): Promise<MigrationResult[]>;
69
130
  /**
70
131
  * Fully reset one database's schema: every applied migration's `down` runs, in one pass, in reverse
71
132
  * chronological order — Kysely's `NO_MIGRATIONS` target, not just the latest — then every migration's
@@ -74,6 +135,16 @@ export declare function rollbackMigration(database: D1Database, provider: Migrat
74
135
  * skip-if-exists) simply work afterward — there is no per-row identity problem to solve. An empty
75
136
  * ledger rolls back nothing; an empty provider reapplies nothing. Refused, before the first `down`, while a
76
137
  * retained table here holds rows the caller has not counted in `consent` (#588).
138
+ *
139
+ * **It leaves the group bookkeeping exactly as it was (#694).** The table is not a migration, so the `down`
140
+ * pass cannot remove it, and rewriting the rows would restamp somebody's release as having happened during
141
+ * a `seed --redo`. Every group row still describes a migration this reset reapplied.
142
+ *
143
+ * **What it does not do is record a group for the rest.** A reset reapplies everything *declared*, which
144
+ * includes migrations that were pending when it started, and those come back applied under no group — this
145
+ * takes no group and invents none. Such a migration sits over the groups below it, so a `--rollback
146
+ * --group` of one of them is refused by name (`./groups`, `readGroupPosition`) rather than reversing a
147
+ * migration nobody recorded.
77
148
  */
78
149
  export declare function resetMigrations(database: D1Database, provider: MigrationProvider, target?: MigrationTarget, consent?: RetainedConsent): Promise<MigrationResult[]>;
79
150
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"runner.d.ts","sourceRoot":"","sources":["../../src/migrations/runner.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAE5D,OAAO,EAAE,KAAK,iBAAiB,EAAE,KAAK,eAAe,EAA2B,MAAM,kBAAkB,CAAC;AAKzG,OAAO,EAAgC,cAAc,EAAE,MAAM,YAAY,CAAC;AA4D1E;;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