Skip to content

Commit c6c0ca5

Browse files
committed
chore: correct code standard
1 parent d0ce540 commit c6c0ca5

File tree

8 files changed

+2346
-135
lines changed

8 files changed

+2346
-135
lines changed

.editorconfig

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# EditorConfig is awesome: https://EditorConfig.org
2+
3+
# top-most EditorConfig file
4+
root = true
5+
6+
[*]
7+
charset = utf-8
8+
indent_style = space
9+
indent_size = 2
10+
end_of_line = lf
11+
trim_trailing_whitespace = true
12+
insert_final_newline = true
13+
14+
[*.md]
15+
trim_trailing_whitespace = false
16+
indent_size = 4

.eslintrc.cjs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/* eslint-disable sort-keys */
2+
module.exports = {
3+
root: true,
4+
env: {
5+
es6: true,
6+
node: true,
7+
},
8+
plugins: ['kuzzle'],
9+
extends: ['plugin:kuzzle/default', 'plugin:kuzzle/typescript'],
10+
};

.eslintrc.js

Lines changed: 0 additions & 61 deletions
This file was deleted.

.prettierrc

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
{
2-
"semi": true,
3-
"singleQuote": true
4-
}
2+
"trailingComma": "all",
3+
"singleQuote": true,
4+
"printWidth": 100,
5+
"tabWidth": 2,
6+
"semi": true
7+
}

index.ts

Lines changed: 38 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,46 @@
11
import { Http, Kuzzle, KuzzleAbstractProtocol, WebSocket } from 'kuzzle-sdk';
2-
import _Vue from 'vue';
2+
import _Vue from 'vue';
33

4-
const LS_KEY = 'kuzzle-backend'
5-
const GLOBAL_NAME = 'kuzzleBackend'
4+
const LS_KEY = 'kuzzle-backend';
5+
const GLOBAL_NAME = 'kuzzleBackend';
66

77
export enum KuzzleProtocol {
88
HTTP = 'http',
9-
WEBSOCKET = 'websocket'
9+
WEBSOCKET = 'websocket',
1010
}
1111
export interface Backend {
1212
host: string;
13-
protocol: KuzzleProtocol
13+
protocol: KuzzleProtocol;
1414
options: {
1515
port: number;
16-
sslConnection: boolean,
17-
}
16+
sslConnection: boolean;
17+
};
1818
}
1919

2020
export interface Backends {
21-
[name: string]: Backend
21+
[name: string]: Backend;
2222
}
2323

2424
export function getBackendFromConf(backendsConfig: Backends) {
25+
/* eslint-disable sort-keys */
2526
const backends: Backends = {
2627
default: {
2728
host: process.env.VUE_APP_BACKEND_HOST || 'localhost',
2829
protocol: (process.env.VUE_APP_BACKEND_PROTO as KuzzleProtocol) || KuzzleProtocol.WEBSOCKET,
2930
options: {
3031
port: parseInt(process.env.VUE_APP_BACKEND_PORT || '7512'),
31-
sslConnection: process.env.VUE_APP_BACKEND_SSL === 'true' || false
32-
}
32+
sslConnection: process.env.VUE_APP_BACKEND_SSL === 'true' || false,
33+
},
3334
},
34-
...backendsConfig
35-
}
35+
...backendsConfig,
36+
};
37+
/* eslint-enable sort-keys */
3638

37-
const backendName: string = process.env.VUE_APP_BACKEND
38-
? process.env.VUE_APP_BACKEND
39-
: 'default';
39+
const backendName: string = process.env.VUE_APP_BACKEND ? process.env.VUE_APP_BACKEND : 'default';
4040

41-
if (!backends[backendName]) {
42-
throw new Error(`Unable to find backend ${backendName} in configuration.`);
43-
}
41+
if (!backends[backendName]) {
42+
throw new Error(`Unable to find backend ${backendName} in configuration.`);
43+
}
4444

4545
return backends[backendName] ? backends[backendName] : null;
4646
}
@@ -50,37 +50,42 @@ export function getBackendFromLocalStorage() {
5050
if (!lsItem) {
5151
return null;
5252
}
53-
const backend = JSON.parse(lsItem)
53+
const backend = JSON.parse(lsItem);
5454

5555
if (typeof backend !== 'object') {
56-
throw new Error(`Item found in localStorage (${LS_KEY}) is malformed. Expected an object, found ${backend}`)
56+
throw new Error(
57+
`Item found in localStorage (${LS_KEY}) is malformed. Expected an object, found ${backend}`,
58+
);
5759
}
5860

5961
return backend;
6062
}
6163

6264
export function getBackendFromWindow() {
6365
if (!(window as any)[GLOBAL_NAME]) {
64-
return null
66+
return null;
6567
}
6668

67-
const backend = JSON.parse((window as any)[GLOBAL_NAME])
69+
const backend = JSON.parse((window as any)[GLOBAL_NAME]);
6870

6971
if (typeof backend !== 'object') {
70-
throw new Error(`Item found in global (${GLOBAL_NAME}) is malformed. Expected an object, found ${backend}`)
72+
throw new Error(
73+
`Item found in global (${GLOBAL_NAME}) is malformed. Expected an object, found ${backend}`,
74+
);
7175
}
7276

7377
return backend;
7478
}
7579

7680
/**
7781
* Instantiates the Kuzzle SDK by resolving the backend from the given config.
78-
*
79-
* @param backendsConfig
80-
* @param sdkOptions
82+
*
83+
* @param backendsConfig
84+
* @param sdkOptions
8185
*/
8286
export const instantiateKuzzleSDK = (backendsConfig: Backends, sdkOptions: any): Kuzzle => {
83-
const backend:Backend | null = getBackendFromLocalStorage() || getBackendFromWindow() || getBackendFromConf(backendsConfig)
87+
const backend: Backend | null =
88+
getBackendFromLocalStorage() || getBackendFromWindow() || getBackendFromConf(backendsConfig);
8489

8590
if (!backend) {
8691
throw new Error('No backend resolved.');
@@ -96,21 +101,21 @@ export const instantiateKuzzleSDK = (backendsConfig: Backends, sdkOptions: any):
96101
const protocolFactory = (backend: Backend): KuzzleAbstractProtocol => {
97102
switch (backend.protocol) {
98103
case KuzzleProtocol.HTTP:
99-
return new Http(backend.host, backend.options)
100-
104+
return new Http(backend.host, backend.options);
105+
101106
case KuzzleProtocol.WEBSOCKET:
102107
default:
103-
return new WebSocket(backend.host, backend.options)
108+
return new WebSocket(backend.host, backend.options);
104109
}
105-
}
110+
};
106111

107112
/**
108113
* The VueKuzzle plugin. Makes the Kuzzle SDK available in Vue components as
109114
* `this.$kuzzle`.
110-
*
115+
*
111116
* @param Vue The Vue application to apply the plugin to
112117
* @param options Options passed to the Kuzzle SDK constructor
113-
*
118+
*
114119
* @see https://docs.kuzzle.io/sdk/js/7/core-classes/kuzzle/constructor/#options
115120
*/
116121
export function VueKuzzle(Vue: typeof _Vue, options: any) {

0 commit comments

Comments
 (0)