@prisma-next/migration-tools 0.0.1 → 0.3.0-dev.100
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.
- package/LICENSE +201 -0
- package/dist/{errors-DdSjGRqx.mjs → errors-CqLiJwqA.mjs} +47 -9
- package/dist/errors-CqLiJwqA.mjs.map +1 -0
- package/dist/exports/attestation.d.mts +1 -1
- package/dist/exports/attestation.d.mts.map +1 -1
- package/dist/exports/attestation.mjs +1 -1
- package/dist/exports/dag.d.mts +36 -17
- package/dist/exports/dag.d.mts.map +1 -1
- package/dist/exports/dag.mjs +206 -76
- package/dist/exports/dag.mjs.map +1 -1
- package/dist/exports/io.d.mts +3 -3
- package/dist/exports/io.d.mts.map +1 -1
- package/dist/exports/io.mjs +1 -1
- package/dist/exports/refs.d.mts +10 -0
- package/dist/exports/refs.d.mts.map +1 -0
- package/dist/exports/refs.mjs +73 -0
- package/dist/exports/refs.mjs.map +1 -0
- package/dist/exports/types.d.mts +2 -2
- package/dist/exports/types.mjs +13 -2
- package/dist/exports/types.mjs.map +1 -0
- package/dist/{io-Dx98-h0p.mjs → io-afog-e8J.mjs} +2 -3
- package/dist/io-afog-e8J.mjs.map +1 -0
- package/dist/types-9YQfIg6N.d.mts +96 -0
- package/dist/types-9YQfIg6N.d.mts.map +1 -0
- package/package.json +26 -22
- package/src/dag.ts +267 -107
- package/src/errors.ts +58 -7
- package/src/exports/dag.ts +3 -0
- package/src/exports/refs.ts +2 -0
- package/src/exports/types.ts +6 -1
- package/src/io.ts +4 -5
- package/src/refs.ts +102 -0
- package/src/types.ts +54 -7
- package/dist/errors-DdSjGRqx.mjs.map +0 -1
- package/dist/io-Dx98-h0p.mjs.map +0 -1
- package/dist/types-CUnzoaLY.d.mts +0 -56
- package/dist/types-CUnzoaLY.d.mts.map +0 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [2026] [Prisma Data, Inc]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -88,28 +88,66 @@ function errorSelfLoop(dirName, hash) {
|
|
|
88
88
|
}
|
|
89
89
|
});
|
|
90
90
|
}
|
|
91
|
-
function errorAmbiguousLeaf(leaves) {
|
|
91
|
+
function errorAmbiguousLeaf(leaves, context) {
|
|
92
|
+
const divergenceInfo = context ? `\nDivergence point: ${context.divergencePoint}\nBranches:\n${context.branches.map((b) => ` → ${b.leaf} (${b.edges.length} edge(s): ${b.edges.map((e) => e.dirName).join(" → ") || "direct"})`).join("\n")}` : "";
|
|
92
93
|
return new MigrationToolsError("MIGRATION.AMBIGUOUS_LEAF", "Ambiguous migration graph", {
|
|
93
|
-
why: `Multiple leaf nodes found: ${leaves.join(", ")}. The migration graph has diverged — this typically happens when two developers plan migrations from the same starting point
|
|
94
|
-
fix: "
|
|
95
|
-
details: {
|
|
94
|
+
why: `Multiple leaf nodes found: ${leaves.join(", ")}. The migration graph has diverged — this typically happens when two developers plan migrations from the same starting point.${divergenceInfo}`,
|
|
95
|
+
fix: "Use `migration ref set <name> <hash>` to target a specific branch, delete one of the conflicting migration directories and re-run `migration plan`, or use --from <hash> to explicitly select a starting point.",
|
|
96
|
+
details: {
|
|
97
|
+
leaves,
|
|
98
|
+
...context ? {
|
|
99
|
+
divergencePoint: context.divergencePoint,
|
|
100
|
+
branches: context.branches
|
|
101
|
+
} : {}
|
|
102
|
+
}
|
|
96
103
|
});
|
|
97
104
|
}
|
|
98
105
|
function errorNoRoot(nodes) {
|
|
99
106
|
return new MigrationToolsError("MIGRATION.NO_ROOT", "Migration graph has no root", {
|
|
100
|
-
why: `No root migration found in the migration graph (nodes: ${nodes.join(", ")}).
|
|
101
|
-
fix: "Inspect the migrations directory for corrupted migration.json files.
|
|
107
|
+
why: `No root migration found in the migration graph (nodes: ${nodes.join(", ")}). No migration starts from the empty contract hash, or all edges form a disconnected subgraph.`,
|
|
108
|
+
fix: "Inspect the migrations directory for corrupted migration.json files. At least one migration must start from the empty contract hash.",
|
|
102
109
|
details: { nodes }
|
|
103
110
|
});
|
|
104
111
|
}
|
|
112
|
+
function errorInvalidRefs(refsPath, reason) {
|
|
113
|
+
return new MigrationToolsError("MIGRATION.INVALID_REFS", "Invalid refs.json", {
|
|
114
|
+
why: `refs.json at "${refsPath}" is invalid: ${reason}`,
|
|
115
|
+
fix: "Ensure refs.json is a flat object mapping valid ref names to contract hash strings.",
|
|
116
|
+
details: {
|
|
117
|
+
path: refsPath,
|
|
118
|
+
reason
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
function errorInvalidRefName(refName) {
|
|
123
|
+
return new MigrationToolsError("MIGRATION.INVALID_REF_NAME", "Invalid ref name", {
|
|
124
|
+
why: `Ref name "${refName}" is invalid. Names must be lowercase alphanumeric with hyphens or forward slashes (no "." or ".." segments).`,
|
|
125
|
+
fix: `Use a valid ref name (e.g., "staging", "envs/production").`,
|
|
126
|
+
details: { refName }
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
function errorNoResolvableLeaf(reachableNodes) {
|
|
130
|
+
return new MigrationToolsError("MIGRATION.NO_RESOLVABLE_LEAF", "Migration graph has no resolvable leaf", {
|
|
131
|
+
why: `The migration graph contains cycles and no node has zero outgoing edges (reachable nodes: ${reachableNodes.join(", ")}). This typically happens after rollback migrations (e.g., C1→C2→C1).`,
|
|
132
|
+
fix: "Use --from <hash> to specify the planning origin explicitly.",
|
|
133
|
+
details: { reachableNodes }
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
function errorInvalidRefValue(value) {
|
|
137
|
+
return new MigrationToolsError("MIGRATION.INVALID_REF_VALUE", "Invalid ref value", {
|
|
138
|
+
why: `Ref value "${value}" is not a valid contract hash. Values must be in the format "sha256:<64 hex chars>" or "sha256:empty".`,
|
|
139
|
+
fix: "Use a valid storage hash from `prisma-next contract emit` output or an existing migration.",
|
|
140
|
+
details: { value }
|
|
141
|
+
});
|
|
142
|
+
}
|
|
105
143
|
function errorDuplicateMigrationId(migrationId) {
|
|
106
144
|
return new MigrationToolsError("MIGRATION.DUPLICATE_MIGRATION_ID", "Duplicate migrationId in migration graph", {
|
|
107
|
-
why: `Multiple migrations share migrationId "${migrationId}".
|
|
145
|
+
why: `Multiple migrations share migrationId "${migrationId}". Each migration must have a unique content-addressed identity.`,
|
|
108
146
|
fix: "Regenerate one of the conflicting migrations so each migrationId is unique, then re-run migration commands.",
|
|
109
147
|
details: { migrationId }
|
|
110
148
|
});
|
|
111
149
|
}
|
|
112
150
|
|
|
113
151
|
//#endregion
|
|
114
|
-
export { errorInvalidJson as a,
|
|
115
|
-
//# sourceMappingURL=errors-
|
|
152
|
+
export { errorInvalidJson as a, errorInvalidRefValue as c, errorMissingFile as d, errorNoResolvableLeaf as f, errorDuplicateMigrationId as i, errorInvalidRefs as l, errorSelfLoop as m, errorAmbiguousLeaf as n, errorInvalidManifest as o, errorNoRoot as p, errorDirectoryExists as r, errorInvalidRefName as s, MigrationToolsError as t, errorInvalidSlug as u };
|
|
153
|
+
//# sourceMappingURL=errors-CqLiJwqA.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors-CqLiJwqA.mjs","names":[],"sources":["../src/errors.ts"],"sourcesContent":["/**\n * Structured error for migration tooling operations.\n *\n * Follows the NAMESPACE.SUBCODE convention from ADR 027. All codes live under\n * the MIGRATION namespace. These are tooling-time errors (file I/O, attestation,\n * migration-chain reconstruction), distinct from the runtime MIGRATION.* codes for apply-time\n * failures (PRECHECK_FAILED, POSTCHECK_FAILED, etc.).\n *\n * Fields:\n * - code: Stable machine-readable code (MIGRATION.SUBCODE)\n * - category: Always 'MIGRATION'\n * - why: Explains the cause in plain language\n * - fix: Actionable remediation step\n * - details: Machine-readable structured data for agents\n */\nexport class MigrationToolsError extends Error {\n readonly code: string;\n readonly category = 'MIGRATION' as const;\n readonly why: string;\n readonly fix: string;\n readonly details: Record<string, unknown> | undefined;\n\n constructor(\n code: string,\n summary: string,\n options: {\n readonly why: string;\n readonly fix: string;\n readonly details?: Record<string, unknown>;\n },\n ) {\n super(summary);\n this.name = 'MigrationToolsError';\n this.code = code;\n this.why = options.why;\n this.fix = options.fix;\n this.details = options.details;\n }\n\n static is(error: unknown): error is MigrationToolsError {\n if (!(error instanceof Error)) return false;\n const candidate = error as MigrationToolsError;\n return candidate.name === 'MigrationToolsError' && typeof candidate.code === 'string';\n }\n}\n\nexport function errorDirectoryExists(dir: string): MigrationToolsError {\n return new MigrationToolsError('MIGRATION.DIR_EXISTS', 'Migration directory already exists', {\n why: `The directory \"${dir}\" already exists. Each migration must have a unique directory.`,\n fix: 'Use --name to pick a different name, or delete the existing directory and re-run.',\n details: { dir },\n });\n}\n\nexport function errorMissingFile(file: string, dir: string): MigrationToolsError {\n return new MigrationToolsError('MIGRATION.FILE_MISSING', `Missing ${file}`, {\n why: `Expected \"${file}\" in \"${dir}\" but the file does not exist.`,\n fix: 'Ensure the migration directory contains both migration.json and ops.json. If the directory is corrupt, delete it and re-run migration plan.',\n details: { file, dir },\n });\n}\n\nexport function errorInvalidJson(filePath: string, parseError: string): MigrationToolsError {\n return new MigrationToolsError('MIGRATION.INVALID_JSON', 'Invalid JSON in migration file', {\n why: `Failed to parse \"${filePath}\": ${parseError}`,\n fix: 'Fix the JSON syntax error, or delete the migration directory and re-run migration plan.',\n details: { filePath, parseError },\n });\n}\n\nexport function errorInvalidManifest(filePath: string, reason: string): MigrationToolsError {\n return new MigrationToolsError('MIGRATION.INVALID_MANIFEST', 'Invalid migration manifest', {\n why: `Manifest at \"${filePath}\" is invalid: ${reason}`,\n fix: 'Ensure the manifest has all required fields (from, to, kind, toContract). If corrupt, delete and re-plan.',\n details: { filePath, reason },\n });\n}\n\nexport function errorInvalidSlug(slug: string): MigrationToolsError {\n return new MigrationToolsError('MIGRATION.INVALID_NAME', 'Invalid migration name', {\n why: `The slug \"${slug}\" contains no valid characters after sanitization (only a-z, 0-9 are kept).`,\n fix: 'Provide a name with at least one alphanumeric character, e.g. --name add_users.',\n details: { slug },\n });\n}\n\nexport function errorSelfLoop(dirName: string, hash: string): MigrationToolsError {\n return new MigrationToolsError('MIGRATION.SELF_LOOP', 'Self-loop in migration graph', {\n why: `Migration \"${dirName}\" has from === to === \"${hash}\". A migration must transition between two different contract states.`,\n fix: 'Delete the invalid migration directory and re-run migration plan.',\n details: { dirName, hash },\n });\n}\n\nexport function errorAmbiguousLeaf(\n leaves: readonly string[],\n context?: {\n divergencePoint: string;\n branches: readonly {\n leaf: string;\n edges: readonly { dirName: string; from: string; to: string }[];\n }[];\n },\n): MigrationToolsError {\n const divergenceInfo = context\n ? `\\nDivergence point: ${context.divergencePoint}\\nBranches:\\n${context.branches.map((b) => ` → ${b.leaf} (${b.edges.length} edge(s): ${b.edges.map((e) => e.dirName).join(' → ') || 'direct'})`).join('\\n')}`\n : '';\n return new MigrationToolsError('MIGRATION.AMBIGUOUS_LEAF', 'Ambiguous migration graph', {\n why: `Multiple leaf nodes found: ${leaves.join(', ')}. The migration graph has diverged — this typically happens when two developers plan migrations from the same starting point.${divergenceInfo}`,\n fix: 'Use `migration ref set <name> <hash>` to target a specific branch, delete one of the conflicting migration directories and re-run `migration plan`, or use --from <hash> to explicitly select a starting point.',\n details: {\n leaves,\n ...(context ? { divergencePoint: context.divergencePoint, branches: context.branches } : {}),\n },\n });\n}\n\nexport function errorNoRoot(nodes: readonly string[]): MigrationToolsError {\n return new MigrationToolsError('MIGRATION.NO_ROOT', 'Migration graph has no root', {\n why: `No root migration found in the migration graph (nodes: ${nodes.join(', ')}). No migration starts from the empty contract hash, or all edges form a disconnected subgraph.`,\n fix: 'Inspect the migrations directory for corrupted migration.json files. At least one migration must start from the empty contract hash.',\n details: { nodes },\n });\n}\n\nexport function errorInvalidRefs(refsPath: string, reason: string): MigrationToolsError {\n return new MigrationToolsError('MIGRATION.INVALID_REFS', 'Invalid refs.json', {\n why: `refs.json at \"${refsPath}\" is invalid: ${reason}`,\n fix: 'Ensure refs.json is a flat object mapping valid ref names to contract hash strings.',\n details: { path: refsPath, reason },\n });\n}\n\nexport function errorInvalidRefName(refName: string): MigrationToolsError {\n return new MigrationToolsError('MIGRATION.INVALID_REF_NAME', 'Invalid ref name', {\n why: `Ref name \"${refName}\" is invalid. Names must be lowercase alphanumeric with hyphens or forward slashes (no \".\" or \"..\" segments).`,\n fix: `Use a valid ref name (e.g., \"staging\", \"envs/production\").`,\n details: { refName },\n });\n}\n\nexport function errorNoResolvableLeaf(reachableNodes: readonly string[]): MigrationToolsError {\n return new MigrationToolsError(\n 'MIGRATION.NO_RESOLVABLE_LEAF',\n 'Migration graph has no resolvable leaf',\n {\n why: `The migration graph contains cycles and no node has zero outgoing edges (reachable nodes: ${reachableNodes.join(', ')}). This typically happens after rollback migrations (e.g., C1→C2→C1).`,\n fix: 'Use --from <hash> to specify the planning origin explicitly.',\n details: { reachableNodes },\n },\n );\n}\n\nexport function errorInvalidRefValue(value: string): MigrationToolsError {\n return new MigrationToolsError('MIGRATION.INVALID_REF_VALUE', 'Invalid ref value', {\n why: `Ref value \"${value}\" is not a valid contract hash. Values must be in the format \"sha256:<64 hex chars>\" or \"sha256:empty\".`,\n fix: 'Use a valid storage hash from `prisma-next contract emit` output or an existing migration.',\n details: { value },\n });\n}\n\nexport function errorDuplicateMigrationId(migrationId: string): MigrationToolsError {\n return new MigrationToolsError(\n 'MIGRATION.DUPLICATE_MIGRATION_ID',\n 'Duplicate migrationId in migration graph',\n {\n why: `Multiple migrations share migrationId \"${migrationId}\". Each migration must have a unique content-addressed identity.`,\n fix: 'Regenerate one of the conflicting migrations so each migrationId is unique, then re-run migration commands.',\n details: { migrationId },\n },\n );\n}\n"],"mappings":";;;;;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,KAAK,CAAC;EAC5H,KAAK;EACL,SAAS,EAAE,gBAAgB;EAC5B,CACF;;AAGH,SAAgB,qBAAqB,OAAoC;AACvE,QAAO,IAAI,oBAAoB,+BAA+B,qBAAqB;EACjF,KAAK,cAAc,MAAM;EACzB,KAAK;EACL,SAAS,EAAE,OAAO;EACnB,CAAC;;AAGJ,SAAgB,0BAA0B,aAA0C;AAClF,QAAO,IAAI,oBACT,oCACA,4CACA;EACE,KAAK,0CAA0C,YAAY;EAC3D,KAAK;EACL,SAAS,EAAE,aAAa;EACzB,CACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"attestation.d.mts","names":[],"sources":["../../src/attestation.ts"],"sourcesContent":[],"mappings":";;;UAQiB,YAAA;;EAAA,SAAA,MAAY,CAAA,EAAA,OAAA,GAAA,UAAA;EAWb,SAAA,iBAAkB,CAAA,EAAA,MAAW;EA2BvB,SAAA,mBAAe,
|
|
1
|
+
{"version":3,"file":"attestation.d.mts","names":[],"sources":["../../src/attestation.ts"],"sourcesContent":[],"mappings":";;;UAQiB,YAAA;;EAAA,SAAA,MAAY,CAAA,EAAA,OAAA,GAAA,UAAA;EAWb,SAAA,iBAAkB,CAAA,EAAA,MAAW;EA2BvB,SAAA,mBAAe,CAAA,EAAe,MAAA;AAUpD;iBArCgB,kBAAA,WAA6B,wBAAwB;iBA2B/C,eAAA,eAA8B;iBAU9B,eAAA,eAA8B,QAAQ"}
|
package/dist/exports/dag.d.mts
CHANGED
|
@@ -1,30 +1,49 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { a as MigrationChainEntry, o as MigrationGraph, t as AttestedMigrationBundle } from "../types-9YQfIg6N.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/dag.d.ts
|
|
4
|
-
declare function reconstructGraph(packages: readonly
|
|
4
|
+
declare function reconstructGraph(packages: readonly AttestedMigrationBundle[]): MigrationGraph;
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
7
|
-
* Returns the
|
|
8
|
-
*
|
|
6
|
+
* Find the shortest path from `fromHash` to `toHash` using BFS over the
|
|
7
|
+
* contract-hash graph. Returns the ordered list of edges, or null if no path
|
|
8
|
+
* exists. Returns an empty array when `fromHash === toHash` (no-op).
|
|
9
|
+
*
|
|
10
|
+
* Neighbor ordering is deterministic via the tie-break sort key:
|
|
11
|
+
* label priority → createdAt → to → migrationId.
|
|
9
12
|
*/
|
|
10
|
-
declare function
|
|
13
|
+
declare function findPath(graph: MigrationGraph, fromHash: string, toHash: string): readonly MigrationChainEntry[] | null;
|
|
14
|
+
interface PathDecision {
|
|
15
|
+
readonly selectedPath: readonly MigrationChainEntry[];
|
|
16
|
+
readonly fromHash: string;
|
|
17
|
+
readonly toHash: string;
|
|
18
|
+
readonly alternativeCount: number;
|
|
19
|
+
readonly tieBreakReasons: readonly string[];
|
|
20
|
+
readonly refName?: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Find the shortest path from `fromHash` to `toHash` and return structured
|
|
24
|
+
* path-decision metadata for machine-readable output.
|
|
25
|
+
*/
|
|
26
|
+
declare function findPathWithDecision(graph: MigrationGraph, fromHash: string, toHash: string, refName?: string): PathDecision | null;
|
|
11
27
|
/**
|
|
12
|
-
* Find
|
|
13
|
-
*
|
|
28
|
+
* Find all leaf nodes reachable from `fromHash` via forward edges.
|
|
29
|
+
* A leaf is a node with no outgoing edges in the graph.
|
|
30
|
+
*/
|
|
31
|
+
declare function findReachableLeaves(graph: MigrationGraph, fromHash: string): readonly string[];
|
|
32
|
+
/**
|
|
33
|
+
* Find the leaf contract hash of the migration graph reachable from
|
|
34
|
+
* EMPTY_CONTRACT_HASH. Throws NO_ROOT if the graph has nodes but none
|
|
35
|
+
* originate from the empty hash (e.g. root migration was deleted).
|
|
36
|
+
* Throws AMBIGUOUS_LEAF if multiple leaves exist.
|
|
14
37
|
*/
|
|
15
38
|
declare function findLeaf(graph: MigrationGraph): string;
|
|
16
39
|
/**
|
|
17
|
-
* Find the
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
* This reconstructs the full chain from root to leaf via parent pointers, then
|
|
22
|
-
* extracts the segment between the two hashes. This correctly handles revisited
|
|
23
|
-
* contract hashes (e.g. A→B→A) because it operates on migrations, not nodes.
|
|
40
|
+
* Find the latest migration entry by traversing from EMPTY_CONTRACT_HASH
|
|
41
|
+
* to the single leaf. Returns null for an empty graph.
|
|
42
|
+
* Throws AMBIGUOUS_LEAF if the graph has multiple leaves.
|
|
24
43
|
*/
|
|
25
|
-
declare function
|
|
44
|
+
declare function findLatestMigration(graph: MigrationGraph): MigrationChainEntry | null;
|
|
26
45
|
declare function detectCycles(graph: MigrationGraph): readonly string[][];
|
|
27
46
|
declare function detectOrphans(graph: MigrationGraph): readonly MigrationChainEntry[];
|
|
28
47
|
//#endregion
|
|
29
|
-
export { detectCycles, detectOrphans, findLatestMigration, findLeaf, findPath, reconstructGraph };
|
|
48
|
+
export { type PathDecision, detectCycles, detectOrphans, findLatestMigration, findLeaf, findPath, findPathWithDecision, findReachableLeaves, reconstructGraph };
|
|
30
49
|
//# sourceMappingURL=dag.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dag.d.mts","names":[],"sources":["../../src/dag.ts"],"sourcesContent":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"dag.d.mts","names":[],"sources":["../../src/dag.ts"],"sourcesContent":[],"mappings":";;;iBAWgB,gBAAA,oBAAoC,4BAA4B;;AAAhF;AAiFA;AA6CA;AAaA;AAqGA;AAgCA;AAwCA;AAkBgB,iBAzPA,QAAA,CAyPoB,KAAA,EAxP3B,cAwPyC,EAAA,QAAA,EAAA,MAAA,EAAA,MAAA,EAAA,MAAA,CAAA,EAAA,SArPtC,mBAqPsC,EAAA,GAAA,IAAA;AAiDlC,UA7PC,YAAA,CA6PY;kCA5PK;;;;;;;;;;;iBAYlB,oBAAA,QACP,qEAIN;;;;;iBAgGa,mBAAA,QAA2B;;;;;;;iBAgC3B,QAAA,QAAgB;;;;;;iBAwChB,mBAAA,QAA2B,iBAAiB;iBAkB5C,YAAA,QAAoB;iBAiDpB,aAAA,QAAqB,0BAA0B"}
|