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

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.
@@ -1,23 +1,24 @@
1
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
- }
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
+ }
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
+ }
@@ -1,23 +1,23 @@
1
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"
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"
21
17
  }
18
+ ],
19
+ "created": "2024-03-24T14:56:21.243Z",
20
+ "modified": "2024-03-24T14:56:21.243Z"
22
21
  }
22
+ }
23
23
  }
@@ -1,14 +1,11 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.DioryClient = void 0;
7
4
  const diosphere_js_1 = require("@diory/diosphere-js");
8
5
  const diograph_1 = require("@diograph/diograph");
9
6
  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
+ const getDefaultDiosphere_1 = require("./getDefaultDiosphere");
8
+ const getDefaultDiograph_1 = require("./getDefaultDiograph");
12
9
  class DioryClient {
13
10
  constructor(dataClients) {
14
11
  this.dataClients = [];
@@ -24,9 +21,11 @@ class DioryClient {
24
21
  console.info('initialiseDiosphere', connections);
25
22
  this.connections = connections;
26
23
  this.diosphere.resetRooms();
27
- const diosphereObject = (_a = (await this.getDiosphere())) !== null && _a !== void 0 ? _a : defaultDiosphere_json_1.default;
24
+ const diosphereObject = (_a = (await this.getDiosphere())) !== null && _a !== void 0 ? _a : (0, getDefaultDiosphere_1.getDefaultDiosphere)(connections);
28
25
  this.diosphere.addDiosphere(diosphereObject);
26
+ await this.saveDiosphere();
29
27
  this.selectRoom({ id: '/' });
28
+ console.info(this.diosphere.toObject());
30
29
  return this.diosphere;
31
30
  };
32
31
  this.getDiosphere = async (connections) => {
@@ -35,7 +34,7 @@ class DioryClient {
35
34
  await Promise.all(this.getDiosphereClients(connections).map(async (connectionClient) => {
36
35
  try {
37
36
  diosphereObject = await connectionClient.getDiosphere();
38
- console.info(this.diosphere.toObject());
37
+ console.info(diosphereObject);
39
38
  }
40
39
  catch (error) {
41
40
  console.error(error);
@@ -66,9 +65,11 @@ class DioryClient {
66
65
  console.info('initialiseDiograph', roomObject);
67
66
  this.selectRoom(roomObject);
68
67
  this.diograph.resetDiograph();
69
- const diographObject = (_a = (await this.getDiograph())) !== null && _a !== void 0 ? _a : defaultDiograph_json_1.default;
68
+ const diographObject = (_a = (await this.getDiograph())) !== null && _a !== void 0 ? _a : (0, getDefaultDiograph_1.getDefaultDiograph)();
70
69
  this.diograph.addDiograph(diographObject);
70
+ await this.saveDiograph();
71
71
  this.focusDiory({ id: '/' });
72
+ console.info(this.diograph.toObject());
72
73
  return this.diograph;
73
74
  };
74
75
  this.getDiograph = async (connections) => {
@@ -100,11 +101,17 @@ class DioryClient {
100
101
  console.info('generateDiograph', connections);
101
102
  await Promise.all(this.getDiographClients(connections).map(async (connectionClient) => {
102
103
  const diographObject = await connectionClient.generateDiograph();
103
- Object.entries(diographObject).forEach(([key, dioryObject]) => {
104
- key === '/'
105
- ? this.diograph.addDioryLink({ id: '/' }, diographObject['/'])
106
- : this.diograph.addDiory(dioryObject);
107
- });
104
+ console.info(diographObject);
105
+ try {
106
+ Object.entries(diographObject).forEach(([key, dioryObject]) => {
107
+ key === '/'
108
+ ? this.diograph.addDioryLink({ id: '/' }, diographObject['/'])
109
+ : this.diograph.addDiory(dioryObject);
110
+ });
111
+ }
112
+ catch (error) {
113
+ console.error(error);
114
+ }
108
115
  await connectionClient.saveDiograph(this.diograph.toObject());
109
116
  console.info(this.diograph.toObject());
110
117
  return;
@@ -0,0 +1,2 @@
1
+ import { IDiographObject } from '@diograph/diograph';
2
+ export declare const getDefaultDiograph: () => IDiographObject;
@@ -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: 'Room root',
13
+ links: [{ id: diory.id }],
14
+ }, '/');
15
+ return diograph.toObject();
16
+ };
17
+ exports.getDefaultDiograph = getDefaultDiograph;
@@ -0,0 +1,2 @@
1
+ import { IConnectionObject, IDiosphereObject } from '@diory/diosphere-js';
2
+ export declare const getDefaultDiosphere: (connections: IConnectionObject[]) => IDiosphereObject;
@@ -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: 'Welcome room',
9
+ connections,
10
+ }, '/');
11
+ return diosphere.toObject();
12
+ };
13
+ exports.getDefaultDiosphere = getDefaultDiosphere;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@diory/client-js",
3
- "version": "0.2.0-rc13",
3
+ "version": "0.2.0-rc16",
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>",
@@ -11,8 +11,8 @@ import { Diograph, IDiograph, IDiographObject, IDiory, IDioryObject } from '@dio
11
11
  import { IDioryClient, IDataClient } from '../types'
12
12
  import { getConnectionClients } from '../utils/getConnectionClients'
13
13
 
14
- import defaultDiosphere from './defaultDiosphere.json'
15
- import defaultDiograph from './defaultDiograph.json'
14
+ import { getDefaultDiosphere } from './getDefaultDiosphere'
15
+ import { getDefaultDiograph } from './getDefaultDiograph'
16
16
 
17
17
  class DioryClient implements IDioryClient {
18
18
  dataClients: IDataClient[] = []
@@ -45,11 +45,13 @@ class DioryClient implements IDioryClient {
45
45
  this.connections = connections
46
46
 
47
47
  this.diosphere.resetRooms()
48
- const diosphereObject = (await this.getDiosphere()) ?? defaultDiosphere
48
+ const diosphereObject = (await this.getDiosphere()) ?? getDefaultDiosphere(connections)
49
49
  this.diosphere.addDiosphere(diosphereObject)
50
+ await this.saveDiosphere()
50
51
 
51
52
  this.selectRoom({ id: '/' })
52
53
 
54
+ console.info(this.diosphere.toObject())
53
55
  return this.diosphere
54
56
  }
55
57
 
@@ -63,7 +65,7 @@ class DioryClient implements IDioryClient {
63
65
  this.getDiosphereClients(connections).map(async (connectionClient) => {
64
66
  try {
65
67
  diosphereObject = await connectionClient.getDiosphere()
66
- console.info(this.diosphere.toObject())
68
+ console.info(diosphereObject)
67
69
  } catch (error) {
68
70
  console.error(error)
69
71
  }
@@ -102,11 +104,13 @@ class DioryClient implements IDioryClient {
102
104
  this.selectRoom(roomObject)
103
105
 
104
106
  this.diograph.resetDiograph()
105
- const diographObject = (await this.getDiograph()) ?? defaultDiograph
107
+ const diographObject = (await this.getDiograph()) ?? getDefaultDiograph()
106
108
  this.diograph.addDiograph(diographObject)
109
+ await this.saveDiograph()
107
110
 
108
111
  this.focusDiory({ id: '/' })
109
112
 
113
+ console.info(this.diograph.toObject())
110
114
  return this.diograph
111
115
  }
112
116
 
@@ -150,11 +154,17 @@ class DioryClient implements IDioryClient {
150
154
  await Promise.all(
151
155
  this.getDiographClients(connections).map(async (connectionClient) => {
152
156
  const diographObject = await connectionClient.generateDiograph()
153
- Object.entries(diographObject).forEach(([key, dioryObject]) => {
154
- key === '/'
155
- ? this.diograph.addDioryLink({ id: '/' }, diographObject['/'])
156
- : this.diograph.addDiory(dioryObject)
157
- })
157
+ console.info(diographObject)
158
+
159
+ try {
160
+ Object.entries(diographObject).forEach(([key, dioryObject]) => {
161
+ key === '/'
162
+ ? this.diograph.addDioryLink({ id: '/' }, diographObject['/'])
163
+ : this.diograph.addDiory(dioryObject)
164
+ })
165
+ } catch (error) {
166
+ console.error(error)
167
+ }
158
168
 
159
169
  await connectionClient.saveDiograph(this.diograph.toObject())
160
170
  console.info(this.diograph.toObject())
@@ -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: 'Room 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: 'Welcome room',
8
+ connections,
9
+ },
10
+ '/',
11
+ )
12
+
13
+ return diosphere.toObject()
14
+ }
@@ -1,23 +0,0 @@
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
- }
@@ -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
- }