Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .ci/doc/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ services:
ash -c '
mkdir -p /var/snippets/node;
apk add --no-cache curl;
npm install -g eslint;
npm install -g eslint@6.8.0;
cd /var/snippets/node;
npm install \
bluebird \
Expand All @@ -76,7 +76,7 @@ services:
apt-get update;
apt-get install -y curl;
npm install -g \
eslint;
eslint@6.8.0;
cd /mnt;
npm install;
cd /var/snippets/web;
Expand Down Expand Up @@ -105,7 +105,7 @@ services:
apt-get update;
apt-get install -y curl;
npm install -g \
eslint;
eslint@6.8.0;
cd /var/snippets/webpack;
cp /mnt/.ci/doc/puppeteer.js /var/snippets/webpack/;
cp /mnt/.ci/doc/webpackBuild.js /var/snippets/webpack/;
Expand Down
31 changes: 31 additions & 0 deletions .ci/doc/templates/print-result-successes.tpl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Loads the Kuzzle SDK module and the websocket protocol
const {
Kuzzle,
WebSocket
} = require('kuzzle-sdk');

// Instantiates a Kuzzle client
const
kuzzle = new Kuzzle(
new WebSocket('kuzzle', { autoReconnect: false })
);

// Adds a listener to detect connection problems
kuzzle.on('networkError', error => {
console.error(`Network Error: ${error.message}`);
});

(async () => {
let result;
try {
await kuzzle.connect();
} catch (error) {
console.log(`Cannot connect to Kuzzle: ${error.message}`);
}
[snippet-code] finally {
kuzzle.disconnect();
}
for (const elem of result.successes) {
console.log(elem);
}
})();
16 changes: 16 additions & 0 deletions .eslintc-ts.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"root": true,
"parser": "@typescript-eslint/parser",
"plugins": [
"@typescript-eslint"
],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended"
],
"rules": {
"@typescript-eslint/no-explicit-any": 0,
"@typescript-eslint/explicit-module-boundary-types": 0
}
}
14 changes: 14 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# JS generated files from TS
src/**/*.d.ts
src/**/*.js.map

src/Kuzzle.js
src/controllers/Auth.js
src/controllers/Document.js
src/controllers/Base.js
src/core/security/User.js
src/core/security/Profile.js
src/core/security/Role.js
src/utils/interfaces.js
src/core/searchResult/SearchResultBase.js
src/core/searchResult/Document.js
17 changes: 16 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,19 @@ doc/7/getting-started/.vuejs/cypress/screenshots
doc/7/getting-started/.vuejs/cypress/videos

# Debug snippets
test-*.js
test-*.js

# Typescript related files
*.d.ts
*.js.map
index.js
src/Kuzzle.js
src/controllers/Auth.js
src/controllers/Document.js
src/controllers/Base.js
src/core/security/User.js
src/core/security/Profile.js
src/core/security/Role.js
src/utils/interfaces.js
src/core/searchResult/SearchResultBase.js
src/core/searchResult/Document.js
2 changes: 1 addition & 1 deletion .mocharc.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
"recursive": true,
"slow": 2000,
"timeout": 10000,
"require": ["should-sinon"]
"require": ["should-sinon", "ts-node/register"]
}
8 changes: 5 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ jobs:
- npm install

script:
- npm run lint
- npm run unit-testing
- npm run test:lint
- npm run test:unit

after_success:
- cat ./coverage/lcov.info | ./node_modules/.bin/codecov
Expand Down Expand Up @@ -65,7 +65,7 @@ jobs:
- npm run build

script:
- npm run functional-testing
- npm run test:functional

- stage: Tests
name: Documentation Tests
Expand Down Expand Up @@ -103,6 +103,7 @@ jobs:
env:
- BRANCH=dev
- NODE_ENV=production
- NODE_OPTIONS="--max_old_space_size=4096"
- S3_BUCKET=docs-next.kuzzle.io
- CLOUDFRONT_DISTRIBUTION_ID=E2ZCCEK9GRB49U
- AWS_DEFAULT_REGION=us-west-2
Expand Down Expand Up @@ -140,6 +141,7 @@ jobs:
node_js: 10
env:
- NODE_ENV=production
- NODE_OPTIONS="--max_old_space_size=4096"
- S3_BUCKET=docs.kuzzle.io
- CLOUDFRONT_DISTRIBUTION_ID=E3D6RP0POLCJMM
- AWS_DEFAULT_REGION=us-west-2
Expand Down
2 changes: 1 addition & 1 deletion doc/7/controllers/auth/check-token/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ An `object` representing the token validity status
| ------------- | ------------------ | --------------------------------- |
| `valid` | <pre>boolean</pre> | Tell if the token is valid or not |
| `state` | <pre>string</pre> | Explain why the token is invalid |
|  `expires_at` | <pre>number</pre> | Token expiration timestamp |
|  `expiresAt` | <pre>number</pre> | Token expiration timestamp |

## Usage

Expand Down
2 changes: 1 addition & 1 deletion doc/7/controllers/auth/create-api-key/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ The API key content has the following properties:
| Name | Type | Description |
| --------- | ----------------- | ---------------- |
| `userId` | <pre>string</pre> | User kuid |
| `expiresAt` | <pre>number</pre> | Aexpiration date in UNIX micro-timestamp format (`-1` if the token never expires) |
| `expiresAt` | <pre>number</pre> | Expiration date in UNIX micro-timestamp format (`-1` if the token never expires) |
| `ttl` | <pre>number</pre> | Original TTL |
| `description` | <pre>string</pre> | API key description |
| `token` | <pre>string</pre> | Authentication token associated with this API key |
Expand Down
4 changes: 3 additions & 1 deletion doc/7/controllers/auth/get-my-rights/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ Additional query options

## Resolves

An `object[]` containing:
An array containing user rights objects.

Each user right object has the following properties:

| Property | Type | Description |
| ------------- | ----------------- | ------------------------------------------- |
Expand Down
43 changes: 43 additions & 0 deletions doc/7/controllers/bulk/delete-by-query/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
---
code: true
type: page
title: deleteByQuery
---

# deleteByQuery

Deletes documents matching the provided search query.

This is a low level route intended to bypass Kuzzle actions on document deletion, notably:
- check document write limit
- trigger [realtime notifications](/core/2/guides/essentials/real-time)

---

```js
deleteByQuery(index, collection, [query], [options]);
```

| Argument | Type | Description |
| ------------ | ----------------- | --------------- |
| `index` | <pre>string</pre> | Index name |
| `collection` | <pre>string</pre> | Collection name |
| `query` | <pre>object</pre> | documents matching this search query will be deleted. Uses the [ElasticSearch Query DSL](https://www.elastic.co/guide/en/elasticsearch/reference/7.4/query-dsl.html) syntax. |
| `options` | <pre>object</pre> | Query options |

### Options

Additional query options

| Options | Type<br/>(default) | Description |
| ---------- | ------------------------------- | ---------------------------------------------------------------------------------- |
| `queuable` | <pre>boolean</pre><br/>(`true`) | If true, queues the request during downtime, until connected to Kuzzle again |
| `refresh` | <pre>string</pre><br/>(`""`) | If set to `wait_for`, waits for the change to be reflected for `search` (up to 1s) |

## Resolves

Resolves to the number of the deleted documents.

## Usage

<<< ./snippets/delete-by-query.js
15 changes: 15 additions & 0 deletions doc/7/controllers/bulk/delete-by-query/snippets/delete-by-query.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
try {
const deleted = await kuzzle.bulk.deleteByQuery(
'nyc-open-data',
'yellow-taxi',
{
query: {
term: { capacity: 7 }
}
}
);

console.log(`Successfully deleted ${deleted} documents`);
} catch (error) {
console.error(error.message);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: bulk#deleteByQuery
description: Delete documents matching query
hooks:
before: |
curl -XDELETE kuzzle:7512/nyc-open-data
curl -XPOST kuzzle:7512/nyc-open-data/_create
curl -XPUT kuzzle:7512/nyc-open-data/yellow-taxi

for i in 1 2 3 4 5; do
curl -H "Content-type: application/json" -d '{"capacity": 4}' kuzzle:7512/nyc-open-data/yellow-taxi/_create
done

for i in 1 2 3 4 5; do
curl -H "Content-type: application/json" -d '{"capacity": 7}' kuzzle:7512/nyc-open-data/yellow-taxi/_create
done

curl -XPOST kuzzle:7512/nyc-open-data/yellow-taxi/_refresh
after:
template: default
expected: Successfully deleted 5 documents
5 changes: 4 additions & 1 deletion doc/7/controllers/collection/update-mapping/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ description: Update the collection mapping

# updateMapping

<SinceBadge version="1.7.1" />
<SinceBadge version="Kuzzle 1.7.1" />
<DeprecatedBadge version="Kuzzle 2.1.0"/>

__Use [collection:update](/sdk/js/7/controllers/collection/update/) instead.__

You can define the collection [dynamic mapping policy](/core/2/guides/essentials/database-mappings#dynamic-mapping-policy) by setting the `dynamic` field to the desired value.

Expand Down
57 changes: 57 additions & 0 deletions doc/7/controllers/collection/update/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
---
code: true
type: page
title: update
description: Update the collection mapping
---

# update

<SinceBadge version="Kuzzle 2.1.0" />

You can define the collection [dynamic mapping policy](/core/2/guides/essentials/database-mappings#dynamic-mapping-policy) by setting the `dynamic` field to the desired value.

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

<br/>

```js
update(index, collection, mapping);
```

<br/>

| Arguments | Type | Description |
| ------------ | ----------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `index` | <pre>string</pre> | Index name |
| `collection` | <pre>string</pre> | Collection name |
| `mapping` | <pre>object</pre> | Describes the collection mapping |

### mapping

An object representing the collection data mapping.

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

```js
const mapping = {
properties: {
field1: { type: 'text' },
field2: {
properties: {
nestedField: { type: 'keyword' }
}
}
}
};
```

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

## Resolves

Resolve if the collection is successfully updated.

## Usage

<<< ./snippets/update.js
17 changes: 17 additions & 0 deletions doc/7/controllers/collection/update/snippets/update.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const mapping = {
dynamic: 'false',
_meta: {
area: 'Panipokhari'
},
properties: {
plate: { type: 'keyword' }
}
};

try {
await kuzzle.collection.update('nyc-open-data', 'yellow-taxi', mapping);

console.log('Success');
} catch (error) {
console.error(error.message);
}
10 changes: 10 additions & 0 deletions doc/7/controllers/collection/update/snippets/update.test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: collection#update
description: Update the collection mapping
hooks:
before: curl -X POST kuzzle:7512/nyc-open-data/_create && curl -X PUT kuzzle:7512/nyc-open-data/yellow-taxi
after:
template: default
expected: Success

sdk: js
version: 7
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ hooks:
curl -H "Content-type: application/json" -d '{"capacity": 7}' kuzzle:7512/nyc-open-data/yellow-taxi/_create
done

curl -XPOST kuzzle:7512/nyc-open-data/_refresh
curl -XPOST kuzzle:7512/nyc-open-data/yellow-taxi/_refresh
after:
template: default
expected: Successfully deleted 5 documents
6 changes: 6 additions & 0 deletions doc/7/controllers/document/search/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ Additional query options
| `from` | <pre>number</pre><br/>(`0`) | Offset of the first document to fetch |
| `size` | <pre>number</pre><br/>(`10`) | Maximum number of documents to retrieve per page |
| `scroll` | <pre>string</pre><br/>(`""`) | When set, gets a forward-only cursor having its ttl set to the given value (ie `30s`; cf [elasticsearch time limits](https://www.elastic.co/guide/en/elasticsearch/reference/7.3/common-options.html#time-units)) |
| `verb` | <pre>string</pre> | (HTTP only) Forces the verb of the route |

#### verb

When instantiated with a HTTP protocol object, the SDK uses the POST API by default for this API route.
You can set the `verb` option to `GET` to force the SDK to use the GET API instead.

## Body properties

Expand Down
Loading