-
Notifications
You must be signed in to change notification settings - Fork 81
/
Copy pathdefinitions.ts
125 lines (100 loc) · 4.51 KB
/
definitions.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import {Entity, EntityKeys} from "$lib/entity";
/** Valid field types for a {@link FieldDefinition}. */
export type FieldType = 'boolean' | 'date' | 'number' | 'number[]' | 'point' | 'string' | 'string[]' | 'text'
/** All configuration properties that any field might have, regardless of type. */
export type AllFieldDefinition = {
/** The type of the field (i.e. string, number, boolean, etc.) */
type: FieldType
/**
* The default field name in Redis is the property name defined in the
* {@link SchemaDefinition}. Overrides the field name for a Hash to this
* value or in the case of JSON documents, sets the JSONPath to this
* value preceded by `$.`. Overridden by {@link field} and/or {@link path}
* settings.
* @deprecated
*/
alias?: string
/**
* Is this field indexed and thus searchable with Redis OM. Defaults
* to true.
*/
indexed?: boolean
/**
* The field name used to store this in a Redis Hash. Defaults to the
* name used in the {@link SchemaDefinition} or the {@link alias}
* property.
*/
field?: string
/**
* The JSONPath expression this field references. Used only by search
* and only for JSON documents. Defaults to the name used in the
* {@link SchemaDefinition} or the {@link alias} property prefixed
* with `$.` .
*/
path?: string
/** Enables sorting by this field. */
sortable?: boolean
/** Is the original case of this field indexed with Redis OM. Defaults to false. */
caseSensitive?: boolean
/** Is this (sortable) field normalized when indexed. Defaults to true. */
normalized?: boolean
/**
* Due to how RediSearch works, strings and arrays are sometimes stored the same in Redis, as a
* simple string. This is the separator used to split those strings when it is an array. If your
* StringField contains this separator, this can cause problems. You can change it here to avoid
* those problems. Defaults to `|`.
*/
separator?: string
/**
* Enables setting the phonetic matcher to use, supported matchers are:
* dm:en - Double Metaphone for English
* dm:fr - Double Metaphone for French
* dm:pt - Double Metaphone for Portuguese
* dm:es - Double Metaphone for Spanish
*/
matcher?: 'dm:en' | 'dm:fr' | 'dm:pt' | 'dm:es'
/** Is word stemming applied to this field with Redis OM. Defaults to true. */
stemming?: boolean
/** Enables setting the weight to apply to a text field */
weight?: number
}
/** The configuration properties that all fields have in common. */
export type CommonFieldDefinition = Pick<AllFieldDefinition, "type" | "alias" | "indexed" | "field" | "path">
/** A field representing a boolean. */
export type BooleanFieldDefinition = { type: 'boolean' }
& CommonFieldDefinition
& Pick<AllFieldDefinition, "sortable">
/** A field representing a date/time. */
export type DateFieldDefinition = { type: 'date' }
& CommonFieldDefinition
& Pick<AllFieldDefinition, "sortable">
/** A field representing a number. */
export type NumberFieldDefinition = { type: 'number' }
& CommonFieldDefinition
& Pick<AllFieldDefinition, "sortable">
/** A field representing an array of numbers. */
export type NumberArrayFieldDefinition = { type: 'number[]' }
& CommonFieldDefinition
& Pick<AllFieldDefinition, "sortable">
/** A field representing a point on the globe. */
export type PointFieldDefinition = { type: 'point' }
& CommonFieldDefinition
/** A field representing a whole string. */
export type StringFieldDefinition = { type: 'string' }
& CommonFieldDefinition
& Pick<AllFieldDefinition, "sortable" | "caseSensitive" | "normalized" | "separator">
/** A field representing an array of strings. */
export type StringArrayFieldDefinition = { type: 'string[]' }
& CommonFieldDefinition
& Pick<AllFieldDefinition, "sortable" | "caseSensitive" | "normalized" | "separator">
/** A field representing searchable text. */
export type TextFieldDefinition = { type: 'text' }
& CommonFieldDefinition
& Pick<AllFieldDefinition, "sortable" | "normalized" | "matcher" | "stemming" | "weight" >
/** Contains instructions telling how to map a property on an {@link Entity} to Redis. */
export type FieldDefinition =
BooleanFieldDefinition | DateFieldDefinition | NumberFieldDefinition | NumberArrayFieldDefinition |
PointFieldDefinition | StringFieldDefinition | StringArrayFieldDefinition |
TextFieldDefinition
/** Group of {@link FieldDefinition}s that define the schema for an {@link Entity}. */
export type SchemaDefinition<T extends Entity = Record<string, any>> = Record<EntityKeys<T>, FieldDefinition>