libshv-js 3.16.0 → 3.17.0

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.
package/package.json CHANGED
@@ -1,12 +1,19 @@
1
1
  {
2
2
  "name": "libshv-js",
3
- "version": "3.16.0",
3
+ "version": "3.17.0",
4
4
  "description": "Typescript implementation of libshv",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "files": [
8
+ "dist"
9
+ ],
5
10
  "scripts": {
6
- "test": "echo \"Error: no test specified\" && exit 1",
11
+ "test": "tsc -p tsconfig.tests.json && node dist-tests/tests/test.js && node dist-tests/tests/test_json.js && node dist-tests/tests/test_zod.js",
12
+ "test:ci": "tsc -p tsconfig.tests.json && node dist-tests/tests/test.js && node dist-tests/tests/test_json.js && node dist-tests/tests/test_zod.js",
7
13
  "lint": "eslint --format unix src/",
8
14
  "fix": "npm run lint -- --fix",
9
- "typecheck": "tsc --noEmit"
15
+ "typecheck": "tsc -p tsconfig.tests.json --noEmit",
16
+ "build": "tsc"
10
17
  },
11
18
  "author": "Elektroline",
12
19
  "repository": {
@@ -18,16 +25,17 @@
18
25
  },
19
26
  "homepage": "https://github.com/silicon-heaven/libshv-js",
20
27
  "exports": {
21
- "./access.ts": "./src/access.ts",
22
- "./chainpack.ts": "./src/chainpack.ts",
23
- "./cpcontext.ts": "./src/cpcontext.ts",
24
- "./cpon.ts": "./src/cpon.ts",
25
- "./json.ts": "./src/json.ts",
26
- "./rpcmessage.ts": "./src/rpcmessage.ts",
27
- "./rpcvalue.ts": "./src/rpcvalue.ts",
28
- "./vue-shv.ts": "./src/vue-shv.ts",
29
- "./ws-client.ts": "./src/ws-client.ts",
30
- "./zod.ts": "./src/zod.ts"
28
+ ".": "./dist/index.js",
29
+ "./access": "./dist/access.js",
30
+ "./chainpack": "./dist/chainpack.js",
31
+ "./cpcontext": "./dist/cpcontext.js",
32
+ "./cpon": "./dist/cpon.js",
33
+ "./json": "./dist/json.js",
34
+ "./rpcmessage": "./dist/rpcmessage.js",
35
+ "./rpcvalue": "./dist/rpcvalue.js",
36
+ "./vue-shv": "./dist/vue-shv.js",
37
+ "./ws-client": "./dist/ws-client.js",
38
+ "./zod": "./dist/zod.js"
31
39
  },
32
40
  "dependencies": {
33
41
  "js-pkce": "^2.0.0",
@@ -1,22 +0,0 @@
1
- # vim: sw=2
2
- name: Misc
3
-
4
- concurrency:
5
- group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
6
- cancel-in-progress: true
7
-
8
- on:
9
- push:
10
- branches: [ "main" ]
11
- pull_request:
12
- branches: [ "main" ]
13
-
14
- jobs:
15
- check-version-bump:
16
- name: Check version bump
17
- runs-on: ubuntu-latest
18
- steps:
19
- - uses: actions/checkout@v4
20
- - name: Check if version bumped
21
- uses: del-systems/check-if-version-bumped@v2
22
-
@@ -1,33 +0,0 @@
1
- # vim: sw=2
2
- name: Lint
3
-
4
- concurrency:
5
- group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
6
- cancel-in-progress: true
7
-
8
- on:
9
- push:
10
- branches: [ "main" ]
11
- pull_request:
12
- branches: [ "main" ]
13
-
14
- jobs:
15
- type-check:
16
- name: Type check
17
- runs-on: ubuntu-latest
18
- steps:
19
- - uses: actions/checkout@v4
20
- - name: Install tsc
21
- run: npm install
22
- - name: Run tsc
23
- run: npx tsc --noEmit
24
-
25
- xo:
26
- name: xo
27
- runs-on: ubuntu-latest
28
- steps:
29
- - uses: actions/checkout@v4
30
- - name: Install tsc
31
- run: npm install
32
- - name: Run linters
33
- run: npm run lint
@@ -1,24 +0,0 @@
1
- # vim: sw=2
2
- name: Publish
3
-
4
- on:
5
- push:
6
- branches: [ "main" ]
7
-
8
- jobs:
9
- test:
10
- name: Publish new version
11
- runs-on: ubuntu-latest
12
- steps:
13
- - uses: actions/checkout@v4
14
-
15
- - name: Setup node
16
- uses: actions/setup-node@v4
17
- with:
18
- node-version: '22.x'
19
- registry-url: 'https://registry.npmjs.org'
20
-
21
- - name: Publish
22
- run: npm publish
23
- env:
24
- NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
@@ -1,31 +0,0 @@
1
- # vim: sw=2
2
- name: Test
3
-
4
- concurrency:
5
- group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
6
- cancel-in-progress: true
7
-
8
- on:
9
- push:
10
- branches: [ "main" ]
11
- pull_request:
12
- branches: [ "main" ]
13
-
14
- jobs:
15
- test:
16
- name: CPON/Chainpack conversions
17
- runs-on: ubuntu-latest
18
- steps:
19
- - uses: actions/checkout@v4
20
-
21
- - name: Install dependencies
22
- run: npm install
23
-
24
- - name: Compile
25
- run: npx tsc
26
-
27
- - name: Run tests
28
- run: |
29
- node test.js
30
- node test_json.js
31
- node test_zod.js
package/eslint.config.js DELETED
@@ -1,103 +0,0 @@
1
- import xo from "eslint-config-xo";
2
- import typescriptEslintParser from "@typescript-eslint/parser";
3
- import eslint from '@eslint/js';
4
- import tseslint from 'typescript-eslint';
5
- import unicornPlugin from 'eslint-plugin-unicorn';
6
-
7
- export default tseslint.config(
8
- eslint.configs.recommended,
9
- eslint.configs.recommended,
10
- ...tseslint.configs.recommendedTypeChecked,
11
- ...tseslint.configs.stylisticTypeChecked,
12
- unicornPlugin.configs.recommended,
13
- ...xo,
14
- {
15
- languageOptions: {
16
- parser: typescriptEslintParser,
17
- parserOptions: {
18
- project: "./tsconfig.json",
19
- },
20
- },
21
- rules: {
22
- "@stylistic/indent": ["error", 4],
23
- "@stylistic/indent-binary-ops": ["error", 4],
24
- "@stylistic/max-len": ["off"],
25
- "@stylistic/multiline-ternary": ["off"],
26
- "@stylistic/function-paren-newline": ["off"],
27
- "@typescript-eslint/no-misused-promises": ["error", {
28
- checksVoidReturn: false
29
- }],
30
- "@typescript-eslint/no-unsafe-assignment": ["off"],
31
- "@typescript-eslint/no-unsafe-call": ["off"],
32
- "@typescript-eslint/no-unsafe-enum-comparison": ["off"],
33
- "@typescript-eslint/consistent-type-definitions": ["error",
34
- "type"
35
- ],
36
- "@typescript-eslint/array-type": ["error", {
37
- default: "array-simple"
38
- }],
39
- "@typescript-eslint/naming-convention": ["error",
40
- {
41
- "selector": "variableLike",
42
- "format": ["camelCase"]
43
- },
44
- {
45
- "selector": "variableLike",
46
- "format": null,
47
- "modifiers": ["unused"]
48
- },
49
- {
50
- "format": ["camelCase", "UPPER_CASE"],
51
- "selector": "variable",
52
- "modifiers": ["const"]
53
- },
54
- {
55
- "format": ["PascalCase"],
56
- "selector": "variable",
57
- "modifiers": ["const"],
58
- "filter": "Validation$|Zod$"
59
- }
60
- ],
61
- "@typescript-eslint/prefer-promise-reject-errors": "off",
62
- "@typescript-eslint/promise-function-async": "off",
63
- "@typescript-eslint/strict-boolean-expressions": ["error",
64
- {
65
- "allowString": false,
66
- "allowNumber": false,
67
- "allowNullableObject": false
68
- }
69
- ],
70
- "@typescript-eslint/triple-slash-reference": "off",
71
- "capitalized-comments": "off",
72
- "@stylistic/object-curly-newline": ["error", {
73
- "ImportDeclaration": "never"
74
- }],
75
- "n/file-extension-in-import": "off",
76
- "promise-function-async": "off",
77
- "camelcase": "off",
78
- "default-case": "off",
79
- "import/extensions": "off",
80
- "import/no-unassigned-import": "off",
81
- "no-dupe-class-members": "off",
82
- "no-negated-condition": "off",
83
- "no-redeclare": "off",
84
- "no-unused-vars": "off",
85
- "no-useless-constructor": "off",
86
- "no-void": ["error", {
87
- allowAsStatement: true
88
- }],
89
- "no-warning-comments": "off",
90
- "prefer-promise-reject-errors": "off",
91
- "unicorn/consistent-function-scoping": "off",
92
- "unicorn/explicit-length-check": "off",
93
- "unicorn/filename-case": "off",
94
- "unicorn/no-negated-condition": "off",
95
- "unicorn/no-useless-undefined": ["error", {
96
- checkArguments: false
97
- }],
98
- "unicorn/prefer-top-level-await": "off",
99
- "unicorn/switch-case-braces": "off",
100
- "unicorn/prevent-abbreviations": "off",
101
- }
102
- }
103
- );
@@ -1,44 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <title>WebSocketoSaurus</title>
5
- <meta charset="utf-8">
6
- <script type="text/javascript" src="../rpcvalue.js"></script>
7
- <script type="text/javascript" src="../cpcontext.js"></script>
8
- <script type="text/javascript" src="../chainpack.js"></script>
9
- <script type="text/javascript" src="../cpon.js"></script>
10
- <script type="text/javascript" src="../bint.js"></script>
11
- <script type="text/javascript" src="../rpcmessage.js"></script>
12
- <script type="text/javascript" src="../ws_client.js"></script>
13
- </head>
14
- <body>
15
- <h1>WebSocketoSaurus</h1>
16
- <h2>WebSocket Shv Broker test Client</h1>
17
- <p>
18
- Uri <input type="text" id="edUri" style="width:50em;"/>
19
- </p>
20
- <p>
21
- user <input type="text" id="edUser"/>
22
- password <input type="password" id="edPassword"/>
23
- </p>
24
- <p>
25
- <button onClick="initWebSocket(true);">Connect ChainPack</button>
26
- <button onClick="initWebSocket(false);">Connect Cpon</button>
27
- <button onClick="stopWebSocket();">Disconnect</button>
28
- </p>
29
- <p>
30
- <input type="text" id="edShvPath" onkeydown="if(event.keyCode==13)sendMessage();"/>
31
- <input type="text" id="edMethod" onkeydown="if(event.keyCode==13)sendMessage();"/>
32
- <input type="text" id="edParams" onkeydown="if(event.keyCode==13)sendMessage();"/>
33
- <button onClick="sendMessage();">Send</button>
34
- </p>
35
- <p>
36
- <textarea id="txtResult" style="width:50em;height:100px;"></textarea>
37
- </p>
38
- <p>
39
- <textarea id="txtLog" style="width:50em;height:200px;"></textarea>
40
- </p>
41
-
42
- <script type="text/javascript" src="websocketosaurus.js" ></script>
43
- </body>
44
- </html>
@@ -1,94 +0,0 @@
1
- //document.getElementById("edUri").value = "wss://nirvana.elektroline.cz:3778";
2
- document.getElementById("edUri").value = "wss://localhost:3778";
3
- document.getElementById("edUser").value = "user";
4
- document.getElementById("edPassword").value = "pwd";
5
-
6
- document.getElementById("edShvPath").value = ".broker/app";
7
- document.getElementById("edMethod").value = "echo";
8
- document.getElementById("edParams").value = "42";
9
-
10
- let txtLog = document.getElementById("txtLog");
11
-
12
- const debug = (...args) => {
13
- let line = "";
14
- for (let i = 0; i < args.length; i++) {
15
- if (i > 0) {
16
- line += " ";
17
- }
18
- line += args[i];
19
- }
20
- txtLog.value += line + "\n";
21
- txtLog.scrollTop = txtLog.scrollHeight;
22
- };
23
-
24
- let ws_client;
25
-
26
- const sendMessage = () => {
27
- if (ws_client && ws_client.websocket.readyState == 1 ) {
28
- const shv_path = document.getElementById("edShvPath").value;
29
- const method = document.getElementById("edMethod").value;
30
- const params = document.getElementById("edParams").value;
31
-
32
- ws_client.callRpcMethod(shv_path, method, params).then((rpc_msg) => {
33
- const txtResult = document.getElementById("txtResult");
34
- // result == 2
35
- // error == 3
36
- const err = rpc_msg.error();
37
- if (err) {
38
- txtResult.value = err.toString();
39
- txtResult.style.background = "salmon";
40
- } else {
41
- const result = rpc_msg.result();
42
- txtResult.value = result.toString();
43
- txtResult.style.background = "";
44
- }
45
- });
46
- }
47
- }
48
-
49
- const initWebSocket = (use_chainpack) => {
50
- const wsUri = document.getElementById("edUri").value;
51
- const user = document.getElementById("edUser").value;
52
- const password = document.getElementById("edPassword").value;
53
-
54
-
55
- const isUseCpon = !use_chainpack;
56
- const txtLog = document.getElementById("txtLog");
57
- txtLog.value = `Connection to shvbroker using ${isUseCpon? "Cpon": "ChainPack"}serialization.`;
58
- try {
59
- ws_client = new WsClient({
60
- user,
61
- password,
62
- wsUri,
63
- logDebug: debug,
64
- onRequest: (rpc_msg) => {
65
- const method = rpc_msg.method().asString();
66
- const resp = new RpcMessage();
67
- if(method == "dir") {
68
- resp.setResult(["ls", "dir", "appName"]);
69
- }
70
- else if(method == "ls") {
71
- resp.setResult([]);
72
- }
73
- else if(method == "appName") {
74
- resp.setResult("websocketosaurus");
75
- }
76
- else {
77
- debug(`ERROR: Method: ${method} is not defined.`);
78
- resp.setError(`Method: ${method} is not defined.`);
79
- }
80
- resp.setRequestId(rpc_msg.requestId());
81
- resp.setCallerIds(rpc_msg.callerIds());
82
- ws_client.sendRpcMessage(resp);
83
- }
84
- });
85
- } catch (exception) {
86
- debug(`EXCEPTION: ${exception}`);
87
- }
88
- };
89
-
90
- const stopWebSocket = () => {
91
- if (websocket) {
92
- websocket.close();
93
- }
94
- };
package/src/access.ts DELETED
@@ -1,103 +0,0 @@
1
- enum Role {
2
- Browse = 'bws',
3
- Read = 'rd',
4
- Write = 'wr',
5
- Command = 'cmd',
6
- Config = 'cfg',
7
- Service = 'srv',
8
- SuperService = 'ssrv',
9
- Devel = 'dev',
10
- Admin = 'su',
11
- }
12
-
13
- enum AccessLevel {
14
- None = 0,
15
-
16
- Browse = 1,
17
- Browse1,
18
- Browse2,
19
- Browse3,
20
- Browse4,
21
- Browse5,
22
- Browse6,
23
-
24
- Read = 8,
25
- Read1,
26
- Read2,
27
- Read3,
28
- Read4,
29
- Read5,
30
- Read6,
31
- Read7,
32
-
33
- Write = 16,
34
- Write1,
35
- Write2,
36
- Write3,
37
- Write4,
38
- Write5,
39
- Write6,
40
- Write7,
41
-
42
- Command = 24,
43
- Command1,
44
- Command2,
45
- Command3,
46
- Command4,
47
- Command5,
48
- Command6,
49
- Command7,
50
-
51
- Config = 32,
52
- Config1,
53
- Config2,
54
- Config3,
55
- Config4,
56
- Config5,
57
- Config6,
58
- Config7,
59
-
60
- Service = 40,
61
- Service1,
62
- Service2,
63
- Service3,
64
- Service4,
65
- Service5,
66
- Service6,
67
- Service7,
68
-
69
- SuperService = 48,
70
- SuperService1,
71
- SuperService2,
72
- SuperService3,
73
- SuperService4,
74
- SuperService5,
75
- SuperService6,
76
- SuperService7,
77
-
78
- Devel = 56,
79
- Devel1,
80
- Devel2,
81
- Devel3,
82
- Devel4,
83
- Devel5,
84
- Devel6,
85
- Devel7,
86
-
87
- Admin = 63,
88
- }
89
-
90
- export const accessLevelFromAccessString = (s: string): AccessLevel => {
91
- switch (s as unknown) {
92
- case Role.Browse: return AccessLevel.Browse;
93
- case Role.Read: return AccessLevel.Read;
94
- case Role.Write: return AccessLevel.Write;
95
- case Role.Command: return AccessLevel.Command;
96
- case Role.Config: return AccessLevel.Config;
97
- case Role.Service: return AccessLevel.Service;
98
- case Role.SuperService: return AccessLevel.SuperService;
99
- case Role.Devel: return AccessLevel.Devel;
100
- case Role.Admin: return AccessLevel.Admin;
101
- default: throw new Error(`unknown access grant string: ${s}`);
102
- }
103
- };