@nocobase/plugin-multi-app-manager 1.2.12-alpha → 1.3.0-alpha.20240710084543
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 +2 -2
- package/dist/client/AppManager.d.ts +0 -10
- package/dist/client/AppNameInput.d.ts +0 -10
- package/dist/client/MultiAppManagerProvider.d.ts +0 -10
- package/dist/client/MultiAppManagerProvider.style.d.ts +0 -13
- package/dist/client/Settings.d.ts +0 -10
- package/dist/client/index.d.ts +0 -14
- package/dist/client/index.js +0 -10
- package/dist/client/settings/schemas/applications.d.ts +0 -18
- package/dist/client/utils.d.ts +0 -12
- package/dist/externalVersion.js +0 -25
- package/dist/index.d.ts +0 -10
- package/dist/index.js +0 -48
- package/dist/locale/en-US.json +0 -11
- package/dist/locale/es-ES.json +0 -9
- package/dist/locale/index.d.ts +0 -9
- package/dist/locale/index.js +0 -36
- package/dist/locale/ko_KR.json +0 -11
- package/dist/locale/pt-BR.json +0 -9
- package/dist/locale/zh-CN.json +0 -14
- package/dist/node_modules/mariadb/LICENSE +0 -502
- package/dist/node_modules/mariadb/callback.js +0 -41
- package/dist/node_modules/mariadb/lib/cmd/batch-bulk.js +0 -278
- package/dist/node_modules/mariadb/lib/cmd/batch-rewrite.js +0 -372
- package/dist/node_modules/mariadb/lib/cmd/change-user.js +0 -149
- package/dist/node_modules/mariadb/lib/cmd/class/ok-packet.js +0 -17
- package/dist/node_modules/mariadb/lib/cmd/column-definition.js +0 -102
- package/dist/node_modules/mariadb/lib/cmd/command.js +0 -168
- package/dist/node_modules/mariadb/lib/cmd/common-binary-cmd.js +0 -327
- package/dist/node_modules/mariadb/lib/cmd/common-text-cmd.js +0 -427
- package/dist/node_modules/mariadb/lib/cmd/handshake/auth/caching-sha2-password-auth.js +0 -168
- package/dist/node_modules/mariadb/lib/cmd/handshake/auth/clear-password-auth.js +0 -23
- package/dist/node_modules/mariadb/lib/cmd/handshake/auth/ed25519-password-auth.js +0 -761
- package/dist/node_modules/mariadb/lib/cmd/handshake/auth/native-password-auth.js +0 -55
- package/dist/node_modules/mariadb/lib/cmd/handshake/auth/pam-password-auth.js +0 -58
- package/dist/node_modules/mariadb/lib/cmd/handshake/auth/plugin-auth.js +0 -19
- package/dist/node_modules/mariadb/lib/cmd/handshake/auth/sha256-password-auth.js +0 -142
- package/dist/node_modules/mariadb/lib/cmd/handshake/client-capabilities.js +0 -74
- package/dist/node_modules/mariadb/lib/cmd/handshake/client-handshake-response.js +0 -126
- package/dist/node_modules/mariadb/lib/cmd/handshake/handshake.js +0 -292
- package/dist/node_modules/mariadb/lib/cmd/handshake/initial-handshake.js +0 -74
- package/dist/node_modules/mariadb/lib/cmd/handshake/ssl-request.js +0 -29
- package/dist/node_modules/mariadb/lib/cmd/ping.js +0 -52
- package/dist/node_modules/mariadb/lib/cmd/query.js +0 -255
- package/dist/node_modules/mariadb/lib/cmd/quit.js +0 -28
- package/dist/node_modules/mariadb/lib/cmd/reset.js +0 -54
- package/dist/node_modules/mariadb/lib/cmd/resultset.js +0 -607
- package/dist/node_modules/mariadb/lib/cmd/stream.js +0 -45
- package/dist/node_modules/mariadb/lib/config/connection-options.js +0 -258
- package/dist/node_modules/mariadb/lib/config/pool-cluster-options.js +0 -19
- package/dist/node_modules/mariadb/lib/config/pool-options.js +0 -47
- package/dist/node_modules/mariadb/lib/connection-callback.js +0 -160
- package/dist/node_modules/mariadb/lib/connection.js +0 -1460
- package/dist/node_modules/mariadb/lib/const/capabilities.js +0 -64
- package/dist/node_modules/mariadb/lib/const/collations.js +0 -473
- package/dist/node_modules/mariadb/lib/const/connection_status.js +0 -13
- package/dist/node_modules/mariadb/lib/const/error-code.js +0 -1282
- package/dist/node_modules/mariadb/lib/const/field-detail.js +0 -35
- package/dist/node_modules/mariadb/lib/const/field-type.js +0 -71
- package/dist/node_modules/mariadb/lib/const/server-status.js +0 -30
- package/dist/node_modules/mariadb/lib/const/state-change.js +0 -12
- package/dist/node_modules/mariadb/lib/filtered-pool-cluster.js +0 -81
- package/dist/node_modules/mariadb/lib/io/bulk-packet.js +0 -590
- package/dist/node_modules/mariadb/lib/io/compression-input-stream.js +0 -141
- package/dist/node_modules/mariadb/lib/io/compression-output-stream.js +0 -171
- package/dist/node_modules/mariadb/lib/io/packet-input-stream.js +0 -193
- package/dist/node_modules/mariadb/lib/io/packet-node-encoded.js +0 -36
- package/dist/node_modules/mariadb/lib/io/packet-node-iconv.js +0 -37
- package/dist/node_modules/mariadb/lib/io/packet-output-stream.js +0 -502
- package/dist/node_modules/mariadb/lib/io/packet.js +0 -515
- package/dist/node_modules/mariadb/lib/io/rewrite-packet.js +0 -481
- package/dist/node_modules/mariadb/lib/misc/connection-information.js +0 -96
- package/dist/node_modules/mariadb/lib/misc/errors.js +0 -123
- package/dist/node_modules/mariadb/lib/misc/parse.js +0 -1033
- package/dist/node_modules/mariadb/lib/misc/utils.js +0 -298
- package/dist/node_modules/mariadb/lib/pool-base.js +0 -611
- package/dist/node_modules/mariadb/lib/pool-callback.js +0 -202
- package/dist/node_modules/mariadb/lib/pool-cluster-callback.js +0 -66
- package/dist/node_modules/mariadb/lib/pool-cluster.js +0 -407
- package/dist/node_modules/mariadb/lib/pool-promise.js +0 -108
- package/dist/node_modules/mariadb/node_modules/@types/node/assert/strict.d.ts +0 -8
- package/dist/node_modules/mariadb/node_modules/@types/node/assert.d.ts +0 -912
- package/dist/node_modules/mariadb/node_modules/@types/node/async_hooks.d.ts +0 -501
- package/dist/node_modules/mariadb/node_modules/@types/node/buffer.d.ts +0 -2232
- package/dist/node_modules/mariadb/node_modules/@types/node/child_process.d.ts +0 -1366
- package/dist/node_modules/mariadb/node_modules/@types/node/cluster.d.ts +0 -414
- package/dist/node_modules/mariadb/node_modules/@types/node/console.d.ts +0 -412
- package/dist/node_modules/mariadb/node_modules/@types/node/constants.d.ts +0 -18
- package/dist/node_modules/mariadb/node_modules/@types/node/crypto.d.ts +0 -3338
- package/dist/node_modules/mariadb/node_modules/@types/node/dgram.d.ts +0 -545
- package/dist/node_modules/mariadb/node_modules/@types/node/diagnostics_channel.d.ts +0 -152
- package/dist/node_modules/mariadb/node_modules/@types/node/dns/promises.d.ts +0 -370
- package/dist/node_modules/mariadb/node_modules/@types/node/dns.d.ts +0 -659
- package/dist/node_modules/mariadb/node_modules/@types/node/domain.d.ts +0 -169
- package/dist/node_modules/mariadb/node_modules/@types/node/events.d.ts +0 -651
- package/dist/node_modules/mariadb/node_modules/@types/node/fs/promises.d.ts +0 -1091
- package/dist/node_modules/mariadb/node_modules/@types/node/fs.d.ts +0 -3869
- package/dist/node_modules/mariadb/node_modules/@types/node/globals.d.ts +0 -294
- package/dist/node_modules/mariadb/node_modules/@types/node/globals.global.d.ts +0 -1
- package/dist/node_modules/mariadb/node_modules/@types/node/http.d.ts +0 -1396
- package/dist/node_modules/mariadb/node_modules/@types/node/http2.d.ts +0 -2101
- package/dist/node_modules/mariadb/node_modules/@types/node/https.d.ts +0 -391
- package/dist/node_modules/mariadb/node_modules/@types/node/index.d.ts +0 -129
- package/dist/node_modules/mariadb/node_modules/@types/node/inspector.d.ts +0 -2744
- package/dist/node_modules/mariadb/node_modules/@types/node/module.d.ts +0 -114
- package/dist/node_modules/mariadb/node_modules/@types/node/net.d.ts +0 -791
- package/dist/node_modules/mariadb/node_modules/@types/node/os.d.ts +0 -455
- package/dist/node_modules/mariadb/node_modules/@types/node/package.json +0 -220
- package/dist/node_modules/mariadb/node_modules/@types/node/path.d.ts +0 -180
- package/dist/node_modules/mariadb/node_modules/@types/node/perf_hooks.d.ts +0 -557
- package/dist/node_modules/mariadb/node_modules/@types/node/process.d.ts +0 -1481
- package/dist/node_modules/mariadb/node_modules/@types/node/punycode.d.ts +0 -117
- package/dist/node_modules/mariadb/node_modules/@types/node/querystring.d.ts +0 -131
- package/dist/node_modules/mariadb/node_modules/@types/node/readline.d.ts +0 -650
- package/dist/node_modules/mariadb/node_modules/@types/node/repl.d.ts +0 -424
- package/dist/node_modules/mariadb/node_modules/@types/node/stream/consumers.d.ts +0 -24
- package/dist/node_modules/mariadb/node_modules/@types/node/stream/promises.d.ts +0 -42
- package/dist/node_modules/mariadb/node_modules/@types/node/stream/web.d.ts +0 -330
- package/dist/node_modules/mariadb/node_modules/@types/node/stream.d.ts +0 -1249
- package/dist/node_modules/mariadb/node_modules/@types/node/string_decoder.d.ts +0 -67
- package/dist/node_modules/mariadb/node_modules/@types/node/timers/promises.d.ts +0 -68
- package/dist/node_modules/mariadb/node_modules/@types/node/timers.d.ts +0 -94
- package/dist/node_modules/mariadb/node_modules/@types/node/tls.d.ts +0 -1020
- package/dist/node_modules/mariadb/node_modules/@types/node/trace_events.d.ts +0 -161
- package/dist/node_modules/mariadb/node_modules/@types/node/tty.d.ts +0 -204
- package/dist/node_modules/mariadb/node_modules/@types/node/url.d.ts +0 -891
- package/dist/node_modules/mariadb/node_modules/@types/node/util.d.ts +0 -1594
- package/dist/node_modules/mariadb/node_modules/@types/node/v8.d.ts +0 -378
- package/dist/node_modules/mariadb/node_modules/@types/node/vm.d.ts +0 -507
- package/dist/node_modules/mariadb/node_modules/@types/node/wasi.d.ts +0 -158
- package/dist/node_modules/mariadb/node_modules/@types/node/worker_threads.d.ts +0 -649
- package/dist/node_modules/mariadb/node_modules/@types/node/zlib.d.ts +0 -517
- package/dist/node_modules/mariadb/node_modules/iconv-lite/.github/dependabot.yml +0 -11
- package/dist/node_modules/mariadb/node_modules/iconv-lite/.idea/codeStyles/Project.xml +0 -47
- package/dist/node_modules/mariadb/node_modules/iconv-lite/.idea/codeStyles/codeStyleConfig.xml +0 -5
- package/dist/node_modules/mariadb/node_modules/iconv-lite/.idea/iconv-lite.iml +0 -12
- package/dist/node_modules/mariadb/node_modules/iconv-lite/.idea/inspectionProfiles/Project_Default.xml +0 -6
- package/dist/node_modules/mariadb/node_modules/iconv-lite/.idea/modules.xml +0 -8
- package/dist/node_modules/mariadb/node_modules/iconv-lite/.idea/vcs.xml +0 -6
- package/dist/node_modules/mariadb/node_modules/iconv-lite/encodings/dbcs-codec.js +0 -597
- package/dist/node_modules/mariadb/node_modules/iconv-lite/encodings/dbcs-data.js +0 -188
- package/dist/node_modules/mariadb/node_modules/iconv-lite/encodings/index.js +0 -23
- package/dist/node_modules/mariadb/node_modules/iconv-lite/encodings/internal.js +0 -198
- package/dist/node_modules/mariadb/node_modules/iconv-lite/encodings/sbcs-codec.js +0 -72
- package/dist/node_modules/mariadb/node_modules/iconv-lite/encodings/sbcs-data-generated.js +0 -451
- package/dist/node_modules/mariadb/node_modules/iconv-lite/encodings/sbcs-data.js +0 -179
- package/dist/node_modules/mariadb/node_modules/iconv-lite/encodings/tables/big5-added.json +0 -122
- package/dist/node_modules/mariadb/node_modules/iconv-lite/encodings/tables/cp936.json +0 -264
- package/dist/node_modules/mariadb/node_modules/iconv-lite/encodings/tables/cp949.json +0 -273
- package/dist/node_modules/mariadb/node_modules/iconv-lite/encodings/tables/cp950.json +0 -177
- package/dist/node_modules/mariadb/node_modules/iconv-lite/encodings/tables/eucjp.json +0 -182
- package/dist/node_modules/mariadb/node_modules/iconv-lite/encodings/tables/gb18030-ranges.json +0 -1
- package/dist/node_modules/mariadb/node_modules/iconv-lite/encodings/tables/gbk-added.json +0 -56
- package/dist/node_modules/mariadb/node_modules/iconv-lite/encodings/tables/shiftjis.json +0 -125
- package/dist/node_modules/mariadb/node_modules/iconv-lite/encodings/utf16.js +0 -197
- package/dist/node_modules/mariadb/node_modules/iconv-lite/encodings/utf32.js +0 -319
- package/dist/node_modules/mariadb/node_modules/iconv-lite/encodings/utf7.js +0 -290
- package/dist/node_modules/mariadb/node_modules/iconv-lite/lib/bom-handling.js +0 -52
- package/dist/node_modules/mariadb/node_modules/iconv-lite/lib/index.d.ts +0 -41
- package/dist/node_modules/mariadb/node_modules/iconv-lite/lib/index.js +0 -180
- package/dist/node_modules/mariadb/node_modules/iconv-lite/lib/streams.js +0 -109
- package/dist/node_modules/mariadb/node_modules/iconv-lite/package.json +0 -44
- package/dist/node_modules/mariadb/package.json +0 -1
- package/dist/node_modules/mariadb/promise.js +0 -34
- package/dist/node_modules/mariadb/types/index.d.ts +0 -870
- package/dist/server/collections/applications.d.ts +0 -10
- package/dist/server/collections/applications.js +0 -75
- package/dist/server/index.d.ts +0 -11
- package/dist/server/index.js +0 -40
- package/dist/server/models/application.d.ts +0 -18
- package/dist/server/models/application.js +0 -50
- package/dist/server/server.d.ts +0 -26
- package/dist/server/server.js +0 -310
- package/dist/swagger/index.d.ts +0 -195
- package/dist/swagger/index.js +0 -226
|
@@ -1,502 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const Iconv = require('iconv-lite');
|
|
4
|
-
const Utils = require('../misc/utils');
|
|
5
|
-
|
|
6
|
-
const QUOTE = 0x27;
|
|
7
|
-
const DBL_QUOTE = 0x22;
|
|
8
|
-
const ZERO_BYTE = 0x00;
|
|
9
|
-
const SLASH = 0x5c;
|
|
10
|
-
|
|
11
|
-
//increase by level to avoid buffer copy.
|
|
12
|
-
const SMALL_BUFFER_SIZE = 1024;
|
|
13
|
-
const MEDIUM_BUFFER_SIZE = 16384; //16k
|
|
14
|
-
const LARGE_BUFFER_SIZE = 131072; //128k
|
|
15
|
-
const BIG_BUFFER_SIZE = 1048576; //1M
|
|
16
|
-
const MAX_BUFFER_SIZE = 16777219; //16M + 4
|
|
17
|
-
const CHARS_GLOBAL_REGEXP = /[\0\"\'\\\b\n\r\t\u001A]/g; // eslint-disable-line no-control-regex
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* MySQL packet builder.
|
|
21
|
-
*
|
|
22
|
-
* @param opts options
|
|
23
|
-
* @param info connection info
|
|
24
|
-
* @constructor
|
|
25
|
-
*/
|
|
26
|
-
class PacketOutputStream {
|
|
27
|
-
constructor(opts, info) {
|
|
28
|
-
this.opts = opts;
|
|
29
|
-
this.info = info;
|
|
30
|
-
this.pos = 4;
|
|
31
|
-
this.buf = Buffer.allocUnsafe(SMALL_BUFFER_SIZE);
|
|
32
|
-
this.changeEncoding(this.opts.collation);
|
|
33
|
-
this.changeDebug(this.opts.logPackets, this.opts.debug);
|
|
34
|
-
|
|
35
|
-
this.opts.on('collation', this.changeEncoding.bind(this));
|
|
36
|
-
this.opts.on('debug', this.changeDebug.bind(this));
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
changeEncoding(collation) {
|
|
40
|
-
this.encoding = collation.charset;
|
|
41
|
-
if (this.encoding === 'utf8') {
|
|
42
|
-
this.writeString = this.writeDefaultBufferString;
|
|
43
|
-
this.writeStringEscapeQuote = this.writeUtf8StringEscapeQuote;
|
|
44
|
-
} else if (Buffer.isEncoding(this.encoding)) {
|
|
45
|
-
this.writeString = this.writeDefaultBufferString;
|
|
46
|
-
this.writeStringEscapeQuote = this.writeDefaultStringEscapeQuote;
|
|
47
|
-
} else {
|
|
48
|
-
this.writeString = this.writeDefaultIconvString;
|
|
49
|
-
this.writeStringEscapeQuote = this.writeDefaultStringEscapeQuote;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
changeDebug(logPackets, debug) {
|
|
54
|
-
this.logPackets = logPackets;
|
|
55
|
-
this.debug = debug;
|
|
56
|
-
this.flushBuffer =
|
|
57
|
-
this.logPackets || this.debug ? this.flushBufferDebug : this.flushBufferBasic;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
setStream(stream) {
|
|
61
|
-
this.stream = stream;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
growBuffer(len) {
|
|
65
|
-
let newCapacity;
|
|
66
|
-
if (len + this.pos < MEDIUM_BUFFER_SIZE) {
|
|
67
|
-
newCapacity = MEDIUM_BUFFER_SIZE;
|
|
68
|
-
} else if (len + this.pos < LARGE_BUFFER_SIZE) {
|
|
69
|
-
newCapacity = LARGE_BUFFER_SIZE;
|
|
70
|
-
} else if (len + this.pos < BIG_BUFFER_SIZE) {
|
|
71
|
-
newCapacity = BIG_BUFFER_SIZE;
|
|
72
|
-
} else newCapacity = MAX_BUFFER_SIZE;
|
|
73
|
-
|
|
74
|
-
let newBuf = Buffer.allocUnsafe(newCapacity);
|
|
75
|
-
this.buf.copy(newBuf, 0, 0, this.pos);
|
|
76
|
-
this.buf = newBuf;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
startPacket(cmd) {
|
|
80
|
-
this.cmd = cmd;
|
|
81
|
-
this.pos = 4;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
writeInt8(value) {
|
|
85
|
-
if (this.pos + 1 >= this.buf.length) {
|
|
86
|
-
if (this.pos >= MAX_BUFFER_SIZE) {
|
|
87
|
-
//buffer is more than a Packet, must flushBuffer()
|
|
88
|
-
this.flushBuffer(false, 1);
|
|
89
|
-
} else this.growBuffer(1);
|
|
90
|
-
}
|
|
91
|
-
this.buf[this.pos++] = value;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
writeInt16(value) {
|
|
95
|
-
if (this.pos + 2 >= this.buf.length) {
|
|
96
|
-
let b = Buffer.allocUnsafe(2);
|
|
97
|
-
b.writeUInt16LE(value, 0);
|
|
98
|
-
this.writeBuffer(b, 0, 2);
|
|
99
|
-
return;
|
|
100
|
-
}
|
|
101
|
-
this.buf[this.pos] = value;
|
|
102
|
-
this.buf[this.pos + 1] = value >> 8;
|
|
103
|
-
this.pos += 2;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
writeInt16AtPos(initPos) {
|
|
107
|
-
this.buf[initPos] = this.pos - initPos - 2;
|
|
108
|
-
this.buf[initPos + 1] = (this.pos - initPos - 2) >> 8;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
writeInt32(value) {
|
|
112
|
-
if (this.pos + 4 >= this.buf.length) {
|
|
113
|
-
//not enough space remaining
|
|
114
|
-
let arr = Buffer.allocUnsafe(4);
|
|
115
|
-
arr.writeInt32LE(value, 0);
|
|
116
|
-
this.writeBuffer(arr, 0, 4);
|
|
117
|
-
return;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
this.buf[this.pos] = value;
|
|
121
|
-
this.buf[this.pos + 1] = value >> 8;
|
|
122
|
-
this.buf[this.pos + 2] = value >> 16;
|
|
123
|
-
this.buf[this.pos + 3] = value >> 24;
|
|
124
|
-
this.pos += 4;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
writeLengthCoded(len) {
|
|
128
|
-
//length encoded can be null(0xfb) or bigger than 65k, but only if using binary protocol
|
|
129
|
-
//so not implemented for now
|
|
130
|
-
if (len < 0xfb) {
|
|
131
|
-
this.writeInt8(len);
|
|
132
|
-
return;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
//max length is len < 0xffff
|
|
136
|
-
this.writeInt8(0xfc);
|
|
137
|
-
this.writeInt16(len);
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
writeBuffer(arr, off, len) {
|
|
141
|
-
if (len > this.buf.length - this.pos) {
|
|
142
|
-
if (this.buf.length !== MAX_BUFFER_SIZE) {
|
|
143
|
-
this.growBuffer(len);
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
//max buffer size
|
|
147
|
-
if (len > this.buf.length - this.pos) {
|
|
148
|
-
//not enough space in buffer, will stream :
|
|
149
|
-
// fill buffer and flush until all data are snd
|
|
150
|
-
let remainingLen = len;
|
|
151
|
-
|
|
152
|
-
while (true) {
|
|
153
|
-
//filling buffer
|
|
154
|
-
let lenToFillBuffer = Math.min(MAX_BUFFER_SIZE - this.pos, remainingLen);
|
|
155
|
-
arr.copy(this.buf, this.pos, off, off + lenToFillBuffer);
|
|
156
|
-
remainingLen -= lenToFillBuffer;
|
|
157
|
-
off += lenToFillBuffer;
|
|
158
|
-
this.pos += lenToFillBuffer;
|
|
159
|
-
|
|
160
|
-
if (remainingLen === 0) return;
|
|
161
|
-
this.flushBuffer(false, remainingLen);
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
arr.copy(this.buf, this.pos, off, off + len);
|
|
166
|
-
this.pos += len;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
/**
|
|
170
|
-
* Write ascii string to socket (no escaping)
|
|
171
|
-
*
|
|
172
|
-
* @param str string
|
|
173
|
-
*/
|
|
174
|
-
writeStringAscii(str) {
|
|
175
|
-
let len = str.length;
|
|
176
|
-
|
|
177
|
-
//not enough space remaining
|
|
178
|
-
if (len >= this.buf.length - this.pos) {
|
|
179
|
-
let strBuf = Buffer.from(str, 'ascii');
|
|
180
|
-
this.writeBuffer(strBuf, 0, strBuf.length);
|
|
181
|
-
return;
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
for (let off = 0; off < len; ) {
|
|
185
|
-
this.buf[this.pos++] = str.charCodeAt(off++);
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
writeUtf8StringEscapeQuote(str) {
|
|
190
|
-
const charsLength = str.length;
|
|
191
|
-
|
|
192
|
-
//not enough space remaining
|
|
193
|
-
if (charsLength * 3 + 2 >= this.buf.length - this.pos) {
|
|
194
|
-
const arr = Buffer.from(str, 'utf8');
|
|
195
|
-
this.writeInt8(QUOTE);
|
|
196
|
-
this.writeBufferEscape(arr);
|
|
197
|
-
this.writeInt8(QUOTE);
|
|
198
|
-
return;
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
//create UTF-8 byte array
|
|
202
|
-
//since javascript char are internally using UTF-16 using surrogate's pattern, 4 bytes unicode characters will
|
|
203
|
-
//represent 2 characters : example "\uD83C\uDFA4" = 🎤 unicode 8 "no microphones"
|
|
204
|
-
//so max size is 3 * charLength
|
|
205
|
-
//(escape characters are 1 byte encoded, so length might only be 2 when escaped)
|
|
206
|
-
// + 2 for the quotes for text protocol
|
|
207
|
-
let charsOffset = 0;
|
|
208
|
-
let currChar;
|
|
209
|
-
this.buf[this.pos++] = QUOTE;
|
|
210
|
-
//quick loop if only ASCII chars for faster escape
|
|
211
|
-
for (
|
|
212
|
-
;
|
|
213
|
-
charsOffset < charsLength && (currChar = str.charCodeAt(charsOffset)) < 0x80;
|
|
214
|
-
charsOffset++
|
|
215
|
-
) {
|
|
216
|
-
if (
|
|
217
|
-
currChar === SLASH ||
|
|
218
|
-
currChar === QUOTE ||
|
|
219
|
-
currChar === ZERO_BYTE ||
|
|
220
|
-
currChar === DBL_QUOTE
|
|
221
|
-
) {
|
|
222
|
-
this.buf[this.pos++] = SLASH;
|
|
223
|
-
}
|
|
224
|
-
this.buf[this.pos++] = currChar;
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
//if quick loop not finished
|
|
228
|
-
while (charsOffset < charsLength) {
|
|
229
|
-
currChar = str.charCodeAt(charsOffset++);
|
|
230
|
-
if (currChar < 0x80) {
|
|
231
|
-
if (
|
|
232
|
-
currChar === SLASH ||
|
|
233
|
-
currChar === QUOTE ||
|
|
234
|
-
currChar === ZERO_BYTE ||
|
|
235
|
-
currChar === DBL_QUOTE
|
|
236
|
-
) {
|
|
237
|
-
this.buf[this.pos++] = SLASH;
|
|
238
|
-
}
|
|
239
|
-
this.buf[this.pos++] = currChar;
|
|
240
|
-
} else if (currChar < 0x800) {
|
|
241
|
-
this.buf[this.pos++] = 0xc0 | (currChar >> 6);
|
|
242
|
-
this.buf[this.pos++] = 0x80 | (currChar & 0x3f);
|
|
243
|
-
} else if (currChar >= 0xd800 && currChar < 0xe000) {
|
|
244
|
-
//reserved for surrogate - see https://en.wikipedia.org/wiki/UTF-16
|
|
245
|
-
if (currChar < 0xdc00) {
|
|
246
|
-
//is high surrogate
|
|
247
|
-
if (charsOffset + 1 > charsLength) {
|
|
248
|
-
this.buf[this.pos++] = 0x3f;
|
|
249
|
-
} else {
|
|
250
|
-
const nextChar = str.charCodeAt(charsOffset);
|
|
251
|
-
if (nextChar >= 0xdc00 && nextChar < 0xe000) {
|
|
252
|
-
//is low surrogate
|
|
253
|
-
const surrogatePairs =
|
|
254
|
-
(currChar << 10) + nextChar + (0x010000 - (0xd800 << 10) - 0xdc00);
|
|
255
|
-
this.buf[this.pos++] = 0xf0 | (surrogatePairs >> 18);
|
|
256
|
-
this.buf[this.pos++] = 0x80 | ((surrogatePairs >> 12) & 0x3f);
|
|
257
|
-
this.buf[this.pos++] = 0x80 | ((surrogatePairs >> 6) & 0x3f);
|
|
258
|
-
this.buf[this.pos++] = 0x80 | (surrogatePairs & 0x3f);
|
|
259
|
-
charsOffset++;
|
|
260
|
-
} else {
|
|
261
|
-
//must have low surrogate
|
|
262
|
-
this.buf[this.pos++] = 0x3f;
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
} else {
|
|
266
|
-
//low surrogate without high surrogate before
|
|
267
|
-
this.buf[this.pos++] = 0x3f;
|
|
268
|
-
}
|
|
269
|
-
} else {
|
|
270
|
-
this.buf[this.pos++] = 0xe0 | (currChar >> 12);
|
|
271
|
-
this.buf[this.pos++] = 0x80 | ((currChar >> 6) & 0x3f);
|
|
272
|
-
this.buf[this.pos++] = 0x80 | (currChar & 0x3f);
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
this.buf[this.pos++] = QUOTE;
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
writeDefaultBufferString(str) {
|
|
279
|
-
//javascript use UCS-2 or UTF-16 string internal representation
|
|
280
|
-
//that means that string to byte will be a maximum of * 3
|
|
281
|
-
// (4 bytes utf-8 are represented on 2 UTF-16 characters)
|
|
282
|
-
if (str.length * 3 < this.buf.length - this.pos) {
|
|
283
|
-
this.pos += this.buf.write(str, this.pos, this.encoding);
|
|
284
|
-
return;
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
//checking real length
|
|
288
|
-
let byteLength = Buffer.byteLength(str, this.encoding);
|
|
289
|
-
if (byteLength > this.buf.length - this.pos) {
|
|
290
|
-
if (this.buf.length < MAX_BUFFER_SIZE) {
|
|
291
|
-
this.growBuffer(byteLength);
|
|
292
|
-
}
|
|
293
|
-
if (byteLength > this.buf.length - this.pos) {
|
|
294
|
-
//not enough space in buffer, will stream :
|
|
295
|
-
let strBuf = Buffer.from(str, this.encoding);
|
|
296
|
-
this.writeBuffer(strBuf, 0, strBuf.length);
|
|
297
|
-
return;
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
this.pos += this.buf.write(str, this.pos, this.encoding);
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
writeDefaultIconvString(str) {
|
|
304
|
-
let buf = Iconv.encode(str, this.encoding);
|
|
305
|
-
this.writeBuffer(buf, 0, buf.length);
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
/**
|
|
309
|
-
* Parameters need to be properly escaped :
|
|
310
|
-
* following characters are to be escaped by "\" :
|
|
311
|
-
* - \0
|
|
312
|
-
* - \\
|
|
313
|
-
* - \'
|
|
314
|
-
* - \"
|
|
315
|
-
* regex split part of string writing part, and escaping special char.
|
|
316
|
-
* Those chars are <= 7f meaning that this will work even with multi-byte encoding
|
|
317
|
-
*
|
|
318
|
-
* @param str string to escape.
|
|
319
|
-
*/
|
|
320
|
-
writeDefaultStringEscapeQuote(str) {
|
|
321
|
-
this.writeInt8(QUOTE);
|
|
322
|
-
let match;
|
|
323
|
-
let lastIndex = 0;
|
|
324
|
-
while ((match = CHARS_GLOBAL_REGEXP.exec(str)) !== null) {
|
|
325
|
-
this.writeString(str.slice(lastIndex, match.index));
|
|
326
|
-
this.writeInt8(SLASH);
|
|
327
|
-
this.writeInt8(match[0].charCodeAt(0));
|
|
328
|
-
lastIndex = CHARS_GLOBAL_REGEXP.lastIndex;
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
if (lastIndex === 0) {
|
|
332
|
-
// Nothing was escaped
|
|
333
|
-
this.writeString(str);
|
|
334
|
-
this.writeInt8(QUOTE);
|
|
335
|
-
return;
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
if (lastIndex < str.length) {
|
|
339
|
-
this.writeString(str.slice(lastIndex));
|
|
340
|
-
}
|
|
341
|
-
this.writeInt8(QUOTE);
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
writeBufferEscape(val) {
|
|
345
|
-
let valLen = val.length;
|
|
346
|
-
if (valLen * 2 > this.buf.length - this.pos) {
|
|
347
|
-
//makes buffer bigger (up to 16M)
|
|
348
|
-
if (this.buf.length !== MAX_BUFFER_SIZE) this.growBuffer(valLen * 2);
|
|
349
|
-
|
|
350
|
-
//data may still be bigger than buffer.
|
|
351
|
-
//must flush buffer when full (and reset position to 4)
|
|
352
|
-
if (valLen * 2 > this.buf.length - this.pos) {
|
|
353
|
-
//not enough space in buffer, will fill buffer
|
|
354
|
-
for (let i = 0; i < valLen; i++) {
|
|
355
|
-
switch (val[i]) {
|
|
356
|
-
case QUOTE:
|
|
357
|
-
case SLASH:
|
|
358
|
-
case DBL_QUOTE:
|
|
359
|
-
case ZERO_BYTE:
|
|
360
|
-
if (this.pos >= this.buf.length) this.flushBuffer(false, (valLen - i) * 2);
|
|
361
|
-
this.buf[this.pos++] = SLASH; //add escape slash
|
|
362
|
-
}
|
|
363
|
-
if (this.pos >= this.buf.length) this.flushBuffer(false, (valLen - i) * 2);
|
|
364
|
-
this.buf[this.pos++] = val[i];
|
|
365
|
-
}
|
|
366
|
-
return;
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
//sure to have enough place to use buffer directly
|
|
371
|
-
for (let i = 0; i < valLen; i++) {
|
|
372
|
-
switch (val[i]) {
|
|
373
|
-
case QUOTE:
|
|
374
|
-
case SLASH:
|
|
375
|
-
case DBL_QUOTE:
|
|
376
|
-
case ZERO_BYTE:
|
|
377
|
-
this.buf[this.pos++] = SLASH; //add escape slash
|
|
378
|
-
}
|
|
379
|
-
this.buf[this.pos++] = val[i];
|
|
380
|
-
}
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
/**
|
|
384
|
-
* Indicate if buffer contain any data.
|
|
385
|
-
* @returns {boolean}
|
|
386
|
-
*/
|
|
387
|
-
isEmpty() {
|
|
388
|
-
return this.pos <= 4;
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
/**
|
|
392
|
-
* Flush the internal buffer.
|
|
393
|
-
*/
|
|
394
|
-
flushBufferDebug(commandEnd, remainingLen) {
|
|
395
|
-
this.buf[0] = this.pos - 4;
|
|
396
|
-
this.buf[1] = (this.pos - 4) >>> 8;
|
|
397
|
-
this.buf[2] = (this.pos - 4) >>> 16;
|
|
398
|
-
this.buf[3] = ++this.cmd.sequenceNo;
|
|
399
|
-
|
|
400
|
-
this.stream.writeBuf(this.buf.slice(0, this.pos), this.cmd);
|
|
401
|
-
|
|
402
|
-
const packet = Utils.log(this.opts, this.buf, 0, this.pos);
|
|
403
|
-
if (this.opts.logPackets) {
|
|
404
|
-
this.info.addPacket(
|
|
405
|
-
'==> conn:' +
|
|
406
|
-
(this.info.threadId ? this.info.threadId : -1) +
|
|
407
|
-
' ' +
|
|
408
|
-
this.cmd.constructor.name +
|
|
409
|
-
'(0,' +
|
|
410
|
-
this.pos +
|
|
411
|
-
')\n' +
|
|
412
|
-
packet
|
|
413
|
-
);
|
|
414
|
-
}
|
|
415
|
-
|
|
416
|
-
if (this.opts.debug) {
|
|
417
|
-
console.log(
|
|
418
|
-
'==> conn:%d %s\n%s',
|
|
419
|
-
this.info.threadId ? this.info.threadId : -1,
|
|
420
|
-
this.cmd.constructor.name + '(0,' + this.pos + ')',
|
|
421
|
-
Utils.log(this.opts, this.buf, 0, this.pos)
|
|
422
|
-
);
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
if (commandEnd) {
|
|
426
|
-
//if last packet fill the max size, must send an empty com to indicate that command end.
|
|
427
|
-
if (this.pos === MAX_BUFFER_SIZE) {
|
|
428
|
-
this.writeEmptyPacket();
|
|
429
|
-
} else {
|
|
430
|
-
this.stream.flush(true, this.cmd);
|
|
431
|
-
this.buf = Buffer.allocUnsafe(SMALL_BUFFER_SIZE);
|
|
432
|
-
}
|
|
433
|
-
} else {
|
|
434
|
-
this.buf = allocateBuffer(remainingLen + 4);
|
|
435
|
-
this.pos = 4;
|
|
436
|
-
}
|
|
437
|
-
}
|
|
438
|
-
|
|
439
|
-
flushBufferBasic(commandEnd, remainingLen) {
|
|
440
|
-
this.buf[0] = this.pos - 4;
|
|
441
|
-
this.buf[1] = (this.pos - 4) >>> 8;
|
|
442
|
-
this.buf[2] = (this.pos - 4) >>> 16;
|
|
443
|
-
this.buf[3] = ++this.cmd.sequenceNo;
|
|
444
|
-
this.stream.writeBuf(this.buf.slice(0, this.pos), this.cmd);
|
|
445
|
-
if (commandEnd) {
|
|
446
|
-
//if last packet fill the max size, must send an empty com to indicate that command end.
|
|
447
|
-
if (this.pos === MAX_BUFFER_SIZE) {
|
|
448
|
-
this.writeEmptyPacket();
|
|
449
|
-
} else {
|
|
450
|
-
this.stream.flush(true, this.cmd);
|
|
451
|
-
this.buf = Buffer.allocUnsafe(SMALL_BUFFER_SIZE);
|
|
452
|
-
}
|
|
453
|
-
} else {
|
|
454
|
-
this.buf = allocateBuffer(remainingLen + 4);
|
|
455
|
-
this.pos = 4;
|
|
456
|
-
}
|
|
457
|
-
}
|
|
458
|
-
|
|
459
|
-
writeEmptyPacket() {
|
|
460
|
-
const emptyBuf = Buffer.from([0x00, 0x00, 0x00, ++this.cmd.sequenceNo]);
|
|
461
|
-
|
|
462
|
-
if (this.opts.logPackets || this.opts.debug) {
|
|
463
|
-
const packet = Utils.log(this.opts, emptyBuf, 0, 4);
|
|
464
|
-
if (this.opts.logPackets) {
|
|
465
|
-
this.info.addPacket(
|
|
466
|
-
'==> conn:' +
|
|
467
|
-
(this.info.threadId ? this.info.threadId : -1) +
|
|
468
|
-
' ' +
|
|
469
|
-
this.cmd.constructor.name +
|
|
470
|
-
'(0,4)\n' +
|
|
471
|
-
packet
|
|
472
|
-
);
|
|
473
|
-
}
|
|
474
|
-
if (this.opts.debug) {
|
|
475
|
-
console.log(
|
|
476
|
-
'==> conn:%d %s\n%s',
|
|
477
|
-
this.info.threadId ? this.info.threadId : -1,
|
|
478
|
-
this.cmd.constructor.name + '(0,4)',
|
|
479
|
-
packet
|
|
480
|
-
);
|
|
481
|
-
}
|
|
482
|
-
}
|
|
483
|
-
|
|
484
|
-
this.stream.writeBuf(emptyBuf, this.cmd);
|
|
485
|
-
this.stream.flush(true, this.cmd);
|
|
486
|
-
}
|
|
487
|
-
}
|
|
488
|
-
|
|
489
|
-
function allocateBuffer(len) {
|
|
490
|
-
if (len < SMALL_BUFFER_SIZE) {
|
|
491
|
-
return Buffer.allocUnsafe(SMALL_BUFFER_SIZE);
|
|
492
|
-
} else if (len < MEDIUM_BUFFER_SIZE) {
|
|
493
|
-
return Buffer.allocUnsafe(MEDIUM_BUFFER_SIZE);
|
|
494
|
-
} else if (len < LARGE_BUFFER_SIZE) {
|
|
495
|
-
return Buffer.allocUnsafe(LARGE_BUFFER_SIZE);
|
|
496
|
-
} else if (len < BIG_BUFFER_SIZE) {
|
|
497
|
-
return Buffer.allocUnsafe(BIG_BUFFER_SIZE);
|
|
498
|
-
}
|
|
499
|
-
return Buffer.allocUnsafe(MAX_BUFFER_SIZE);
|
|
500
|
-
}
|
|
501
|
-
|
|
502
|
-
module.exports = PacketOutputStream;
|