@droz-js/sdk 0.2.7 → 0.2.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@droz-js/sdk",
3
3
  "description": "Droz SDK",
4
- "version": "0.2.7",
4
+ "version": "0.2.8",
5
5
  "private": false,
6
6
  "exports": {
7
7
  ".": "./src/index.js",
@@ -6,4 +6,14 @@ export type GetSdk<Sdk> = (requester: Requester<Sdk>) => Sdk;
6
6
  export declare function toAuthorizationProvider(type?: string, ...values: string[]): AuthorizationProvider;
7
7
  export declare function resolveAuthorization(provider?: AuthorizationProvider): Promise<string>;
8
8
  export declare function mapGraphqlResponse<T>(response: ExecutionResult<T> | Error): T;
9
- export declare function mapAsyncIterableGraphqlResponse<T>(iterable: AsyncIterableIterator<ExecutionResult<T, any>>): AsyncGenerator<Awaited<T>, void, unknown>;
9
+ declare class AsyncIterableIteratorMapper<T = any> implements AsyncIterableIterator<T> {
10
+ private from;
11
+ private mapper;
12
+ constructor(from: AsyncIterableIterator<ExecutionResult<T, any>>, mapper: (response: ExecutionResult<T, any>) => T);
13
+ next(...args: [] | [undefined]): Promise<IteratorResult<T, any>>;
14
+ return(value?: any): Promise<IteratorResult<T, any>>;
15
+ throw(e?: any): Promise<IteratorResult<T, any>>;
16
+ [Symbol.asyncIterator](): AsyncIterableIterator<T>;
17
+ }
18
+ export declare function mapAsyncIterableGraphqlResponse<T>(iterable: AsyncIterableIterator<ExecutionResult<T, any>>): AsyncIterableIteratorMapper<T>;
19
+ export {};
@@ -41,9 +41,39 @@ function mapGraphqlResponse(response) {
41
41
  }
42
42
  }
43
43
  exports.mapGraphqlResponse = mapGraphqlResponse;
44
- async function* mapAsyncIterableGraphqlResponse(iterable) {
45
- for await (const each of iterable) {
46
- yield mapGraphqlResponse(each);
44
+ class AsyncIterableIteratorMapper {
45
+ from;
46
+ mapper;
47
+ constructor(from, mapper) {
48
+ this.from = from;
49
+ this.mapper = mapper;
47
50
  }
51
+ async next(...args) {
52
+ const next = await this.from.next(...args);
53
+ return {
54
+ done: next.done,
55
+ value: this.mapper(next.value)
56
+ };
57
+ }
58
+ async return(value) {
59
+ const ret = await this.from.return(value);
60
+ return {
61
+ done: ret.done,
62
+ value: this.mapper(ret.value)
63
+ };
64
+ }
65
+ async throw(e) {
66
+ const thr = await this.from.throw(e);
67
+ return {
68
+ done: thr.done,
69
+ value: this.mapper(thr.value)
70
+ };
71
+ }
72
+ [Symbol.asyncIterator]() {
73
+ return this;
74
+ }
75
+ }
76
+ function mapAsyncIterableGraphqlResponse(iterable) {
77
+ return new AsyncIterableIteratorMapper(iterable, mapGraphqlResponse);
48
78
  }
49
79
  exports.mapAsyncIterableGraphqlResponse = mapAsyncIterableGraphqlResponse;