@diory/client-js 0.4.4-rc1 → 0.4.4-rc11

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,5 +1,6 @@
1
1
  import { IDataClient } from '@diory/types';
2
2
  import { IDiograph, IDiographObject } from '@diograph/diograph';
3
+ import { GenerateDiographOptions } from '@diograph/folder-generator';
3
4
  import { IDioryClient } from '../types';
4
5
  export declare class DioryClient implements IDioryClient {
5
6
  diographs: {
@@ -10,6 +11,6 @@ export declare class DioryClient implements IDioryClient {
10
11
  addDiograph: (address: string, diographObject: IDiographObject) => IDioryClient;
11
12
  getDiograph: (address: string) => IDiograph | undefined;
12
13
  fetchDiograph: (address: string) => Promise<IDioryClient>;
13
- generateDiograph: (address: string, saveDiograph?: boolean) => Promise<IDioryClient>;
14
+ generateDiograph: (address: string, path?: string, options?: GenerateDiographOptions) => Promise<IDioryClient>;
14
15
  saveDiograph: (address: string) => () => any;
15
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
  };
@@ -24,6 +24,7 @@ class DioryClient {
24
24
  this.addDiograph = (address, diographObject) => {
25
25
  const connection = resolveConnection(address);
26
26
  const diographKey = getDiographKey(connection);
27
+ console.log(address, connection, diographKey);
27
28
  this.diographs[diographKey] = new diograph_1.Diograph(this.saveDiograph(address)).addDiograph(diographObject);
28
29
  return this;
29
30
  };
@@ -33,33 +34,33 @@ class DioryClient {
33
34
  return this.diographs[diographKey];
34
35
  };
35
36
  this.fetchDiograph = async (address) => {
36
- const { client, path } = resolveConnection(address);
37
+ const { client, root } = resolveConnection(address);
37
38
  const dataClient = findDataClient(this.dataClients, client);
38
39
  if (dataClient) {
39
- const diographString = await dataClient.readTextItem((0, path_browserify_1.join)(path, DIOGRAPH_JSON));
40
+ const diographString = await dataClient.readTextItem((0, path_browserify_1.join)(root, DIOGRAPH_JSON));
40
41
  if (diographString)
41
42
  this.addDiograph(address, JSON.parse(diographString));
42
43
  }
43
44
  return this;
44
45
  };
45
- this.generateDiograph = async (address, saveDiograph) => {
46
- const { client, path } = resolveConnection(address);
46
+ this.generateDiograph = async (address, path = '/', options) => {
47
+ const { client, root } = resolveConnection(address);
47
48
  const dataClient = findDataClient(this.dataClients, client);
48
49
  if (dataClient) {
49
50
  // TODO save based on client properties
50
- const diographObject = await (0, folder_generator_1.generateDiograph)(path, '/', dataClient, { saveDiograph });
51
+ const diographObject = await (0, folder_generator_1.generateDiograph)(root, path, dataClient, options);
51
52
  if (diographObject)
52
- this.addDiograph(address, diographObject);
53
+ this.addDiograph((0, path_browserify_1.join)(address, path), diographObject);
53
54
  }
54
55
  return this;
55
56
  };
56
57
  this.saveDiograph = (address) => (0, debounce_1.debounce)(async () => {
57
- const { client, path } = resolveConnection(address);
58
+ const { client, root } = resolveConnection(address);
58
59
  const dataClient = findDataClient(this.dataClients, client);
59
60
  if (dataClient) {
60
61
  const diograph = this.getDiograph(address);
61
62
  if (diograph)
62
- dataClient.writeItem((0, path_browserify_1.join)(path, DIOGRAPH_JSON), diograph.toJson());
63
+ dataClient.writeItem((0, path_browserify_1.join)(root, DIOGRAPH_JSON), diograph.toJson());
63
64
  }
64
65
  return;
65
66
  }, 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,13 +1,13 @@
1
1
  {
2
2
  "name": "@diory/client-js",
3
- "version": "0.4.4-rc1",
3
+ "version": "0.4.4-rc11",
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>",
7
7
  "license": "MIT",
8
8
  "dependencies": {
9
9
  "@diograph/diograph": "^0.4.3",
10
- "@diograph/folder-generator": "0.4.4-rc1",
10
+ "@diograph/folder-generator": "0.4.4-rc5",
11
11
  "path-browserify": "^1.0.1",
12
12
  "uuid": "8.3.2"
13
13
  },
@@ -1,7 +1,7 @@
1
1
  import { join } from 'path-browserify'
2
2
  import { IDataClient } from '@diory/types'
3
3
  import { Diograph, IDiograph, IDiographObject } from '@diograph/diograph'
4
- import { generateDiograph } from '@diograph/folder-generator'
4
+ import { generateDiograph, GenerateDiographOptions } from '@diograph/folder-generator'
5
5
 
6
6
  import { IConnectionObject, IDioryClient } from '../types'
7
7
 
@@ -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)
@@ -35,6 +35,7 @@ export class DioryClient implements IDioryClient {
35
35
  addDiograph = (address: string, diographObject: IDiographObject): IDioryClient => {
36
36
  const connection = resolveConnection(address)
37
37
  const diographKey = getDiographKey(connection)
38
+ console.log(address, connection, diographKey)
38
39
  this.diographs[diographKey] = new Diograph(this.saveDiograph(address)).addDiograph(
39
40
  diographObject,
40
41
  )
@@ -48,23 +49,27 @@ export class DioryClient implements IDioryClient {
48
49
  }
49
50
 
50
51
  fetchDiograph = async (address: string): Promise<IDioryClient> => {
51
- const { client, path } = resolveConnection(address)
52
+ const { client, root } = resolveConnection(address)
52
53
  const dataClient = findDataClient(this.dataClients, client)
53
54
  if (dataClient) {
54
- const diographString = await dataClient.readTextItem(join(path, DIOGRAPH_JSON))
55
+ const diographString = await dataClient.readTextItem(join(root, DIOGRAPH_JSON))
55
56
  if (diographString) this.addDiograph(address, JSON.parse(diographString))
56
57
  }
57
58
 
58
59
  return this
59
60
  }
60
61
 
61
- generateDiograph = async (address: string, saveDiograph?: boolean): Promise<IDioryClient> => {
62
- const { client, path } = resolveConnection(address)
62
+ generateDiograph = async (
63
+ address: string,
64
+ path = '/',
65
+ options?: GenerateDiographOptions,
66
+ ): Promise<IDioryClient> => {
67
+ const { client, root } = resolveConnection(address)
63
68
  const dataClient = findDataClient(this.dataClients, client)
64
69
  if (dataClient) {
65
70
  // TODO save based on client properties
66
- const diographObject = await generateDiograph(path, '/', dataClient, { saveDiograph })
67
- if (diographObject) this.addDiograph(address, diographObject)
71
+ const diographObject = await generateDiograph(root, path, dataClient, options)
72
+ if (diographObject) this.addDiograph(join(address, path), diographObject)
68
73
  }
69
74
 
70
75
  return this
@@ -72,11 +77,11 @@ export class DioryClient implements IDioryClient {
72
77
 
73
78
  saveDiograph = (address: string) =>
74
79
  debounce(async () => {
75
- const { client, path } = resolveConnection(address)
80
+ const { client, root } = resolveConnection(address)
76
81
  const dataClient = findDataClient(this.dataClients, client)
77
82
  if (dataClient) {
78
83
  const diograph = this.getDiograph(address)
79
- if (diograph) dataClient.writeItem(join(path, DIOGRAPH_JSON), diograph.toJson())
84
+ if (diograph) dataClient.writeItem(join(root, DIOGRAPH_JSON), diograph.toJson())
80
85
  }
81
86
 
82
87
  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