(migrationId: MigrationId)
| 17 | } |
| 18 | |
| 19 | export function getTestMigration(migrationId: MigrationId) { |
| 20 | const migration = testSchema.sortedMigrations.find((m) => m.id === migrationId) as Migration |
| 21 | if (!migration) { |
| 22 | throw new Error(`Migration ${migrationId} not found`) |
| 23 | } |
| 24 | return { |
| 25 | id: migrationId, |
| 26 | up: (stuff: any) => { |
| 27 | nextNanoId = 0 |
| 28 | if (migration.scope === 'record' || migration.scope === 'store') { |
| 29 | const result = structuredClone(stuff) |
| 30 | return migration.up(result) ?? result |
| 31 | } |
| 32 | const storage = |
| 33 | typeof stuff.entries === 'function' ? stuff : new Map(Object.entries(stuff).map(devFreeze)) |
| 34 | migration.up(storage) |
| 35 | return typeof stuff.entries === 'function' ? storage : Object.fromEntries(storage.entries()) |
| 36 | }, |
| 37 | down: (stuff: any) => { |
| 38 | nextNanoId = 0 |
| 39 | if (typeof migration.down !== 'function') { |
| 40 | throw new Error(`Migration ${migrationId} does not have a down function`) |
| 41 | } |
| 42 | const result = structuredClone(stuff) |
| 43 | return migration.down(result) ?? result |
| 44 | }, |
| 45 | } |
| 46 | } |
no test coverage detected
searching dependent graphs…