@diory/client-js 0.2.0-rc16 → 0.2.0-rc18
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.
- package/dist/connectionClient/connectionClient.d.ts +3 -3
- package/dist/connectionClient/connectionClient.js +5 -4
- package/dist/connectionClient/utils/debounce.d.ts +1 -0
- package/dist/connectionClient/utils/debounce.js +24 -0
- package/dist/dioryClient/dioryClient.js +7 -7
- package/package.json +1 -1
- package/src/connectionClient/connectionClient.ts +5 -4
- package/src/connectionClient/utils/debounce.ts +18 -0
- package/src/dioryClient/dioryClient.ts +6 -6
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IDiographObject } from '@diograph/diograph';
|
|
2
|
-
import { IConnectionObject
|
|
2
|
+
import { IConnectionObject } from '@diory/diosphere-js';
|
|
3
3
|
import { IConnectionClient, IDataClient } from '../types';
|
|
4
4
|
declare class ConnectionClient implements IConnectionClient {
|
|
5
5
|
type: string;
|
|
@@ -7,9 +7,9 @@ declare class ConnectionClient implements IConnectionClient {
|
|
|
7
7
|
connection: IConnectionObject;
|
|
8
8
|
constructor(dataClient: IDataClient, connection: IConnectionObject);
|
|
9
9
|
getDiosphere: () => Promise<any>;
|
|
10
|
-
saveDiosphere: (
|
|
10
|
+
saveDiosphere: () => void;
|
|
11
11
|
getDiograph: () => Promise<any>;
|
|
12
|
-
saveDiograph: (
|
|
12
|
+
saveDiograph: () => void;
|
|
13
13
|
generateDiograph: () => Promise<IDiographObject>;
|
|
14
14
|
}
|
|
15
15
|
export { ConnectionClient };
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.ConnectionClient = void 0;
|
|
4
4
|
const path_browserify_1 = require("path-browserify");
|
|
5
5
|
const folder_generator_1 = require("@diograph/folder-generator");
|
|
6
|
+
const debounce_1 = require("./utils/debounce");
|
|
6
7
|
const DIOSPHERE_JSON = 'diosphere.json';
|
|
7
8
|
const DIOGRAPH_JSON = 'diograph.json';
|
|
8
9
|
class ConnectionClient {
|
|
@@ -12,21 +13,21 @@ class ConnectionClient {
|
|
|
12
13
|
const diosphereString = await this.client.readTextItem(path);
|
|
13
14
|
return JSON.parse(diosphereString);
|
|
14
15
|
};
|
|
15
|
-
this.saveDiosphere = async (diosphereObject) => {
|
|
16
|
+
this.saveDiosphere = (0, debounce_1.debounce)(async (diosphereObject) => {
|
|
16
17
|
const path = (0, path_browserify_1.join)(this.connection.address, DIOSPHERE_JSON);
|
|
17
18
|
const diosphereString = JSON.stringify(diosphereObject, null, 2);
|
|
18
19
|
return this.client.writeItem(path, diosphereString);
|
|
19
|
-
};
|
|
20
|
+
}, 1000);
|
|
20
21
|
this.getDiograph = async () => {
|
|
21
22
|
const path = (0, path_browserify_1.join)(this.connection.address, DIOGRAPH_JSON);
|
|
22
23
|
const diographString = await this.client.readTextItem(path);
|
|
23
24
|
return JSON.parse(diographString);
|
|
24
25
|
};
|
|
25
|
-
this.saveDiograph = async (diographObject) => {
|
|
26
|
+
this.saveDiograph = (0, debounce_1.debounce)(async (diographObject) => {
|
|
26
27
|
const path = (0, path_browserify_1.join)(this.connection.address, DIOGRAPH_JSON);
|
|
27
28
|
const diographString = JSON.stringify(diographObject, null, 2);
|
|
28
29
|
return this.client.writeItem(path, diographString);
|
|
29
|
-
};
|
|
30
|
+
}, 1000);
|
|
30
31
|
this.generateDiograph = async () => {
|
|
31
32
|
const { diograph } = await (0, folder_generator_1.generateDiograph)(this.connection.address, this.client);
|
|
32
33
|
return diograph.toObject();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function debounce(func: any, wait: number, immediate?: boolean): () => void;
|
|
@@ -0,0 +1,24 @@
|
|
|
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)
|
|
15
|
+
func.apply(context, args);
|
|
16
|
+
};
|
|
17
|
+
const callNow = immediate && !timeout;
|
|
18
|
+
clearTimeout(timeout);
|
|
19
|
+
timeout = setTimeout(later, wait);
|
|
20
|
+
if (callNow)
|
|
21
|
+
func.apply(context, args);
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
exports.debounce = debounce;
|
|
@@ -102,16 +102,16 @@ class DioryClient {
|
|
|
102
102
|
await Promise.all(this.getDiographClients(connections).map(async (connectionClient) => {
|
|
103
103
|
const diographObject = await connectionClient.generateDiograph();
|
|
104
104
|
console.info(diographObject);
|
|
105
|
-
|
|
106
|
-
|
|
105
|
+
Object.entries(diographObject).forEach(([key, dioryObject]) => {
|
|
106
|
+
try {
|
|
107
107
|
key === '/'
|
|
108
108
|
? this.diograph.addDioryLink({ id: '/' }, diographObject['/'])
|
|
109
109
|
: this.diograph.addDiory(dioryObject);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
}
|
|
110
|
+
}
|
|
111
|
+
catch (error) {
|
|
112
|
+
console.error(error);
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
115
|
await connectionClient.saveDiograph(this.diograph.toObject());
|
|
116
116
|
console.info(this.diograph.toObject());
|
|
117
117
|
return;
|
package/package.json
CHANGED
|
@@ -4,6 +4,7 @@ import { generateDiograph } from '@diograph/folder-generator'
|
|
|
4
4
|
import { IDiographObject } from '@diograph/diograph'
|
|
5
5
|
import { IConnectionObject, IDiosphereObject } from '@diory/diosphere-js'
|
|
6
6
|
import { IConnectionClient, IDataClient } from '../types'
|
|
7
|
+
import { debounce } from './utils/debounce'
|
|
7
8
|
|
|
8
9
|
const DIOSPHERE_JSON = 'diosphere.json'
|
|
9
10
|
const DIOGRAPH_JSON = 'diograph.json'
|
|
@@ -25,11 +26,11 @@ class ConnectionClient implements IConnectionClient {
|
|
|
25
26
|
return JSON.parse(diosphereString)
|
|
26
27
|
}
|
|
27
28
|
|
|
28
|
-
saveDiosphere = async (diosphereObject: IDiosphereObject) => {
|
|
29
|
+
saveDiosphere = debounce(async (diosphereObject: IDiosphereObject) => {
|
|
29
30
|
const path = join(this.connection.address, DIOSPHERE_JSON)
|
|
30
31
|
const diosphereString = JSON.stringify(diosphereObject, null, 2)
|
|
31
32
|
return this.client.writeItem(path, diosphereString)
|
|
32
|
-
}
|
|
33
|
+
}, 1000)
|
|
33
34
|
|
|
34
35
|
getDiograph = async () => {
|
|
35
36
|
const path = join(this.connection.address, DIOGRAPH_JSON)
|
|
@@ -37,11 +38,11 @@ class ConnectionClient implements IConnectionClient {
|
|
|
37
38
|
return JSON.parse(diographString)
|
|
38
39
|
}
|
|
39
40
|
|
|
40
|
-
saveDiograph = async (diographObject: IDiographObject) => {
|
|
41
|
+
saveDiograph = debounce(async (diographObject: IDiographObject) => {
|
|
41
42
|
const path = join(this.connection.address, DIOGRAPH_JSON)
|
|
42
43
|
const diographString = JSON.stringify(diographObject, null, 2)
|
|
43
44
|
return this.client.writeItem(path, diographString)
|
|
44
|
-
}
|
|
45
|
+
}, 1000)
|
|
45
46
|
|
|
46
47
|
generateDiograph = async (): Promise<IDiographObject> => {
|
|
47
48
|
const { diograph } = await generateDiograph(this.connection.address, this.client)
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export function debounce(func: any, wait: number, immediate = false) {
|
|
2
|
+
let timeout: any
|
|
3
|
+
// eslint-disable-next-line func-names
|
|
4
|
+
return () => {
|
|
5
|
+
// @ts-ignore
|
|
6
|
+
const context = this
|
|
7
|
+
const args = arguments
|
|
8
|
+
// eslint-disable-next-line func-names
|
|
9
|
+
const later = function () {
|
|
10
|
+
timeout = null
|
|
11
|
+
if (!immediate) func.apply(context, args)
|
|
12
|
+
}
|
|
13
|
+
const callNow = immediate && !timeout
|
|
14
|
+
clearTimeout(timeout)
|
|
15
|
+
timeout = setTimeout(later, wait)
|
|
16
|
+
if (callNow) func.apply(context, args)
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -156,15 +156,15 @@ class DioryClient implements IDioryClient {
|
|
|
156
156
|
const diographObject = await connectionClient.generateDiograph()
|
|
157
157
|
console.info(diographObject)
|
|
158
158
|
|
|
159
|
-
|
|
160
|
-
|
|
159
|
+
Object.entries(diographObject).forEach(([key, dioryObject]) => {
|
|
160
|
+
try {
|
|
161
161
|
key === '/'
|
|
162
162
|
? this.diograph.addDioryLink({ id: '/' }, diographObject['/'])
|
|
163
163
|
: this.diograph.addDiory(dioryObject)
|
|
164
|
-
})
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
}
|
|
164
|
+
} catch (error) {
|
|
165
|
+
console.error(error)
|
|
166
|
+
}
|
|
167
|
+
})
|
|
168
168
|
|
|
169
169
|
await connectionClient.saveDiograph(this.diograph.toObject())
|
|
170
170
|
console.info(this.diograph.toObject())
|