From 43edeb09b50b650ef3cf9e5c8837c4ebfd152d09 Mon Sep 17 00:00:00 2001 From: Steve Ruiz Date: Thu, 4 Apr 2024 19:16:17 +0100 Subject: [PATCH] Add white migration (#3334) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This PR adds a down migration for #3321. ### Change Type - [x] `sdk` — Changes the tldraw SDK - [x] `dunno` — I don't know --- packages/state/api/api.json | 4 ++-- packages/tlschema/src/migrations.test.ts | 28 ++++++++++++++++++++++++ packages/tlschema/src/records/TLShape.ts | 19 +++++++++++++++- 3 files changed, 48 insertions(+), 3 deletions(-) diff --git a/packages/state/api/api.json b/packages/state/api/api.json index fc6d8c913..6b0f0291a 100644 --- a/packages/state/api/api.json +++ b/packages/state/api/api.json @@ -2387,7 +2387,7 @@ }, { "kind": "Content", - "text": "Value | (() => Value)" + "text": "(() => Value) | Value" }, { "kind": "Content", @@ -2813,7 +2813,7 @@ }, { "kind": "Content", - "text": "undefined | any[]" + "text": "any[] | undefined" }, { "kind": "Content", diff --git a/packages/tlschema/src/migrations.test.ts b/packages/tlschema/src/migrations.test.ts index 377920f2d..f9a6d9548 100644 --- a/packages/tlschema/src/migrations.test.ts +++ b/packages/tlschema/src/migrations.test.ts @@ -2030,6 +2030,34 @@ describe('Fractional indexing for line points', () => { }) }) +describe('add white', () => { + const { up, down } = rootShapeMigrations.migrators[rootShapeVersions.AddWhite] + + test('up works as expected', () => { + expect( + up({ + props: {}, + }) + ).toEqual({ + props: {}, + }) + }) + + test('down works as expected', () => { + expect( + down({ + props: { + color: 'white', + }, + }) + ).toEqual({ + props: { + color: 'black', + }, + }) + }) +}) + /* --- PUT YOUR MIGRATIONS TESTS ABOVE HERE --- */ for (const migrator of allMigrators) { diff --git a/packages/tlschema/src/records/TLShape.ts b/packages/tlschema/src/records/TLShape.ts index 5821ae09e..300c5fad4 100644 --- a/packages/tlschema/src/records/TLShape.ts +++ b/packages/tlschema/src/records/TLShape.ts @@ -87,11 +87,12 @@ export const rootShapeVersions = { AddIsLocked: 1, HoistOpacity: 2, AddMeta: 3, + AddWhite: 4, } as const /** @internal */ export const rootShapeMigrations = defineMigrations({ - currentVersion: rootShapeVersions.AddMeta, + currentVersion: rootShapeVersions.AddWhite, migrators: { [rootShapeVersions.AddIsLocked]: { up: (record) => { @@ -147,6 +148,22 @@ export const rootShapeMigrations = defineMigrations({ } }, }, + [rootShapeVersions.AddWhite]: { + up: (record) => { + return { + ...record, + } + }, + down: (record) => { + return { + ...record, + props: { + ...record.props, + color: record.props.color === 'white' ? 'black' : record.props.color, + }, + } + }, + }, }, })