-
Notifications
You must be signed in to change notification settings - Fork 81
/
Copy pathfield.ts
88 lines (72 loc) · 2.32 KB
/
field.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import { AllFieldDefinition, FieldDefinition, FieldType } from './definitions'
/**
* Describes a field in a {@link Schema}.
*/
export class Field {
readonly #name: string
#definition: AllFieldDefinition
/**
* Creates a Field.
*
* @param name The name of the Field.
* @param definition The underlying {@link FieldDefinition}.
*/
constructor(name: string, definition: FieldDefinition) {
this.#name = name
this.#definition = definition
}
/** The name of the field. */
get name(): string {
return this.#name
}
/** The {@link FieldType | type} of the field. */
get type(): FieldType {
return this.#definition.type
}
/** The field name used to store this {@link Field} in a Hash. */
get hashField(): string {
return this.#definition.field ?? this.#definition.alias ?? this.name
}
/** The JSONPath used to store this {@link Field} in a JSON document. */
get jsonPath(): string {
if (this.#definition.path) return this.#definition.path
const alias = (this.#definition.alias ?? this.name).replace(/"/g, '\\"')
return this.isArray ? `$["${alias}"][*]` : `$["${alias}"]`
}
/** The separator for string[] fields when stored in Hashes. */
get separator(): string {
return this.#definition.separator ?? '|'
}
/** Indicates that the field as sortable. */
get sortable(): boolean {
return this.#definition.sortable ?? false
}
/** The case-sensitivity of the field. */
get caseSensitive(): boolean {
return this.#definition.caseSensitive ?? false
}
/** Indicates the field as being indexed—and thus queryable—by RediSearch. */
get indexed(): boolean {
return this.#definition.indexed ?? true
}
/** Indicates that the field as indexed with stemming support. */
get stemming(): boolean {
return this.#definition.stemming ?? true
}
/** Indicates that the field is normalized. Ignored if sortable is false. */
get normalized(): boolean {
return this.#definition.normalized ?? true
}
/** The search weight of the field. */
get weight(): number | null {
return this.#definition.weight ?? null
}
/** The phonetic matcher for the field. */
get matcher(): string | null {
return this.#definition.matcher ?? null
}
/** Is this type an array or not. */
get isArray(): boolean {
return this.type.endsWith('[]')
}
}