@superbia/untrue 1.1.6 → 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/README.md +7 -8
- package/package.json +2 -2
- package/src/DocumentContext.js +9 -14
- package/src/RequestContext.js +8 -8
- package/src/SuperbiaContext.js +7 -8
package/README.md
CHANGED
|
@@ -373,11 +373,8 @@ To implement paginated requests the server must return a Pagination object.
|
|
|
373
373
|
{ "_typename": "Post", "_id": "123", "text": "Hello world" },
|
|
374
374
|
{ "_typename": "Post", "_id": "456", "text": "Lorem ipsum" }
|
|
375
375
|
],
|
|
376
|
-
"
|
|
377
|
-
|
|
378
|
-
"hasNextPage": true,
|
|
379
|
-
"nextPageCursor": "789"
|
|
380
|
-
}
|
|
376
|
+
"hasNextPage": true,
|
|
377
|
+
"nextPageCursor": "789"
|
|
381
378
|
}
|
|
382
379
|
}
|
|
383
380
|
```
|
|
@@ -388,7 +385,7 @@ To implement paginated requests the server must return a Pagination object.
|
|
|
388
385
|
this.requests = {
|
|
389
386
|
someRequestKey: {
|
|
390
387
|
loading: false,
|
|
391
|
-
done:
|
|
388
|
+
done: true,
|
|
392
389
|
error: null,
|
|
393
390
|
data: {
|
|
394
391
|
userPosts: {
|
|
@@ -396,7 +393,8 @@ this.requests = {
|
|
|
396
393
|
error: null,
|
|
397
394
|
data: {
|
|
398
395
|
nodes: ["123", "456"],
|
|
399
|
-
|
|
396
|
+
hasNextPage: true,
|
|
397
|
+
nextPageCursor: "789",
|
|
400
398
|
},
|
|
401
399
|
},
|
|
402
400
|
},
|
|
@@ -518,7 +516,8 @@ export default Wrapper.wrapContext(Content, AppRequestContext, (props) => {
|
|
|
518
516
|
error,
|
|
519
517
|
data: {
|
|
520
518
|
nodes: postIds, // renaming for convenience
|
|
521
|
-
|
|
519
|
+
hasNextPage,
|
|
520
|
+
nextPageCursor,
|
|
522
521
|
},
|
|
523
522
|
} = requests[requestKey].data.posts; // the desired request's data
|
|
524
523
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@superbia/untrue",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.8",
|
|
4
4
|
"description": "Integrate Superbia and Untrue.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
],
|
|
14
14
|
"license": "MIT",
|
|
15
15
|
"peerDependencies": {
|
|
16
|
-
"untrue": "^4.
|
|
16
|
+
"untrue": "^4.4.2"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"uuid": "^9.0.0"
|
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;
|