@diory/client-js 0.1.3 → 0.1.5-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.
@@ -10,5 +10,6 @@ declare class ConnectionClient implements IConnectionClient {
10
10
  saveDiosphere: (diosphereObject: IDiosphereObject) => Promise<boolean>;
11
11
  getDiograph: () => Promise<any>;
12
12
  saveDiograph: (diographObject: IDiographObject) => Promise<boolean>;
13
+ generateDiograph: () => Promise<IDiographObject>;
13
14
  }
14
15
  export { ConnectionClient };
@@ -1,23 +1,35 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ConnectionClient = void 0;
4
+ const path_browserify_1 = require("path-browserify");
5
+ const folder_generator_1 = require("@diograph/folder-generator");
6
+ const DIOSPHERE_JSON = 'diosphere.json';
7
+ const DIOGRAPH_JSON = 'diograph.json';
4
8
  class ConnectionClient {
5
9
  constructor(dataClient, connection) {
6
10
  this.getDiosphere = async () => {
7
- const diosphereString = await this.client.readTextItem(this.connection.address);
11
+ const path = (0, path_browserify_1.join)(this.connection.address, DIOSPHERE_JSON);
12
+ const diosphereString = await this.client.readTextItem(path);
8
13
  return JSON.parse(diosphereString);
9
14
  };
10
15
  this.saveDiosphere = async (diosphereObject) => {
16
+ const path = (0, path_browserify_1.join)(this.connection.address, DIOSPHERE_JSON);
11
17
  const diosphereString = JSON.stringify(diosphereObject, null, 2);
12
- return this.client.writeItem(this.connection.address, diosphereString);
18
+ return this.client.writeItem(path, diosphereString);
13
19
  };
14
20
  this.getDiograph = async () => {
15
- const diographString = await this.client.readTextItem(this.connection.address);
21
+ const path = (0, path_browserify_1.join)(this.connection.address, DIOGRAPH_JSON);
22
+ const diographString = await this.client.readTextItem(path);
16
23
  return JSON.parse(diographString);
17
24
  };
18
25
  this.saveDiograph = async (diographObject) => {
26
+ const path = (0, path_browserify_1.join)(this.connection.address, DIOGRAPH_JSON);
19
27
  const diographString = JSON.stringify(diographObject, null, 2);
20
- return this.client.writeItem(this.connection.address, diographString);
28
+ return this.client.writeItem(path, diographString);
29
+ };
30
+ this.generateDiograph = async () => {
31
+ const { diograph } = await (0, folder_generator_1.generateDiograph)(this.connection.address); // TODO: Client
32
+ return diograph.toObject();
21
33
  };
22
34
  this.type = dataClient.type;
23
35
  this.client = dataClient;
@@ -12,9 +12,10 @@ declare class DioryClient implements IDioryClient {
12
12
  initialise: (connections: IConnectionObject[]) => Promise<IDioryClient>;
13
13
  enterRoom: (roomObject: IRoomObject) => Promise<IRoom>;
14
14
  focusDiory: (dioryObject: IDioryObject) => IDiory;
15
- getDiosphere: () => Promise<void>;
16
- saveDiosphere: () => Promise<void>;
17
- getDiograph: () => Promise<void>;
18
- saveDiograph: () => Promise<void>;
15
+ getDiosphere: () => Promise<IDiosphere>;
16
+ saveDiosphere: () => Promise<IDiosphere>;
17
+ getDiograph: () => Promise<IDiograph>;
18
+ saveDiograph: () => Promise<IDiograph>;
19
+ generateDiograph: () => Promise<IDiograph>;
19
20
  }
20
21
  export { DioryClient };
@@ -20,6 +20,7 @@ class DioryClient {
20
20
  this.diograph.resetDiograph();
21
21
  await this.getDiograph();
22
22
  this.focusDiory({ id: '/' });
23
+ await this.generateDiograph();
23
24
  return this.room;
24
25
  };
25
26
  this.focusDiory = (dioryObject) => {
@@ -32,21 +33,22 @@ class DioryClient {
32
33
  await Promise.all(connectionClients.map(async (connectionClient) => {
33
34
  const diosphereObject = await connectionClient.getDiosphere();
34
35
  console.info(diosphereObject);
35
- return this.diosphere.initialise(diosphereObject);
36
+ return this.diosphere.addDiosphere(diosphereObject);
36
37
  }));
37
38
  }
38
- return;
39
+ return this.diosphere;
39
40
  };
40
41
  this.saveDiosphere = async () => {
41
42
  console.info('saveDiosphere', this.connections);
42
43
  if (this.connections) {
43
44
  const connectionClients = (0, getConnectionClients_1.getConnectionClients)(this.dataClients, this.connections);
44
- await Promise.all(connectionClients.map((connectionClient) => {
45
+ await Promise.all(connectionClients.map(async (connectionClient) => {
45
46
  console.info(this.diosphere.toObject());
46
- return connectionClient.saveDiosphere(this.diosphere.toObject());
47
+ await connectionClient.saveDiosphere(this.diosphere.toObject());
48
+ return;
47
49
  }));
48
50
  }
49
- return;
51
+ return this.diosphere;
50
52
  };
51
53
  this.getDiograph = async () => {
52
54
  var _a, _b;
@@ -56,22 +58,39 @@ class DioryClient {
56
58
  await Promise.all(connectionClients.map(async (connectionClient) => {
57
59
  const diographObject = await connectionClient.getDiograph();
58
60
  console.info(diographObject);
59
- return this.diograph.initialise(diographObject);
61
+ this.diograph.addDiograph(diographObject);
62
+ return;
60
63
  }));
61
64
  }
62
- return;
65
+ return this.diograph;
63
66
  };
64
67
  this.saveDiograph = async () => {
65
68
  var _a, _b;
66
69
  console.info('saveDiograph', (_a = this.room) === null || _a === void 0 ? void 0 : _a.connections);
67
70
  if ((_b = this.room) === null || _b === void 0 ? void 0 : _b.connections) {
68
71
  const connectionClients = (0, getConnectionClients_1.getConnectionClients)(this.dataClients, this.room.connections);
69
- await Promise.all(connectionClients.map((connectionClient) => {
72
+ await Promise.all(connectionClients.map(async (connectionClient) => {
70
73
  console.info(this.diograph.toObject());
71
- return connectionClient.saveDiograph(this.diograph.toObject());
74
+ await connectionClient.saveDiograph(this.diograph.toObject());
75
+ return;
76
+ }));
77
+ }
78
+ return this.diograph;
79
+ };
80
+ this.generateDiograph = async () => {
81
+ var _a, _b, _c;
82
+ console.info('generateDiograph', (_a = this.room) === null || _a === void 0 ? void 0 : _a.connections);
83
+ if ((_b = this.room) === null || _b === void 0 ? void 0 : _b.connections) {
84
+ const connectionClients = (0, getConnectionClients_1.getConnectionClients)(this.dataClients, (_c = this.room) === null || _c === void 0 ? void 0 : _c.connections);
85
+ await Promise.all(connectionClients.map(async (connectionClient) => {
86
+ const diographObject = await connectionClient.generateDiograph();
87
+ console.info(diographObject);
88
+ this.diograph.addDiograph(diographObject);
89
+ await connectionClient.saveDiograph(this.diograph.toObject());
90
+ return;
72
91
  }));
73
92
  }
74
- return;
93
+ return this.diograph;
75
94
  };
76
95
  this.dataClients = dataClients;
77
96
  this.diosphere = new diosphere_js_1.Diosphere();
@@ -10,4 +10,9 @@ describe('dioryClient', () => {
10
10
  expect(true).toEqual(true);
11
11
  });
12
12
  });
13
+ describe('enterRoom()', () => {
14
+ it('should initialise with connections', () => {
15
+ expect(true).toEqual(true);
16
+ });
17
+ });
13
18
  });
package/dist/types.d.ts CHANGED
@@ -21,6 +21,7 @@ export interface IConnectionClient {
21
21
  saveDiosphere: (diosphereObject: IDiosphereObject) => void;
22
22
  getDiograph: () => Promise<IDiographObject>;
23
23
  saveDiograph: (diographObject: IDiographObject) => void;
24
+ generateDiograph: () => Promise<IDiographObject>;
24
25
  }
25
26
  export interface IDioryClient {
26
27
  dataClients: IDataClient[];
@@ -32,8 +33,9 @@ export interface IDioryClient {
32
33
  initialise: (connections: IConnectionObject[]) => Promise<IDioryClient>;
33
34
  enterRoom: (roomObject: IRoomObject) => Promise<IRoom>;
34
35
  focusDiory: (dioryObject: IDioryObject) => IDiory;
35
- getDiosphere: () => void;
36
- saveDiosphere: () => void;
37
- getDiograph: () => void;
38
- saveDiograph: () => void;
36
+ getDiosphere: () => Promise<IDiosphere>;
37
+ saveDiosphere: () => Promise<IDiosphere>;
38
+ getDiograph: () => Promise<IDiograph>;
39
+ saveDiograph: () => Promise<IDiograph>;
40
+ generateDiograph: () => Promise<IDiograph>;
39
41
  }
package/package.json CHANGED
@@ -1,16 +1,21 @@
1
1
  {
2
2
  "name": "@diory/client-js",
3
- "version": "0.1.3",
3
+ "version": "0.1.5-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-rc12",
10
- "@diory/diosphere-js": "0.2.6-rc1"
9
+ "@diograph/diograph": "0.3.0-rc14",
10
+ "@diograph/folder-generator": "^0.2.0-rc1",
11
+ "@diory/diosphere-js": "0.2.6-rc2",
12
+ "path-browserify": "^1.0.1",
13
+ "uuid": "8.3.2"
11
14
  },
12
15
  "devDependencies": {
13
16
  "@types/jest": "^27.4.0",
17
+ "@types/path-browserify": "^1.0.2",
18
+ "@types/uuid": "8.3.2",
14
19
  "jest": "^27.5.0",
15
20
  "prettier": "^2.5.1",
16
21
  "ts-jest": "^27.1.3",
@@ -1,7 +1,13 @@
1
+ import { join } from 'path-browserify'
2
+ import { generateDiograph } from '@diograph/folder-generator'
3
+
1
4
  import { IDiographObject } from '@diograph/diograph'
2
5
  import { IConnectionObject, IDiosphereObject } from '@diory/diosphere-js'
3
6
  import { IConnectionClient, IDataClient } from './types'
4
7
 
8
+ const DIOSPHERE_JSON = 'diosphere.json'
9
+ const DIOGRAPH_JSON = 'diograph.json'
10
+
5
11
  class ConnectionClient implements IConnectionClient {
6
12
  type: string
7
13
  client: IDataClient
@@ -14,23 +20,32 @@ class ConnectionClient implements IConnectionClient {
14
20
  }
15
21
 
16
22
  getDiosphere = async () => {
17
- const diosphereString = await this.client.readTextItem(this.connection.address)
23
+ const path = join(this.connection.address, DIOSPHERE_JSON)
24
+ const diosphereString = await this.client.readTextItem(path)
18
25
  return JSON.parse(diosphereString)
19
26
  }
20
27
 
21
28
  saveDiosphere = async (diosphereObject: IDiosphereObject) => {
29
+ const path = join(this.connection.address, DIOSPHERE_JSON)
22
30
  const diosphereString = JSON.stringify(diosphereObject, null, 2)
23
- return this.client.writeItem(this.connection.address, diosphereString)
31
+ return this.client.writeItem(path, diosphereString)
24
32
  }
25
33
 
26
34
  getDiograph = async () => {
27
- const diographString = await this.client.readTextItem(this.connection.address)
35
+ const path = join(this.connection.address, DIOGRAPH_JSON)
36
+ const diographString = await this.client.readTextItem(path)
28
37
  return JSON.parse(diographString)
29
38
  }
30
39
 
31
40
  saveDiograph = async (diographObject: IDiographObject) => {
41
+ const path = join(this.connection.address, DIOGRAPH_JSON)
32
42
  const diographString = JSON.stringify(diographObject, null, 2)
33
- return this.client.writeItem(this.connection.address, diographString)
43
+ return this.client.writeItem(path, diographString)
44
+ }
45
+
46
+ generateDiograph = async (): Promise<IDiographObject> => {
47
+ const { diograph } = await generateDiograph(this.connection.address) // TODO: Client
48
+ return diograph.toObject()
34
49
  }
35
50
  }
36
51
 
@@ -10,4 +10,10 @@ describe('dioryClient', () => {
10
10
  expect(true).toEqual(true)
11
11
  })
12
12
  })
13
+
14
+ describe('enterRoom()', () => {
15
+ it('should initialise with connections', () => {
16
+ expect(true).toEqual(true)
17
+ })
18
+ })
13
19
  })
@@ -39,6 +39,8 @@ class DioryClient implements IDioryClient {
39
39
  await this.getDiograph()
40
40
  this.focusDiory({ id: '/' })
41
41
 
42
+ await this.generateDiograph()
43
+
42
44
  return this.room
43
45
  }
44
46
 
@@ -46,7 +48,7 @@ class DioryClient implements IDioryClient {
46
48
  return (this.diory = this.diograph.getDiory(dioryObject))
47
49
  }
48
50
 
49
- getDiosphere = async (): Promise<void> => {
51
+ getDiosphere = async (): Promise<IDiosphere> => {
50
52
  console.info('getDiosphere', this.connections)
51
53
  if (this.connections) {
52
54
  const connectionClients = getConnectionClients(this.dataClients, this.connections)
@@ -55,31 +57,32 @@ class DioryClient implements IDioryClient {
55
57
  connectionClients.map(async (connectionClient) => {
56
58
  const diosphereObject = await connectionClient.getDiosphere()
57
59
  console.info(diosphereObject)
58
- return this.diosphere.initialise(diosphereObject)
60
+ return this.diosphere.addDiosphere(diosphereObject)
59
61
  }),
60
62
  )
61
63
  }
62
64
 
63
- return
65
+ return this.diosphere
64
66
  }
65
67
 
66
- saveDiosphere = async (): Promise<void> => {
68
+ saveDiosphere = async (): Promise<IDiosphere> => {
67
69
  console.info('saveDiosphere', this.connections)
68
70
  if (this.connections) {
69
71
  const connectionClients = getConnectionClients(this.dataClients, this.connections)
70
72
 
71
73
  await Promise.all(
72
- connectionClients.map((connectionClient) => {
74
+ connectionClients.map(async (connectionClient) => {
73
75
  console.info(this.diosphere.toObject())
74
- return connectionClient.saveDiosphere(this.diosphere.toObject())
76
+ await connectionClient.saveDiosphere(this.diosphere.toObject())
77
+ return
75
78
  }),
76
79
  )
77
80
  }
78
81
 
79
- return
82
+ return this.diosphere
80
83
  }
81
84
 
82
- getDiograph = async (): Promise<void> => {
85
+ getDiograph = async (): Promise<IDiograph> => {
83
86
  console.info('getDiograph', this.room?.connections)
84
87
  if (this.room?.connections) {
85
88
  const connectionClients = getConnectionClients(this.dataClients, this.room.connections)
@@ -88,28 +91,50 @@ class DioryClient implements IDioryClient {
88
91
  connectionClients.map(async (connectionClient) => {
89
92
  const diographObject = await connectionClient.getDiograph()
90
93
  console.info(diographObject)
91
- return this.diograph.initialise(diographObject)
94
+ this.diograph.addDiograph(diographObject)
95
+ return
92
96
  }),
93
97
  )
94
98
  }
95
99
 
96
- return
100
+ return this.diograph
97
101
  }
98
102
 
99
- saveDiograph = async (): Promise<void> => {
103
+ saveDiograph = async (): Promise<IDiograph> => {
100
104
  console.info('saveDiograph', this.room?.connections)
101
105
  if (this.room?.connections) {
102
106
  const connectionClients = getConnectionClients(this.dataClients, this.room.connections)
103
107
 
104
108
  await Promise.all(
105
- connectionClients.map((connectionClient) => {
109
+ connectionClients.map(async (connectionClient) => {
106
110
  console.info(this.diograph.toObject())
107
- return connectionClient.saveDiograph(this.diograph.toObject())
111
+ await connectionClient.saveDiograph(this.diograph.toObject())
112
+ return
113
+ }),
114
+ )
115
+ }
116
+
117
+ return this.diograph
118
+ }
119
+
120
+ generateDiograph = async (): Promise<IDiograph> => {
121
+ console.info('generateDiograph', this.room?.connections)
122
+ if (this.room?.connections) {
123
+ const connectionClients = getConnectionClients(this.dataClients, this.room?.connections)
124
+
125
+ await Promise.all(
126
+ connectionClients.map(async (connectionClient) => {
127
+ const diographObject = await connectionClient.generateDiograph()
128
+ console.info(diographObject)
129
+ this.diograph.addDiograph(diographObject)
130
+
131
+ await connectionClient.saveDiograph(this.diograph.toObject())
132
+ return
108
133
  }),
109
134
  )
110
135
  }
111
136
 
112
- return
137
+ return this.diograph
113
138
  }
114
139
  }
115
140
 
package/src/types.ts CHANGED
@@ -28,6 +28,7 @@ export interface IConnectionClient {
28
28
  saveDiosphere: (diosphereObject: IDiosphereObject) => void
29
29
  getDiograph: () => Promise<IDiographObject>
30
30
  saveDiograph: (diographObject: IDiographObject) => void
31
+ generateDiograph: () => Promise<IDiographObject>
31
32
  }
32
33
 
33
34
  export interface IDioryClient {
@@ -40,8 +41,9 @@ export interface IDioryClient {
40
41
  initialise: (connections: IConnectionObject[]) => Promise<IDioryClient>
41
42
  enterRoom: (roomObject: IRoomObject) => Promise<IRoom>
42
43
  focusDiory: (dioryObject: IDioryObject) => IDiory
43
- getDiosphere: () => void
44
- saveDiosphere: () => void
45
- getDiograph: () => void
46
- saveDiograph: () => void
44
+ getDiosphere: () => Promise<IDiosphere>
45
+ saveDiosphere: () => Promise<IDiosphere>
46
+ getDiograph: () => Promise<IDiograph>
47
+ saveDiograph: () => Promise<IDiograph>
48
+ generateDiograph: () => Promise<IDiograph>
47
49
  }