@diory/client-js 0.2.0-rc11 → 0.2.0-rc13

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.
@@ -0,0 +1,23 @@
1
+ {
2
+ "/": {
3
+ "id": "welcome-root-diory"
4
+ },
5
+ "welcome-root-diory": {
6
+ "id": "welcome-root-diory",
7
+ "image": "",
8
+ "links": [
9
+ {
10
+ "id": "welcome-diory"
11
+ }
12
+ ],
13
+ "modified": "2020-01-03T14:03:04.751Z"
14
+ },
15
+ "welcome-diory": {
16
+ "id": "welcome-diory",
17
+ "image": "",
18
+ "modified": "2020-01-03T14:03:04.751Z",
19
+ "text": "Welcome to Diory",
20
+ "latitude": 60.01366036242365,
21
+ "longitude": 20.007133483886722
22
+ }
23
+ }
@@ -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,15 +9,16 @@ 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
- focusDiory: (dioryObject: IDioryObject) => IDiory;
12
+ selectRoom: (roomObject: IRoomObject) => IRoom;
15
13
  getDiosphereClients: (connections?: IConnectionObject[]) => import("../types").IConnectionClient[];
14
+ initialiseDiosphere: (connections: IConnectionObject[]) => Promise<IDiosphere>;
15
+ getDiosphere: (connections?: IConnectionObject[]) => Promise<IDiosphereObject | undefined>;
16
+ saveDiosphere: (connections?: IConnectionObject[]) => Promise<IDiosphereObject>;
16
17
  getDiographClients: (connections?: IConnectionObject[]) => import("../types").IConnectionClient[];
17
- getDiosphere: (connections?: IConnectionObject[]) => Promise<IDiosphere>;
18
- saveDiosphere: (connections?: IConnectionObject[]) => Promise<IDiosphere>;
19
- getDiograph: (connections?: IConnectionObject[]) => Promise<IDiograph>;
20
- saveDiograph: (connections?: IConnectionObject[]) => Promise<IDiograph>;
18
+ focusDiory: (dioryObject: IDioryObject) => IDiory;
19
+ initialiseDiograph: (roomObject: IRoomObject) => Promise<IDiograph>;
20
+ getDiograph: (connections?: IConnectionObject[]) => Promise<IDiographObject | undefined>;
21
+ saveDiograph: (connections?: IConnectionObject[]) => Promise<IDiographObject>;
21
22
  generateDiograph: (connections?: IConnectionObject[]) => Promise<IDiograph>;
22
23
  }
23
24
  export { DioryClient };
@@ -1,75 +1,100 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.DioryClient = void 0;
4
7
  const diosphere_js_1 = require("@diory/diosphere-js");
5
8
  const diograph_1 = require("@diograph/diograph");
6
9
  const getConnectionClients_1 = require("../utils/getConnectionClients");
10
+ const defaultDiosphere_json_1 = __importDefault(require("./defaultDiosphere.json"));
11
+ const defaultDiograph_json_1 = __importDefault(require("./defaultDiograph.json"));
7
12
  class DioryClient {
8
13
  constructor(dataClients) {
9
14
  this.dataClients = [];
10
15
  this.connections = [];
11
- this.initialise = async (connections) => {
12
- console.info('initialise', connections);
13
- this.connections = connections;
14
- this.diosphere.resetRooms();
15
- return this;
16
- };
17
- this.enterRoom = async (roomObject) => {
18
- console.info('enterRoom', roomObject);
19
- this.room = this.diosphere.getRoom(roomObject);
20
- this.diograph.resetDiograph();
21
- await this.getDiograph();
22
- this.focusDiory({ id: '/' });
23
- console.info(this.room);
24
- return this.room;
25
- };
26
- this.focusDiory = (dioryObject) => {
27
- return (this.diory = this.diograph.getDiory(dioryObject));
16
+ this.selectRoom = (roomObject) => {
17
+ return (this.room = this.diosphere.getRoom(roomObject));
28
18
  };
29
19
  this.getDiosphereClients = (connections) => {
30
20
  return (0, getConnectionClients_1.getConnectionClients)(this.dataClients, connections !== null && connections !== void 0 ? connections : this.connections);
31
21
  };
32
- this.getDiographClients = (connections) => {
22
+ this.initialiseDiosphere = async (connections) => {
33
23
  var _a;
34
- return (0, getConnectionClients_1.getConnectionClients)(this.dataClients, connections !== null && connections !== void 0 ? connections : (_a = this.room) === null || _a === void 0 ? void 0 : _a.connections);
24
+ console.info('initialiseDiosphere', connections);
25
+ this.connections = connections;
26
+ this.diosphere.resetRooms();
27
+ const diosphereObject = (_a = (await this.getDiosphere())) !== null && _a !== void 0 ? _a : defaultDiosphere_json_1.default;
28
+ this.diosphere.addDiosphere(diosphereObject);
29
+ this.selectRoom({ id: '/' });
30
+ return this.diosphere;
35
31
  };
36
32
  this.getDiosphere = async (connections) => {
37
33
  console.info('getDiosphere', connections);
34
+ let diosphereObject;
38
35
  await Promise.all(this.getDiosphereClients(connections).map(async (connectionClient) => {
39
- const diosphereObject = await connectionClient.getDiosphere();
40
- this.diosphere.addDiosphere(diosphereObject);
41
- console.info(this.diosphere.toObject());
36
+ try {
37
+ diosphereObject = await connectionClient.getDiosphere();
38
+ console.info(this.diosphere.toObject());
39
+ }
40
+ catch (error) {
41
+ console.error(error);
42
+ }
42
43
  return;
43
44
  }));
44
- return this.diosphere;
45
+ return diosphereObject;
45
46
  };
46
47
  this.saveDiosphere = async (connections) => {
47
48
  console.info('saveDiosphere', connections);
49
+ const diosphereObject = this.diosphere.toObject();
48
50
  await Promise.all(this.getDiosphereClients(connections).map(async (connectionClient) => {
49
- await connectionClient.saveDiosphere(this.diosphere.toObject());
50
- console.info(this.diosphere.toObject());
51
+ await connectionClient.saveDiosphere(diosphereObject);
52
+ console.info(diosphereObject);
51
53
  return;
52
54
  }));
53
- return this.diosphere;
55
+ return diosphereObject;
56
+ };
57
+ this.getDiographClients = (connections) => {
58
+ var _a;
59
+ return (0, getConnectionClients_1.getConnectionClients)(this.dataClients, connections !== null && connections !== void 0 ? connections : (_a = this.room) === null || _a === void 0 ? void 0 : _a.connections);
60
+ };
61
+ this.focusDiory = (dioryObject) => {
62
+ return (this.diory = this.diograph.getDiory(dioryObject));
63
+ };
64
+ this.initialiseDiograph = async (roomObject) => {
65
+ var _a;
66
+ console.info('initialiseDiograph', roomObject);
67
+ this.selectRoom(roomObject);
68
+ this.diograph.resetDiograph();
69
+ const diographObject = (_a = (await this.getDiograph())) !== null && _a !== void 0 ? _a : defaultDiograph_json_1.default;
70
+ this.diograph.addDiograph(diographObject);
71
+ this.focusDiory({ id: '/' });
72
+ return this.diograph;
54
73
  };
55
74
  this.getDiograph = async (connections) => {
56
75
  console.info('getDiograph', connections);
76
+ let diographObject;
57
77
  await Promise.all(this.getDiographClients(connections).map(async (connectionClient) => {
58
- const diographObject = await connectionClient.getDiograph();
59
- this.diograph.addDiograph(diographObject);
60
- console.info(this.diograph.toObject());
78
+ try {
79
+ diographObject = await connectionClient.getDiograph();
80
+ console.info(diographObject);
81
+ }
82
+ catch (error) {
83
+ console.error(error);
84
+ }
61
85
  return;
62
86
  }));
63
- return this.diograph;
87
+ return diographObject;
64
88
  };
65
89
  this.saveDiograph = async (connections) => {
66
90
  console.info('saveDiograph', connections);
91
+ const diographObject = this.diograph.toObject();
67
92
  await Promise.all(this.getDiographClients(connections).map(async (connectionClient) => {
68
- await connectionClient.saveDiograph(this.diograph.toObject());
69
- console.info(this.diograph.toObject());
93
+ await connectionClient.saveDiograph(diographObject);
94
+ console.info(diographObject);
70
95
  return;
71
96
  }));
72
- return this.diograph;
97
+ return diographObject;
73
98
  };
74
99
  this.generateDiograph = async (connections) => {
75
100
  console.info('generateDiograph', connections);
package/dist/types.d.ts CHANGED
@@ -48,12 +48,13 @@ export interface IDioryClient {
48
48
  room?: IRoom;
49
49
  diograph: IDiograph;
50
50
  diory?: IDiory;
51
- initialise: (connections: IConnectionObject[]) => Promise<IDioryClient>;
52
- enterRoom: (roomObject: IRoomObject) => Promise<IRoom>;
51
+ selectRoom: (roomObject: IRoomObject) => IRoom;
52
+ getDiosphere: () => Promise<IDiosphereObject | undefined>;
53
+ saveDiosphere: () => Promise<IDiosphereObject>;
54
+ initialiseDiosphere: (connections: IConnectionObject[]) => Promise<IDiosphere>;
53
55
  focusDiory: (dioryObject: IDioryObject) => IDiory;
54
- getDiosphere: () => Promise<IDiosphere>;
55
- saveDiosphere: () => Promise<IDiosphere>;
56
- getDiograph: () => Promise<IDiograph>;
57
- saveDiograph: () => Promise<IDiograph>;
56
+ getDiograph: () => Promise<IDiographObject | undefined>;
57
+ saveDiograph: () => Promise<IDiographObject>;
58
+ initialiseDiograph: (roomObject: IRoomObject) => Promise<IDiograph>;
58
59
  generateDiograph: () => Promise<IDiograph>;
59
60
  }
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "@diory/client-js",
3
- "version": "0.2.0-rc11",
3
+ "version": "0.2.0-rc13",
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-rc15",
9
+ "@diograph/diograph": "0.3.0-rc16",
10
10
  "@diograph/folder-generator": "^0.3.0-rc3",
11
- "@diory/diosphere-js": "^0.2.6-rc3",
11
+ "@diory/diosphere-js": "0.2.6-rc4",
12
12
  "path-browserify": "^1.0.1",
13
13
  "uuid": "8.3.2"
14
14
  },
@@ -0,0 +1,23 @@
1
+ {
2
+ "/": {
3
+ "id": "welcome-root-diory"
4
+ },
5
+ "welcome-root-diory": {
6
+ "id": "welcome-root-diory",
7
+ "image": "",
8
+ "links": [
9
+ {
10
+ "id": "welcome-diory"
11
+ }
12
+ ],
13
+ "modified": "2020-01-03T14:03:04.751Z"
14
+ },
15
+ "welcome-diory": {
16
+ "id": "welcome-diory",
17
+ "image": "",
18
+ "modified": "2020-01-03T14:03:04.751Z",
19
+ "text": "Welcome to Diory",
20
+ "latitude": 60.01366036242365,
21
+ "longitude": 20.007133483886722
22
+ }
23
+ }
@@ -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,9 +1,19 @@
1
- import { Diosphere, IConnectionObject, IDiosphere, IRoom, IRoomObject } from '@diory/diosphere-js'
2
- import { Diograph, IDiograph, IDiory, IDioryObject } from '@diograph/diograph'
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'
6
13
 
14
+ import defaultDiosphere from './defaultDiosphere.json'
15
+ import defaultDiograph from './defaultDiograph.json'
16
+
7
17
  class DioryClient implements IDioryClient {
8
18
  dataClients: IDataClient[] = []
9
19
  connections: IConnectionObject[] = []
@@ -22,98 +32,116 @@ class DioryClient implements IDioryClient {
22
32
  this.diograph.saveDiograph = this.saveDiograph
23
33
  }
24
34
 
25
- initialise = async (connections: IConnectionObject[]): Promise<IDioryClient> => {
26
- console.info('initialise', connections)
27
-
28
- this.connections = connections
29
- this.diosphere.resetRooms()
30
-
31
- return this
32
- }
33
-
34
- enterRoom = async (roomObject: IRoomObject): Promise<IRoom> => {
35
- console.info('enterRoom', roomObject)
36
-
37
- this.room = this.diosphere.getRoom(roomObject)
38
- this.diograph.resetDiograph()
39
- await this.getDiograph()
40
- this.focusDiory({ id: '/' })
41
- console.info(this.room)
42
-
43
- return this.room
44
- }
45
-
46
- focusDiory = (dioryObject: IDioryObject): IDiory => {
47
- return (this.diory = this.diograph.getDiory(dioryObject))
35
+ selectRoom = (roomObject: IRoomObject): IRoom => {
36
+ return (this.room = this.diosphere.getRoom(roomObject))
48
37
  }
49
38
 
50
39
  getDiosphereClients = (connections?: IConnectionObject[]) => {
51
40
  return getConnectionClients(this.dataClients, connections ?? this.connections)
52
41
  }
53
42
 
54
- getDiographClients = (connections?: IConnectionObject[]) => {
55
- return getConnectionClients(this.dataClients, connections ?? this.room?.connections)
43
+ initialiseDiosphere = async (connections: IConnectionObject[]): Promise<IDiosphere> => {
44
+ console.info('initialiseDiosphere', connections)
45
+ this.connections = connections
46
+
47
+ this.diosphere.resetRooms()
48
+ const diosphereObject = (await this.getDiosphere()) ?? defaultDiosphere
49
+ this.diosphere.addDiosphere(diosphereObject)
50
+
51
+ this.selectRoom({ id: '/' })
52
+
53
+ return this.diosphere
56
54
  }
57
55
 
58
- getDiosphere = async (connections?: IConnectionObject[]): Promise<IDiosphere> => {
56
+ getDiosphere = async (
57
+ connections?: IConnectionObject[],
58
+ ): Promise<IDiosphereObject | undefined> => {
59
59
  console.info('getDiosphere', connections)
60
+
61
+ let diosphereObject
60
62
  await Promise.all(
61
63
  this.getDiosphereClients(connections).map(async (connectionClient) => {
62
- const diosphereObject = await connectionClient.getDiosphere()
63
- this.diosphere.addDiosphere(diosphereObject)
64
- console.info(this.diosphere.toObject())
65
-
64
+ try {
65
+ diosphereObject = await connectionClient.getDiosphere()
66
+ console.info(this.diosphere.toObject())
67
+ } catch (error) {
68
+ console.error(error)
69
+ }
66
70
  return
67
71
  }),
68
72
  )
69
73
 
70
- return this.diosphere
74
+ return diosphereObject
71
75
  }
72
76
 
73
- saveDiosphere = async (connections?: IConnectionObject[]): Promise<IDiosphere> => {
77
+ saveDiosphere = async (connections?: IConnectionObject[]): Promise<IDiosphereObject> => {
74
78
  console.info('saveDiosphere', connections)
75
79
 
80
+ const diosphereObject = this.diosphere.toObject()
76
81
  await Promise.all(
77
82
  this.getDiosphereClients(connections).map(async (connectionClient) => {
78
- await connectionClient.saveDiosphere(this.diosphere.toObject())
79
- console.info(this.diosphere.toObject())
80
-
83
+ await connectionClient.saveDiosphere(diosphereObject)
84
+ console.info(diosphereObject)
81
85
  return
82
86
  }),
83
87
  )
84
88
 
85
- return this.diosphere
89
+ return diosphereObject
86
90
  }
87
91
 
88
- getDiograph = async (connections?: IConnectionObject[]): Promise<IDiograph> => {
92
+ getDiographClients = (connections?: IConnectionObject[]) => {
93
+ return getConnectionClients(this.dataClients, connections ?? this.room?.connections)
94
+ }
95
+
96
+ focusDiory = (dioryObject: IDioryObject): IDiory => {
97
+ return (this.diory = this.diograph.getDiory(dioryObject))
98
+ }
99
+
100
+ initialiseDiograph = async (roomObject: IRoomObject): Promise<IDiograph> => {
101
+ console.info('initialiseDiograph', roomObject)
102
+ this.selectRoom(roomObject)
103
+
104
+ this.diograph.resetDiograph()
105
+ const diographObject = (await this.getDiograph()) ?? defaultDiograph
106
+ this.diograph.addDiograph(diographObject)
107
+
108
+ this.focusDiory({ id: '/' })
109
+
110
+ return this.diograph
111
+ }
112
+
113
+ getDiograph = async (connections?: IConnectionObject[]): Promise<IDiographObject | undefined> => {
89
114
  console.info('getDiograph', connections)
90
115
 
116
+ let diographObject
91
117
  await Promise.all(
92
118
  this.getDiographClients(connections).map(async (connectionClient) => {
93
- const diographObject = await connectionClient.getDiograph()
94
- this.diograph.addDiograph(diographObject)
95
- console.info(this.diograph.toObject())
96
-
119
+ try {
120
+ diographObject = await connectionClient.getDiograph()
121
+ console.info(diographObject)
122
+ } catch (error) {
123
+ console.error(error)
124
+ }
97
125
  return
98
126
  }),
99
127
  )
100
128
 
101
- return this.diograph
129
+ return diographObject
102
130
  }
103
131
 
104
- saveDiograph = async (connections?: IConnectionObject[]): Promise<IDiograph> => {
132
+ saveDiograph = async (connections?: IConnectionObject[]): Promise<IDiographObject> => {
105
133
  console.info('saveDiograph', connections)
106
134
 
135
+ const diographObject = this.diograph.toObject()
107
136
  await Promise.all(
108
137
  this.getDiographClients(connections).map(async (connectionClient) => {
109
- await connectionClient.saveDiograph(this.diograph.toObject())
110
- console.info(this.diograph.toObject())
111
-
138
+ await connectionClient.saveDiograph(diographObject)
139
+ console.info(diographObject)
112
140
  return
113
141
  }),
114
142
  )
115
143
 
116
- return this.diograph
144
+ return diographObject
117
145
  }
118
146
 
119
147
  generateDiograph = async (connections?: IConnectionObject[]): Promise<IDiograph> => {
package/src/types.ts CHANGED
@@ -58,12 +58,13 @@ export interface IDioryClient {
58
58
  room?: IRoom
59
59
  diograph: IDiograph
60
60
  diory?: IDiory
61
- initialise: (connections: IConnectionObject[]) => Promise<IDioryClient>
62
- enterRoom: (roomObject: IRoomObject) => Promise<IRoom>
61
+ selectRoom: (roomObject: IRoomObject) => IRoom
62
+ getDiosphere: () => Promise<IDiosphereObject | undefined>
63
+ saveDiosphere: () => Promise<IDiosphereObject>
64
+ initialiseDiosphere: (connections: IConnectionObject[]) => Promise<IDiosphere>
63
65
  focusDiory: (dioryObject: IDioryObject) => IDiory
64
- getDiosphere: () => Promise<IDiosphere>
65
- saveDiosphere: () => Promise<IDiosphere>
66
- getDiograph: () => Promise<IDiograph>
67
- saveDiograph: () => Promise<IDiograph>
66
+ getDiograph: () => Promise<IDiographObject | undefined>
67
+ saveDiograph: () => Promise<IDiographObject>
68
+ initialiseDiograph: (roomObject: IRoomObject) => Promise<IDiograph>
68
69
  generateDiograph: () => Promise<IDiograph>
69
70
  }
package/tsconfig.json CHANGED
@@ -5,7 +5,9 @@
5
5
  "target": "es2017",
6
6
  "module": "commonjs",
7
7
  "strict": true,
8
- "forceConsistentCasingInFileNames": true
8
+ "forceConsistentCasingInFileNames": true,
9
+ "resolveJsonModule": true,
10
+ "esModuleInterop": true
9
11
  },
10
12
  "exclude": ["node_modules", "dist"]
11
13
  }