@boristype/ws-client 0.1.0-alpha.5 → 0.1.0-alpha.6
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/README.md +93 -2
- package/build/client.d.ts +3 -1
- package/build/client.d.ts.map +1 -1
- package/build/client.js +3 -1
- package/build/client.js.map +1 -1
- package/build/evaluator.d.ts +8 -0
- package/build/evaluator.d.ts.map +1 -1
- package/build/evaluator.js +10 -0
- package/build/evaluator.js.map +1 -1
- package/build/hcm/api.d.ts +3 -2
- package/build/hcm/api.d.ts.map +1 -1
- package/build/hcm/api.js +1 -1
- package/build/hcm/api.js.map +1 -1
- package/build/hcm/xquery.d.ts +4 -3
- package/build/hcm/xquery.d.ts.map +1 -1
- package/build/hcm/xquery.js +3 -28
- package/build/hcm/xquery.js.map +1 -1
- package/build/index.d.ts +3 -1
- package/build/index.d.ts.map +1 -1
- package/build/index.js +1 -0
- package/build/index.js.map +1 -1
- package/build/soap-utils.d.ts +8 -14
- package/build/soap-utils.d.ts.map +1 -1
- package/build/soap-utils.js +205 -169
- package/build/soap-utils.js.map +1 -1
- package/build/types.d.ts +9 -0
- package/build/types.d.ts.map +1 -1
- package/build/xquery.d.ts +28 -0
- package/build/xquery.d.ts.map +1 -0
- package/build/xquery.js +151 -0
- package/build/xquery.js.map +1 -0
- package/package.json +4 -2
- package/resources/xquery.bs +94 -24
package/build/xquery.js
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
const template = readFileSync(new URL("../resources/xquery.bs", import.meta.url), "utf8");
|
|
3
|
+
const maxBytes = 262144;
|
|
4
|
+
const maxDepth = 32;
|
|
5
|
+
const maxValues = 10000;
|
|
6
|
+
function invalid(message) {
|
|
7
|
+
throw new Error(`Invalid XQuery response: ${message}`);
|
|
8
|
+
}
|
|
9
|
+
function record(value, keys) {
|
|
10
|
+
if (value === null || typeof value !== "object" || Array.isArray(value))
|
|
11
|
+
return false;
|
|
12
|
+
if (Object.getPrototypeOf(value) !== Object.prototype && Object.getPrototypeOf(value) !== null)
|
|
13
|
+
return false;
|
|
14
|
+
const actual = Reflect.ownKeys(value);
|
|
15
|
+
return (actual.length === keys.length &&
|
|
16
|
+
keys.every((key) => {
|
|
17
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
18
|
+
return descriptor?.enumerable === true && "value" in descriptor;
|
|
19
|
+
}));
|
|
20
|
+
}
|
|
21
|
+
function array(value) {
|
|
22
|
+
if (!Array.isArray(value) || Object.getPrototypeOf(value) !== Array.prototype || value.length > maxValues)
|
|
23
|
+
return false;
|
|
24
|
+
if (Reflect.ownKeys(value).length !== value.length + 1)
|
|
25
|
+
return false;
|
|
26
|
+
for (let index = 0; index < value.length; index++) {
|
|
27
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, String(index));
|
|
28
|
+
if (!descriptor?.enumerable || !("value" in descriptor))
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
33
|
+
function decodeString(value) {
|
|
34
|
+
if (typeof value !== "string" || Buffer.byteLength(value, "utf8") > maxBytes * 6 + 2)
|
|
35
|
+
invalid("expected bounded encoded string");
|
|
36
|
+
let decoded;
|
|
37
|
+
try {
|
|
38
|
+
decoded = JSON.parse(value);
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
invalid("malformed encoded string carrier");
|
|
42
|
+
}
|
|
43
|
+
if (typeof decoded !== "string" || !decoded.isWellFormed())
|
|
44
|
+
invalid("expected a well-formed encoded string");
|
|
45
|
+
return decoded;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Execute XQuery once through an evaluator and decode the private typed carrier.
|
|
49
|
+
* Query text is passed unchanged as data. No retries, read-only validation,
|
|
50
|
+
* database work bound or transport cancellation guarantee are provided.
|
|
51
|
+
* Results are limited to whole rows, depth 32, 10,000 values and 256 KiB of
|
|
52
|
+
* JSON-compatible data. Strings preserve CR/LF; native dates become ISO strings.
|
|
53
|
+
*/
|
|
54
|
+
export async function executeXQuery(evaluator, query, options = {}) {
|
|
55
|
+
if (typeof query !== "string" ||
|
|
56
|
+
!query.trim() ||
|
|
57
|
+
!query.isWellFormed() ||
|
|
58
|
+
query.includes("\0") ||
|
|
59
|
+
Buffer.byteLength(query, "utf8") > 65536) {
|
|
60
|
+
throw new TypeError("XQuery query must be nonblank, well-formed text without NUL, within 65536 UTF-8 bytes");
|
|
61
|
+
}
|
|
62
|
+
const maxRows = options.maxRows === undefined ? 100 : options.maxRows;
|
|
63
|
+
if (!Number.isInteger(maxRows) || maxRows < 1 || maxRows > 1000)
|
|
64
|
+
throw new TypeError("XQuery maxRows must be an integer from 1 to 1000");
|
|
65
|
+
// JSON string syntax is valid BS string syntax; escape line separator literals.
|
|
66
|
+
const literal = JSON.stringify(query)
|
|
67
|
+
.replace(/\u2028/g, "\\u2028")
|
|
68
|
+
.replace(/\u2029/g, "\\u2029");
|
|
69
|
+
const script = template.replace(/\$\{(queryLiteral|maxRows)\}/g, (_, name) => name === "queryLiteral" ? literal : String(maxRows));
|
|
70
|
+
const response = await evaluator.eval(script);
|
|
71
|
+
if (!record(response, ["rows", "returnedRows", "truncated", "limitReason"]))
|
|
72
|
+
invalid("expected the result envelope");
|
|
73
|
+
const { rows: carrier, returnedRows, truncated, limitReason } = response;
|
|
74
|
+
if (!array(carrier) ||
|
|
75
|
+
typeof returnedRows !== "bigint" ||
|
|
76
|
+
returnedRows < 0n ||
|
|
77
|
+
returnedRows > BigInt(maxRows) ||
|
|
78
|
+
returnedRows !== BigInt(carrier.length))
|
|
79
|
+
invalid("inconsistent row count");
|
|
80
|
+
if (typeof truncated !== "boolean" ||
|
|
81
|
+
(limitReason !== null && limitReason !== "rows" && limitReason !== "output") ||
|
|
82
|
+
truncated !== (limitReason !== null))
|
|
83
|
+
invalid("inconsistent truncation metadata");
|
|
84
|
+
if (limitReason === "rows" && returnedRows !== BigInt(maxRows))
|
|
85
|
+
invalid("row limit contradicts maxRows");
|
|
86
|
+
let values = 0;
|
|
87
|
+
const active = new WeakSet();
|
|
88
|
+
let textBytes = 0;
|
|
89
|
+
function text(value) {
|
|
90
|
+
const decoded = decodeString(value);
|
|
91
|
+
textBytes += Buffer.byteLength(decoded, "utf8");
|
|
92
|
+
if (textBytes > maxBytes)
|
|
93
|
+
invalid("decoded text exceeds output limit");
|
|
94
|
+
return decoded;
|
|
95
|
+
}
|
|
96
|
+
function decode(value, depth) {
|
|
97
|
+
if (depth > maxDepth || ++values > maxValues)
|
|
98
|
+
invalid("projection depth or values limit exceeded");
|
|
99
|
+
if (typeof value === "string")
|
|
100
|
+
return text(value);
|
|
101
|
+
if (value === null || value === undefined || typeof value === "boolean" || typeof value === "number")
|
|
102
|
+
return value;
|
|
103
|
+
if (typeof value === "bigint") {
|
|
104
|
+
if (value < -(1n << 63n) || value > (1n << 63n) - 1n)
|
|
105
|
+
invalid("integer outside signed int64");
|
|
106
|
+
return value;
|
|
107
|
+
}
|
|
108
|
+
if (typeof value !== "object")
|
|
109
|
+
invalid("unsupported carrier value");
|
|
110
|
+
if (active.has(value))
|
|
111
|
+
invalid("cyclic carrier");
|
|
112
|
+
active.add(value);
|
|
113
|
+
try {
|
|
114
|
+
if (Array.isArray(value)) {
|
|
115
|
+
if (!array(value))
|
|
116
|
+
invalid("malformed array carrier");
|
|
117
|
+
return value.map((entry) => decode(entry, depth + 1));
|
|
118
|
+
}
|
|
119
|
+
if (!record(value, ["entries"]) || !array(value.entries))
|
|
120
|
+
invalid("malformed record carrier");
|
|
121
|
+
const result = {};
|
|
122
|
+
for (const entry of value.entries) {
|
|
123
|
+
if (!array(entry) || entry.length !== 2)
|
|
124
|
+
invalid("malformed record entry carrier");
|
|
125
|
+
const name = text(entry[0]);
|
|
126
|
+
if (Object.hasOwn(result, name))
|
|
127
|
+
invalid("duplicate record key");
|
|
128
|
+
Object.defineProperty(result, name, { value: decode(entry[1], depth + 1), enumerable: true, configurable: true, writable: true });
|
|
129
|
+
}
|
|
130
|
+
return result;
|
|
131
|
+
}
|
|
132
|
+
finally {
|
|
133
|
+
active.delete(value);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
const rows = carrier.map((row) => decode(row, 0));
|
|
137
|
+
const result = { rows, returnedRows: Number(returnedRows), truncated, limitReason };
|
|
138
|
+
// Conservative size accounting only: presentation policy remains the caller's.
|
|
139
|
+
// Decimal strings bound both safe-number and large-decimal-string bigint JSON.
|
|
140
|
+
const bounded = JSON.stringify(result, (_, value) => {
|
|
141
|
+
if (typeof value === "bigint")
|
|
142
|
+
return value.toString();
|
|
143
|
+
if (typeof value === "number" && !Number.isFinite(value))
|
|
144
|
+
return String(value);
|
|
145
|
+
return value === undefined ? null : value;
|
|
146
|
+
});
|
|
147
|
+
if (Buffer.byteLength(bounded, "utf8") > maxBytes)
|
|
148
|
+
invalid("JSON-compatible output exceeds 256 KiB limit");
|
|
149
|
+
return result;
|
|
150
|
+
}
|
|
151
|
+
//# sourceMappingURL=xquery.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"xquery.js","sourceRoot":"","sources":["../src/xquery.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAqBvC,MAAM,QAAQ,GAAG,YAAY,CAAC,IAAI,GAAG,CAAC,wBAAwB,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,CAAC;AAC1F,MAAM,QAAQ,GAAG,MAAM,CAAC;AACxB,MAAM,QAAQ,GAAG,EAAE,CAAC;AACpB,MAAM,SAAS,GAAG,KAAK,CAAC;AAExB,SAAS,OAAO,CAAC,OAAe;IAC9B,MAAM,IAAI,KAAK,CAAC,4BAA4B,OAAO,EAAE,CAAC,CAAC;AACzD,CAAC;AAED,SAAS,MAAM,CAAC,KAAc,EAAE,IAAc;IAC5C,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,Q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C,GAAG,EAAE,EAAE,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC;IAClD,MAAM,MAAM,GAAiB,EAAE,IAAI,EAAE,YAAY,EAAE,MAAM,CAAC,YAAY,CAAC,EAAE,SAAS,EAAE,WAAW,EAAE,CAAC;IAClG,+EAA+E;IAC/E,+EAA+E;IAC/E,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC,CAAC,EAAE,KAAc,EAAE,EAAE;QAC3D,IAAI,OAAO,KAAK,KAAK,QAAQ;YAAE,OAAO,KAAK,CAAC,QAAQ,EAAE,CAAC;QACvD,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC;YAAE,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;QAC/E,OAAO,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC;IAC5C,CAAC,CAAC,CAAC;IACH,IAAI,MAAM,CAAC,UAAU,CAAC,OAAO,EAAE,MAAM,CAAC,GAAG,QAAQ;QAAE,OAAO,CAAC,8CAA8C,CAAC,CAAC;IAC3G,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@boristype/ws-client",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.6",
|
|
4
4
|
"description": "WSHCM SOAP client — клиент для работы с WebSoft HCM через SP-XML API",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "build/index.js",
|
|
@@ -44,6 +44,8 @@
|
|
|
44
44
|
"scripts": {
|
|
45
45
|
"build": "node tools/prepare-runtime.mjs && tsc",
|
|
46
46
|
"build:runtime": "node tools/prepare-runtime.mjs",
|
|
47
|
-
"test": "node --test test/*.test.mjs"
|
|
47
|
+
"test": "node --test test/*.test.mjs",
|
|
48
|
+
"test:e2e:values": "node --test --test-concurrency=1 test/e2e/values.mjs",
|
|
49
|
+
"test:e2e:xquery": "node --test --test-concurrency=1 test/e2e/xquery.mjs"
|
|
48
50
|
}
|
|
49
51
|
}
|
package/resources/xquery.bs
CHANGED
|
@@ -1,30 +1,100 @@
|
|
|
1
|
-
// Query is
|
|
2
|
-
|
|
1
|
+
// Query text is a string literal. This adapter imposes no read-only guarantee.
|
|
2
|
+
var _xqValues = 0;
|
|
3
|
+
function _xqCheck(depth) {
|
|
4
|
+
if (depth > 32) throw 'XQuery projection exceeds depth limit (32)';
|
|
5
|
+
_xqValues++;
|
|
6
|
+
if (_xqValues > 10000) throw 'XQuery projection exceeds values limit (10000)';
|
|
7
|
+
}
|
|
8
|
+
function _xqScalar(value) {
|
|
9
|
+
var kind = DataType(value);
|
|
10
|
+
// JSON-string transport protects CR/LF from SOAP XML normalization.
|
|
11
|
+
// Dates are an explicit ISO-string projection, not generic SOAP date support.
|
|
12
|
+
if ((kind == 'string') || (kind == 'date')) return EncodeJson(value);
|
|
13
|
+
if ((kind == 'integer') || (kind == 'real') || (kind == 'bool') || (kind == 'null') || (kind == 'undefined')) return value;
|
|
14
|
+
throw 'XQuery projection encountered an unsupported scalar';
|
|
15
|
+
}
|
|
16
|
+
function _xqProject(value, depth) {
|
|
17
|
+
_xqCheck(depth);
|
|
18
|
+
if (DataType(value) != 'object') return _xqScalar(value);
|
|
19
|
+
var kind = ObjectType(value);
|
|
20
|
+
var entries = [];
|
|
21
|
+
var repeated = [];
|
|
22
|
+
var result;
|
|
23
|
+
var child;
|
|
24
|
+
var name;
|
|
25
|
+
var key;
|
|
26
|
+
var projected;
|
|
27
|
+
var multi;
|
|
28
|
+
var index;
|
|
29
|
+
var slot;
|
|
30
|
+
var search;
|
|
31
|
+
if (kind == 'XmElem') {
|
|
32
|
+
// Complex schema nodes have Type == '', including empty structures.
|
|
33
|
+
// Dynamic parents can have Type == 'string' with real children.
|
|
34
|
+
if ((value.ChildNum == 0) && (value.Type != '')) return _xqScalar(value.Value);
|
|
35
|
+
if (value.ChildNum > 10000) throw 'XQuery projection exceeds values limit (10000)';
|
|
36
|
+
for (index = 0; index < value.ChildNum; index++) {
|
|
37
|
+
child = value[index];
|
|
38
|
+
name = child.Name;
|
|
39
|
+
key = EncodeJson(name);
|
|
40
|
+
multi = child.IsMultiElem;
|
|
41
|
+
// Indexed XmlElem instances are not XmlMultiElem collections.
|
|
42
|
+
// Name collisions with native XML properties must not prevent traversal.
|
|
43
|
+
try { multi = (multi || GetObjectProperty(value, name).IsMultiElem); } catch (err) { }
|
|
44
|
+
slot = -1;
|
|
45
|
+
for (search = 0; search < ArrayCount(entries); search++) {
|
|
46
|
+
if (entries[search][0] == key) { slot = search; break; }
|
|
47
|
+
}
|
|
48
|
+
projected = _xqProject(child, depth + 1);
|
|
49
|
+
if (slot < 0) {
|
|
50
|
+
if (multi) {
|
|
51
|
+
_xqCheck(depth + 1);
|
|
52
|
+
entries.push([key, [projected]]);
|
|
53
|
+
} else {
|
|
54
|
+
entries.push([key, projected]);
|
|
55
|
+
}
|
|
56
|
+
repeated.push(multi);
|
|
57
|
+
} else {
|
|
58
|
+
if (!repeated[slot]) {
|
|
59
|
+
_xqCheck(depth + 1);
|
|
60
|
+
entries[slot][1] = [entries[slot][1]];
|
|
61
|
+
repeated[slot] = true;
|
|
62
|
+
}
|
|
63
|
+
entries[slot][1].push(projected);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return { entries: entries };
|
|
67
|
+
}
|
|
68
|
+
if (kind == 'JsArray') {
|
|
69
|
+
result = [];
|
|
70
|
+
if (ArrayCount(value) > 10000) throw 'XQuery projection exceeds values limit (10000)';
|
|
71
|
+
for (index = 0; index < ArrayCount(value); index++) result.push(_xqProject(value[index], depth + 1));
|
|
72
|
+
return result;
|
|
73
|
+
}
|
|
74
|
+
if (kind == 'JsObject') {
|
|
75
|
+
for (name in value) entries.push([EncodeJson(name), _xqProject(GetObjectProperty(value, name), depth + 1)]);
|
|
76
|
+
return { entries: entries };
|
|
77
|
+
}
|
|
78
|
+
throw 'XQuery projection encountered an unsupported object';
|
|
79
|
+
}
|
|
3
80
|
var _xqMaxRows = ${maxRows};
|
|
4
|
-
|
|
5
|
-
var
|
|
6
|
-
var
|
|
81
|
+
// Count only this materialized range, never the unbounded lazy source.
|
|
82
|
+
var _xqItems = ArraySelectAll(ArrayRange(XQuery(${queryLiteral}), 0, _xqMaxRows + 1));
|
|
83
|
+
var _xqRows = [];
|
|
84
|
+
var _xqChars = 0;
|
|
7
85
|
var _xqReason = null;
|
|
8
86
|
var _xqIndex;
|
|
9
87
|
var _xqRow;
|
|
10
|
-
var
|
|
88
|
+
var _xqSize;
|
|
11
89
|
for (_xqIndex = 0; _xqIndex < ArrayCount(_xqItems); _xqIndex++) {
|
|
12
|
-
if (
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
if (StrCharCount(_xqRows) + StrCharCount(_xqRow) + StrCharCount(_xqSeparator) > 65000) {
|
|
21
|
-
_xqReason = 'output';
|
|
22
|
-
break;
|
|
23
|
-
}
|
|
24
|
-
_xqRows = _xqRows + _xqSeparator + _xqRow;
|
|
25
|
-
_xqCount++;
|
|
90
|
+
if (ArrayCount(_xqRows) >= _xqMaxRows) { _xqReason = 'rows'; break; }
|
|
91
|
+
_xqRow = _xqProject(_xqItems[_xqIndex], 0);
|
|
92
|
+
_xqSize = StrCharCount(EncodeJson(_xqRow)) + 1;
|
|
93
|
+
// At most four UTF-8 bytes per character, plus room for the envelope.
|
|
94
|
+
// A complete row is projected before checking its size: no memory/work bound.
|
|
95
|
+
if ((_xqChars + _xqSize) > 65000) { _xqReason = 'output'; break; }
|
|
96
|
+
_xqRows.push(_xqRow);
|
|
97
|
+
_xqChars = _xqChars + _xqSize;
|
|
26
98
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
',"truncated":' + (_xqReason == null ? 'false' : 'true') + ',"limitReason":' + EncodeJson(_xqReason) + '}';
|
|
30
|
-
return EncodeJson(_xqJson);
|
|
99
|
+
var _xqTruncated = (_xqReason != null);
|
|
100
|
+
return { rows: _xqRows, returnedRows: ArrayCount(_xqRows), truncated: _xqTruncated, limitReason: _xqReason };
|