@diory/client-js 0.1.2 → 0.1.4
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/connectionClient.js +10 -6
- package/dist/dioryClient.d.ts +2 -2
- package/dist/dioryClient.js +7 -18
- package/dist/dioryClient.spec.js +5 -0
- package/dist/types.d.ts +3 -4
- package/dist/utils/getConnectionClients.d.ts +3 -0
- package/dist/utils/getConnectionClients.js +16 -0
- package/package.json +3 -4
- package/src/connectionClient.ts +10 -10
- package/src/dioryClient.spec.ts +6 -0
- package/src/dioryClient.ts +6 -25
- package/src/types.ts +3 -4
- package/src/utils/getConnectionClients.ts +23 -0
package/dist/connectionClient.js
CHANGED
|
@@ -7,20 +7,24 @@ const DIOGRAPH_JSON = 'diograph.json';
|
|
|
7
7
|
class ConnectionClient {
|
|
8
8
|
constructor(dataClient, connection) {
|
|
9
9
|
this.getDiosphere = async () => {
|
|
10
|
-
const
|
|
10
|
+
const path = (0, path_browserify_1.join)(this.connection.address, DIOSPHERE_JSON);
|
|
11
|
+
const diosphereString = await this.client.readTextItem(path);
|
|
11
12
|
return JSON.parse(diosphereString);
|
|
12
13
|
};
|
|
13
14
|
this.saveDiosphere = async (diosphereObject) => {
|
|
14
|
-
const
|
|
15
|
-
|
|
15
|
+
const path = (0, path_browserify_1.join)(this.connection.address, DIOSPHERE_JSON);
|
|
16
|
+
const diosphereString = JSON.stringify(diosphereObject, null, 2);
|
|
17
|
+
return this.client.writeItem(path, diosphereString);
|
|
16
18
|
};
|
|
17
19
|
this.getDiograph = async () => {
|
|
18
|
-
const
|
|
20
|
+
const path = (0, path_browserify_1.join)(this.connection.address, DIOGRAPH_JSON);
|
|
21
|
+
const diographString = await this.client.readTextItem(path);
|
|
19
22
|
return JSON.parse(diographString);
|
|
20
23
|
};
|
|
21
24
|
this.saveDiograph = async (diographObject) => {
|
|
22
|
-
const
|
|
23
|
-
|
|
25
|
+
const path = (0, path_browserify_1.join)(this.connection.address, DIOGRAPH_JSON);
|
|
26
|
+
const diographString = JSON.stringify(diographObject, null, 2);
|
|
27
|
+
return this.client.writeItem(path, diographString);
|
|
24
28
|
};
|
|
25
29
|
this.type = dataClient.type;
|
|
26
30
|
this.client = dataClient;
|
package/dist/dioryClient.d.ts
CHANGED
|
@@ -9,8 +9,8 @@ declare class DioryClient implements IDioryClient {
|
|
|
9
9
|
diograph: IDiograph;
|
|
10
10
|
diory?: IDiory;
|
|
11
11
|
constructor(dataClients: IDataClient[]);
|
|
12
|
-
initialise: (connections: IConnectionObject[]) => Promise<
|
|
13
|
-
enterRoom: (roomObject: IRoomObject) => Promise<
|
|
12
|
+
initialise: (connections: IConnectionObject[]) => Promise<IDioryClient>;
|
|
13
|
+
enterRoom: (roomObject: IRoomObject) => Promise<IRoom>;
|
|
14
14
|
focusDiory: (dioryObject: IDioryObject) => IDiory;
|
|
15
15
|
getDiosphere: () => Promise<void>;
|
|
16
16
|
saveDiosphere: () => Promise<void>;
|
package/dist/dioryClient.js
CHANGED
|
@@ -3,18 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.DioryClient = void 0;
|
|
4
4
|
const diosphere_js_1 = require("@diory/diosphere-js");
|
|
5
5
|
const diograph_1 = require("@diograph/diograph");
|
|
6
|
-
const
|
|
7
|
-
function getDataClient(dataClients, { client }) {
|
|
8
|
-
return dataClients.find(({ type }) => type === client);
|
|
9
|
-
}
|
|
10
|
-
function getConnectionClients(dataClients, connections) {
|
|
11
|
-
return connections
|
|
12
|
-
.filter(({ client }) => dataClients.some(({ type }) => type === client))
|
|
13
|
-
.map((connection) => {
|
|
14
|
-
const dataClient = getDataClient(dataClients, connection);
|
|
15
|
-
return new connectionClient_1.ConnectionClient(dataClient, connection);
|
|
16
|
-
});
|
|
17
|
-
}
|
|
6
|
+
const getConnectionClients_1 = require("./utils/getConnectionClients");
|
|
18
7
|
class DioryClient {
|
|
19
8
|
constructor(dataClients) {
|
|
20
9
|
this.dataClients = [];
|
|
@@ -24,11 +13,11 @@ class DioryClient {
|
|
|
24
13
|
this.diosphere.resetRooms();
|
|
25
14
|
await this.getDiosphere();
|
|
26
15
|
await this.enterRoom({ id: '/' });
|
|
27
|
-
return;
|
|
16
|
+
return this;
|
|
28
17
|
};
|
|
29
18
|
this.enterRoom = async (roomObject) => {
|
|
30
19
|
this.room = this.diosphere.getRoom(roomObject);
|
|
31
|
-
this.diograph.
|
|
20
|
+
this.diograph.resetDiograph();
|
|
32
21
|
await this.getDiograph();
|
|
33
22
|
this.focusDiory({ id: '/' });
|
|
34
23
|
return this.room;
|
|
@@ -39,7 +28,7 @@ class DioryClient {
|
|
|
39
28
|
this.getDiosphere = async () => {
|
|
40
29
|
console.info('getDiosphere', this.connections);
|
|
41
30
|
if (this.connections) {
|
|
42
|
-
const connectionClients = getConnectionClients(this.dataClients, this.connections);
|
|
31
|
+
const connectionClients = (0, getConnectionClients_1.getConnectionClients)(this.dataClients, this.connections);
|
|
43
32
|
await Promise.all(connectionClients.map(async (connectionClient) => {
|
|
44
33
|
const diosphereObject = await connectionClient.getDiosphere();
|
|
45
34
|
console.info(diosphereObject);
|
|
@@ -51,7 +40,7 @@ class DioryClient {
|
|
|
51
40
|
this.saveDiosphere = async () => {
|
|
52
41
|
console.info('saveDiosphere', this.connections);
|
|
53
42
|
if (this.connections) {
|
|
54
|
-
const connectionClients = getConnectionClients(this.dataClients, this.connections);
|
|
43
|
+
const connectionClients = (0, getConnectionClients_1.getConnectionClients)(this.dataClients, this.connections);
|
|
55
44
|
await Promise.all(connectionClients.map((connectionClient) => {
|
|
56
45
|
console.info(this.diosphere.toObject());
|
|
57
46
|
return connectionClient.saveDiosphere(this.diosphere.toObject());
|
|
@@ -63,7 +52,7 @@ class DioryClient {
|
|
|
63
52
|
var _a, _b;
|
|
64
53
|
console.info('getDiograph', (_a = this.room) === null || _a === void 0 ? void 0 : _a.connections);
|
|
65
54
|
if ((_b = this.room) === null || _b === void 0 ? void 0 : _b.connections) {
|
|
66
|
-
const connectionClients = getConnectionClients(this.dataClients, this.room.connections);
|
|
55
|
+
const connectionClients = (0, getConnectionClients_1.getConnectionClients)(this.dataClients, this.room.connections);
|
|
67
56
|
await Promise.all(connectionClients.map(async (connectionClient) => {
|
|
68
57
|
const diographObject = await connectionClient.getDiograph();
|
|
69
58
|
console.info(diographObject);
|
|
@@ -76,7 +65,7 @@ class DioryClient {
|
|
|
76
65
|
var _a, _b;
|
|
77
66
|
console.info('saveDiograph', (_a = this.room) === null || _a === void 0 ? void 0 : _a.connections);
|
|
78
67
|
if ((_b = this.room) === null || _b === void 0 ? void 0 : _b.connections) {
|
|
79
|
-
const connectionClients = getConnectionClients(this.dataClients, this.room.connections);
|
|
68
|
+
const connectionClients = (0, getConnectionClients_1.getConnectionClients)(this.dataClients, this.room.connections);
|
|
80
69
|
await Promise.all(connectionClients.map((connectionClient) => {
|
|
81
70
|
console.info(this.diograph.toObject());
|
|
82
71
|
return connectionClient.saveDiograph(this.diograph.toObject());
|
package/dist/dioryClient.spec.js
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
describe('dioryClient', () => {
|
|
3
|
+
describe('constructor()', () => {
|
|
4
|
+
it('should construct with dataClient', () => {
|
|
5
|
+
expect(true).toEqual(true);
|
|
6
|
+
});
|
|
7
|
+
});
|
|
3
8
|
describe('initialise()', () => {
|
|
4
9
|
it('should initialise with connections', () => {
|
|
5
10
|
expect(true).toEqual(true);
|
package/dist/types.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { IConnectionObject, IDiosphere, IDiosphereObject, IRoom, IRoomObject } from '@diory/diosphere-js';
|
|
3
|
-
import { IDiograph, IDiory } from '@diograph/diograph';
|
|
4
|
-
import { IDiographObject, IDioryObject } from '@diograph/diograph';
|
|
3
|
+
import { IDiographObject, IDiograph, IDiory, IDioryObject } from '@diograph/diograph';
|
|
5
4
|
export interface IDataClient {
|
|
6
5
|
type: string;
|
|
7
6
|
readTextItem(url: string): Promise<string>;
|
|
@@ -30,8 +29,8 @@ export interface IDioryClient {
|
|
|
30
29
|
room?: IRoom;
|
|
31
30
|
diograph: IDiograph;
|
|
32
31
|
diory?: IDiory;
|
|
33
|
-
initialise: (connections: IConnectionObject[]) => Promise<
|
|
34
|
-
enterRoom: (roomObject: IRoomObject) => Promise<
|
|
32
|
+
initialise: (connections: IConnectionObject[]) => Promise<IDioryClient>;
|
|
33
|
+
enterRoom: (roomObject: IRoomObject) => Promise<IRoom>;
|
|
35
34
|
focusDiory: (dioryObject: IDioryObject) => IDiory;
|
|
36
35
|
getDiosphere: () => void;
|
|
37
36
|
saveDiosphere: () => void;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getConnectionClients = void 0;
|
|
4
|
+
const connectionClient_1 = require("../connectionClient");
|
|
5
|
+
function getDataClient(dataClients, { client }) {
|
|
6
|
+
return dataClients.find(({ type }) => type === client);
|
|
7
|
+
}
|
|
8
|
+
function getConnectionClients(dataClients, connections) {
|
|
9
|
+
return connections
|
|
10
|
+
.filter(({ client }) => dataClients.some(({ type }) => type === client))
|
|
11
|
+
.map((connection) => {
|
|
12
|
+
const dataClient = getDataClient(dataClients, connection);
|
|
13
|
+
return new connectionClient_1.ConnectionClient(dataClient, connection);
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
exports.getConnectionClients = getConnectionClients;
|
package/package.json
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@diory/client-js",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
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": "
|
|
10
|
-
"@diory/diosphere-js": "
|
|
11
|
-
"path": "^0.12.7",
|
|
9
|
+
"@diograph/diograph": "0.3.0-rc12",
|
|
10
|
+
"@diory/diosphere-js": "0.2.6-rc1",
|
|
12
11
|
"path-browserify": "^1.0.1",
|
|
13
12
|
"uuid": "8.3.2"
|
|
14
13
|
},
|
package/src/connectionClient.ts
CHANGED
|
@@ -19,27 +19,27 @@ class ConnectionClient implements IConnectionClient {
|
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
getDiosphere = async () => {
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
)
|
|
22
|
+
const path = join(this.connection.address, DIOSPHERE_JSON)
|
|
23
|
+
const diosphereString = await this.client.readTextItem(path)
|
|
25
24
|
return JSON.parse(diosphereString)
|
|
26
25
|
}
|
|
27
26
|
|
|
28
27
|
saveDiosphere = async (diosphereObject: IDiosphereObject) => {
|
|
29
|
-
const
|
|
30
|
-
|
|
28
|
+
const path = join(this.connection.address, DIOSPHERE_JSON)
|
|
29
|
+
const diosphereString = JSON.stringify(diosphereObject, null, 2)
|
|
30
|
+
return this.client.writeItem(path, diosphereString)
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
getDiograph = async () => {
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
)
|
|
34
|
+
const path = join(this.connection.address, DIOGRAPH_JSON)
|
|
35
|
+
const diographString = await this.client.readTextItem(path)
|
|
37
36
|
return JSON.parse(diographString)
|
|
38
37
|
}
|
|
39
38
|
|
|
40
39
|
saveDiograph = async (diographObject: IDiographObject) => {
|
|
41
|
-
const
|
|
42
|
-
|
|
40
|
+
const path = join(this.connection.address, DIOGRAPH_JSON)
|
|
41
|
+
const diographString = JSON.stringify(diographObject, null, 2)
|
|
42
|
+
return this.client.writeItem(path, diographString)
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
45
|
|
package/src/dioryClient.spec.ts
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
describe('dioryClient', () => {
|
|
2
|
+
describe('constructor()', () => {
|
|
3
|
+
it('should construct with dataClient', () => {
|
|
4
|
+
expect(true).toEqual(true)
|
|
5
|
+
})
|
|
6
|
+
})
|
|
7
|
+
|
|
2
8
|
describe('initialise()', () => {
|
|
3
9
|
it('should initialise with connections', () => {
|
|
4
10
|
expect(true).toEqual(true)
|
package/src/dioryClient.ts
CHANGED
|
@@ -1,27 +1,8 @@
|
|
|
1
1
|
import { Diosphere, IConnectionObject, IDiosphere, IRoom, IRoomObject } from '@diory/diosphere-js'
|
|
2
2
|
import { Diograph, IDiograph, IDiory, IDioryObject } from '@diograph/diograph'
|
|
3
3
|
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
function getDataClient(
|
|
8
|
-
dataClients: IDataClient[],
|
|
9
|
-
{ client }: IConnectionObject,
|
|
10
|
-
): IDataClient | undefined {
|
|
11
|
-
return dataClients.find(({ type }) => type === client)
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
function getConnectionClients(
|
|
15
|
-
dataClients: IDataClient[],
|
|
16
|
-
connections: IConnectionObject[],
|
|
17
|
-
): IConnectionClient[] {
|
|
18
|
-
return connections
|
|
19
|
-
.filter(({ client }) => dataClients.some(({ type }) => type === client))
|
|
20
|
-
.map((connection) => {
|
|
21
|
-
const dataClient = getDataClient(dataClients, connection)
|
|
22
|
-
return new ConnectionClient(dataClient!, connection)
|
|
23
|
-
}) as IConnectionClient[]
|
|
24
|
-
}
|
|
4
|
+
import { IDataClient, IDioryClient } from './types'
|
|
5
|
+
import { getConnectionClients } from './utils/getConnectionClients'
|
|
25
6
|
|
|
26
7
|
class DioryClient implements IDioryClient {
|
|
27
8
|
dataClients: IDataClient[] = []
|
|
@@ -41,20 +22,20 @@ class DioryClient implements IDioryClient {
|
|
|
41
22
|
this.diograph.saveDiograph = this.saveDiograph
|
|
42
23
|
}
|
|
43
24
|
|
|
44
|
-
initialise = async (connections: IConnectionObject[]): Promise<
|
|
25
|
+
initialise = async (connections: IConnectionObject[]): Promise<IDioryClient> => {
|
|
45
26
|
this.connections = connections
|
|
46
27
|
|
|
47
28
|
this.diosphere.resetRooms()
|
|
48
29
|
await this.getDiosphere()
|
|
49
30
|
await this.enterRoom({ id: '/' })
|
|
50
31
|
|
|
51
|
-
return
|
|
32
|
+
return this
|
|
52
33
|
}
|
|
53
34
|
|
|
54
|
-
enterRoom = async (roomObject: IRoomObject): Promise<
|
|
35
|
+
enterRoom = async (roomObject: IRoomObject): Promise<IRoom> => {
|
|
55
36
|
this.room = this.diosphere.getRoom(roomObject)
|
|
56
37
|
|
|
57
|
-
this.diograph.
|
|
38
|
+
this.diograph.resetDiograph()
|
|
58
39
|
await this.getDiograph()
|
|
59
40
|
this.focusDiory({ id: '/' })
|
|
60
41
|
|
package/src/types.ts
CHANGED
|
@@ -5,8 +5,7 @@ import {
|
|
|
5
5
|
IRoom,
|
|
6
6
|
IRoomObject,
|
|
7
7
|
} from '@diory/diosphere-js'
|
|
8
|
-
import { IDiograph, IDiory } from '@diograph/diograph'
|
|
9
|
-
import { IDiographObject, IDioryObject } from '@diograph/diograph'
|
|
8
|
+
import { IDiographObject, IDiograph, IDiory, IDioryObject } from '@diograph/diograph'
|
|
10
9
|
|
|
11
10
|
export interface IDataClient {
|
|
12
11
|
type: string
|
|
@@ -38,8 +37,8 @@ export interface IDioryClient {
|
|
|
38
37
|
room?: IRoom
|
|
39
38
|
diograph: IDiograph
|
|
40
39
|
diory?: IDiory
|
|
41
|
-
initialise: (connections: IConnectionObject[]) => Promise<
|
|
42
|
-
enterRoom: (roomObject: IRoomObject) => Promise<
|
|
40
|
+
initialise: (connections: IConnectionObject[]) => Promise<IDioryClient>
|
|
41
|
+
enterRoom: (roomObject: IRoomObject) => Promise<IRoom>
|
|
43
42
|
focusDiory: (dioryObject: IDioryObject) => IDiory
|
|
44
43
|
getDiosphere: () => void
|
|
45
44
|
saveDiosphere: () => void
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { IConnectionObject } from '@diory/diosphere-js'
|
|
2
|
+
|
|
3
|
+
import { IConnectionClient, IDataClient } from '../types'
|
|
4
|
+
import { ConnectionClient } from '../connectionClient'
|
|
5
|
+
|
|
6
|
+
function getDataClient(
|
|
7
|
+
dataClients: IDataClient[],
|
|
8
|
+
{ client }: IConnectionObject,
|
|
9
|
+
): IDataClient | undefined {
|
|
10
|
+
return dataClients.find(({ type }) => type === client)
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function getConnectionClients(
|
|
14
|
+
dataClients: IDataClient[],
|
|
15
|
+
connections: IConnectionObject[],
|
|
16
|
+
): IConnectionClient[] {
|
|
17
|
+
return connections
|
|
18
|
+
.filter(({ client }) => dataClients.some(({ type }) => type === client))
|
|
19
|
+
.map((connection) => {
|
|
20
|
+
const dataClient = getDataClient(dataClients, connection)
|
|
21
|
+
return new ConnectionClient(dataClient!, connection)
|
|
22
|
+
}) as IConnectionClient[]
|
|
23
|
+
}
|