Skip to content

Ipfs package#188

Closed
MakMuftic wants to merge 69 commits into
polywrap:origin-devfrom
NodeFactoryIo:mmuftic/ipfs-package
Closed

Ipfs package#188
MakMuftic wants to merge 69 commits into
polywrap:origin-devfrom
NodeFactoryIo:mmuftic/ipfs-package

Conversation

@MakMuftic
Copy link
Copy Markdown
Contributor

@MakMuftic MakMuftic commented Mar 4, 2021

Changes

HTTP plugin

I have refactored the HTTP plugin to support sending body as form data (this is necessary as IPFS expects files to come in this way). Currently, I implemented this by defining Body type to be:

type Body {
  stringBody: String
  rawBody: Bytes
  formDataBody: FormData!
}

This allows users to define what kind of request body (payload) is going to be sent. I am not entirely pleased with this solution...it would be for sure better to define a union type for the body that would include all defined types (body: String | Bytes | FormData) but we are not going to support this so I had to find a workaround. Another idea is to have multiple post functions defined within HTTP plugin (postWithStringPayload, postWithFormDataPayload,...).

@dOrgJelli I would like to hear what you think about the current solution.

IPFS package

Implemented catFile, catToString and addFile ipfs functions + e2e tests.

Other

I expanded query command of CLI to support defining paths toward files in format file:path/to/file/example.txt. This will read file content and convert it to Uint8Array. This is used when testing ipfs function addFile, but I think functionality itself could be useful in multiple usecases.

TODO

I can't figure out why, but when inside schema definition of HTTP plugin I set property formDataBody of body to be nullable then generated code has a problem on the compilation. For some reason in generated function writeHttp_Body even though there is a check if (type.formDataBody) before calling write, the type is being considered to be Http_FormData | null, and because of that compilation fails.

Here is the error message:

Compile Web3APIERROR TS2322: Type 'src/mutation/w3/imported/Http_FormData/index/Http_FormData | null' is not assignable to type 'src/mutation/w3/imported/Http_FormData/index/Http_FormData'.

     Types.Http_FormData.write(writer, type.formDataBody);
                                       ~~~~~~~~~~~~~~~~~
 in src/mutation/w3/imported/Http_Body/serialization.ts(29,39)

And here is a snip from generated code where an error occurs:

export function writeHttp_Body(writer: Write, type: Http_Body): void {
  writer.writeMapLength(3);
  writer.writeString("stringBody");
  writer.writeNullableString(type.stringBody);
  writer.writeString("rawBody");
  writer.writeNullableBytes(type.rawBody);
  writer.writeString("formDataBody");
  if (type.formDataBody) {
    Types.Http_FormData.write(writer, type.formDataBody);
  } else {
    writer.writeNil();
  }
}

Issues

Closes #188
Closes #247

@morrigan morrigan requested a review from dOrgJelli March 4, 2021 19:17
@dOrgJelli dOrgJelli changed the base branch from prealpha to prealpha-dev March 8, 2021 21:23
@MakMuftic MakMuftic changed the base branch from prealpha-dev to prealpha March 15, 2021 12:32
@MakMuftic MakMuftic requested a review from dOrgJelli May 27, 2021 18:16
@cbrzn
Copy link
Copy Markdown
Contributor

cbrzn commented Sep 8, 2021

hey @MakMuftic I am trying to build this locally but I am getting an error:

Screenshot 2021-09-08 at 04 30 12

Probably I am missing something, do you have any idea?

@MakMuftic
Copy link
Copy Markdown
Contributor Author

hey @MakMuftic I am trying to build this locally but I am getting an error:

Screenshot 2021-09-08 at 04 30 12

Probably I am missing something, do you have any idea?

Sorry for the late reply, I will investigate what happened and try to resolve this problem asap

@dOrgJelli dOrgJelli changed the base branch from prealpha-dev to origin-dev July 6, 2022 09:07
@dOrgJelli
Copy link
Copy Markdown
Contributor

Thank you so much for your work on this @MakMuftic, it's wonderful!

We're migrating this wrapper to the integrations repo in this PR: polywrap/wrap-integrations#101

Going to close this.

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.

IPFS WASM Web3API

3 participants