@koa-stack/body 0.23.0 → 0.25.0-dev.20260629.122506Z

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/LICENSE CHANGED
@@ -1,21 +1,201 @@
1
- MIT License
2
-
3
- Copyright (c) 2023 Bogdan Stefanescu
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 Vertesia
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -1,7 +1,8 @@
1
- import readRawBody from 'raw-body';
2
- import inflate from 'inflation';
3
1
  import formidable from 'formidable';
4
- import Koa, { Context } from 'koa';
2
+ import inflate from 'inflation';
3
+ import type Koa from 'koa';
4
+ import type { Context } from 'koa';
5
+ import readRawBody from 'raw-body';
5
6
  declare module 'koa' {
6
7
  interface BaseContext {
7
8
  payload: Promise<LazyBody>;
@@ -57,11 +58,11 @@ export declare class LazyBody {
57
58
  static install(koa: Koa, opts?: LazyBodyOpts): void;
58
59
  }
59
60
  declare enum FormType {
60
- 'multipart' = 0,
61
- 'form' = 1,
62
- 'json' = 2,
63
- 'xml' = 3,
64
- 'text' = 4
61
+ multipart = 0,
62
+ form = 1,
63
+ json = 2,
64
+ xml = 3,
65
+ text = 4
65
66
  }
66
67
  export {};
67
68
  //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,OAAO,MAAM,WAAW,CAAC;AAChC,OAAO,KAAK,GAAG,MAAM,KAAK,CAAC;AAC3B,OAAO,KAAK,EAAE,OAAO,EAAW,MAAM,KAAK,CAAC;AAE5C,OAAO,WAAW,MAAM,UAAU,CAAC;AAEnC,OAAO,QAAQ,KAAK,CAAC;IACjB,UAAU,WAAW;QACjB,OAAO,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC;QAC3B,UAAU,EAAE,OAAO,CAAC;KACvB;CACJ;AAED,MAAM,WAAW,OAAO;IACpB,UAAU,CAAC,EAAE,UAAU,CAAC,OAAO,CAAC;IAChC,OAAO,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC;IAE1B,IAAI,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,GAAG,CAAC;IAE7B,IAAI,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,GAAG,CAAC;IAE7B,GAAG,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,GAAG,CAAC;CAC/B;AACD,MAAM,MAAM,YAAY,GAAG,WAAW,CAAC,OAAO,GAAG,OAAO,CAAC;AAkCzD;;;;GAIG;AACH,qBAAa,QAAQ;IACjB,GAAG,EAAE,OAAO,CAAC;IACb,IAAI,EAAE,QAAQ,CAAC;IAEf,IAAI,EAAE,GAAG,CAAC;IACV,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,UAAU,CAAC,KAAK,GAAG,IAAI,GAAG,SAAS,CAAC;gBAGvC,GAAG,EAAE,OAAO,EACZ,IAAI,EAAE,QAAQ,EAEd,IAAI,EAAE,GAAG,EACT,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,UAAU,CAAC,KAAK,GAAG,IAAI,GAAG,SAAS;IAS9C,IAAI,OAAO,YAEV;IAED,UAAU,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;IAM9C,SAAS,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;IAM7C;;;;OAIG;IACH,UAAU,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;IAM9C,eAAe,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;IAMnD,UAAU,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;IAM9C;;;;OAIG;IACH,YAAY,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;IAMhD,IAAI,IAAI,WAEP;IAED,IAAI,IAAI,QAEP;IAED,IAAI,GAAG,QAEN;IAED,IAAI,MAAM,QAQT;IAED,IAAI,MAAM,YAET;IAED,IAAI,MAAM,YAET;IAED,IAAI,KAAK,YAER;IAED,IAAI,WAAW,YAEd;IAED,IAAI,MAAM,YAET;IAED,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,GAAE,YAAiB,GAAG,IAAI;CA+B1D;AACD,aAAK,QAAQ;IACT,SAAS,IAAA;IACT,IAAI,IAAA;IACJ,IAAI,IAAA;IACJ,GAAG,IAAA;IACH,IAAI,IAAA;CACP"}
@@ -1,7 +1,7 @@
1
- import readRawBody from 'raw-body';
1
+ import formidable from 'formidable';
2
2
  import inflate from 'inflation';
3
3
  import qs from 'qs';
4
- import formidable from 'formidable';
4
+ import readRawBody from 'raw-body';
5
5
  function parseMultipartBody(koaRequest, opts) {
6
6
  const form = formidable(opts.formidable);
7
7
  return new Promise((resolve, reject) => {
@@ -12,7 +12,7 @@ function parseMultipartBody(koaRequest, opts) {
12
12
  else {
13
13
  resolve({
14
14
  params: fields,
15
- files: files
15
+ files: files,
16
16
  });
17
17
  }
18
18
  });
@@ -20,7 +20,7 @@ function parseMultipartBody(koaRequest, opts) {
20
20
  }
21
21
  async function getRawBodyText(koaRequest, opts) {
22
22
  const len = koaRequest.length;
23
- let encoding = koaRequest.headers['content-encoding'];
23
+ const encoding = koaRequest.headers['content-encoding'];
24
24
  if (len && !encoding) {
25
25
  opts.length = len;
26
26
  }
@@ -33,37 +33,15 @@ async function getRawBodyText(koaRequest, opts) {
33
33
  *
34
34
  */
35
35
  export class LazyBody {
36
- constructor(ctx, type, data, raw, files) {
37
- Object.defineProperty(this, "ctx", {
38
- enumerable: true,
39
- configurable: true,
40
- writable: true,
41
- value: void 0
42
- });
43
- Object.defineProperty(this, "type", {
44
- enumerable: true,
45
- configurable: true,
46
- writable: true,
47
- value: void 0
48
- });
49
- Object.defineProperty(this, "data", {
50
- enumerable: true,
51
- configurable: true,
52
- writable: true,
53
- value: void 0
54
- });
55
- Object.defineProperty(this, "raw", {
56
- enumerable: true,
57
- configurable: true,
58
- writable: true,
59
- value: void 0
60
- });
61
- Object.defineProperty(this, "files", {
62
- enumerable: true,
63
- configurable: true,
64
- writable: true,
65
- value: void 0
66
- });
36
+ ctx;
37
+ type;
38
+ // biome-ignore lint/suspicious/noExplicitAny: parsed HTTP body — caller types per route
39
+ data;
40
+ raw;
41
+ files;
42
+ constructor(ctx, type,
43
+ // biome-ignore lint/suspicious/noExplicitAny: parsed HTTP body — caller types per route
44
+ data, raw, files) {
67
45
  this.ctx = ctx;
68
46
  this.type = type;
69
47
  this.data = data;
@@ -127,7 +105,8 @@ export class LazyBody {
127
105
  case FormType.form:
128
106
  case FormType.multipart:
129
107
  return this.data;
130
- default: return undefined;
108
+ default:
109
+ return undefined;
131
110
  }
132
111
  }
133
112
  get isForm() {
@@ -158,7 +137,7 @@ export class LazyBody {
158
137
  // be able to work along code using koa2-formidable (wich sets the body property pf the request)
159
138
  set(body) {
160
139
  this._body = body;
161
- }
140
+ },
162
141
  });
163
142
  // payload is an alias to request.body
164
143
  Object.defineProperty(koa.context, 'payload', {
@@ -167,13 +146,12 @@ export class LazyBody {
167
146
  },
168
147
  set(body) {
169
148
  this.request.body = body;
170
- }
149
+ },
171
150
  });
172
151
  // payload is an alias to request.hasBody in v3
173
152
  Object.defineProperty(koa.context, 'hasPayload', {
174
153
  get() {
175
- return this.request.length > 0 ||
176
- this.request.headers['transfer-encoding'] != null;
154
+ return this.request.length > 0 || this.request.headers['transfer-encoding'] != null;
177
155
  },
178
156
  });
179
157
  }
@@ -187,7 +165,9 @@ var FormType;
187
165
  FormType[FormType["text"] = 4] = "text";
188
166
  })(FormType || (FormType = {}));
189
167
  async function createBody(koaRequest, opts) {
190
- let type, data, raw, files = null;
168
+ let type,
169
+ // biome-ignore lint/suspicious/noExplicitAny: parsed HTTP body — caller types per route
170
+ data, raw, files = null;
191
171
  if (koaRequest.is('multipart')) {
192
172
  raw = '';
193
173
  const result = await parseMultipartBody(koaRequest, opts);
@@ -209,7 +189,8 @@ async function createBody(koaRequest, opts) {
209
189
  else {
210
190
  raw = '';
211
191
  }
212
- if (raw === '') { // for JSON we support no content posted
192
+ if (raw === '') {
193
+ // for JSON we support no content posted
213
194
  data = undefined;
214
195
  }
215
196
  else {
@@ -224,7 +205,7 @@ async function createBody(koaRequest, opts) {
224
205
  data = opts.xml(raw);
225
206
  }
226
207
  else {
227
- let parser = await tryGetXmlParser();
208
+ const parser = await tryGetXmlParser();
228
209
  if (parser) {
229
210
  data = parser.parse(raw);
230
211
  }
@@ -254,11 +235,11 @@ async function createBody(koaRequest, opts) {
254
235
  */
255
236
  async function tryGetXmlParser() {
256
237
  try {
257
- const mod = await import("fast-xml-parser");
238
+ const mod = (await import('fast-xml-parser'));
258
239
  return new mod.XMLParser();
259
240
  }
260
241
  catch (err) {
261
- console.warn("Could not find fast-xml-parser. You need to pass xml option for a custom parser", err);
242
+ console.warn('Could not find fast-xml-parser. You need to pass xml option for a custom parser', err);
262
243
  return undefined;
263
244
  }
264
245
  }
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,OAAO,MAAM,WAAW,CAAC;AAGhC,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,WAAW,MAAM,UAAU,CAAC;AAqBnC,SAAS,kBAAkB,CACvB,UAAmB,EACnB,IAAkB;IAKlB,MAAM,IAAI,GAAG,UAAU,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IACzC,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACnC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE;YAC9C,IAAI,GAAG,EAAE,CAAC;gBACN,MAAM,CAAC,GAAG,CAAC,CAAC;YAChB,CAAC;iBAAM,CAAC;gBACJ,OAAO,CAAC;oBACJ,MAAM,EAAE,MAAM;oBACd,KAAK,EAAE,KAAK;iBACf,CAAC,CAAC;YACP,CAAC;QACL,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACP,CAAC;AAED,KAAK,UAAU,cAAc,CAAC,UAAmB,EAAE,IAAkB;IACjE,MAAM,GAAG,GAAG,UAAU,CAAC,MAAM,CAAC;IAC9B,MAAM,QAAQ,GAAG,UAAU,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAC;IACxD,IAAI,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAC;QACnB,IAAI,CAAC,MAAM,GAAG,GAAG,CAAC;IACtB,CAAC;IACD,qFAAqF;IACrF,OAAO,CAAC,MAAM,WAAW,CAAC,OAAO,CAAC,UAAU,CAAC,GAAG,EAAE,IAAI,CAAC,OAAO,CAAC,EAAE,IAAI,CA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ACjC,GAAG,GAAG,MAAM,cAAc,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;QAC7C,IAAI,GAAG,QAAQ,CAAC,IAAI,CAAC;IACzB,CAAC;SAAM,CAAC;QACJ,IAAI,GAAG,QAAQ,CAAC,IAAI,CAAC;QACrB,cAAc;QACd,OAAO,CAAC,GAAG,EAAE,CAAC;QACd,IAAI,UAAU,CAAC,GAAG,CAAC,UAAU,EAAE,CAAC;YAC5B,GAAG,GAAG,MAAM,cAAc,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;QACjD,CAAC;aAAM,CAAC;YACJ,GAAG,GAAG,EAAE,CAAC;QACb,CAAC;IACL,CAAC;IACD,OAAO,IAAI,QAAQ,CAAC,UAAU,CAAC,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;AAChE,CAAC;AAED;;;GAGG;AACH,KAAK,UAAU,eAAe;IAC1B,IAAI,CAAC;QACD,MAAM,GAAG,GAAG,CAAC,MAAM,MAAM,CAAC,iBAAiB,CAAC,CAAqC,CAAC;QAClF,OAAO,IAAI,GAAG,CAAC,SAAS,EAAE,CAAC;IAC/B,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACX,OAAO,CAAC,IAAI,CAAC,iFAAiF,EAAE,GAAG,CAAC,CAAC;QACrG,OAAO,SAAS,CAAC;IACrB,CAAC;AACL,CAAC"}
package/package.json CHANGED
@@ -1,8 +1,7 @@
1
1
  {
2
2
  "name": "@koa-stack/body",
3
- "version": "0.23.0",
3
+ "version": "0.25.0-dev.20260629.122506Z",
4
4
  "description": "Expose the request body as a promise in koa Context.body",
5
- "main": "./lib/cjs/index.js",
6
5
  "type": "module",
7
6
  "files": [
8
7
  "lib",
@@ -16,31 +15,38 @@
16
15
  ],
17
16
  "author": "stefanescu.bogdan@gmail.com",
18
17
  "license": "MIT",
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "https://github.com/vertesia/composableai.git",
21
+ "directory": "libraries/koa-stack/body"
22
+ },
19
23
  "dependencies": {
20
- "formidable": "^3.5.1",
24
+ "formidable": "^3.5.4",
21
25
  "inflation": "^2.1.0",
22
- "qs": "^6.12.1",
23
- "raw-body": "^2.5.2"
26
+ "koa": "^3.2.1",
27
+ "qs": "^6.15.2",
28
+ "raw-body": "^3.0.2"
24
29
  },
25
30
  "devDependencies": {
26
- "@types/formidable": "^3.4.5",
31
+ "@types/formidable": "^3.5.1",
27
32
  "@types/inflation": "^2.0.4",
28
- "@types/qs": "^6.9.15",
29
- "fast-xml-parser": "^5.2.5",
30
- "ts-dual-module": "^0.6.3"
31
- },
32
- "ts_dual_module": {
33
- "outDir": "lib"
33
+ "@types/koa": "^3.0.3",
34
+ "@types/qs": "^6.15.1",
35
+ "fast-xml-parser": "^5.8.0",
36
+ "typescript": "^6.0.3",
37
+ "@vertesia/tsconfig": "0.1.0"
34
38
  },
39
+ "main": "./lib/index.js",
40
+ "types": "./lib/index.d.ts",
35
41
  "exports": {
36
- "types": "./lib/types/index.d.ts",
37
- "import": "./lib/esm/index.js",
38
- "require": "./lib/cjs/index.js"
42
+ ".": {
43
+ "types": "./lib/index.d.ts",
44
+ "default": "./lib/index.js"
45
+ }
39
46
  },
40
- "types": "./lib/types/index.d.ts",
41
47
  "scripts": {
42
- "build": "pnpm exec tsmod build",
43
- "clean": "rimraf ./lib",
48
+ "build": "tsc -p tsconfig.json",
49
+ "clean": "rimraf ./node_modules ./lib ./tsconfig.tsbuildinfo",
44
50
  "test": "echo \"Error: no test specified\""
45
51
  }
46
52
  }
package/src/index.ts CHANGED
@@ -1,30 +1,36 @@
1
- import readRawBody from 'raw-body';
1
+ import type { XMLParser } from 'fast-xml-parser';
2
+ import formidable from 'formidable';
2
3
  import inflate from 'inflation';
4
+ import type Koa from 'koa';
5
+ import type { Context, Request } from 'koa';
3
6
  import qs from 'qs';
4
- import formidable from 'formidable';
5
- import Koa, { Context, Request } from 'koa';
6
- import type { XMLParser } from 'fast-xml-parser';
7
+ import readRawBody from 'raw-body';
7
8
 
8
9
  declare module 'koa' {
9
10
  interface BaseContext {
10
- payload: Promise<LazyBody>,
11
- hasPayload: boolean,
11
+ payload: Promise<LazyBody>;
12
+ hasPayload: boolean;
12
13
  }
13
14
  }
14
15
 
15
16
  export interface OwnOpts {
16
- formidable?: formidable.Options,
17
- inflate?: inflate.Options,
18
- form?: (data: string) => any,
19
- json?: (data: string) => any,
20
- xml?: (data: string) => any,
17
+ formidable?: formidable.Options;
18
+ inflate?: inflate.Options;
19
+ // biome-ignore lint/suspicious/noExplicitAny: custom parser returns user-defined shape
20
+ form?: (data: string) => any;
21
+ // biome-ignore lint/suspicious/noExplicitAny: custom parser returns user-defined shape
22
+ json?: (data: string) => any;
23
+ // biome-ignore lint/suspicious/noExplicitAny: custom parser returns user-defined shape
24
+ xml?: (data: string) => any;
21
25
  }
22
26
  export type LazyBodyOpts = readRawBody.Options & OwnOpts;
23
27
 
24
-
25
- function parseMultipartBody(koaRequest: Request, opts: LazyBodyOpts): Promise<{
26
- params: formidable.Fields,
27
- files: formidable.Files
28
+ function parseMultipartBody(
29
+ koaRequest: Request,
30
+ opts: LazyBodyOpts,
31
+ ): Promise<{
32
+ params: formidable.Fields;
33
+ files: formidable.Files;
28
34
  }> {
29
35
  const form = formidable(opts.formidable);
30
36
  return new Promise((resolve, reject) => {
@@ -34,7 +40,7 @@ function parseMultipartBody(koaRequest: Request, opts: LazyBodyOpts): Promise<{
34
40
  } else {
35
41
  resolve({
36
42
  params: fields,
37
- files: files
43
+ files: files,
38
44
  });
39
45
  }
40
46
  });
@@ -43,7 +49,7 @@ function parseMultipartBody(koaRequest: Request, opts: LazyBodyOpts): Promise<{
43
49
 
44
50
  async function getRawBodyText(koaRequest: Request, opts: LazyBodyOpts): Promise<string> {
45
51
  const len = koaRequest.length;
46
- let encoding = koaRequest.headers['content-encoding'];
52
+ const encoding = koaRequest.headers['content-encoding'];
47
53
  if (len && !encoding) {
48
54
  opts.length = len;
49
55
  }
@@ -57,14 +63,21 @@ async function getRawBodyText(koaRequest: Request, opts: LazyBodyOpts): Promise<
57
63
  *
58
64
  */
59
65
  export class LazyBody {
60
-
61
66
  ctx: Context;
62
67
  type: FormType;
68
+ // biome-ignore lint/suspicious/noExplicitAny: parsed HTTP body — caller types per route
63
69
  data: any;
64
70
  raw: string;
65
71
  files: formidable.Files | null | undefined;
66
72
 
67
- constructor(ctx: Context, type: FormType, data: any, raw: string, files: formidable.Files | null | undefined) {
73
+ constructor(
74
+ ctx: Context,
75
+ type: FormType,
76
+ // biome-ignore lint/suspicious/noExplicitAny: parsed HTTP body — caller types per route
77
+ data: any,
78
+ raw: string,
79
+ files: formidable.Files | null | undefined,
80
+ ) {
68
81
  this.ctx = ctx;
69
82
  this.type = type;
70
83
  this.data = data;
@@ -139,7 +152,8 @@ export class LazyBody {
139
152
  case FormType.form:
140
153
  case FormType.multipart:
141
154
  return this.data;
142
- default: return undefined;
155
+ default:
156
+ return undefined;
143
157
  }
144
158
  }
145
159
 
@@ -176,7 +190,7 @@ export class LazyBody {
176
190
  // be able to work along code using koa2-formidable (wich sets the body property pf the request)
177
191
  set(body) {
178
192
  this._body = body;
179
- }
193
+ },
180
194
  });
181
195
  // payload is an alias to request.body
182
196
  Object.defineProperty(koa.context, 'payload', {
@@ -185,24 +199,30 @@ export class LazyBody {
185
199
  },
186
200
  set(body) {
187
201
  this.request.body = body;
188
- }
202
+ },
189
203
  });
190
204
  // payload is an alias to request.hasBody in v3
191
205
  Object.defineProperty(koa.context, 'hasPayload', {
192
206
  get() {
193
- return this.request.length > 0 ||
194
- this.request.headers['transfer-encoding'] != null;
207
+ return this.request.length > 0 || this.request.headers['transfer-encoding'] != null;
195
208
  },
196
209
  });
197
210
  }
198
-
199
211
  }
200
212
  enum FormType {
201
- 'multipart', 'form', 'json', 'xml', 'text'
213
+ multipart,
214
+ form,
215
+ json,
216
+ xml,
217
+ text,
202
218
  }
203
219
 
204
220
  async function createBody(koaRequest: Request, opts: LazyBodyOpts) {
205
- let type: FormType, data: any, raw: string, files: formidable.Files | null | undefined = null;
221
+ let type: FormType,
222
+ // biome-ignore lint/suspicious/noExplicitAny: parsed HTTP body — caller types per route
223
+ data: any,
224
+ raw: string,
225
+ files: formidable.Files | null | undefined = null;
206
226
  if (koaRequest.is('multipart')) {
207
227
  raw = '';
208
228
  const result = await parseMultipartBody(koaRequest, opts);
@@ -221,7 +241,8 @@ async function createBody(koaRequest: Request, opts: LazyBodyOpts) {
221
241
  } else {
222
242
  raw = '';
223
243
  }
224
- if (raw === '') { // for JSON we support no content posted
244
+ if (raw === '') {
245
+ // for JSON we support no content posted
225
246
  data = undefined;
226
247
  } else {
227
248
  data = opts.json ? opts.json(raw) : JSON.parse(raw);
@@ -233,7 +254,7 @@ async function createBody(koaRequest: Request, opts: LazyBodyOpts) {
233
254
  if (opts.xml) {
234
255
  data = opts.xml(raw);
235
256
  } else {
236
- let parser = await tryGetXmlParser();
257
+ const parser = await tryGetXmlParser();
237
258
  if (parser) {
238
259
  data = parser.parse(raw);
239
260
  }
@@ -257,14 +278,14 @@ async function createBody(koaRequest: Request, opts: LazyBodyOpts) {
257
278
 
258
279
  /**
259
280
  * Use fast-xml-parser if available
260
- * @returns
281
+ * @returns
261
282
  */
262
283
  async function tryGetXmlParser(): Promise<XMLParser | undefined> {
263
284
  try {
264
- const mod = await import("fast-xml-parser") as typeof import("fast-xml-parser");
285
+ const mod = (await import('fast-xml-parser')) as typeof import('fast-xml-parser');
265
286
  return new mod.XMLParser();
266
287
  } catch (err) {
267
- console.warn("Could not find fast-xml-parser. You need to pass xml option for a custom parser", err);
288
+ console.warn('Could not find fast-xml-parser. You need to pass xml option for a custom parser', err);
268
289
  return undefined;
269
290
  }
270
- }
291
+ }
package/lib/cjs/index.js DELETED
@@ -1,305 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- var __importDefault = (this && this.__importDefault) || function (mod) {
36
- return (mod && mod.__esModule) ? mod : { "default": mod };
37
- };
38
- Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.LazyBody = void 0;
40
- const raw_body_1 = __importDefault(require("raw-body"));
41
- const inflation_1 = __importDefault(require("inflation"));
42
- const qs_1 = __importDefault(require("qs"));
43
- const formidable_1 = __importDefault(require("formidable"));
44
- function parseMultipartBody(koaRequest, opts) {
45
- const form = (0, formidable_1.default)(opts.formidable);
46
- return new Promise((resolve, reject) => {
47
- form.parse(koaRequest.req, (err, fields, files) => {
48
- if (err) {
49
- reject(err);
50
- }
51
- else {
52
- resolve({
53
- params: fields,
54
- files: files
55
- });
56
- }
57
- });
58
- });
59
- }
60
- async function getRawBodyText(koaRequest, opts) {
61
- const len = koaRequest.length;
62
- let encoding = koaRequest.headers['content-encoding'];
63
- if (len && !encoding) {
64
- opts.length = len;
65
- }
66
- // TODO how to detect custom encoding on content type to ser encoding for readRawBody
67
- return (await (0, raw_body_1.default)((0, inflation_1.default)(koaRequest.req, opts.inflate), opts)).toString( /*which charset?*/);
68
- }
69
- /**
70
- * Request body class
71
- * json
72
- *
73
- */
74
- class LazyBody {
75
- constructor(ctx, type, data, raw, files) {
76
- Object.defineProperty(this, "ctx", {
77
- enumerable: true,
78
- configurable: true,
79
- writable: true,
80
- value: void 0
81
- });
82
- Object.defineProperty(this, "type", {
83
- enumerable: true,
84
- configurable: true,
85
- writable: true,
86
- value: void 0
87
- });
88
- Object.defineProperty(this, "data", {
89
- enumerable: true,
90
- configurable: true,
91
- writable: true,
92
- value: void 0
93
- });
94
- Object.defineProperty(this, "raw", {
95
- enumerable: true,
96
- configurable: true,
97
- writable: true,
98
- value: void 0
99
- });
100
- Object.defineProperty(this, "files", {
101
- enumerable: true,
102
- configurable: true,
103
- writable: true,
104
- value: void 0
105
- });
106
- this.ctx = ctx;
107
- this.type = type;
108
- this.data = data;
109
- this.raw = raw;
110
- this.files = files;
111
- }
112
- get isEmpty() {
113
- return this.raw === '';
114
- }
115
- assertJSON(statusCode, message) {
116
- if (this.type !== FormType.json) {
117
- this.ctx.throw(statusCode || 415, message);
118
- }
119
- }
120
- assertXML(statusCode, message) {
121
- if (this.type !== FormType.xml) {
122
- this.ctx.throw(statusCode || 415, message);
123
- }
124
- }
125
- /**
126
- * Assert body type is urlencoded
127
- * @param {*} statusCode
128
- * @param {*} message
129
- */
130
- assertForm(statusCode, message) {
131
- if (this.type !== FormType.form) {
132
- this.ctx.throw(statusCode || 415, message);
133
- }
134
- }
135
- assertMultipart(statusCode, message) {
136
- if (this.type !== FormType.multipart) {
137
- this.ctx.throw(statusCode || 415, message);
138
- }
139
- }
140
- assertText(statusCode, message) {
141
- if (this.type !== FormType.text) {
142
- this.ctx.throw(statusCode || 415, message);
143
- }
144
- }
145
- /**
146
- * Assert that body type is either multipart or urlencoded
147
- * @param {*} statusCode
148
- * @param {*} message
149
- */
150
- assertParams(statusCode, message) {
151
- if (this.type !== FormType.form && this.type !== FormType.multipart) {
152
- this.ctx.throw(statusCode || 415, message);
153
- }
154
- }
155
- get text() {
156
- return this.raw;
157
- }
158
- get json() {
159
- return this.isJSON ? this.data : undefined;
160
- }
161
- get xml() {
162
- return this.isXML ? this.data : undefined;
163
- }
164
- get params() {
165
- switch (this.type) {
166
- case FormType.form:
167
- case FormType.multipart:
168
- return this.data;
169
- default: return undefined;
170
- }
171
- }
172
- get isForm() {
173
- return this.type === FormType.form;
174
- }
175
- get isJSON() {
176
- return this.type === FormType.json;
177
- }
178
- get isXML() {
179
- return this.type === FormType.xml;
180
- }
181
- get isMultipart() {
182
- return this.type === FormType.multipart;
183
- }
184
- get isText() {
185
- return this.type === FormType.text;
186
- }
187
- static install(koa, opts = {}) {
188
- opts.encoding = opts.encoding || 'utf8';
189
- opts.limit = opts.limit || '1mb';
190
- Object.defineProperty(koa.request, 'body', {
191
- get() {
192
- if (!this._body) {
193
- this._body = createBody(this, opts);
194
- }
195
- return this._body;
196
- },
197
- // be able to work along code using koa2-formidable (wich sets the body property pf the request)
198
- set(body) {
199
- this._body = body;
200
- }
201
- });
202
- // payload is an alias to request.body
203
- Object.defineProperty(koa.context, 'payload', {
204
- get() {
205
- return this.request.body;
206
- },
207
- set(body) {
208
- this.request.body = body;
209
- }
210
- });
211
- // payload is an alias to request.hasBody in v3
212
- Object.defineProperty(koa.context, 'hasPayload', {
213
- get() {
214
- return this.request.length > 0 ||
215
- this.request.headers['transfer-encoding'] != null;
216
- },
217
- });
218
- }
219
- }
220
- exports.LazyBody = LazyBody;
221
- var FormType;
222
- (function (FormType) {
223
- FormType[FormType["multipart"] = 0] = "multipart";
224
- FormType[FormType["form"] = 1] = "form";
225
- FormType[FormType["json"] = 2] = "json";
226
- FormType[FormType["xml"] = 3] = "xml";
227
- FormType[FormType["text"] = 4] = "text";
228
- })(FormType || (FormType = {}));
229
- async function createBody(koaRequest, opts) {
230
- let type, data, raw, files = null;
231
- if (koaRequest.is('multipart')) {
232
- raw = '';
233
- const result = await parseMultipartBody(koaRequest, opts);
234
- data = result.params || {};
235
- files = result.files || {};
236
- type = FormType.multipart;
237
- }
238
- else if (koaRequest.is('urlencoded')) {
239
- // by default we use qs. You can replace the querystring parser using opts.form
240
- raw = await getRawBodyText(koaRequest, opts);
241
- data = opts.form ? opts.form(raw) : qs_1.default.parse(raw);
242
- type = FormType.form;
243
- }
244
- else if (koaRequest.is('json', '+json')) {
245
- // by default we use JSON.parse. You can replace the json parser using opts.json
246
- if (koaRequest.ctx.hasPayload) {
247
- raw = await getRawBodyText(koaRequest, opts);
248
- }
249
- else {
250
- raw = '';
251
- }
252
- if (raw === '') { // for JSON we support no content posted
253
- data = undefined;
254
- }
255
- else {
256
- data = opts.json ? opts.json(raw) : JSON.parse(raw);
257
- }
258
- type = FormType.json;
259
- }
260
- else if (koaRequest.is('xml', '+xml')) {
261
- // by default fast-xml-parser is used - to change the parser you should provde an xml parser through opts.xml
262
- raw = await getRawBodyText(koaRequest, opts);
263
- if (opts.xml) {
264
- data = opts.xml(raw);
265
- }
266
- else {
267
- let parser = await tryGetXmlParser();
268
- if (parser) {
269
- data = parser.parse(raw);
270
- }
271
- }
272
- type = FormType.xml;
273
- }
274
- else if (koaRequest.is('text/*')) {
275
- raw = await getRawBodyText(koaRequest, opts);
276
- type = FormType.text;
277
- }
278
- else {
279
- type = FormType.text;
280
- // if has body
281
- console.log();
282
- if (koaRequest.ctx.hasPayload) {
283
- raw = await getRawBodyText(koaRequest, opts);
284
- }
285
- else {
286
- raw = '';
287
- }
288
- }
289
- return new LazyBody(koaRequest.ctx, type, data, raw, files);
290
- }
291
- /**
292
- * Use fast-xml-parser if available
293
- * @returns
294
- */
295
- async function tryGetXmlParser() {
296
- try {
297
- const mod = await Promise.resolve().then(() => __importStar(require("fast-xml-parser")));
298
- return new mod.XMLParser();
299
- }
300
- catch (err) {
301
- console.warn("Could not find fast-xml-parser. You need to pass xml option for a custom parser", err);
302
- return undefined;
303
- }
304
- }
305
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,wDAAmC;AACnC,0DAAgC;AAChC,4CAAoB;AACpB,4DAAoC;AAqBpC,SAAS,kBAAkB,CAAC,UAAmB,EAAE,IAAkB;IAI/D,MAAM,IAAI,GAAG,IAAA,oBAAU,EAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IACzC,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACnC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE;YAC9C,IAAI,GAAG,EAAE,CAAC;gBACN,MAAM,CAAC,GAAG,CAAC,CAAC;YAChB,CAAC;iBAAM,CAAC;gBACJ,OAAO,CAAC;oBACJ,MAAM,EAAE,MAAM;oBACd,KAAK,EAAE,KAAK;iBACf,CAAC,CAAC;YACP,CAAC;QACL,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACP,CAAC;AAED,KAAK,UAAU,cAAc,CAAC,UAAmB,EAAE,IAAkB;IACjE,MAAM,GAAG,GAAG,UAAU,CAAC,MAAM,CAAC;IAC9B,IAAI,QAAQ,GAAG,UAAU,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAC;IACtD,IAAI,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAC;QACnB,IAAI,CAAC,MAAM,GAAG,GAAG,CAAC;IACtB,CAAC;IACD,qFAAqF;IACrF,OAAO,CAAC,MAAM,IAAA,kBAAW,EAAC,IAAA,mBAAO,EAAC,UAAU,CAAC,GAAG,EAAE,IAAI,CAAC,OAAO,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,QAAQ,EAAC,kBAAkB,CAA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