@diory/client-js 0.4.4-rc6 → 0.4.4-rc7
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.
|
@@ -11,6 +11,6 @@ export declare class DioryClient implements IDioryClient {
|
|
|
11
11
|
addDiograph: (address: string, diographObject: IDiographObject) => IDioryClient;
|
|
12
12
|
getDiograph: (address: string) => IDiograph | undefined;
|
|
13
13
|
fetchDiograph: (address: string) => Promise<IDioryClient>;
|
|
14
|
-
generateDiograph: (
|
|
14
|
+
generateDiograph: (address: string, path?: string, options?: GenerateDiographOptions) => Promise<IDioryClient>;
|
|
15
15
|
saveDiograph: (address: string) => () => any;
|
|
16
16
|
}
|
|
@@ -9,11 +9,11 @@ const resolveConnection = (address) => {
|
|
|
9
9
|
const addressArray = (address || '').split('/') || [];
|
|
10
10
|
return {
|
|
11
11
|
client: addressArray[0],
|
|
12
|
-
|
|
12
|
+
root: addressArray.slice(1, -1).join('/'),
|
|
13
13
|
id: addressArray[addressArray.length - 1],
|
|
14
14
|
};
|
|
15
15
|
};
|
|
16
|
-
const getDiographKey = (connection) => `${connection.client}/${connection.
|
|
16
|
+
const getDiographKey = (connection) => `${connection.client}/${connection.root}`;
|
|
17
17
|
const findDataClient = (dataClients, client) => {
|
|
18
18
|
return dataClients.find(({ type }) => type === client);
|
|
19
19
|
};
|
|
@@ -33,17 +33,17 @@ class DioryClient {
|
|
|
33
33
|
return this.diographs[diographKey];
|
|
34
34
|
};
|
|
35
35
|
this.fetchDiograph = async (address) => {
|
|
36
|
-
const { client,
|
|
36
|
+
const { client, root } = resolveConnection(address);
|
|
37
37
|
const dataClient = findDataClient(this.dataClients, client);
|
|
38
38
|
if (dataClient) {
|
|
39
|
-
const diographString = await dataClient.readTextItem((0, path_browserify_1.join)(
|
|
39
|
+
const diographString = await dataClient.readTextItem((0, path_browserify_1.join)(root, DIOGRAPH_JSON));
|
|
40
40
|
if (diographString)
|
|
41
41
|
this.addDiograph(address, JSON.parse(diographString));
|
|
42
42
|
}
|
|
43
43
|
return this;
|
|
44
44
|
};
|
|
45
|
-
this.generateDiograph = async (
|
|
46
|
-
const { client } = resolveConnection(
|
|
45
|
+
this.generateDiograph = async (address, path = '/', options) => {
|
|
46
|
+
const { client, root } = resolveConnection(address);
|
|
47
47
|
const dataClient = findDataClient(this.dataClients, client);
|
|
48
48
|
if (dataClient) {
|
|
49
49
|
// TODO save based on client properties
|
|
@@ -55,12 +55,12 @@ class DioryClient {
|
|
|
55
55
|
return this;
|
|
56
56
|
};
|
|
57
57
|
this.saveDiograph = (address) => (0, debounce_1.debounce)(async () => {
|
|
58
|
-
const { client,
|
|
58
|
+
const { client, root } = resolveConnection(address);
|
|
59
59
|
const dataClient = findDataClient(this.dataClients, client);
|
|
60
60
|
if (dataClient) {
|
|
61
61
|
const diograph = this.getDiograph(address);
|
|
62
62
|
if (diograph)
|
|
63
|
-
dataClient.writeItem((0, path_browserify_1.join)(
|
|
63
|
+
dataClient.writeItem((0, path_browserify_1.join)(root, DIOGRAPH_JSON), diograph.toJson());
|
|
64
64
|
}
|
|
65
65
|
return;
|
|
66
66
|
}, 1000);
|
package/dist/types.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -11,12 +11,12 @@ const resolveConnection = (address: string): IConnectionObject => {
|
|
|
11
11
|
const addressArray = (address || '').split('/') || []
|
|
12
12
|
return {
|
|
13
13
|
client: addressArray[0],
|
|
14
|
-
|
|
14
|
+
root: addressArray.slice(1, -1).join('/'),
|
|
15
15
|
id: addressArray[addressArray.length - 1],
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
const getDiographKey = (connection: IConnectionObject) => `${connection.client}/${connection.
|
|
19
|
+
const getDiographKey = (connection: IConnectionObject) => `${connection.client}/${connection.root}`
|
|
20
20
|
|
|
21
21
|
const findDataClient = (dataClients: IDataClient[], client: string): IDataClient | undefined => {
|
|
22
22
|
return dataClients.find(({ type }) => type === client)
|
|
@@ -48,10 +48,10 @@ export class DioryClient implements IDioryClient {
|
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
fetchDiograph = async (address: string): Promise<IDioryClient> => {
|
|
51
|
-
const { client,
|
|
51
|
+
const { client, root } = resolveConnection(address)
|
|
52
52
|
const dataClient = findDataClient(this.dataClients, client)
|
|
53
53
|
if (dataClient) {
|
|
54
|
-
const diographString = await dataClient.readTextItem(join(
|
|
54
|
+
const diographString = await dataClient.readTextItem(join(root, DIOGRAPH_JSON))
|
|
55
55
|
if (diographString) this.addDiograph(address, JSON.parse(diographString))
|
|
56
56
|
}
|
|
57
57
|
|
|
@@ -59,11 +59,11 @@ export class DioryClient implements IDioryClient {
|
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
generateDiograph = async (
|
|
62
|
-
|
|
62
|
+
address: string,
|
|
63
63
|
path = '/',
|
|
64
64
|
options?: GenerateDiographOptions,
|
|
65
65
|
): Promise<IDioryClient> => {
|
|
66
|
-
const { client } = resolveConnection(
|
|
66
|
+
const { client, root } = resolveConnection(address)
|
|
67
67
|
const dataClient = findDataClient(this.dataClients, client)
|
|
68
68
|
if (dataClient) {
|
|
69
69
|
// TODO save based on client properties
|
|
@@ -77,11 +77,11 @@ export class DioryClient implements IDioryClient {
|
|
|
77
77
|
|
|
78
78
|
saveDiograph = (address: string) =>
|
|
79
79
|
debounce(async () => {
|
|
80
|
-
const { client,
|
|
80
|
+
const { client, root } = resolveConnection(address)
|
|
81
81
|
const dataClient = findDataClient(this.dataClients, client)
|
|
82
82
|
if (dataClient) {
|
|
83
83
|
const diograph = this.getDiograph(address)
|
|
84
|
-
if (diograph) dataClient.writeItem(join(
|
|
84
|
+
if (diograph) dataClient.writeItem(join(root, DIOGRAPH_JSON), diograph.toJson())
|
|
85
85
|
}
|
|
86
86
|
|
|
87
87
|
return
|