|
1
|
import { BaseProperty } from "./base" |
|
2
|
import { PrimaryKeyModifier } from "./primary-key" |
|
3
|
|
|
4
|
/** |
|
5
|
* The TextProperty is used to define a textual property |
|
6
|
*/ |
|
7
|
export class TextProperty extends BaseProperty<string> { |
|
8
|
protected dataType: { |
|
9
|
name: "text" |
|
10
|
options: { |
|
11
|
prefix?: string |
|
12
|
searchable: boolean |
|
13
|
translatable?: boolean |
|
14
|
} |
|
15
|
} = { |
|
16
|
name: "text", |
|
17
|
options: { |
|
18
|
searchable: false, |
|
19
|
}, |
|
20
|
} |
|
21
|
|
|
22
|
/** |
|
23
|
* This method indicates that the property is the data model's primary key. |
|
24
|
* |
|
25
|
* @example |
|
26
|
* import { model } from "@medusajs/framework/utils" |
|
27
|
* |
|
28
|
* const Product = model.define("Product", { |
|
29
|
* code: model.text().primaryKey(), |
|
30
|
* // ... |
|
31
|
* }) |
|
32
|
* |
|
33
|
* export default Product |
|
34
|
* |
|
35
|
* @customNamespace Property Configuration Methods |
|
36
|
*/ |
|
37
|
primaryKey() { |
|
38
|
return new PrimaryKeyModifier<string, TextProperty>(this) |
|
39
|
} |
|
40
|
|
|
41
|
/** |
|
42
|
* This method indicates that a text property is searchable. |
|
43
|
* |
|
44
|
* @example |
|
45
|
* import { model } from "@medusajs/framework/utils" |
|
46
|
* |
|
47
|
* const MyCustom = model.define("my_custom", { |
|
48
|
* name: model.text().searchable(), |
|
49
|
* // ... |
|
50
|
* }) |
|
51
|
* |
|
52
|
* export default MyCustom |
|
53
|
* |
|
54
|
* @customNamespace Property Configuration Methods |
|
55
|
*/ |
|
56
|
searchable() { |
|
57
|
this.dataType.options.searchable = true |
|
58
|
|
|
59
|
return this |
|
60
|
} |
|
61
|
|
|
62
|
/** |
|
63
|
* This method indicates that a text property is translatable. |
|
64
|
* Translatable properties can have different values per locale. |
|
65
|
* See [Translate Custom Data Models](https://docs.medusajs.com/resources/commerce-modules/translation/custom-data-models) for more information. |
|
66
|
* |
|
67
|
* @example |
|
68
|
* import { model } from "@medusajs/framework/utils" |
|
69
|
* |
|
70
|
* const Store = model.define("store", { |
|
71
|
* name: model.text().translatable(), |
|
72
|
* // ... |
|
73
|
* }) |
|
74
|
* |
|
75
|
* export default Store |
|
76
|
* |
|
77
|
* @customNamespace Property Configuration Methods |
|
78
|
* @since 2.13.0 |
|
79
|
*/ |
|
80
|
translatable() { |
|
81
|
this.dataType.options.translatable = true |
|
82
|
return this |
|
83
|
} |
|
84
|
} |