@diory/client-js 0.4.0-rc1 → 0.4.0

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.
Files changed (35) hide show
  1. package/README.md +2 -1
  2. package/dist/dioryClient/dioryClient.d.ts +5 -17
  3. package/dist/dioryClient/dioryClient.js +25 -114
  4. package/dist/index.d.ts +1 -2
  5. package/dist/index.js +1 -3
  6. package/dist/types.d.ts +8 -27
  7. package/dist/utils/addDefaultDiograph.d.ts +2 -0
  8. package/dist/{dioryClient/getDefaultDiograph.js → utils/addDefaultDiograph.js} +4 -7
  9. package/dist/utils/addDefaultRoom.d.ts +2 -0
  10. package/dist/utils/addDefaultRoom.js +10 -0
  11. package/package.json +10 -9
  12. package/src/dioryClient/dioryClient.ts +35 -148
  13. package/src/index.ts +1 -2
  14. package/src/types.ts +8 -34
  15. package/src/{dioryClient/getDefaultDiograph.ts → utils/addDefaultDiograph.ts} +3 -6
  16. package/src/utils/addDefaultRoom.ts +11 -0
  17. package/dist/connectionClient/connectionClient.d.ts +0 -16
  18. package/dist/connectionClient/connectionClient.js +0 -39
  19. package/dist/connectionClient/connectionClient.spec.d.ts +0 -0
  20. package/dist/connectionClient/connectionClient.spec.js +0 -18
  21. package/dist/connectionClient/utils/debounce.d.ts +0 -1
  22. package/dist/connectionClient/utils/debounce.js +0 -22
  23. package/dist/dioryClient/defaultDiograph.json +0 -24
  24. package/dist/dioryClient/defaultDiosphere.d.ts +0 -21
  25. package/dist/dioryClient/defaultDiosphere.js +0 -26
  26. package/dist/dioryClient/defaultDiosphere.json +0 -23
  27. package/dist/dioryClient/getDefaultDiograph.d.ts +0 -2
  28. package/dist/dioryClient/getDefaultDiosphere.d.ts +0 -2
  29. package/dist/dioryClient/getDefaultDiosphere.js +0 -13
  30. package/dist/utils/getConnectionClients.d.ts +0 -4
  31. package/dist/utils/getConnectionClients.js +0 -16
  32. package/src/connectionClient/connectionClient.spec.ts +0 -19
  33. package/src/connectionClient/connectionClient.ts +0 -54
  34. package/src/dioryClient/getDefaultDiosphere.ts +0 -14
  35. package/src/utils/getConnectionClients.ts +0 -24
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 { diosphere, room, diograph, diory } = DioryClient(clients)
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,26 +1,14 @@
1
- import { IConnectionObject, IDiosphere, IDiosphereObject, IRoom, IRoomObject } from '@diory/diosphere-js';
2
- import { IDiograph, IDiographObject, IDiory, IDioryObject } from '@diograph/diograph';
3
- import { IDataClient } from '@diograph/local-client';
1
+ import { IConnectionObject, IDiosphere, IRoom, IRoomObject, IDiograph, IDiory, IDioryObject, IDataClient } from '@diory/types';
4
2
  import { IDioryClient } from '../types';
5
3
  declare class DioryClient implements IDioryClient {
6
- dataClients: IDataClient[];
7
- connections: IConnectionObject[];
8
4
  diosphere: IDiosphere;
9
- room?: IRoom;
10
5
  diograph: IDiograph;
6
+ room?: IRoom;
11
7
  diory?: IDiory;
12
8
  constructor(dataClients: IDataClient[]);
13
- focusDiory: (dioryObject: IDioryObject) => IDiory;
14
- selectRoom: (roomObject: IRoomObject) => IRoom;
15
- getDiographClients: (connections?: IConnectionObject[]) => import("../types").IConnectionClient[];
16
- initialiseDiograph: (roomObject: IRoomObject) => Promise<IDiograph>;
17
- getDiograph: () => Promise<IDiographObject | undefined>;
18
- saveDiograph: () => Promise<IDiographObject>;
19
- importDiograph: (connections?: IConnectionObject[]) => Promise<IDiograph>;
20
- generateDiograph: (connections?: IConnectionObject[]) => Promise<IDiographObject | undefined>;
21
- getDiosphereClients: (connections?: IConnectionObject[]) => import("../types").IConnectionClient[];
22
9
  initialiseDiosphere: (connections: IConnectionObject[]) => Promise<IDiosphere>;
23
- getDiosphere: () => Promise<IDiosphereObject | undefined>;
24
- saveDiosphere: () => Promise<IDiosphereObject>;
10
+ initialiseDiograph: (roomObject: IRoomObject) => Promise<IDiograph>;
11
+ selectRoom: (roomObject: IRoomObject) => IRoom;
12
+ focusDiory: (dioryObject: IDioryObject) => IDiory;
25
13
  }
26
14
  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 getConnectionClients_1 = require("../utils/getConnectionClients");
7
- const debounce_1 = require("../utils/debounce");
8
- const getDefaultDiosphere_1 = require("./getDefaultDiosphere");
9
- const getDefaultDiograph_1 = require("./getDefaultDiograph");
6
+ const connection_client_js_1 = require("@diory/connection-client-js");
7
+ const addDefaultRoom_1 = require("../utils/addDefaultRoom");
8
+ const addDefaultDiograph_1 = require("../utils/addDefaultDiograph");
10
9
  class DioryClient {
11
10
  constructor(dataClients) {
12
- this.dataClients = [];
13
- this.connections = [];
14
- this.focusDiory = (dioryObject) => {
15
- return (this.diory = this.diograph.getDiory(dioryObject));
16
- };
17
- this.selectRoom = (roomObject) => {
18
- return (this.room = this.diosphere.getRoom(roomObject));
19
- };
20
- this.getDiographClients = (connections) => {
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.diograph.resetDiograph();
29
- const diographObject = (_a = (await this.getDiograph())) !== null && _a !== void 0 ? _a : (0, getDefaultDiograph_1.getDefaultDiograph)();
30
- this.diograph.addDiograph(diographObject);
31
- this.focusDiory({ id: '/' });
32
- return this.diograph;
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
- return;
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.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', 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.saveDiosphere = async () => {
118
- console.info('saveDiosphere');
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.dataClients = dataClients;
128
- this.diosphere = new diosphere_js_1.Diosphere();
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 connection_client_js_1.ConnectionClient(dataClients));
42
+ this.diograph = new diograph_1.Diograph(new connection_client_js_1.ConnectionClient(dataClients));
132
43
  }
133
44
  }
134
45
  exports.DioryClient = DioryClient;
package/dist/index.d.ts CHANGED
@@ -1,3 +1,2 @@
1
1
  export { DioryClient } from './dioryClient/dioryClient';
2
- export { ConnectionClient } from './connectionClient/connectionClient';
3
- export { IDioryClient, IConnectionClient } from './types';
2
+ export { IDioryClient } from './types';
package/dist/index.js CHANGED
@@ -1,7 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ConnectionClient = exports.DioryClient = void 0;
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,31 +1,12 @@
1
- import { IConnectionObject, IDiosphere, IDiosphereObject, IRoom, IRoomObject } from '@diory/diosphere-js';
2
- import { IDiograph, IDiographObject, IDiory, IDioryObject } from '@diograph/diograph';
3
- import { IDataClient } from '@diograph/local-client';
4
- export interface IConnectionClient {
5
- type: string;
6
- client: IDataClient;
7
- connection: IConnectionObject;
8
- getDiosphere: () => Promise<IDiosphereObject>;
9
- saveDiosphere: (diosphereObject: IDiosphereObject) => void;
10
- getDiograph: () => Promise<IDiographObject>;
11
- saveDiograph: (diographObject: IDiographObject) => void;
12
- generateDiograph: () => Promise<IDiographObject>;
13
- }
1
+ import { IConnectionObject, IDiosphere, IRoom, IRoomObject } from '@diory/types';
2
+ import { IDiograph, IDiory, IDioryObject } from '@diory/types';
14
3
  export interface IDioryClient {
15
- dataClients: IDataClient[];
16
- connections: IConnectionObject[];
17
- diory?: IDiory;
18
- focusDiory: (dioryObject: IDioryObject) => IDiory;
19
- room?: IRoom;
20
- selectRoom: (roomObject: IRoomObject) => IRoom;
21
- diograph: IDiograph;
22
- initialiseDiograph: (roomObject: IRoomObject) => Promise<IDiograph>;
23
- getDiograph: () => Promise<IDiographObject | undefined>;
24
- saveDiograph: () => Promise<IDiographObject>;
25
- importDiograph: (connections?: IConnectionObject[]) => Promise<IDiograph>;
26
- generateDiograph: (connections?: IConnectionObject[]) => Promise<IDiographObject | undefined>;
27
4
  diosphere: IDiosphere;
5
+ diograph: IDiograph;
6
+ room?: IRoom;
7
+ diory?: IDiory;
28
8
  initialiseDiosphere: (connections: IConnectionObject[]) => Promise<IDiosphere>;
29
- getDiosphere: () => Promise<IDiosphereObject | undefined>;
30
- saveDiosphere: () => Promise<IDiosphereObject>;
9
+ initialiseDiograph: (roomObject: IRoomObject) => Promise<IDiograph>;
10
+ selectRoom: (roomObject: IRoomObject) => IRoom;
11
+ focusDiory: (dioryObject: IDioryObject) => IDiory;
31
12
  }
@@ -0,0 +1,2 @@
1
+ import { IDiograph } from '@diory/types';
2
+ export declare const addDefaultDiograph: (diograph: IDiograph) => void;
@@ -1,17 +1,14 @@
1
1
  "use strict";
2
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();
3
+ exports.addDefaultDiograph = void 0;
4
+ const addDefaultDiograph = (diograph) => {
7
5
  const diory = diograph.addDiory({
8
6
  text: 'Welcome to Diory',
9
7
  latlng: '60.01366036242365, 20.007133483886722',
10
8
  });
11
9
  diograph.addDiory({
12
- text: 'Root',
10
+ text: 'Root diory',
13
11
  links: [{ id: diory.id }],
14
12
  }, '/');
15
- return diograph.toObject();
16
13
  };
17
- exports.getDefaultDiograph = getDefaultDiograph;
14
+ exports.addDefaultDiograph = addDefaultDiograph;
@@ -0,0 +1,2 @@
1
+ import { IConnectionObject, IDiosphere } from '@diory/types';
2
+ export declare const addDefaultRoom: (diosphere: IDiosphere, connections: IConnectionObject[]) => void;
@@ -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;
package/package.json CHANGED
@@ -1,19 +1,19 @@
1
1
  {
2
2
  "name": "@diory/client-js",
3
- "version": "0.4.0-rc1",
3
+ "version": "0.4.0",
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.4.0-rc1",
11
- "@diograph/local-client": "^0.3.2",
12
- "@diory/diosphere-js": "^0.2.6",
9
+ "@diograph/diograph": "^0.4.0",
10
+ "@diory/connection-client-js": "^0.4.0",
11
+ "@diory/diosphere-js": "^0.4.0",
13
12
  "path-browserify": "^1.0.1",
14
13
  "uuid": "8.3.2"
15
14
  },
16
15
  "devDependencies": {
16
+ "@diory/types": "^0.4.0",
17
17
  "@types/jest": "^27.4.0",
18
18
  "@types/path-browserify": "^1.0.2",
19
19
  "@types/uuid": "8.3.2",
@@ -41,14 +41,15 @@
41
41
  },
42
42
  "repository": {
43
43
  "type": "git",
44
- "url": "git+https://github.com/DioryMe/diosphere-js.git"
44
+ "url": "git+https://github.com/DioryMe/diory-client-js.git"
45
45
  },
46
46
  "keywords": [
47
47
  "diory",
48
- "diosphere"
48
+ "diosphere",
49
+ "diograph"
49
50
  ],
50
51
  "bugs": {
51
- "url": "https://github.com/DioryMe/diosphere-js/issues"
52
+ "url": "https://github.com/DioryMe/diory-client-js/issues"
52
53
  },
53
- "homepage": "https://github.com/DioryMe/diosphere-js#readme"
54
+ "homepage": "https://github.com/DioryMe/diory-client-js#readme"
54
55
  }
@@ -1,186 +1,73 @@
1
+ import { Diosphere } from '@diory/diosphere-js'
2
+ import { Diograph } from '@diograph/diograph'
3
+ import { ConnectionClient } from '@diory/connection-client-js'
4
+
1
5
  import {
2
- Diosphere,
3
6
  IConnectionObject,
4
7
  IDiosphere,
5
- IDiosphereObject,
6
8
  IRoom,
7
9
  IRoomObject,
8
- } from '@diory/diosphere-js'
9
- import { Diograph, IDiograph, IDiographObject, IDiory, IDioryObject } from '@diograph/diograph'
10
- import { IDataClient } from '@diograph/local-client'
10
+ IDiograph,
11
+ IDiory,
12
+ IDioryObject,
13
+ IDataClient,
14
+ } from '@diory/types'
11
15
 
12
16
  import { IDioryClient } from '../types'
13
- import { getConnectionClients } from '../utils/getConnectionClients'
14
- import { debounce } from '../utils/debounce'
15
17
 
16
- import { getDefaultDiosphere } from './getDefaultDiosphere'
17
- import { getDefaultDiograph } from './getDefaultDiograph'
18
+ import { addDefaultRoom } from '../utils/addDefaultRoom'
19
+ import { addDefaultDiograph } from '../utils/addDefaultDiograph'
18
20
 
19
21
  class DioryClient implements IDioryClient {
20
- dataClients: IDataClient[] = []
21
- connections: IConnectionObject[] = []
22
22
  diosphere: IDiosphere
23
- room?: IRoom
24
23
  diograph: IDiograph
24
+ room?: IRoom
25
25
  diory?: IDiory
26
26
 
27
27
  constructor(dataClients: IDataClient[]) {
28
- this.dataClients = dataClients
28
+ this.diosphere = new Diosphere(new ConnectionClient(dataClients))
29
+ this.diograph = new Diograph(new ConnectionClient(dataClients))
30
+ }
29
31
 
30
- this.diosphere = new Diosphere()
31
- this.diograph = new Diograph()
32
+ initialiseDiosphere = async (connections: IConnectionObject[]): Promise<IDiosphere> => {
33
+ console.info('initialiseDiosphere: connections', connections)
32
34
 
33
- this.diosphere.saveDiosphere = debounce(this.saveDiosphere, 1000)
34
- this.diograph.saveDiograph = debounce(this.saveDiograph, 1000)
35
- }
35
+ this.diosphere.initialise(connections)
36
+ await this.diosphere.getDiosphere()
36
37
 
37
- focusDiory = (dioryObject: IDioryObject): IDiory => {
38
- return (this.diory = this.diograph.getDiory(dioryObject))
39
- }
38
+ if (!Object.keys(this.diosphere.rooms)) {
39
+ addDefaultRoom(this.diosphere, connections)
40
+ }
40
41
 
41
- selectRoom = (roomObject: IRoomObject): IRoom => {
42
- return (this.room = this.diosphere.getRoom(roomObject))
43
- }
42
+ this.selectRoom({ id: '/' })
44
43
 
45
- getDiographClients = (connections?: IConnectionObject[]) => {
46
- return getConnectionClients(this.dataClients, connections ?? this.room?.connections)
44
+ return this.diosphere
47
45
  }
48
46
 
49
47
  initialiseDiograph = async (roomObject: IRoomObject): Promise<IDiograph> => {
50
48
  console.info('initialiseDiograph: room', roomObject)
51
49
  this.selectRoom(roomObject)
52
50
 
53
- this.diograph.resetDiograph()
54
- const diographObject = (await this.getDiograph()) ?? getDefaultDiograph()
55
- this.diograph.addDiograph(diographObject)
56
-
57
- this.focusDiory({ id: '/' })
58
-
59
- return this.diograph
60
- }
61
-
62
- getDiograph = async (): Promise<IDiographObject | undefined> => {
63
- console.info('getDiograph')
64
-
65
- let diographObject
66
- await Promise.all(
67
- this.getDiographClients().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
79
- }
80
-
81
- saveDiograph = async (): Promise<IDiographObject> => {
82
- console.info('saveDiograph')
83
-
84
- const diographObject = this.diograph.toObject()
85
- await Promise.all(
86
- this.getDiographClients().map(async (connectionClient) => {
87
- await connectionClient.saveDiograph(diographObject)
88
- console.info(diographObject)
89
- return
90
- }),
91
- )
51
+ if (this.room?.connections) {
52
+ this.diograph.initialise(this.room?.connections)
53
+ await this.diograph.getDiograph()
92
54
 
93
- return diographObject
94
- }
55
+ if (!Object.keys(this.diograph.diograph)) {
56
+ addDefaultDiograph(this.diograph)
57
+ }
95
58
 
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())
59
+ this.focusDiory({ id: '/' })
113
60
  }
114
61
 
115
62
  return this.diograph
116
63
  }
117
64
 
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
- }
134
-
135
- getDiosphereClients = (connections?: IConnectionObject[]) => {
136
- return getConnectionClients(this.dataClients, connections ?? this.connections)
137
- }
138
-
139
- initialiseDiosphere = async (connections: IConnectionObject[]): Promise<IDiosphere> => {
140
- console.info('initialiseDiosphere: connections', connections)
141
- this.connections = connections
142
-
143
- this.diosphere.resetRooms()
144
- const diosphereObject = (await this.getDiosphere()) ?? getDefaultDiosphere(connections)
145
- this.diosphere.addDiosphere(diosphereObject)
146
-
147
- this.selectRoom({ id: '/' })
148
-
149
- return this.diosphere
150
- }
151
-
152
- getDiosphere = async (): Promise<IDiosphereObject | undefined> => {
153
- console.info('getDiosphere')
154
-
155
- let diosphereObject
156
- await Promise.all(
157
- this.getDiosphereClients().map(async (connectionClient) => {
158
- try {
159
- diosphereObject = await connectionClient.getDiosphere()
160
- console.info(diosphereObject)
161
- } catch (error) {
162
- console.error(error)
163
- }
164
- return
165
- }),
166
- )
167
-
168
- return diosphereObject
65
+ selectRoom = (roomObject: IRoomObject): IRoom => {
66
+ return (this.room = this.diosphere.getRoom(roomObject))
169
67
  }
170
68
 
171
- saveDiosphere = async (): Promise<IDiosphereObject> => {
172
- console.info('saveDiosphere')
173
-
174
- const diosphereObject = this.diosphere.toObject()
175
- await Promise.all(
176
- this.getDiosphereClients().map(async (connectionClient) => {
177
- await connectionClient.saveDiosphere(diosphereObject)
178
- console.info(diosphereObject)
179
- return
180
- }),
181
- )
182
-
183
- return diosphereObject
69
+ focusDiory = (dioryObject: IDioryObject): IDiory => {
70
+ return (this.diory = this.diograph.getDiory(dioryObject))
184
71
  }
185
72
  }
186
73
 
package/src/index.ts CHANGED
@@ -1,3 +1,2 @@
1
1
  export { DioryClient } from './dioryClient/dioryClient'
2
- export { ConnectionClient } from './connectionClient/connectionClient'
3
- export { IDioryClient, IConnectionClient } from './types'
2
+ export { IDioryClient } from './types'
package/src/types.ts CHANGED
@@ -1,39 +1,13 @@
1
- import {
2
- IConnectionObject,
3
- IDiosphere,
4
- IDiosphereObject,
5
- IRoom,
6
- IRoomObject,
7
- } from '@diory/diosphere-js'
8
- import { IDiograph, IDiographObject, IDiory, IDioryObject } from '@diograph/diograph'
9
- import { IDataClient } from '@diograph/local-client'
10
-
11
- export interface IConnectionClient {
12
- type: string
13
- client: IDataClient
14
- connection: IConnectionObject
15
- getDiosphere: () => Promise<IDiosphereObject>
16
- saveDiosphere: (diosphereObject: IDiosphereObject) => void
17
- getDiograph: () => Promise<IDiographObject>
18
- saveDiograph: (diographObject: IDiographObject) => void
19
- generateDiograph: () => Promise<IDiographObject>
20
- }
1
+ import { IConnectionObject, IDiosphere, IRoom, IRoomObject } from '@diory/types'
2
+ import { IDiograph, IDiory, IDioryObject } from '@diory/types'
21
3
 
22
4
  export interface IDioryClient {
23
- dataClients: IDataClient[]
24
- connections: IConnectionObject[]
25
- diory?: IDiory
26
- focusDiory: (dioryObject: IDioryObject) => IDiory
27
- room?: IRoom
28
- selectRoom: (roomObject: IRoomObject) => IRoom
29
- diograph: IDiograph
30
- initialiseDiograph: (roomObject: IRoomObject) => Promise<IDiograph>
31
- getDiograph: () => Promise<IDiographObject | undefined>
32
- saveDiograph: () => Promise<IDiographObject>
33
- importDiograph: (connections?: IConnectionObject[]) => Promise<IDiograph>
34
- generateDiograph: (connections?: IConnectionObject[]) => Promise<IDiographObject | undefined>
35
5
  diosphere: IDiosphere
6
+ diograph: IDiograph
7
+ room?: IRoom
8
+ diory?: IDiory
36
9
  initialiseDiosphere: (connections: IConnectionObject[]) => Promise<IDiosphere>
37
- getDiosphere: () => Promise<IDiosphereObject | undefined>
38
- saveDiosphere: () => Promise<IDiosphereObject>
10
+ initialiseDiograph: (roomObject: IRoomObject) => Promise<IDiograph>
11
+ selectRoom: (roomObject: IRoomObject) => IRoom
12
+ focusDiory: (dioryObject: IDioryObject) => IDiory
39
13
  }
@@ -1,18 +1,15 @@
1
- import { Diograph, IDiographObject } from '@diograph/diograph'
1
+ import { IDiograph } from '@diory/types'
2
2
 
3
- export const getDefaultDiograph = (): IDiographObject => {
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
  }
@@ -0,0 +1,11 @@
1
+ import { IConnectionObject, IDiosphere } from '@diory/types'
2
+
3
+ export const addDefaultRoom = (diosphere: IDiosphere, connections: IConnectionObject[]): void => {
4
+ diosphere.addRoom(
5
+ {
6
+ text: 'Home room',
7
+ connections,
8
+ },
9
+ '/',
10
+ )
11
+ }
@@ -1,16 +0,0 @@
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';
5
- declare class ConnectionClient implements IConnectionClient {
6
- type: string;
7
- client: IDataClient;
8
- connection: IConnectionObject;
9
- constructor(dataClient: IDataClient, connection: IConnectionObject);
10
- getDiosphere: () => Promise<any>;
11
- saveDiosphere: (diosphereObject: IDiosphereObject) => Promise<boolean>;
12
- getDiograph: () => Promise<any>;
13
- saveDiograph: (diographObject: IDiographObject) => Promise<boolean>;
14
- generateDiograph: () => Promise<IDiographObject>;
15
- }
16
- export { ConnectionClient };
@@ -1,39 +0,0 @@
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
- class ConnectionClient {
9
- constructor(dataClient, connection) {
10
- this.getDiosphere = async () => {
11
- const path = (0, path_browserify_1.join)(this.connection.address, DIOSPHERE_JSON);
12
- const diosphereString = await this.client.readTextItem(path);
13
- return JSON.parse(diosphereString);
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;
37
- }
38
- }
39
- exports.ConnectionClient = ConnectionClient;
File without changes
@@ -1,18 +0,0 @@
1
- "use strict";
2
- describe('connectionClient', () => {
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
- });
@@ -1 +0,0 @@
1
- export declare function debounce(func: any, wait: number, immediate?: boolean): () => typeof func
@@ -1,22 +0,0 @@
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
@@ -1,24 +0,0 @@
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
- }
@@ -1,21 +0,0 @@
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
- }
@@ -1,26 +0,0 @@
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
- }
@@ -1,23 +0,0 @@
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,2 +0,0 @@
1
- import { IDiographObject } from '@diograph/diograph';
2
- export declare const getDefaultDiograph: () => IDiographObject;
@@ -1,2 +0,0 @@
1
- import { IConnectionObject, IDiosphereObject } from '@diory/diosphere-js';
2
- export declare const getDefaultDiosphere: (connections: IConnectionObject[]) => IDiosphereObject;
@@ -1,13 +0,0 @@
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;
@@ -1,4 +0,0 @@
1
- import { IConnectionObject } from '@diory/diosphere-js';
2
- import { IDataClient } from '@diograph/local-client';
3
- import { IConnectionClient } from '../types';
4
- export declare function getConnectionClients(dataClients: IDataClient[], connections?: IConnectionObject[]): IConnectionClient[];
@@ -1,16 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getConnectionClients = void 0;
4
- const connectionClient_1 = require("../connectionClient/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;
@@ -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,54 +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 { IDataClient } from '@diograph/local-client'
7
-
8
- import { IConnectionClient } from '../types'
9
-
10
- const DIOSPHERE_JSON = 'diosphere.json'
11
- const DIOGRAPH_JSON = 'diograph.json'
12
-
13
- class ConnectionClient implements IConnectionClient {
14
- type: string
15
- client: IDataClient
16
- connection: IConnectionObject
17
-
18
- constructor(dataClient: IDataClient, connection: IConnectionObject) {
19
- this.type = dataClient.type
20
- this.client = dataClient
21
- this.connection = connection
22
- }
23
-
24
- getDiosphere = async () => {
25
- const path = join(this.connection.address, DIOSPHERE_JSON)
26
- const diosphereString = await this.client.readTextItem(path)
27
- return JSON.parse(diosphereString)
28
- }
29
-
30
- saveDiosphere = async (diosphereObject: IDiosphereObject) => {
31
- const path = join(this.connection.address, DIOSPHERE_JSON)
32
- const diosphereString = JSON.stringify(diosphereObject, null, 2)
33
- return this.client.writeItem(path, diosphereString)
34
- }
35
-
36
- getDiograph = async () => {
37
- const path = join(this.connection.address, DIOGRAPH_JSON)
38
- const diographString = await this.client.readTextItem(path)
39
- return JSON.parse(diographString)
40
- }
41
-
42
- saveDiograph = async (diographObject: IDiographObject) => {
43
- const path = join(this.connection.address, DIOGRAPH_JSON)
44
- const diographString = JSON.stringify(diographObject, null, 2)
45
- return this.client.writeItem(path, diographString)
46
- }
47
-
48
- generateDiograph = async (): Promise<IDiographObject> => {
49
- const { diograph } = await generateDiograph(this.connection.address, this.client)
50
- return diograph.toObject()
51
- }
52
- }
53
-
54
- 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,24 +0,0 @@
1
- import { IConnectionObject } from '@diory/diosphere-js'
2
- import { IDataClient } from '@diograph/local-client'
3
-
4
- import { ConnectionClient } from '../connectionClient/connectionClient'
5
- import { IConnectionClient } from '../types'
6
-
7
- function getDataClient(
8
- dataClients: IDataClient[],
9
- { client }: IConnectionObject,
10
- ): IDataClient | undefined {
11
- return dataClients.find(({ type }) => type === client)
12
- }
13
-
14
- export 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
- }