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
7 changes: 7 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,20 @@ src/**/*.d.ts
src/**/*.js.map

src/Kuzzle.js
src/KuzzleError.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/protocols/abstract/Base.js
src/protocols/abstract/Realtime.js
src/protocols/Http.js
src/protocols/WebSocket.js
src/protocols/index.js
src/utils/interfaces.js
src/core/KuzzleEventEmitter.js
src/core/searchResult/SearchResultBase.js
src/core/searchResult/Document.js
src/core/searchResult/Profile.js
Expand Down
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,20 @@ test-*.js
*.js.map
index.js
src/Kuzzle.js
src/KuzzleError.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/protocols/abstract/Base.js
src/protocols/abstract/Realtime.js
src/protocols/Http.js
src/protocols/WebSocket.js
src/protocols/index.js
src/utils/interfaces.js
src/core/KuzzleEventEmitter.js
src/core/searchResult/SearchResultBase.js
src/core/searchResult/Document.js
src/core/searchResult/Profile.js
Expand Down
3 changes: 3 additions & 0 deletions doc/7/core-classes/kuzzle-error/properties/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,6 @@ order: 10
| `message` | <pre>string</pre> | Error message |
| `status` | <pre>number</pre> | Error status code |
| `stack` | <pre>string</pre> | Error stacktrace (only in development mode) |
| `id` | <pre>string</pre> | Error unique identifier |
| `code` | <pre>string</pre> | Error unique code |

4 changes: 3 additions & 1 deletion doc/7/essentials/error-handling/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ All SDK methods return a promise, that can be rejected with a `KuzzleError` valu
| Property | Type | Description |
| -------- | ----------------- | ------------------------------------------------------------------------------------------ |
| `status` | <pre>number</pre> | Status following [HTTP Standards](https://en.wikipedia.org/wiki/List_of_HTTP_status_codes) |
| `stack` | <pre>string</pre> | Error stacktrace (Only in development mode) |
| `stack` | <pre>string</pre> | Error stacktrace (Only in development mode) | `id` | <pre>string</pre> | Error unique identifier |
| `code` | <pre>string</pre> | Error unique code |


You can find a detailed list of possible errors messages and statuses in the [documentation API](/core/2/api/essentials/error-handling).

Expand Down
3 changes: 2 additions & 1 deletion doc/7/protocols/http/constructor/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ Http protocol connection options.
| Property | Type<br/>(default) | Description |
| --------------- | -------------------------------- | ----------------------------------- |
| `port` | <pre>number</pre><br/>(`7512`) | Kuzzle server port |
| `sslConnection` | <pre>boolean</pre><br/>(`false`) | Use SSL to connect to Kuzzle server |
| `sslConnection` | <pre>boolean</pre><br/>(`false`) | Use SSL to connect to Kuzzle server <DeprecatedBadge version="auto-version"/> |
| `ssl` | <pre>boolean</pre><br/>(`false`) | Use SSL to connect to Kuzzle server. Defaults to `true` for ports 443 and 7443. |
| `customRoutes` | <pre>object</pre><br/>(`{}`) | Add custom routes <SinceBadge version="6.2.0"/> |
| `timeout` | <pre>number</pre><br/>(`0`) | Connection timeout in milliseconds (`0` means no timeout)<SinceBadge version="6.2.1"/> |

Expand Down
5 changes: 3 additions & 2 deletions doc/7/protocols/websocket/constructor/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ WebSocket protocol connection options.
| ------------------- | -------------------------------- | -------------------------------------------------------------------------------------------- |
| `autoReconnect` | <pre>boolean</pre><br/>(`true`) | Automatically reconnect to kuzzle after a `disconnected` event |
| `port` | <pre>number</pre><br/>(`7512`) | Kuzzle server port |
| `headers` | <pre>object</pre>(`{}`) | Connection HTTP headers (e.g. origin, subprotocols, ...)<br/>**(Not supported by browsers)** |
| `headers` | <pre>object</pre>(`{}`) | Connection custom HTTP headers (e.g. origin, subprotocols, ...)<br/>**(Not supported by browsers)** |
| `reconnectionDelay` | <pre>number</pre><br/>(`1000`) | Number of milliseconds between reconnection attempts |
| `sslConnection` | <pre>boolean</pre><br/>(`false`) | Use SSL to connect to Kuzzle server |
| `sslConnection` | <pre>boolean</pre><br/>(`false`) | Use SSL to connect to Kuzzle server <DeprecatedBadge version="auto-version"/> |
| `ssl` | <pre>boolean</pre><br/>(`false`) | Use SSL to connect to Kuzzle server. Defaults to `true` for ports 443 and 7443. |

## Return

Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
"test:functional": "cucumber-js --exit --fail-fast",
"test:lint": "npm run test:lint:js && npm run test:lint:ts",
"test:lint:js": "eslint --max-warnings=0 ./src ./test ./features",
"test:lint:js:fix": "eslint --max-warnings=0 ./src ./test ./features --fix",
"test:lint:ts": "eslint ./src --ext .ts --config .eslintc-ts.json",
"test:lint:ts:fix": "eslint ./src --ext .ts --config .eslintc-ts.json --fix",
"build": "npm run build-ts && node build.js",
"build-ts": "tsc --build tsconfig.json",
"doc": "docker-compose -f doc/docker-compose.yml up",
Expand Down
3 changes: 0 additions & 3 deletions src/Kuzzle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,4 @@ Discarded request: ${JSON.stringify(request)}`));

dequeuingProcess();
}

}

module.exports = { Kuzzle };
20 changes: 0 additions & 20 deletions src/KuzzleError.js

This file was deleted.

51 changes: 51 additions & 0 deletions src/KuzzleError.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
'use strict';

/**
* Standard Kuzzle error.
*
* @see https://docs.kuzzle.io/core/2/api/essentials/error-handling/
*/
export class KuzzleError extends Error {
/**
* Http status code
*/
public status: number;
/**
* Stacktrace (only if NODE_ENV=development)
*/
public stack?: string;
/**
* Unique ID
*/
public id: string;
/**
* Code
*/
public code: number;

/**
* Associated errors
* (PartialError only)
*/
public errors?: Array<any>;
/**
* Number of associated errors
* (PartialError only)
*/
public count?: number;

constructor (apiError) {
super(apiError.message);

this.status = apiError.status;
this.stack = apiError.stack;
this.id = apiError.id;
this.code = apiError.code;

// PartialError
if (this.status === 206) {
this.errors = apiError.errors;
this.count = apiError.count;
}
}
}
2 changes: 0 additions & 2 deletions src/controllers/Auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -520,5 +520,3 @@ export class AuthController extends BaseController {
});
}
}

module.exports = { AuthController };
2 changes: 0 additions & 2 deletions src/controllers/Base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,3 @@ export class BaseController {
return this._kuzzle.query(request, options);
}
}

module.exports = { BaseController };
2 changes: 0 additions & 2 deletions src/controllers/Document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -801,5 +801,3 @@ export class DocumentController extends BaseController {
.then(response => response.result);
}
}

module.exports = { DocumentController };
14 changes: 11 additions & 3 deletions src/core/KuzzleEventEmitter.js → src/core/KuzzleEventEmitter.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
class Listener {
public fn: (...any) => any;
public once: boolean;

constructor(fn, once = false) {
this.fn = fn;
this.once = once;
}
}

class KuzzleEventEmitter {
constructor() {
/**
* @todo proper TS conversion
*/
export class KuzzleEventEmitter {
private _events: Map<string, Array<Listener>>;

constructor () {
this._events = new Map();
}

Expand Down Expand Up @@ -98,7 +106,7 @@ class KuzzleEventEmitter {
return this;
}

removeAllListeners (eventName) {
removeAllListeners (eventName?: string) {
if (eventName) {
this._events.delete(eventName);
}
Expand Down
3 changes: 0 additions & 3 deletions src/core/searchResult/SearchResultBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,3 @@ export class SearchResultBase<T> implements SearchResult<T> {
return nextSearchResult;
}
}


module.exports = { SearchResultBase };
Loading