@diory/client-js 0.2.0-rc9 → 0.2.1-rc1
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/utils/debounce.d.ts +1 -0
- package/dist/connectionClient/utils/debounce.js +22 -0
- package/dist/dioryClient/defaultDiograph.json +24 -0
- package/dist/dioryClient/defaultDiosphere.d.ts +21 -0
- package/dist/dioryClient/defaultDiosphere.js +26 -0
- package/dist/dioryClient/defaultDiosphere.json +23 -0
- package/dist/dioryClient/dioryClient.d.ts +13 -9
- package/dist/dioryClient/dioryClient.js +106 -72
- package/dist/dioryClient/getDefaultDiograph.d.ts +2 -0
- package/dist/dioryClient/getDefaultDiograph.js +17 -0
- package/dist/dioryClient/getDefaultDiosphere.d.ts +2 -0
- package/dist/dioryClient/getDefaultDiosphere.js +13 -0
- package/dist/types.d.ts +12 -10
- package/dist/utils/debounce.d.ts +1 -0
- package/dist/utils/debounce.js +24 -0
- package/dist/utils/getConnectionClients.d.ts +1 -1
- package/dist/utils/getConnectionClients.js +1 -3
- package/package.json +4 -4
- package/src/dioryClient/dioryClient.ts +135 -84
- package/src/dioryClient/getDefaultDiograph.ts +18 -0
- package/src/dioryClient/getDefaultDiosphere.ts +14 -0
- package/src/types.ts +12 -10
- package/src/utils/debounce.ts +18 -0
- package/src/utils/getConnectionClients.ts +2 -2
- package/tsconfig.json +3 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function debounce(func: any, wait: number, immediate?: boolean): () => typeof func
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
Object.defineProperty(exports, '__esModule', { value: true })
|
|
3
|
+
exports.debounce = void 0
|
|
4
|
+
function debounce(func, wait, immediate = false) {
|
|
5
|
+
let timeout
|
|
6
|
+
// eslint-disable-next-line func-names
|
|
7
|
+
return () => {
|
|
8
|
+
// @ts-ignore
|
|
9
|
+
const context = this
|
|
10
|
+
const args = arguments
|
|
11
|
+
// eslint-disable-next-line func-names
|
|
12
|
+
const later = function () {
|
|
13
|
+
timeout = null
|
|
14
|
+
if (!immediate) func.apply(context, args)
|
|
15
|
+
}
|
|
16
|
+
const callNow = immediate && !timeout
|
|
17
|
+
clearTimeout(timeout)
|
|
18
|
+
timeout = setTimeout(later, wait)
|
|
19
|
+
if (callNow) func.apply(context, args)
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.debounce = debounce
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"/": {
|
|
3
|
+
"id": "welcome-root-diory"
|
|
4
|
+
},
|
|
5
|
+
"welcome-root-diory": {
|
|
6
|
+
"id": "welcome-root-diory",
|
|
7
|
+
"text": "Room",
|
|
8
|
+
"image": "",
|
|
9
|
+
"links": [
|
|
10
|
+
{
|
|
11
|
+
"id": "welcome-diory"
|
|
12
|
+
}
|
|
13
|
+
],
|
|
14
|
+
"modified": "2020-01-03T14:03:04.751Z"
|
|
15
|
+
},
|
|
16
|
+
"welcome-diory": {
|
|
17
|
+
"id": "welcome-diory",
|
|
18
|
+
"image": "",
|
|
19
|
+
"modified": "2020-01-03T14:03:04.751Z",
|
|
20
|
+
"text": "Welcome to Diory",
|
|
21
|
+
"latitude": 60.01366036242365,
|
|
22
|
+
"longitude": 20.007133483886722
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export declare const diosphere: {
|
|
2
|
+
rooms: {
|
|
3
|
+
'/': {
|
|
4
|
+
id: string
|
|
5
|
+
created: string
|
|
6
|
+
modified: string
|
|
7
|
+
}
|
|
8
|
+
'welcome-room': {
|
|
9
|
+
id: string
|
|
10
|
+
text: string
|
|
11
|
+
doors: never[]
|
|
12
|
+
connections: {
|
|
13
|
+
id: string
|
|
14
|
+
client: string
|
|
15
|
+
address: string
|
|
16
|
+
}[]
|
|
17
|
+
created: string
|
|
18
|
+
modified: string
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
Object.defineProperty(exports, '__esModule', { value: true })
|
|
3
|
+
exports.diosphere = void 0
|
|
4
|
+
exports.diosphere = {
|
|
5
|
+
rooms: {
|
|
6
|
+
'/': {
|
|
7
|
+
id: 'welcome-room',
|
|
8
|
+
created: '2024-03-24T14:56:21.243Z',
|
|
9
|
+
modified: '2024-03-24T14:56:21.243Z',
|
|
10
|
+
},
|
|
11
|
+
'welcome-room': {
|
|
12
|
+
id: 'welcome-room',
|
|
13
|
+
text: 'Wellcome',
|
|
14
|
+
doors: [],
|
|
15
|
+
connections: [
|
|
16
|
+
{
|
|
17
|
+
id: 'welcome-connection',
|
|
18
|
+
client: 'LocalClient',
|
|
19
|
+
address: 'public/welcome-room',
|
|
20
|
+
},
|
|
21
|
+
],
|
|
22
|
+
created: '2024-03-24T14:56:21.243Z',
|
|
23
|
+
modified: '2024-03-24T14:56:21.243Z',
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"rooms": {
|
|
3
|
+
"/": {
|
|
4
|
+
"id": "welcome-room",
|
|
5
|
+
"created": "2024-03-24T14:56:21.243Z",
|
|
6
|
+
"modified": "2024-03-24T14:56:21.243Z"
|
|
7
|
+
},
|
|
8
|
+
"welcome-room": {
|
|
9
|
+
"id": "welcome-room",
|
|
10
|
+
"text": "Wellcome room",
|
|
11
|
+
"doors": [],
|
|
12
|
+
"connections": [
|
|
13
|
+
{
|
|
14
|
+
"id": "welcome-room",
|
|
15
|
+
"client": "LocalClient",
|
|
16
|
+
"address": "public/welcome-room"
|
|
17
|
+
}
|
|
18
|
+
],
|
|
19
|
+
"created": "2024-03-24T14:56:21.243Z",
|
|
20
|
+
"modified": "2024-03-24T14:56:21.243Z"
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { IConnectionObject, IDiosphere, IRoom, IRoomObject } from '@diory/diosphere-js';
|
|
2
|
-
import { IDiograph, IDiory, IDioryObject } from '@diograph/diograph';
|
|
1
|
+
import { IConnectionObject, IDiosphere, IDiosphereObject, IRoom, IRoomObject } from '@diory/diosphere-js';
|
|
2
|
+
import { IDiograph, IDiographObject, IDiory, IDioryObject } from '@diograph/diograph';
|
|
3
3
|
import { IDioryClient, IDataClient } from '../types';
|
|
4
4
|
declare class DioryClient implements IDioryClient {
|
|
5
5
|
dataClients: IDataClient[];
|
|
@@ -9,13 +9,17 @@ declare class DioryClient implements IDioryClient {
|
|
|
9
9
|
diograph: IDiograph;
|
|
10
10
|
diory?: IDiory;
|
|
11
11
|
constructor(dataClients: IDataClient[]);
|
|
12
|
-
initialise: (connections: IConnectionObject[]) => Promise<IDioryClient>;
|
|
13
|
-
enterRoom: (roomObject: IRoomObject) => Promise<IRoom>;
|
|
14
12
|
focusDiory: (dioryObject: IDioryObject) => IDiory;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
13
|
+
selectRoom: (roomObject: IRoomObject) => IRoom;
|
|
14
|
+
getDiographClients: (connections?: IConnectionObject[]) => import("../types").IConnectionClient[];
|
|
15
|
+
initialiseDiograph: (roomObject: IRoomObject) => Promise<IDiograph>;
|
|
16
|
+
getDiograph: (connections?: IConnectionObject[]) => Promise<IDiographObject | undefined>;
|
|
17
|
+
saveDiograph: (connections?: IConnectionObject[]) => Promise<IDiographObject>;
|
|
18
|
+
importDiograph: (connections?: IConnectionObject[]) => Promise<IDiograph>;
|
|
19
|
+
generateDiograph: (connections?: IConnectionObject[]) => Promise<IDiographObject | undefined>;
|
|
20
|
+
getDiosphereClients: (connections?: IConnectionObject[]) => import("../types").IConnectionClient[];
|
|
21
|
+
initialiseDiosphere: (connections: IConnectionObject[]) => Promise<IDiosphere>;
|
|
22
|
+
getDiosphere: (connections?: IConnectionObject[]) => Promise<IDiosphereObject | undefined>;
|
|
23
|
+
saveDiosphere: (connections?: IConnectionObject[]) => Promise<IDiosphereObject>;
|
|
20
24
|
}
|
|
21
25
|
export { DioryClient };
|
|
@@ -4,93 +4,127 @@ exports.DioryClient = void 0;
|
|
|
4
4
|
const diosphere_js_1 = require("@diory/diosphere-js");
|
|
5
5
|
const diograph_1 = require("@diograph/diograph");
|
|
6
6
|
const getConnectionClients_1 = require("../utils/getConnectionClients");
|
|
7
|
+
const getDefaultDiosphere_1 = require("./getDefaultDiosphere");
|
|
8
|
+
const getDefaultDiograph_1 = require("./getDefaultDiograph");
|
|
7
9
|
class DioryClient {
|
|
8
10
|
constructor(dataClients) {
|
|
9
11
|
this.dataClients = [];
|
|
10
12
|
this.connections = [];
|
|
11
|
-
this.initialise = async (connections) => {
|
|
12
|
-
this.connections = connections;
|
|
13
|
-
this.diosphere.resetRooms();
|
|
14
|
-
await this.getDiosphere();
|
|
15
|
-
await this.enterRoom({ id: '/' });
|
|
16
|
-
return this;
|
|
17
|
-
};
|
|
18
|
-
this.enterRoom = async (roomObject) => {
|
|
19
|
-
this.room = this.diosphere.getRoom(roomObject);
|
|
20
|
-
this.diograph.resetDiograph();
|
|
21
|
-
await this.getDiograph();
|
|
22
|
-
this.focusDiory({ id: '/' });
|
|
23
|
-
return this.room;
|
|
24
|
-
};
|
|
25
13
|
this.focusDiory = (dioryObject) => {
|
|
26
14
|
return (this.diory = this.diograph.getDiory(dioryObject));
|
|
27
15
|
};
|
|
28
|
-
this.
|
|
29
|
-
|
|
30
|
-
if (this.connections) {
|
|
31
|
-
const connectionClients = (0, getConnectionClients_1.getConnectionClients)(this.dataClients, this.connections);
|
|
32
|
-
await Promise.all(connectionClients.map(async (connectionClient) => {
|
|
33
|
-
const diosphereObject = await connectionClient.getDiosphere();
|
|
34
|
-
console.info(diosphereObject);
|
|
35
|
-
return this.diosphere.addDiosphere(diosphereObject);
|
|
36
|
-
}));
|
|
37
|
-
}
|
|
38
|
-
return this.diosphere;
|
|
39
|
-
};
|
|
40
|
-
this.saveDiosphere = async () => {
|
|
41
|
-
console.info('saveDiosphere', this.connections);
|
|
42
|
-
if (this.connections) {
|
|
43
|
-
const connectionClients = (0, getConnectionClients_1.getConnectionClients)(this.dataClients, this.connections);
|
|
44
|
-
await Promise.all(connectionClients.map(async (connectionClient) => {
|
|
45
|
-
console.info(this.diosphere.toObject());
|
|
46
|
-
await connectionClient.saveDiosphere(this.diosphere.toObject());
|
|
47
|
-
return;
|
|
48
|
-
}));
|
|
49
|
-
}
|
|
50
|
-
return this.diosphere;
|
|
16
|
+
this.selectRoom = (roomObject) => {
|
|
17
|
+
return (this.room = this.diosphere.getRoom(roomObject));
|
|
51
18
|
};
|
|
52
|
-
this.
|
|
53
|
-
var _a
|
|
54
|
-
|
|
55
|
-
if ((_b = this.room) === null || _b === void 0 ? void 0 : _b.connections) {
|
|
56
|
-
const connectionClients = (0, getConnectionClients_1.getConnectionClients)(this.dataClients, this.room.connections);
|
|
57
|
-
await Promise.all(connectionClients.map(async (connectionClient) => {
|
|
58
|
-
const diographObject = await connectionClient.getDiograph();
|
|
59
|
-
console.info(diographObject);
|
|
60
|
-
this.diograph.addDiograph(diographObject);
|
|
61
|
-
return;
|
|
62
|
-
}));
|
|
63
|
-
}
|
|
64
|
-
return this.diograph;
|
|
19
|
+
this.getDiographClients = (connections) => {
|
|
20
|
+
var _a;
|
|
21
|
+
return (0, getConnectionClients_1.getConnectionClients)(this.dataClients, connections !== null && connections !== void 0 ? connections : (_a = this.room) === null || _a === void 0 ? void 0 : _a.connections);
|
|
65
22
|
};
|
|
66
|
-
this.
|
|
67
|
-
var _a
|
|
68
|
-
console.info('
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}));
|
|
76
|
-
}
|
|
23
|
+
this.initialiseDiograph = async (roomObject) => {
|
|
24
|
+
var _a;
|
|
25
|
+
console.info('initialiseDiograph', roomObject);
|
|
26
|
+
this.selectRoom(roomObject);
|
|
27
|
+
this.diograph.resetDiograph();
|
|
28
|
+
const diographObject = (_a = (await this.getDiograph())) !== null && _a !== void 0 ? _a : (0, getDefaultDiograph_1.getDefaultDiograph)();
|
|
29
|
+
this.diograph.addDiograph(diographObject);
|
|
30
|
+
this.focusDiory({ id: '/' });
|
|
31
|
+
console.info(this.diograph.toObject());
|
|
77
32
|
return this.diograph;
|
|
78
33
|
};
|
|
79
|
-
this.
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
const diographObject = await connectionClient.generateDiograph();
|
|
34
|
+
this.getDiograph = async (connections) => {
|
|
35
|
+
console.info('getDiograph', connections);
|
|
36
|
+
let diographObject;
|
|
37
|
+
await Promise.all(this.getDiographClients(connections).map(async (connectionClient) => {
|
|
38
|
+
try {
|
|
39
|
+
diographObject = await connectionClient.getDiograph();
|
|
86
40
|
console.info(diographObject);
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
}
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
console.error(error);
|
|
44
|
+
}
|
|
45
|
+
return;
|
|
46
|
+
}));
|
|
47
|
+
return diographObject;
|
|
48
|
+
};
|
|
49
|
+
this.saveDiograph = async (connections) => {
|
|
50
|
+
console.info('saveDiograph', connections);
|
|
51
|
+
const diographObject = this.diograph.toObject();
|
|
52
|
+
await Promise.all(this.getDiographClients(connections).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());
|
|
91
76
|
}
|
|
92
77
|
return this.diograph;
|
|
93
78
|
};
|
|
79
|
+
this.generateDiograph = async (connections) => {
|
|
80
|
+
console.info('generateDiograph', connections);
|
|
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);
|
|
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
|
+
console.info(this.diosphere.toObject());
|
|
101
|
+
return this.diosphere;
|
|
102
|
+
};
|
|
103
|
+
this.getDiosphere = async (connections) => {
|
|
104
|
+
console.info('getDiosphere', connections);
|
|
105
|
+
let diosphereObject;
|
|
106
|
+
await Promise.all(this.getDiosphereClients(connections).map(async (connectionClient) => {
|
|
107
|
+
try {
|
|
108
|
+
diosphereObject = await connectionClient.getDiosphere();
|
|
109
|
+
console.info(diosphereObject);
|
|
110
|
+
}
|
|
111
|
+
catch (error) {
|
|
112
|
+
console.error(error);
|
|
113
|
+
}
|
|
114
|
+
return;
|
|
115
|
+
}));
|
|
116
|
+
return diosphereObject;
|
|
117
|
+
};
|
|
118
|
+
this.saveDiosphere = async (connections) => {
|
|
119
|
+
console.info('saveDiosphere', connections);
|
|
120
|
+
const diosphereObject = this.diosphere.toObject();
|
|
121
|
+
await Promise.all(this.getDiosphereClients(connections).map(async (connectionClient) => {
|
|
122
|
+
await connectionClient.saveDiosphere(diosphereObject);
|
|
123
|
+
console.info(diosphereObject);
|
|
124
|
+
return;
|
|
125
|
+
}));
|
|
126
|
+
return diosphereObject;
|
|
127
|
+
};
|
|
94
128
|
this.dataClients = dataClients;
|
|
95
129
|
this.diosphere = new diosphere_js_1.Diosphere();
|
|
96
130
|
this.diograph = new diograph_1.Diograph();
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getDefaultDiograph = void 0;
|
|
4
|
+
const diograph_1 = require("@diograph/diograph");
|
|
5
|
+
const getDefaultDiograph = () => {
|
|
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
|
+
text: 'Root',
|
|
13
|
+
links: [{ id: diory.id }],
|
|
14
|
+
}, '/');
|
|
15
|
+
return diograph.toObject();
|
|
16
|
+
};
|
|
17
|
+
exports.getDefaultDiograph = getDefaultDiograph;
|
|
@@ -0,0 +1,13 @@
|
|
|
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
|
+
const getDefaultDiosphere = (connections) => {
|
|
6
|
+
const diosphere = new diosphere_js_1.Diosphere();
|
|
7
|
+
diosphere.addRoom({
|
|
8
|
+
text: 'Room',
|
|
9
|
+
connections,
|
|
10
|
+
}, '/');
|
|
11
|
+
return diosphere.toObject();
|
|
12
|
+
};
|
|
13
|
+
exports.getDefaultDiosphere = getDefaultDiosphere;
|
package/dist/types.d.ts
CHANGED
|
@@ -44,16 +44,18 @@ export interface IConnectionClient {
|
|
|
44
44
|
export interface IDioryClient {
|
|
45
45
|
dataClients: IDataClient[];
|
|
46
46
|
connections: IConnectionObject[];
|
|
47
|
-
diosphere: IDiosphere;
|
|
48
|
-
room?: IRoom;
|
|
49
|
-
diograph: IDiograph;
|
|
50
47
|
diory?: IDiory;
|
|
51
|
-
initialise: (connections: IConnectionObject[]) => Promise<IDioryClient>;
|
|
52
|
-
enterRoom: (roomObject: IRoomObject) => Promise<IRoom>;
|
|
53
48
|
focusDiory: (dioryObject: IDioryObject) => IDiory;
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
49
|
+
room?: IRoom;
|
|
50
|
+
selectRoom: (roomObject: IRoomObject) => IRoom;
|
|
51
|
+
diograph: IDiograph;
|
|
52
|
+
initialiseDiograph: (roomObject: IRoomObject) => Promise<IDiograph>;
|
|
53
|
+
getDiograph: (connections?: IConnectionObject[]) => Promise<IDiographObject | undefined>;
|
|
54
|
+
saveDiograph: (connections?: IConnectionObject[]) => Promise<IDiographObject>;
|
|
55
|
+
importDiograph: (connections?: IConnectionObject[]) => Promise<IDiograph>;
|
|
56
|
+
generateDiograph: (connections?: IConnectionObject[]) => Promise<IDiographObject | undefined>;
|
|
57
|
+
diosphere: IDiosphere;
|
|
58
|
+
initialiseDiosphere: (connections: IConnectionObject[]) => Promise<IDiosphere>;
|
|
59
|
+
getDiosphere: (connections?: IConnectionObject[]) => Promise<IDiosphereObject | undefined>;
|
|
60
|
+
saveDiosphere: (connections?: IConnectionObject[]) => Promise<IDiosphereObject>;
|
|
59
61
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function debounce(func: any, wait: number, immediate?: boolean): () => typeof func;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.debounce = void 0;
|
|
4
|
+
function debounce(func, wait, immediate = false) {
|
|
5
|
+
let timeout;
|
|
6
|
+
// eslint-disable-next-line func-names
|
|
7
|
+
return () => {
|
|
8
|
+
// @ts-ignore
|
|
9
|
+
const context = this;
|
|
10
|
+
const args = arguments;
|
|
11
|
+
// eslint-disable-next-line func-names
|
|
12
|
+
const later = function () {
|
|
13
|
+
timeout = null;
|
|
14
|
+
if (!immediate)
|
|
15
|
+
func.apply(context, args);
|
|
16
|
+
};
|
|
17
|
+
const callNow = immediate && !timeout;
|
|
18
|
+
clearTimeout(timeout);
|
|
19
|
+
timeout = setTimeout(later, wait);
|
|
20
|
+
if (callNow)
|
|
21
|
+
func.apply(context, args);
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
exports.debounce = debounce;
|
|
@@ -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.
|
|
3
|
+
"version": "0.2.1-rc1",
|
|
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
|
|
10
|
-
"@diograph/folder-generator": "^0.3.0
|
|
11
|
-
"@diory/diosphere-js": "0.2.6
|
|
9
|
+
"@diograph/diograph": "^0.3.0",
|
|
10
|
+
"@diograph/folder-generator": "^0.3.0",
|
|
11
|
+
"@diory/diosphere-js": "^0.2.6",
|
|
12
12
|
"path-browserify": "^1.0.1",
|
|
13
13
|
"uuid": "8.3.2"
|
|
14
14
|
},
|
|
@@ -1,8 +1,19 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
Diosphere,
|
|
3
|
+
IConnectionObject,
|
|
4
|
+
IDiosphere,
|
|
5
|
+
IDiosphereObject,
|
|
6
|
+
IRoom,
|
|
7
|
+
IRoomObject,
|
|
8
|
+
} from '@diory/diosphere-js'
|
|
9
|
+
import { Diograph, IDiograph, IDiographObject, IDiory, IDioryObject } from '@diograph/diograph'
|
|
3
10
|
|
|
4
11
|
import { IDioryClient, IDataClient } from '../types'
|
|
5
12
|
import { getConnectionClients } from '../utils/getConnectionClients'
|
|
13
|
+
import { debounce } from '../utils/debounce'
|
|
14
|
+
|
|
15
|
+
import { getDefaultDiosphere } from './getDefaultDiosphere'
|
|
16
|
+
import { getDefaultDiograph } from './getDefaultDiograph'
|
|
6
17
|
|
|
7
18
|
class DioryClient implements IDioryClient {
|
|
8
19
|
dataClients: IDataClient[] = []
|
|
@@ -22,117 +33,157 @@ class DioryClient implements IDioryClient {
|
|
|
22
33
|
this.diograph.saveDiograph = this.saveDiograph
|
|
23
34
|
}
|
|
24
35
|
|
|
25
|
-
|
|
26
|
-
this.
|
|
36
|
+
focusDiory = (dioryObject: IDioryObject): IDiory => {
|
|
37
|
+
return (this.diory = this.diograph.getDiory(dioryObject))
|
|
38
|
+
}
|
|
27
39
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
40
|
+
selectRoom = (roomObject: IRoomObject): IRoom => {
|
|
41
|
+
return (this.room = this.diosphere.getRoom(roomObject))
|
|
42
|
+
}
|
|
31
43
|
|
|
32
|
-
|
|
44
|
+
getDiographClients = (connections?: IConnectionObject[]) => {
|
|
45
|
+
return getConnectionClients(this.dataClients, connections ?? this.room?.connections)
|
|
33
46
|
}
|
|
34
47
|
|
|
35
|
-
|
|
36
|
-
|
|
48
|
+
initialiseDiograph = async (roomObject: IRoomObject): Promise<IDiograph> => {
|
|
49
|
+
console.info('initialiseDiograph', roomObject)
|
|
50
|
+
this.selectRoom(roomObject)
|
|
37
51
|
|
|
38
52
|
this.diograph.resetDiograph()
|
|
39
|
-
await this.getDiograph()
|
|
53
|
+
const diographObject = (await this.getDiograph()) ?? getDefaultDiograph()
|
|
54
|
+
this.diograph.addDiograph(diographObject)
|
|
55
|
+
|
|
40
56
|
this.focusDiory({ id: '/' })
|
|
41
57
|
|
|
42
|
-
|
|
58
|
+
console.info(this.diograph.toObject())
|
|
59
|
+
return this.diograph
|
|
43
60
|
}
|
|
44
61
|
|
|
45
|
-
|
|
46
|
-
|
|
62
|
+
getDiograph = async (connections?: IConnectionObject[]): Promise<IDiographObject | undefined> => {
|
|
63
|
+
console.info('getDiograph', connections)
|
|
64
|
+
|
|
65
|
+
let diographObject
|
|
66
|
+
await Promise.all(
|
|
67
|
+
this.getDiographClients(connections).map(async (connectionClient) => {
|
|
68
|
+
try {
|
|
69
|
+
diographObject = await connectionClient.getDiograph()
|
|
70
|
+
console.info(diographObject)
|
|
71
|
+
} catch (error) {
|
|
72
|
+
console.error(error)
|
|
73
|
+
}
|
|
74
|
+
return
|
|
75
|
+
}),
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
return diographObject
|
|
47
79
|
}
|
|
48
80
|
|
|
49
|
-
|
|
50
|
-
console.info('
|
|
51
|
-
if (this.connections) {
|
|
52
|
-
const connectionClients = getConnectionClients(this.dataClients, this.connections)
|
|
81
|
+
saveDiograph = async (connections?: IConnectionObject[]): Promise<IDiographObject> => {
|
|
82
|
+
console.info('saveDiograph', connections)
|
|
53
83
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
)
|
|
61
|
-
|
|
84
|
+
const diographObject = this.diograph.toObject()
|
|
85
|
+
await Promise.all(
|
|
86
|
+
this.getDiographClients(connections).map(async (connectionClient) => {
|
|
87
|
+
await connectionClient.saveDiograph(diographObject)
|
|
88
|
+
console.info(diographObject)
|
|
89
|
+
return
|
|
90
|
+
}),
|
|
91
|
+
)
|
|
62
92
|
|
|
63
|
-
return
|
|
93
|
+
return diographObject
|
|
64
94
|
}
|
|
65
95
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
})
|
|
77
|
-
|
|
96
|
+
importDiograph = async (connections?: IConnectionObject[]): Promise<IDiograph> => {
|
|
97
|
+
const diographObject = await this.generateDiograph(connections)
|
|
98
|
+
|
|
99
|
+
if (diographObject) {
|
|
100
|
+
const diory = this.diory?.toObject()
|
|
101
|
+
Object.entries(diographObject).forEach(([key, dioryObject]) => {
|
|
102
|
+
try {
|
|
103
|
+
key === '/' && diory
|
|
104
|
+
? this.diograph.addDioryLink(diory, diographObject['/'])
|
|
105
|
+
: this.diograph.addDiory(dioryObject)
|
|
106
|
+
} catch (error) {
|
|
107
|
+
console.error(error)
|
|
108
|
+
}
|
|
109
|
+
})
|
|
110
|
+
|
|
111
|
+
await this.saveDiograph()
|
|
112
|
+
console.info(this.diograph.toObject())
|
|
78
113
|
}
|
|
79
114
|
|
|
80
|
-
return this.
|
|
115
|
+
return this.diograph
|
|
81
116
|
}
|
|
82
117
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
118
|
+
generateDiograph = async (
|
|
119
|
+
connections?: IConnectionObject[],
|
|
120
|
+
): Promise<IDiographObject | undefined> => {
|
|
121
|
+
console.info('generateDiograph', connections)
|
|
122
|
+
|
|
123
|
+
let diographObject
|
|
124
|
+
await Promise.all(
|
|
125
|
+
this.getDiographClients(connections).map(async (connectionClient) => {
|
|
126
|
+
diographObject = await connectionClient.generateDiograph()
|
|
127
|
+
console.info(diographObject)
|
|
128
|
+
return
|
|
129
|
+
}),
|
|
130
|
+
)
|
|
131
|
+
|
|
132
|
+
return diographObject
|
|
133
|
+
}
|
|
97
134
|
|
|
98
|
-
|
|
135
|
+
getDiosphereClients = (connections?: IConnectionObject[]) => {
|
|
136
|
+
return getConnectionClients(this.dataClients, connections ?? this.connections)
|
|
99
137
|
}
|
|
100
138
|
|
|
101
|
-
|
|
102
|
-
console.info('
|
|
103
|
-
|
|
104
|
-
const connectionClients = getConnectionClients(this.dataClients, this.room.connections)
|
|
105
|
-
|
|
106
|
-
await Promise.all(
|
|
107
|
-
connectionClients.map(async (connectionClient) => {
|
|
108
|
-
console.info(this.diograph.toObject())
|
|
109
|
-
await connectionClient.saveDiograph(this.diograph.toObject())
|
|
110
|
-
return
|
|
111
|
-
}),
|
|
112
|
-
)
|
|
113
|
-
}
|
|
139
|
+
initialiseDiosphere = async (connections: IConnectionObject[]): Promise<IDiosphere> => {
|
|
140
|
+
console.info('initialiseDiosphere', connections)
|
|
141
|
+
this.connections = connections
|
|
114
142
|
|
|
115
|
-
|
|
143
|
+
this.diosphere.resetRooms()
|
|
144
|
+
const diosphereObject = (await this.getDiosphere()) ?? getDefaultDiosphere(connections)
|
|
145
|
+
this.diosphere.addDiosphere(diosphereObject)
|
|
146
|
+
|
|
147
|
+
this.selectRoom({ id: '/' })
|
|
148
|
+
|
|
149
|
+
console.info(this.diosphere.toObject())
|
|
150
|
+
return this.diosphere
|
|
116
151
|
}
|
|
117
152
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
153
|
+
getDiosphere = async (
|
|
154
|
+
connections?: IConnectionObject[],
|
|
155
|
+
): Promise<IDiosphereObject | undefined> => {
|
|
156
|
+
console.info('getDiosphere', connections)
|
|
122
157
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
158
|
+
let diosphereObject
|
|
159
|
+
await Promise.all(
|
|
160
|
+
this.getDiosphereClients(connections).map(async (connectionClient) => {
|
|
161
|
+
try {
|
|
162
|
+
diosphereObject = await connectionClient.getDiosphere()
|
|
163
|
+
console.info(diosphereObject)
|
|
164
|
+
} catch (error) {
|
|
165
|
+
console.error(error)
|
|
166
|
+
}
|
|
167
|
+
return
|
|
168
|
+
}),
|
|
169
|
+
)
|
|
170
|
+
|
|
171
|
+
return diosphereObject
|
|
172
|
+
}
|
|
128
173
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
}),
|
|
132
|
-
)
|
|
133
|
-
}
|
|
174
|
+
saveDiosphere = async (connections?: IConnectionObject[]): Promise<IDiosphereObject> => {
|
|
175
|
+
console.info('saveDiosphere', connections)
|
|
134
176
|
|
|
135
|
-
|
|
177
|
+
const diosphereObject = this.diosphere.toObject()
|
|
178
|
+
await Promise.all(
|
|
179
|
+
this.getDiosphereClients(connections).map(async (connectionClient) => {
|
|
180
|
+
await connectionClient.saveDiosphere(diosphereObject)
|
|
181
|
+
console.info(diosphereObject)
|
|
182
|
+
return
|
|
183
|
+
}),
|
|
184
|
+
)
|
|
185
|
+
|
|
186
|
+
return diosphereObject
|
|
136
187
|
}
|
|
137
188
|
}
|
|
138
189
|
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Diograph, IDiographObject } from '@diograph/diograph'
|
|
2
|
+
|
|
3
|
+
export const getDefaultDiograph = (): IDiographObject => {
|
|
4
|
+
const diograph = new 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',
|
|
12
|
+
links: [{ id: diory.id }],
|
|
13
|
+
},
|
|
14
|
+
'/',
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
return diograph.toObject()
|
|
18
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
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
|
+
}
|
package/src/types.ts
CHANGED
|
@@ -54,16 +54,18 @@ export interface IConnectionClient {
|
|
|
54
54
|
export interface IDioryClient {
|
|
55
55
|
dataClients: IDataClient[]
|
|
56
56
|
connections: IConnectionObject[]
|
|
57
|
-
diosphere: IDiosphere
|
|
58
|
-
room?: IRoom
|
|
59
|
-
diograph: IDiograph
|
|
60
57
|
diory?: IDiory
|
|
61
|
-
initialise: (connections: IConnectionObject[]) => Promise<IDioryClient>
|
|
62
|
-
enterRoom: (roomObject: IRoomObject) => Promise<IRoom>
|
|
63
58
|
focusDiory: (dioryObject: IDioryObject) => IDiory
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
59
|
+
room?: IRoom
|
|
60
|
+
selectRoom: (roomObject: IRoomObject) => IRoom
|
|
61
|
+
diograph: IDiograph
|
|
62
|
+
initialiseDiograph: (roomObject: IRoomObject) => Promise<IDiograph>
|
|
63
|
+
getDiograph: (connections?: IConnectionObject[]) => Promise<IDiographObject | undefined>
|
|
64
|
+
saveDiograph: (connections?: IConnectionObject[]) => Promise<IDiographObject>
|
|
65
|
+
importDiograph: (connections?: IConnectionObject[]) => Promise<IDiograph>
|
|
66
|
+
generateDiograph: (connections?: IConnectionObject[]) => Promise<IDiographObject | undefined>
|
|
67
|
+
diosphere: IDiosphere
|
|
68
|
+
initialiseDiosphere: (connections: IConnectionObject[]) => Promise<IDiosphere>
|
|
69
|
+
getDiosphere: (connections?: IConnectionObject[]) => Promise<IDiosphereObject | undefined>
|
|
70
|
+
saveDiosphere: (connections?: IConnectionObject[]) => Promise<IDiosphereObject>
|
|
69
71
|
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export function debounce(func: any, wait: number, immediate = false) {
|
|
2
|
+
let timeout: any
|
|
3
|
+
// eslint-disable-next-line func-names
|
|
4
|
+
return (): typeof func => {
|
|
5
|
+
// @ts-ignore
|
|
6
|
+
const context = this
|
|
7
|
+
const args = arguments
|
|
8
|
+
// eslint-disable-next-line func-names
|
|
9
|
+
const later = function () {
|
|
10
|
+
timeout = null
|
|
11
|
+
if (!immediate) func.apply(context, args)
|
|
12
|
+
}
|
|
13
|
+
const callNow = immediate && !timeout
|
|
14
|
+
clearTimeout(timeout)
|
|
15
|
+
timeout = setTimeout(later, wait)
|
|
16
|
+
if (callNow) func.apply(context, args)
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -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)
|
package/tsconfig.json
CHANGED