@tldraw/tlschema 4.5.2 → 4.6.0-canary.4ec045c286e1

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.
@@ -7,6 +7,7 @@ import { MakeUndefinedOptional } from '@tldraw/utils';
7
7
  import { MigrationId } from '@tldraw/store';
8
8
  import { MigrationSequence } from '@tldraw/store';
9
9
  import { RecordId } from '@tldraw/store';
10
+ import { RecordScope } from '@tldraw/store';
10
11
  import { RecordType } from '@tldraw/store';
11
12
  import { SerializedStore } from '@tldraw/store';
12
13
  import { Signal } from '@tldraw/state';
@@ -717,6 +718,82 @@ export declare function createBindingValidator<Type extends string, Props extend
717
718
  [K in keyof Meta]: T.Validatable<Meta[K]>;
718
719
  }): T.ObjectValidator<Expand< { [P in "fromId" | "id" | "meta" | "toId" | "typeName" | (undefined extends Props ? never : "props") | (undefined extends Type ? never : "type")]: TLBaseBinding<Type, Props>[P]; } & { [P in (undefined extends Props ? "props" : never) | (undefined extends Type ? "type" : never)]?: TLBaseBinding<Type, Props>[P] | undefined; }>>;
719
720
 
721
+ /**
722
+ * Creates a unique ID for a custom record type.
723
+ *
724
+ * @param typeName - The type name of the custom record
725
+ * @param id - Optional custom ID suffix. If not provided, a unique ID will be generated
726
+ * @returns A properly formatted record ID
727
+ *
728
+ * @example
729
+ * ```ts
730
+ * // Create with auto-generated ID
731
+ * const commentId = createCustomRecordId('comment') // 'comment:abc123'
732
+ *
733
+ * // Create with custom ID
734
+ * const customId = createCustomRecordId('comment', 'my-comment') // 'comment:my-comment'
735
+ * ```
736
+ *
737
+ * @public
738
+ */
739
+ export declare function createCustomRecordId<T extends string>(typeName: T, id?: string): RecordId<UnknownRecord> & `${T}:${string}`;
740
+
741
+ /**
742
+ * Creates properly formatted migration IDs for custom record migrations.
743
+ *
744
+ * Generates standardized migration IDs following the convention:
745
+ * `com.tldraw.{recordType}/{version}`
746
+ *
747
+ * @param recordType - The type name of the custom record
748
+ * @param ids - Record mapping migration names to version numbers
749
+ * @returns Record with the same keys but formatted migration ID values
750
+ *
751
+ * @example
752
+ * ```ts
753
+ * const commentVersions = createCustomRecordMigrationIds('comment', {
754
+ * AddAuthorId: 1,
755
+ * AddCreatedAt: 2,
756
+ * RefactorReactions: 3
757
+ * })
758
+ * // Result: {
759
+ * // AddAuthorId: 'com.tldraw.comment/1',
760
+ * // AddCreatedAt: 'com.tldraw.comment/2',
761
+ * // RefactorReactions: 'com.tldraw.comment/3'
762
+ * // }
763
+ * ```
764
+ *
765
+ * @public
766
+ */
767
+ export declare function createCustomRecordMigrationIds<const S extends string, const T extends Record<string, number>>(recordType: S, ids: T): {
768
+ [k in keyof T]: `com.tldraw.${S}/${T[k]}`;
769
+ };
770
+
771
+ /**
772
+ * Creates a migration sequence for custom record types.
773
+ *
774
+ * This is a pass-through function that maintains the same structure as the input.
775
+ * It's used for consistency and to provide a clear API for defining custom record migrations.
776
+ *
777
+ * @param migrations - The migration sequence to create
778
+ * @returns The same migration sequence (pass-through)
779
+ *
780
+ * @example
781
+ * ```ts
782
+ * const commentMigrations = createCustomRecordMigrationSequence({
783
+ * sequence: [
784
+ * {
785
+ * id: 'com.myapp.comment/1',
786
+ * up: (record) => ({ ...record, authorId: record.authorId ?? 'unknown' }),
787
+ * down: ({ authorId, ...record }) => record
788
+ * }
789
+ * ]
790
+ * })
791
+ * ```
792
+ *
793
+ * @public
794
+ */
795
+ export declare function createCustomRecordMigrationSequence(migrations: TLPropsMigrations): TLPropsMigrations;
796
+
720
797
  /**
721
798
  * Creates a derivation that represents the current presence state of the current user.
722
799
  *
@@ -882,12 +959,14 @@ export declare function createShapeValidator<Type extends string, Props extends
882
959
  * validation, and migration sequences for all record types in a tldraw application.
883
960
  *
884
961
  * The schema includes all core record types (pages, cameras, instances, etc.) plus the
885
- * shape and binding types you specify. Style properties are automatically collected from
886
- * all shapes to ensure consistency across the application.
962
+ * shape, binding, and custom record types you specify. Style properties are automatically
963
+ * collected from all shapes to ensure consistency across the application.
887
964
  *
888
965
  * @param options - Configuration options for the schema
889
966
  * - shapes - Shape schema configurations. Defaults to defaultShapeSchemas if not provided
890
967
  * - bindings - Binding schema configurations. Defaults to defaultBindingSchemas if not provided
968
+ * - records - Custom record type configurations. These are additional record types beyond
969
+ * the built-in shapes, bindings, assets, etc.
891
970
  * - migrations - Additional migration sequences to include in the schema
892
971
  * @returns A complete TLSchema ready for use with Store creation
893
972
  *
@@ -911,13 +990,19 @@ export declare function createShapeValidator<Type extends string, Props extends
911
990
  * },
912
991
  * })
913
992
  *
914
- * // Create schema with only specific shapes
915
- * const minimalSchema = createTLSchema({
916
- * shapes: {
917
- * geo: defaultShapeSchemas.geo,
918
- * text: defaultShapeSchemas.text,
993
+ * // Create schema with custom record types
994
+ * const schemaWithCustomRecords = createTLSchema({
995
+ * records: {
996
+ * comment: {
997
+ * scope: 'document',
998
+ * validator: T.object({
999
+ * id: T.string,
1000
+ * typeName: T.literal('comment'),
1001
+ * text: T.string,
1002
+ * shapeId: T.string,
1003
+ * }),
1004
+ * },
919
1005
  * },
920
- * bindings: defaultBindingSchemas,
921
1006
  * })
922
1007
  *
923
1008
  * // Use the schema with a store
@@ -929,12 +1014,74 @@ export declare function createShapeValidator<Type extends string, Props extends
929
1014
  * })
930
1015
  * ```
931
1016
  */
932
- export declare function createTLSchema({ shapes, bindings, migrations }?: {
1017
+ export declare function createTLSchema({ shapes, bindings, records, migrations }?: {
933
1018
  bindings?: Record<string, SchemaPropsInfo>;
934
1019
  migrations?: readonly MigrationSequence[];
1020
+ records?: Record<string, CustomRecordInfo>;
935
1021
  shapes?: Record<string, SchemaPropsInfo>;
936
1022
  }): TLSchema;
937
1023
 
1024
+ /**
1025
+ * Configuration for a custom record type in the schema.
1026
+ *
1027
+ * Custom record types allow you to add entirely new data types to the tldraw store
1028
+ * that don't fit into the existing shape, binding, or asset categories. This is useful
1029
+ * for storing domain-specific data like comments, annotations, or application state
1030
+ * that needs to participate in persistence and synchronization.
1031
+ *
1032
+ * @example
1033
+ * ```ts
1034
+ * const commentRecordConfig: CustomRecordInfo = {
1035
+ * scope: 'document',
1036
+ * validator: T.object({
1037
+ * id: T.string,
1038
+ * typeName: T.literal('comment'),
1039
+ * text: T.string,
1040
+ * shapeId: T.string,
1041
+ * authorId: T.string,
1042
+ * createdAt: T.number,
1043
+ * }),
1044
+ * migrations: createRecordMigrationSequence({
1045
+ * sequenceId: 'com.myapp.comment',
1046
+ * recordType: 'comment',
1047
+ * sequence: [],
1048
+ * }),
1049
+ * }
1050
+ * ```
1051
+ *
1052
+ * @public
1053
+ */
1054
+ export declare interface CustomRecordInfo {
1055
+ /**
1056
+ * The scope determines how records of this type are persisted and synchronized:
1057
+ * - **document**: Persisted and synced across all clients
1058
+ * - **session**: Local to current session, not synced
1059
+ * - **presence**: Ephemeral presence data, may be synced but not persisted
1060
+ */
1061
+ scope: RecordScope;
1062
+ /**
1063
+ * Validator for the complete record structure.
1064
+ *
1065
+ * Should validate the entire record including `id` and `typeName` fields.
1066
+ * Use validators like T.object, T.string, etc.
1067
+ */
1068
+ validator: T.Validatable<any>;
1069
+ /**
1070
+ * Optional migration sequence for handling schema evolution over time.
1071
+ *
1072
+ * Can be a full MigrationSequence or a simplified TLPropsMigrations format.
1073
+ * If not provided, an empty migration sequence will be created automatically.
1074
+ */
1075
+ migrations?: MigrationSequence | TLPropsMigrations;
1076
+ /**
1077
+ * Optional factory function that returns default property values for new records.
1078
+ *
1079
+ * Called when creating new records to provide initial values for any properties
1080
+ * not explicitly provided during creation.
1081
+ */
1082
+ createDefaultProperties?: () => Record<string, unknown>;
1083
+ }
1084
+
938
1085
  /**
939
1086
  * Default binding schema configurations for all built-in tldraw binding types.
940
1087
  * Bindings represent relationships between shapes, such as arrows connected to shapes.
@@ -1971,6 +2118,47 @@ export declare function isBinding(record?: UnknownRecord): record is TLBinding;
1971
2118
  */
1972
2119
  export declare function isBindingId(id?: string): id is TLBindingId;
1973
2120
 
2121
+ /**
2122
+ * Type guard to check if a record is of a specific custom type.
2123
+ *
2124
+ * @param typeName - The type name to check against
2125
+ * @param record - The record to check
2126
+ * @returns True if the record is of the specified type
2127
+ *
2128
+ * @example
2129
+ * ```ts
2130
+ * function handleRecord(record: TLRecord) {
2131
+ * if (isCustomRecord('comment', record)) {
2132
+ * // Handle comment record
2133
+ * console.log(`Comment: ${record.text}`)
2134
+ * }
2135
+ * }
2136
+ * ```
2137
+ *
2138
+ * @public
2139
+ */
2140
+ export declare function isCustomRecord(typeName: string, record?: UnknownRecord): boolean;
2141
+
2142
+ /**
2143
+ * Type guard to check if a string is a valid ID for a specific custom record type.
2144
+ *
2145
+ * @param typeName - The type name to check against
2146
+ * @param id - The string to check
2147
+ * @returns True if the string is a valid ID for the specified record type
2148
+ *
2149
+ * @example
2150
+ * ```ts
2151
+ * const id = 'comment:abc123'
2152
+ * if (isCustomRecordId('comment', id)) {
2153
+ * // id is now typed as a comment record ID
2154
+ * const comment = store.get(id)
2155
+ * }
2156
+ * ```
2157
+ *
2158
+ * @public
2159
+ */
2160
+ export declare function isCustomRecordId(typeName: string, id?: string): boolean;
2161
+
1974
2162
  /**
1975
2163
  * Type guard to check if a record is a TLDocument.
1976
2164
  * Useful for filtering or type narrowing when working with mixed record types.
@@ -3787,6 +3975,13 @@ export declare interface TLCursor {
3787
3975
  */
3788
3976
  export declare type TLCursorType = SetValue<typeof TL_CURSOR_TYPES>;
3789
3977
 
3978
+ /**
3979
+ * Union type representing a custom record from the TLGlobalRecordPropsMap.
3980
+ *
3981
+ * @public
3982
+ */
3983
+ export declare type TLCustomRecord = TLIndexedRecords[keyof TLIndexedRecords];
3984
+
3790
3985
  /**
3791
3986
  * The default set of bindings that are available in the editor.
3792
3987
  * Currently includes only arrow bindings, but can be extended with custom bindings.
@@ -3994,6 +4189,16 @@ export declare type TLDefaultFontStyle = T.TypeOf<typeof DefaultFontStyle>;
3994
4189
  */
3995
4190
  export declare type TLDefaultHorizontalAlignStyle = T.TypeOf<typeof DefaultHorizontalAlignStyle>;
3996
4191
 
4192
+ /**
4193
+ * Union type of all built-in tldraw record types.
4194
+ *
4195
+ * This includes persistent records (documents, pages, shapes, assets, bindings)
4196
+ * and session/presence records (cameras, instances, pointers, page states).
4197
+ *
4198
+ * @public
4199
+ */
4200
+ export declare type TLDefaultRecord = TLAsset | TLBinding | TLCamera | TLDocument | TLInstance | TLInstancePageState | TLInstancePresence | TLPage | TLPointer | TLShape;
4201
+
3997
4202
  /**
3998
4203
  * The default set of shapes that are available in the editor.
3999
4204
  *
@@ -4407,6 +4612,41 @@ export declare interface TLGeoShapeProps {
4407
4612
  export declare interface TLGlobalBindingPropsMap {
4408
4613
  }
4409
4614
 
4615
+ /**
4616
+ * Interface for extending tldraw with custom record types via TypeScript module augmentation.
4617
+ *
4618
+ * Custom record types allow you to add entirely new data types to the tldraw store that
4619
+ * don't fit into the existing shape, binding, or asset categories. Each key in this
4620
+ * interface becomes a new record type name, and the value should be your full record type.
4621
+ *
4622
+ * @example
4623
+ * ```ts
4624
+ * import { BaseRecord, RecordId } from '@tldraw/store'
4625
+ *
4626
+ * // Define your custom record type
4627
+ * interface TLComment extends BaseRecord<'comment', RecordId<TLComment>> {
4628
+ * text: string
4629
+ * shapeId: TLShapeId
4630
+ * authorId: string
4631
+ * createdAt: number
4632
+ * }
4633
+ *
4634
+ * // Augment the global record props map
4635
+ * declare module '@tldraw/tlschema' {
4636
+ * interface TLGlobalRecordPropsMap {
4637
+ * comment: TLComment
4638
+ * }
4639
+ * }
4640
+ *
4641
+ * // Now TLRecord includes your custom comment type
4642
+ * // and you can use it with createTLSchema()
4643
+ * ```
4644
+ *
4645
+ * @public
4646
+ */
4647
+ export declare interface TLGlobalRecordPropsMap {
4648
+ }
4649
+
4410
4650
  /** @public */
4411
4651
  export declare interface TLGlobalShapePropsMap {
4412
4652
  }
@@ -4700,6 +4940,19 @@ export declare type TLIndexedBindings = {
4700
4940
  }> : TLBaseBinding<K, TLGlobalBindingPropsMap[K & keyof TLGlobalBindingPropsMap]>;
4701
4941
  };
4702
4942
 
4943
+ /**
4944
+ * Index type that maps custom record type names to their record types.
4945
+ *
4946
+ * Similar to TLIndexedShapes and TLIndexedBindings, this type creates a mapping
4947
+ * from type name keys to their corresponding record types, filtering out any
4948
+ * disabled types (those set to null or undefined in TLGlobalRecordPropsMap).
4949
+ *
4950
+ * @public
4951
+ */
4952
+ export declare type TLIndexedRecords = {
4953
+ [K in keyof TLGlobalRecordPropsMap as TLGlobalRecordPropsMap[K] extends null | undefined ? never : K]: TLGlobalRecordPropsMap[K];
4954
+ };
4955
+
4703
4956
  /** @public */
4704
4957
  export declare type TLIndexedShapes = {
4705
4958
  [K in keyof TLGlobalShapePropsMap | TLDefaultShape['type'] as K extends TLDefaultShape['type'] ? K extends 'group' ? K : K extends keyof TLGlobalShapePropsMap ? TLGlobalShapePropsMap[K] extends null | undefined ? never : K : K : K]: K extends 'group' ? Extract<TLDefaultShape, {
@@ -5385,7 +5638,8 @@ export declare interface TLPropsMigrations {
5385
5638
  /**
5386
5639
  * Union type representing all possible record types in a tldraw store.
5387
5640
  * This includes both persistent records (documents, pages, shapes, assets, bindings)
5388
- * and session/presence records (cameras, instances, pointers, page states).
5641
+ * and session/presence records (cameras, instances, pointers, page states),
5642
+ * as well as any custom record types added via TLGlobalRecordPropsMap augmentation.
5389
5643
  *
5390
5644
  * Records are organized by scope:
5391
5645
  * - **document**: Persisted across sessions (shapes, pages, assets, bindings, documents)
@@ -5425,7 +5679,7 @@ export declare interface TLPropsMigrations {
5425
5679
  *
5426
5680
  * @public
5427
5681
  */
5428
- export declare type TLRecord = TLAsset | TLBinding | TLCamera | TLDocument | TLInstance | TLInstancePageState | TLInstancePresence | TLPage | TLPointer | TLShape;
5682
+ export declare type TLRecord = TLCustomRecord | TLDefaultRecord;
5429
5683
 
5430
5684
  /**
5431
5685
  * Type representing rich text content in tldraw. Rich text follows a document-based
@@ -47,6 +47,13 @@ import {
47
47
  rootBindingMigrations
48
48
  } from "./records/TLBinding.mjs";
49
49
  import { CameraRecordType } from "./records/TLCamera.mjs";
50
+ import {
51
+ createCustomRecordId,
52
+ createCustomRecordMigrationIds,
53
+ createCustomRecordMigrationSequence,
54
+ isCustomRecord,
55
+ isCustomRecordId
56
+ } from "./records/TLCustomRecord.mjs";
50
57
  import {
51
58
  DocumentRecordType,
52
59
  isDocument,
@@ -174,7 +181,7 @@ import {
174
181
  } from "./translations/translations.mjs";
175
182
  registerTldrawLibraryVersion(
176
183
  "@tldraw/tlschema",
177
- "4.5.2",
184
+ "4.6.0-canary.4ec045c286e1",
178
185
  "esm"
179
186
  );
180
187
  import { b64Vecs } from "./misc/b64Vecs.mjs";
@@ -235,6 +242,9 @@ export {
235
242
  createBindingPropsMigrationIds,
236
243
  createBindingPropsMigrationSequence,
237
244
  createBindingValidator,
245
+ createCustomRecordId,
246
+ createCustomRecordMigrationIds,
247
+ createCustomRecordMigrationSequence,
238
248
  createPresenceStateDerivation,
239
249
  createShapeId,
240
250
  createShapePropsMigrationIds,
@@ -266,6 +276,8 @@ export {
266
276
  imageShapeProps,
267
277
  isBinding,
268
278
  isBindingId,
279
+ isCustomRecord,
280
+ isCustomRecordId,
269
281
  isDocument,
270
282
  isPageId,
271
283
  isShape,
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/index.ts"],
4
- "sourcesContent": ["/**\n * @fileoverview\n * Main entry point for the tldraw schema package. Exports the complete type system,\n * data structures, validation, and migrations for tldraw's persisted data.\n *\n * This package provides:\n * - Schema creation utilities (createTLSchema, defaultShapeSchemas, defaultBindingSchemas)\n * - All built-in shape types (TLGeoShape, TLTextShape, TLArrowShape, etc.)\n * - Asset management types and validators (TLImageAsset, TLVideoAsset, TLBookmarkAsset)\n * - Binding system for shape relationships (TLArrowBinding)\n * - Store integration types (TLStore, TLStoreProps, TLStoreSnapshot)\n * - Style properties for consistent styling (DefaultColorStyle, DefaultSizeStyle, etc.)\n * - Validation utilities and type guards\n * - Migration systems for schema evolution\n * - Geometry and utility types\n *\n * @example\n * ```ts\n * import { createTLSchema, defaultShapeSchemas, TLStore } from '@tldraw/tlschema'\n *\n * // Create a schema with default shapes\n * const schema = createTLSchema({\n * shapes: defaultShapeSchemas\n * })\n *\n * // Use with a store\n * const store = new Store({ schema })\n * ```\n *\n * @public\n */\n\nimport { registerTldrawLibraryVersion } from '@tldraw/utils'\nexport { assetIdValidator, createAssetValidator, type TLBaseAsset } from './assets/TLBaseAsset'\nexport { type TLBookmarkAsset } from './assets/TLBookmarkAsset'\nexport { type TLImageAsset } from './assets/TLImageAsset'\nexport { type TLVideoAsset } from './assets/TLVideoAsset'\nexport {\n\tarrowBindingMigrations,\n\tarrowBindingProps,\n\tarrowBindingVersions,\n\tElbowArrowSnap,\n\ttype TLArrowBinding,\n\ttype TLArrowBindingProps,\n} from './bindings/TLArrowBinding'\nexport {\n\tbindingIdValidator,\n\tcreateBindingValidator,\n\ttype TLBaseBinding,\n} from './bindings/TLBaseBinding'\nexport {\n\tcreatePresenceStateDerivation,\n\tgetDefaultUserPresence,\n\ttype TLPresenceStateInfo,\n\ttype TLPresenceUserInfo,\n} from './createPresenceStateDerivation'\nexport {\n\tcreateTLSchema,\n\tdefaultBindingSchemas,\n\tdefaultShapeSchemas,\n\ttype SchemaPropsInfo,\n\ttype TLSchema,\n} from './createTLSchema'\nexport {\n\tboxModelValidator,\n\tvecModelValidator,\n\ttype BoxModel,\n\ttype VecModel,\n} from './misc/geometry-types'\nexport { idValidator } from './misc/id-validator'\nexport {\n\tcanvasUiColorTypeValidator,\n\tTL_CANVAS_UI_COLOR_TYPES,\n\ttype TLCanvasUiColor,\n} from './misc/TLColor'\nexport { TL_CURSOR_TYPES, type TLCursor, type TLCursorType } from './misc/TLCursor'\nexport { TL_HANDLE_TYPES, type TLHandle, type TLHandleType } from './misc/TLHandle'\nexport { opacityValidator, type TLOpacityType } from './misc/TLOpacity'\nexport { richTextValidator, toRichText, type TLRichText } from './misc/TLRichText'\nexport { scribbleValidator, TL_SCRIBBLE_STATES, type TLScribble } from './misc/TLScribble'\nexport {\n\tassetMigrations,\n\tAssetRecordType,\n\tassetValidator,\n\ttype TLAsset,\n\ttype TLAssetId,\n\ttype TLAssetPartial,\n\ttype TLAssetShape,\n} from './records/TLAsset'\nexport {\n\tcreateBindingId,\n\tcreateBindingPropsMigrationIds,\n\tcreateBindingPropsMigrationSequence,\n\tisBinding,\n\tisBindingId,\n\trootBindingMigrations,\n\ttype TLBinding,\n\ttype TLBindingCreate,\n\ttype TLBindingId,\n\ttype TLBindingUpdate,\n\ttype TLDefaultBinding,\n\ttype TLGlobalBindingPropsMap,\n\ttype TLIndexedBindings,\n\ttype TLUnknownBinding,\n} from './records/TLBinding'\nexport { CameraRecordType, type TLCamera, type TLCameraId } from './records/TLCamera'\nexport {\n\tDocumentRecordType,\n\tisDocument,\n\tTLDOCUMENT_ID,\n\ttype TLDocument,\n} from './records/TLDocument'\nexport {\n\tpluckPreservingValues,\n\tTLINSTANCE_ID,\n\ttype TLInstance,\n\ttype TLInstanceId,\n} from './records/TLInstance'\nexport {\n\tisPageId,\n\tpageIdValidator,\n\tPageRecordType,\n\ttype TLPage,\n\ttype TLPageId,\n} from './records/TLPage'\nexport {\n\tInstancePageStateRecordType,\n\ttype TLInstancePageState,\n\ttype TLInstancePageStateId,\n} from './records/TLPageState'\nexport {\n\tPointerRecordType,\n\tTLPOINTER_ID,\n\ttype TLPointer,\n\ttype TLPointerId,\n} from './records/TLPointer'\nexport {\n\tInstancePresenceRecordType,\n\ttype TLInstancePresence,\n\ttype TLInstancePresenceID,\n} from './records/TLPresence'\nexport { type TLRecord } from './records/TLRecord'\nexport {\n\tcreateShapeId,\n\tcreateShapePropsMigrationIds,\n\tcreateShapePropsMigrationSequence,\n\tgetShapePropKeysByStyle,\n\tisShape,\n\tisShapeId,\n\trootShapeMigrations,\n\ttype ExtractShapeByProps,\n\ttype TLCreateShapePartial,\n\ttype TLDefaultShape,\n\ttype TLGlobalShapePropsMap,\n\ttype TLIndexedShapes,\n\ttype TLParentId,\n\ttype TLShape,\n\ttype TLShapeId,\n\ttype TLShapePartial,\n\ttype TLUnknownShape,\n} from './records/TLShape'\nexport {\n\ttype RecordProps,\n\ttype RecordPropsType,\n\ttype TLPropsMigration,\n\ttype TLPropsMigrations,\n} from './recordsWithProps'\nexport { type ShapeWithCrop, type TLShapeCrop } from './shapes/ShapeWithCrop'\nexport {\n\tArrowShapeArrowheadEndStyle,\n\tArrowShapeArrowheadStartStyle,\n\tArrowShapeKindStyle,\n\tarrowShapeMigrations,\n\tarrowShapeProps,\n\tarrowShapeVersions,\n\ttype TLArrowShape,\n\ttype TLArrowShapeArrowheadStyle,\n\ttype TLArrowShapeKind,\n\ttype TLArrowShapeProps,\n} from './shapes/TLArrowShape'\nexport {\n\tcreateShapeValidator,\n\tparentIdValidator,\n\tshapeIdValidator,\n\ttype TLBaseShape,\n} from './shapes/TLBaseShape'\nexport {\n\tbookmarkShapeMigrations,\n\tbookmarkShapeProps,\n\ttype TLBookmarkShape,\n\ttype TLBookmarkShapeProps,\n} from './shapes/TLBookmarkShape'\nexport {\n\tcompressLegacySegments,\n\tdrawShapeMigrations,\n\tdrawShapeProps,\n\ttype TLDrawShape,\n\ttype TLDrawShapeProps,\n\ttype TLDrawShapeSegment,\n} from './shapes/TLDrawShape'\nexport {\n\tembedShapeMigrations,\n\tembedShapeProps,\n\ttype TLEmbedShape,\n\ttype TLEmbedShapeProps,\n} from './shapes/TLEmbedShape'\nexport {\n\tframeShapeMigrations,\n\tframeShapeProps,\n\ttype TLFrameShape,\n\ttype TLFrameShapeProps,\n} from './shapes/TLFrameShape'\nexport {\n\tGeoShapeGeoStyle,\n\tgeoShapeMigrations,\n\tgeoShapeProps,\n\ttype TLGeoShape,\n\ttype TLGeoShapeGeoStyle,\n\ttype TLGeoShapeProps,\n} from './shapes/TLGeoShape'\nexport {\n\tgroupShapeMigrations,\n\tgroupShapeProps,\n\ttype TLGroupShape,\n\ttype TLGroupShapeProps,\n} from './shapes/TLGroupShape'\nexport {\n\thighlightShapeMigrations,\n\thighlightShapeProps,\n\ttype TLHighlightShape,\n\ttype TLHighlightShapeProps,\n} from './shapes/TLHighlightShape'\nexport {\n\tImageShapeCrop,\n\timageShapeMigrations,\n\timageShapeProps,\n\ttype TLImageShape,\n\ttype TLImageShapeProps,\n} from './shapes/TLImageShape'\nexport {\n\tlineShapeMigrations,\n\tlineShapeProps,\n\tLineShapeSplineStyle,\n\ttype TLLineShape,\n\ttype TLLineShapePoint,\n\ttype TLLineShapeProps,\n\ttype TLLineShapeSplineStyle,\n} from './shapes/TLLineShape'\nexport {\n\tnoteShapeMigrations,\n\tnoteShapeProps,\n\ttype TLNoteShape,\n\ttype TLNoteShapeProps,\n} from './shapes/TLNoteShape'\nexport {\n\ttextShapeMigrations,\n\ttextShapeProps,\n\ttype TLTextShape,\n\ttype TLTextShapeProps,\n} from './shapes/TLTextShape'\nexport {\n\tvideoShapeMigrations,\n\tvideoShapeProps,\n\ttype TLVideoShape,\n\ttype TLVideoShapeProps,\n} from './shapes/TLVideoShape'\nexport { EnumStyleProp, StyleProp, type StylePropValue } from './styles/StyleProp'\nexport {\n\tdefaultColorNames,\n\tDefaultColorStyle,\n\tDefaultColorThemePalette,\n\tDefaultLabelColorStyle,\n\tgetColorValue,\n\tgetDefaultColorTheme,\n\ttype TLDefaultColorStyle,\n\ttype TLDefaultColorTheme,\n\ttype TLDefaultColorThemeColor,\n} from './styles/TLColorStyle'\nexport { DefaultDashStyle, type TLDefaultDashStyle } from './styles/TLDashStyle'\nexport { DefaultFillStyle, type TLDefaultFillStyle } from './styles/TLFillStyle'\nexport {\n\tDefaultFontFamilies,\n\tDefaultFontStyle,\n\ttype TLDefaultFontStyle,\n} from './styles/TLFontStyle'\nexport {\n\tDefaultHorizontalAlignStyle,\n\ttype TLDefaultHorizontalAlignStyle,\n} from './styles/TLHorizontalAlignStyle'\nexport { DefaultSizeStyle, type TLDefaultSizeStyle } from './styles/TLSizeStyle'\nexport { DefaultTextAlignStyle, type TLDefaultTextAlignStyle } from './styles/TLTextAlignStyle'\nexport {\n\tDefaultVerticalAlignStyle,\n\ttype TLDefaultVerticalAlignStyle,\n} from './styles/TLVerticalAlignStyle'\nexport {\n\ttype TLAssetContext,\n\ttype TLAssetStore,\n\ttype TLSerializedStore,\n\ttype TLStore,\n\ttype TLStoreProps,\n\ttype TLStoreSchema,\n\ttype TLStoreSnapshot,\n} from './TLStore'\nexport {\n\tgetDefaultTranslationLocale,\n\tLANGUAGES,\n\ttype TLLanguage,\n} from './translations/translations'\nexport { type SetValue } from './util-types'\n\nregisterTldrawLibraryVersion(\n\t(globalThis as any).TLDRAW_LIBRARY_NAME,\n\t(globalThis as any).TLDRAW_LIBRARY_VERSION,\n\t(globalThis as any).TLDRAW_LIBRARY_MODULES\n)\n\nexport { b64Vecs } from './misc/b64Vecs'\n"],
5
- "mappings": "AAgCA,SAAS,oCAAoC;AAC7C,SAAS,kBAAkB,4BAA8C;AAIzE;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAGM;AACP;AAAA,EACC;AAAA,EACA;AAAA,OAEM;AACP;AAAA,EACC;AAAA,EACA;AAAA,OAGM;AACP;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,OAGM;AACP;AAAA,EACC;AAAA,EACA;AAAA,OAGM;AACP,SAAS,mBAAmB;AAC5B;AAAA,EACC;AAAA,EACA;AAAA,OAEM;AACP,SAAS,uBAAyD;AAClE,SAAS,uBAAyD;AAClE,SAAS,wBAA4C;AACrD,SAAS,mBAAmB,kBAAmC;AAC/D,SAAS,mBAAmB,0BAA2C;AACvE;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,OAKM;AACP;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OASM;AACP,SAAS,wBAAwD;AACjE;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,OAEM;AACP;AAAA,EACC;AAAA,EACA;AAAA,OAGM;AACP;AAAA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AACF;AAEA,SAAS,eAAe;",
4
+ "sourcesContent": ["/**\n * @fileoverview\n * Main entry point for the tldraw schema package. Exports the complete type system,\n * data structures, validation, and migrations for tldraw's persisted data.\n *\n * This package provides:\n * - Schema creation utilities (createTLSchema, defaultShapeSchemas, defaultBindingSchemas)\n * - All built-in shape types (TLGeoShape, TLTextShape, TLArrowShape, etc.)\n * - Asset management types and validators (TLImageAsset, TLVideoAsset, TLBookmarkAsset)\n * - Binding system for shape relationships (TLArrowBinding)\n * - Store integration types (TLStore, TLStoreProps, TLStoreSnapshot)\n * - Style properties for consistent styling (DefaultColorStyle, DefaultSizeStyle, etc.)\n * - Validation utilities and type guards\n * - Migration systems for schema evolution\n * - Geometry and utility types\n *\n * @example\n * ```ts\n * import { createTLSchema, defaultShapeSchemas, TLStore } from '@tldraw/tlschema'\n *\n * // Create a schema with default shapes\n * const schema = createTLSchema({\n * shapes: defaultShapeSchemas\n * })\n *\n * // Use with a store\n * const store = new Store({ schema })\n * ```\n *\n * @public\n */\n\nimport { registerTldrawLibraryVersion } from '@tldraw/utils'\nexport { assetIdValidator, createAssetValidator, type TLBaseAsset } from './assets/TLBaseAsset'\nexport { type TLBookmarkAsset } from './assets/TLBookmarkAsset'\nexport { type TLImageAsset } from './assets/TLImageAsset'\nexport { type TLVideoAsset } from './assets/TLVideoAsset'\nexport {\n\tarrowBindingMigrations,\n\tarrowBindingProps,\n\tarrowBindingVersions,\n\tElbowArrowSnap,\n\ttype TLArrowBinding,\n\ttype TLArrowBindingProps,\n} from './bindings/TLArrowBinding'\nexport {\n\tbindingIdValidator,\n\tcreateBindingValidator,\n\ttype TLBaseBinding,\n} from './bindings/TLBaseBinding'\nexport {\n\tcreatePresenceStateDerivation,\n\tgetDefaultUserPresence,\n\ttype TLPresenceStateInfo,\n\ttype TLPresenceUserInfo,\n} from './createPresenceStateDerivation'\nexport {\n\tcreateTLSchema,\n\tdefaultBindingSchemas,\n\tdefaultShapeSchemas,\n\ttype SchemaPropsInfo,\n\ttype TLSchema,\n} from './createTLSchema'\nexport {\n\tboxModelValidator,\n\tvecModelValidator,\n\ttype BoxModel,\n\ttype VecModel,\n} from './misc/geometry-types'\nexport { idValidator } from './misc/id-validator'\nexport {\n\tcanvasUiColorTypeValidator,\n\tTL_CANVAS_UI_COLOR_TYPES,\n\ttype TLCanvasUiColor,\n} from './misc/TLColor'\nexport { TL_CURSOR_TYPES, type TLCursor, type TLCursorType } from './misc/TLCursor'\nexport { TL_HANDLE_TYPES, type TLHandle, type TLHandleType } from './misc/TLHandle'\nexport { opacityValidator, type TLOpacityType } from './misc/TLOpacity'\nexport { richTextValidator, toRichText, type TLRichText } from './misc/TLRichText'\nexport { scribbleValidator, TL_SCRIBBLE_STATES, type TLScribble } from './misc/TLScribble'\nexport {\n\tassetMigrations,\n\tAssetRecordType,\n\tassetValidator,\n\ttype TLAsset,\n\ttype TLAssetId,\n\ttype TLAssetPartial,\n\ttype TLAssetShape,\n} from './records/TLAsset'\nexport {\n\tcreateBindingId,\n\tcreateBindingPropsMigrationIds,\n\tcreateBindingPropsMigrationSequence,\n\tisBinding,\n\tisBindingId,\n\trootBindingMigrations,\n\ttype TLBinding,\n\ttype TLBindingCreate,\n\ttype TLBindingId,\n\ttype TLBindingUpdate,\n\ttype TLDefaultBinding,\n\ttype TLGlobalBindingPropsMap,\n\ttype TLIndexedBindings,\n\ttype TLUnknownBinding,\n} from './records/TLBinding'\nexport { CameraRecordType, type TLCamera, type TLCameraId } from './records/TLCamera'\nexport {\n\tcreateCustomRecordId,\n\tcreateCustomRecordMigrationIds,\n\tcreateCustomRecordMigrationSequence,\n\tisCustomRecord,\n\tisCustomRecordId,\n\ttype CustomRecordInfo,\n} from './records/TLCustomRecord'\nexport {\n\tDocumentRecordType,\n\tisDocument,\n\tTLDOCUMENT_ID,\n\ttype TLDocument,\n} from './records/TLDocument'\nexport {\n\tpluckPreservingValues,\n\tTLINSTANCE_ID,\n\ttype TLInstance,\n\ttype TLInstanceId,\n} from './records/TLInstance'\nexport {\n\tisPageId,\n\tpageIdValidator,\n\tPageRecordType,\n\ttype TLPage,\n\ttype TLPageId,\n} from './records/TLPage'\nexport {\n\tInstancePageStateRecordType,\n\ttype TLInstancePageState,\n\ttype TLInstancePageStateId,\n} from './records/TLPageState'\nexport {\n\tPointerRecordType,\n\tTLPOINTER_ID,\n\ttype TLPointer,\n\ttype TLPointerId,\n} from './records/TLPointer'\nexport {\n\tInstancePresenceRecordType,\n\ttype TLInstancePresence,\n\ttype TLInstancePresenceID,\n} from './records/TLPresence'\nexport {\n\ttype TLCustomRecord,\n\ttype TLDefaultRecord,\n\ttype TLGlobalRecordPropsMap,\n\ttype TLIndexedRecords,\n\ttype TLRecord,\n} from './records/TLRecord'\nexport {\n\tcreateShapeId,\n\tcreateShapePropsMigrationIds,\n\tcreateShapePropsMigrationSequence,\n\tgetShapePropKeysByStyle,\n\tisShape,\n\tisShapeId,\n\trootShapeMigrations,\n\ttype ExtractShapeByProps,\n\ttype TLCreateShapePartial,\n\ttype TLDefaultShape,\n\ttype TLGlobalShapePropsMap,\n\ttype TLIndexedShapes,\n\ttype TLParentId,\n\ttype TLShape,\n\ttype TLShapeId,\n\ttype TLShapePartial,\n\ttype TLUnknownShape,\n} from './records/TLShape'\nexport {\n\ttype RecordProps,\n\ttype RecordPropsType,\n\ttype TLPropsMigration,\n\ttype TLPropsMigrations,\n} from './recordsWithProps'\nexport { type ShapeWithCrop, type TLShapeCrop } from './shapes/ShapeWithCrop'\nexport {\n\tArrowShapeArrowheadEndStyle,\n\tArrowShapeArrowheadStartStyle,\n\tArrowShapeKindStyle,\n\tarrowShapeMigrations,\n\tarrowShapeProps,\n\tarrowShapeVersions,\n\ttype TLArrowShape,\n\ttype TLArrowShapeArrowheadStyle,\n\ttype TLArrowShapeKind,\n\ttype TLArrowShapeProps,\n} from './shapes/TLArrowShape'\nexport {\n\tcreateShapeValidator,\n\tparentIdValidator,\n\tshapeIdValidator,\n\ttype TLBaseShape,\n} from './shapes/TLBaseShape'\nexport {\n\tbookmarkShapeMigrations,\n\tbookmarkShapeProps,\n\ttype TLBookmarkShape,\n\ttype TLBookmarkShapeProps,\n} from './shapes/TLBookmarkShape'\nexport {\n\tcompressLegacySegments,\n\tdrawShapeMigrations,\n\tdrawShapeProps,\n\ttype TLDrawShape,\n\ttype TLDrawShapeProps,\n\ttype TLDrawShapeSegment,\n} from './shapes/TLDrawShape'\nexport {\n\tembedShapeMigrations,\n\tembedShapeProps,\n\ttype TLEmbedShape,\n\ttype TLEmbedShapeProps,\n} from './shapes/TLEmbedShape'\nexport {\n\tframeShapeMigrations,\n\tframeShapeProps,\n\ttype TLFrameShape,\n\ttype TLFrameShapeProps,\n} from './shapes/TLFrameShape'\nexport {\n\tGeoShapeGeoStyle,\n\tgeoShapeMigrations,\n\tgeoShapeProps,\n\ttype TLGeoShape,\n\ttype TLGeoShapeGeoStyle,\n\ttype TLGeoShapeProps,\n} from './shapes/TLGeoShape'\nexport {\n\tgroupShapeMigrations,\n\tgroupShapeProps,\n\ttype TLGroupShape,\n\ttype TLGroupShapeProps,\n} from './shapes/TLGroupShape'\nexport {\n\thighlightShapeMigrations,\n\thighlightShapeProps,\n\ttype TLHighlightShape,\n\ttype TLHighlightShapeProps,\n} from './shapes/TLHighlightShape'\nexport {\n\tImageShapeCrop,\n\timageShapeMigrations,\n\timageShapeProps,\n\ttype TLImageShape,\n\ttype TLImageShapeProps,\n} from './shapes/TLImageShape'\nexport {\n\tlineShapeMigrations,\n\tlineShapeProps,\n\tLineShapeSplineStyle,\n\ttype TLLineShape,\n\ttype TLLineShapePoint,\n\ttype TLLineShapeProps,\n\ttype TLLineShapeSplineStyle,\n} from './shapes/TLLineShape'\nexport {\n\tnoteShapeMigrations,\n\tnoteShapeProps,\n\ttype TLNoteShape,\n\ttype TLNoteShapeProps,\n} from './shapes/TLNoteShape'\nexport {\n\ttextShapeMigrations,\n\ttextShapeProps,\n\ttype TLTextShape,\n\ttype TLTextShapeProps,\n} from './shapes/TLTextShape'\nexport {\n\tvideoShapeMigrations,\n\tvideoShapeProps,\n\ttype TLVideoShape,\n\ttype TLVideoShapeProps,\n} from './shapes/TLVideoShape'\nexport { EnumStyleProp, StyleProp, type StylePropValue } from './styles/StyleProp'\nexport {\n\tdefaultColorNames,\n\tDefaultColorStyle,\n\tDefaultColorThemePalette,\n\tDefaultLabelColorStyle,\n\tgetColorValue,\n\tgetDefaultColorTheme,\n\ttype TLDefaultColorStyle,\n\ttype TLDefaultColorTheme,\n\ttype TLDefaultColorThemeColor,\n} from './styles/TLColorStyle'\nexport { DefaultDashStyle, type TLDefaultDashStyle } from './styles/TLDashStyle'\nexport { DefaultFillStyle, type TLDefaultFillStyle } from './styles/TLFillStyle'\nexport {\n\tDefaultFontFamilies,\n\tDefaultFontStyle,\n\ttype TLDefaultFontStyle,\n} from './styles/TLFontStyle'\nexport {\n\tDefaultHorizontalAlignStyle,\n\ttype TLDefaultHorizontalAlignStyle,\n} from './styles/TLHorizontalAlignStyle'\nexport { DefaultSizeStyle, type TLDefaultSizeStyle } from './styles/TLSizeStyle'\nexport { DefaultTextAlignStyle, type TLDefaultTextAlignStyle } from './styles/TLTextAlignStyle'\nexport {\n\tDefaultVerticalAlignStyle,\n\ttype TLDefaultVerticalAlignStyle,\n} from './styles/TLVerticalAlignStyle'\nexport {\n\ttype TLAssetContext,\n\ttype TLAssetStore,\n\ttype TLSerializedStore,\n\ttype TLStore,\n\ttype TLStoreProps,\n\ttype TLStoreSchema,\n\ttype TLStoreSnapshot,\n} from './TLStore'\nexport {\n\tgetDefaultTranslationLocale,\n\tLANGUAGES,\n\ttype TLLanguage,\n} from './translations/translations'\nexport { type SetValue } from './util-types'\n\nregisterTldrawLibraryVersion(\n\t(globalThis as any).TLDRAW_LIBRARY_NAME,\n\t(globalThis as any).TLDRAW_LIBRARY_VERSION,\n\t(globalThis as any).TLDRAW_LIBRARY_MODULES\n)\n\nexport { b64Vecs } from './misc/b64Vecs'\n"],
5
+ "mappings": "AAgCA,SAAS,oCAA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A;AAAA,OAGM;AACP;AAAA,EACC;AAAA,EACA;AAAA,OAGM;AACP;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,OAIM;AACP;AAAA,EACC;AAAA,EACA;AAAA,OAGM;AACP;AAAA,EACC;AAAA,EACA;AAAA,OAGM;AACP;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,OAGM;AACP;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,OAKM;AACP;AAAA,EACC;AAAA,EACA;AAAA,OAGM;AACP;AAAA,EACC;AAAA,EACA;AAAA,OAGM;AACP;AAAA,EACC;AAAA,EACA;AAAA,OAGM;AACP,SAAS,eAAe,iBAAsC;AAC9D;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAIM;AACP,SAAS,wBAAiD;AAC1D,SAAS,wBAAiD;AAC1D;AAAA,EACC;AAAA,EACA;AAAA,OAEM;AACP;AAAA,EACC;AAAA,OAEM;AACP,SAAS,wBAAiD;AAC1D,SAAS,6BAA2D;AACpE;AAAA,EACC;AAAA,OAEM;AAUP;AAAA,EACC;AAAA,EACA;AAAA,OAEM;AAGP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AACF;AAEA,SAAS,eAAe;",
6
6
  "names": []
7
7
  }
@@ -0,0 +1,85 @@
1
+ import {
2
+ createMigrationSequence,
3
+ createRecordType
4
+ } from "@tldraw/store";
5
+ import { assert, mapObjectMapValues, uniqueId } from "@tldraw/utils";
6
+ function createCustomRecordType(typeName, config) {
7
+ return createRecordType(typeName, {
8
+ scope: config.scope,
9
+ validator: config.validator
10
+ }).withDefaultProperties(config.createDefaultProperties ?? (() => ({})));
11
+ }
12
+ function processCustomRecordMigrations(records) {
13
+ const result = [];
14
+ for (const [typeName, config] of Object.entries(records)) {
15
+ const sequenceId = `com.tldraw.${typeName}`;
16
+ const { migrations } = config;
17
+ if (!migrations) {
18
+ result.push(
19
+ createMigrationSequence({
20
+ sequenceId,
21
+ retroactive: true,
22
+ sequence: []
23
+ })
24
+ );
25
+ } else if ("sequenceId" in migrations) {
26
+ assert(
27
+ sequenceId === migrations.sequenceId,
28
+ `sequenceId mismatch for ${typeName} custom record migrations. Expected '${sequenceId}', got '${migrations.sequenceId}'`
29
+ );
30
+ result.push(migrations);
31
+ } else if ("sequence" in migrations) {
32
+ result.push(
33
+ createMigrationSequence({
34
+ sequenceId,
35
+ retroactive: true,
36
+ sequence: migrations.sequence.map((m) => {
37
+ if (!("id" in m)) return m;
38
+ return {
39
+ id: m.id,
40
+ dependsOn: m.dependsOn,
41
+ scope: "record",
42
+ filter: (r) => r.typeName === typeName,
43
+ up: (record) => {
44
+ const result2 = m.up(record);
45
+ if (result2) return result2;
46
+ },
47
+ down: typeof m.down === "function" ? (record) => {
48
+ const result2 = m.down(record);
49
+ if (result2) return result2;
50
+ } : void 0
51
+ };
52
+ })
53
+ })
54
+ );
55
+ }
56
+ }
57
+ return result;
58
+ }
59
+ function createCustomRecordMigrationIds(recordType, ids) {
60
+ return mapObjectMapValues(ids, (_k, v) => `com.tldraw.${recordType}/${v}`);
61
+ }
62
+ function createCustomRecordMigrationSequence(migrations) {
63
+ return migrations;
64
+ }
65
+ function createCustomRecordId(typeName, id) {
66
+ return `${typeName}:${id ?? uniqueId()}`;
67
+ }
68
+ function isCustomRecordId(typeName, id) {
69
+ if (!id) return false;
70
+ return id.startsWith(`${typeName}:`);
71
+ }
72
+ function isCustomRecord(typeName, record) {
73
+ if (!record) return false;
74
+ return record.typeName === typeName;
75
+ }
76
+ export {
77
+ createCustomRecordId,
78
+ createCustomRecordMigrationIds,
79
+ createCustomRecordMigrationSequence,
80
+ createCustomRecordType,
81
+ isCustomRecord,
82
+ isCustomRecordId,
83
+ processCustomRecordMigrations
84
+ };
85
+ //# sourceMappingURL=TLCustomRecord.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/records/TLCustomRecord.ts"],
4
+ "sourcesContent": ["import {\n\tMigrationSequence,\n\tRecordId,\n\tRecordScope,\n\tUnknownRecord,\n\tcreateMigrationSequence,\n\tcreateRecordType,\n} from '@tldraw/store'\nimport { assert, mapObjectMapValues, uniqueId } from '@tldraw/utils'\nimport { T } from '@tldraw/validate'\nimport { TLPropsMigrations } from '../recordsWithProps'\n\n/**\n * Configuration for a custom record type in the schema.\n *\n * Custom record types allow you to add entirely new data types to the tldraw store\n * that don't fit into the existing shape, binding, or asset categories. This is useful\n * for storing domain-specific data like comments, annotations, or application state\n * that needs to participate in persistence and synchronization.\n *\n * @example\n * ```ts\n * const commentRecordConfig: CustomRecordInfo = {\n * scope: 'document',\n * validator: T.object({\n * id: T.string,\n * typeName: T.literal('comment'),\n * text: T.string,\n * shapeId: T.string,\n * authorId: T.string,\n * createdAt: T.number,\n * }),\n * migrations: createRecordMigrationSequence({\n * sequenceId: 'com.myapp.comment',\n * recordType: 'comment',\n * sequence: [],\n * }),\n * }\n * ```\n *\n * @public\n */\nexport interface CustomRecordInfo {\n\t/**\n\t * The scope determines how records of this type are persisted and synchronized:\n\t * - **document**: Persisted and synced across all clients\n\t * - **session**: Local to current session, not synced\n\t * - **presence**: Ephemeral presence data, may be synced but not persisted\n\t */\n\tscope: RecordScope\n\n\t/**\n\t * Validator for the complete record structure.\n\t *\n\t * Should validate the entire record including `id` and `typeName` fields.\n\t * Use validators like T.object, T.string, etc.\n\t */\n\tvalidator: T.Validatable<any>\n\n\t/**\n\t * Optional migration sequence for handling schema evolution over time.\n\t *\n\t * Can be a full MigrationSequence or a simplified TLPropsMigrations format.\n\t * If not provided, an empty migration sequence will be created automatically.\n\t */\n\tmigrations?: MigrationSequence | TLPropsMigrations\n\n\t/**\n\t * Optional factory function that returns default property values for new records.\n\t *\n\t * Called when creating new records to provide initial values for any properties\n\t * not explicitly provided during creation.\n\t */\n\t// eslint-disable-next-line @typescript-eslint/method-signature-style\n\tcreateDefaultProperties?: () => Record<string, unknown>\n}\n\n/**\n * Creates a RecordType for a custom record based on its configuration.\n *\n * @param typeName - The unique type name for this record type\n * @param config - Configuration for the custom record type\n * @returns A RecordType instance that can be used to create and manage records\n *\n * @internal\n */\nexport function createCustomRecordType(typeName: string, config: CustomRecordInfo) {\n\treturn createRecordType<UnknownRecord>(typeName, {\n\t\tscope: config.scope,\n\t\tvalidator: config.validator,\n\t}).withDefaultProperties(config.createDefaultProperties ?? (() => ({})))\n}\n\n/**\n * Processes migrations for custom record types.\n *\n * Converts the migration configuration from CustomRecordInfo into proper\n * MigrationSequence objects that can be used by the store system.\n *\n * @param records - Record of type names to their configuration\n * @returns Array of migration sequences for the custom record types\n *\n * @internal\n */\nexport function processCustomRecordMigrations(\n\trecords: Record<string, CustomRecordInfo>\n): MigrationSequence[] {\n\tconst result: MigrationSequence[] = []\n\n\tfor (const [typeName, config] of Object.entries(records)) {\n\t\tconst sequenceId = `com.tldraw.${typeName}`\n\t\tconst { migrations } = config\n\n\t\tif (!migrations) {\n\t\t\t// Provide empty migration sequence to allow for future migrations\n\t\t\tresult.push(\n\t\t\t\tcreateMigrationSequence({\n\t\t\t\t\tsequenceId,\n\t\t\t\t\tretroactive: true,\n\t\t\t\t\tsequence: [],\n\t\t\t\t})\n\t\t\t)\n\t\t} else if ('sequenceId' in migrations) {\n\t\t\t// Full MigrationSequence provided\n\t\t\tassert(\n\t\t\t\tsequenceId === migrations.sequenceId,\n\t\t\t\t`sequenceId mismatch for ${typeName} custom record migrations. Expected '${sequenceId}', got '${migrations.sequenceId}'`\n\t\t\t)\n\t\t\tresult.push(migrations)\n\t\t} else if ('sequence' in migrations) {\n\t\t\t// TLPropsMigrations format - convert to full MigrationSequence\n\t\t\tresult.push(\n\t\t\t\tcreateMigrationSequence({\n\t\t\t\t\tsequenceId,\n\t\t\t\t\tretroactive: true,\n\t\t\t\t\tsequence: migrations.sequence.map((m) => {\n\t\t\t\t\t\tif (!('id' in m)) return m\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tid: m.id,\n\t\t\t\t\t\t\tdependsOn: m.dependsOn,\n\t\t\t\t\t\t\tscope: 'record' as const,\n\t\t\t\t\t\t\tfilter: (r: UnknownRecord) => r.typeName === typeName,\n\t\t\t\t\t\t\tup: (record: any) => {\n\t\t\t\t\t\t\t\tconst result = m.up(record)\n\t\t\t\t\t\t\t\tif (result) return result\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tdown:\n\t\t\t\t\t\t\t\ttypeof m.down === 'function'\n\t\t\t\t\t\t\t\t\t? (record: any) => {\n\t\t\t\t\t\t\t\t\t\t\tconst result = (m.down as (r: any) => any)(record)\n\t\t\t\t\t\t\t\t\t\t\tif (result) return result\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t: undefined,\n\t\t\t\t\t\t}\n\t\t\t\t\t}),\n\t\t\t\t})\n\t\t\t)\n\t\t}\n\t}\n\n\treturn result\n}\n\n/**\n * Creates properly formatted migration IDs for custom record migrations.\n *\n * Generates standardized migration IDs following the convention:\n * `com.tldraw.{recordType}/{version}`\n *\n * @param recordType - The type name of the custom record\n * @param ids - Record mapping migration names to version numbers\n * @returns Record with the same keys but formatted migration ID values\n *\n * @example\n * ```ts\n * const commentVersions = createCustomRecordMigrationIds('comment', {\n * AddAuthorId: 1,\n * AddCreatedAt: 2,\n * RefactorReactions: 3\n * })\n * // Result: {\n * // AddAuthorId: 'com.tldraw.comment/1',\n * // AddCreatedAt: 'com.tldraw.comment/2',\n * // RefactorReactions: 'com.tldraw.comment/3'\n * // }\n * ```\n *\n * @public\n */\nexport function createCustomRecordMigrationIds<\n\tconst S extends string,\n\tconst T extends Record<string, number>,\n>(recordType: S, ids: T): { [k in keyof T]: `com.tldraw.${S}/${T[k]}` } {\n\treturn mapObjectMapValues(ids, (_k, v) => `com.tldraw.${recordType}/${v}`) as any\n}\n\n/**\n * Creates a migration sequence for custom record types.\n *\n * This is a pass-through function that maintains the same structure as the input.\n * It's used for consistency and to provide a clear API for defining custom record migrations.\n *\n * @param migrations - The migration sequence to create\n * @returns The same migration sequence (pass-through)\n *\n * @example\n * ```ts\n * const commentMigrations = createCustomRecordMigrationSequence({\n * sequence: [\n * {\n * id: 'com.myapp.comment/1',\n * up: (record) => ({ ...record, authorId: record.authorId ?? 'unknown' }),\n * down: ({ authorId, ...record }) => record\n * }\n * ]\n * })\n * ```\n *\n * @public\n */\nexport function createCustomRecordMigrationSequence(\n\tmigrations: TLPropsMigrations\n): TLPropsMigrations {\n\treturn migrations\n}\n\n/**\n * Creates a unique ID for a custom record type.\n *\n * @param typeName - The type name of the custom record\n * @param id - Optional custom ID suffix. If not provided, a unique ID will be generated\n * @returns A properly formatted record ID\n *\n * @example\n * ```ts\n * // Create with auto-generated ID\n * const commentId = createCustomRecordId('comment') // 'comment:abc123'\n *\n * // Create with custom ID\n * const customId = createCustomRecordId('comment', 'my-comment') // 'comment:my-comment'\n * ```\n *\n * @public\n */\nexport function createCustomRecordId<T extends string>(\n\ttypeName: T,\n\tid?: string\n): RecordId<UnknownRecord> & `${T}:${string}` {\n\treturn `${typeName}:${id ?? uniqueId()}` as RecordId<UnknownRecord> & `${T}:${string}`\n}\n\n/**\n * Type guard to check if a string is a valid ID for a specific custom record type.\n *\n * @param typeName - The type name to check against\n * @param id - The string to check\n * @returns True if the string is a valid ID for the specified record type\n *\n * @example\n * ```ts\n * const id = 'comment:abc123'\n * if (isCustomRecordId('comment', id)) {\n * // id is now typed as a comment record ID\n * const comment = store.get(id)\n * }\n * ```\n *\n * @public\n */\nexport function isCustomRecordId(typeName: string, id?: string): boolean {\n\tif (!id) return false\n\treturn id.startsWith(`${typeName}:`)\n}\n\n/**\n * Type guard to check if a record is of a specific custom type.\n *\n * @param typeName - The type name to check against\n * @param record - The record to check\n * @returns True if the record is of the specified type\n *\n * @example\n * ```ts\n * function handleRecord(record: TLRecord) {\n * if (isCustomRecord('comment', record)) {\n * // Handle comment record\n * console.log(`Comment: ${record.text}`)\n * }\n * }\n * ```\n *\n * @public\n */\nexport function isCustomRecord(typeName: string, record?: UnknownR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,CAAC,WAAgB;AACjB,sBAAMA,UAAU,EAAE,KAAyB,MAAM;AACjD,oBAAIA,QAAQ,QAAOA;AAAA,cACpB,IACC;AAAA,YACL;AAAA,UACD,CAAC;AAAA,QACF,CAAC;AAAA,MACF;AAAA,IACD;AAAA,EACD;AAEA,SAAO;AACR;AA4BO,SAAS,+BAGd,YAAe,KAAuD;AACvE,SAAO,mBAAmB,KAAK,CAAC,IAAI,MAAM,cAAc,UAAU,IAAI,CAAC,EAAE;AAC1E;AA0BO,SAAS,oCACf,YACoB;AACpB,SAAO;AACR;AAoBO,SAAS,qBACf,UACA,IAC6C;AAC7C,SAAO,GAAG,QAAQ,IAAI,MAAM,SAAS,CAAC;AACvC;AAoBO,SAAS,iBAAiB,UAAkB,IAAsB;AACxE,MAAI,CAAC,GAAI,QAAO;AAChB,SAAO,GAAG,WAAW,GAAG,QAAQ,GAAG;AACpC;AAqBO,SAAS,eAAe,UAAkB,QAAiC;AACjF,MAAI,CAAC,OAAQ,QAAO;AACpB,SAAO,OAAO,aAAa;AAC5B;",
6
+ "names": ["result"]
7
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tldraw/tlschema",
3
3
  "description": "tldraw infinite canvas SDK (schema).",
4
- "version": "4.5.2",
4
+ "version": "4.6.0-canary.4ec045c286e1",
5
5
  "author": {
6
6
  "name": "tldraw Inc.",
7
7
  "email": "hello@tldraw.com"
@@ -50,10 +50,10 @@
50
50
  "vitest": "^3.2.4"
51
51
  },
52
52
  "dependencies": {
53
- "@tldraw/state": "4.5.2",
54
- "@tldraw/store": "4.5.2",
55
- "@tldraw/utils": "4.5.2",
56
- "@tldraw/validate": "4.5.2"
53
+ "@tldraw/state": "4.6.0-canary.4ec045c286e1",
54
+ "@tldraw/store": "4.6.0-canary.4ec045c286e1",
55
+ "@tldraw/utils": "4.6.0-canary.4ec045c286e1",
56
+ "@tldraw/validate": "4.6.0-canary.4ec045c286e1"
57
57
  },
58
58
  "peerDependencies": {
59
59
  "react": "^18.2.0 || ^19.2.1",