js.documents 14.4.45 → 14.4.47
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/convert/composition.cjs +9 -4
- package/dist/convert/composition.js +9 -4
- package/dist/convert/variant-bridges.cjs +2 -1
- package/dist/convert/variant-bridges.js +2 -1
- package/dist/csv/records.cjs +2 -1
- package/dist/csv/records.js +2 -1
- package/dist/edit/geometry.cjs +2 -1
- package/dist/edit/geometry.js +2 -1
- package/dist/edit/odg/svg-path.cjs +2 -1
- package/dist/edit/odg/svg-path.js +2 -1
- package/dist/edit/ods/cell.cjs +2 -1
- package/dist/edit/ods/cell.js +2 -1
- package/dist/edit/pdf/util.cjs +2 -1
- package/dist/edit/pdf/util.js +2 -1
- package/dist/firebird/data.cjs +2 -1
- package/dist/firebird/data.js +2 -1
- package/dist/firebird/date.cjs +40 -21
- package/dist/firebird/date.js +40 -21
- package/dist/firebird/reader.cjs +30 -19
- package/dist/firebird/reader.js +30 -19
- package/dist/hsqldb/binary-script.cjs +5 -4
- package/dist/hsqldb/binary-script.js +5 -4
- package/dist/hsqldb/cache.cjs +4 -2
- package/dist/hsqldb/cache.js +4 -2
- package/dist/hsqldb/rowformat.cjs +93 -57
- package/dist/hsqldb/rowformat.js +93 -57
- package/dist/hsqldb/script.cjs +2 -1
- package/dist/hsqldb/script.js +2 -1
- package/dist/latex/lower.cjs +2 -1
- package/dist/latex/lower.js +2 -1
- package/dist/latex/rational.cjs +6 -3
- package/dist/latex/rational.js +6 -3
- package/dist/layout/cell-typing.cjs +7 -3
- package/dist/layout/cell-typing.js +7 -3
- package/dist/layout/reconstruct.cjs +17 -15
- package/dist/layout/reconstruct.js +17 -15
- package/dist/layout/shared.cjs +2 -1
- package/dist/layout/shared.js +2 -1
- package/dist/layout/sheets.cjs +2 -1
- package/dist/layout/sheets.js +2 -1
- package/dist/mathml/layout.cjs +11 -5
- package/dist/mathml/layout.js +11 -5
- package/dist/mathml/length.cjs +12 -10
- package/dist/mathml/length.js +12 -10
- package/dist/mathml/operators.cjs +7 -3
- package/dist/mathml/operators.js +7 -3
- package/dist/mathml/variant.cjs +116 -1142
- package/dist/mathml/variant.js +116 -1142
- package/dist/model/bytes.cjs +9 -16
- package/dist/model/bytes.js +9 -16
- package/dist/model/geometry.cjs +2 -1
- package/dist/model/geometry.js +2 -1
- package/dist/odb/read.cjs +10 -2
- package/dist/odb/read.js +10 -2
- package/dist/svg/paint.cjs +177 -749
- package/dist/svg/paint.js +177 -749
- package/dist/svg/path.cjs +11 -6
- package/dist/svg/path.js +11 -6
- package/dist/svg/read.cjs +7 -3
- package/dist/svg/read.js +8 -4
- package/dist/svg/transform.cjs +11 -7
- package/dist/svg/transform.js +11 -7
- package/dist/svg/units.cjs +9 -5
- package/dist/svg/units.d.cts +2 -1
- package/dist/svg/units.d.ts +2 -1
- package/dist/svg/units.js +9 -6
- package/package.json +3 -3
package/dist/firebird/reader.js
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
//#region src/firebird/reader.ts
|
|
2
|
+
const INT32_BYTE_LENGTH = 4;
|
|
3
|
+
const BYTE_1_SHIFT = 8;
|
|
4
|
+
const BYTE_2_SHIFT = 16;
|
|
5
|
+
const BYTE_3_SHIFT = 24;
|
|
6
|
+
const SIGNED_BYTE_SIGN_BIT = 128;
|
|
7
|
+
const SIGNED_BYTE_WRAP = 256;
|
|
2
8
|
var FirebirdBackupParseError = class extends Error {
|
|
3
9
|
offset;
|
|
4
10
|
constructor(message, offset) {
|
|
@@ -46,8 +52,8 @@ var FirebirdBackupReader = class {
|
|
|
46
52
|
}
|
|
47
53
|
readInt32Attribute() {
|
|
48
54
|
const bytes = this.readAttributeBytes();
|
|
49
|
-
if (bytes.length !==
|
|
50
|
-
return (bytes[0] ?? 0) | (bytes[1] ?? 0) <<
|
|
55
|
+
if (bytes.length !== INT32_BYTE_LENGTH) throw new FirebirdBackupParseError(`expected a 4-byte int32 attribute, found ${bytes.length} byte(s)`, this.position);
|
|
56
|
+
return (bytes[0] ?? 0) | (bytes[1] ?? 0) << BYTE_1_SHIFT | (bytes[2] ?? 0) << BYTE_2_SHIFT | (bytes[3] ?? 0) << BYTE_3_SHIFT;
|
|
51
57
|
}
|
|
52
58
|
readTextAttribute() {
|
|
53
59
|
const bytes = this.readAttributeBytes();
|
|
@@ -66,13 +72,13 @@ var FirebirdBackupReader = class {
|
|
|
66
72
|
return this.readRawBytes(length);
|
|
67
73
|
}
|
|
68
74
|
readBlobSegmentLength() {
|
|
69
|
-
return this.readLengthByte() | this.readLengthByte() <<
|
|
75
|
+
return this.readLengthByte() | this.readLengthByte() << BYTE_1_SHIFT;
|
|
70
76
|
}
|
|
71
77
|
readSignedByte() {
|
|
72
78
|
const byte = this.bytes[this.position];
|
|
73
79
|
if (byte === void 0) throw new FirebirdBackupParseError("unexpected end of stream reading a compression control byte", this.position);
|
|
74
80
|
this.position++;
|
|
75
|
-
return byte >=
|
|
81
|
+
return byte >= SIGNED_BYTE_SIGN_BIT ? byte - SIGNED_BYTE_WRAP : byte;
|
|
76
82
|
}
|
|
77
83
|
readCompressedPayload(decompressedLength) {
|
|
78
84
|
const output = new Uint8Array(decompressedLength);
|
|
@@ -95,6 +101,11 @@ var FirebirdBackupReader = class {
|
|
|
95
101
|
return output;
|
|
96
102
|
}
|
|
97
103
|
};
|
|
104
|
+
const THIRD_BYTE_OFFSET = 3;
|
|
105
|
+
const INT16_SIGN_EXTEND_SHIFT = 16;
|
|
106
|
+
const INT32_BITS_BIGINT = 32n;
|
|
107
|
+
const UINT32_MASK_BIGINT = 4294967295n;
|
|
108
|
+
const DOUBLE_BYTE_LENGTH = 8;
|
|
98
109
|
var XdrReader = class {
|
|
99
110
|
bytes;
|
|
100
111
|
position;
|
|
@@ -111,41 +122,41 @@ var XdrReader = class {
|
|
|
111
122
|
return this.position >= this.end;
|
|
112
123
|
}
|
|
113
124
|
readInt32() {
|
|
114
|
-
if (this.position +
|
|
125
|
+
if (this.position + INT32_BYTE_LENGTH > this.end) throw new FirebirdBackupParseError("unexpected end of XDR data reading a 4-byte integer", this.position);
|
|
115
126
|
const b0 = this.bytes[this.position] ?? 0;
|
|
116
127
|
const b1 = this.bytes[this.position + 1] ?? 0;
|
|
117
128
|
const b2 = this.bytes[this.position + 2] ?? 0;
|
|
118
|
-
const b3 = this.bytes[this.position +
|
|
119
|
-
this.position +=
|
|
120
|
-
return b0 <<
|
|
129
|
+
const b3 = this.bytes[this.position + THIRD_BYTE_OFFSET] ?? 0;
|
|
130
|
+
this.position += INT32_BYTE_LENGTH;
|
|
131
|
+
return b0 << BYTE_3_SHIFT | b1 << BYTE_2_SHIFT | b2 << BYTE_1_SHIFT | b3 | 0;
|
|
121
132
|
}
|
|
122
133
|
readInt16() {
|
|
123
|
-
return this.readInt32() <<
|
|
134
|
+
return this.readInt32() << INT16_SIGN_EXTEND_SHIFT >> INT16_SIGN_EXTEND_SHIFT;
|
|
124
135
|
}
|
|
125
136
|
readInt64() {
|
|
126
137
|
const high = this.readInt32();
|
|
127
138
|
const low = this.readInt32();
|
|
128
|
-
return BigInt(high) <<
|
|
139
|
+
return BigInt(high) << INT32_BITS_BIGINT | BigInt(low) & UINT32_MASK_BIGINT;
|
|
129
140
|
}
|
|
130
141
|
readDouble() {
|
|
131
|
-
if (this.position +
|
|
132
|
-
const view = /* @__PURE__ */ new DataView(/* @__PURE__ */ new ArrayBuffer(
|
|
133
|
-
for (let i = 0; i <
|
|
134
|
-
this.position +=
|
|
142
|
+
if (this.position + DOUBLE_BYTE_LENGTH > this.end) throw new FirebirdBackupParseError("unexpected end of XDR data reading an 8-byte double", this.position);
|
|
143
|
+
const view = /* @__PURE__ */ new DataView(/* @__PURE__ */ new ArrayBuffer(DOUBLE_BYTE_LENGTH));
|
|
144
|
+
for (let i = 0; i < DOUBLE_BYTE_LENGTH; i++) view.setUint8(i, this.bytes[this.position + i] ?? 0);
|
|
145
|
+
this.position += DOUBLE_BYTE_LENGTH;
|
|
135
146
|
return view.getFloat64(0, false);
|
|
136
147
|
}
|
|
137
148
|
readFloat() {
|
|
138
|
-
if (this.position +
|
|
139
|
-
const view = /* @__PURE__ */ new DataView(/* @__PURE__ */ new ArrayBuffer(
|
|
140
|
-
for (let i = 0; i <
|
|
141
|
-
this.position +=
|
|
149
|
+
if (this.position + INT32_BYTE_LENGTH > this.end) throw new FirebirdBackupParseError("unexpected end of XDR data reading a 4-byte float", this.position);
|
|
150
|
+
const view = /* @__PURE__ */ new DataView(/* @__PURE__ */ new ArrayBuffer(INT32_BYTE_LENGTH));
|
|
151
|
+
for (let i = 0; i < INT32_BYTE_LENGTH; i++) view.setUint8(i, this.bytes[this.position + i] ?? 0);
|
|
152
|
+
this.position += INT32_BYTE_LENGTH;
|
|
142
153
|
return view.getFloat32(0, false);
|
|
143
154
|
}
|
|
144
155
|
readOpaque(len) {
|
|
145
156
|
if (this.position + len > this.end) throw new FirebirdBackupParseError(`unexpected end of XDR data reading ${len} opaque byte(s)`, this.position);
|
|
146
157
|
const slice = this.bytes.subarray(this.position, this.position + len);
|
|
147
158
|
this.position += len;
|
|
148
|
-
const padding = (
|
|
159
|
+
const padding = (INT32_BYTE_LENGTH - len % INT32_BYTE_LENGTH) % INT32_BYTE_LENGTH;
|
|
149
160
|
this.position += padding;
|
|
150
161
|
return slice;
|
|
151
162
|
}
|
|
@@ -3,6 +3,7 @@ const require_hsqldb_script = require("./script.cjs");
|
|
|
3
3
|
const require_hsqldb_rowformat = require("./rowformat.cjs");
|
|
4
4
|
let byte_codec = require("byte-codec");
|
|
5
5
|
//#region src/hsqldb/binary-script.ts
|
|
6
|
+
const INT32_BYTE_LENGTH = 4;
|
|
6
7
|
var HsqldbBinaryScriptParseError = class extends Error {
|
|
7
8
|
offset;
|
|
8
9
|
constructor(message, offset) {
|
|
@@ -29,13 +30,13 @@ var BinaryScriptCursor = class {
|
|
|
29
30
|
this.cursor.position = value;
|
|
30
31
|
}
|
|
31
32
|
hasRecordLength() {
|
|
32
|
-
return this.cursor.position +
|
|
33
|
+
return this.cursor.position + INT32_BYTE_LENGTH <= this.length;
|
|
33
34
|
}
|
|
34
35
|
require(byteCount, what) {
|
|
35
36
|
if (this.cursor.position + byteCount > this.length) throw new HsqldbBinaryScriptParseError(`stream ends after ${this.length} bytes while reading ${what} (${byteCount} byte(s) needed)`, this.cursor.position);
|
|
36
37
|
}
|
|
37
38
|
readInt32(what) {
|
|
38
|
-
this.require(
|
|
39
|
+
this.require(INT32_BYTE_LENGTH, what);
|
|
39
40
|
return this.cursor.readInt32();
|
|
40
41
|
}
|
|
41
42
|
readInt16(what) {
|
|
@@ -72,7 +73,7 @@ function readResultMetaData(reader) {
|
|
|
72
73
|
function readDdlStatements(reader) {
|
|
73
74
|
const recordStart = reader.position;
|
|
74
75
|
const recordLength = reader.readInt32("the leading DDL result record's own length");
|
|
75
|
-
if (recordLength <=
|
|
76
|
+
if (recordLength <= INT32_BYTE_LENGTH) throw new HsqldbBinaryScriptParseError(`the leading DDL result record declares an implausible length ${recordLength} — not a recognisable HSQLDB binary script`, recordStart);
|
|
76
77
|
const mode = reader.readInt32("the DDL result's own mode");
|
|
77
78
|
if (mode !== RESULT_MODE_DATA) throw new HsqldbBinaryScriptParseError(`the leading record has Result mode ${mode}, not the DATA mode (${RESULT_MODE_DATA}) a script's own DDL result always carries — not a recognisable HSQLDB binary script`, recordStart);
|
|
78
79
|
reader.readInt32("the DDL result's own database id");
|
|
@@ -111,7 +112,7 @@ function readTableSection(reader, tables, options) {
|
|
|
111
112
|
if (rowLength === 0) break;
|
|
112
113
|
if (rowLength < 0) throw new HsqldbBinaryScriptParseError(`a row in table "${tableName}" declares a negative length ${rowLength}`, rowStart);
|
|
113
114
|
const rowEnd = rowStart + rowLength;
|
|
114
|
-
reader.require(rowLength -
|
|
115
|
+
reader.require(rowLength - INT32_BYTE_LENGTH, `a row in table "${tableName}"`);
|
|
115
116
|
rows.push(typeCodes.map((typeCode) => require_hsqldb_rowformat.readHsqldbColumnValue(reader.cursor, typeCode, options)));
|
|
116
117
|
if (reader.position > rowEnd) throw new HsqldbBinaryScriptParseError(`a row in table "${tableName}" overran its own declared length (consumed ${reader.position - rowStart} bytes, declared ${rowLength})`, reader.position);
|
|
117
118
|
reader.position = rowEnd;
|
|
@@ -2,6 +2,7 @@ import { parseHsqldbScript } from "./script.js";
|
|
|
2
2
|
import { HsqldbDataCursor, readHsqldbColumnValue, readModifiedUtf8, resolveHsqldbTypeCode } from "./rowformat.js";
|
|
3
3
|
import { inflate } from "byte-codec";
|
|
4
4
|
//#region src/hsqldb/binary-script.ts
|
|
5
|
+
const INT32_BYTE_LENGTH = 4;
|
|
5
6
|
var HsqldbBinaryScriptParseError = class extends Error {
|
|
6
7
|
offset;
|
|
7
8
|
constructor(message, offset) {
|
|
@@ -28,13 +29,13 @@ var BinaryScriptCursor = class {
|
|
|
28
29
|
this.cursor.position = value;
|
|
29
30
|
}
|
|
30
31
|
hasRecordLength() {
|
|
31
|
-
return this.cursor.position +
|
|
32
|
+
return this.cursor.position + INT32_BYTE_LENGTH <= this.length;
|
|
32
33
|
}
|
|
33
34
|
require(byteCount, what) {
|
|
34
35
|
if (this.cursor.position + byteCount > this.length) throw new HsqldbBinaryScriptParseError(`stream ends after ${this.length} bytes while reading ${what} (${byteCount} byte(s) needed)`, this.cursor.position);
|
|
35
36
|
}
|
|
36
37
|
readInt32(what) {
|
|
37
|
-
this.require(
|
|
38
|
+
this.require(INT32_BYTE_LENGTH, what);
|
|
38
39
|
return this.cursor.readInt32();
|
|
39
40
|
}
|
|
40
41
|
readInt16(what) {
|
|
@@ -71,7 +72,7 @@ function readResultMetaData(reader) {
|
|
|
71
72
|
function readDdlStatements(reader) {
|
|
72
73
|
const recordStart = reader.position;
|
|
73
74
|
const recordLength = reader.readInt32("the leading DDL result record's own length");
|
|
74
|
-
if (recordLength <=
|
|
75
|
+
if (recordLength <= INT32_BYTE_LENGTH) throw new HsqldbBinaryScriptParseError(`the leading DDL result record declares an implausible length ${recordLength} — not a recognisable HSQLDB binary script`, recordStart);
|
|
75
76
|
const mode = reader.readInt32("the DDL result's own mode");
|
|
76
77
|
if (mode !== RESULT_MODE_DATA) throw new HsqldbBinaryScriptParseError(`the leading record has Result mode ${mode}, not the DATA mode (${RESULT_MODE_DATA}) a script's own DDL result always carries — not a recognisable HSQLDB binary script`, recordStart);
|
|
77
78
|
reader.readInt32("the DDL result's own database id");
|
|
@@ -110,7 +111,7 @@ function readTableSection(reader, tables, options) {
|
|
|
110
111
|
if (rowLength === 0) break;
|
|
111
112
|
if (rowLength < 0) throw new HsqldbBinaryScriptParseError(`a row in table "${tableName}" declares a negative length ${rowLength}`, rowStart);
|
|
112
113
|
const rowEnd = rowStart + rowLength;
|
|
113
|
-
reader.require(rowLength -
|
|
114
|
+
reader.require(rowLength - INT32_BYTE_LENGTH, `a row in table "${tableName}"`);
|
|
114
115
|
rows.push(typeCodes.map((typeCode) => readHsqldbColumnValue(reader.cursor, typeCode, options)));
|
|
115
116
|
if (reader.position > rowEnd) throw new HsqldbBinaryScriptParseError(`a row in table "${tableName}" overran its own declared length (consumed ${reader.position - rowStart} bytes, declared ${rowLength})`, reader.position);
|
|
116
117
|
reader.position = rowEnd;
|
package/dist/hsqldb/cache.cjs
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_hsqldb_rowformat = require("./rowformat.cjs");
|
|
3
3
|
//#region src/hsqldb/cache.ts
|
|
4
|
+
const NON_DEFAULT_CACHE_FILE_SCALE = 8;
|
|
5
|
+
const INT32_BYTE_LENGTH = 4;
|
|
4
6
|
const SUPPORTED_COMPATIBLE_VERSION_PREFIXES = ["1.7.", "1.8."];
|
|
5
7
|
const DISK_NODE_SIZE_BYTES = 16;
|
|
6
8
|
function parseHsqldbProperties(text) {
|
|
@@ -15,7 +17,7 @@ function parseHsqldbProperties(text) {
|
|
|
15
17
|
const compatibleVersion = props.get("hsqldb.compatible_version");
|
|
16
18
|
if (compatibleVersion !== void 0 && !SUPPORTED_COMPATIBLE_VERSION_PREFIXES.some((prefix) => compatibleVersion.startsWith(prefix))) throw new require_hsqldb_rowformat.HsqldbRowFormatError(`database/properties declares hsqldb.compatible_version "${compatibleVersion}" — this decoder is scoped to the HSQLDB 1.7.x/1.8.x CACHED-table row-store format (the version LibreOffice's own embedded driver ships) and does not know this version's own on-disk row-store layout`);
|
|
17
19
|
return {
|
|
18
|
-
cacheFileScale: Number(props.get("hsqldb.cache_file_scale") ?? "1") === 1 ? 1 :
|
|
20
|
+
cacheFileScale: Number(props.get("hsqldb.cache_file_scale") ?? "1") === 1 ? 1 : NON_DEFAULT_CACHE_FILE_SCALE,
|
|
19
21
|
compatibleVersion
|
|
20
22
|
};
|
|
21
23
|
}
|
|
@@ -52,7 +54,7 @@ function readHsqldbCachedTableRows(dataBytes, roots, cacheFileScale, columns, op
|
|
|
52
54
|
function visit(pos) {
|
|
53
55
|
if (pos <= 0) return;
|
|
54
56
|
const byteOffset = pos * cacheFileScale;
|
|
55
|
-
if (byteOffset < 0 || byteOffset +
|
|
57
|
+
if (byteOffset < 0 || byteOffset + INT32_BYTE_LENGTH > dataBytes.length) throw new require_hsqldb_rowformat.HsqldbRowFormatError(`row position ${pos} (byte offset ${byteOffset}) falls outside database/data (${dataBytes.length} bytes)`);
|
|
56
58
|
const cursor = new require_hsqldb_rowformat.HsqldbDataCursor(dataBytes, byteOffset);
|
|
57
59
|
const storageSize = cursor.readInt32();
|
|
58
60
|
const rowEnd = byteOffset + storageSize;
|
package/dist/hsqldb/cache.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { HsqldbDataCursor, HsqldbRowFormatError, readHsqldbColumnValue, resolveHsqldbTypeCode } from "./rowformat.js";
|
|
2
2
|
//#region src/hsqldb/cache.ts
|
|
3
|
+
const NON_DEFAULT_CACHE_FILE_SCALE = 8;
|
|
4
|
+
const INT32_BYTE_LENGTH = 4;
|
|
3
5
|
const SUPPORTED_COMPATIBLE_VERSION_PREFIXES = ["1.7.", "1.8."];
|
|
4
6
|
const DISK_NODE_SIZE_BYTES = 16;
|
|
5
7
|
function parseHsqldbProperties(text) {
|
|
@@ -14,7 +16,7 @@ function parseHsqldbProperties(text) {
|
|
|
14
16
|
const compatibleVersion = props.get("hsqldb.compatible_version");
|
|
15
17
|
if (compatibleVersion !== void 0 && !SUPPORTED_COMPATIBLE_VERSION_PREFIXES.some((prefix) => compatibleVersion.startsWith(prefix))) throw new HsqldbRowFormatError(`database/properties declares hsqldb.compatible_version "${compatibleVersion}" — this decoder is scoped to the HSQLDB 1.7.x/1.8.x CACHED-table row-store format (the version LibreOffice's own embedded driver ships) and does not know this version's own on-disk row-store layout`);
|
|
16
18
|
return {
|
|
17
|
-
cacheFileScale: Number(props.get("hsqldb.cache_file_scale") ?? "1") === 1 ? 1 :
|
|
19
|
+
cacheFileScale: Number(props.get("hsqldb.cache_file_scale") ?? "1") === 1 ? 1 : NON_DEFAULT_CACHE_FILE_SCALE,
|
|
18
20
|
compatibleVersion
|
|
19
21
|
};
|
|
20
22
|
}
|
|
@@ -51,7 +53,7 @@ function readHsqldbCachedTableRows(dataBytes, roots, cacheFileScale, columns, op
|
|
|
51
53
|
function visit(pos) {
|
|
52
54
|
if (pos <= 0) return;
|
|
53
55
|
const byteOffset = pos * cacheFileScale;
|
|
54
|
-
if (byteOffset < 0 || byteOffset +
|
|
56
|
+
if (byteOffset < 0 || byteOffset + INT32_BYTE_LENGTH > dataBytes.length) throw new HsqldbRowFormatError(`row position ${pos} (byte offset ${byteOffset}) falls outside database/data (${dataBytes.length} bytes)`);
|
|
55
57
|
const cursor = new HsqldbDataCursor(dataBytes, byteOffset);
|
|
56
58
|
const storageSize = cursor.readInt32();
|
|
57
59
|
const rowEnd = byteOffset + storageSize;
|
|
@@ -6,29 +6,46 @@ var HsqldbRowFormatError = class extends Error {
|
|
|
6
6
|
this.name = "HsqldbRowFormatError";
|
|
7
7
|
}
|
|
8
8
|
};
|
|
9
|
+
const SQL_CHAR = 1;
|
|
10
|
+
const SQL_NUMERIC = 2;
|
|
11
|
+
const SQL_DECIMAL = 3;
|
|
12
|
+
const SQL_INTEGER = 4;
|
|
13
|
+
const SQL_SMALLINT = 5;
|
|
14
|
+
const SQL_FLOAT = 6;
|
|
15
|
+
const SQL_REAL = 7;
|
|
16
|
+
const SQL_DOUBLE = 8;
|
|
17
|
+
const SQL_VARCHAR = 12;
|
|
18
|
+
const SQL_BOOLEAN_BIT = 16;
|
|
19
|
+
const SQL_DATE = 91;
|
|
20
|
+
const SQL_TIME = 92;
|
|
21
|
+
const SQL_TIMESTAMP = 93;
|
|
22
|
+
const SQL_VARCHAR_IGNORECASE = 100;
|
|
23
|
+
const SQL_BIGINT = -5;
|
|
24
|
+
const SQL_TINYINT = -6;
|
|
25
|
+
const SQL_LONGVARCHAR = -1;
|
|
9
26
|
const SQL_TYPE_NAME_TO_CODE = {
|
|
10
|
-
INTEGER:
|
|
11
|
-
INT:
|
|
12
|
-
IDENTITY:
|
|
13
|
-
DOUBLE:
|
|
14
|
-
FLOAT:
|
|
15
|
-
REAL:
|
|
16
|
-
VARCHAR:
|
|
17
|
-
CHAR:
|
|
18
|
-
CHARACTER:
|
|
19
|
-
LONGVARCHAR:
|
|
20
|
-
VARCHAR_IGNORECASE:
|
|
21
|
-
DATE:
|
|
22
|
-
TIME:
|
|
23
|
-
TIMESTAMP:
|
|
24
|
-
DATETIME:
|
|
25
|
-
DECIMAL:
|
|
26
|
-
NUMERIC:
|
|
27
|
-
BIT:
|
|
28
|
-
BOOLEAN:
|
|
29
|
-
TINYINT:
|
|
30
|
-
SMALLINT:
|
|
31
|
-
BIGINT:
|
|
27
|
+
INTEGER: SQL_INTEGER,
|
|
28
|
+
INT: SQL_INTEGER,
|
|
29
|
+
IDENTITY: SQL_INTEGER,
|
|
30
|
+
DOUBLE: SQL_DOUBLE,
|
|
31
|
+
FLOAT: SQL_FLOAT,
|
|
32
|
+
REAL: SQL_REAL,
|
|
33
|
+
VARCHAR: SQL_VARCHAR,
|
|
34
|
+
CHAR: SQL_CHAR,
|
|
35
|
+
CHARACTER: SQL_CHAR,
|
|
36
|
+
LONGVARCHAR: SQL_LONGVARCHAR,
|
|
37
|
+
VARCHAR_IGNORECASE: SQL_VARCHAR_IGNORECASE,
|
|
38
|
+
DATE: SQL_DATE,
|
|
39
|
+
TIME: SQL_TIME,
|
|
40
|
+
TIMESTAMP: SQL_TIMESTAMP,
|
|
41
|
+
DATETIME: SQL_TIMESTAMP,
|
|
42
|
+
DECIMAL: SQL_DECIMAL,
|
|
43
|
+
NUMERIC: SQL_NUMERIC,
|
|
44
|
+
BIT: SQL_BOOLEAN_BIT,
|
|
45
|
+
BOOLEAN: SQL_BOOLEAN_BIT,
|
|
46
|
+
TINYINT: SQL_TINYINT,
|
|
47
|
+
SMALLINT: SQL_SMALLINT,
|
|
48
|
+
BIGINT: SQL_BIGINT
|
|
32
49
|
};
|
|
33
50
|
const UNSUPPORTED_SQL_TYPE_NAMES = /* @__PURE__ */ new Set([
|
|
34
51
|
"BINARY",
|
|
@@ -86,46 +103,62 @@ var HsqldbDataCursor = class {
|
|
|
86
103
|
return slice;
|
|
87
104
|
}
|
|
88
105
|
};
|
|
106
|
+
const HIGH_BIT = 128;
|
|
107
|
+
const UTF8_CONTINUATION_MASK = 192;
|
|
108
|
+
const UTF8_TWO_BYTE_LEAD_NIBBLE_LOW = 12;
|
|
109
|
+
const UTF8_TWO_BYTE_LEAD_NIBBLE_HIGH = 13;
|
|
110
|
+
const UTF8_TWO_BYTE_DATA_MASK = 31;
|
|
111
|
+
const UTF8_THREE_BYTE_LEAD_NIBBLE = 14;
|
|
112
|
+
const UTF8_THREE_BYTE_DATA_MASK = 15;
|
|
113
|
+
const UTF8_CONTINUATION_DATA_MASK = 63;
|
|
114
|
+
const UTF8_CONTINUATION_BITS = 6;
|
|
115
|
+
const UTF8_THREE_BYTE_SEQUENCE_LENGTH = 3;
|
|
116
|
+
const HEX_RADIX = 16;
|
|
117
|
+
const NIBBLE_BITS = 4;
|
|
89
118
|
function readModifiedUtf8(bytes) {
|
|
90
119
|
let result = "";
|
|
91
120
|
let i = 0;
|
|
92
121
|
while (i < bytes.length) {
|
|
93
122
|
const b0 = bytes[i];
|
|
94
123
|
if (b0 === void 0) throw new HsqldbRowFormatError("truncated modified-UTF-8 byte sequence");
|
|
95
|
-
if (b0 > 0 && b0 <
|
|
124
|
+
if (b0 > 0 && b0 < HIGH_BIT) {
|
|
96
125
|
result += String.fromCharCode(b0);
|
|
97
126
|
i += 1;
|
|
98
127
|
continue;
|
|
99
128
|
}
|
|
100
|
-
const leadNibble = b0 >>
|
|
101
|
-
if (leadNibble ===
|
|
129
|
+
const leadNibble = b0 >> NIBBLE_BITS;
|
|
130
|
+
if (leadNibble === UTF8_TWO_BYTE_LEAD_NIBBLE_LOW || leadNibble === UTF8_TWO_BYTE_LEAD_NIBBLE_HIGH) {
|
|
102
131
|
const b1 = bytes[i + 1];
|
|
103
|
-
if (b1 === void 0 || (b1 &
|
|
104
|
-
result += String.fromCharCode((b0 &
|
|
132
|
+
if (b1 === void 0 || (b1 & UTF8_CONTINUATION_MASK) !== HIGH_BIT) throw new HsqldbRowFormatError("malformed modified-UTF-8 2-byte sequence");
|
|
133
|
+
result += String.fromCharCode((b0 & UTF8_TWO_BYTE_DATA_MASK) << UTF8_CONTINUATION_BITS | b1 & UTF8_CONTINUATION_DATA_MASK);
|
|
105
134
|
i += 2;
|
|
106
135
|
continue;
|
|
107
136
|
}
|
|
108
|
-
if (leadNibble ===
|
|
137
|
+
if (leadNibble === UTF8_THREE_BYTE_LEAD_NIBBLE) {
|
|
109
138
|
const b1 = bytes[i + 1];
|
|
110
139
|
const b2 = bytes[i + 2];
|
|
111
|
-
if (b1 === void 0 || b2 === void 0 || (b1 &
|
|
112
|
-
result += String.fromCharCode((b0 &
|
|
113
|
-
i +=
|
|
140
|
+
if (b1 === void 0 || b2 === void 0 || (b1 & UTF8_CONTINUATION_MASK) !== HIGH_BIT || (b2 & UTF8_CONTINUATION_MASK) !== HIGH_BIT) throw new HsqldbRowFormatError("malformed modified-UTF-8 3-byte sequence");
|
|
141
|
+
result += String.fromCharCode((b0 & UTF8_THREE_BYTE_DATA_MASK) << 12 | (b1 & UTF8_CONTINUATION_DATA_MASK) << UTF8_CONTINUATION_BITS | b2 & UTF8_CONTINUATION_DATA_MASK);
|
|
142
|
+
i += UTF8_THREE_BYTE_SEQUENCE_LENGTH;
|
|
114
143
|
continue;
|
|
115
144
|
}
|
|
116
|
-
throw new HsqldbRowFormatError(`malformed modified-UTF-8 lead byte 0x${b0.toString(
|
|
145
|
+
throw new HsqldbRowFormatError(`malformed modified-UTF-8 lead byte 0x${b0.toString(HEX_RADIX)}`);
|
|
117
146
|
}
|
|
118
147
|
return result;
|
|
119
148
|
}
|
|
149
|
+
const ZERO_BIGINT = 0n;
|
|
150
|
+
const ONE_BIGINT = 1n;
|
|
151
|
+
const BITS_PER_BYTE = 8;
|
|
152
|
+
const BITS_PER_BYTE_BIGINT = 8n;
|
|
120
153
|
function signedBigIntFromBytes(bytes) {
|
|
121
|
-
if (bytes.length === 0) return
|
|
122
|
-
let magnitude =
|
|
123
|
-
for (const byte of bytes) magnitude = magnitude <<
|
|
154
|
+
if (bytes.length === 0) return ZERO_BIGINT;
|
|
155
|
+
let magnitude = ZERO_BIGINT;
|
|
156
|
+
for (const byte of bytes) magnitude = magnitude << BITS_PER_BYTE_BIGINT | BigInt(byte);
|
|
124
157
|
const firstByte = bytes[0];
|
|
125
|
-
return firstByte !== void 0 && (firstByte &
|
|
158
|
+
return firstByte !== void 0 && (firstByte & HIGH_BIT) !== 0 ? magnitude - (ONE_BIGINT << BigInt(BITS_PER_BYTE * bytes.length)) : magnitude;
|
|
126
159
|
}
|
|
127
160
|
function exactDecimalDigits(unscaled, scale) {
|
|
128
|
-
const isNegative = unscaled <
|
|
161
|
+
const isNegative = unscaled < ZERO_BIGINT;
|
|
129
162
|
const magnitudeDigits = (isNegative ? -unscaled : unscaled).toString();
|
|
130
163
|
const sign = isNegative ? "-" : "";
|
|
131
164
|
if (scale <= 0) return `${sign}${magnitudeDigits}${"0".repeat(-scale)}`;
|
|
@@ -194,73 +227,76 @@ function calendarFieldsAt(epochMillis, timeZone) {
|
|
|
194
227
|
seconds: requiredPart(parts, "second", timeZone)
|
|
195
228
|
};
|
|
196
229
|
}
|
|
230
|
+
const MILLIS_PER_SECOND_BIGINT = 1000n;
|
|
197
231
|
function millisOfSecond(epochMillis) {
|
|
198
|
-
return Number((epochMillis %
|
|
232
|
+
return Number((epochMillis % MILLIS_PER_SECOND_BIGINT + MILLIS_PER_SECOND_BIGINT) % MILLIS_PER_SECOND_BIGINT);
|
|
199
233
|
}
|
|
200
234
|
function formatDate(epochMillis, timeZone) {
|
|
201
235
|
const { year, month, day } = calendarFieldsAt(epochMillis, timeZone);
|
|
202
236
|
return `${year}-${pad2(month)}-${pad2(day)}`;
|
|
203
237
|
}
|
|
238
|
+
const MILLIS_DIGIT_WIDTH = 3;
|
|
204
239
|
function formatTime(epochMillis, timeZone) {
|
|
205
240
|
const { hours, minutes, seconds } = calendarFieldsAt(epochMillis, timeZone);
|
|
206
241
|
const base = `${pad2(hours)}:${pad2(minutes)}:${pad2(seconds)}`;
|
|
207
242
|
const millis = millisOfSecond(epochMillis);
|
|
208
|
-
return millis === 0 ? base : `${base}.${String(millis).padStart(
|
|
243
|
+
return millis === 0 ? base : `${base}.${String(millis).padStart(MILLIS_DIGIT_WIDTH, "0")}`;
|
|
209
244
|
}
|
|
245
|
+
const NANOS_DIGIT_WIDTH = 9;
|
|
210
246
|
function formatTimestamp(epochMillis, nanos, timeZone) {
|
|
211
247
|
const { year, month, day, hours, minutes, seconds } = calendarFieldsAt(epochMillis, timeZone);
|
|
212
248
|
const base = `${year}-${pad2(month)}-${pad2(day)} ${pad2(hours)}:${pad2(minutes)}:${pad2(seconds)}`;
|
|
213
|
-
return nanos === 0 ? base : `${base}.${String(nanos).padStart(
|
|
249
|
+
return nanos === 0 ? base : `${base}.${String(nanos).padStart(NANOS_DIGIT_WIDTH, "0")}`;
|
|
214
250
|
}
|
|
215
251
|
function readHsqldbColumnValue(cursor, typeCode, options) {
|
|
216
252
|
if (cursor.readUint8() === 0) return { kind: "empty" };
|
|
217
253
|
switch (typeCode) {
|
|
218
|
-
case
|
|
219
|
-
case
|
|
220
|
-
case
|
|
221
|
-
case
|
|
254
|
+
case SQL_CHAR:
|
|
255
|
+
case SQL_VARCHAR:
|
|
256
|
+
case SQL_LONGVARCHAR:
|
|
257
|
+
case SQL_VARCHAR_IGNORECASE: {
|
|
222
258
|
const byteLength = cursor.readInt32();
|
|
223
259
|
return {
|
|
224
260
|
kind: "string",
|
|
225
261
|
value: readModifiedUtf8(cursor.readBytes(byteLength))
|
|
226
262
|
};
|
|
227
263
|
}
|
|
228
|
-
case
|
|
229
|
-
case
|
|
264
|
+
case SQL_SMALLINT:
|
|
265
|
+
case SQL_TINYINT: return {
|
|
230
266
|
kind: "number",
|
|
231
267
|
value: cursor.readInt16()
|
|
232
268
|
};
|
|
233
|
-
case
|
|
269
|
+
case SQL_INTEGER: return {
|
|
234
270
|
kind: "number",
|
|
235
271
|
value: cursor.readInt32()
|
|
236
272
|
};
|
|
237
|
-
case
|
|
238
|
-
case
|
|
239
|
-
case
|
|
240
|
-
case
|
|
273
|
+
case SQL_BIGINT: return numericCellValue(cursor.readBigInt64(), 0);
|
|
274
|
+
case SQL_FLOAT:
|
|
275
|
+
case SQL_REAL:
|
|
276
|
+
case SQL_DOUBLE: return {
|
|
241
277
|
kind: "number",
|
|
242
278
|
value: cursor.readFloat64()
|
|
243
279
|
};
|
|
244
|
-
case
|
|
245
|
-
case
|
|
280
|
+
case SQL_NUMERIC:
|
|
281
|
+
case SQL_DECIMAL: {
|
|
246
282
|
const byteLength = cursor.readInt32();
|
|
247
283
|
const magnitudeBytes = cursor.readBytes(byteLength);
|
|
248
284
|
const scale = cursor.readInt32();
|
|
249
285
|
return numericCellValue(signedBigIntFromBytes(magnitudeBytes), scale);
|
|
250
286
|
}
|
|
251
|
-
case
|
|
287
|
+
case SQL_BOOLEAN_BIT: return {
|
|
252
288
|
kind: "boolean",
|
|
253
289
|
value: cursor.readUint8() !== 0
|
|
254
290
|
};
|
|
255
|
-
case
|
|
291
|
+
case SQL_DATE: return {
|
|
256
292
|
kind: "date",
|
|
257
293
|
value: formatDate(cursor.readBigInt64(), options?.timeZone)
|
|
258
294
|
};
|
|
259
|
-
case
|
|
295
|
+
case SQL_TIME: return {
|
|
260
296
|
kind: "time",
|
|
261
297
|
value: formatTime(cursor.readBigInt64(), options?.timeZone)
|
|
262
298
|
};
|
|
263
|
-
case
|
|
299
|
+
case SQL_TIMESTAMP: return {
|
|
264
300
|
kind: "date",
|
|
265
301
|
value: formatTimestamp(cursor.readBigInt64(), cursor.readInt32(), options?.timeZone)
|
|
266
302
|
};
|