@prisma-next/migration-tools 0.5.0-dev.1 → 0.5.0-dev.10

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 (76) hide show
  1. package/README.md +32 -20
  2. package/dist/{constants-BRi0X7B_.mjs → constants-WVGVMOdu.mjs} +1 -1
  3. package/dist/{constants-BRi0X7B_.mjs.map → constants-WVGVMOdu.mjs.map} +1 -1
  4. package/dist/{errors-BKbRGCJM.mjs → errors-CZ9JD4sd.mjs} +50 -21
  5. package/dist/errors-CZ9JD4sd.mjs.map +1 -0
  6. package/dist/exports/constants.mjs +1 -1
  7. package/dist/exports/dag.d.mts +4 -3
  8. package/dist/exports/dag.d.mts.map +1 -1
  9. package/dist/exports/dag.mjs +15 -15
  10. package/dist/exports/dag.mjs.map +1 -1
  11. package/dist/exports/{types.d.mts → errors.d.mts} +6 -8
  12. package/dist/exports/errors.d.mts.map +1 -0
  13. package/dist/exports/errors.mjs +3 -0
  14. package/dist/exports/graph.d.mts +2 -0
  15. package/dist/exports/graph.mjs +1 -0
  16. package/dist/exports/hash.d.mts +52 -0
  17. package/dist/exports/hash.d.mts.map +1 -0
  18. package/dist/exports/hash.mjs +3 -0
  19. package/dist/exports/io.d.mts +7 -6
  20. package/dist/exports/io.d.mts.map +1 -1
  21. package/dist/exports/io.mjs +156 -2
  22. package/dist/exports/io.mjs.map +1 -0
  23. package/dist/exports/metadata.d.mts +2 -0
  24. package/dist/exports/metadata.mjs +1 -0
  25. package/dist/exports/migration-ts.mjs +1 -1
  26. package/dist/exports/migration.d.mts +13 -10
  27. package/dist/exports/migration.d.mts.map +1 -1
  28. package/dist/exports/migration.mjs +20 -21
  29. package/dist/exports/migration.mjs.map +1 -1
  30. package/dist/exports/package.d.mts +2 -0
  31. package/dist/exports/package.mjs +1 -0
  32. package/dist/exports/refs.d.mts +11 -5
  33. package/dist/exports/refs.d.mts.map +1 -1
  34. package/dist/exports/refs.mjs +106 -30
  35. package/dist/exports/refs.mjs.map +1 -1
  36. package/dist/graph-HiqjZROg.d.mts +22 -0
  37. package/dist/graph-HiqjZROg.d.mts.map +1 -0
  38. package/dist/hash-BNWumjn7.mjs +76 -0
  39. package/dist/hash-BNWumjn7.mjs.map +1 -0
  40. package/dist/metadata-DDa5L-uD.d.mts +45 -0
  41. package/dist/metadata-DDa5L-uD.d.mts.map +1 -0
  42. package/dist/package-BJ5KAEcD.d.mts +21 -0
  43. package/dist/package-BJ5KAEcD.d.mts.map +1 -0
  44. package/package.json +23 -11
  45. package/src/dag.ts +19 -18
  46. package/src/errors.ts +57 -15
  47. package/src/exports/errors.ts +1 -0
  48. package/src/exports/graph.ts +1 -0
  49. package/src/exports/hash.ts +2 -0
  50. package/src/exports/io.ts +1 -1
  51. package/src/exports/metadata.ts +1 -0
  52. package/src/exports/package.ts +1 -0
  53. package/src/exports/refs.ts +10 -2
  54. package/src/graph.ts +19 -0
  55. package/src/hash.ts +91 -0
  56. package/src/io.ts +32 -20
  57. package/src/metadata.ts +36 -0
  58. package/src/migration-base.ts +32 -28
  59. package/src/package.ts +18 -0
  60. package/src/refs.ts +148 -37
  61. package/dist/attestation-DtF8tEOM.mjs +0 -65
  62. package/dist/attestation-DtF8tEOM.mjs.map +0 -1
  63. package/dist/errors-BKbRGCJM.mjs.map +0 -1
  64. package/dist/exports/attestation.d.mts +0 -37
  65. package/dist/exports/attestation.d.mts.map +0 -1
  66. package/dist/exports/attestation.mjs +0 -4
  67. package/dist/exports/types.d.mts.map +0 -1
  68. package/dist/exports/types.mjs +0 -3
  69. package/dist/io-CCnYsUHU.mjs +0 -153
  70. package/dist/io-CCnYsUHU.mjs.map +0 -1
  71. package/dist/types-DyGXcWWp.d.mts +0 -71
  72. package/dist/types-DyGXcWWp.d.mts.map +0 -1
  73. package/src/attestation.ts +0 -81
  74. package/src/exports/attestation.ts +0 -2
  75. package/src/exports/types.ts +0 -10
  76. package/src/types.ts +0 -66
@@ -1,81 +0,0 @@
1
- import { createHash } from 'node:crypto';
2
- import { canonicalizeJson } from './canonicalize-json';
3
- import { readMigrationPackage } from './io';
4
- import type { MigrationBundle, MigrationManifest, MigrationOps } from './types';
5
-
6
- export interface VerifyResult {
7
- readonly ok: boolean;
8
- readonly reason?: 'mismatch';
9
- readonly storedMigrationId?: string;
10
- readonly computedMigrationId?: string;
11
- }
12
-
13
- function sha256Hex(input: string): string {
14
- return createHash('sha256').update(input).digest('hex');
15
- }
16
-
17
- /**
18
- * Content-addressed migration identity over (manifest envelope sans
19
- * contracts/hints, ops). See ADR 199 "Storage-only migration identity"
20
- * for the rationale: contracts are anchored separately by the
21
- * storage-hash bookends inside the envelope; planner hints are advisory
22
- * and must not affect identity.
23
- *
24
- * The `migrationId` field on the manifest is stripped before hashing so
25
- * the function can be used both at write time (when no id exists yet)
26
- * and at verify time (rehashing an already-attested manifest).
27
- */
28
- export function computeMigrationId(
29
- manifest: Omit<MigrationManifest, 'migrationId'> & { readonly migrationId?: string },
30
- ops: MigrationOps,
31
- ): string {
32
- const {
33
- migrationId: _migrationId,
34
- signature: _signature,
35
- fromContract: _fromContract,
36
- toContract: _toContract,
37
- hints: _hints,
38
- ...strippedMeta
39
- } = manifest;
40
-
41
- const canonicalManifest = canonicalizeJson(strippedMeta);
42
- const canonicalOps = canonicalizeJson(ops);
43
-
44
- const partHashes = [canonicalManifest, canonicalOps].map(sha256Hex);
45
- const hash = sha256Hex(canonicalizeJson(partHashes));
46
-
47
- return `sha256:${hash}`;
48
- }
49
-
50
- /**
51
- * Re-hash an on-disk migration bundle and compare against the stored
52
- * `migrationId`. Returns `{ ok: true }` when the package is internally
53
- * consistent (manifest + ops still produce the recorded id), or
54
- * `{ ok: false, reason: 'mismatch', stored, computed }` when they do
55
- * not — typically a sign of FS corruption, partial writes, or a
56
- * post-emit hand edit.
57
- */
58
- export function verifyMigrationBundle(bundle: MigrationBundle): VerifyResult {
59
- const computed = computeMigrationId(bundle.manifest, bundle.ops);
60
-
61
- if (bundle.manifest.migrationId === computed) {
62
- return {
63
- ok: true,
64
- storedMigrationId: bundle.manifest.migrationId,
65
- computedMigrationId: computed,
66
- };
67
- }
68
-
69
- return {
70
- ok: false,
71
- reason: 'mismatch',
72
- storedMigrationId: bundle.manifest.migrationId,
73
- computedMigrationId: computed,
74
- };
75
- }
76
-
77
- /** Convenience wrapper: read the package from disk then verify it. */
78
- export async function verifyMigration(dir: string): Promise<VerifyResult> {
79
- const pkg = await readMigrationPackage(dir);
80
- return verifyMigrationBundle(pkg);
81
- }
@@ -1,2 +0,0 @@
1
- export type { VerifyResult } from '../attestation';
2
- export { computeMigrationId, verifyMigration, verifyMigrationBundle } from '../attestation';
@@ -1,10 +0,0 @@
1
- export { MigrationToolsError } from '../errors';
2
- export type {
3
- MigrationBundle,
4
- MigrationBundle as MigrationPackage,
5
- MigrationChainEntry,
6
- MigrationGraph,
7
- MigrationHints,
8
- MigrationManifest,
9
- MigrationOps,
10
- } from '../types';
package/src/types.ts DELETED
@@ -1,66 +0,0 @@
1
- import type { Contract } from '@prisma-next/contract/types';
2
- import type { MigrationPlanOperation } from '@prisma-next/framework-components/control';
3
-
4
- export interface MigrationHints {
5
- readonly used: readonly string[];
6
- readonly applied: readonly string[];
7
- readonly plannerVersion: string;
8
- }
9
-
10
- /**
11
- * On-disk migration manifest. Every migration is content-addressed: the
12
- * `migrationId` is a hash over the manifest envelope plus the operations
13
- * list, computed at write time. There is no draft state — a migration
14
- * directory either exists with a fully attested manifest or it does not.
15
- *
16
- * When the planner cannot lower an operation because of an unfilled
17
- * `placeholder(...)` slot, the migration is still written with
18
- * `migrationId` hashed over `ops: []`. Re-running self-emit after the
19
- * user fills the placeholder produces a *different* `migrationId`
20
- * (committed to the real ops); this is intentional.
21
- */
22
- export interface MigrationManifest {
23
- readonly migrationId: string;
24
- readonly from: string;
25
- readonly to: string;
26
- readonly kind: 'regular' | 'baseline';
27
- readonly fromContract: Contract | null;
28
- readonly toContract: Contract;
29
- readonly hints: MigrationHints;
30
- readonly labels: readonly string[];
31
- readonly authorship?: { readonly author?: string; readonly email?: string };
32
- readonly signature?: { readonly keyId: string; readonly value: string } | null;
33
- readonly createdAt: string;
34
- }
35
-
36
- export type MigrationOps = readonly MigrationPlanOperation[];
37
-
38
- /**
39
- * An on-disk migration directory containing a manifest and operations.
40
- */
41
- export interface MigrationBundle {
42
- readonly dirName: string;
43
- readonly dirPath: string;
44
- readonly manifest: MigrationManifest;
45
- readonly ops: MigrationOps;
46
- }
47
-
48
- /**
49
- * An entry in the migration graph. All on-disk migrations are attested,
50
- * so `migrationId` is always a string.
51
- */
52
- export interface MigrationChainEntry {
53
- readonly from: string;
54
- readonly to: string;
55
- readonly migrationId: string;
56
- readonly dirName: string;
57
- readonly createdAt: string;
58
- readonly labels: readonly string[];
59
- }
60
-
61
- export interface MigrationGraph {
62
- readonly nodes: ReadonlySet<string>;
63
- readonly forwardChain: ReadonlyMap<string, readonly MigrationChainEntry[]>;
64
- readonly reverseChain: ReadonlyMap<string, readonly MigrationChainEntry[]>;
65
- readonly migrationById: ReadonlyMap<string, MigrationChainEntry>;
66
- }