@nocobase/plugin-field-sort 1.5.0-alpha.1

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 (142) hide show
  1. package/LICENSE.txt +159 -0
  2. package/README.md +1 -0
  3. package/client.d.ts +2 -0
  4. package/client.js +1 -0
  5. package/dist/client/index.d.ts +15 -0
  6. package/dist/client/index.js +10 -0
  7. package/dist/client/locale.d.ts +10 -0
  8. package/dist/client/sort-interface.d.ts +131 -0
  9. package/dist/externalVersion.js +18 -0
  10. package/dist/index.d.ts +10 -0
  11. package/dist/index.js +48 -0
  12. package/dist/locale/en-US.json +1 -0
  13. package/dist/locale/zh-CN.json +1 -0
  14. package/dist/node_modules/@nocobase/lock-manager/LICENSE +661 -0
  15. package/dist/node_modules/@nocobase/lock-manager/lib/index.d.ts +10 -0
  16. package/dist/node_modules/@nocobase/lock-manager/lib/index.js +1 -0
  17. package/dist/node_modules/@nocobase/lock-manager/lib/lock-manager.d.ts +46 -0
  18. package/dist/node_modules/@nocobase/lock-manager/lib/lock-manager.js +171 -0
  19. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/client.js +12 -0
  20. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/assign.d.ts +17 -0
  21. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/assign.js +143 -0
  22. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/client.d.ts +30 -0
  23. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/client.js +88 -0
  24. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/collections-graph.d.ts +24 -0
  25. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/collections-graph.js +107 -0
  26. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/common.d.ts +14 -0
  27. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/common.js +87 -0
  28. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/date.d.ts +38 -0
  29. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/date.js +214 -0
  30. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/dayjs.d.ts +10 -0
  31. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/dayjs.js +72 -0
  32. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/forEach.d.ts +9 -0
  33. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/forEach.js +45 -0
  34. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/fs-exists.d.ts +9 -0
  35. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/fs-exists.js +46 -0
  36. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/getValuesByPath.d.ts +9 -0
  37. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/getValuesByPath.js +71 -0
  38. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/handlebars.d.ts +10 -0
  39. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/handlebars.js +73 -0
  40. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/i18n.d.ts +10 -0
  41. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/i18n.js +43 -0
  42. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/index.d.ts +38 -0
  43. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/index.js +105 -0
  44. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/isPortalInBody.d.ts +13 -0
  45. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/isPortalInBody.js +54 -0
  46. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/isValidFilter.d.ts +9 -0
  47. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/isValidFilter.js +63 -0
  48. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/json-templates.d.ts +9 -0
  49. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/json-templates.js +141 -0
  50. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/koa-multer.d.ts +15 -0
  51. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/koa-multer.js +92 -0
  52. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/log.d.ts +9 -0
  53. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/log.js +39 -0
  54. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/measure-execution-time.d.ts +9 -0
  55. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/measure-execution-time.js +44 -0
  56. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/merge.d.ts +9 -0
  57. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/merge.js +55 -0
  58. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/mixin/AsyncEmitter.d.ts +11 -0
  59. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/mixin/AsyncEmitter.js +80 -0
  60. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/mixin/index.d.ts +9 -0
  61. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/mixin/index.js +48 -0
  62. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/notification.d.ts +9 -0
  63. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/notification.js +43 -0
  64. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/number.d.ts +9 -0
  65. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/number.js +45 -0
  66. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/parse-date.d.ts +15 -0
  67. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/parse-date.js +262 -0
  68. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/parse-filter.d.ts +67 -0
  69. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/parse-filter.js +320 -0
  70. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/parseHTML.d.ts +15 -0
  71. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/parseHTML.js +42 -0
  72. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/perf-hooks.d.ts +14 -0
  73. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/perf-hooks.js +69 -0
  74. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/registry.d.ts +22 -0
  75. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/registry.js +69 -0
  76. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/requireModule.d.ts +12 -0
  77. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/requireModule.js +90 -0
  78. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/server.d.ts +19 -0
  79. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/server.js +50 -0
  80. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/toposort.d.ts +18 -0
  81. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/toposort.js +83 -0
  82. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/uid.d.ts +9 -0
  83. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/uid.js +44 -0
  84. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/url.d.ts +14 -0
  85. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/url.js +46 -0
  86. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/wrap-middleware.d.ts +1 -0
  87. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/lib/wrap-middleware.js +63 -0
  88. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/package.json +20 -0
  89. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/plugin-symlink.d.ts +6 -0
  90. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/plugin-symlink.js +102 -0
  91. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/server.d.ts +2 -0
  92. package/dist/node_modules/@nocobase/lock-manager/node_modules/@nocobase/utils/server.js +12 -0
  93. package/dist/node_modules/@nocobase/lock-manager/node_modules/busboy/.eslintrc.js +5 -0
  94. package/dist/node_modules/@nocobase/lock-manager/node_modules/busboy/.github/workflows/ci.yml +24 -0
  95. package/dist/node_modules/@nocobase/lock-manager/node_modules/busboy/.github/workflows/lint.yml +23 -0
  96. package/dist/node_modules/@nocobase/lock-manager/node_modules/busboy/bench/bench-multipart-fields-100mb-big.js +149 -0
  97. package/dist/node_modules/@nocobase/lock-manager/node_modules/busboy/bench/bench-multipart-fields-100mb-small.js +143 -0
  98. package/dist/node_modules/@nocobase/lock-manager/node_modules/busboy/bench/bench-multipart-files-100mb-big.js +154 -0
  99. package/dist/node_modules/@nocobase/lock-manager/node_modules/busboy/bench/bench-multipart-files-100mb-small.js +148 -0
  100. package/dist/node_modules/@nocobase/lock-manager/node_modules/busboy/bench/bench-urlencoded-fields-100pairs-small.js +101 -0
  101. package/dist/node_modules/@nocobase/lock-manager/node_modules/busboy/bench/bench-urlencoded-fields-900pairs-small-alt.js +84 -0
  102. package/dist/node_modules/@nocobase/lock-manager/node_modules/busboy/lib/index.js +57 -0
  103. package/dist/node_modules/@nocobase/lock-manager/node_modules/busboy/lib/types/multipart.js +653 -0
  104. package/dist/node_modules/@nocobase/lock-manager/node_modules/busboy/lib/types/urlencoded.js +350 -0
  105. package/dist/node_modules/@nocobase/lock-manager/node_modules/busboy/lib/utils.js +596 -0
  106. package/dist/node_modules/@nocobase/lock-manager/node_modules/busboy/package.json +22 -0
  107. package/dist/node_modules/@nocobase/lock-manager/node_modules/busboy/test/common.js +109 -0
  108. package/dist/node_modules/@nocobase/lock-manager/node_modules/busboy/test/test-types-multipart-charsets.js +94 -0
  109. package/dist/node_modules/@nocobase/lock-manager/node_modules/busboy/test/test-types-multipart-stream-pause.js +102 -0
  110. package/dist/node_modules/@nocobase/lock-manager/node_modules/busboy/test/test-types-multipart.js +1053 -0
  111. package/dist/node_modules/@nocobase/lock-manager/node_modules/busboy/test/test-types-urlencoded.js +488 -0
  112. package/dist/node_modules/@nocobase/lock-manager/node_modules/busboy/test/test.js +20 -0
  113. package/dist/node_modules/@nocobase/lock-manager/node_modules/multer/index.js +104 -0
  114. package/dist/node_modules/@nocobase/lock-manager/node_modules/multer/lib/counter.js +28 -0
  115. package/dist/node_modules/@nocobase/lock-manager/node_modules/multer/lib/file-appender.js +67 -0
  116. package/dist/node_modules/@nocobase/lock-manager/node_modules/multer/lib/make-middleware.js +173 -0
  117. package/dist/node_modules/@nocobase/lock-manager/node_modules/multer/lib/multer-error.js +24 -0
  118. package/dist/node_modules/@nocobase/lock-manager/node_modules/multer/lib/remove-uploaded-files.js +28 -0
  119. package/dist/node_modules/@nocobase/lock-manager/node_modules/multer/package.json +52 -0
  120. package/dist/node_modules/@nocobase/lock-manager/node_modules/multer/storage/disk.js +66 -0
  121. package/dist/node_modules/@nocobase/lock-manager/node_modules/multer/storage/memory.js +21 -0
  122. package/dist/node_modules/@nocobase/lock-manager/node_modules/streamsearch/.eslintrc.js +5 -0
  123. package/dist/node_modules/@nocobase/lock-manager/node_modules/streamsearch/.github/workflows/ci.yml +24 -0
  124. package/dist/node_modules/@nocobase/lock-manager/node_modules/streamsearch/.github/workflows/lint.yml +23 -0
  125. package/dist/node_modules/@nocobase/lock-manager/node_modules/streamsearch/lib/sbmh.js +267 -0
  126. package/dist/node_modules/@nocobase/lock-manager/node_modules/streamsearch/package.json +34 -0
  127. package/dist/node_modules/@nocobase/lock-manager/node_modules/streamsearch/test/test.js +70 -0
  128. package/dist/node_modules/@nocobase/lock-manager/package.json +1 -0
  129. package/dist/node_modules/@nocobase/lock-manager/src/__tests__/lock-manager.test.ts +169 -0
  130. package/dist/node_modules/@nocobase/lock-manager/src/index.ts +11 -0
  131. package/dist/node_modules/@nocobase/lock-manager/src/lock-manager.ts +169 -0
  132. package/dist/server/action.d.ts +26 -0
  133. package/dist/server/action.js +168 -0
  134. package/dist/server/index.d.ts +10 -0
  135. package/dist/server/index.js +48 -0
  136. package/dist/server/plugin.d.ts +19 -0
  137. package/dist/server/plugin.js +69 -0
  138. package/dist/server/sort-field.d.ts +24 -0
  139. package/dist/server/sort-field.js +197 -0
  140. package/package.json +16 -0
  141. package/server.d.ts +2 -0
  142. package/server.js +1 -0
@@ -0,0 +1,350 @@
1
+ 'use strict';
2
+
3
+ const { Writable } = require('stream');
4
+
5
+ const { getDecoder } = require('../utils.js');
6
+
7
+ class URLEncoded extends Writable {
8
+ constructor(cfg) {
9
+ const streamOpts = {
10
+ autoDestroy: true,
11
+ emitClose: true,
12
+ highWaterMark: (typeof cfg.highWaterMark === 'number'
13
+ ? cfg.highWaterMark
14
+ : undefined),
15
+ };
16
+ super(streamOpts);
17
+
18
+ let charset = (cfg.defCharset || 'utf8');
19
+ if (cfg.conType.params && typeof cfg.conType.params.charset === 'string')
20
+ charset = cfg.conType.params.charset;
21
+
22
+ this.charset = charset;
23
+
24
+ const limits = cfg.limits;
25
+ this.fieldSizeLimit = (limits && typeof limits.fieldSize === 'number'
26
+ ? limits.fieldSize
27
+ : 1 * 1024 * 1024);
28
+ this.fieldsLimit = (limits && typeof limits.fields === 'number'
29
+ ? limits.fields
30
+ : Infinity);
31
+ this.fieldNameSizeLimit = (
32
+ limits && typeof limits.fieldNameSize === 'number'
33
+ ? limits.fieldNameSize
34
+ : 100
35
+ );
36
+
37
+ this._inKey = true;
38
+ this._keyTrunc = false;
39
+ this._valTrunc = false;
40
+ this._bytesKey = 0;
41
+ this._bytesVal = 0;
42
+ this._fields = 0;
43
+ this._key = '';
44
+ this._val = '';
45
+ this._byte = -2;
46
+ this._lastPos = 0;
47
+ this._encode = 0;
48
+ this._decoder = getDecoder(charset);
49
+ }
50
+
51
+ static detect(conType) {
52
+ return (conType.type === 'application'
53
+ && conType.subtype === 'x-www-form-urlencoded');
54
+ }
55
+
56
+ _write(chunk, enc, cb) {
57
+ if (this._fields >= this.fieldsLimit)
58
+ return cb();
59
+
60
+ let i = 0;
61
+ const len = chunk.length;
62
+ this._lastPos = 0;
63
+
64
+ // Check if we last ended mid-percent-encoded byte
65
+ if (this._byte !== -2) {
66
+ i = readPctEnc(this, chunk, i, len);
67
+ if (i === -1)
68
+ return cb(new Error('Malformed urlencoded form'));
69
+ if (i >= len)
70
+ return cb();
71
+ if (this._inKey)
72
+ ++this._bytesKey;
73
+ else
74
+ ++this._bytesVal;
75
+ }
76
+
77
+ main:
78
+ while (i < len) {
79
+ if (this._inKey) {
80
+ // Parsing key
81
+
82
+ i = skipKeyBytes(this, chunk, i, len);
83
+
84
+ while (i < len) {
85
+ switch (chunk[i]) {
86
+ case 61: // '='
87
+ if (this._lastPos < i)
88
+ this._key += chunk.latin1Slice(this._lastPos, i);
89
+ this._lastPos = ++i;
90
+ this._key = this._decoder(this._key, this._encode);
91
+ this._encode = 0;
92
+ this._inKey = false;
93
+ continue main;
94
+ case 38: // '&'
95
+ if (this._lastPos < i)
96
+ this._key += chunk.latin1Slice(this._lastPos, i);
97
+ this._lastPos = ++i;
98
+ this._key = this._decoder(this._key, this._encode);
99
+ this._encode = 0;
100
+ if (this._bytesKey > 0) {
101
+ this.emit(
102
+ 'field',
103
+ this._key,
104
+ '',
105
+ { nameTruncated: this._keyTrunc,
106
+ valueTruncated: false,
107
+ encoding: this.charset,
108
+ mimeType: 'text/plain' }
109
+ );
110
+ }
111
+ this._key = '';
112
+ this._val = '';
113
+ this._keyTrunc = false;
114
+ this._valTrunc = false;
115
+ this._bytesKey = 0;
116
+ this._bytesVal = 0;
117
+ if (++this._fields >= this.fieldsLimit) {
118
+ this.emit('fieldsLimit');
119
+ return cb();
120
+ }
121
+ continue;
122
+ case 43: // '+'
123
+ if (this._lastPos < i)
124
+ this._key += chunk.latin1Slice(this._lastPos, i);
125
+ this._key += ' ';
126
+ this._lastPos = i + 1;
127
+ break;
128
+ case 37: // '%'
129
+ if (this._encode === 0)
130
+ this._encode = 1;
131
+ if (this._lastPos < i)
132
+ this._key += chunk.latin1Slice(this._lastPos, i);
133
+ this._lastPos = i + 1;
134
+ this._byte = -1;
135
+ i = readPctEnc(this, chunk, i + 1, len);
136
+ if (i === -1)
137
+ return cb(new Error('Malformed urlencoded form'));
138
+ if (i >= len)
139
+ return cb();
140
+ ++this._bytesKey;
141
+ i = skipKeyBytes(this, chunk, i, len);
142
+ continue;
143
+ }
144
+ ++i;
145
+ ++this._bytesKey;
146
+ i = skipKeyBytes(this, chunk, i, len);
147
+ }
148
+ if (this._lastPos < i)
149
+ this._key += chunk.latin1Slice(this._lastPos, i);
150
+ } else {
151
+ // Parsing value
152
+
153
+ i = skipValBytes(this, chunk, i, len);
154
+
155
+ while (i < len) {
156
+ switch (chunk[i]) {
157
+ case 38: // '&'
158
+ if (this._lastPos < i)
159
+ this._val += chunk.latin1Slice(this._lastPos, i);
160
+ this._lastPos = ++i;
161
+ this._inKey = true;
162
+ this._val = this._decoder(this._val, this._encode);
163
+ this._encode = 0;
164
+ if (this._bytesKey > 0 || this._bytesVal > 0) {
165
+ this.emit(
166
+ 'field',
167
+ this._key,
168
+ this._val,
169
+ { nameTruncated: this._keyTrunc,
170
+ valueTruncated: this._valTrunc,
171
+ encoding: this.charset,
172
+ mimeType: 'text/plain' }
173
+ );
174
+ }
175
+ this._key = '';
176
+ this._val = '';
177
+ this._keyTrunc = false;
178
+ this._valTrunc = false;
179
+ this._bytesKey = 0;
180
+ this._bytesVal = 0;
181
+ if (++this._fields >= this.fieldsLimit) {
182
+ this.emit('fieldsLimit');
183
+ return cb();
184
+ }
185
+ continue main;
186
+ case 43: // '+'
187
+ if (this._lastPos < i)
188
+ this._val += chunk.latin1Slice(this._lastPos, i);
189
+ this._val += ' ';
190
+ this._lastPos = i + 1;
191
+ break;
192
+ case 37: // '%'
193
+ if (this._encode === 0)
194
+ this._encode = 1;
195
+ if (this._lastPos < i)
196
+ this._val += chunk.latin1Slice(this._lastPos, i);
197
+ this._lastPos = i + 1;
198
+ this._byte = -1;
199
+ i = readPctEnc(this, chunk, i + 1, len);
200
+ if (i === -1)
201
+ return cb(new Error('Malformed urlencoded form'));
202
+ if (i >= len)
203
+ return cb();
204
+ ++this._bytesVal;
205
+ i = skipValBytes(this, chunk, i, len);
206
+ continue;
207
+ }
208
+ ++i;
209
+ ++this._bytesVal;
210
+ i = skipValBytes(this, chunk, i, len);
211
+ }
212
+ if (this._lastPos < i)
213
+ this._val += chunk.latin1Slice(this._lastPos, i);
214
+ }
215
+ }
216
+
217
+ cb();
218
+ }
219
+
220
+ _final(cb) {
221
+ if (this._byte !== -2)
222
+ return cb(new Error('Malformed urlencoded form'));
223
+ if (!this._inKey || this._bytesKey > 0 || this._bytesVal > 0) {
224
+ if (this._inKey)
225
+ this._key = this._decoder(this._key, this._encode);
226
+ else
227
+ this._val = this._decoder(this._val, this._encode);
228
+ this.emit(
229
+ 'field',
230
+ this._key,
231
+ this._val,
232
+ { nameTruncated: this._keyTrunc,
233
+ valueTruncated: this._valTrunc,
234
+ encoding: this.charset,
235
+ mimeType: 'text/plain' }
236
+ );
237
+ }
238
+ cb();
239
+ }
240
+ }
241
+
242
+ function readPctEnc(self, chunk, pos, len) {
243
+ if (pos >= len)
244
+ return len;
245
+
246
+ if (self._byte === -1) {
247
+ // We saw a '%' but no hex characters yet
248
+ const hexUpper = HEX_VALUES[chunk[pos++]];
249
+ if (hexUpper === -1)
250
+ return -1;
251
+
252
+ if (hexUpper >= 8)
253
+ self._encode = 2; // Indicate high bits detected
254
+
255
+ if (pos < len) {
256
+ // Both hex characters are in this chunk
257
+ const hexLower = HEX_VALUES[chunk[pos++]];
258
+ if (hexLower === -1)
259
+ return -1;
260
+
261
+ if (self._inKey)
262
+ self._key += String.fromCharCode((hexUpper << 4) + hexLower);
263
+ else
264
+ self._val += String.fromCharCode((hexUpper << 4) + hexLower);
265
+
266
+ self._byte = -2;
267
+ self._lastPos = pos;
268
+ } else {
269
+ // Only one hex character was available in this chunk
270
+ self._byte = hexUpper;
271
+ }
272
+ } else {
273
+ // We saw only one hex character so far
274
+ const hexLower = HEX_VALUES[chunk[pos++]];
275
+ if (hexLower === -1)
276
+ return -1;
277
+
278
+ if (self._inKey)
279
+ self._key += String.fromCharCode((self._byte << 4) + hexLower);
280
+ else
281
+ self._val += String.fromCharCode((self._byte << 4) + hexLower);
282
+
283
+ self._byte = -2;
284
+ self._lastPos = pos;
285
+ }
286
+
287
+ return pos;
288
+ }
289
+
290
+ function skipKeyBytes(self, chunk, pos, len) {
291
+ // Skip bytes if we've truncated
292
+ if (self._bytesKey > self.fieldNameSizeLimit) {
293
+ if (!self._keyTrunc) {
294
+ if (self._lastPos < pos)
295
+ self._key += chunk.latin1Slice(self._lastPos, pos - 1);
296
+ }
297
+ self._keyTrunc = true;
298
+ for (; pos < len; ++pos) {
299
+ const code = chunk[pos];
300
+ if (code === 61/* '=' */ || code === 38/* '&' */)
301
+ break;
302
+ ++self._bytesKey;
303
+ }
304
+ self._lastPos = pos;
305
+ }
306
+
307
+ return pos;
308
+ }
309
+
310
+ function skipValBytes(self, chunk, pos, len) {
311
+ // Skip bytes if we've truncated
312
+ if (self._bytesVal > self.fieldSizeLimit) {
313
+ if (!self._valTrunc) {
314
+ if (self._lastPos < pos)
315
+ self._val += chunk.latin1Slice(self._lastPos, pos - 1);
316
+ }
317
+ self._valTrunc = true;
318
+ for (; pos < len; ++pos) {
319
+ if (chunk[pos] === 38/* '&' */)
320
+ break;
321
+ ++self._bytesVal;
322
+ }
323
+ self._lastPos = pos;
324
+ }
325
+
326
+ return pos;
327
+ }
328
+
329
+ /* eslint-disable no-multi-spaces */
330
+ const HEX_VALUES = [
331
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
332
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
333
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
334
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1,
335
+ -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1,
336
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
337
+ -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1,
338
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
339
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
340
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
341
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
342
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
343
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
344
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
345
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
346
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
347
+ ];
348
+ /* eslint-enable no-multi-spaces */
349
+
350
+ module.exports = URLEncoded;