@superbia/untrue 1.1.7 → 1.1.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 +1 -1
- package/src/DocumentContext.js +9 -14
- package/src/RequestContext.js +8 -8
- package/src/SuperbiaContext.js +7 -8
package/package.json
CHANGED
package/src/DocumentContext.js
CHANGED
|
@@ -1,22 +1,17 @@
|
|
|
1
1
|
import SuperbiaContext from "./SuperbiaContext";
|
|
2
2
|
|
|
3
3
|
export class DocumentContext extends SuperbiaContext {
|
|
4
|
-
constructor(client,
|
|
5
|
-
super(
|
|
4
|
+
constructor(client, id) {
|
|
5
|
+
super(id);
|
|
6
6
|
|
|
7
7
|
this.documents = {};
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
.on("
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
.on("subscribe", (endpoint, emitter) => {
|
|
16
|
-
emitter.on("data", (data) => {
|
|
17
|
-
this.onData(data);
|
|
18
|
-
});
|
|
19
|
-
});
|
|
9
|
+
const listener = (endpoints, emitter) => {
|
|
10
|
+
emitter.on("data", (data) => this.data(data));
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
client.on("request", listener);
|
|
14
|
+
client.on("subscribe", listener);
|
|
20
15
|
}
|
|
21
16
|
|
|
22
17
|
// default persistence
|
|
@@ -33,7 +28,7 @@ export class DocumentContext extends SuperbiaContext {
|
|
|
33
28
|
return this.documents;
|
|
34
29
|
}
|
|
35
30
|
|
|
36
|
-
|
|
31
|
+
data(data) {
|
|
37
32
|
const newData = {};
|
|
38
33
|
|
|
39
34
|
Object.values(data).forEach((result) => {
|
package/src/RequestContext.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import SuperbiaContext from "./SuperbiaContext";
|
|
2
2
|
|
|
3
3
|
export class RequestContext extends SuperbiaContext {
|
|
4
|
-
constructor(client,
|
|
5
|
-
super(
|
|
4
|
+
constructor(client, id) {
|
|
5
|
+
super(id);
|
|
6
6
|
|
|
7
7
|
this.requests = {};
|
|
8
8
|
|
|
@@ -31,8 +31,8 @@ export class RequestContext extends SuperbiaContext {
|
|
|
31
31
|
if (
|
|
32
32
|
result !== null &&
|
|
33
33
|
typeof result === "object" &&
|
|
34
|
-
this.
|
|
35
|
-
result[this.
|
|
34
|
+
this.keys.typename in result &&
|
|
35
|
+
result[this.keys.typename].endsWith("Pagination")
|
|
36
36
|
) {
|
|
37
37
|
return { loading: false, error: null, data: this.parseResult(result) };
|
|
38
38
|
} else {
|
|
@@ -40,7 +40,7 @@ export class RequestContext extends SuperbiaContext {
|
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
|
|
43
|
+
async request(key, endpoints, payload = null) {
|
|
44
44
|
key = key !== null && key !== undefined ? key : Date.now().toString();
|
|
45
45
|
|
|
46
46
|
this.requests[key] = {
|
|
@@ -104,9 +104,9 @@ export class RequestContext extends SuperbiaContext {
|
|
|
104
104
|
|
|
105
105
|
this.update();
|
|
106
106
|
}
|
|
107
|
-
}
|
|
107
|
+
}
|
|
108
108
|
|
|
109
|
-
|
|
109
|
+
async load(key, endpoints, payload = null) {
|
|
110
110
|
const interceptors = this.intercept();
|
|
111
111
|
|
|
112
112
|
const endpointKey = Object.keys(endpoints)[0];
|
|
@@ -151,5 +151,5 @@ export class RequestContext extends SuperbiaContext {
|
|
|
151
151
|
|
|
152
152
|
this.update();
|
|
153
153
|
}
|
|
154
|
-
}
|
|
154
|
+
}
|
|
155
155
|
}
|
package/src/SuperbiaContext.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { Context } from "untrue";
|
|
2
2
|
|
|
3
3
|
class SuperbiaContext extends Context {
|
|
4
|
-
constructor(
|
|
4
|
+
constructor(id = "id") {
|
|
5
5
|
super();
|
|
6
6
|
|
|
7
|
-
this.
|
|
7
|
+
this.keys = { id, typename: "_typename" };
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
parseResult(result, data = {}) {
|
|
@@ -13,7 +13,7 @@ class SuperbiaContext extends Context {
|
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
if (Array.isArray(result)) {
|
|
16
|
-
return result.map((
|
|
16
|
+
return result.map((element) => this.parseResult(element, data));
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
if (typeof result === "object") {
|
|
@@ -23,15 +23,14 @@ class SuperbiaContext extends Context {
|
|
|
23
23
|
newResult[key] = this.parseResult(result[key], data);
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
const isDocument =
|
|
27
|
-
this.documentKeys.id in result && this.documentKeys.typename in result;
|
|
26
|
+
const isDocument = this.keys.id in result && this.keys.typename in result;
|
|
28
27
|
|
|
29
28
|
if (!isDocument) {
|
|
30
29
|
return newResult;
|
|
31
30
|
}
|
|
32
31
|
|
|
33
|
-
const id = result[this.
|
|
34
|
-
const typename = result[this.
|
|
32
|
+
const id = result[this.keys.id];
|
|
33
|
+
const typename = result[this.keys.typename];
|
|
35
34
|
|
|
36
35
|
if (!(typename in data)) {
|
|
37
36
|
data[typename] = {};
|
|
@@ -39,7 +38,7 @@ class SuperbiaContext extends Context {
|
|
|
39
38
|
|
|
40
39
|
data[typename][id] = newResult;
|
|
41
40
|
|
|
42
|
-
return result[this.
|
|
41
|
+
return result[this.keys.id];
|
|
43
42
|
}
|
|
44
43
|
|
|
45
44
|
return result;
|