@diory/client-js 0.4.3 → 0.4.4-rc10

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
  };
@@ -33,33 +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 (address, saveDiograph) => {
46
- const { client, path } = resolveConnection(address);
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
- const diographObject = await (0, folder_generator_1.generateDiograph)(path, '/', dataClient, { saveDiograph });
50
+ const diographObject = await (0, folder_generator_1.generateDiograph)(root, path, dataClient, options);
51
51
  if (diographObject)
52
- this.addDiograph(address, diographObject);
52
+ this.addDiograph((0, path_browserify_1.join)(address, path), diographObject);
53
53
  }
54
54
  return this;
55
55
  };
56
56
  this.saveDiograph = (address) => (0, debounce_1.debounce)(async () => {
57
- const { client, path } = resolveConnection(address);
57
+ const { client, root } = resolveConnection(address);
58
58
  const dataClient = findDataClient(this.dataClients, client);
59
59
  if (dataClient) {
60
60
  const diograph = this.getDiograph(address);
61
61
  if (diograph)
62
- 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());
63
63
  }
64
64
  return;
65
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,13 +1,13 @@
1
1
  {
2
2
  "name": "@diory/client-js",
3
- "version": "0.4.3",
3
+ "version": "0.4.4-rc10",
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.3",
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)
@@ -48,23 +48,27 @@ 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
 
58
58
  return this
59
59
  }
60
60
 
61
- generateDiograph = async (address: string, saveDiograph?: boolean): Promise<IDioryClient> => {
62
- const { client, path } = resolveConnection(address)
61
+ generateDiograph = async (
62
+ address: string,
63
+ path = '/',
64
+ options?: GenerateDiographOptions,
65
+ ): Promise<IDioryClient> => {
66
+ const { client, root } = resolveConnection(address)
63
67
  const dataClient = findDataClient(this.dataClients, client)
64
68
  if (dataClient) {
65
69
  // TODO save based on client properties
66
- const diographObject = await generateDiograph(path, '/', dataClient, { saveDiograph })
67
- if (diographObject) this.addDiograph(address, diographObject)
70
+ const diographObject = await generateDiograph(root, path, dataClient, options)
71
+ if (diographObject) this.addDiograph(join(address, path), diographObject)
68
72
  }
69
73
 
70
74
  return this
@@ -72,11 +76,11 @@ export class DioryClient implements IDioryClient {
72
76
 
73
77
  saveDiograph = (address: string) =>
74
78
  debounce(async () => {
75
- const { client, path } = resolveConnection(address)
79
+ const { client, root } = resolveConnection(address)
76
80
  const dataClient = findDataClient(this.dataClients, client)
77
81
  if (dataClient) {
78
82
  const diograph = this.getDiograph(address)
79
- if (diograph) dataClient.writeItem(join(path, DIOGRAPH_JSON), diograph.toJson())
83
+ if (diograph) dataClient.writeItem(join(root, DIOGRAPH_JSON), diograph.toJson())
80
84
  }
81
85
 
82
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