Skip to content

Commit

Permalink
Move impl to src
Browse files Browse the repository at this point in the history
  • Loading branch information
rafasofizada committed Nov 11, 2022
1 parent 77fa122 commit ba33051
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 8 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
17 changes: 10 additions & 7 deletions index.ts → src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,19 +82,22 @@ class FileIterator {
private readonly parser: busboy.Busboy,
private readonly config: PechkinConfig,
) {
this.fileController= new FileController(config);
this.fileController = new FileController(config);

this.iterator = on(this.parser, 'file');

// AsyncIterableIterator interface's next(), return(), throw() methods are optional, however,
// from the Node.js source code for on(), the returned object always providers
// implementations for next(), return(), throw().
this.parser
.once('partsLimit', () => {
return this.iterator.throw(new TotalLimitError("maxTotalPartCount"));
return this.iterator.throw!(new TotalLimitError("maxTotalPartCount"));
})
.once('filesLimit', () => {
return this.iterator.throw(new TotalLimitError("maxTotalFileCount"))
return this.iterator.throw!(new TotalLimitError("maxTotalFileCount"))
})
.once('error', (error) => {
return this.iterator.throw(error);
return this.iterator.throw!(error);
})
.once('close', () => {
return this.iterator.return!();
Expand Down Expand Up @@ -181,7 +184,7 @@ class FileController {

constructor(private readonly config: PechkinConfig) {}

getFieldControllerUpsert(field: string): [TotalLimitError, SingleFileFieldController?] {
getFieldControllerUpsert(field: string): [TotalLimitError] | [null, SingleFileFieldController] {
this.fileFieldControllers[field] ??= new SingleFileFieldController(field, this.config);

if (Object.keys(this.fileFieldControllers).length > this.config.base.maxTotalFileFieldCount) {
Expand All @@ -203,7 +206,7 @@ class SingleFileFieldController {
this.limits = this.fileFieldLimits(field, config);
}

limitCount(): [FieldLimitError, number] {
limitCount(): [FieldLimitError | null, number] {
this.count += 1;

if (this.count > this.limits.maxFileCountPerField) {
Expand Down Expand Up @@ -236,7 +239,7 @@ class SingleFileFieldController {
private fileFieldLimits(field: string, config: PechkinConfig): FileFieldLimits {
return {
...config.base,
...(config.fileOverride[field] ?? {}),
...(config.fileOverride?.[field] ?? {}),
};
}
}
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
"module": "CommonJS",
"sourceMap": true
},
"include": ["index.ts", "manual-test.ts"],
"include": ["src"],
"exclude": ["node_modules"]
}

0 comments on commit ba33051

Please sign in to comment.