Skip to content

Commit c144cd1

Browse files
committed
Add docs
1 parent d9078a2 commit c144cd1

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

docs/behaviors.md

+11-4
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,25 @@ Behaviors should be used via `implements` in the specification.
66

77
You can find all the special classes and aliases in in the [modeling guide](./modeling-guide.md).
88

9-
## AdditionalProperties
9+
## AdditionalProperties & AdditionalProperty
1010

1111
In some places in the specification an object consists of the union of a set of known properties
12-
and a set of runtime injected properties. Meaning that object should theoretically extend Dictionary but expose
13-
a set of known keys and possibly. The object might already be part of an object graph and have a parent class.
14-
This puts it into a bind that needs a client specific solution.
12+
and a set of runtime injected properties. Meaning that object should theoretically extend `Dictionary` but expose
13+
a set of known keys. The object might also be part of an object graph and have a parent class.
14+
This puts it into a bin that needs a client specific solution.
1515
We therefore document the requirement to behave like a dictionary for unknown properties with this interface.
1616

1717
```ts
1818
class IpRangeBucket implements AdditionalProperties<AggregateName, Aggregate> {}
1919
```
2020

21+
There are also many places where we expect only one runtime-defined property, such as in field-related queries. To capture that uniqueness constraint, we can use the `AdditionalProperty` (singular) behavior.
22+
23+
```ts
24+
class GeoBoundingBoxQuery extends QueryBase
25+
implements AdditionalProperty<Field, BoundingBox>
26+
```
27+
2128
## CommonQueryParameters
2229
2330
Implements a set of common query parameters all API's support.

docs/modeling-guide.md

+19
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,25 @@ class AggregationContainer {
317317
avg?: AverageAggregation
318318
...
319319
```
320+
321+
### Shortcut properties
322+
323+
In many places Elasticsearch accepts a property value to be either a complete data structure or a single value, that value being a shortcut for a property in the data structure.
324+
325+
A typical example can be found in queries such as term query: `{"term": {"some_field": {"value": "some_text"}}}` can also be written as `{"term": {"some_field": "some_text"}}`.
326+
327+
This could be modelled as a union of `SomeClass | string`, but this notation doesn't capture the relation between the string variant and the corresponding field (`value` in the above example).
328+
329+
To capture this information and also simplify the spec by avoiding the union, we use the `@shortcut_property` JSDoc tag:
330+
331+
```ts
332+
/** @shortcut_property value */
333+
export class TermQuery extends QueryBase {
334+
value: string | float | boolean
335+
case_insensitive?: boolean
336+
}
337+
```
338+
320339
### Additional information
321340

322341
If needed, you can specify additional information on each type with the approariate JSDoc tag.

0 commit comments

Comments
 (0)