@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,154 @@
1
+ 'use strict';
2
+
3
+ function createMultipartBuffers(boundary, sizes) {
4
+ const bufs = [];
5
+ for (let i = 0; i < sizes.length; ++i) {
6
+ const mb = sizes[i] * 1024 * 1024;
7
+ bufs.push(Buffer.from([
8
+ `--${boundary}`,
9
+ `content-disposition: form-data; name="file${i + 1}"; `
10
+ + `filename="random${i + 1}.bin"`,
11
+ 'content-type: application/octet-stream',
12
+ '',
13
+ '0'.repeat(mb),
14
+ '',
15
+ ].join('\r\n')));
16
+ }
17
+ bufs.push(Buffer.from([
18
+ `--${boundary}--`,
19
+ '',
20
+ ].join('\r\n')));
21
+ return bufs;
22
+ }
23
+
24
+ const boundary = '-----------------------------168072824752491622650073';
25
+ const buffers = createMultipartBuffers(boundary, [
26
+ 10,
27
+ 10,
28
+ 10,
29
+ 20,
30
+ 50,
31
+ ]);
32
+ const calls = {
33
+ partBegin: 0,
34
+ headerField: 0,
35
+ headerValue: 0,
36
+ headerEnd: 0,
37
+ headersEnd: 0,
38
+ partData: 0,
39
+ partEnd: 0,
40
+ end: 0,
41
+ };
42
+
43
+ const moduleName = process.argv[2];
44
+ switch (moduleName) {
45
+ case 'busboy': {
46
+ const busboy = require('busboy');
47
+
48
+ const parser = busboy({
49
+ limits: {
50
+ fieldSizeLimit: Infinity,
51
+ },
52
+ headers: {
53
+ 'content-type': `multipart/form-data; boundary=${boundary}`,
54
+ },
55
+ });
56
+ parser.on('file', (name, stream, info) => {
57
+ ++calls.partBegin;
58
+ stream.on('data', (chunk) => {
59
+ ++calls.partData;
60
+ }).on('end', () => {
61
+ ++calls.partEnd;
62
+ });
63
+ }).on('close', () => {
64
+ ++calls.end;
65
+ console.timeEnd(moduleName);
66
+ });
67
+
68
+ console.time(moduleName);
69
+ for (const buf of buffers)
70
+ parser.write(buf);
71
+ break;
72
+ }
73
+
74
+ case 'formidable': {
75
+ const { MultipartParser } = require('formidable');
76
+
77
+ const parser = new MultipartParser();
78
+ parser.initWithBoundary(boundary);
79
+ parser.on('data', ({ name }) => {
80
+ ++calls[name];
81
+ if (name === 'end')
82
+ console.timeEnd(moduleName);
83
+ });
84
+
85
+ console.time(moduleName);
86
+ for (const buf of buffers)
87
+ parser.write(buf);
88
+
89
+ break;
90
+ }
91
+
92
+ case 'multiparty': {
93
+ const { Readable } = require('stream');
94
+
95
+ const { Form } = require('multiparty');
96
+
97
+ const form = new Form({
98
+ maxFieldsSize: Infinity,
99
+ maxFields: Infinity,
100
+ maxFilesSize: Infinity,
101
+ autoFields: false,
102
+ autoFiles: false,
103
+ });
104
+
105
+ const req = new Readable({ read: () => {} });
106
+ req.headers = {
107
+ 'content-type': `multipart/form-data; boundary=${boundary}`,
108
+ };
109
+
110
+ function hijack(name, fn) {
111
+ const oldFn = form[name];
112
+ form[name] = function() {
113
+ fn();
114
+ return oldFn.apply(this, arguments);
115
+ };
116
+ }
117
+
118
+ hijack('onParseHeaderField', () => {
119
+ ++calls.headerField;
120
+ });
121
+ hijack('onParseHeaderValue', () => {
122
+ ++calls.headerValue;
123
+ });
124
+ hijack('onParsePartBegin', () => {
125
+ ++calls.partBegin;
126
+ });
127
+ hijack('onParsePartData', () => {
128
+ ++calls.partData;
129
+ });
130
+ hijack('onParsePartEnd', () => {
131
+ ++calls.partEnd;
132
+ });
133
+
134
+ form.on('close', () => {
135
+ ++calls.end;
136
+ console.timeEnd(moduleName);
137
+ }).on('part', (p) => p.resume());
138
+
139
+ console.time(moduleName);
140
+ form.parse(req);
141
+ for (const buf of buffers)
142
+ req.push(buf);
143
+ req.push(null);
144
+
145
+ break;
146
+ }
147
+
148
+ default:
149
+ if (moduleName === undefined)
150
+ console.error('Missing parser module name');
151
+ else
152
+ console.error(`Invalid parser module name: ${moduleName}`);
153
+ process.exit(1);
154
+ }
@@ -0,0 +1,148 @@
1
+ 'use strict';
2
+
3
+ function createMultipartBuffers(boundary, sizes) {
4
+ const bufs = [];
5
+ for (let i = 0; i < sizes.length; ++i) {
6
+ const mb = sizes[i] * 1024 * 1024;
7
+ bufs.push(Buffer.from([
8
+ `--${boundary}`,
9
+ `content-disposition: form-data; name="file${i + 1}"; `
10
+ + `filename="random${i + 1}.bin"`,
11
+ 'content-type: application/octet-stream',
12
+ '',
13
+ '0'.repeat(mb),
14
+ '',
15
+ ].join('\r\n')));
16
+ }
17
+ bufs.push(Buffer.from([
18
+ `--${boundary}--`,
19
+ '',
20
+ ].join('\r\n')));
21
+ return bufs;
22
+ }
23
+
24
+ const boundary = '-----------------------------168072824752491622650073';
25
+ const buffers = createMultipartBuffers(boundary, (new Array(100)).fill(1));
26
+ const calls = {
27
+ partBegin: 0,
28
+ headerField: 0,
29
+ headerValue: 0,
30
+ headerEnd: 0,
31
+ headersEnd: 0,
32
+ partData: 0,
33
+ partEnd: 0,
34
+ end: 0,
35
+ };
36
+
37
+ const moduleName = process.argv[2];
38
+ switch (moduleName) {
39
+ case 'busboy': {
40
+ const busboy = require('busboy');
41
+
42
+ const parser = busboy({
43
+ limits: {
44
+ fieldSizeLimit: Infinity,
45
+ },
46
+ headers: {
47
+ 'content-type': `multipart/form-data; boundary=${boundary}`,
48
+ },
49
+ });
50
+ parser.on('file', (name, stream, info) => {
51
+ ++calls.partBegin;
52
+ stream.on('data', (chunk) => {
53
+ ++calls.partData;
54
+ }).on('end', () => {
55
+ ++calls.partEnd;
56
+ });
57
+ }).on('close', () => {
58
+ ++calls.end;
59
+ console.timeEnd(moduleName);
60
+ });
61
+
62
+ console.time(moduleName);
63
+ for (const buf of buffers)
64
+ parser.write(buf);
65
+ break;
66
+ }
67
+
68
+ case 'formidable': {
69
+ const { MultipartParser } = require('formidable');
70
+
71
+ const parser = new MultipartParser();
72
+ parser.initWithBoundary(boundary);
73
+ parser.on('data', ({ name }) => {
74
+ ++calls[name];
75
+ if (name === 'end')
76
+ console.timeEnd(moduleName);
77
+ });
78
+
79
+ console.time(moduleName);
80
+ for (const buf of buffers)
81
+ parser.write(buf);
82
+
83
+ break;
84
+ }
85
+
86
+ case 'multiparty': {
87
+ const { Readable } = require('stream');
88
+
89
+ const { Form } = require('multiparty');
90
+
91
+ const form = new Form({
92
+ maxFieldsSize: Infinity,
93
+ maxFields: Infinity,
94
+ maxFilesSize: Infinity,
95
+ autoFields: false,
96
+ autoFiles: false,
97
+ });
98
+
99
+ const req = new Readable({ read: () => {} });
100
+ req.headers = {
101
+ 'content-type': `multipart/form-data; boundary=${boundary}`,
102
+ };
103
+
104
+ function hijack(name, fn) {
105
+ const oldFn = form[name];
106
+ form[name] = function() {
107
+ fn();
108
+ return oldFn.apply(this, arguments);
109
+ };
110
+ }
111
+
112
+ hijack('onParseHeaderField', () => {
113
+ ++calls.headerField;
114
+ });
115
+ hijack('onParseHeaderValue', () => {
116
+ ++calls.headerValue;
117
+ });
118
+ hijack('onParsePartBegin', () => {
119
+ ++calls.partBegin;
120
+ });
121
+ hijack('onParsePartData', () => {
122
+ ++calls.partData;
123
+ });
124
+ hijack('onParsePartEnd', () => {
125
+ ++calls.partEnd;
126
+ });
127
+
128
+ form.on('close', () => {
129
+ ++calls.end;
130
+ console.timeEnd(moduleName);
131
+ }).on('part', (p) => p.resume());
132
+
133
+ console.time(moduleName);
134
+ form.parse(req);
135
+ for (const buf of buffers)
136
+ req.push(buf);
137
+ req.push(null);
138
+
139
+ break;
140
+ }
141
+
142
+ default:
143
+ if (moduleName === undefined)
144
+ console.error('Missing parser module name');
145
+ else
146
+ console.error(`Invalid parser module name: ${moduleName}`);
147
+ process.exit(1);
148
+ }
@@ -0,0 +1,101 @@
1
+ 'use strict';
2
+
3
+ const buffers = [
4
+ Buffer.from(
5
+ (new Array(100)).fill('').map((_, i) => `key${i}=value${i}`).join('&')
6
+ ),
7
+ ];
8
+ const calls = {
9
+ field: 0,
10
+ end: 0,
11
+ };
12
+
13
+ let n = 3e3;
14
+
15
+ const moduleName = process.argv[2];
16
+ switch (moduleName) {
17
+ case 'busboy': {
18
+ const busboy = require('busboy');
19
+
20
+ console.time(moduleName);
21
+ (function next() {
22
+ const parser = busboy({
23
+ limits: {
24
+ fieldSizeLimit: Infinity,
25
+ },
26
+ headers: {
27
+ 'content-type': 'application/x-www-form-urlencoded; charset=utf-8',
28
+ },
29
+ });
30
+ parser.on('field', (name, val, info) => {
31
+ ++calls.field;
32
+ }).on('close', () => {
33
+ ++calls.end;
34
+ if (--n === 0)
35
+ console.timeEnd(moduleName);
36
+ else
37
+ process.nextTick(next);
38
+ });
39
+
40
+ for (const buf of buffers)
41
+ parser.write(buf);
42
+ parser.end();
43
+ })();
44
+ break;
45
+ }
46
+
47
+ case 'formidable': {
48
+ const QuerystringParser =
49
+ require('formidable/src/parsers/Querystring.js');
50
+
51
+ console.time(moduleName);
52
+ (function next() {
53
+ const parser = new QuerystringParser();
54
+ parser.on('data', (obj) => {
55
+ ++calls.field;
56
+ }).on('end', () => {
57
+ ++calls.end;
58
+ if (--n === 0)
59
+ console.timeEnd(moduleName);
60
+ else
61
+ process.nextTick(next);
62
+ });
63
+
64
+ for (const buf of buffers)
65
+ parser.write(buf);
66
+ parser.end();
67
+ })();
68
+ break;
69
+ }
70
+
71
+ case 'formidable-streaming': {
72
+ const QuerystringParser =
73
+ require('formidable/src/parsers/StreamingQuerystring.js');
74
+
75
+ console.time(moduleName);
76
+ (function next() {
77
+ const parser = new QuerystringParser();
78
+ parser.on('data', (obj) => {
79
+ ++calls.field;
80
+ }).on('end', () => {
81
+ ++calls.end;
82
+ if (--n === 0)
83
+ console.timeEnd(moduleName);
84
+ else
85
+ process.nextTick(next);
86
+ });
87
+
88
+ for (const buf of buffers)
89
+ parser.write(buf);
90
+ parser.end();
91
+ })();
92
+ break;
93
+ }
94
+
95
+ default:
96
+ if (moduleName === undefined)
97
+ console.error('Missing parser module name');
98
+ else
99
+ console.error(`Invalid parser module name: ${moduleName}`);
100
+ process.exit(1);
101
+ }
@@ -0,0 +1,84 @@
1
+ 'use strict';
2
+
3
+ const buffers = [
4
+ Buffer.from(
5
+ (new Array(900)).fill('').map((_, i) => `key${i}=value${i}`).join('&')
6
+ ),
7
+ ];
8
+ const calls = {
9
+ field: 0,
10
+ end: 0,
11
+ };
12
+
13
+ const moduleName = process.argv[2];
14
+ switch (moduleName) {
15
+ case 'busboy': {
16
+ const busboy = require('busboy');
17
+
18
+ console.time(moduleName);
19
+ const parser = busboy({
20
+ limits: {
21
+ fieldSizeLimit: Infinity,
22
+ },
23
+ headers: {
24
+ 'content-type': 'application/x-www-form-urlencoded; charset=utf-8',
25
+ },
26
+ });
27
+ parser.on('field', (name, val, info) => {
28
+ ++calls.field;
29
+ }).on('close', () => {
30
+ ++calls.end;
31
+ console.timeEnd(moduleName);
32
+ });
33
+
34
+ for (const buf of buffers)
35
+ parser.write(buf);
36
+ parser.end();
37
+ break;
38
+ }
39
+
40
+ case 'formidable': {
41
+ const QuerystringParser =
42
+ require('formidable/src/parsers/Querystring.js');
43
+
44
+ console.time(moduleName);
45
+ const parser = new QuerystringParser();
46
+ parser.on('data', (obj) => {
47
+ ++calls.field;
48
+ }).on('end', () => {
49
+ ++calls.end;
50
+ console.timeEnd(moduleName);
51
+ });
52
+
53
+ for (const buf of buffers)
54
+ parser.write(buf);
55
+ parser.end();
56
+ break;
57
+ }
58
+
59
+ case 'formidable-streaming': {
60
+ const QuerystringParser =
61
+ require('formidable/src/parsers/StreamingQuerystring.js');
62
+
63
+ console.time(moduleName);
64
+ const parser = new QuerystringParser();
65
+ parser.on('data', (obj) => {
66
+ ++calls.field;
67
+ }).on('end', () => {
68
+ ++calls.end;
69
+ console.timeEnd(moduleName);
70
+ });
71
+
72
+ for (const buf of buffers)
73
+ parser.write(buf);
74
+ parser.end();
75
+ break;
76
+ }
77
+
78
+ default:
79
+ if (moduleName === undefined)
80
+ console.error('Missing parser module name');
81
+ else
82
+ console.error(`Invalid parser module name: ${moduleName}`);
83
+ process.exit(1);
84
+ }
@@ -0,0 +1,57 @@
1
+ 'use strict';
2
+
3
+ const { parseContentType } = require('./utils.js');
4
+
5
+ function getInstance(cfg) {
6
+ const headers = cfg.headers;
7
+ const conType = parseContentType(headers['content-type']);
8
+ if (!conType)
9
+ throw new Error('Malformed content type');
10
+
11
+ for (const type of TYPES) {
12
+ const matched = type.detect(conType);
13
+ if (!matched)
14
+ continue;
15
+
16
+ const instanceCfg = {
17
+ limits: cfg.limits,
18
+ headers,
19
+ conType,
20
+ highWaterMark: undefined,
21
+ fileHwm: undefined,
22
+ defCharset: undefined,
23
+ defParamCharset: undefined,
24
+ preservePath: false,
25
+ };
26
+ if (cfg.highWaterMark)
27
+ instanceCfg.highWaterMark = cfg.highWaterMark;
28
+ if (cfg.fileHwm)
29
+ instanceCfg.fileHwm = cfg.fileHwm;
30
+ instanceCfg.defCharset = cfg.defCharset;
31
+ instanceCfg.defParamCharset = cfg.defParamCharset;
32
+ instanceCfg.preservePath = cfg.preservePath;
33
+ return new type(instanceCfg);
34
+ }
35
+
36
+ throw new Error(`Unsupported content type: ${headers['content-type']}`);
37
+ }
38
+
39
+ // Note: types are explicitly listed here for easier bundling
40
+ // See: https://github.com/mscdex/busboy/issues/121
41
+ const TYPES = [
42
+ require('./types/multipart'),
43
+ require('./types/urlencoded'),
44
+ ].filter(function(typemod) { return typeof typemod.detect === 'function'; });
45
+
46
+ module.exports = (cfg) => {
47
+ if (typeof cfg !== 'object' || cfg === null)
48
+ cfg = {};
49
+
50
+ if (typeof cfg.headers !== 'object'
51
+ || cfg.headers === null
52
+ || typeof cfg.headers['content-type'] !== 'string') {
53
+ throw new Error('Missing Content-Type');
54
+ }
55
+
56
+ return getInstance(cfg);
57
+ };