@diory/client-js 0.2.2 → 0.4.0-rc2
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 +2 -1
- package/dist/connectionClient/connectionClient.d.ts +15 -13
- package/dist/connectionClient/connectionClient.js +92 -36
- package/dist/connectionClient/connectionClient.spec.js +17 -17
- package/dist/dioryClient/addDefaultDiograph.d.ts +2 -0
- package/dist/dioryClient/addDefaultDiograph.js +17 -0
- package/dist/dioryClient/addDefaultRoom.d.ts +5 -0
- package/dist/dioryClient/addDefaultRoom.js +13 -0
- package/dist/dioryClient/dioryClient.d.ts +8 -17
- package/dist/dioryClient/dioryClient.js +25 -114
- package/dist/dioryClient/getDefaultDiograph.d.ts +2 -2
- package/dist/dioryClient/getDefaultDiograph.js +19 -16
- package/dist/dioryClient/getDefaultDiosphere.d.ts +2 -2
- package/dist/dioryClient/getDefaultDiosphere.js +15 -12
- package/dist/index.d.ts +1 -2
- package/dist/index.js +1 -3
- package/dist/types.d.ts +8 -57
- package/dist/utils/addDefaultDiograph.d.ts +2 -0
- package/dist/utils/addDefaultDiograph.js +14 -0
- package/dist/utils/addDefaultRoom.d.ts +2 -0
- package/dist/utils/addDefaultRoom.js +10 -0
- package/dist/utils/getConnectionClients.d.ts +7 -3
- package/dist/utils/getConnectionClients.js +12 -12
- package/package.json +5 -4
- package/src/dioryClient/dioryClient.ts +32 -155
- package/src/index.ts +1 -2
- package/src/types.ts +8 -66
- package/src/{dioryClient/getDefaultDiograph.ts → utils/addDefaultDiograph.ts} +3 -6
- package/src/utils/addDefaultRoom.ts +11 -0
- package/src/connectionClient/connectionClient.spec.ts +0 -19
- package/src/connectionClient/connectionClient.ts +0 -52
- package/src/dioryClient/getDefaultDiosphere.ts +0 -14
- package/src/utils/getConnectionClients.ts +0 -23
package/README.md
CHANGED
|
@@ -12,7 +12,8 @@ yarn add @diory/client-js
|
|
|
12
12
|
|
|
13
13
|
```
|
|
14
14
|
const clients = [localClient, S3Client, ...]
|
|
15
|
-
const
|
|
15
|
+
const dioryClient = DioryClient(clients)
|
|
16
|
+
dioryClient.initialiseDiosphere([connections])
|
|
16
17
|
diosphere.initialise([connection])
|
|
17
18
|
diosphere.enterRoom(room)
|
|
18
19
|
diograph.focusDiory(diory)
|
|
@@ -1,15 +1,17 @@
|
|
|
1
|
-
import { IDiographObject } from '@diograph/diograph'
|
|
2
|
-
import { IConnectionObject, IDiosphereObject } from '@diory/diosphere-js'
|
|
3
|
-
import {
|
|
1
|
+
import { IDiographObject } from '@diograph/diograph'
|
|
2
|
+
import { IConnectionObject, IDiosphereObject } from '@diory/diosphere-js'
|
|
3
|
+
import { IDataClient } from '@diograph/local-client'
|
|
4
|
+
import { IConnectionClient } from '../types'
|
|
4
5
|
declare class ConnectionClient implements IConnectionClient {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
6
|
+
dataClients: IDataClient[]
|
|
7
|
+
connections: IConnectionObject[]
|
|
8
|
+
constructor(dataClients: IDataClient[])
|
|
9
|
+
initialiseConnections: (connections?: IConnectionObject[]) => IConnectionClient
|
|
10
|
+
findDataClient: ({ client }: IConnectionObject) => IDataClient | undefined
|
|
11
|
+
getDiosphere: () => Promise<IDiosphereObject | undefined>
|
|
12
|
+
saveDiosphere: (diosphereObject: IDiosphereObject) => Promise<void>
|
|
13
|
+
getDiograph: () => Promise<IDiographObject | undefined>
|
|
14
|
+
saveDiograph: (diographObject: IDiographObject) => Promise<void>
|
|
15
|
+
generateDiograph: () => Promise<IDiographObject>
|
|
14
16
|
}
|
|
15
|
-
export { ConnectionClient }
|
|
17
|
+
export { ConnectionClient }
|
|
@@ -1,39 +1,95 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports,
|
|
3
|
-
exports.ConnectionClient = void 0
|
|
4
|
-
const path_browserify_1 = require(
|
|
5
|
-
const folder_generator_1 = require(
|
|
6
|
-
const DIOSPHERE_JSON = 'diosphere.json'
|
|
7
|
-
const DIOGRAPH_JSON = 'diograph.json'
|
|
1
|
+
'use strict'
|
|
2
|
+
Object.defineProperty(exports, '__esModule', { value: true })
|
|
3
|
+
exports.ConnectionClient = void 0
|
|
4
|
+
const path_browserify_1 = require('path-browserify')
|
|
5
|
+
const folder_generator_1 = require('@diograph/folder-generator')
|
|
6
|
+
const DIOSPHERE_JSON = 'diosphere.json'
|
|
7
|
+
const DIOGRAPH_JSON = 'diograph.json'
|
|
8
8
|
class ConnectionClient {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
};
|
|
15
|
-
this.saveDiosphere = async (diosphereObject) => {
|
|
16
|
-
const path = (0, path_browserify_1.join)(this.connection.address, DIOSPHERE_JSON);
|
|
17
|
-
const diosphereString = JSON.stringify(diosphereObject, null, 2);
|
|
18
|
-
return this.client.writeItem(path, diosphereString);
|
|
19
|
-
};
|
|
20
|
-
this.getDiograph = async () => {
|
|
21
|
-
const path = (0, path_browserify_1.join)(this.connection.address, DIOGRAPH_JSON);
|
|
22
|
-
const diographString = await this.client.readTextItem(path);
|
|
23
|
-
return JSON.parse(diographString);
|
|
24
|
-
};
|
|
25
|
-
this.saveDiograph = async (diographObject) => {
|
|
26
|
-
const path = (0, path_browserify_1.join)(this.connection.address, DIOGRAPH_JSON);
|
|
27
|
-
const diographString = JSON.stringify(diographObject, null, 2);
|
|
28
|
-
return this.client.writeItem(path, diographString);
|
|
29
|
-
};
|
|
30
|
-
this.generateDiograph = async () => {
|
|
31
|
-
const { diograph } = await (0, folder_generator_1.generateDiograph)(this.connection.address, this.client);
|
|
32
|
-
return diograph.toObject();
|
|
33
|
-
};
|
|
34
|
-
this.type = dataClient.type;
|
|
35
|
-
this.client = dataClient;
|
|
36
|
-
this.connection = connection;
|
|
9
|
+
constructor(dataClients) {
|
|
10
|
+
this.connections = []
|
|
11
|
+
this.initialiseConnections = (connections = []) => {
|
|
12
|
+
this.connections = connections
|
|
13
|
+
return this
|
|
37
14
|
}
|
|
15
|
+
this.findDataClient = ({ client }) => {
|
|
16
|
+
return this.dataClients.find(({ type }) => type === client)
|
|
17
|
+
}
|
|
18
|
+
this.getDiosphere = async () => {
|
|
19
|
+
let diosphereObject
|
|
20
|
+
await Promise.all(
|
|
21
|
+
this.connections.map(async (connection) => {
|
|
22
|
+
const client = this.findDataClient(connection)
|
|
23
|
+
if (client) {
|
|
24
|
+
const path = (0, path_browserify_1.join)(connection.address, DIOSPHERE_JSON)
|
|
25
|
+
const diosphereString = await client.readTextItem(path)
|
|
26
|
+
diosphereObject = JSON.parse(diosphereString)
|
|
27
|
+
}
|
|
28
|
+
}),
|
|
29
|
+
)
|
|
30
|
+
// @ts-ignore
|
|
31
|
+
return diosphereObject
|
|
32
|
+
}
|
|
33
|
+
this.saveDiosphere = async (diosphereObject) => {
|
|
34
|
+
await Promise.all(
|
|
35
|
+
this.connections.map(async (connection) => {
|
|
36
|
+
const client = this.findDataClient(connection)
|
|
37
|
+
if (client) {
|
|
38
|
+
const path = (0, path_browserify_1.join)(connection.address, DIOSPHERE_JSON)
|
|
39
|
+
const diosphereString = JSON.stringify(diosphereObject, null, 2)
|
|
40
|
+
return client.writeItem(path, diosphereString)
|
|
41
|
+
}
|
|
42
|
+
}),
|
|
43
|
+
)
|
|
44
|
+
return
|
|
45
|
+
}
|
|
46
|
+
this.getDiograph = async () => {
|
|
47
|
+
let diographObject
|
|
48
|
+
await Promise.all(
|
|
49
|
+
this.connections.map(async (connection) => {
|
|
50
|
+
const client = this.findDataClient(connection)
|
|
51
|
+
if (client) {
|
|
52
|
+
const path = (0, path_browserify_1.join)(connection.address, DIOGRAPH_JSON)
|
|
53
|
+
const diographString = await client.readTextItem(path)
|
|
54
|
+
diographObject = JSON.parse(diographString)
|
|
55
|
+
}
|
|
56
|
+
}),
|
|
57
|
+
)
|
|
58
|
+
// @ts-ignore
|
|
59
|
+
return diographObject
|
|
60
|
+
}
|
|
61
|
+
this.saveDiograph = async (diographObject) => {
|
|
62
|
+
await Promise.all(
|
|
63
|
+
this.connections.map(async (connection) => {
|
|
64
|
+
const client = this.findDataClient(connection)
|
|
65
|
+
if (client) {
|
|
66
|
+
const path = (0, path_browserify_1.join)(connection.address, DIOGRAPH_JSON)
|
|
67
|
+
const diosphereString = JSON.stringify(diographObject, null, 2)
|
|
68
|
+
return client.writeItem(path, diosphereString)
|
|
69
|
+
}
|
|
70
|
+
}),
|
|
71
|
+
)
|
|
72
|
+
return
|
|
73
|
+
}
|
|
74
|
+
this.generateDiograph = async () => {
|
|
75
|
+
let diographObject
|
|
76
|
+
await Promise.all(
|
|
77
|
+
this.connections.map(async (connection) => {
|
|
78
|
+
const client = this.findDataClient(connection)
|
|
79
|
+
if (client) {
|
|
80
|
+
const { diograph } = await (0, folder_generator_1.generateDiograph)(
|
|
81
|
+
connection.address,
|
|
82
|
+
client,
|
|
83
|
+
)
|
|
84
|
+
diographObject = diograph.toObject()
|
|
85
|
+
return
|
|
86
|
+
}
|
|
87
|
+
}),
|
|
88
|
+
)
|
|
89
|
+
// @ts-ignore
|
|
90
|
+
return diographObject
|
|
91
|
+
}
|
|
92
|
+
this.dataClients = dataClients
|
|
93
|
+
}
|
|
38
94
|
}
|
|
39
|
-
exports.ConnectionClient = ConnectionClient
|
|
95
|
+
exports.ConnectionClient = ConnectionClient
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict'
|
|
2
2
|
describe('connectionClient', () => {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
})
|
|
3
|
+
describe('construct()', () => {
|
|
4
|
+
it('should construct with dataClient and connection', () => {
|
|
5
|
+
expect(true).toEqual(true)
|
|
6
|
+
})
|
|
7
|
+
})
|
|
8
|
+
describe('getDiosphere()', () => {
|
|
9
|
+
it('should get diosphere', () => {
|
|
10
|
+
expect(true).toEqual(true)
|
|
11
|
+
})
|
|
12
|
+
})
|
|
13
|
+
describe('saveDiosphere()', () => {
|
|
14
|
+
it('should save diosphere object', () => {
|
|
15
|
+
expect(true).toEqual(true)
|
|
16
|
+
})
|
|
17
|
+
})
|
|
18
|
+
})
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
Object.defineProperty(exports, '__esModule', { value: true })
|
|
3
|
+
exports.addDefaultDiograph = void 0
|
|
4
|
+
const addDefaultDiograph = (diograph) => {
|
|
5
|
+
const diory = diograph.addDiory({
|
|
6
|
+
text: 'Welcome to Diory',
|
|
7
|
+
latlng: '60.01366036242365, 20.007133483886722',
|
|
8
|
+
})
|
|
9
|
+
diograph.addDiory(
|
|
10
|
+
{
|
|
11
|
+
text: 'Root diory',
|
|
12
|
+
links: [{ id: diory.id }],
|
|
13
|
+
},
|
|
14
|
+
'/',
|
|
15
|
+
)
|
|
16
|
+
}
|
|
17
|
+
exports.addDefaultDiograph = addDefaultDiograph
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
Object.defineProperty(exports, '__esModule', { value: true })
|
|
3
|
+
exports.addDefaultRoom = void 0
|
|
4
|
+
const addDefaultRoom = (diosphere, connections) => {
|
|
5
|
+
diosphere.addRoom(
|
|
6
|
+
{
|
|
7
|
+
text: 'Home room',
|
|
8
|
+
connections,
|
|
9
|
+
},
|
|
10
|
+
'/',
|
|
11
|
+
)
|
|
12
|
+
}
|
|
13
|
+
exports.addDefaultRoom = addDefaultRoom
|
|
@@ -1,25 +1,16 @@
|
|
|
1
|
-
import { IConnectionObject, IDiosphere,
|
|
2
|
-
import { IDiograph,
|
|
3
|
-
import {
|
|
1
|
+
import { IConnectionObject, IDiosphere, IRoom, IRoomObject } from '@diory/diosphere-js';
|
|
2
|
+
import { IDiograph, IDiory, IDioryObject } from '@diograph/diograph';
|
|
3
|
+
import { IDataClient } from '@diograph/local-client';
|
|
4
|
+
import { IDioryClient } from '../types';
|
|
4
5
|
declare class DioryClient implements IDioryClient {
|
|
5
|
-
dataClients: IDataClient[];
|
|
6
|
-
connections: IConnectionObject[];
|
|
7
6
|
diosphere: IDiosphere;
|
|
8
|
-
room?: IRoom;
|
|
9
7
|
diograph: IDiograph;
|
|
8
|
+
room?: IRoom;
|
|
10
9
|
diory?: IDiory;
|
|
11
10
|
constructor(dataClients: IDataClient[]);
|
|
12
|
-
focusDiory: (dioryObject: IDioryObject) => IDiory;
|
|
13
|
-
selectRoom: (roomObject: IRoomObject) => IRoom;
|
|
14
|
-
getDiographClients: (connections?: IConnectionObject[]) => import("../types").IConnectionClient[];
|
|
15
|
-
initialiseDiograph: (roomObject: IRoomObject) => Promise<IDiograph>;
|
|
16
|
-
getDiograph: () => Promise<IDiographObject | undefined>;
|
|
17
|
-
saveDiograph: () => Promise<IDiographObject>;
|
|
18
|
-
importDiograph: (connections?: IConnectionObject[]) => Promise<IDiograph>;
|
|
19
|
-
generateDiograph: (connections?: IConnectionObject[]) => Promise<IDiographObject | undefined>;
|
|
20
|
-
getDiosphereClients: (connections?: IConnectionObject[]) => import("../types").IConnectionClient[];
|
|
21
11
|
initialiseDiosphere: (connections: IConnectionObject[]) => Promise<IDiosphere>;
|
|
22
|
-
|
|
23
|
-
|
|
12
|
+
initialiseDiograph: (roomObject: IRoomObject) => Promise<IDiograph>;
|
|
13
|
+
selectRoom: (roomObject: IRoomObject) => IRoom;
|
|
14
|
+
focusDiory: (dioryObject: IDioryObject) => IDiory;
|
|
24
15
|
}
|
|
25
16
|
export { DioryClient };
|
|
@@ -3,132 +3,43 @@ 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
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const getDefaultDiograph_1 = require("./getDefaultDiograph");
|
|
6
|
+
const local_client_1 = require("@diograph/local-client");
|
|
7
|
+
const addDefaultRoom_1 = require("../utils/addDefaultRoom");
|
|
8
|
+
const addDefaultDiograph_1 = require("../utils/addDefaultDiograph");
|
|
10
9
|
class DioryClient {
|
|
11
10
|
constructor(dataClients) {
|
|
12
|
-
this.
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
var _a;
|
|
22
|
-
return (0, getConnectionClients_1.getConnectionClients)(this.dataClients, connections !== null && connections !== void 0 ? connections : (_a = this.room) === null || _a === void 0 ? void 0 : _a.connections);
|
|
11
|
+
this.initialiseDiosphere = async (connections) => {
|
|
12
|
+
console.info('initialiseDiosphere: connections', connections);
|
|
13
|
+
this.diosphere.initialise(connections);
|
|
14
|
+
await this.diosphere.getDiosphere();
|
|
15
|
+
if (!Object.keys(this.diosphere.rooms)) {
|
|
16
|
+
(0, addDefaultRoom_1.addDefaultRoom)(this.diosphere, connections);
|
|
17
|
+
}
|
|
18
|
+
this.selectRoom({ id: '/' });
|
|
19
|
+
return this.diosphere;
|
|
23
20
|
};
|
|
24
21
|
this.initialiseDiograph = async (roomObject) => {
|
|
25
|
-
var _a;
|
|
22
|
+
var _a, _b;
|
|
26
23
|
console.info('initialiseDiograph: room', roomObject);
|
|
27
24
|
this.selectRoom(roomObject);
|
|
28
|
-
this.
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
};
|
|
34
|
-
this.getDiograph = async () => {
|
|
35
|
-
console.info('getDiograph');
|
|
36
|
-
let diographObject;
|
|
37
|
-
await Promise.all(this.getDiographClients().map(async (connectionClient) => {
|
|
38
|
-
try {
|
|
39
|
-
diographObject = await connectionClient.getDiograph();
|
|
40
|
-
console.info(diographObject);
|
|
41
|
-
}
|
|
42
|
-
catch (error) {
|
|
43
|
-
console.error(error);
|
|
25
|
+
if ((_a = this.room) === null || _a === void 0 ? void 0 : _a.connections) {
|
|
26
|
+
this.diograph.initialise((_b = this.room) === null || _b === void 0 ? void 0 : _b.connections);
|
|
27
|
+
await this.diograph.getDiograph();
|
|
28
|
+
if (!Object.keys(this.diograph.diograph)) {
|
|
29
|
+
(0, addDefaultDiograph_1.addDefaultDiograph)(this.diograph);
|
|
44
30
|
}
|
|
45
|
-
|
|
46
|
-
}));
|
|
47
|
-
return diographObject;
|
|
48
|
-
};
|
|
49
|
-
this.saveDiograph = async () => {
|
|
50
|
-
console.info('saveDiograph');
|
|
51
|
-
const diographObject = this.diograph.toObject();
|
|
52
|
-
await Promise.all(this.getDiographClients().map(async (connectionClient) => {
|
|
53
|
-
await connectionClient.saveDiograph(diographObject);
|
|
54
|
-
console.info(diographObject);
|
|
55
|
-
return;
|
|
56
|
-
}));
|
|
57
|
-
return diographObject;
|
|
58
|
-
};
|
|
59
|
-
this.importDiograph = async (connections) => {
|
|
60
|
-
var _a;
|
|
61
|
-
const diographObject = await this.generateDiograph(connections);
|
|
62
|
-
if (diographObject) {
|
|
63
|
-
const diory = (_a = this.diory) === null || _a === void 0 ? void 0 : _a.toObject();
|
|
64
|
-
Object.entries(diographObject).forEach(([key, dioryObject]) => {
|
|
65
|
-
try {
|
|
66
|
-
key === '/' && diory
|
|
67
|
-
? this.diograph.addDioryLink(diory, diographObject['/'])
|
|
68
|
-
: this.diograph.addDiory(dioryObject);
|
|
69
|
-
}
|
|
70
|
-
catch (error) {
|
|
71
|
-
console.error(error);
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
await this.saveDiograph();
|
|
75
|
-
console.info(this.diograph.toObject());
|
|
31
|
+
this.focusDiory({ id: '/' });
|
|
76
32
|
}
|
|
77
33
|
return this.diograph;
|
|
78
34
|
};
|
|
79
|
-
this.
|
|
80
|
-
|
|
81
|
-
let diographObject;
|
|
82
|
-
await Promise.all(this.getDiographClients(connections).map(async (connectionClient) => {
|
|
83
|
-
diographObject = await connectionClient.generateDiograph();
|
|
84
|
-
console.info(diographObject);
|
|
85
|
-
return;
|
|
86
|
-
}));
|
|
87
|
-
return diographObject;
|
|
88
|
-
};
|
|
89
|
-
this.getDiosphereClients = (connections) => {
|
|
90
|
-
return (0, getConnectionClients_1.getConnectionClients)(this.dataClients, connections !== null && connections !== void 0 ? connections : this.connections);
|
|
91
|
-
};
|
|
92
|
-
this.initialiseDiosphere = async (connections) => {
|
|
93
|
-
var _a;
|
|
94
|
-
console.info('initialiseDiosphere: connections', connections);
|
|
95
|
-
this.connections = connections;
|
|
96
|
-
this.diosphere.resetRooms();
|
|
97
|
-
const diosphereObject = (_a = (await this.getDiosphere())) !== null && _a !== void 0 ? _a : (0, getDefaultDiosphere_1.getDefaultDiosphere)(connections);
|
|
98
|
-
this.diosphere.addDiosphere(diosphereObject);
|
|
99
|
-
this.selectRoom({ id: '/' });
|
|
100
|
-
return this.diosphere;
|
|
101
|
-
};
|
|
102
|
-
this.getDiosphere = async () => {
|
|
103
|
-
console.info('getDiosphere');
|
|
104
|
-
let diosphereObject;
|
|
105
|
-
await Promise.all(this.getDiosphereClients().map(async (connectionClient) => {
|
|
106
|
-
try {
|
|
107
|
-
diosphereObject = await connectionClient.getDiosphere();
|
|
108
|
-
console.info(diosphereObject);
|
|
109
|
-
}
|
|
110
|
-
catch (error) {
|
|
111
|
-
console.error(error);
|
|
112
|
-
}
|
|
113
|
-
return;
|
|
114
|
-
}));
|
|
115
|
-
return diosphereObject;
|
|
35
|
+
this.selectRoom = (roomObject) => {
|
|
36
|
+
return (this.room = this.diosphere.getRoom(roomObject));
|
|
116
37
|
};
|
|
117
|
-
this.
|
|
118
|
-
|
|
119
|
-
const diosphereObject = this.diosphere.toObject();
|
|
120
|
-
await Promise.all(this.getDiosphereClients().map(async (connectionClient) => {
|
|
121
|
-
await connectionClient.saveDiosphere(diosphereObject);
|
|
122
|
-
console.info(diosphereObject);
|
|
123
|
-
return;
|
|
124
|
-
}));
|
|
125
|
-
return diosphereObject;
|
|
38
|
+
this.focusDiory = (dioryObject) => {
|
|
39
|
+
return (this.diory = this.diograph.getDiory(dioryObject));
|
|
126
40
|
};
|
|
127
|
-
this.
|
|
128
|
-
this.
|
|
129
|
-
this.diograph = new diograph_1.Diograph();
|
|
130
|
-
this.diosphere.saveDiosphere = (0, debounce_1.debounce)(this.saveDiosphere, 1000);
|
|
131
|
-
this.diograph.saveDiograph = (0, debounce_1.debounce)(this.saveDiograph, 1000);
|
|
41
|
+
this.diosphere = new diosphere_js_1.Diosphere(new local_client_1.ConnectionClient(dataClients));
|
|
42
|
+
this.diograph = new diograph_1.Diograph(new local_client_1.ConnectionClient(dataClients));
|
|
132
43
|
}
|
|
133
44
|
}
|
|
134
45
|
exports.DioryClient = DioryClient;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { IDiographObject } from '@diograph/diograph'
|
|
2
|
-
export declare const getDefaultDiograph: () => IDiographObject
|
|
1
|
+
import { IDiographObject } from '@diograph/diograph'
|
|
2
|
+
export declare const getDefaultDiograph: () => IDiographObject
|
|
@@ -1,17 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports,
|
|
3
|
-
exports.getDefaultDiograph = void 0
|
|
4
|
-
const diograph_1 = require(
|
|
1
|
+
'use strict'
|
|
2
|
+
Object.defineProperty(exports, '__esModule', { value: true })
|
|
3
|
+
exports.getDefaultDiograph = void 0
|
|
4
|
+
const diograph_1 = require('@diograph/diograph')
|
|
5
5
|
const getDefaultDiograph = () => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
6
|
+
const diograph = new diograph_1.Diograph()
|
|
7
|
+
const diory = diograph.addDiory({
|
|
8
|
+
text: 'Welcome to Diory',
|
|
9
|
+
latlng: '60.01366036242365, 20.007133483886722',
|
|
10
|
+
})
|
|
11
|
+
diograph.addDiory(
|
|
12
|
+
{
|
|
13
|
+
text: 'Root',
|
|
14
|
+
links: [{ id: diory.id }],
|
|
15
|
+
},
|
|
16
|
+
'/',
|
|
17
|
+
)
|
|
18
|
+
return diograph.toObject()
|
|
19
|
+
}
|
|
20
|
+
exports.getDefaultDiograph = getDefaultDiograph
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { IConnectionObject, IDiosphereObject } from '@diory/diosphere-js'
|
|
2
|
-
export declare const getDefaultDiosphere: (connections: IConnectionObject[]) => IDiosphereObject
|
|
1
|
+
import { IConnectionObject, IDiosphereObject } from '@diory/diosphere-js'
|
|
2
|
+
export declare const getDefaultDiosphere: (connections: IConnectionObject[]) => IDiosphereObject
|
|
@@ -1,13 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports,
|
|
3
|
-
exports.getDefaultDiosphere = void 0
|
|
4
|
-
const diosphere_js_1 = require(
|
|
1
|
+
'use strict'
|
|
2
|
+
Object.defineProperty(exports, '__esModule', { value: true })
|
|
3
|
+
exports.getDefaultDiosphere = void 0
|
|
4
|
+
const diosphere_js_1 = require('@diory/diosphere-js')
|
|
5
5
|
const getDefaultDiosphere = (connections) => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
6
|
+
const diosphere = new diosphere_js_1.Diosphere()
|
|
7
|
+
diosphere.addRoom(
|
|
8
|
+
{
|
|
9
|
+
text: 'Room',
|
|
10
|
+
connections,
|
|
11
|
+
},
|
|
12
|
+
'/',
|
|
13
|
+
)
|
|
14
|
+
return diosphere.toObject()
|
|
15
|
+
}
|
|
16
|
+
exports.getDefaultDiosphere = getDefaultDiosphere
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.DioryClient = void 0;
|
|
4
4
|
var dioryClient_1 = require("./dioryClient/dioryClient");
|
|
5
5
|
Object.defineProperty(exports, "DioryClient", { enumerable: true, get: function () { return dioryClient_1.DioryClient; } });
|
|
6
|
-
var connectionClient_1 = require("./connectionClient/connectionClient");
|
|
7
|
-
Object.defineProperty(exports, "ConnectionClient", { enumerable: true, get: function () { return connectionClient_1.ConnectionClient; } });
|
package/dist/types.d.ts
CHANGED
|
@@ -1,61 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import { IDiograph, IDiographObject, IDiory, IDioryObject } from '@diograph/diograph';
|
|
4
|
-
export interface IMetadata {
|
|
5
|
-
name: string;
|
|
6
|
-
created?: string;
|
|
7
|
-
modified?: string;
|
|
8
|
-
duration?: string;
|
|
9
|
-
thumbnail?: string;
|
|
10
|
-
latlng?: string;
|
|
11
|
-
}
|
|
12
|
-
export interface IFileType {
|
|
13
|
-
ext?: string;
|
|
14
|
-
mime?: string;
|
|
15
|
-
}
|
|
16
|
-
export interface IDataClient {
|
|
17
|
-
type: string;
|
|
18
|
-
readTextItem(url: string): Promise<string>;
|
|
19
|
-
readItem(url: string): Promise<Buffer>;
|
|
20
|
-
readToStream(url: string): any;
|
|
21
|
-
exists(url: string): Promise<boolean>;
|
|
22
|
-
writeTextItem(url: string, fileContent: string): Promise<boolean>;
|
|
23
|
-
writeItem(url: string, fileContent: Buffer | string): Promise<boolean>;
|
|
24
|
-
deleteItem(url: string): Promise<boolean>;
|
|
25
|
-
deleteFolder(url: string): Promise<void>;
|
|
26
|
-
list(url: string): Promise<string[]>;
|
|
27
|
-
getFileNames(url: string): Promise<string[]>;
|
|
28
|
-
getFolderNames(url: string): Promise<string[]>;
|
|
29
|
-
getFileType(url: string): Promise<IFileType>;
|
|
30
|
-
getMetadata(url: string): IMetadata;
|
|
31
|
-
getThumbnail?(imageUrl: string): Promise<string | undefined>;
|
|
32
|
-
getVideoMetadata?(videoUrl: string): Promise<IMetadata>;
|
|
33
|
-
}
|
|
34
|
-
export interface IConnectionClient {
|
|
35
|
-
type: string;
|
|
36
|
-
client: IDataClient;
|
|
37
|
-
connection: IConnectionObject;
|
|
38
|
-
getDiosphere: () => Promise<IDiosphereObject>;
|
|
39
|
-
saveDiosphere: (diosphereObject: IDiosphereObject) => void;
|
|
40
|
-
getDiograph: () => Promise<IDiographObject>;
|
|
41
|
-
saveDiograph: (diographObject: IDiographObject) => void;
|
|
42
|
-
generateDiograph: () => Promise<IDiographObject>;
|
|
43
|
-
}
|
|
1
|
+
import { IConnectionObject, IDiosphere, IRoom, IRoomObject } from '@diory/diosphere-js';
|
|
2
|
+
import { IDiograph, IDiory, IDioryObject } from '@diograph/diograph';
|
|
44
3
|
export interface IDioryClient {
|
|
45
|
-
dataClients: IDataClient[];
|
|
46
|
-
connections: IConnectionObject[];
|
|
47
|
-
diory?: IDiory;
|
|
48
|
-
focusDiory: (dioryObject: IDioryObject) => IDiory;
|
|
49
|
-
room?: IRoom;
|
|
50
|
-
selectRoom: (roomObject: IRoomObject) => IRoom;
|
|
51
|
-
diograph: IDiograph;
|
|
52
|
-
initialiseDiograph: (roomObject: IRoomObject) => Promise<IDiograph>;
|
|
53
|
-
getDiograph: () => Promise<IDiographObject | undefined>;
|
|
54
|
-
saveDiograph: () => Promise<IDiographObject>;
|
|
55
|
-
importDiograph: (connections?: IConnectionObject[]) => Promise<IDiograph>;
|
|
56
|
-
generateDiograph: (connections?: IConnectionObject[]) => Promise<IDiographObject | undefined>;
|
|
57
4
|
diosphere: IDiosphere;
|
|
5
|
+
diograph: IDiograph;
|
|
6
|
+
room?: IRoom;
|
|
7
|
+
diory?: IDiory;
|
|
58
8
|
initialiseDiosphere: (connections: IConnectionObject[]) => Promise<IDiosphere>;
|
|
59
|
-
|
|
60
|
-
|
|
9
|
+
initialiseDiograph: (roomObject: IRoomObject) => Promise<IDiograph>;
|
|
10
|
+
selectRoom: (roomObject: IRoomObject) => IRoom;
|
|
11
|
+
focusDiory: (dioryObject: IDioryObject) => IDiory;
|
|
61
12
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.addDefaultDiograph = void 0;
|
|
4
|
+
const addDefaultDiograph = (diograph) => {
|
|
5
|
+
const diory = diograph.addDiory({
|
|
6
|
+
text: 'Welcome to Diory',
|
|
7
|
+
latlng: '60.01366036242365, 20.007133483886722',
|
|
8
|
+
});
|
|
9
|
+
diograph.addDiory({
|
|
10
|
+
text: 'Root diory',
|
|
11
|
+
links: [{ id: diory.id }],
|
|
12
|
+
}, '/');
|
|
13
|
+
};
|
|
14
|
+
exports.addDefaultDiograph = addDefaultDiograph;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.addDefaultRoom = void 0;
|
|
4
|
+
const addDefaultRoom = (diosphere, connections) => {
|
|
5
|
+
diosphere.addRoom({
|
|
6
|
+
text: 'Home room',
|
|
7
|
+
connections,
|
|
8
|
+
}, '/');
|
|
9
|
+
};
|
|
10
|
+
exports.addDefaultRoom = addDefaultRoom;
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
-
import { IConnectionObject } from '@diory/diosphere-js'
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import { IConnectionObject } from '@diory/diosphere-js'
|
|
2
|
+
import { IDataClient } from '@diograph/local-client'
|
|
3
|
+
import { IConnectionClient } from '../types'
|
|
4
|
+
export declare function getConnectionClients(
|
|
5
|
+
dataClients: IDataClient[],
|
|
6
|
+
connections?: IConnectionObject[],
|
|
7
|
+
): IConnectionClient[]
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports,
|
|
3
|
-
exports.getConnectionClients = void 0
|
|
4
|
-
const connectionClient_1 = require(
|
|
1
|
+
'use strict'
|
|
2
|
+
Object.defineProperty(exports, '__esModule', { value: true })
|
|
3
|
+
exports.getConnectionClients = void 0
|
|
4
|
+
const connectionClient_1 = require('../connectionClient/connectionClient')
|
|
5
5
|
function getDataClient(dataClients, { client }) {
|
|
6
|
-
|
|
6
|
+
return dataClients.find(({ type }) => type === client)
|
|
7
7
|
}
|
|
8
8
|
function getConnectionClients(dataClients, connections = []) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
})
|
|
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
15
|
}
|
|
16
|
-
exports.getConnectionClients = getConnectionClients
|
|
16
|
+
exports.getConnectionClients = getConnectionClients
|
package/package.json
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@diory/client-js",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0-rc2",
|
|
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.
|
|
10
|
-
"@diograph/folder-generator": "^0.
|
|
11
|
-
"@
|
|
9
|
+
"@diograph/diograph": "^0.4.0-rc1",
|
|
10
|
+
"@diograph/folder-generator": "^0.4.0-rc1",
|
|
11
|
+
"@diograph/local-client": "^0.4.0-rc3",
|
|
12
|
+
"@diory/diosphere-js": "^0.4.0-rc1",
|
|
12
13
|
"path-browserify": "^1.0.1",
|
|
13
14
|
"uuid": "8.3.2"
|
|
14
15
|
},
|
|
@@ -1,185 +1,62 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
} from '
|
|
9
|
-
import { Diograph, IDiograph, IDiographObject, IDiory, IDioryObject } from '@diograph/diograph'
|
|
10
|
-
|
|
11
|
-
import { IDioryClient, IDataClient } from '../types'
|
|
12
|
-
import { getConnectionClients } from '../utils/getConnectionClients'
|
|
13
|
-
import { debounce } from '../utils/debounce'
|
|
14
|
-
|
|
15
|
-
import { getDefaultDiosphere } from './getDefaultDiosphere'
|
|
16
|
-
import { getDefaultDiograph } from './getDefaultDiograph'
|
|
1
|
+
import { Diosphere, IConnectionObject, IDiosphere, IRoom, IRoomObject } from '@diory/diosphere-js'
|
|
2
|
+
import { Diograph, IDiograph, IDiory, IDioryObject } from '@diograph/diograph'
|
|
3
|
+
import { IDataClient, ConnectionClient } from '@diograph/local-client'
|
|
4
|
+
|
|
5
|
+
import { IDioryClient } from '../types'
|
|
6
|
+
|
|
7
|
+
import { addDefaultRoom } from '../utils/addDefaultRoom'
|
|
8
|
+
import { addDefaultDiograph } from '../utils/addDefaultDiograph'
|
|
17
9
|
|
|
18
10
|
class DioryClient implements IDioryClient {
|
|
19
|
-
dataClients: IDataClient[] = []
|
|
20
|
-
connections: IConnectionObject[] = []
|
|
21
11
|
diosphere: IDiosphere
|
|
22
|
-
room?: IRoom
|
|
23
12
|
diograph: IDiograph
|
|
13
|
+
room?: IRoom
|
|
24
14
|
diory?: IDiory
|
|
25
15
|
|
|
26
16
|
constructor(dataClients: IDataClient[]) {
|
|
27
|
-
this.
|
|
17
|
+
this.diosphere = new Diosphere(new ConnectionClient(dataClients))
|
|
18
|
+
this.diograph = new Diograph(new ConnectionClient(dataClients))
|
|
19
|
+
}
|
|
28
20
|
|
|
29
|
-
|
|
30
|
-
|
|
21
|
+
initialiseDiosphere = async (connections: IConnectionObject[]): Promise<IDiosphere> => {
|
|
22
|
+
console.info('initialiseDiosphere: connections', connections)
|
|
31
23
|
|
|
32
|
-
this.diosphere.
|
|
33
|
-
this.
|
|
34
|
-
}
|
|
24
|
+
this.diosphere.initialise(connections)
|
|
25
|
+
await this.diosphere.getDiosphere()
|
|
35
26
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
27
|
+
if (!Object.keys(this.diosphere.rooms)) {
|
|
28
|
+
addDefaultRoom(this.diosphere, connections)
|
|
29
|
+
}
|
|
39
30
|
|
|
40
|
-
|
|
41
|
-
return (this.room = this.diosphere.getRoom(roomObject))
|
|
42
|
-
}
|
|
31
|
+
this.selectRoom({ id: '/' })
|
|
43
32
|
|
|
44
|
-
|
|
45
|
-
return getConnectionClients(this.dataClients, connections ?? this.room?.connections)
|
|
33
|
+
return this.diosphere
|
|
46
34
|
}
|
|
47
35
|
|
|
48
36
|
initialiseDiograph = async (roomObject: IRoomObject): Promise<IDiograph> => {
|
|
49
37
|
console.info('initialiseDiograph: room', roomObject)
|
|
50
38
|
this.selectRoom(roomObject)
|
|
51
39
|
|
|
52
|
-
this.
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
this.focusDiory({ id: '/' })
|
|
57
|
-
|
|
58
|
-
return this.diograph
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
getDiograph = async (): Promise<IDiographObject | undefined> => {
|
|
62
|
-
console.info('getDiograph')
|
|
63
|
-
|
|
64
|
-
let diographObject
|
|
65
|
-
await Promise.all(
|
|
66
|
-
this.getDiographClients().map(async (connectionClient) => {
|
|
67
|
-
try {
|
|
68
|
-
diographObject = await connectionClient.getDiograph()
|
|
69
|
-
console.info(diographObject)
|
|
70
|
-
} catch (error) {
|
|
71
|
-
console.error(error)
|
|
72
|
-
}
|
|
73
|
-
return
|
|
74
|
-
}),
|
|
75
|
-
)
|
|
76
|
-
|
|
77
|
-
return diographObject
|
|
78
|
-
}
|
|
40
|
+
if (this.room?.connections) {
|
|
41
|
+
this.diograph.initialise(this.room?.connections)
|
|
42
|
+
await this.diograph.getDiograph()
|
|
79
43
|
|
|
80
|
-
|
|
81
|
-
|
|
44
|
+
if (!Object.keys(this.diograph.diograph)) {
|
|
45
|
+
addDefaultDiograph(this.diograph)
|
|
46
|
+
}
|
|
82
47
|
|
|
83
|
-
|
|
84
|
-
await Promise.all(
|
|
85
|
-
this.getDiographClients().map(async (connectionClient) => {
|
|
86
|
-
await connectionClient.saveDiograph(diographObject)
|
|
87
|
-
console.info(diographObject)
|
|
88
|
-
return
|
|
89
|
-
}),
|
|
90
|
-
)
|
|
91
|
-
|
|
92
|
-
return diographObject
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
importDiograph = async (connections?: IConnectionObject[]): Promise<IDiograph> => {
|
|
96
|
-
const diographObject = await this.generateDiograph(connections)
|
|
97
|
-
|
|
98
|
-
if (diographObject) {
|
|
99
|
-
const diory = this.diory?.toObject()
|
|
100
|
-
Object.entries(diographObject).forEach(([key, dioryObject]) => {
|
|
101
|
-
try {
|
|
102
|
-
key === '/' && diory
|
|
103
|
-
? this.diograph.addDioryLink(diory, diographObject['/'])
|
|
104
|
-
: this.diograph.addDiory(dioryObject)
|
|
105
|
-
} catch (error) {
|
|
106
|
-
console.error(error)
|
|
107
|
-
}
|
|
108
|
-
})
|
|
109
|
-
|
|
110
|
-
await this.saveDiograph()
|
|
111
|
-
console.info(this.diograph.toObject())
|
|
48
|
+
this.focusDiory({ id: '/' })
|
|
112
49
|
}
|
|
113
50
|
|
|
114
51
|
return this.diograph
|
|
115
52
|
}
|
|
116
53
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
): Promise<IDiographObject | undefined> => {
|
|
120
|
-
console.info('generateDiograph', connections)
|
|
121
|
-
|
|
122
|
-
let diographObject
|
|
123
|
-
await Promise.all(
|
|
124
|
-
this.getDiographClients(connections).map(async (connectionClient) => {
|
|
125
|
-
diographObject = await connectionClient.generateDiograph()
|
|
126
|
-
console.info(diographObject)
|
|
127
|
-
return
|
|
128
|
-
}),
|
|
129
|
-
)
|
|
130
|
-
|
|
131
|
-
return diographObject
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
getDiosphereClients = (connections?: IConnectionObject[]) => {
|
|
135
|
-
return getConnectionClients(this.dataClients, connections ?? this.connections)
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
initialiseDiosphere = async (connections: IConnectionObject[]): Promise<IDiosphere> => {
|
|
139
|
-
console.info('initialiseDiosphere: connections', connections)
|
|
140
|
-
this.connections = connections
|
|
141
|
-
|
|
142
|
-
this.diosphere.resetRooms()
|
|
143
|
-
const diosphereObject = (await this.getDiosphere()) ?? getDefaultDiosphere(connections)
|
|
144
|
-
this.diosphere.addDiosphere(diosphereObject)
|
|
145
|
-
|
|
146
|
-
this.selectRoom({ id: '/' })
|
|
147
|
-
|
|
148
|
-
return this.diosphere
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
getDiosphere = async (): Promise<IDiosphereObject | undefined> => {
|
|
152
|
-
console.info('getDiosphere')
|
|
153
|
-
|
|
154
|
-
let diosphereObject
|
|
155
|
-
await Promise.all(
|
|
156
|
-
this.getDiosphereClients().map(async (connectionClient) => {
|
|
157
|
-
try {
|
|
158
|
-
diosphereObject = await connectionClient.getDiosphere()
|
|
159
|
-
console.info(diosphereObject)
|
|
160
|
-
} catch (error) {
|
|
161
|
-
console.error(error)
|
|
162
|
-
}
|
|
163
|
-
return
|
|
164
|
-
}),
|
|
165
|
-
)
|
|
166
|
-
|
|
167
|
-
return diosphereObject
|
|
54
|
+
selectRoom = (roomObject: IRoomObject): IRoom => {
|
|
55
|
+
return (this.room = this.diosphere.getRoom(roomObject))
|
|
168
56
|
}
|
|
169
57
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
const diosphereObject = this.diosphere.toObject()
|
|
174
|
-
await Promise.all(
|
|
175
|
-
this.getDiosphereClients().map(async (connectionClient) => {
|
|
176
|
-
await connectionClient.saveDiosphere(diosphereObject)
|
|
177
|
-
console.info(diosphereObject)
|
|
178
|
-
return
|
|
179
|
-
}),
|
|
180
|
-
)
|
|
181
|
-
|
|
182
|
-
return diosphereObject
|
|
58
|
+
focusDiory = (dioryObject: IDioryObject): IDiory => {
|
|
59
|
+
return (this.diory = this.diograph.getDiory(dioryObject))
|
|
183
60
|
}
|
|
184
61
|
}
|
|
185
62
|
|
package/src/index.ts
CHANGED
package/src/types.ts
CHANGED
|
@@ -1,71 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
IDiosphere,
|
|
4
|
-
IDiosphereObject,
|
|
5
|
-
IRoom,
|
|
6
|
-
IRoomObject,
|
|
7
|
-
} from '@diory/diosphere-js'
|
|
8
|
-
import { IDiograph, IDiographObject, IDiory, IDioryObject } from '@diograph/diograph'
|
|
9
|
-
|
|
10
|
-
export interface IMetadata {
|
|
11
|
-
name: string
|
|
12
|
-
created?: string
|
|
13
|
-
modified?: string
|
|
14
|
-
duration?: string
|
|
15
|
-
thumbnail?: string
|
|
16
|
-
latlng?: string
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export interface IFileType {
|
|
20
|
-
ext?: string
|
|
21
|
-
mime?: string
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export interface IDataClient {
|
|
25
|
-
type: string
|
|
26
|
-
readTextItem(url: string): Promise<string>
|
|
27
|
-
readItem(url: string): Promise<Buffer>
|
|
28
|
-
readToStream(url: string): any
|
|
29
|
-
exists(url: string): Promise<boolean>
|
|
30
|
-
writeTextItem(url: string, fileContent: string): Promise<boolean>
|
|
31
|
-
writeItem(url: string, fileContent: Buffer | string): Promise<boolean>
|
|
32
|
-
deleteItem(url: string): Promise<boolean>
|
|
33
|
-
deleteFolder(url: string): Promise<void>
|
|
34
|
-
list(url: string): Promise<string[]>
|
|
35
|
-
getFileNames(url: string): Promise<string[]>
|
|
36
|
-
getFolderNames(url: string): Promise<string[]>
|
|
37
|
-
getFileType(url: string): Promise<IFileType>
|
|
38
|
-
getMetadata(url: string): IMetadata
|
|
39
|
-
getThumbnail?(imageUrl: string): Promise<string | undefined>
|
|
40
|
-
getVideoMetadata?(videoUrl: string): Promise<IMetadata>
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export interface IConnectionClient {
|
|
44
|
-
type: string
|
|
45
|
-
client: IDataClient
|
|
46
|
-
connection: IConnectionObject
|
|
47
|
-
getDiosphere: () => Promise<IDiosphereObject>
|
|
48
|
-
saveDiosphere: (diosphereObject: IDiosphereObject) => void
|
|
49
|
-
getDiograph: () => Promise<IDiographObject>
|
|
50
|
-
saveDiograph: (diographObject: IDiographObject) => void
|
|
51
|
-
generateDiograph: () => Promise<IDiographObject>
|
|
52
|
-
}
|
|
1
|
+
import { IConnectionObject, IDiosphere, IRoom, IRoomObject } from '@diory/diosphere-js'
|
|
2
|
+
import { IDiograph, IDiory, IDioryObject } from '@diograph/diograph'
|
|
53
3
|
|
|
54
4
|
export interface IDioryClient {
|
|
55
|
-
dataClients: IDataClient[]
|
|
56
|
-
connections: IConnectionObject[]
|
|
57
|
-
diory?: IDiory
|
|
58
|
-
focusDiory: (dioryObject: IDioryObject) => IDiory
|
|
59
|
-
room?: IRoom
|
|
60
|
-
selectRoom: (roomObject: IRoomObject) => IRoom
|
|
61
|
-
diograph: IDiograph
|
|
62
|
-
initialiseDiograph: (roomObject: IRoomObject) => Promise<IDiograph>
|
|
63
|
-
getDiograph: () => Promise<IDiographObject | undefined>
|
|
64
|
-
saveDiograph: () => Promise<IDiographObject>
|
|
65
|
-
importDiograph: (connections?: IConnectionObject[]) => Promise<IDiograph>
|
|
66
|
-
generateDiograph: (connections?: IConnectionObject[]) => Promise<IDiographObject | undefined>
|
|
67
5
|
diosphere: IDiosphere
|
|
6
|
+
diograph: IDiograph
|
|
7
|
+
room?: IRoom
|
|
8
|
+
diory?: IDiory
|
|
68
9
|
initialiseDiosphere: (connections: IConnectionObject[]) => Promise<IDiosphere>
|
|
69
|
-
|
|
70
|
-
|
|
10
|
+
initialiseDiograph: (roomObject: IRoomObject) => Promise<IDiograph>
|
|
11
|
+
selectRoom: (roomObject: IRoomObject) => IRoom
|
|
12
|
+
focusDiory: (dioryObject: IDioryObject) => IDiory
|
|
71
13
|
}
|
|
@@ -1,18 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IDiograph } from '@diograph/diograph'
|
|
2
2
|
|
|
3
|
-
export const
|
|
4
|
-
const diograph = new Diograph()
|
|
3
|
+
export const addDefaultDiograph = (diograph: IDiograph): void => {
|
|
5
4
|
const diory = diograph.addDiory({
|
|
6
5
|
text: 'Welcome to Diory',
|
|
7
6
|
latlng: '60.01366036242365, 20.007133483886722',
|
|
8
7
|
})
|
|
9
8
|
diograph.addDiory(
|
|
10
9
|
{
|
|
11
|
-
text: 'Root',
|
|
10
|
+
text: 'Root diory',
|
|
12
11
|
links: [{ id: diory.id }],
|
|
13
12
|
},
|
|
14
13
|
'/',
|
|
15
14
|
)
|
|
16
|
-
|
|
17
|
-
return diograph.toObject()
|
|
18
15
|
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
describe('connectionClient', () => {
|
|
2
|
-
describe('construct()', () => {
|
|
3
|
-
it('should construct with dataClient and connection', () => {
|
|
4
|
-
expect(true).toEqual(true)
|
|
5
|
-
})
|
|
6
|
-
})
|
|
7
|
-
|
|
8
|
-
describe('getDiosphere()', () => {
|
|
9
|
-
it('should get diosphere', () => {
|
|
10
|
-
expect(true).toEqual(true)
|
|
11
|
-
})
|
|
12
|
-
})
|
|
13
|
-
|
|
14
|
-
describe('saveDiosphere()', () => {
|
|
15
|
-
it('should save diosphere object', () => {
|
|
16
|
-
expect(true).toEqual(true)
|
|
17
|
-
})
|
|
18
|
-
})
|
|
19
|
-
})
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { join } from 'path-browserify'
|
|
2
|
-
import { generateDiograph } from '@diograph/folder-generator'
|
|
3
|
-
|
|
4
|
-
import { IDiographObject } from '@diograph/diograph'
|
|
5
|
-
import { IConnectionObject, IDiosphereObject } from '@diory/diosphere-js'
|
|
6
|
-
import { IConnectionClient, IDataClient } from '../types'
|
|
7
|
-
|
|
8
|
-
const DIOSPHERE_JSON = 'diosphere.json'
|
|
9
|
-
const DIOGRAPH_JSON = 'diograph.json'
|
|
10
|
-
|
|
11
|
-
class ConnectionClient implements IConnectionClient {
|
|
12
|
-
type: string
|
|
13
|
-
client: IDataClient
|
|
14
|
-
connection: IConnectionObject
|
|
15
|
-
|
|
16
|
-
constructor(dataClient: IDataClient, connection: IConnectionObject) {
|
|
17
|
-
this.type = dataClient.type
|
|
18
|
-
this.client = dataClient
|
|
19
|
-
this.connection = connection
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
getDiosphere = async () => {
|
|
23
|
-
const path = join(this.connection.address, DIOSPHERE_JSON)
|
|
24
|
-
const diosphereString = await this.client.readTextItem(path)
|
|
25
|
-
return JSON.parse(diosphereString)
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
saveDiosphere = async (diosphereObject: IDiosphereObject) => {
|
|
29
|
-
const path = join(this.connection.address, DIOSPHERE_JSON)
|
|
30
|
-
const diosphereString = JSON.stringify(diosphereObject, null, 2)
|
|
31
|
-
return this.client.writeItem(path, diosphereString)
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
getDiograph = async () => {
|
|
35
|
-
const path = join(this.connection.address, DIOGRAPH_JSON)
|
|
36
|
-
const diographString = await this.client.readTextItem(path)
|
|
37
|
-
return JSON.parse(diographString)
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
saveDiograph = async (diographObject: IDiographObject) => {
|
|
41
|
-
const path = join(this.connection.address, DIOGRAPH_JSON)
|
|
42
|
-
const diographString = JSON.stringify(diographObject, null, 2)
|
|
43
|
-
return this.client.writeItem(path, diographString)
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
generateDiograph = async (): Promise<IDiographObject> => {
|
|
47
|
-
const { diograph } = await generateDiograph(this.connection.address, this.client)
|
|
48
|
-
return diograph.toObject()
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export { ConnectionClient }
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { Diosphere, IConnectionObject, IDiosphereObject } from '@diory/diosphere-js'
|
|
2
|
-
|
|
3
|
-
export const getDefaultDiosphere = (connections: IConnectionObject[]): IDiosphereObject => {
|
|
4
|
-
const diosphere = new Diosphere()
|
|
5
|
-
diosphere.addRoom(
|
|
6
|
-
{
|
|
7
|
-
text: 'Room',
|
|
8
|
-
connections,
|
|
9
|
-
},
|
|
10
|
-
'/',
|
|
11
|
-
)
|
|
12
|
-
|
|
13
|
-
return diosphere.toObject()
|
|
14
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { IConnectionObject } from '@diory/diosphere-js'
|
|
2
|
-
|
|
3
|
-
import { ConnectionClient } from '../connectionClient/connectionClient'
|
|
4
|
-
import { IConnectionClient, IDataClient } from '../types'
|
|
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
|
-
}
|