@diory/client-js 0.2.0-rc10 → 0.2.0-rc12
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 +8 -5
- package/dist/dioryClient/dioryClient.js +67 -61
- package/dist/types.d.ts +1 -0
- package/dist/utils/getConnectionClients.d.ts +1 -1
- package/dist/utils/getConnectionClients.js +1 -3
- package/package.json +3 -3
- package/src/dioryClient/dioryClient.ts +85 -72
- package/src/types.ts +1 -0
- package/src/utils/getConnectionClients.ts +2 -2
|
@@ -10,12 +10,15 @@ declare class DioryClient implements IDioryClient {
|
|
|
10
10
|
diory?: IDiory;
|
|
11
11
|
constructor(dataClients: IDataClient[]);
|
|
12
12
|
initialise: (connections: IConnectionObject[]) => Promise<IDioryClient>;
|
|
13
|
+
selectRoom: (roomObject: IRoomObject) => IRoom;
|
|
13
14
|
enterRoom: (roomObject: IRoomObject) => Promise<IRoom>;
|
|
14
15
|
focusDiory: (dioryObject: IDioryObject) => IDiory;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
getDiosphereClients: (connections?: IConnectionObject[]) => import("../types").IConnectionClient[];
|
|
17
|
+
getDiographClients: (connections?: IConnectionObject[]) => import("../types").IConnectionClient[];
|
|
18
|
+
getDiosphere: (connections?: IConnectionObject[]) => Promise<IDiosphere>;
|
|
19
|
+
saveDiosphere: (connections?: IConnectionObject[]) => Promise<IDiosphere>;
|
|
20
|
+
getDiograph: (connections?: IConnectionObject[]) => Promise<IDiograph>;
|
|
21
|
+
saveDiograph: (connections?: IConnectionObject[]) => Promise<IDiograph>;
|
|
22
|
+
generateDiograph: (connections?: IConnectionObject[]) => Promise<IDiograph>;
|
|
20
23
|
}
|
|
21
24
|
export { DioryClient };
|
|
@@ -9,90 +9,96 @@ class DioryClient {
|
|
|
9
9
|
this.dataClients = [];
|
|
10
10
|
this.connections = [];
|
|
11
11
|
this.initialise = async (connections) => {
|
|
12
|
+
console.info('initialise', connections);
|
|
12
13
|
this.connections = connections;
|
|
13
14
|
this.diosphere.resetRooms();
|
|
14
|
-
|
|
15
|
-
await this.enterRoom({ id: '/' });
|
|
15
|
+
console.info(this.diosphere);
|
|
16
16
|
return this;
|
|
17
17
|
};
|
|
18
|
+
this.selectRoom = (roomObject) => {
|
|
19
|
+
return (this.room = this.diosphere.getRoom(roomObject));
|
|
20
|
+
};
|
|
18
21
|
this.enterRoom = async (roomObject) => {
|
|
19
|
-
|
|
22
|
+
console.info('enterRoom', roomObject);
|
|
23
|
+
this.selectRoom(roomObject);
|
|
20
24
|
this.diograph.resetDiograph();
|
|
21
25
|
await this.getDiograph();
|
|
22
|
-
this.
|
|
26
|
+
console.info(this.room);
|
|
23
27
|
return this.room;
|
|
24
28
|
};
|
|
25
29
|
this.focusDiory = (dioryObject) => {
|
|
26
30
|
return (this.diory = this.diograph.getDiory(dioryObject));
|
|
27
31
|
};
|
|
28
|
-
this.
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
32
|
+
this.getDiosphereClients = (connections) => {
|
|
33
|
+
return (0, getConnectionClients_1.getConnectionClients)(this.dataClients, connections !== null && connections !== void 0 ? connections : this.connections);
|
|
34
|
+
};
|
|
35
|
+
this.getDiographClients = (connections) => {
|
|
36
|
+
var _a;
|
|
37
|
+
return (0, getConnectionClients_1.getConnectionClients)(this.dataClients, connections !== null && connections !== void 0 ? connections : (_a = this.room) === null || _a === void 0 ? void 0 : _a.connections);
|
|
38
|
+
};
|
|
39
|
+
this.getDiosphere = async (connections) => {
|
|
40
|
+
console.info('getDiosphere', connections);
|
|
41
|
+
await Promise.all(this.getDiosphereClients(connections).map(async (connectionClient) => {
|
|
42
|
+
try {
|
|
33
43
|
const diosphereObject = await connectionClient.getDiosphere();
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
44
|
+
this.diosphere.addDiosphere(diosphereObject);
|
|
45
|
+
this.selectRoom({ id: '/' });
|
|
46
|
+
console.info(this.diosphere.toObject());
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
console.error(error);
|
|
50
|
+
}
|
|
51
|
+
return;
|
|
52
|
+
}));
|
|
38
53
|
return this.diosphere;
|
|
39
54
|
};
|
|
40
|
-
this.saveDiosphere = async () => {
|
|
41
|
-
console.info('saveDiosphere',
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
return;
|
|
48
|
-
}));
|
|
49
|
-
}
|
|
55
|
+
this.saveDiosphere = async (connections) => {
|
|
56
|
+
console.info('saveDiosphere', connections);
|
|
57
|
+
await Promise.all(this.getDiosphereClients(connections).map(async (connectionClient) => {
|
|
58
|
+
await connectionClient.saveDiosphere(this.diosphere.toObject());
|
|
59
|
+
console.info(this.diosphere.toObject());
|
|
60
|
+
return;
|
|
61
|
+
}));
|
|
50
62
|
return this.diosphere;
|
|
51
63
|
};
|
|
52
|
-
this.getDiograph = async () => {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
const connectionClients = (0, getConnectionClients_1.getConnectionClients)(this.dataClients, this.room.connections);
|
|
57
|
-
await Promise.all(connectionClients.map(async (connectionClient) => {
|
|
64
|
+
this.getDiograph = async (connections) => {
|
|
65
|
+
console.info('getDiograph', connections);
|
|
66
|
+
await Promise.all(this.getDiographClients(connections).map(async (connectionClient) => {
|
|
67
|
+
try {
|
|
58
68
|
const diographObject = await connectionClient.getDiograph();
|
|
59
|
-
console.info(diographObject);
|
|
60
69
|
this.diograph.addDiograph(diographObject);
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
70
|
+
this.focusDiory({ id: '/' });
|
|
71
|
+
console.info(this.diograph.toObject());
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
console.error(error);
|
|
75
|
+
}
|
|
76
|
+
return;
|
|
77
|
+
}));
|
|
64
78
|
return this.diograph;
|
|
65
79
|
};
|
|
66
|
-
this.saveDiograph = async () => {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
await connectionClient.saveDiograph(this.diograph.toObject());
|
|
74
|
-
return;
|
|
75
|
-
}));
|
|
76
|
-
}
|
|
80
|
+
this.saveDiograph = async (connections) => {
|
|
81
|
+
console.info('saveDiograph', connections);
|
|
82
|
+
await Promise.all(this.getDiographClients(connections).map(async (connectionClient) => {
|
|
83
|
+
await connectionClient.saveDiograph(this.diograph.toObject());
|
|
84
|
+
console.info(this.diograph.toObject());
|
|
85
|
+
return;
|
|
86
|
+
}));
|
|
77
87
|
return this.diograph;
|
|
78
88
|
};
|
|
79
|
-
this.generateDiograph = async () => {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
await connectionClient.saveDiograph(this.diograph.toObject());
|
|
93
|
-
return;
|
|
94
|
-
}));
|
|
95
|
-
}
|
|
89
|
+
this.generateDiograph = async (connections) => {
|
|
90
|
+
console.info('generateDiograph', connections);
|
|
91
|
+
await Promise.all(this.getDiographClients(connections).map(async (connectionClient) => {
|
|
92
|
+
const diographObject = await connectionClient.generateDiograph();
|
|
93
|
+
Object.entries(diographObject).forEach(([key, dioryObject]) => {
|
|
94
|
+
key === '/'
|
|
95
|
+
? this.diograph.addDioryLink({ id: '/' }, diographObject['/'])
|
|
96
|
+
: this.diograph.addDiory(dioryObject);
|
|
97
|
+
});
|
|
98
|
+
await connectionClient.saveDiograph(this.diograph.toObject());
|
|
99
|
+
console.info(this.diograph.toObject());
|
|
100
|
+
return;
|
|
101
|
+
}));
|
|
96
102
|
return this.diograph;
|
|
97
103
|
};
|
|
98
104
|
this.dataClients = dataClients;
|
package/dist/types.d.ts
CHANGED
|
@@ -49,6 +49,7 @@ export interface IDioryClient {
|
|
|
49
49
|
diograph: IDiograph;
|
|
50
50
|
diory?: IDiory;
|
|
51
51
|
initialise: (connections: IConnectionObject[]) => Promise<IDioryClient>;
|
|
52
|
+
selectRoom: (roomObject: IRoomObject) => IRoom;
|
|
52
53
|
enterRoom: (roomObject: IRoomObject) => Promise<IRoom>;
|
|
53
54
|
focusDiory: (dioryObject: IDioryObject) => IDiory;
|
|
54
55
|
getDiosphere: () => Promise<IDiosphere>;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { IConnectionObject } from '@diory/diosphere-js';
|
|
2
2
|
import { IConnectionClient, IDataClient } from '../types';
|
|
3
|
-
export declare function getConnectionClients(dataClients: IDataClient[], connections
|
|
3
|
+
export declare function getConnectionClients(dataClients: IDataClient[], connections?: IConnectionObject[]): IConnectionClient[];
|
|
@@ -6,9 +6,7 @@ function getDataClient(dataClients, { client }) {
|
|
|
6
6
|
return dataClients.find(({ type }) => type === client);
|
|
7
7
|
}
|
|
8
8
|
function getConnectionClients(dataClients, connections) {
|
|
9
|
-
return connections
|
|
10
|
-
.filter(({ client }) => dataClients.some(({ type }) => type === client))
|
|
11
|
-
.map((connection) => {
|
|
9
|
+
return connections === null || connections === void 0 ? void 0 : connections.filter(({ client }) => dataClients.some(({ type }) => type === client)).map((connection) => {
|
|
12
10
|
const dataClient = getDataClient(dataClients, connection);
|
|
13
11
|
return new connectionClient_1.ConnectionClient(dataClient, connection);
|
|
14
12
|
});
|
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@diory/client-js",
|
|
3
|
-
"version": "0.2.0-
|
|
3
|
+
"version": "0.2.0-rc12",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"author": "Olli-Pekka Pohjola <op@diory.me>, Jouni Alanen <jouni@diory.me>",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@diograph/diograph": "0.3.0-
|
|
9
|
+
"@diograph/diograph": "^0.3.0-rc15",
|
|
10
10
|
"@diograph/folder-generator": "^0.3.0-rc3",
|
|
11
|
-
"@diory/diosphere-js": "0.2.6-
|
|
11
|
+
"@diory/diosphere-js": "^0.2.6-rc3",
|
|
12
12
|
"path-browserify": "^1.0.1",
|
|
13
13
|
"uuid": "8.3.2"
|
|
14
14
|
},
|
|
@@ -23,118 +23,131 @@ class DioryClient implements IDioryClient {
|
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
initialise = async (connections: IConnectionObject[]): Promise<IDioryClient> => {
|
|
26
|
-
|
|
26
|
+
console.info('initialise', connections)
|
|
27
27
|
|
|
28
|
+
this.connections = connections
|
|
28
29
|
this.diosphere.resetRooms()
|
|
29
|
-
|
|
30
|
-
await this.enterRoom({ id: '/' })
|
|
30
|
+
console.info(this.diosphere)
|
|
31
31
|
|
|
32
32
|
return this
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
+
selectRoom = (roomObject: IRoomObject): IRoom => {
|
|
36
|
+
return (this.room = this.diosphere.getRoom(roomObject))
|
|
37
|
+
}
|
|
38
|
+
|
|
35
39
|
enterRoom = async (roomObject: IRoomObject): Promise<IRoom> => {
|
|
36
|
-
|
|
40
|
+
console.info('enterRoom', roomObject)
|
|
37
41
|
|
|
42
|
+
this.selectRoom(roomObject)
|
|
38
43
|
this.diograph.resetDiograph()
|
|
39
44
|
await this.getDiograph()
|
|
40
|
-
this.
|
|
45
|
+
console.info(this.room)
|
|
41
46
|
|
|
42
|
-
return this.room
|
|
47
|
+
return this.room as IRoom
|
|
43
48
|
}
|
|
44
49
|
|
|
45
50
|
focusDiory = (dioryObject: IDioryObject): IDiory => {
|
|
46
51
|
return (this.diory = this.diograph.getDiory(dioryObject))
|
|
47
52
|
}
|
|
48
53
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
const connectionClients = getConnectionClients(this.dataClients, this.connections)
|
|
54
|
+
getDiosphereClients = (connections?: IConnectionObject[]) => {
|
|
55
|
+
return getConnectionClients(this.dataClients, connections ?? this.connections)
|
|
56
|
+
}
|
|
53
57
|
|
|
54
|
-
|
|
55
|
-
|
|
58
|
+
getDiographClients = (connections?: IConnectionObject[]) => {
|
|
59
|
+
return getConnectionClients(this.dataClients, connections ?? this.room?.connections)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
getDiosphere = async (connections?: IConnectionObject[]): Promise<IDiosphere> => {
|
|
63
|
+
console.info('getDiosphere', connections)
|
|
64
|
+
await Promise.all(
|
|
65
|
+
this.getDiosphereClients(connections).map(async (connectionClient) => {
|
|
66
|
+
try {
|
|
56
67
|
const diosphereObject = await connectionClient.getDiosphere()
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
68
|
+
this.diosphere.addDiosphere(diosphereObject)
|
|
69
|
+
this.selectRoom({ id: '/' })
|
|
70
|
+
console.info(this.diosphere.toObject())
|
|
71
|
+
} catch (error) {
|
|
72
|
+
console.error(error)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return
|
|
76
|
+
}),
|
|
77
|
+
)
|
|
62
78
|
|
|
63
79
|
return this.diosphere
|
|
64
80
|
}
|
|
65
81
|
|
|
66
|
-
saveDiosphere = async (): Promise<IDiosphere> => {
|
|
67
|
-
console.info('saveDiosphere',
|
|
68
|
-
if (this.connections) {
|
|
69
|
-
const connectionClients = getConnectionClients(this.dataClients, this.connections)
|
|
82
|
+
saveDiosphere = async (connections?: IConnectionObject[]): Promise<IDiosphere> => {
|
|
83
|
+
console.info('saveDiosphere', connections)
|
|
70
84
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
)
|
|
78
|
-
|
|
85
|
+
await Promise.all(
|
|
86
|
+
this.getDiosphereClients(connections).map(async (connectionClient) => {
|
|
87
|
+
await connectionClient.saveDiosphere(this.diosphere.toObject())
|
|
88
|
+
console.info(this.diosphere.toObject())
|
|
89
|
+
|
|
90
|
+
return
|
|
91
|
+
}),
|
|
92
|
+
)
|
|
79
93
|
|
|
80
94
|
return this.diosphere
|
|
81
95
|
}
|
|
82
96
|
|
|
83
|
-
getDiograph = async (): Promise<IDiograph> => {
|
|
84
|
-
console.info('getDiograph',
|
|
85
|
-
if (this.room?.connections) {
|
|
86
|
-
const connectionClients = getConnectionClients(this.dataClients, this.room.connections)
|
|
97
|
+
getDiograph = async (connections?: IConnectionObject[]): Promise<IDiograph> => {
|
|
98
|
+
console.info('getDiograph', connections)
|
|
87
99
|
|
|
88
|
-
|
|
89
|
-
|
|
100
|
+
await Promise.all(
|
|
101
|
+
this.getDiographClients(connections).map(async (connectionClient) => {
|
|
102
|
+
try {
|
|
90
103
|
const diographObject = await connectionClient.getDiograph()
|
|
91
|
-
console.info(diographObject)
|
|
92
104
|
this.diograph.addDiograph(diographObject)
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
105
|
+
this.focusDiory({ id: '/' })
|
|
106
|
+
console.info(this.diograph.toObject())
|
|
107
|
+
} catch (error) {
|
|
108
|
+
console.error(error)
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return
|
|
112
|
+
}),
|
|
113
|
+
)
|
|
97
114
|
|
|
98
115
|
return this.diograph
|
|
99
116
|
}
|
|
100
117
|
|
|
101
|
-
saveDiograph = async (): Promise<IDiograph> => {
|
|
102
|
-
console.info('saveDiograph',
|
|
103
|
-
if (this.room?.connections) {
|
|
104
|
-
const connectionClients = getConnectionClients(this.dataClients, this.room.connections)
|
|
118
|
+
saveDiograph = async (connections?: IConnectionObject[]): Promise<IDiograph> => {
|
|
119
|
+
console.info('saveDiograph', connections)
|
|
105
120
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
)
|
|
113
|
-
|
|
121
|
+
await Promise.all(
|
|
122
|
+
this.getDiographClients(connections).map(async (connectionClient) => {
|
|
123
|
+
await connectionClient.saveDiograph(this.diograph.toObject())
|
|
124
|
+
console.info(this.diograph.toObject())
|
|
125
|
+
|
|
126
|
+
return
|
|
127
|
+
}),
|
|
128
|
+
)
|
|
114
129
|
|
|
115
130
|
return this.diograph
|
|
116
131
|
}
|
|
117
132
|
|
|
118
|
-
generateDiograph = async (): Promise<IDiograph> => {
|
|
119
|
-
console.info('generateDiograph',
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
)
|
|
137
|
-
}
|
|
133
|
+
generateDiograph = async (connections?: IConnectionObject[]): Promise<IDiograph> => {
|
|
134
|
+
console.info('generateDiograph', connections)
|
|
135
|
+
|
|
136
|
+
await Promise.all(
|
|
137
|
+
this.getDiographClients(connections).map(async (connectionClient) => {
|
|
138
|
+
const diographObject = await connectionClient.generateDiograph()
|
|
139
|
+
Object.entries(diographObject).forEach(([key, dioryObject]) => {
|
|
140
|
+
key === '/'
|
|
141
|
+
? this.diograph.addDioryLink({ id: '/' }, diographObject['/'])
|
|
142
|
+
: this.diograph.addDiory(dioryObject)
|
|
143
|
+
})
|
|
144
|
+
|
|
145
|
+
await connectionClient.saveDiograph(this.diograph.toObject())
|
|
146
|
+
console.info(this.diograph.toObject())
|
|
147
|
+
|
|
148
|
+
return
|
|
149
|
+
}),
|
|
150
|
+
)
|
|
138
151
|
|
|
139
152
|
return this.diograph
|
|
140
153
|
}
|
package/src/types.ts
CHANGED
|
@@ -59,6 +59,7 @@ export interface IDioryClient {
|
|
|
59
59
|
diograph: IDiograph
|
|
60
60
|
diory?: IDiory
|
|
61
61
|
initialise: (connections: IConnectionObject[]) => Promise<IDioryClient>
|
|
62
|
+
selectRoom: (roomObject: IRoomObject) => IRoom
|
|
62
63
|
enterRoom: (roomObject: IRoomObject) => Promise<IRoom>
|
|
63
64
|
focusDiory: (dioryObject: IDioryObject) => IDiory
|
|
64
65
|
getDiosphere: () => Promise<IDiosphere>
|
|
@@ -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)
|