1 import { BaseProperty } from "./base"
2 import { PrimaryKeyModifier } from "./primary-key"
3
4 /**
5 * The AutoIncrementProperty is used to define a serial
6 * property
7 */
8 export class AutoIncrementProperty extends BaseProperty<number> {
9 protected dataType: {
10 name: "serial"
11 options: {
12 searchable?: boolean
13 primaryKey?: boolean
14 }
15 }
16
17 /**
18 * This method indicates that the property is the data model's primary key.
19 *
20 * @example
21 * import { model } from "@medusajs/framework/utils"
22 *
23 * const Product = model.define("Product", {
24 * id: model.autoincrement().primaryKey(),
25 * // ...
26 * })
27 *
28 * export default Product
29 *
30 * @customNamespace Property Configuration Methods
31 */
32 primaryKey() {
33 return new PrimaryKeyModifier<number, AutoIncrementProperty>(this)
34 }
35
36 /**
37 * This method indicates that a serial property is searchable.
38 *
39 * @example
40 * import { model } from "@medusajs/framework/utils"
41 *
42 * const MyCustom = model.define("my_custom", {
43 * name: model.autoincrement().searchable(),
44 * // ...
45 * })
46 *
47 * export default MyCustom
48 *
49 * @customNamespace Property Configuration Methods
50 */
51 searchable() {
52 this.dataType.options.searchable = true
53
54 return this
55 }
56
57 constructor(options?: { primaryKey?: boolean }) {
58 super()
59
60 this.dataType = {
61 name: "serial",
62 options: { ...options },
63 }
64 }
65 }