libshv-js 3.16.1 → 3.20.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/dist/access.d.ts +69 -0
- package/dist/access.js +98 -0
- package/dist/chainpack.d.ts +39 -0
- package/{src/chainpack.ts → dist/chainpack.js} +120 -218
- package/dist/cpcontext.d.ts +18 -0
- package/{src/cpcontext.ts → dist/cpcontext.js} +18 -27
- package/dist/cpon.d.ts +55 -0
- package/{src/cpon.ts → dist/cpon.js} +192 -292
- package/dist/index.d.ts +10 -0
- package/dist/index.js +26 -0
- package/dist/json.d.ts +3 -0
- package/{src/json.ts → dist/json.js} +31 -49
- package/dist/rpcmessage.d.ts +285 -0
- package/dist/rpcmessage.js +111 -0
- package/dist/rpcvalue.d.ts +56 -0
- package/dist/rpcvalue.js +100 -0
- package/dist/vue-shv.d.ts +91 -0
- package/{src/vue-shv.ts → dist/vue-shv.js} +104 -164
- package/dist/ws-client.d.ts +232 -0
- package/dist/ws-client.js +586 -0
- package/dist/zod.d.ts +30 -0
- package/dist/zod.js +112 -0
- package/package.json +21 -13
- package/.github/workflows/check-version-bump.yml +0 -22
- package/.github/workflows/lint.yml +0 -33
- package/.github/workflows/publish.yml +0 -24
- package/.github/workflows/test.yml +0 -31
- package/eslint.config.js +0 -103
- package/examples/websocketosaurus.html +0 -44
- package/examples/websocketosaurus.js +0 -94
- package/src/access.ts +0 -103
- package/src/rpcmessage.ts +0 -91
- package/src/rpcvalue.ts +0 -147
- package/src/ws-client.ts +0 -708
- package/src/zod.ts +0 -95
- package/test.ts +0 -110
- package/test_json.ts +0 -44
- package/test_zod.ts +0 -24
- package/tsconfig.json +0 -108
package/dist/zod.js
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.withMeta = exports.rpcvalue = exports.list = exports.blob = exports.decimal = exports.double = exports.uint = exports.recmap = exports.metamap = exports.imap = exports.map = void 0;
|
|
18
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
19
|
+
const v4_1 = require("zod/v4");
|
|
20
|
+
const rpcvalue_1 = require("./rpcvalue");
|
|
21
|
+
const implMakeMapParser = (mapValidator, _mapBrand, mapName, objectParser) => v4_1.z.custom().check(ctx => {
|
|
22
|
+
if (!mapValidator(ctx.value)) {
|
|
23
|
+
ctx.issues.push({
|
|
24
|
+
expected: 'map',
|
|
25
|
+
code: 'invalid_type',
|
|
26
|
+
input: ctx.value,
|
|
27
|
+
message: `Invalid input: expected ${mapName}, received ${(0, rpcvalue_1.typeName)(ctx.value)}`,
|
|
28
|
+
});
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
// For record, Zod finds out map brand, and calls the record's value parser with the value. There's no way to detect
|
|
32
|
+
// it, because Zod does not supply the parser with the key. To prevent this, remove the key before passing the value
|
|
33
|
+
// to Zod. This unfortunately means that we need to copy the whole object. :/
|
|
34
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
35
|
+
const { [rpcvalue_1.shvMapType]: zodMustNotHaveThis, ...rest } = { ...ctx.value };
|
|
36
|
+
const parsedObject = objectParser.safeParse(rest);
|
|
37
|
+
if (!parsedObject.success) {
|
|
38
|
+
ctx.issues = parsedObject.error.issues;
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
const map = (schema) => implMakeMapParser(rpcvalue_1.isShvMap, 'map', 'ShvMap', v4_1.z.object(schema));
|
|
42
|
+
exports.map = map;
|
|
43
|
+
const imap = (schema) => implMakeMapParser(rpcvalue_1.isIMap, 'imap', 'IMap', v4_1.z.object(schema));
|
|
44
|
+
exports.imap = imap;
|
|
45
|
+
const metamap = (schema) => implMakeMapParser(rpcvalue_1.isMetaMap, 'metamap', 'MetaMap', v4_1.z.object(schema));
|
|
46
|
+
exports.metamap = metamap;
|
|
47
|
+
const recmap = (schema) => implMakeMapParser(val => (0, rpcvalue_1.isShvMap)(val) || (0, rpcvalue_1.isIMap)(val), 'map', 'ShvMap', v4_1.z.record(v4_1.z.any(), schema));
|
|
48
|
+
exports.recmap = recmap;
|
|
49
|
+
const uint = () => v4_1.z.instanceof((rpcvalue_1.UInt));
|
|
50
|
+
exports.uint = uint;
|
|
51
|
+
const double = () => v4_1.z.instanceof(rpcvalue_1.Double);
|
|
52
|
+
exports.double = double;
|
|
53
|
+
const decimal = () => v4_1.z.instanceof(rpcvalue_1.Decimal);
|
|
54
|
+
exports.decimal = decimal;
|
|
55
|
+
const blob = () => v4_1.z.instanceof(ArrayBuffer);
|
|
56
|
+
exports.blob = blob;
|
|
57
|
+
const list = () => v4_1.z.array(v4_1.z.lazy(exports.rpcvalue));
|
|
58
|
+
exports.list = list;
|
|
59
|
+
const withMetaInstanceParser = v4_1.z.instanceof(rpcvalue_1.RpcValueWithMetaData);
|
|
60
|
+
const rpcvalue = () => v4_1.z.lazy(() => v4_1.z.union([
|
|
61
|
+
v4_1.z.undefined(),
|
|
62
|
+
v4_1.z.boolean(),
|
|
63
|
+
v4_1.z.number(),
|
|
64
|
+
(0, exports.uint)(),
|
|
65
|
+
(0, exports.double)(),
|
|
66
|
+
(0, exports.decimal)(),
|
|
67
|
+
(0, exports.blob)(),
|
|
68
|
+
v4_1.z.string(),
|
|
69
|
+
v4_1.z.date(),
|
|
70
|
+
(0, exports.list)(),
|
|
71
|
+
(0, exports.recmap)((0, exports.rpcvalue)()),
|
|
72
|
+
withMetaInstanceParser,
|
|
73
|
+
]));
|
|
74
|
+
exports.rpcvalue = rpcvalue;
|
|
75
|
+
const withMeta = (metaParser, valueParser) => v4_1.z.custom().check(ctx => {
|
|
76
|
+
if (!withMetaInstanceParser.safeParse(ctx.value).success) {
|
|
77
|
+
ctx.issues.push({
|
|
78
|
+
expected: 'map',
|
|
79
|
+
code: 'invalid_type',
|
|
80
|
+
input: ctx.value,
|
|
81
|
+
message: 'Invalid input: expected a value with metadata, got a value with no metadata}',
|
|
82
|
+
});
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
const parsedMeta = metaParser.safeParse(ctx.value.meta);
|
|
86
|
+
if (!parsedMeta.success) {
|
|
87
|
+
ctx.issues = [
|
|
88
|
+
{
|
|
89
|
+
expected: 'map',
|
|
90
|
+
code: 'invalid_type',
|
|
91
|
+
input: ctx.value,
|
|
92
|
+
message: 'Wrong RpcValueWithMetaData meta',
|
|
93
|
+
},
|
|
94
|
+
...parsedMeta.error.issues,
|
|
95
|
+
];
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
const parsedValue = valueParser.safeParse(ctx.value.value);
|
|
99
|
+
if (!parsedValue.success) {
|
|
100
|
+
ctx.issues = [
|
|
101
|
+
{
|
|
102
|
+
expected: 'map',
|
|
103
|
+
code: 'invalid_type',
|
|
104
|
+
input: ctx.value,
|
|
105
|
+
message: 'Wrong RpcValueWithMetaData value',
|
|
106
|
+
},
|
|
107
|
+
...parsedValue.error.issues,
|
|
108
|
+
];
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
exports.withMeta = withMeta;
|
|
112
|
+
__exportStar(require("zod/v4"), exports);
|
package/package.json
CHANGED
|
@@ -1,12 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "libshv-js",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.20.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": "
|
|
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
|
-
"
|
|
22
|
-
"./
|
|
23
|
-
"./
|
|
24
|
-
"./
|
|
25
|
-
"./
|
|
26
|
-
"./
|
|
27
|
-
"./
|
|
28
|
-
"./
|
|
29
|
-
"./
|
|
30
|
-
"./
|
|
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
|
-
};
|