Skip to content

Commit ae60f66

Browse files
authored
Add typescript support for Index and Collection controllers (#531)
## What does this PR do? Add typescript support for Index and Collection controllers ### Other changes - Update `collection:update` and `collection:create` methods (new syntax with `mappings` and `settings`) - Returns `undefined` instead of some useless `{ acknowledged: true }`. Since this was undocumented it's not a breaking change
1 parent a167d04 commit ae60f66

File tree

19 files changed

+693
-257
lines changed

19 files changed

+693
-257
lines changed

.eslintignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ src/Kuzzle.js
66
src/KuzzleError.js
77
src/controllers/Auth.js
88
src/controllers/Document.js
9+
src/controllers/Index.js
10+
src/controllers/Collection.js
911
src/controllers/Base.js
1012
src/core/security/User.js
1113
src/core/security/Profile.js

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ src/Kuzzle.js
3434
src/KuzzleError.js
3535
src/controllers/Auth.js
3636
src/controllers/Document.js
37+
src/controllers/Index.js
38+
src/controllers/Collection.js
3739
src/controllers/Base.js
3840
src/core/security/User.js
3941
src/core/security/Profile.js

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ jobs:
9393
- $(npm bin)/kuzdoc framework:link -d /sdk/js/7/ -v 7
9494
script:
9595
- gem install typhoeus
96-
- cd doc/framework/ && HYDRA_MAX_CONCURRENCY=20 ruby .ci/dead-links.rb -p src/sdk/js/7/
96+
- cd doc/framework/ && HYDRA_MAX_CONCURRENCY=20 travis_retry ruby .ci/dead-links.rb -p src/sdk/js/7/
9797

9898
- stage: Deployment Doc Dev
9999
name: Deploy next-docs.kuzzle.io

doc/7/controllers/collection/create/index.md

Lines changed: 46 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,22 @@ description: Create a new collection
77

88
# create
99

10-
Creates a new [collection](/core/2/guides/essentials/store-access-data) in Kuzzle via the persistence engine, in the provided index.
10+
Creates a new [collection](/core/2/guides/essentials/store-access-data) in the provided index.
1111

1212
You can also provide an optional data mapping that allow you to exploit the full capabilities of our
13-
persistent data storage layer, [ElasticSearch](https://www.elastic.co/elastic-stack) (check here the [mapping capabilities of ElasticSearch](https://www.elastic.co/guide/en/elasticsearch/reference/7.3/mapping.html)).
13+
persistent data storage layer, [ElasticSearch](https://www.elastic.co/elastic-stack) (check here the [mapping capabilities of ElasticSearch](/core/2/guides/essentials/database-mappings/)).
1414

1515
This method will only update the mapping if the collection already exists.
1616

17+
<SinceBadge version="Kuzzle 2.2.0" />
18+
<SinceBadge version="auto-version" />
19+
20+
You can also provide Elasticsearch [index settings](https://www.elastic.co/guide/en/elasticsearch/reference/7.5/index-modules.html#index-modules-settings) when creating a new collection.
21+
1722
<br/>
1823

1924
```js
20-
create(index, collection, [mapping], [options]);
25+
create(index, collection, [definition], [options]);
2126
```
2227

2328
<br/>
@@ -26,17 +31,48 @@ create(index, collection, [mapping], [options]);
2631
| ------------ | ----------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
2732
| `index` | <pre>string</pre> | Index name |
2833
| `collection` | <pre>string</pre> | Collection name |
29-
| `mapping` | <pre>object</pre> | Describes the data mapping to associate to the new collection, using Elasticsearch [mapping format](https://www.elastic.co/guide/en/elasticsearch/reference/7.3/mapping.html) |
34+
| `definition` | <pre>object</pre> | Describes the collection mappings and the ES index settings |
3035
| `options` | <pre>object</pre> | Query options |
36+
<SinceBadge version="auto-version">
3137

32-
### mapping
33-
34-
An object representing the data mapping of the collection.
38+
### definition
3539

40+
An object containings:
41+
- [collection mappings](/core/2/guides/essentials/database-mappings).
42+
- Elasticsearch [index settings](https://www.elastic.co/guide/en/elasticsearch/reference/7.5/index-modules.html#index-modules-settings)
3643
The mapping must have a root field `properties` that contain the mapping definition:
3744

3845
```js
39-
const mapping = {
46+
const definition = {
47+
mappings: {
48+
properties: {
49+
field1: { type: 'text' },
50+
field2: {
51+
properties: {
52+
nestedField: { type: 'keyword' }
53+
}
54+
}
55+
}
56+
},
57+
settings: {
58+
59+
}
60+
};
61+
```
62+
63+
</SinceBadge>
64+
65+
66+
<DeprecatedBadge version="auto-version">
67+
68+
### definition
69+
70+
An object representing the data mappings of the collection.
71+
72+
The mappings must have a root field `properties` that contain the mappings properties definition:
73+
74+
```js
75+
const mappings = {
4076
properties: {
4177
field1: { type: 'text' },
4278
field2: {
@@ -50,6 +86,8 @@ const mapping = {
5086

5187
More informations about database mappings [here](/core/2/guides/essentials/database-mappings).
5288

89+
</DeprecatedBadge>
90+
5391
### options
5492

5593
Additional query options

doc/7/controllers/collection/create/snippets/create.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const mapping = {
1+
const mappings = {
22
properties: {
33
license: { type: 'keyword' },
44
driver: {
@@ -11,7 +11,7 @@ const mapping = {
1111
};
1212

1313
try {
14-
await kuzzle.collection.create('nyc-open-data', 'yellow-taxi', mapping);
14+
await kuzzle.collection.create('nyc-open-data', 'yellow-taxi', { mappings });
1515

1616
console.log('Success');
1717
} catch (error) {

doc/7/controllers/collection/exists/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ description: Check if collection exists
77

88
# exists
99

10-
Check if a collection exists in Kuzzle.
10+
Checks if a collection exists in Kuzzle.
1111

1212
<br/>
1313

doc/7/controllers/collection/get-mapping/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ Additional query options
3030
| Property | Type<br/>(default) | Description |
3131
| ---------- | ------------------------------- | ---------------------------------------------------------------------------- |
3232
| `queuable` | <pre>boolean</pre><br/>(`true`) | If true, queues the request during downtime, until connected to Kuzzle again |
33+
| `includeKuzzleMeta` | <pre>boolean</pre><br/>(`true`) | If true, the returned mappings will contain [Kuzzle metadata](/core/2/guides/essentials/document-metadata/) |
3334

3435
## Resolves
3536

doc/7/controllers/collection/refresh/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ description: Forces an Elasticsearch search index update
77

88
# refresh
99

10-
When writing or deleting documents in Kuzzle, the update needs to be indexed before being available in search results.
10+
Refreshes a collection to reindex the written and deleted documents so they are available in search results.
1111

1212
:::info
1313
A refresh operation comes with some performance costs.

doc/7/controllers/collection/update-specifications/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ description: Update the validation specifications
77

88
# updateSpecifications
99

10-
The updateSpecifications method allows you to create or update the validation specifications for a collection.
10+
Creates or updates the validation specifications for a collection.
1111

1212
When the validation specification is not formatted correctly, a detailed error message is returned to help you to debug.
1313

doc/7/controllers/collection/update/index.md

Lines changed: 51 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,66 @@ You can define the collection [dynamic mapping policy](/core/2/guides/essentials
1313

1414
You can define [collection additional metadata](/core/2/guides/essentials/database-mappings#collection-metadata) within the `_meta` root field.
1515

16+
<SinceBadge version="Kuzzle 2.2.0" />
17+
<SinceBadge version="auto-version" />
18+
19+
You can also provide Elasticsearch [index settings](https://www.elastic.co/guide/en/elasticsearch/reference/7.5/index-modules.html#index-modules-settings) when creating a new collection.
20+
1621
<br/>
1722

1823
```js
19-
update(index, collection, mapping);
24+
update(index, collection, definition);
2025
```
2126

2227
<br/>
2328

24-
| Arguments | Type | Description |
25-
| ------------ | ----------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
26-
| `index` | <pre>string</pre> | Index name |
27-
| `collection` | <pre>string</pre> | Collection name |
28-
| `mapping` | <pre>object</pre> | Describes the collection mapping |
29+
| Arguments | Type | Description |
30+
|--------------|-------------------|-------------------------------------------------------------|
31+
| `index` | <pre>string</pre> | Index name |
32+
| `collection` | <pre>string</pre> | Collection name |
33+
| `definition` | <pre>object</pre> | Describes the collection mappings and the ES index settings |
34+
| `options` | <pre>object</pre> | Query options |
35+
36+
<SinceBadge version="auto-version">
2937

30-
### mapping
38+
### definition
3139

32-
An object representing the collection data mapping.
40+
An object containing:
41+
- [collection mappings](/core/2/guides/essentials/database-mappings).
42+
- Elasticsearch [index settings](https://www.elastic.co/guide/en/elasticsearch/reference/7.5/index-modules.html#index-modules-settings)
3343

34-
This object must have a root field `properties` that contain the mapping definition:
3544

3645
```js
37-
const mapping = {
46+
const definition = {
47+
mappings: {
48+
properties: {
49+
field1: { type: 'text' },
50+
field2: {
51+
properties: {
52+
nestedField: { type: 'keyword' }
53+
}
54+
}
55+
}
56+
},
57+
settings: {
58+
// index settings (e.g. analyzers)
59+
}
60+
};
61+
```
62+
63+
</SinceBadge>
64+
65+
66+
<DeprecatedBadge version="auto-version">
67+
68+
### definition
69+
70+
An object representing the data mappings of the collection.
71+
72+
The mappings must have a root field `properties` that contain the mappings properties definition:
73+
74+
```js
75+
const mappings = {
3876
properties: {
3977
field1: { type: 'text' },
4078
field2: {
@@ -48,6 +86,9 @@ const mapping = {
4886

4987
More informations about database mappings [here](/core/2/guides/essentials/database-mappings).
5088

89+
</DeprecatedBadge>
90+
91+
5192
## Resolves
5293

5394
Resolve if the collection is successfully updated.

0 commit comments

Comments
 (0)