diff --git a/CHANGELOG.md b/CHANGELOG.md index d4b04a44..17475dce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## [2.4.0] + +- Add custom properties to a KuzzleRequest + ## [2.3.0] - Add an option to accept bad SSL certificate diff --git a/doc/2/core-classes/kuzzle/query/index.md b/doc/2/core-classes/kuzzle/query/index.md index 9948e1ab..5b5f41c7 100644 --- a/doc/2/core-classes/kuzzle/query/index.md +++ b/doc/2/core-classes/kuzzle/query/index.md @@ -24,7 +24,7 @@ This is a low-level method, exposed to allow advanced SDK users to bypass high-l | Argument | Type | Description | | --------- | ----------------- | ---------------------- | -| `request` |
KuzzleRequest
| API request | +| `request` |
[KuzzleRequest](/sdk/dart/2/core-classes/request)
| API request | | `volatile` |
Map
| Additional information to send to Kuzzle | | `queueable` |
bool
| If true, queues the request during downtime, until connected to Kuzzle again | diff --git a/doc/2/core-classes/request/index.md b/doc/2/core-classes/request/index.md new file mode 100644 index 00000000..5606888f --- /dev/null +++ b/doc/2/core-classes/request/index.md @@ -0,0 +1,7 @@ +--- +code: true +type: branch +title: KuzzleRequest +description: KuzzleRequest object documentation +order: 0 +--- \ No newline at end of file diff --git a/doc/2/core-classes/request/introduction/index.md b/doc/2/core-classes/request/introduction/index.md new file mode 100644 index 00000000..be91aa39 --- /dev/null +++ b/doc/2/core-classes/request/introduction/index.md @@ -0,0 +1,36 @@ +--- +code: false +type: page +title: Introduction +description: KuzzleRequest object description +order: 0 +--- + +## KuzzleRequest + +`KuzzleRequest` is a **serializable** class representing a raw Kuzzle request. + + +## Properties + +| Property | Type | Description | +|--- |--- |--- | +| `action` |
String
| Executed Kuzzle API controller's action ` +| `body` |
Map body
| +| `collection` |
String
| Impacted collection | +| `controller` |
String
| Executed Kuzzle API controller | +| `index` |
String
| Impacted index | +| `jwt` |
String
| Authentication token | +| `lang` |
String
| ES lang | +| `requestId` |
String
| Request unique identifier | +| `waitForRefresh` |
bool
| If set to `true`, Kuzzle will wait for the persistence layer to finish indexing | +| `volatile` |
Map
| Volatile data | +| `from` |
int

(`0`) | Offset of the first document to fetch | +| `size` |
int

(`10`) | Maximum number of documents to retrieve per page | +| `scroll` |
String

(`""`) | When set, gets a forward-only cursor having its ttl set to the given value (ie `1s`; cf [elasticsearch time limits](https://www.elastic.co/guide/en/elasticsearch/reference/7.3/common-options.html#time-units)) | +| `scrollId` |
String
| The scrollId if using scroll option | +| `sort` |
List
| Contains a list of fields, used to [sort search results](https://www.elastic.co/guide/en/elasticsearch/reference/7.3/search-request-sort.html), in order of importance. | + +## Overrided operators + +The `[]` and `[]=` are overrided so you can dynamically add any args you want to this class and it will be taken in consideration in the request sent to Kuzzle. diff --git a/lib/src/kuzzle/request.dart b/lib/src/kuzzle/request.dart index c4fc9abe..a4ff77ab 100644 --- a/lib/src/kuzzle/request.dart +++ b/lib/src/kuzzle/request.dart @@ -111,8 +111,13 @@ class KuzzleRequest { includeKuzzleMeta = data['includeKuzzleMeta'] as bool; } + final Map _args = {}; + + dynamic operator [](String key) => _args[key]; + void operator []=(String key, dynamic value) => _args[key] = value; + Map toJson() { - final map = {}; + final map = _args; if (action != null) { map['action'] = action; diff --git a/lib/src/protocols/abstract.dart b/lib/src/protocols/abstract.dart index af871e90..e82df6e7 100644 --- a/lib/src/protocols/abstract.dart +++ b/lib/src/protocols/abstract.dart @@ -123,6 +123,15 @@ abstract class KuzzleProtocol extends KuzzleEventEmitter { final syncRes = send(request); // If we use a synchronous protocol the result is returned directly if (syncRes != null) { + syncRes.then((response) { + if (response.error != null) { + emit(ProtocolEvents.QUERY_ERROR, [response, request]); + } + }).catchError((err) { + emit(ProtocolEvents.QUERY_ERROR, [{ + 'error': err, + }, request]); + }); return syncRes; } } on Exception catch (error) { diff --git a/pubspec.yaml b/pubspec.yaml index 003d0f04..0d9830d3 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,5 +1,5 @@ name: kuzzle -version: 2.3.0 +version: 2.4.0 description: A library to interact with kuzzle API. A backend software, self-hostable and ready to use to power modern cross-platform apps. homepage: https://github.com/kuzzleio/sdk-dart