@diory/client-js 0.4.4-rc6 → 0.4.4-rc8

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: (root: string, path?: string, options?: GenerateDiographOptions) => Promise<IDioryClient>;
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
- path: addressArray.slice(1, -1).join('/'),
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.path}`;
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,34 +33,33 @@ class DioryClient {
33
33
  return this.diographs[diographKey];
34
34
  };
35
35
  this.fetchDiograph = async (address) => {
36
- const { client, path } = resolveConnection(address);
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)(path, DIOGRAPH_JSON));
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 (root, path = '/', options) => {
46
- const { client } = resolveConnection(root);
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
50
50
  const diographObject = await (0, folder_generator_1.generateDiograph)(root, path, dataClient, options);
51
- const address = (0, path_browserify_1.join)(root, path);
52
51
  if (diographObject)
53
52
  this.addDiograph(address, diographObject);
54
53
  }
55
54
  return this;
56
55
  };
57
56
  this.saveDiograph = (address) => (0, debounce_1.debounce)(async () => {
58
- const { client, path } = resolveConnection(address);
57
+ const { client, root } = resolveConnection(address);
59
58
  const dataClient = findDataClient(this.dataClients, client);
60
59
  if (dataClient) {
61
60
  const diograph = this.getDiograph(address);
62
61
  if (diograph)
63
- dataClient.writeItem((0, path_browserify_1.join)(path, DIOGRAPH_JSON), diograph.toJson());
62
+ dataClient.writeItem((0, path_browserify_1.join)(root, DIOGRAPH_JSON), diograph.toJson());
64
63
  }
65
64
  return;
66
65
  }, 1000);
package/dist/types.d.ts CHANGED
@@ -2,7 +2,7 @@ import { IDataClient } from '@diory/types';
2
2
  import { IDiograph } from '@diograph/diograph';
3
3
  export type IConnectionObject = {
4
4
  client: string;
5
- path: string;
5
+ root: string;
6
6
  id: string;
7
7
  };
8
8
  export interface IDioryClient {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@diory/client-js",
3
- "version": "0.4.4-rc6",
3
+ "version": "0.4.4-rc8",
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,12 +11,12 @@ const resolveConnection = (address: string): IConnectionObject => {
11
11
  const addressArray = (address || '').split('/') || []
12
12
  return {
13
13
  client: addressArray[0],
14
- path: addressArray.slice(1, -1).join('/'),
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.path}`
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, path } = resolveConnection(address)
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(path, DIOGRAPH_JSON))
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,16 +59,15 @@ export class DioryClient implements IDioryClient {
59
59
  }
60
60
 
61
61
  generateDiograph = async (
62
- root: string,
62
+ address: string,
63
63
  path = '/',
64
64
  options?: GenerateDiographOptions,
65
65
  ): Promise<IDioryClient> => {
66
- const { client } = resolveConnection(root)
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
70
70
  const diographObject = await generateDiograph(root, path, dataClient, options)
71
- const address = join(root, path)
72
71
  if (diographObject) this.addDiograph(address, diographObject)
73
72
  }
74
73
 
@@ -77,11 +76,11 @@ export class DioryClient implements IDioryClient {
77
76
 
78
77
  saveDiograph = (address: string) =>
79
78
  debounce(async () => {
80
- const { client, path } = resolveConnection(address)
79
+ const { client, root } = resolveConnection(address)
81
80
  const dataClient = findDataClient(this.dataClients, client)
82
81
  if (dataClient) {
83
82
  const diograph = this.getDiograph(address)
84
- if (diograph) dataClient.writeItem(join(path, DIOGRAPH_JSON), diograph.toJson())
83
+ if (diograph) dataClient.writeItem(join(root, DIOGRAPH_JSON), diograph.toJson())
85
84
  }
86
85
 
87
86
  return
package/src/types.ts CHANGED
@@ -3,7 +3,7 @@ import { IDiograph } from '@diograph/diograph'
3
3
 
4
4
  export type IConnectionObject = {
5
5
  client: string
6
- path: string
6
+ root: string
7
7
  id: string
8
8
  }
9
9