-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtype.html
More file actions
206 lines (182 loc) · 8.33 KB
/
Copy pathtype.html
File metadata and controls
206 lines (182 loc) · 8.33 KB
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
---
layout: default
---
<div class="content">
<h1>Type</h1>
<div class="desc">
<p>
Also known as "Domain".
</p>
<p>
The default built-in types are:
<ul>
<li>array
<li>bitmask
<li>boolean
<li>date
<li>datetime
<li>double
<li>email
<li>image
<li>integer
<li>link
<li>mongoid
<li>object
<li>password
<li>s3
<li>string
<li>time
<li>uid
<li>url
</ul>
</p>
<p>See <a href="field#def">Field.def</a> for information on type-specific Field options.</p>
<p>When creating your own types, they will get automatically registered with Tyranid via the new <u>Tyr.Type()</u> constructor.</p>
</div>
<h2>static</h2>
<article id="byName">
<b class="method"></b>
<b class="server"></b>
<b class="client"></b>
<span class="sig">byName: { <i>type name</i>: <a href="type">Type</a> }</span>
<p>This contains a dictionary of the supported Tyranid types.
</p>
</article>
<h2>instance</h2>
<article id="compare">
<b class="method"></b>
<b class="server"></b>
<b class="client"></b>
<span class="sig">compare(field: <a href="field">Field</a>, a: any, b: any): number</span>
<p>This compares two values of this type and returns a negative (a < b), zero (a == b), or positive (a > b) number suitable
for sorting comparators.
</article>
<article>
<b class="method"></b>
<b class="server"></b>
<span class="sig">compile(compiler: Compiler, <a href="/#paths">path</a>: string, field: <a href="field">Field</a>): void</span>
<p>
Any schema validation can be done inside this method. For example, ArrayTypes verify that the field has a valid "of" property.
</p>
</article>
<article>
<b class="method"></b>
<b class="server"></b>
<b class="client"></b>
<span class="sig">create(field: <a href="field">Field</a>): any</span>
<p>This creates a new value for the given type. Usually this will return <u>undefined</u> but if
<p>there is a <u>defaultValue</u> specified for the <u>field</u>, then that value will be returned.</p>
<p>This can also be useful if a custom type needs to have a certain structure guaranteed to be present.</p>
</article>
<article id="def">
<b class="property"></b>
<b class="server"></b>
<b class="client"></b>
<span class="sig">def</span>
<p>This defines the structure of a type and is the argument that is passed into the Type constructor when you want to define your own types.
<p>In the table below, <u>TType</u> refers to the TypeScript type for this Type.</p>
<table class="def">
<thead>
<tr><th>Object Structure<th>Type<th>Default<th>Notes
</thead>
<tr><td>{</td>
<tr><td> compare:<td>(field: <a href="field">Field</a>, a: TType, b: TType) => number<td>
<td>Comparator to use for members of this type. Must be isomorphic.
<tr><td> compile:<td>(compiler, field: <a href="field">Field</a>) => void<td>
<td>Callback called when parsing fields using your type. This should be used to validate any properties that your type adds to <a href="field">Field</a>s.
<tr><td> fromClient:<td>(field: <a href="field">Field</a>, value: string) => TType<td>
<td>Method used to when reading values from the client onto the server.
<tr><td> fromString:<td>(s: string) => TType<td>
<td>Comparator to use for members of this type. Must be isomorphic.
<tr><td> format:<td>(field: <a href="field">Field</a>, value: TType) => string<td>
<td>Method used to convert values of this Type to a display string.
<tr><td> matches:<td>(path: <a href="path">Path</a>, where, document: <a href="document">Document</a>) => boolean<td>
<td>Returns whether this type matches the given where clause.
<tr><td> name:<td>string<td><i>required</i>
<td>The name of this type.
<tr><td> query:<td>(path: <a href="path">Path</a>, where, query: <i>Mongo query</i>) => void<td>
<td>Applies any <u>where</u> clause set on a <a href="field">Field</a> for this type.
<tr><td> typescript:<td>string<td>
<td>The name of the TypeScript type to use for this type (this defines <u>TType<u>).
<tr><td> validate:<td>(field: <a href="field">Field</a>, value: string) => void<td>
<td>This method should throw a <a href="userError">UserError</a> if this field does not validate.
<tr><td> width:<td>integer<td>
<td>This provides the default width in pixels for fields of this type when displayed in a table.
<tr><td colspan="4" class="subtitle">Developer Documentation
<tr><td> note:<td>string<td>none<td>Contains developer-facing documentation about this type (only visible in the Tyranid console).
<tr><td>}</td>
</table>
<article>
<b class="method"></b>
<b class="server"></b>
<span class="sig">fromString(str: string): any</span>
<p>This method will be used by Tyranid to coerce strings to this data type.</p>
</article>
<article id="fromClient">
<b class="method"></b>
<b class="server"></b>
<span class="sig">fromClient(field: <a href="field">Field</a>, value: any): any</span>
<p>This method will be used by Tyranid to convert incoming data from the client into server objects. For example, MongoId types will
convert client-side MongoID strings into server-side <u>ObjectId</u> objects.</p>
</article>
<article id="fromClientQuery">
<b class="method"></b>
<b class="server"></b>
<span class="sig">fromClientQuery(field: <a href="field">Field</a>, value: any): any</span>
<p>This method will be used by Tyranid to convert incoming query data from the client into server query objects. For example, MongoId types will
convert client-side MongoID strings into server-side <u>ObjectId</u> objects.</p>
</article>
<article id="format">
<b class="method"></b>
<b class="server"></b>
<b class="client"></b>
<span class="sig">format(field: <a href="field">Field</a>, value: any): string</span>
<p>This returns a formatted version of this value for display.</p>
</article>
<article id="matches">
<b class="method"></b>
<b class="server"></b>
<span class="sig">matches(path: <a href="path">Path</a>, where: any, doc: <a href="document">Document</a> | object): boolean</span>
<p>This returns true if the given <u>doc</u>'s property given by <u>path</u> matches the <u>where</u>.</p>
</article>
<article>
<b class="property"></b>
<b class="server"></b>
<b class="client"></b>
<span class="sig">name: string</span>
<p>Contains the name of this type.</p>
</article>
<article id="query">
<b class="async"></b>
<b class="method"></b>
<b class="server"></b>
<span class="sig">query(path: <a href="path">Path</a>, where: any, query: object): void</span>
<p>This updates the passed in MongoDB-style <u>query</u> with the given <u>where</u>.</p>
</article>
<article id="sortValue">
<b class="method"></b>
<b class="server"></b>
<span class="sig">sortValue(path: <a href="path">Path</a>, value: any): any</span>
<p>This returns the sortValue to use in sorting comparisons.</p>
</article>
<article id="toClient">
<b class="method"></b>
<b class="server"></b>
<span class="sig">toClient(field: <a href="field">Field</a>, value: any): any</span>
<p>This method will be used by Tyranid to convert server data into JSON suitable for the client. For example, MongoId types will
convert server-side <u>ObjectId</u>s into client-side MongoID strings.</p>
</article>
<article id="validate">
<b class="method"></b>
<b class="server"></b>
<span class="sig">validate(field: <a href="field">Field</a>, value: any): <a href="userError">UserError</a></span>
<p>This is used by Tyranid to validate fields of this type.</p>
</article>
<article id="width">
<b class="property"></b>
<b class="server"></b>
<b class="client"></b>
<span class="sig">width?: number</span>
<p>This returns the default with for this fields of this type when displayed in a table.</p>
</article>
</div>