1 # TSDoc: Data Models
2
3 Data model files live under `packages/modules/*/src/models/`. They define DML (Data Model Language) entities using `model.define(...)`.
4
5 ## Rules
6
7 - Document the model-level `const` with a 1-sentence description of the entity
8 - Document each property with a brief description
9 - Use `@since <version>` (from the prompt) on properties or models that are **new in the commit diff**
10 - Use `@example` for non-obvious string formats (e.g. locale codes, currency codes)
11 - Do NOT document `id` if it is the primary key — this is implied by convention
12 - Relationship properties (`.belongsTo`, `.hasMany`, `.manyToMany`) use: "The associated [related model]."
13
14 ## Model-Level Description
15
16 ```typescript
17 // ✅ correct
18 /**
19 * A locale supported by a store.
20 */
21 const StoreLocale = model.define("StoreLocale", {
22 ```
23
24 ```typescript
25 // ✅ also fine — brief phrase
26 /**
27 * A product variant's image.
28 */
29 const ProductVariantProductImage = model.define("ProductVariantProductImage", {
30 ```
31
32 ## Property Descriptions
33
34 ```typescript
35 const ProductVariant = model.define("ProductVariant", {
36 // id: omit — it's the primary key
37
38 /**
39 * The variant's stock keeping unit.
40 */
41 sku: model.text().nullable(),
42
43 /**
44 * The variant's display name.
45 */
46 title: model.text(),
47
48 /**
49 * The variant's position in the product's variants list.
50 */
51 variant_rank: model.number().default(0),
52
53 /**
54 * Whether inventory is tracked for this variant.
55 */
56 manage_inventory: model.boolean().default(true),
57
58 /**
59 * The associated product.
60 */
61 product: model.belongsTo(() => Product, {
62 mappedBy: "variants",
63 }),
64 })
65 ```
66
67 ## @since Tag — New Properties
68
69 Add `@since <version>` only on properties that are **new in this commit's diff** (appear in added lines only):
70
71 ```typescript
72 const ProductVariant = model.define("ProductVariant", {
73 // ... existing properties (no @since)
74
75 /**
76 * The variant's thumbnail image URL.
77 * @since 2.14.0
78 */
79 thumbnail: model.text().nullable(),
80
81 /**
82 * The variant's images.
83 * @since 2.14.0
84 */
85 images: model.manyToMany(() => ProductImage, {
86 mappedBy: "variants",
87 pivotEntity: () => ProductVariantProductImage,
88 }),
89 })
90 ```
91
92 When the entire model is new in the diff, add `@since` at the model level:
93
94 ```typescript
95 /**
96 * A locale supported by a store.
97 * @since 2.14.0
98 */
99 const StoreLocale = model.define("StoreLocale", {
100 /**
101 * The BCP 47 language tag code of the locale.
102 * @example "en-US"
103 */
104 locale_code: model.text().searchable(),
105
106 /**
107 * The associated store.
108 */
109 store: model.belongsTo(() => Store, { mappedBy: "supported_locales" }).nullable(),
110 })
111 ```
112
113 ## @example for Non-Obvious Values
114
115 Use `@example` when the expected value format isn't obvious from the field name:
116
117 ```typescript
118 /**
119 * The BCP 47 language tag code of the locale.
120 * @example "en-US"
121 */
122 locale_code: model.text(),
123
124 /**
125 * The ISO 4217 currency code.
126 * @example "usd"
127 */
128 currency_code: model.text(),
129
130 /**
131 * The IANA timezone identifier.
132 * @example "America/New_York"
133 */
134 timezone: model.text().nullable(),
135 ```
136
137 ## Relationship Properties
138
139 ```typescript
140 /**
141 * The associated store.
142 */
143 store: model.belongsTo(() => Store, { mappedBy: "supported_locales" }),
144
145 /**
146 * The product's variants.
147 */
148 variants: model.hasMany(() => ProductVariant, { mappedBy: "product" }),
149
150 /**
151 * The variant's images.
152 */
153 images: model.manyToMany(() => ProductImage, { mappedBy: "variants" }),
154 ```
155
156 ## What NOT to Document
157
158 ```typescript
159 // ❌ Don't document id (primary key — always implied)
160 id: model.id({ prefix: "pv" }).primaryKey(),
161
162 // ❌ Don't add @since to properties that existed before this commit
163 sku: model.text(),
164 ```