@diory/client-js 0.1.2 → 0.1.3
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 +6 -9
- 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 -8
- package/src/connectionClient.ts +6 -15
- 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
|
@@ -1,26 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ConnectionClient = void 0;
|
|
4
|
-
const path_browserify_1 = require("path-browserify");
|
|
5
|
-
const DIOSPHERE_JSON = 'diosphere.json';
|
|
6
|
-
const DIOGRAPH_JSON = 'diograph.json';
|
|
7
4
|
class ConnectionClient {
|
|
8
5
|
constructor(dataClient, connection) {
|
|
9
6
|
this.getDiosphere = async () => {
|
|
10
|
-
const diosphereString = await this.client.readTextItem(
|
|
7
|
+
const diosphereString = await this.client.readTextItem(this.connection.address);
|
|
11
8
|
return JSON.parse(diosphereString);
|
|
12
9
|
};
|
|
13
10
|
this.saveDiosphere = async (diosphereObject) => {
|
|
14
|
-
const diosphereString = JSON.stringify(diosphereObject);
|
|
15
|
-
return this.client.writeItem(
|
|
11
|
+
const diosphereString = JSON.stringify(diosphereObject, null, 2);
|
|
12
|
+
return this.client.writeItem(this.connection.address, diosphereString);
|
|
16
13
|
};
|
|
17
14
|
this.getDiograph = async () => {
|
|
18
|
-
const diographString = await this.client.readTextItem(
|
|
15
|
+
const diographString = await this.client.readTextItem(this.connection.address);
|
|
19
16
|
return JSON.parse(diographString);
|
|
20
17
|
};
|
|
21
18
|
this.saveDiograph = async (diographObject) => {
|
|
22
|
-
const
|
|
23
|
-
return this.client.writeItem(
|
|
19
|
+
const diographString = JSON.stringify(diographObject, null, 2);
|
|
20
|
+
return this.client.writeItem(this.connection.address, diographString);
|
|
24
21
|
};
|
|
25
22
|
this.type = dataClient.type;
|
|
26
23
|
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,21 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@diory/client-js",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
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",
|
|
12
|
-
"path-browserify": "^1.0.1",
|
|
13
|
-
"uuid": "8.3.2"
|
|
9
|
+
"@diograph/diograph": "0.3.0-rc12",
|
|
10
|
+
"@diory/diosphere-js": "0.2.6-rc1"
|
|
14
11
|
},
|
|
15
12
|
"devDependencies": {
|
|
16
13
|
"@types/jest": "^27.4.0",
|
|
17
|
-
"@types/path-browserify": "^1.0.2",
|
|
18
|
-
"@types/uuid": "8.3.2",
|
|
19
14
|
"jest": "^27.5.0",
|
|
20
15
|
"prettier": "^2.5.1",
|
|
21
16
|
"ts-jest": "^27.1.3",
|
package/src/connectionClient.ts
CHANGED
|
@@ -1,12 +1,7 @@
|
|
|
1
|
-
import { join } from 'path-browserify'
|
|
2
|
-
|
|
3
1
|
import { IDiographObject } from '@diograph/diograph'
|
|
4
2
|
import { IConnectionObject, IDiosphereObject } from '@diory/diosphere-js'
|
|
5
3
|
import { IConnectionClient, IDataClient } from './types'
|
|
6
4
|
|
|
7
|
-
const DIOSPHERE_JSON = 'diosphere.json'
|
|
8
|
-
const DIOGRAPH_JSON = 'diograph.json'
|
|
9
|
-
|
|
10
5
|
class ConnectionClient implements IConnectionClient {
|
|
11
6
|
type: string
|
|
12
7
|
client: IDataClient
|
|
@@ -19,27 +14,23 @@ class ConnectionClient implements IConnectionClient {
|
|
|
19
14
|
}
|
|
20
15
|
|
|
21
16
|
getDiosphere = async () => {
|
|
22
|
-
const diosphereString = await this.client.readTextItem(
|
|
23
|
-
join(this.connection.address, DIOSPHERE_JSON),
|
|
24
|
-
)
|
|
17
|
+
const diosphereString = await this.client.readTextItem(this.connection.address)
|
|
25
18
|
return JSON.parse(diosphereString)
|
|
26
19
|
}
|
|
27
20
|
|
|
28
21
|
saveDiosphere = async (diosphereObject: IDiosphereObject) => {
|
|
29
|
-
const diosphereString = JSON.stringify(diosphereObject)
|
|
30
|
-
return this.client.writeItem(
|
|
22
|
+
const diosphereString = JSON.stringify(diosphereObject, null, 2)
|
|
23
|
+
return this.client.writeItem(this.connection.address, diosphereString)
|
|
31
24
|
}
|
|
32
25
|
|
|
33
26
|
getDiograph = async () => {
|
|
34
|
-
const diographString = await this.client.readTextItem(
|
|
35
|
-
join(this.connection.address, DIOGRAPH_JSON),
|
|
36
|
-
)
|
|
27
|
+
const diographString = await this.client.readTextItem(this.connection.address)
|
|
37
28
|
return JSON.parse(diographString)
|
|
38
29
|
}
|
|
39
30
|
|
|
40
31
|
saveDiograph = async (diographObject: IDiographObject) => {
|
|
41
|
-
const
|
|
42
|
-
return this.client.writeItem(
|
|
32
|
+
const diographString = JSON.stringify(diographObject, null, 2)
|
|
33
|
+
return this.client.writeItem(this.connection.address, diographString)
|
|
43
34
|
}
|
|
44
35
|
}
|
|
45
36
|
|
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
|
+
}
|