@diory/client-js 0.2.1-rc1 → 0.2.1
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/dist/dioryClient/dioryClient.d.ts +6 -6
- package/dist/dioryClient/dioryClient.js +20 -19
- package/dist/types.d.ts +6 -6
- package/dist/utils/getConnectionClients.js +4 -2
- package/package.json +1 -1
- package/src/dioryClient/dioryClient.ts +19 -23
- package/src/types.ts +6 -6
- package/src/utils/getConnectionClients.ts +2 -2
|
@@ -13,13 +13,13 @@ declare class DioryClient implements IDioryClient {
|
|
|
13
13
|
selectRoom: (roomObject: IRoomObject) => IRoom;
|
|
14
14
|
getDiographClients: (connections?: IConnectionObject[]) => import("../types").IConnectionClient[];
|
|
15
15
|
initialiseDiograph: (roomObject: IRoomObject) => Promise<IDiograph>;
|
|
16
|
-
getDiograph: (
|
|
17
|
-
saveDiograph: (
|
|
18
|
-
importDiograph: (
|
|
19
|
-
generateDiograph: (
|
|
16
|
+
getDiograph: () => Promise<IDiographObject | undefined>;
|
|
17
|
+
saveDiograph: () => Promise<IDiographObject>;
|
|
18
|
+
importDiograph: () => Promise<IDiograph>;
|
|
19
|
+
generateDiograph: () => Promise<IDiographObject | undefined>;
|
|
20
20
|
getDiosphereClients: (connections?: IConnectionObject[]) => import("../types").IConnectionClient[];
|
|
21
21
|
initialiseDiosphere: (connections: IConnectionObject[]) => Promise<IDiosphere>;
|
|
22
|
-
getDiosphere: (
|
|
23
|
-
saveDiosphere: (
|
|
22
|
+
getDiosphere: () => Promise<IDiosphereObject | undefined>;
|
|
23
|
+
saveDiosphere: () => Promise<IDiosphereObject>;
|
|
24
24
|
}
|
|
25
25
|
export { DioryClient };
|
|
@@ -4,6 +4,7 @@ exports.DioryClient = void 0;
|
|
|
4
4
|
const diosphere_js_1 = require("@diory/diosphere-js");
|
|
5
5
|
const diograph_1 = require("@diograph/diograph");
|
|
6
6
|
const getConnectionClients_1 = require("../utils/getConnectionClients");
|
|
7
|
+
const debounce_1 = require("../utils/debounce");
|
|
7
8
|
const getDefaultDiosphere_1 = require("./getDefaultDiosphere");
|
|
8
9
|
const getDefaultDiograph_1 = require("./getDefaultDiograph");
|
|
9
10
|
class DioryClient {
|
|
@@ -31,10 +32,10 @@ class DioryClient {
|
|
|
31
32
|
console.info(this.diograph.toObject());
|
|
32
33
|
return this.diograph;
|
|
33
34
|
};
|
|
34
|
-
this.getDiograph = async (
|
|
35
|
-
console.info('getDiograph'
|
|
35
|
+
this.getDiograph = async () => {
|
|
36
|
+
console.info('getDiograph');
|
|
36
37
|
let diographObject;
|
|
37
|
-
await Promise.all(this.getDiographClients(
|
|
38
|
+
await Promise.all(this.getDiographClients().map(async (connectionClient) => {
|
|
38
39
|
try {
|
|
39
40
|
diographObject = await connectionClient.getDiograph();
|
|
40
41
|
console.info(diographObject);
|
|
@@ -46,19 +47,19 @@ class DioryClient {
|
|
|
46
47
|
}));
|
|
47
48
|
return diographObject;
|
|
48
49
|
};
|
|
49
|
-
this.saveDiograph = async (
|
|
50
|
-
console.info('saveDiograph'
|
|
50
|
+
this.saveDiograph = async () => {
|
|
51
|
+
console.info('saveDiograph');
|
|
51
52
|
const diographObject = this.diograph.toObject();
|
|
52
|
-
await Promise.all(this.getDiographClients(
|
|
53
|
+
await Promise.all(this.getDiographClients().map(async (connectionClient) => {
|
|
53
54
|
await connectionClient.saveDiograph(diographObject);
|
|
54
55
|
console.info(diographObject);
|
|
55
56
|
return;
|
|
56
57
|
}));
|
|
57
58
|
return diographObject;
|
|
58
59
|
};
|
|
59
|
-
this.importDiograph = async (
|
|
60
|
+
this.importDiograph = async () => {
|
|
60
61
|
var _a;
|
|
61
|
-
const diographObject = await this.generateDiograph(
|
|
62
|
+
const diographObject = await this.generateDiograph();
|
|
62
63
|
if (diographObject) {
|
|
63
64
|
const diory = (_a = this.diory) === null || _a === void 0 ? void 0 : _a.toObject();
|
|
64
65
|
Object.entries(diographObject).forEach(([key, dioryObject]) => {
|
|
@@ -76,10 +77,10 @@ class DioryClient {
|
|
|
76
77
|
}
|
|
77
78
|
return this.diograph;
|
|
78
79
|
};
|
|
79
|
-
this.generateDiograph = async (
|
|
80
|
-
console.info('generateDiograph'
|
|
80
|
+
this.generateDiograph = async () => {
|
|
81
|
+
console.info('generateDiograph');
|
|
81
82
|
let diographObject;
|
|
82
|
-
await Promise.all(this.getDiographClients(
|
|
83
|
+
await Promise.all(this.getDiographClients().map(async (connectionClient) => {
|
|
83
84
|
diographObject = await connectionClient.generateDiograph();
|
|
84
85
|
console.info(diographObject);
|
|
85
86
|
return;
|
|
@@ -100,10 +101,10 @@ class DioryClient {
|
|
|
100
101
|
console.info(this.diosphere.toObject());
|
|
101
102
|
return this.diosphere;
|
|
102
103
|
};
|
|
103
|
-
this.getDiosphere = async (
|
|
104
|
-
console.info('getDiosphere'
|
|
104
|
+
this.getDiosphere = async () => {
|
|
105
|
+
console.info('getDiosphere');
|
|
105
106
|
let diosphereObject;
|
|
106
|
-
await Promise.all(this.getDiosphereClients(
|
|
107
|
+
await Promise.all(this.getDiosphereClients().map(async (connectionClient) => {
|
|
107
108
|
try {
|
|
108
109
|
diosphereObject = await connectionClient.getDiosphere();
|
|
109
110
|
console.info(diosphereObject);
|
|
@@ -115,10 +116,10 @@ class DioryClient {
|
|
|
115
116
|
}));
|
|
116
117
|
return diosphereObject;
|
|
117
118
|
};
|
|
118
|
-
this.saveDiosphere = async (
|
|
119
|
-
console.info('saveDiosphere'
|
|
119
|
+
this.saveDiosphere = async () => {
|
|
120
|
+
console.info('saveDiosphere');
|
|
120
121
|
const diosphereObject = this.diosphere.toObject();
|
|
121
|
-
await Promise.all(this.getDiosphereClients(
|
|
122
|
+
await Promise.all(this.getDiosphereClients().map(async (connectionClient) => {
|
|
122
123
|
await connectionClient.saveDiosphere(diosphereObject);
|
|
123
124
|
console.info(diosphereObject);
|
|
124
125
|
return;
|
|
@@ -128,8 +129,8 @@ class DioryClient {
|
|
|
128
129
|
this.dataClients = dataClients;
|
|
129
130
|
this.diosphere = new diosphere_js_1.Diosphere();
|
|
130
131
|
this.diograph = new diograph_1.Diograph();
|
|
131
|
-
this.diosphere.saveDiosphere = this.saveDiosphere;
|
|
132
|
-
this.diograph.saveDiograph = this.saveDiograph;
|
|
132
|
+
this.diosphere.saveDiosphere = (0, debounce_1.debounce)(this.saveDiosphere, 1000);
|
|
133
|
+
this.diograph.saveDiograph = (0, debounce_1.debounce)(this.saveDiograph, 1000);
|
|
133
134
|
}
|
|
134
135
|
}
|
|
135
136
|
exports.DioryClient = DioryClient;
|
package/dist/types.d.ts
CHANGED
|
@@ -50,12 +50,12 @@ export interface IDioryClient {
|
|
|
50
50
|
selectRoom: (roomObject: IRoomObject) => IRoom;
|
|
51
51
|
diograph: IDiograph;
|
|
52
52
|
initialiseDiograph: (roomObject: IRoomObject) => Promise<IDiograph>;
|
|
53
|
-
getDiograph: (
|
|
54
|
-
saveDiograph: (
|
|
55
|
-
importDiograph: (
|
|
56
|
-
generateDiograph: (
|
|
53
|
+
getDiograph: () => Promise<IDiographObject | undefined>;
|
|
54
|
+
saveDiograph: () => Promise<IDiographObject>;
|
|
55
|
+
importDiograph: () => Promise<IDiograph>;
|
|
56
|
+
generateDiograph: () => Promise<IDiographObject | undefined>;
|
|
57
57
|
diosphere: IDiosphere;
|
|
58
58
|
initialiseDiosphere: (connections: IConnectionObject[]) => Promise<IDiosphere>;
|
|
59
|
-
getDiosphere: (
|
|
60
|
-
saveDiosphere: (
|
|
59
|
+
getDiosphere: () => Promise<IDiosphereObject | undefined>;
|
|
60
|
+
saveDiosphere: () => Promise<IDiosphereObject>;
|
|
61
61
|
}
|
|
@@ -5,8 +5,10 @@ const connectionClient_1 = require("../connectionClient/connectionClient");
|
|
|
5
5
|
function getDataClient(dataClients, { client }) {
|
|
6
6
|
return dataClients.find(({ type }) => type === client);
|
|
7
7
|
}
|
|
8
|
-
function getConnectionClients(dataClients, connections) {
|
|
9
|
-
return connections
|
|
8
|
+
function getConnectionClients(dataClients, connections = []) {
|
|
9
|
+
return connections
|
|
10
|
+
.filter(({ client }) => dataClients.some(({ type }) => type === client))
|
|
11
|
+
.map((connection) => {
|
|
10
12
|
const dataClient = getDataClient(dataClients, connection);
|
|
11
13
|
return new connectionClient_1.ConnectionClient(dataClient, connection);
|
|
12
14
|
});
|
package/package.json
CHANGED
|
@@ -29,8 +29,8 @@ class DioryClient implements IDioryClient {
|
|
|
29
29
|
this.diosphere = new Diosphere()
|
|
30
30
|
this.diograph = new Diograph()
|
|
31
31
|
|
|
32
|
-
this.diosphere.saveDiosphere = this.saveDiosphere
|
|
33
|
-
this.diograph.saveDiograph = this.saveDiograph
|
|
32
|
+
this.diosphere.saveDiosphere = debounce(this.saveDiosphere, 1000)
|
|
33
|
+
this.diograph.saveDiograph = debounce(this.saveDiograph, 1000)
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
focusDiory = (dioryObject: IDioryObject): IDiory => {
|
|
@@ -59,12 +59,12 @@ class DioryClient implements IDioryClient {
|
|
|
59
59
|
return this.diograph
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
-
getDiograph = async (
|
|
63
|
-
console.info('getDiograph'
|
|
62
|
+
getDiograph = async (): Promise<IDiographObject | undefined> => {
|
|
63
|
+
console.info('getDiograph')
|
|
64
64
|
|
|
65
65
|
let diographObject
|
|
66
66
|
await Promise.all(
|
|
67
|
-
this.getDiographClients(
|
|
67
|
+
this.getDiographClients().map(async (connectionClient) => {
|
|
68
68
|
try {
|
|
69
69
|
diographObject = await connectionClient.getDiograph()
|
|
70
70
|
console.info(diographObject)
|
|
@@ -78,12 +78,12 @@ class DioryClient implements IDioryClient {
|
|
|
78
78
|
return diographObject
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
-
saveDiograph = async (
|
|
82
|
-
console.info('saveDiograph'
|
|
81
|
+
saveDiograph = async (): Promise<IDiographObject> => {
|
|
82
|
+
console.info('saveDiograph')
|
|
83
83
|
|
|
84
84
|
const diographObject = this.diograph.toObject()
|
|
85
85
|
await Promise.all(
|
|
86
|
-
this.getDiographClients(
|
|
86
|
+
this.getDiographClients().map(async (connectionClient) => {
|
|
87
87
|
await connectionClient.saveDiograph(diographObject)
|
|
88
88
|
console.info(diographObject)
|
|
89
89
|
return
|
|
@@ -93,8 +93,8 @@ class DioryClient implements IDioryClient {
|
|
|
93
93
|
return diographObject
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
-
importDiograph = async (
|
|
97
|
-
const diographObject = await this.generateDiograph(
|
|
96
|
+
importDiograph = async (): Promise<IDiograph> => {
|
|
97
|
+
const diographObject = await this.generateDiograph()
|
|
98
98
|
|
|
99
99
|
if (diographObject) {
|
|
100
100
|
const diory = this.diory?.toObject()
|
|
@@ -115,14 +115,12 @@ class DioryClient implements IDioryClient {
|
|
|
115
115
|
return this.diograph
|
|
116
116
|
}
|
|
117
117
|
|
|
118
|
-
generateDiograph = async (
|
|
119
|
-
|
|
120
|
-
): Promise<IDiographObject | undefined> => {
|
|
121
|
-
console.info('generateDiograph', connections)
|
|
118
|
+
generateDiograph = async (): Promise<IDiographObject | undefined> => {
|
|
119
|
+
console.info('generateDiograph')
|
|
122
120
|
|
|
123
121
|
let diographObject
|
|
124
122
|
await Promise.all(
|
|
125
|
-
this.getDiographClients(
|
|
123
|
+
this.getDiographClients().map(async (connectionClient) => {
|
|
126
124
|
diographObject = await connectionClient.generateDiograph()
|
|
127
125
|
console.info(diographObject)
|
|
128
126
|
return
|
|
@@ -150,14 +148,12 @@ class DioryClient implements IDioryClient {
|
|
|
150
148
|
return this.diosphere
|
|
151
149
|
}
|
|
152
150
|
|
|
153
|
-
getDiosphere = async (
|
|
154
|
-
|
|
155
|
-
): Promise<IDiosphereObject | undefined> => {
|
|
156
|
-
console.info('getDiosphere', connections)
|
|
151
|
+
getDiosphere = async (): Promise<IDiosphereObject | undefined> => {
|
|
152
|
+
console.info('getDiosphere')
|
|
157
153
|
|
|
158
154
|
let diosphereObject
|
|
159
155
|
await Promise.all(
|
|
160
|
-
this.getDiosphereClients(
|
|
156
|
+
this.getDiosphereClients().map(async (connectionClient) => {
|
|
161
157
|
try {
|
|
162
158
|
diosphereObject = await connectionClient.getDiosphere()
|
|
163
159
|
console.info(diosphereObject)
|
|
@@ -171,12 +167,12 @@ class DioryClient implements IDioryClient {
|
|
|
171
167
|
return diosphereObject
|
|
172
168
|
}
|
|
173
169
|
|
|
174
|
-
saveDiosphere = async (
|
|
175
|
-
console.info('saveDiosphere'
|
|
170
|
+
saveDiosphere = async (): Promise<IDiosphereObject> => {
|
|
171
|
+
console.info('saveDiosphere')
|
|
176
172
|
|
|
177
173
|
const diosphereObject = this.diosphere.toObject()
|
|
178
174
|
await Promise.all(
|
|
179
|
-
this.getDiosphereClients(
|
|
175
|
+
this.getDiosphereClients().map(async (connectionClient) => {
|
|
180
176
|
await connectionClient.saveDiosphere(diosphereObject)
|
|
181
177
|
console.info(diosphereObject)
|
|
182
178
|
return
|
package/src/types.ts
CHANGED
|
@@ -60,12 +60,12 @@ export interface IDioryClient {
|
|
|
60
60
|
selectRoom: (roomObject: IRoomObject) => IRoom
|
|
61
61
|
diograph: IDiograph
|
|
62
62
|
initialiseDiograph: (roomObject: IRoomObject) => Promise<IDiograph>
|
|
63
|
-
getDiograph: (
|
|
64
|
-
saveDiograph: (
|
|
65
|
-
importDiograph: (
|
|
66
|
-
generateDiograph: (
|
|
63
|
+
getDiograph: () => Promise<IDiographObject | undefined>
|
|
64
|
+
saveDiograph: () => Promise<IDiographObject>
|
|
65
|
+
importDiograph: () => Promise<IDiograph>
|
|
66
|
+
generateDiograph: () => Promise<IDiographObject | undefined>
|
|
67
67
|
diosphere: IDiosphere
|
|
68
68
|
initialiseDiosphere: (connections: IConnectionObject[]) => Promise<IDiosphere>
|
|
69
|
-
getDiosphere: (
|
|
70
|
-
saveDiosphere: (
|
|
69
|
+
getDiosphere: () => Promise<IDiosphereObject | undefined>
|
|
70
|
+
saveDiosphere: () => Promise<IDiosphereObject>
|
|
71
71
|
}
|
|
@@ -12,10 +12,10 @@ function getDataClient(
|
|
|
12
12
|
|
|
13
13
|
export function getConnectionClients(
|
|
14
14
|
dataClients: IDataClient[],
|
|
15
|
-
connections
|
|
15
|
+
connections: IConnectionObject[] = [],
|
|
16
16
|
): IConnectionClient[] {
|
|
17
17
|
return connections
|
|
18
|
-
|
|
18
|
+
.filter(({ client }) => dataClients.some(({ type }) => type === client))
|
|
19
19
|
.map((connection) => {
|
|
20
20
|
const dataClient = getDataClient(dataClients, connection)
|
|
21
21
|
return new ConnectionClient(dataClient!, connection)
|