2.1.4 • Published 3 days ago

@tldraw/tlschema v2.1.4

Weekly downloads
-
License
SEE LICENSE IN LI...
Repository
github
Last release
3 days ago

@tldraw/tlschema

This package houses type definitions, schema migrations, and other type metadata for any persisted data in tldraw.

There are three main kinds of types:

  • Record types

    These are root record types added to the Store class. They are defined in the ./src/records directory.

  • Shape types

    These are subtypes of the root TLShape record type. They allow specifying a unique name and custom props for a particular kind of shape.

  • Asset types

    These are subtypes of the root TLAsset record type. They allow specifying a unique name and custom props for a particular kind of asset.

Creating a new record type

To create a new record type called, e.g. TLBanana, run

# Create the new file in ./records/TLBanana.ts
yarn new-record TLBanana
# Rebuild the index files to make sure it is exported
yarn index

You may then customize your new blank TLBanana type!

Creating a new shape type

To create a new shape type called, e.g. TLMapboxShape, run

# Create the new file in ./shapes/TLMapboxShape.ts
yarn new-shape TLMapboxShape
# Rebuild the index files to make sure it is exported
yarn index

You may then customize your new blank TLMapboxShape type!

Creating a new asset type

To create a new shape type called, e.g. TLZipFileAsset, run

# Create the new file in ./assets/TLZipFileAsset.ts
yarn new-asset TLZipFileAsset
# Rebuild the index files to make sure it is exported
yarn index

You may then customize your new blank TLZipFileAsset type!

Adding migrations

If you make any kind of change to any persisted data shape in this package, you must add migrations that are able to convert old versions to new versions, and vice-versa.

If you are making a change that affects the structure of a record, shape, or asset, update the migrations in the same file as the record, shape, or asset is defined.

If you are making a change that affects the structure of the store (e.g. renaming or deleting a type, consolidating two shape types into one, etc), add your changes in the migrations in schema.ts.

After making your changes, add a new version number, using a meaninful name. For example, if you add a new property to the TLShape type called ownerId that points to a user, you might do this:

In TLShape.ts

 const Versions = {
   Initial: 1,
+  AddOwnerId: 2,
 } as const

and then in the TLShape type

   x: number
   y: number
+  ownerId: ID<TLUser> | null
   props: Props
   parentId: ID<TLShape> | ID<TLPage>

and then adding a migration:

 export const shapeTypeMigrations = defineMigrations({
   // STEP 2: Update the current version to point to your latest version
   currentVersion: Versions.Initial,
   firstVersion: Versions.Initial,
   migrators: {
     // STEP 3: Add an up+down migration for the new version here
+    [Versions.AddOwnerId]: {
+      // add ownerId property
+      up: (shape) => ({...shape, ownerId: null}),
+      // remove ownerId property
+      down: ({ownerId, ...shape}) => shape,
+    }
   },

After you've added your migration, make sure to add a test for it in src/migrations.test.ts. It will complain if you do not!

2.1.4

23 days ago

2.1.2

27 days ago

2.1.3

27 days ago

2.1.1

28 days ago

2.1.0

29 days ago

2.0.2

2 months ago

2.0.1

2 months ago

2.0.0

3 months ago

2.0.0-beta.9

3 months ago

2.0.0-beta.8

3 months ago

2.0.0-beta.7

3 months ago

2.0.0-beta.6

3 months ago

2.0.0-beta.5

3 months ago

2.0.0-beta.4

3 months ago

2.0.0-beta.3

3 months ago

2.0.0-beta.2

4 months ago

2.0.0-beta.1

5 months ago

2.0.0-alpha.19

5 months ago

2.0.0-alpha.18

6 months ago

2.0.0-alpha.17

7 months ago

2.0.0-alpha.16

7 months ago

2.0.0-alpha.15

8 months ago

2.0.0-alpha.14

11 months ago

2.0.0-alpha.13

11 months ago

0.1.0-alpha.10

1 year ago

0.1.0-alpha.11

1 year ago

2.0.0-alpha.7

1 year ago

2.0.0-alpha.8

1 year ago

2.0.0-alpha.9

1 year ago

2.0.0-alpha.11

1 year ago

2.0.0-alpha.3

1 year ago

2.0.0-alpha.10

1 year ago

2.0.0-alpha.4

1 year ago

2.0.0-alpha.5

1 year ago

2.0.0-alpha.6

1 year ago

2.0.0-alpha.2

1 year ago

2.0.0-alpha.12

1 year ago

0.1.0-alpha.9

1 year ago

0.1.0-alpha.8

1 year ago

0.1.0-alpha.7

1 year ago

0.1.0-alpha.5

1 year ago

0.1.0-alpha.6

1 year ago

0.1.0-alpha.3

1 year ago

0.1.0-alpha.2

1 year ago

0.0.2-alpha.1

1 year ago

0.0.2-alpha.0

1 year ago

0.0.1-alpha.4

1 year ago

0.0.1-alpha.3

1 year ago

0.0.1-alpha.2

1 year ago

0.0.1-alpha.1

1 year ago

0.0.1-alpha.0

1 year ago

0.0.0

1 year ago

0.0.0-alpha.1

1 year ago