@diory/client-js 0.1.5-rc1 → 0.2.0-rc2

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,6 +1,6 @@
1
1
  import { IDiographObject } from '@diograph/diograph';
2
2
  import { IConnectionObject, IDiosphereObject } from '@diory/diosphere-js';
3
- import { IConnectionClient, IDataClient } from './types';
3
+ import { IConnectionClient, IDataClient } from '../types';
4
4
  declare class ConnectionClient implements IConnectionClient {
5
5
  type: string;
6
6
  client: IDataClient;
@@ -28,7 +28,7 @@ class ConnectionClient {
28
28
  return this.client.writeItem(path, diographString);
29
29
  };
30
30
  this.generateDiograph = async () => {
31
- const { diograph } = await (0, folder_generator_1.generateDiograph)(this.connection.address); // TODO: Client
31
+ const { diograph } = await (0, folder_generator_1.generateDiograph)(this.connection.address, this.client);
32
32
  return diograph.toObject();
33
33
  };
34
34
  this.type = dataClient.type;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ describe('connectionClient', () => {
3
+ describe('construct()', () => {
4
+ it('should construct with dataClient and connection', () => {
5
+ expect(true).toEqual(true);
6
+ });
7
+ });
8
+ describe('getDiosphere()', () => {
9
+ it('should get diosphere', () => {
10
+ expect(true).toEqual(true);
11
+ });
12
+ });
13
+ describe('saveDiosphere()', () => {
14
+ it('should save diosphere object', () => {
15
+ expect(true).toEqual(true);
16
+ });
17
+ });
18
+ });
@@ -1,6 +1,6 @@
1
1
  import { IConnectionObject, IDiosphere, IRoom, IRoomObject } from '@diory/diosphere-js';
2
2
  import { IDiograph, IDiory, IDioryObject } from '@diograph/diograph';
3
- import { IDataClient, IDioryClient } from './types';
3
+ import { IDioryClient, IDataClient } from '../types';
4
4
  declare class DioryClient implements IDioryClient {
5
5
  dataClients: IDataClient[];
6
6
  connections: IConnectionObject[];
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DioryClient = void 0;
4
4
  const diosphere_js_1 = require("@diory/diosphere-js");
5
5
  const diograph_1 = require("@diograph/diograph");
6
- const getConnectionClients_1 = require("./utils/getConnectionClients");
6
+ const getConnectionClients_1 = require("../utils/getConnectionClients");
7
7
  class DioryClient {
8
8
  constructor(dataClients) {
9
9
  this.dataClients = [];
File without changes
package/dist/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- export { DioryClient } from './dioryClient';
2
- export { ConnectionClient } from './connectionClient';
3
- export { IDioryClient, IConnectionClient, IDataClient } from './types';
1
+ export { DioryClient } from './dioryClient/dioryClient';
2
+ export { ConnectionClient } from './connectionClient/connectionClient';
3
+ export { IDioryClient, IConnectionClient, IDataClient, IFileType, IMetadata } from './types';
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ConnectionClient = exports.DioryClient = void 0;
4
- var dioryClient_1 = require("./dioryClient");
4
+ var dioryClient_1 = require("./dioryClient/dioryClient");
5
5
  Object.defineProperty(exports, "DioryClient", { enumerable: true, get: function () { return dioryClient_1.DioryClient; } });
6
- var connectionClient_1 = require("./connectionClient");
6
+ var connectionClient_1 = require("./connectionClient/connectionClient");
7
7
  Object.defineProperty(exports, "ConnectionClient", { enumerable: true, get: function () { return connectionClient_1.ConnectionClient; } });
package/dist/types.d.ts CHANGED
@@ -1,6 +1,15 @@
1
1
  /// <reference types="node" />
2
2
  import { IConnectionObject, IDiosphere, IDiosphereObject, IRoom, IRoomObject } from '@diory/diosphere-js';
3
- import { IDiographObject, IDiograph, IDiory, IDioryObject } from '@diograph/diograph';
3
+ import { IDiograph, IDiographObject, IDiory, IDioryObject } from '@diograph/diograph';
4
+ export interface IMetadata {
5
+ name: string;
6
+ created?: string;
7
+ modified?: string;
8
+ }
9
+ export interface IFileType {
10
+ ext?: string;
11
+ mime?: string;
12
+ }
4
13
  export interface IDataClient {
5
14
  type: string;
6
15
  readTextItem(url: string): Promise<string>;
@@ -12,6 +21,10 @@ export interface IDataClient {
12
21
  deleteItem(url: string): Promise<boolean>;
13
22
  deleteFolder(url: string): Promise<void>;
14
23
  list(url: string): Promise<string[]>;
24
+ getFileNames(url: string): Promise<string[]>;
25
+ getFolderNames(url: string): Promise<string[]>;
26
+ getMetadata(url: string): IMetadata;
27
+ getFileType(url: string): Promise<IFileType>;
15
28
  }
16
29
  export interface IConnectionClient {
17
30
  type: string;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getConnectionClients = void 0;
4
- const connectionClient_1 = require("../connectionClient");
4
+ const connectionClient_1 = require("../connectionClient/connectionClient");
5
5
  function getDataClient(dataClients, { client }) {
6
6
  return dataClients.find(({ type }) => type === client);
7
7
  }
package/package.json CHANGED
@@ -1,13 +1,16 @@
1
1
  {
2
2
  "name": "@diory/client-js",
3
- "version": "0.1.5-rc1",
3
+ "version": "0.2.0-rc2",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
+ "files": [
7
+ "dist"
8
+ ],
6
9
  "author": "Olli-Pekka Pohjola <op@diory.me>, Jouni Alanen <jouni@diory.me>",
7
10
  "license": "MIT",
8
11
  "dependencies": {
9
12
  "@diograph/diograph": "0.3.0-rc14",
10
- "@diograph/folder-generator": "^0.2.0-rc1",
13
+ "@diograph/folder-generator": "^0.3.0-rc1",
11
14
  "@diory/diosphere-js": "0.2.6-rc2",
12
15
  "path-browserify": "^1.0.1",
13
16
  "uuid": "8.3.2"
@@ -1,44 +0,0 @@
1
- name: Publish to NPM
2
-
3
- on:
4
- workflow_dispatch:
5
- inputs:
6
- version:
7
- description: 'Specify the version to publish'
8
- required: true
9
-
10
- jobs:
11
- publish:
12
- runs-on: ubuntu-latest
13
- permissions:
14
- contents: write
15
-
16
- steps:
17
- - name: Checkout code
18
- uses: actions/checkout@v4
19
-
20
- - name: Setup Node.js
21
- uses: actions/setup-node@v4
22
- with:
23
- node-version-file: '.nvmrc'
24
- registry-url: 'https://registry.npmjs.org'
25
-
26
- - name: Install dependencies
27
- run: yarn install
28
-
29
- - name: Build
30
- run: yarn build
31
-
32
- - name: Update version using Yarn
33
- run: |
34
- git config user.email "<>"
35
- git config user.name "GitHub Actions Bot"
36
- yarn version --new-version ${{ github.event.inputs.version }}
37
-
38
- - name: Push version update commit
39
- run: git push origin HEAD --follow-tags
40
-
41
- - name: Publish to NPM
42
- run: npm publish --access=public --tag=next
43
- env:
44
- NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
@@ -1,23 +0,0 @@
1
- # This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
2
- # For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
3
-
4
- name: Test (yarn test)
5
-
6
- on: [push]
7
-
8
- jobs:
9
- build:
10
- runs-on: ubuntu-latest
11
- env:
12
- CI: false
13
- steps:
14
- - uses: actions/checkout@v4
15
- with:
16
- submodules: recursive
17
- - name: Use Node.js
18
- uses: actions/setup-node@v4
19
- with:
20
- node-version-file: '.nvmrc'
21
- - run: yarn
22
- - run: yarn build
23
- - run: yarn test
package/.nvmrc DELETED
@@ -1 +0,0 @@
1
- 20.10.0
package/jest.config.js DELETED
@@ -1,6 +0,0 @@
1
- /** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
2
- module.exports = {
3
- preset: 'ts-jest',
4
- testEnvironment: 'node',
5
- testPathIgnorePatterns: ['dist', 'node_modules'],
6
- }
@@ -1,52 +0,0 @@
1
- import { join } from 'path-browserify'
2
- import { generateDiograph } from '@diograph/folder-generator'
3
-
4
- import { IDiographObject } from '@diograph/diograph'
5
- import { IConnectionObject, IDiosphereObject } from '@diory/diosphere-js'
6
- import { IConnectionClient, IDataClient } from './types'
7
-
8
- const DIOSPHERE_JSON = 'diosphere.json'
9
- const DIOGRAPH_JSON = 'diograph.json'
10
-
11
- class ConnectionClient implements IConnectionClient {
12
- type: string
13
- client: IDataClient
14
- connection: IConnectionObject
15
-
16
- constructor(dataClient: IDataClient, connection: IConnectionObject) {
17
- this.type = dataClient.type
18
- this.client = dataClient
19
- this.connection = connection
20
- }
21
-
22
- getDiosphere = async () => {
23
- const path = join(this.connection.address, DIOSPHERE_JSON)
24
- const diosphereString = await this.client.readTextItem(path)
25
- return JSON.parse(diosphereString)
26
- }
27
-
28
- saveDiosphere = async (diosphereObject: IDiosphereObject) => {
29
- const path = join(this.connection.address, DIOSPHERE_JSON)
30
- const diosphereString = JSON.stringify(diosphereObject, null, 2)
31
- return this.client.writeItem(path, diosphereString)
32
- }
33
-
34
- getDiograph = async () => {
35
- const path = join(this.connection.address, DIOGRAPH_JSON)
36
- const diographString = await this.client.readTextItem(path)
37
- return JSON.parse(diographString)
38
- }
39
-
40
- saveDiograph = async (diographObject: IDiographObject) => {
41
- const path = join(this.connection.address, DIOGRAPH_JSON)
42
- const diographString = JSON.stringify(diographObject, null, 2)
43
- return this.client.writeItem(path, diographString)
44
- }
45
-
46
- generateDiograph = async (): Promise<IDiographObject> => {
47
- const { diograph } = await generateDiograph(this.connection.address) // TODO: Client
48
- return diograph.toObject()
49
- }
50
- }
51
-
52
- export { ConnectionClient }
@@ -1,19 +0,0 @@
1
- describe('dioryClient', () => {
2
- describe('constructor()', () => {
3
- it('should construct with dataClient', () => {
4
- expect(true).toEqual(true)
5
- })
6
- })
7
-
8
- describe('initialise()', () => {
9
- it('should initialise with connections', () => {
10
- expect(true).toEqual(true)
11
- })
12
- })
13
-
14
- describe('enterRoom()', () => {
15
- it('should initialise with connections', () => {
16
- expect(true).toEqual(true)
17
- })
18
- })
19
- })
@@ -1,141 +0,0 @@
1
- import { Diosphere, IConnectionObject, IDiosphere, IRoom, IRoomObject } from '@diory/diosphere-js'
2
- import { Diograph, IDiograph, IDiory, IDioryObject } from '@diograph/diograph'
3
-
4
- import { IDataClient, IDioryClient } from './types'
5
- import { getConnectionClients } from './utils/getConnectionClients'
6
-
7
- class DioryClient implements IDioryClient {
8
- dataClients: IDataClient[] = []
9
- connections: IConnectionObject[] = []
10
- diosphere: IDiosphere
11
- room?: IRoom
12
- diograph: IDiograph
13
- diory?: IDiory
14
-
15
- constructor(dataClients: IDataClient[]) {
16
- this.dataClients = dataClients
17
-
18
- this.diosphere = new Diosphere()
19
- this.diograph = new Diograph()
20
-
21
- this.diosphere.saveDiosphere = this.saveDiosphere
22
- this.diograph.saveDiograph = this.saveDiograph
23
- }
24
-
25
- initialise = async (connections: IConnectionObject[]): Promise<IDioryClient> => {
26
- this.connections = connections
27
-
28
- this.diosphere.resetRooms()
29
- await this.getDiosphere()
30
- await this.enterRoom({ id: '/' })
31
-
32
- return this
33
- }
34
-
35
- enterRoom = async (roomObject: IRoomObject): Promise<IRoom> => {
36
- this.room = this.diosphere.getRoom(roomObject)
37
-
38
- this.diograph.resetDiograph()
39
- await this.getDiograph()
40
- this.focusDiory({ id: '/' })
41
-
42
- await this.generateDiograph()
43
-
44
- return this.room
45
- }
46
-
47
- focusDiory = (dioryObject: IDioryObject): IDiory => {
48
- return (this.diory = this.diograph.getDiory(dioryObject))
49
- }
50
-
51
- getDiosphere = async (): Promise<IDiosphere> => {
52
- console.info('getDiosphere', this.connections)
53
- if (this.connections) {
54
- const connectionClients = getConnectionClients(this.dataClients, this.connections)
55
-
56
- await Promise.all(
57
- connectionClients.map(async (connectionClient) => {
58
- const diosphereObject = await connectionClient.getDiosphere()
59
- console.info(diosphereObject)
60
- return this.diosphere.addDiosphere(diosphereObject)
61
- }),
62
- )
63
- }
64
-
65
- return this.diosphere
66
- }
67
-
68
- saveDiosphere = async (): Promise<IDiosphere> => {
69
- console.info('saveDiosphere', this.connections)
70
- if (this.connections) {
71
- const connectionClients = getConnectionClients(this.dataClients, this.connections)
72
-
73
- await Promise.all(
74
- connectionClients.map(async (connectionClient) => {
75
- console.info(this.diosphere.toObject())
76
- await connectionClient.saveDiosphere(this.diosphere.toObject())
77
- return
78
- }),
79
- )
80
- }
81
-
82
- return this.diosphere
83
- }
84
-
85
- getDiograph = async (): Promise<IDiograph> => {
86
- console.info('getDiograph', this.room?.connections)
87
- if (this.room?.connections) {
88
- const connectionClients = getConnectionClients(this.dataClients, this.room.connections)
89
-
90
- await Promise.all(
91
- connectionClients.map(async (connectionClient) => {
92
- const diographObject = await connectionClient.getDiograph()
93
- console.info(diographObject)
94
- this.diograph.addDiograph(diographObject)
95
- return
96
- }),
97
- )
98
- }
99
-
100
- return this.diograph
101
- }
102
-
103
- saveDiograph = async (): Promise<IDiograph> => {
104
- console.info('saveDiograph', this.room?.connections)
105
- if (this.room?.connections) {
106
- const connectionClients = getConnectionClients(this.dataClients, this.room.connections)
107
-
108
- await Promise.all(
109
- connectionClients.map(async (connectionClient) => {
110
- console.info(this.diograph.toObject())
111
- await connectionClient.saveDiograph(this.diograph.toObject())
112
- return
113
- }),
114
- )
115
- }
116
-
117
- return this.diograph
118
- }
119
-
120
- generateDiograph = async (): Promise<IDiograph> => {
121
- console.info('generateDiograph', this.room?.connections)
122
- if (this.room?.connections) {
123
- const connectionClients = getConnectionClients(this.dataClients, this.room?.connections)
124
-
125
- await Promise.all(
126
- connectionClients.map(async (connectionClient) => {
127
- const diographObject = await connectionClient.generateDiograph()
128
- console.info(diographObject)
129
- this.diograph.addDiograph(diographObject)
130
-
131
- await connectionClient.saveDiograph(this.diograph.toObject())
132
- return
133
- }),
134
- )
135
- }
136
-
137
- return this.diograph
138
- }
139
- }
140
-
141
- export { DioryClient }
package/src/index.ts DELETED
@@ -1,3 +0,0 @@
1
- export { DioryClient } from './dioryClient'
2
- export { ConnectionClient } from './connectionClient'
3
- export { IDioryClient, IConnectionClient, IDataClient } from './types'
package/src/types.ts DELETED
@@ -1,49 +0,0 @@
1
- import {
2
- IConnectionObject,
3
- IDiosphere,
4
- IDiosphereObject,
5
- IRoom,
6
- IRoomObject,
7
- } from '@diory/diosphere-js'
8
- import { IDiographObject, IDiograph, IDiory, IDioryObject } from '@diograph/diograph'
9
-
10
- export interface IDataClient {
11
- type: string
12
- readTextItem(url: string): Promise<string>
13
- readItem(url: string): Promise<Buffer>
14
- readToStream(url: string): any
15
- exists(url: string): Promise<boolean>
16
- writeTextItem(url: string, fileContent: string): Promise<boolean>
17
- writeItem(url: string, fileContent: Buffer | string): Promise<boolean>
18
- deleteItem(url: string): Promise<boolean>
19
- deleteFolder(url: string): Promise<void>
20
- list(url: string): Promise<string[]>
21
- }
22
-
23
- export interface IConnectionClient {
24
- type: string
25
- client: IDataClient
26
- connection: IConnectionObject
27
- getDiosphere: () => Promise<IDiosphereObject>
28
- saveDiosphere: (diosphereObject: IDiosphereObject) => void
29
- getDiograph: () => Promise<IDiographObject>
30
- saveDiograph: (diographObject: IDiographObject) => void
31
- generateDiograph: () => Promise<IDiographObject>
32
- }
33
-
34
- export interface IDioryClient {
35
- dataClients: IDataClient[]
36
- connections: IConnectionObject[]
37
- diosphere: IDiosphere
38
- room?: IRoom
39
- diograph: IDiograph
40
- diory?: IDiory
41
- initialise: (connections: IConnectionObject[]) => Promise<IDioryClient>
42
- enterRoom: (roomObject: IRoomObject) => Promise<IRoom>
43
- focusDiory: (dioryObject: IDioryObject) => IDiory
44
- getDiosphere: () => Promise<IDiosphere>
45
- saveDiosphere: () => Promise<IDiosphere>
46
- getDiograph: () => Promise<IDiograph>
47
- saveDiograph: () => Promise<IDiograph>
48
- generateDiograph: () => Promise<IDiograph>
49
- }
@@ -1,23 +0,0 @@
1
- import { IConnectionObject } from '@diory/diosphere-js'
2
-
3
- import { IConnectionClient, IDataClient } from '../types'
4
- import { ConnectionClient } from '../connectionClient'
5
-
6
- function getDataClient(
7
- dataClients: IDataClient[],
8
- { client }: IConnectionObject,
9
- ): IDataClient | undefined {
10
- return dataClients.find(({ type }) => type === client)
11
- }
12
-
13
- export function getConnectionClients(
14
- dataClients: IDataClient[],
15
- connections: IConnectionObject[],
16
- ): IConnectionClient[] {
17
- return connections
18
- .filter(({ client }) => dataClients.some(({ type }) => type === client))
19
- .map((connection) => {
20
- const dataClient = getDataClient(dataClients, connection)
21
- return new ConnectionClient(dataClient!, connection)
22
- }) as IConnectionClient[]
23
- }
package/tsconfig.json DELETED
@@ -1,11 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "outDir": "dist",
4
- "declaration": true,
5
- "target": "es2017",
6
- "module": "commonjs",
7
- "strict": true,
8
- "forceConsistentCasingInFileNames": true
9
- },
10
- "exclude": ["node_modules", "dist"]
11
- }