@tachybase/module-multi-app 1.6.0 → 1.6.2

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.
Files changed (105) hide show
  1. package/README.md +34 -34
  2. package/README.zh-CN.md +34 -34
  3. package/client.d.ts +1 -1
  4. package/client.js +1 -1
  5. package/dist/externalVersion.js +5 -5
  6. package/dist/locale/en-US.json +48 -48
  7. package/dist/locale/es-ES.json +9 -9
  8. package/dist/locale/ko_KR.json +11 -11
  9. package/dist/locale/pt-BR.json +9 -9
  10. package/dist/locale/zh-CN.json +58 -58
  11. package/dist/node_modules/mariadb/callback.js +43 -8
  12. package/dist/node_modules/mariadb/check-node.js +30 -0
  13. package/dist/node_modules/mariadb/lib/cluster-callback.js +84 -0
  14. package/dist/node_modules/mariadb/lib/cluster.js +446 -0
  15. package/dist/node_modules/mariadb/lib/cmd/batch-bulk.js +576 -177
  16. package/dist/node_modules/mariadb/lib/cmd/change-user.js +54 -44
  17. package/dist/node_modules/mariadb/lib/cmd/class/ok-packet.js +3 -2
  18. package/dist/node_modules/mariadb/lib/cmd/class/prepare-cache-wrapper.js +46 -0
  19. package/dist/node_modules/mariadb/lib/cmd/class/prepare-result-packet.js +141 -0
  20. package/dist/node_modules/mariadb/lib/cmd/class/prepare-wrapper.js +70 -0
  21. package/dist/node_modules/mariadb/lib/cmd/close-prepare.js +38 -0
  22. package/dist/node_modules/mariadb/lib/cmd/column-definition.js +145 -47
  23. package/dist/node_modules/mariadb/lib/cmd/command.js +41 -75
  24. package/dist/node_modules/mariadb/lib/cmd/decoder/binary-decoder.js +282 -0
  25. package/dist/node_modules/mariadb/lib/cmd/decoder/text-decoder.js +210 -0
  26. package/dist/node_modules/mariadb/lib/cmd/{common-binary-cmd.js → encoder/binary-encoder.js} +34 -77
  27. package/dist/node_modules/mariadb/lib/cmd/encoder/text-encoder.js +311 -0
  28. package/dist/node_modules/mariadb/lib/cmd/execute-stream.js +61 -0
  29. package/dist/node_modules/mariadb/lib/cmd/execute.js +338 -0
  30. package/dist/node_modules/mariadb/lib/cmd/handshake/auth/caching-sha2-password-auth.js +25 -62
  31. package/dist/node_modules/mariadb/lib/cmd/handshake/auth/clear-password-auth.js +39 -6
  32. package/dist/node_modules/mariadb/lib/cmd/handshake/auth/ed25519-password-auth.js +48 -16
  33. package/dist/node_modules/mariadb/lib/cmd/handshake/auth/handshake.js +198 -0
  34. package/dist/node_modules/mariadb/lib/cmd/handshake/{initial-handshake.js → auth/initial-handshake.js} +10 -8
  35. package/dist/node_modules/mariadb/lib/cmd/handshake/auth/native-password-auth.js +22 -9
  36. package/dist/node_modules/mariadb/lib/cmd/handshake/auth/pam-password-auth.js +9 -4
  37. package/dist/node_modules/mariadb/lib/cmd/handshake/auth/parsec-auth.js +115 -0
  38. package/dist/node_modules/mariadb/lib/cmd/handshake/auth/plugin-auth.js +12 -5
  39. package/dist/node_modules/mariadb/lib/cmd/handshake/auth/sha256-password-auth.js +44 -33
  40. package/dist/node_modules/mariadb/lib/cmd/handshake/authentication.js +335 -0
  41. package/dist/node_modules/mariadb/lib/cmd/handshake/client-capabilities.js +20 -19
  42. package/dist/node_modules/mariadb/lib/cmd/handshake/ssl-request.js +6 -3
  43. package/dist/node_modules/mariadb/lib/cmd/parser.js +861 -0
  44. package/dist/node_modules/mariadb/lib/cmd/ping.js +17 -18
  45. package/dist/node_modules/mariadb/lib/cmd/prepare.js +170 -0
  46. package/dist/node_modules/mariadb/lib/cmd/query.js +281 -144
  47. package/dist/node_modules/mariadb/lib/cmd/quit.js +9 -6
  48. package/dist/node_modules/mariadb/lib/cmd/reset.js +15 -19
  49. package/dist/node_modules/mariadb/lib/cmd/stream.js +21 -6
  50. package/dist/node_modules/mariadb/lib/config/cluster-options.js +23 -0
  51. package/dist/node_modules/mariadb/lib/config/connection-options.js +196 -132
  52. package/dist/node_modules/mariadb/lib/config/pool-options.js +27 -19
  53. package/dist/node_modules/mariadb/lib/connection-callback.js +492 -120
  54. package/dist/node_modules/mariadb/lib/connection-promise.js +372 -0
  55. package/dist/node_modules/mariadb/lib/connection.js +1739 -1016
  56. package/dist/node_modules/mariadb/lib/const/capabilities.js +36 -30
  57. package/dist/node_modules/mariadb/lib/const/collations.js +972 -36
  58. package/dist/node_modules/mariadb/lib/const/connection_status.js +3 -0
  59. package/dist/node_modules/mariadb/lib/const/error-code.js +35 -11
  60. package/dist/node_modules/mariadb/lib/const/field-detail.js +3 -0
  61. package/dist/node_modules/mariadb/lib/const/field-type.js +7 -4
  62. package/dist/node_modules/mariadb/lib/const/server-status.js +4 -1
  63. package/dist/node_modules/mariadb/lib/const/state-change.js +3 -0
  64. package/dist/node_modules/mariadb/lib/filtered-cluster-callback.js +136 -0
  65. package/dist/node_modules/mariadb/lib/filtered-cluster.js +118 -0
  66. package/dist/node_modules/mariadb/lib/io/compression-input-stream.js +14 -13
  67. package/dist/node_modules/mariadb/lib/io/compression-output-stream.js +21 -18
  68. package/dist/node_modules/mariadb/lib/io/packet-input-stream.js +75 -64
  69. package/dist/node_modules/mariadb/lib/io/packet-node-encoded.js +13 -9
  70. package/dist/node_modules/mariadb/lib/io/packet-node-iconv.js +12 -10
  71. package/dist/node_modules/mariadb/lib/io/packet-output-stream.js +402 -134
  72. package/dist/node_modules/mariadb/lib/io/packet.js +287 -202
  73. package/dist/node_modules/mariadb/lib/lru-prepare-cache.js +84 -0
  74. package/dist/node_modules/mariadb/lib/misc/connection-information.js +15 -32
  75. package/dist/node_modules/mariadb/lib/misc/errors.js +68 -25
  76. package/dist/node_modules/mariadb/lib/misc/parse.js +207 -711
  77. package/dist/node_modules/mariadb/lib/misc/utils.js +34 -62
  78. package/dist/node_modules/mariadb/lib/pool-callback.js +213 -174
  79. package/dist/node_modules/mariadb/lib/pool-promise.js +228 -94
  80. package/dist/node_modules/mariadb/lib/pool.js +951 -0
  81. package/dist/node_modules/mariadb/package.json +1 -1
  82. package/dist/node_modules/mariadb/promise.js +1 -34
  83. package/dist/node_modules/mariadb/types/callback.d.ts +207 -0
  84. package/dist/node_modules/mariadb/types/index.d.ts +94 -674
  85. package/dist/node_modules/mariadb/types/share.d.ts +804 -0
  86. package/dist/node_modules/qs/package.json +1 -1
  87. package/dist/server/actions/apps.js +2 -2
  88. package/dist/server/app-lifecycle.d.ts +1 -1
  89. package/dist/server/app-lifecycle.js +4 -4
  90. package/dist/server/models/application.d.ts +1 -1
  91. package/package.json +7 -7
  92. package/server.d.ts +2 -2
  93. package/server.js +1 -1
  94. package/dist/node_modules/mariadb/lib/cmd/batch-rewrite.js +0 -372
  95. package/dist/node_modules/mariadb/lib/cmd/common-text-cmd.js +0 -427
  96. package/dist/node_modules/mariadb/lib/cmd/handshake/client-handshake-response.js +0 -126
  97. package/dist/node_modules/mariadb/lib/cmd/handshake/handshake.js +0 -292
  98. package/dist/node_modules/mariadb/lib/cmd/resultset.js +0 -607
  99. package/dist/node_modules/mariadb/lib/config/pool-cluster-options.js +0 -19
  100. package/dist/node_modules/mariadb/lib/filtered-pool-cluster.js +0 -81
  101. package/dist/node_modules/mariadb/lib/io/bulk-packet.js +0 -590
  102. package/dist/node_modules/mariadb/lib/io/rewrite-packet.js +0 -481
  103. package/dist/node_modules/mariadb/lib/pool-base.js +0 -611
  104. package/dist/node_modules/mariadb/lib/pool-cluster-callback.js +0 -66
  105. package/dist/node_modules/mariadb/lib/pool-cluster.js +0 -407
@@ -1 +1 @@
1
- {"name":"qs","description":"A querystring parser that supports nesting and arrays, with a depth limit","homepage":"https://github.com/ljharb/qs","version":"6.14.0","repository":{"type":"git","url":"https://github.com/ljharb/qs.git"},"funding":{"url":"https://github.com/sponsors/ljharb"},"main":"lib/index.js","sideEffects":false,"contributors":[{"name":"Jordan Harband","email":"ljharb@gmail.com","url":"http://ljharb.codes"}],"keywords":["querystring","qs","query","url","parse","stringify"],"engines":{"node":">=0.6"},"dependencies":{"side-channel":"^1.1.0"},"devDependencies":{"@browserify/envify":"^6.0.0","@browserify/uglifyify":"^6.0.0","@ljharb/eslint-config":"^21.1.1","browserify":"^16.5.2","bundle-collapser":"^1.4.0","common-shakeify":"~1.0.0","eclint":"^2.8.1","es-value-fixtures":"^1.7.0","eslint":"=8.8.0","evalmd":"^0.0.19","for-each":"^0.3.3","glob":"=10.3.7","has-bigints":"^1.1.0","has-override-mistake":"^1.0.1","has-property-descriptors":"^1.0.2","has-proto":"^1.2.0","has-symbols":"^1.1.0","iconv-lite":"^0.5.1","in-publish":"^2.0.1","jackspeak":"=2.1.1","mkdirp":"^0.5.5","mock-property":"^1.1.0","module-deps":"^6.2.3","npmignore":"^0.3.1","nyc":"^10.3.2","object-inspect":"^1.13.3","qs-iconv":"^1.0.4","safe-publish-latest":"^2.0.0","safer-buffer":"^2.1.2","tape":"^5.9.0","unassertify":"^3.0.1"},"scripts":{"prepack":"npmignore --auto --commentLines=autogenerated && npm run dist","prepublishOnly":"safe-publish-latest","prepublish":"not-in-publish || npm run prepublishOnly","pretest":"npm run --silent readme && npm run --silent lint","test":"npm run tests-only","tests-only":"nyc tape 'test/**/*.js'","posttest":"npx npm@'>=10.2' audit --production","readme":"evalmd README.md","postlint":"eclint check $(git ls-files | xargs find 2> /dev/null | grep -vE 'node_modules|\\.git' | grep -v dist/)","lint":"eslint --ext=js,mjs .","dist":"mkdirp dist && browserify --standalone Qs -g unassertify -g @browserify/envify -g [@browserify/uglifyify --mangle.keep_fnames --compress.keep_fnames --format.indent_level=1 --compress.arrows=false --compress.passes=4 --compress.typeofs=false] -p common-shakeify -p bundle-collapser/plugin lib/index.js > dist/qs.js"},"license":"BSD-3-Clause","publishConfig":{"ignore":["!dist/*","bower.json","component.json",".github/workflows","logos","tea.yaml"]},"_lastModified":"2025-11-20T08:10:04.233Z"}
1
+ {"name":"qs","description":"A querystring parser that supports nesting and arrays, with a depth limit","homepage":"https://github.com/ljharb/qs","version":"6.14.0","repository":{"type":"git","url":"https://github.com/ljharb/qs.git"},"funding":{"url":"https://github.com/sponsors/ljharb"},"main":"lib/index.js","sideEffects":false,"contributors":[{"name":"Jordan Harband","email":"ljharb@gmail.com","url":"http://ljharb.codes"}],"keywords":["querystring","qs","query","url","parse","stringify"],"engines":{"node":">=0.6"},"dependencies":{"side-channel":"^1.1.0"},"devDependencies":{"@browserify/envify":"^6.0.0","@browserify/uglifyify":"^6.0.0","@ljharb/eslint-config":"^21.1.1","browserify":"^16.5.2","bundle-collapser":"^1.4.0","common-shakeify":"~1.0.0","eclint":"^2.8.1","es-value-fixtures":"^1.7.0","eslint":"=8.8.0","evalmd":"^0.0.19","for-each":"^0.3.3","glob":"=10.3.7","has-bigints":"^1.1.0","has-override-mistake":"^1.0.1","has-property-descriptors":"^1.0.2","has-proto":"^1.2.0","has-symbols":"^1.1.0","iconv-lite":"^0.5.1","in-publish":"^2.0.1","jackspeak":"=2.1.1","mkdirp":"^0.5.5","mock-property":"^1.1.0","module-deps":"^6.2.3","npmignore":"^0.3.1","nyc":"^10.3.2","object-inspect":"^1.13.3","qs-iconv":"^1.0.4","safe-publish-latest":"^2.0.0","safer-buffer":"^2.1.2","tape":"^5.9.0","unassertify":"^3.0.1"},"scripts":{"prepack":"npmignore --auto --commentLines=autogenerated && npm run dist","prepublishOnly":"safe-publish-latest","prepublish":"not-in-publish || npm run prepublishOnly","pretest":"npm run --silent readme && npm run --silent lint","test":"npm run tests-only","tests-only":"nyc tape 'test/**/*.js'","posttest":"npx npm@'>=10.2' audit --production","readme":"evalmd README.md","postlint":"eclint check $(git ls-files | xargs find 2> /dev/null | grep -vE 'node_modules|\\.git' | grep -v dist/)","lint":"eslint --ext=js,mjs .","dist":"mkdirp dist && browserify --standalone Qs -g unassertify -g @browserify/envify -g [@browserify/uglifyify --mangle.keep_fnames --compress.keep_fnames --format.indent_level=1 --compress.arrows=false --compress.passes=4 --compress.typeofs=false] -p common-shakeify -p bundle-collapser/plugin lib/index.js > dist/qs.js"},"license":"BSD-3-Clause","publishConfig":{"ignore":["!dist/*","bower.json","component.json",".github/workflows","logos","tea.yaml"]},"_lastModified":"2025-12-05T11:15:54.128Z"}
@@ -132,7 +132,7 @@ async function startAll(ctx, next) {
132
132
  })
133
133
  ).finally(() => {
134
134
  const message = `${messageTitle}: ${count}/${all}`;
135
- ctx.app.noticeManager.notify(import_constants.NOTIFY_STATUS_EVENT_KEY, { level: "info", message });
135
+ ctx.tego.noticeManager.notify(import_constants.NOTIFY_STATUS_EVENT_KEY, { level: "info", message });
136
136
  });
137
137
  }
138
138
  ctx.body = {
@@ -161,7 +161,7 @@ async function stopAll(ctx, next) {
161
161
  if (all) {
162
162
  Promise.allSettled(promises).finally(() => {
163
163
  const message = `${messageTitle}: ${count}/${all}`;
164
- ctx.app.noticeManager.notify(import_constants.NOTIFY_STATUS_EVENT_KEY, { level: "info", message });
164
+ ctx.tego.noticeManager.notify(import_constants.NOTIFY_STATUS_EVENT_KEY, { level: "info", message });
165
165
  });
166
166
  }
167
167
  ctx.body = {
@@ -1,6 +1,6 @@
1
1
  import { Application, AppSupervisor } from '@tego/server';
2
2
  export type AppOptionsFactory = (appName: string, mainApp: Application, preset: string) => any;
3
- export declare function LazyLoadApplication(context: any): ({ appSupervisor, appName, options, }: {
3
+ export declare function LazyLoadApplication(ctx: any): ({ appSupervisor, appName, options, }: {
4
4
  appSupervisor: AppSupervisor;
5
5
  appName: string;
6
6
  options: any;
@@ -22,7 +22,7 @@ __export(app_lifecycle_exports, {
22
22
  });
23
23
  module.exports = __toCommonJS(app_lifecycle_exports);
24
24
  var import_server = require("@tego/server");
25
- function LazyLoadApplication(context) {
25
+ function LazyLoadApplication(ctx) {
26
26
  return async ({
27
27
  appSupervisor,
28
28
  appName,
@@ -33,7 +33,7 @@ function LazyLoadApplication(context) {
33
33
  if (appSupervisor.hasApp(name)) {
34
34
  return;
35
35
  }
36
- const applicationRecord = await context.app.db.getRepository("applications").findOne({
36
+ const applicationRecord = await ctx.tego.db.getRepository("applications").findOne({
37
37
  filter: {
38
38
  name
39
39
  }
@@ -48,8 +48,8 @@ function LazyLoadApplication(context) {
48
48
  if (!applicationRecord) {
49
49
  return;
50
50
  }
51
- const subApp = applicationRecord.registerToSupervisor(context.app, {
52
- appOptionsFactory: context.appOptionsFactory
51
+ const subApp = applicationRecord.registerToSupervisor(ctx.tego, {
52
+ appOptionsFactory: ctx.appOptionsFactory
53
53
  });
54
54
  if (!loadButNotStart) {
55
55
  await subApp.runCommand("start", "--quickstart");
@@ -5,5 +5,5 @@ export interface registerAppOptions extends Transactionable {
5
5
  appOptionsFactory: AppOptionsFactory;
6
6
  }
7
7
  export declare class ApplicationModel extends Model {
8
- registerToSupervisor(mainApp: Application, options: registerAppOptions): Application<import("@tego/server").DefaultState, import("@tego/server").DefaultContext>;
8
+ registerToSupervisor(mainApp: Application, options: registerAppOptions): Application;
9
9
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tachybase/module-multi-app",
3
3
  "displayName": "Multi-app manager",
4
- "version": "1.6.0",
4
+ "version": "1.6.2",
5
5
  "description": "Dynamically create multiple apps without separate deployments.",
6
6
  "keywords": [
7
7
  "System management"
@@ -9,11 +9,11 @@
9
9
  "license": "Apache-2.0",
10
10
  "main": "./dist/server/index.js",
11
11
  "devDependencies": {
12
- "@ant-design/icons": "^5.6.1",
13
- "@tachybase/schema": "1.3.52",
14
- "@tachybase/test": "1.3.52",
15
- "@tego/client": "1.3.52",
16
- "@tego/server": "1.3.52",
12
+ "@ant-design/icons": "^6.1.0",
13
+ "@tachybase/schema": "1.6.1",
14
+ "@tachybase/test": "1.6.1",
15
+ "@tego/client": "1.6.1",
16
+ "@tego/server": "1.6.1",
17
17
  "@types/lodash": "^4.17.20",
18
18
  "antd": "5.22.5",
19
19
  "async-mutex": "^0.5.0",
@@ -24,7 +24,7 @@
24
24
  "react": "18.3.1",
25
25
  "react-i18next": "16.2.1",
26
26
  "react-router-dom": "6.28.1",
27
- "@tachybase/client": "1.6.0"
27
+ "@tachybase/client": "1.6.2"
28
28
  },
29
29
  "description.zh-CN": "无需单独部署即可动态创建多个应用。",
30
30
  "displayName.zh-CN": "多应用管理器",
package/server.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export * from './dist/server';
2
- export { default } from './dist/server';
1
+ export * from './dist/server';
2
+ export { default } from './dist/server';
package/server.js CHANGED
@@ -1 +1 @@
1
- module.exports = require('./dist/server/index.js');
1
+ module.exports = require('./dist/server/index.js');
@@ -1,372 +0,0 @@
1
- 'use strict';
2
-
3
- const CommonText = require('./common-text-cmd');
4
- const Errors = require('../misc/errors');
5
- const Parse = require('../misc/parse');
6
- const RewritePacket = require('../io/rewrite-packet');
7
- const QUOTE = 0x27;
8
-
9
- /**
10
- * Protocol COM_QUERY
11
- * see : https://mariadb.com/kb/en/library/com_query/
12
- */
13
- class BatchRewrite extends CommonText {
14
- constructor(resolve, reject, options, connOpts, sql, values) {
15
- super(resolve, reject, options, connOpts, sql, values);
16
- }
17
-
18
- /**
19
- * Send COM_QUERY
20
- *
21
- * @param out output writer
22
- * @param opts connection options
23
- * @param info connection information
24
- */
25
- start(out, opts, info) {
26
- this.sending = true;
27
- this.info = info;
28
- if (this.opts.timeout) {
29
- const err = Errors.createError(
30
- 'Cannot use timeout for Batch statement',
31
- this.sql,
32
- false,
33
- info,
34
- 'HY000',
35
- Errors.ER_TIMEOUT_NOT_SUPPORTED
36
- );
37
- this.emit('send_end');
38
- this.throwError(err, info);
39
- return;
40
- }
41
-
42
- if (this.initialValues.length === 0) this.initialValues = [[]];
43
- if (this.opts.namedPlaceholders) {
44
- this.parseResults = Parse.splitRewritableNamedParameterQuery(this.sql, this.initialValues);
45
- this.values = this.parseResults.values;
46
- } else {
47
- this.parseResults = Parse.splitRewritableQuery(this.sql);
48
- this.values = this.initialValues;
49
- if (!this.validateParameters(info)) {
50
- this.sending = false;
51
- return;
52
- }
53
- }
54
-
55
- out.startPacket(this);
56
- this.packet = new RewritePacket(
57
- this.opts.maxAllowedPacket,
58
- out,
59
- this.parseResults.partList[0],
60
- this.parseResults.partList[this.parseResults.partList.length - 1]
61
- );
62
-
63
- this.onPacketReceive = this.readResponsePacket;
64
- this.valueIdx = 0;
65
- this.sendQueries();
66
- }
67
-
68
- sendQueries() {
69
- let flushed = false;
70
- while (!flushed && this.sending && this.valueIdx < this.values.length) {
71
- this.valueRow = this.values[this.valueIdx++];
72
-
73
- //********************************************
74
- // send params
75
- //********************************************
76
- const len = this.parseResults.partList.length - 3;
77
- for (let i = 0; i < len; i++) {
78
- const value = this.valueRow[i];
79
- flushed = this.packet.writeString(this.parseResults.partList[i + 1]) || flushed;
80
- if (value === null) {
81
- flushed = this.packet.writeStringAscii('NULL') || flushed;
82
- continue;
83
- }
84
-
85
- if (
86
- typeof value === 'object' &&
87
- typeof value.pipe === 'function' &&
88
- typeof value.read === 'function'
89
- ) {
90
- //********************************************
91
- // param is stream,
92
- // now all params will be written by event
93
- //********************************************
94
- this.registerStreamSendEvent(this.packet, this.info);
95
- this.currentParam = i;
96
- this.packet.writeInt8(QUOTE); //'
97
-
98
- value.on(
99
- 'data',
100
- function (chunk) {
101
- this.packet.writeBufferEscape(chunk);
102
- }.bind(this)
103
- );
104
-
105
- value.on(
106
- 'end',
107
- function () {
108
- this.packet.writeInt8(QUOTE); //'
109
- this.currentParam++;
110
- this.paramWritten();
111
- }.bind(this)
112
- );
113
-
114
- return;
115
- } else {
116
- //********************************************
117
- // param isn't stream. directly write in buffer
118
- //********************************************
119
- flushed = this.writeParam(this.packet, value, this.opts, this.info) || flushed;
120
- }
121
- }
122
- this.packet.writeString(this.parseResults.partList[this.parseResults.partList.length - 2]);
123
- this.packet.mark(!this.parseResults.reWritable || this.valueIdx === this.values.length);
124
- }
125
-
126
- if (this.valueIdx < this.values.length && !this.packet.haveErrorResponse) {
127
- //there is still data to send
128
- setImmediate(this.sendQueries.bind(this));
129
- } else {
130
- if (this.sending && this.valueIdx === this.values.length) this.emit('send_end');
131
- this.sending = false;
132
- }
133
- }
134
-
135
- displaySql() {
136
- if (this.opts && this.initialValues) {
137
- if (this.sql.length > this.opts.debugLen) {
138
- return 'sql: ' + this.sql.substring(0, this.opts.debugLen) + '...';
139
- }
140
-
141
- let sqlMsg = 'sql: ' + this.sql + ' - parameters:';
142
- sqlMsg += '[';
143
- for (let i = 0; i < this.initialValues.length; i++) {
144
- if (i !== 0) sqlMsg += ',';
145
- let param = this.initialValues[i];
146
- sqlMsg = this.logParameters(sqlMsg, param);
147
- if (sqlMsg.length > this.opts.debugLen) {
148
- sqlMsg = sqlMsg.substr(0, this.opts.debugLen) + '...';
149
- break;
150
- }
151
- }
152
- sqlMsg += ']';
153
- return sqlMsg;
154
- }
155
- return 'sql: ' + this.sql + ' - parameters:[]';
156
- }
157
-
158
- success(val) {
159
- this.packet.waitingResponseNo--;
160
-
161
- if (this.packet.haveErrorResponse) {
162
- if (!this.sending && this.packet.waitingResponseNo === 0) {
163
- this.packet = null;
164
- this.onPacketReceive = null;
165
- this.resolve = null;
166
- this._columns = null;
167
- this._rows = null;
168
- process.nextTick(this.reject, this.firstError);
169
- this.reject = null;
170
- this.emit('end', this.firstError);
171
- }
172
- } else {
173
- if (!this.sending && this.packet.waitingResponseNo === 0) {
174
- if (this.parseResults.reWritable) {
175
- this.packet = null;
176
- let totalAffectedRows = 0;
177
- this._rows.forEach((row) => {
178
- totalAffectedRows += row.affectedRows;
179
- });
180
-
181
- const rs = {
182
- affectedRows: totalAffectedRows,
183
- insertId: this._rows[0].insertId,
184
- warningStatus: this._rows[this._rows.length - 1].warningStatus
185
- };
186
- this.successEnd(rs);
187
- return;
188
- } else {
189
- this.successEnd(this._rows);
190
- }
191
- this._columns = null;
192
- this._rows = null;
193
- return;
194
- }
195
- this._responseIndex++;
196
- this.onPacketReceive = this.readResponsePacket;
197
- }
198
- }
199
-
200
- throwError(err, info) {
201
- this.packet.waitingResponseNo--;
202
- this.sending = false;
203
-
204
- if (this.packet && !this.packet.haveErrorResponse) {
205
- if (err.fatal) {
206
- this.packet.waitingResponseNo = 0;
207
- }
208
- if (this.stack) {
209
- err = Errors.createError(
210
- err.message,
211
- this.sql,
212
- err.fatal,
213
- info,
214
- err.sqlState,
215
- err.errno,
216
- this.stack,
217
- false
218
- );
219
- }
220
- this.firstError = err;
221
- this.packet.endedWithError();
222
- }
223
-
224
- if (!this.sending && this.packet.waitingResponseNo === 0) {
225
- this.packet = null;
226
- this.onPacketReceive = null;
227
- this.resolve = null;
228
- process.nextTick(this.reject, this.firstError);
229
- this.reject = null;
230
- this.emit('end', this.firstError);
231
- } else {
232
- this._responseIndex++;
233
- this.onPacketReceive = this.readResponsePacket;
234
- }
235
- }
236
-
237
- /**
238
- * Validate that parameters exists and are defined.
239
- *
240
- * @param info connection info
241
- * @returns {boolean} return false if any error occur.
242
- */
243
- validateParameters(info) {
244
- //validate parameter size.
245
- for (let r = 0; r < this.values.length; r++) {
246
- let val = this.values[r];
247
- if (!Array.isArray(val)) {
248
- val = [val];
249
- this.values[r] = val;
250
- }
251
-
252
- if (this.parseResults.partList.length - 3 > val.length) {
253
- this.emit('send_end');
254
- this.throwNewError(
255
- 'Parameter at position ' +
256
- val.length +
257
- ' is not set for values ' +
258
- r +
259
- '\n' +
260
- this.displaySql(),
261
- false,
262
- info,
263
- 'HY000',
264
- Errors.ER_MISSING_PARAMETER
265
- );
266
- return false;
267
- }
268
-
269
- //validate parameter is defined.
270
- for (let i = 0; i < this.parseResults.partList.length - 3; i++) {
271
- if (val[i] === undefined) {
272
- this.emit('send_end');
273
- this.throwNewError(
274
- 'Parameter at position ' +
275
- (i + 1) +
276
- ' is undefined for values ' +
277
- r +
278
- '\n' +
279
- this.displaySql(),
280
- false,
281
- info,
282
- 'HY000',
283
- Errors.ER_PARAMETER_UNDEFINED
284
- );
285
- return false;
286
- }
287
- }
288
- }
289
-
290
- return true;
291
- }
292
-
293
- /**
294
- * Define params events.
295
- * Each parameter indicate that he is written to socket,
296
- * emitting event so next parameter can be written.
297
- */
298
- registerStreamSendEvent(packet, info) {
299
- this.paramWritten = function () {
300
- let flushed = false;
301
- while (!flushed) {
302
- if (this.packet.haveErrorResponse) {
303
- this.sending = false;
304
- this.emit('send_end');
305
- return;
306
- }
307
- if (this.currentParam === this.valueRow.length) {
308
- // all parameters from row are written.
309
- flushed =
310
- packet.writeString(this.parseResults.partList[this.parseResults.partList.length - 2]) ||
311
- flushed;
312
- flushed =
313
- packet.mark(!this.parseResults.reWritable || this.valueIdx === this.values.length) ||
314
- flushed;
315
- if (this.valueIdx < this.values.length) {
316
- // still remaining rows
317
- this.valueRow = this.values[this.valueIdx++];
318
- this.currentParam = 0;
319
- } else {
320
- // all rows are written
321
- this.sending = false;
322
- this.emit('send_end');
323
- return;
324
- }
325
- }
326
-
327
- flushed = packet.writeString(this.parseResults.partList[this.currentParam + 1]) || flushed;
328
- const value = this.valueRow[this.currentParam];
329
-
330
- if (value === null) {
331
- flushed = packet.writeStringAscii('NULL') || flushed;
332
- this.currentParam++;
333
- continue;
334
- }
335
-
336
- if (
337
- typeof value === 'object' &&
338
- typeof value.pipe === 'function' &&
339
- typeof value.read === 'function'
340
- ) {
341
- //********************************************
342
- // param is stream,
343
- //********************************************
344
- flushed = packet.writeInt8(QUOTE) || flushed;
345
- value.once(
346
- 'end',
347
- function () {
348
- packet.writeInt8(QUOTE);
349
- this.currentParam++;
350
- this.paramWritten();
351
- }.bind(this)
352
- );
353
-
354
- value.on('data', function (chunk) {
355
- packet.writeBufferEscape(chunk);
356
- });
357
- return;
358
- }
359
-
360
- //********************************************
361
- // param isn't stream. directly write in buffer
362
- //********************************************
363
- flushed = this.writeParam(packet, value, this.opts, info) || flushed;
364
- this.currentParam++;
365
- }
366
-
367
- if (this.sending) setImmediate(this.paramWritten.bind(this));
368
- }.bind(this);
369
- }
370
- }
371
-
372
- module.exports = BatchRewrite;