@diory/client-js 0.2.0-rc19 → 0.2.0-rc20

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.
@@ -19,6 +19,7 @@ declare class DioryClient implements IDioryClient {
19
19
  initialiseDiograph: (roomObject: IRoomObject) => Promise<IDiograph>;
20
20
  getDiograph: (connections?: IConnectionObject[]) => Promise<IDiographObject | undefined>;
21
21
  saveDiograph: (connections?: IConnectionObject[]) => Promise<IDiographObject>;
22
- generateDiograph: (connections?: IConnectionObject[]) => Promise<IDiograph>;
22
+ mergeDiograph: (diographObject: IDiographObject) => Promise<void>;
23
+ generateDiograph: (connections?: IConnectionObject[]) => Promise<IDiographObject | undefined>;
23
24
  }
24
25
  export { DioryClient };
@@ -4,9 +4,9 @@ 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 debounce_1 = require("../connectionClient/utils/debounce");
7
8
  const getDefaultDiosphere_1 = require("./getDefaultDiosphere");
8
9
  const getDefaultDiograph_1 = require("./getDefaultDiograph");
9
- const debounce_1 = require("../connectionClient/utils/debounce");
10
10
  class DioryClient {
11
11
  constructor(dataClients) {
12
12
  this.dataClients = [];
@@ -24,7 +24,6 @@ class DioryClient {
24
24
  this.diosphere.resetRooms();
25
25
  const diosphereObject = (_a = (await this.getDiosphere())) !== null && _a !== void 0 ? _a : (0, getDefaultDiosphere_1.getDefaultDiosphere)(connections);
26
26
  this.diosphere.addDiosphere(diosphereObject);
27
- await this.saveDiosphere();
28
27
  this.selectRoom({ id: '/' });
29
28
  console.info(this.diosphere.toObject());
30
29
  return this.diosphere;
@@ -68,7 +67,6 @@ class DioryClient {
68
67
  this.diograph.resetDiograph();
69
68
  const diographObject = (_a = (await this.getDiograph())) !== null && _a !== void 0 ? _a : (0, getDefaultDiograph_1.getDefaultDiograph)();
70
69
  this.diograph.addDiograph(diographObject);
71
- await this.saveDiograph();
72
70
  this.focusDiory({ id: '/' });
73
71
  console.info(this.diograph.toObject());
74
72
  return this.diograph;
@@ -98,26 +96,29 @@ class DioryClient {
98
96
  }));
99
97
  return diographObject;
100
98
  };
99
+ this.mergeDiograph = async (diographObject) => {
100
+ Object.entries(diographObject).forEach(([key, dioryObject]) => {
101
+ try {
102
+ key === '/'
103
+ ? this.diograph.addDioryLink({ id: '/' }, diographObject['/'])
104
+ : this.diograph.addDiory(dioryObject);
105
+ }
106
+ catch (error) {
107
+ console.error(error);
108
+ }
109
+ });
110
+ await this.saveDiograph();
111
+ console.info(this.diograph.toObject());
112
+ };
101
113
  this.generateDiograph = async (connections) => {
102
114
  console.info('generateDiograph', connections);
115
+ let diographObject;
103
116
  await Promise.all(this.getDiographClients(connections).map(async (connectionClient) => {
104
- const diographObject = await connectionClient.generateDiograph();
117
+ diographObject = await connectionClient.generateDiograph();
105
118
  console.info(diographObject);
106
- Object.entries(diographObject).forEach(([key, dioryObject]) => {
107
- try {
108
- key === '/'
109
- ? this.diograph.addDioryLink({ id: '/' }, diographObject['/'])
110
- : this.diograph.addDiory(dioryObject);
111
- }
112
- catch (error) {
113
- console.error(error);
114
- }
115
- });
116
- await connectionClient.saveDiograph(this.diograph.toObject());
117
- console.info(this.diograph.toObject());
118
119
  return;
119
120
  }));
120
- return this.diograph;
121
+ return diographObject;
121
122
  };
122
123
  this.dataClients = dataClients;
123
124
  this.diosphere = new diosphere_js_1.Diosphere();
package/dist/types.d.ts CHANGED
@@ -56,5 +56,5 @@ export interface IDioryClient {
56
56
  getDiograph: () => Promise<IDiographObject | undefined>;
57
57
  saveDiograph: () => Promise<IDiographObject>;
58
58
  initialiseDiograph: (roomObject: IRoomObject) => Promise<IDiograph>;
59
- generateDiograph: () => Promise<IDiograph>;
59
+ generateDiograph: () => Promise<IDiographObject | undefined>;
60
60
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@diory/client-js",
3
- "version": "0.2.0-rc19",
3
+ "version": "0.2.0-rc20",
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>",
@@ -10,10 +10,10 @@ import { Diograph, IDiograph, IDiographObject, IDiory, IDioryObject } from '@dio
10
10
 
11
11
  import { IDioryClient, IDataClient } from '../types'
12
12
  import { getConnectionClients } from '../utils/getConnectionClients'
13
+ import { debounce } from '../connectionClient/utils/debounce'
13
14
 
14
15
  import { getDefaultDiosphere } from './getDefaultDiosphere'
15
16
  import { getDefaultDiograph } from './getDefaultDiograph'
16
- import { debounce } from '../connectionClient/utils/debounce'
17
17
 
18
18
  class DioryClient implements IDioryClient {
19
19
  dataClients: IDataClient[] = []
@@ -48,7 +48,6 @@ class DioryClient implements IDioryClient {
48
48
  this.diosphere.resetRooms()
49
49
  const diosphereObject = (await this.getDiosphere()) ?? getDefaultDiosphere(connections)
50
50
  this.diosphere.addDiosphere(diosphereObject)
51
- await this.saveDiosphere()
52
51
 
53
52
  this.selectRoom({ id: '/' })
54
53
 
@@ -107,7 +106,6 @@ class DioryClient implements IDioryClient {
107
106
  this.diograph.resetDiograph()
108
107
  const diographObject = (await this.getDiograph()) ?? getDefaultDiograph()
109
108
  this.diograph.addDiograph(diographObject)
110
- await this.saveDiograph()
111
109
 
112
110
  this.focusDiory({ id: '/' })
113
111
 
@@ -149,32 +147,36 @@ class DioryClient implements IDioryClient {
149
147
  return diographObject
150
148
  }
151
149
 
152
- generateDiograph = async (connections?: IConnectionObject[]): Promise<IDiograph> => {
150
+ mergeDiograph = async (diographObject: IDiographObject) => {
151
+ Object.entries(diographObject).forEach(([key, dioryObject]) => {
152
+ try {
153
+ key === '/'
154
+ ? this.diograph.addDioryLink({ id: '/' }, diographObject['/'])
155
+ : this.diograph.addDiory(dioryObject)
156
+ } catch (error) {
157
+ console.error(error)
158
+ }
159
+ })
160
+
161
+ await this.saveDiograph()
162
+ console.info(this.diograph.toObject())
163
+ }
164
+
165
+ generateDiograph = async (
166
+ connections?: IConnectionObject[],
167
+ ): Promise<IDiographObject | undefined> => {
153
168
  console.info('generateDiograph', connections)
154
169
 
170
+ let diographObject
155
171
  await Promise.all(
156
172
  this.getDiographClients(connections).map(async (connectionClient) => {
157
- const diographObject = await connectionClient.generateDiograph()
173
+ diographObject = await connectionClient.generateDiograph()
158
174
  console.info(diographObject)
159
-
160
- Object.entries(diographObject).forEach(([key, dioryObject]) => {
161
- try {
162
- key === '/'
163
- ? this.diograph.addDioryLink({ id: '/' }, diographObject['/'])
164
- : this.diograph.addDiory(dioryObject)
165
- } catch (error) {
166
- console.error(error)
167
- }
168
- })
169
-
170
- await connectionClient.saveDiograph(this.diograph.toObject())
171
- console.info(this.diograph.toObject())
172
-
173
175
  return
174
176
  }),
175
177
  )
176
178
 
177
- return this.diograph
179
+ return diographObject
178
180
  }
179
181
  }
180
182
 
package/src/types.ts CHANGED
@@ -66,5 +66,5 @@ export interface IDioryClient {
66
66
  getDiograph: () => Promise<IDiographObject | undefined>
67
67
  saveDiograph: () => Promise<IDiographObject>
68
68
  initialiseDiograph: (roomObject: IRoomObject) => Promise<IDiograph>
69
- generateDiograph: () => Promise<IDiograph>
69
+ generateDiograph: () => Promise<IDiographObject | undefined>
70
70
  }