Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update index.d.ts #154

Merged
merged 5 commits into from
Sep 3, 2020
Merged

Update index.d.ts #154

merged 5 commits into from
Sep 3, 2020

Conversation

BlackGlory
Copy link
Contributor

@BlackGlory BlackGlory commented Sep 1, 2020

Update index.d.ts to v3.0

Checklist

If the field names are the same, the value of the field will be an array.
Copy link
Member

@StarpTech StarpTech left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, thanks.

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind to add a test for this type?

@BlackGlory
Copy link
Contributor Author

BlackGlory commented Sep 1, 2020

@mcollina I did not find a file for testing TypeScript types in the repo, test/index.test-d.ts doesn't look like a unit test.

@BlackGlory
Copy link
Contributor Author

test/index.test-d.ts is the v2.0 test file, so I updated it to v3.0.
But IMHO, since the file is not updated with the new version, obviously these tests are not helpful.

@BlackGlory BlackGlory changed the title Update MultipartFields Update index.d.ts Sep 2, 2020
@BlackGlory
Copy link
Contributor Author

Considering the properties of the field type, it seems necessary to split Multipart into two interfaces.
But it will break the examples in the README, because we need to distinguish between different types. I'm not sure if these definitions should be added.

type Multipart = MultipartField | MultipartFile

interface MultipartField {
  fieldname: string
  value: string
  fieldnameTruncated: boolean
  valueTruncated: boolean
  fields: MultipartFields
}

interface MultipartFile  {
  toBuffer: () => Promise<Buffer>,
  file: NodeJS.ReadableStream,
  filepath: string,
  fieldname: string,
  filename: string,
  encoding: string,
  mimetype: string,
  fields: MultipartFields
}

@hixus
Copy link

hixus commented Sep 2, 2020

I might also export all interfaces (for example Multipart) so one can use them for own function declarations that use the result

@mcollina
Copy link
Member

mcollina commented Sep 2, 2020

I don't understand the question. Is this ready to land?

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@hixus
Copy link

hixus commented Sep 2, 2020

I don't understand the question. Is this ready to land?

Could be different pr, but for example I might wan't to define separate handler which would take just the Multipart as an argument. Currently not possible without defining it again.

const handleFile = async (part: Multipart) => {
  pump(part.file, fs.createWriteStream(part.filename))
}

server.post("/upload", async (req, reply) => {
  const parts = req.parts()
  for await (const part of parts) {
    if (part.file) {
      await handleFile(part)
    } else {
      console.log(part)
    }
  }
  reply.send()
});

With type exports one could just do import {Multipart} from 'fastify-multipart'

@BlackGlory
Copy link
Contributor Author

This PR is ready to merge.

It may take someone more familiar with this project to decide which TypeScript interfaces should be exported, not me.

index.d.ts Outdated Show resolved Hide resolved
@fox1t
Copy link
Member

fox1t commented Sep 2, 2020

Nice work! Thanks for you contribution.
There is one missing export to add, then this PR can be merged.

Co-authored-by: Maksim Sinik <maksim@sinik.it>
Copy link
Member

@fox1t fox1t left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@mcollina mcollina merged commit 6f7803c into fastify:master Sep 3, 2020
@BlackGlory BlackGlory deleted the patch-1 branch September 4, 2020 01:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants