MCPcopy
hub / github.com/tldraw/tldraw / getTestMigration

Function getTestMigration

packages/tlschema/src/__tests__/migrationTestUtils.ts:19–46  ·  view source on GitHub ↗
(migrationId: MigrationId)

Source from the content-addressed store, hash-verified

17}
18
19export 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}

Callers 2

migrations.test.tsFile · 0.90

Calls 2

findMethod · 0.80
entriesMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…