@diory/client-js 0.2.0-rc2 → 0.2.0-rc4

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.
@@ -0,0 +1,44 @@
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 }}
@@ -0,0 +1,23 @@
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 ADDED
@@ -0,0 +1 @@
1
+ 20.10.0
package/jest.config.js ADDED
@@ -0,0 +1,6 @@
1
+ /** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
2
+ module.exports = {
3
+ preset: 'ts-jest',
4
+ testEnvironment: 'node',
5
+ testPathIgnorePatterns: ['dist', 'node_modules'],
6
+ }
package/package.json CHANGED
@@ -1,11 +1,8 @@
1
1
  {
2
2
  "name": "@diory/client-js",
3
- "version": "0.2.0-rc2",
3
+ "version": "0.2.0-rc4",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
- "files": [
7
- "dist"
8
- ],
9
6
  "author": "Olli-Pekka Pohjola <op@diory.me>, Jouni Alanen <jouni@diory.me>",
10
7
  "license": "MIT",
11
8
  "dependencies": {
@@ -0,0 +1,19 @@
1
+ describe('connectionClient', () => {
2
+ describe('construct()', () => {
3
+ it('should construct with dataClient and connection', () => {
4
+ expect(true).toEqual(true)
5
+ })
6
+ })
7
+
8
+ describe('getDiosphere()', () => {
9
+ it('should get diosphere', () => {
10
+ expect(true).toEqual(true)
11
+ })
12
+ })
13
+
14
+ describe('saveDiosphere()', () => {
15
+ it('should save diosphere object', () => {
16
+ expect(true).toEqual(true)
17
+ })
18
+ })
19
+ })
@@ -0,0 +1,52 @@
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, this.client)
48
+ return diograph.toObject()
49
+ }
50
+ }
51
+
52
+ export { ConnectionClient }
@@ -0,0 +1,19 @@
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
+ })
@@ -0,0 +1,141 @@
1
+ import { Diosphere, IConnectionObject, IDiosphere, IRoom, IRoomObject } from '@diory/diosphere-js'
2
+ import { Diograph, IDiograph, IDiory, IDioryObject } from '@diograph/diograph'
3
+
4
+ import { IDioryClient, IDataClient } 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 ADDED
@@ -0,0 +1,3 @@
1
+ export { DioryClient } from './dioryClient/dioryClient'
2
+ export { ConnectionClient } from './connectionClient/connectionClient'
3
+ export { IDioryClient, IConnectionClient, IDataClient, IFileType, IMetadata } from './types'
package/src/types.ts ADDED
@@ -0,0 +1,64 @@
1
+ import {
2
+ IConnectionObject,
3
+ IDiosphere,
4
+ IDiosphereObject,
5
+ IRoom,
6
+ IRoomObject,
7
+ } from '@diory/diosphere-js'
8
+ import { IDiograph, IDiographObject, IDiory, IDioryObject } from '@diograph/diograph'
9
+
10
+ export interface IMetadata {
11
+ name: string
12
+ created?: string
13
+ modified?: string
14
+ }
15
+
16
+ export interface IFileType {
17
+ ext?: string
18
+ mime?: string
19
+ }
20
+
21
+ export interface IDataClient {
22
+ type: string
23
+ readTextItem(url: string): Promise<string>
24
+ readItem(url: string): Promise<Buffer>
25
+ readToStream(url: string): any
26
+ exists(url: string): Promise<boolean>
27
+ writeTextItem(url: string, fileContent: string): Promise<boolean>
28
+ writeItem(url: string, fileContent: Buffer | string): Promise<boolean>
29
+ deleteItem(url: string): Promise<boolean>
30
+ deleteFolder(url: string): Promise<void>
31
+ list(url: string): Promise<string[]>
32
+ getFileNames(url: string): Promise<string[]>
33
+ getFolderNames(url: string): Promise<string[]>
34
+ getMetadata(url: string): IMetadata
35
+ getFileType(url: string): Promise<IFileType>
36
+ }
37
+
38
+ export interface IConnectionClient {
39
+ type: string
40
+ client: IDataClient
41
+ connection: IConnectionObject
42
+ getDiosphere: () => Promise<IDiosphereObject>
43
+ saveDiosphere: (diosphereObject: IDiosphereObject) => void
44
+ getDiograph: () => Promise<IDiographObject>
45
+ saveDiograph: (diographObject: IDiographObject) => void
46
+ generateDiograph: () => Promise<IDiographObject>
47
+ }
48
+
49
+ export interface IDioryClient {
50
+ dataClients: IDataClient[]
51
+ connections: IConnectionObject[]
52
+ diosphere: IDiosphere
53
+ room?: IRoom
54
+ diograph: IDiograph
55
+ diory?: IDiory
56
+ initialise: (connections: IConnectionObject[]) => Promise<IDioryClient>
57
+ enterRoom: (roomObject: IRoomObject) => Promise<IRoom>
58
+ focusDiory: (dioryObject: IDioryObject) => IDiory
59
+ getDiosphere: () => Promise<IDiosphere>
60
+ saveDiosphere: () => Promise<IDiosphere>
61
+ getDiograph: () => Promise<IDiograph>
62
+ saveDiograph: () => Promise<IDiograph>
63
+ generateDiograph: () => Promise<IDiograph>
64
+ }
@@ -0,0 +1,23 @@
1
+ import { IConnectionObject } from '@diory/diosphere-js'
2
+
3
+ import { ConnectionClient } from '../connectionClient/connectionClient'
4
+ import { IConnectionClient, IDataClient } from '../types'
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 ADDED
@@ -0,0 +1,11 @@
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
+ }