Skip to content
This repository has been archived by the owner on Aug 3, 2023. It is now read-only.

feat: unify upload form building #329

Merged
merged 15 commits into from
Jul 29, 2019
Merged

Conversation

ashleymichal
Copy link
Contributor

@ashleymichal ashleymichal commented Jul 18, 2019

This PR introduces structs that are eerily similar to #300 , with the main difference being that the bulk of the changes target the publish process, since that's where the multipart form needs to be built. Hopefully it is clear how this can be extended to add KV Namespaces as Bindings. If it is not, feedback is appreciated!

Further work could be done to make the job of building the Assets to be the responsibility of the Project struct, but this is already pretty big. The best thing happening here is that the form is being built based on the Project, (type for now), which leaves room for that info to come from project config (i.e. project.kv_namespaces).

Steps taken:

  • WranglerJS build step no longer writes metadata.json file
  • Publish step no longer looks for metadata.json file in the filesystem (another "breaking" change)
  • Publish step generates form data based on Project
  • Data structures representing the parts of a Project we want to upload (Assets and its children), and how to translate them into the different parts of a Form (Files and Bindings).
  • all project types call the same form building logic, "assets" are configured per project.

@ashleymichal ashleymichal force-pushed the alewis/feat-generate-metadata branch from 02e550a to 10bafd7 Compare July 18, 2019 18:09
Copy link
Contributor

@xortive xortive left a comment

Choose a reason for hiding this comment

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

the To<Type> pattern in here smells of a reimplementation of https://doc.rust-lang.org/std/convert/trait.Into.html that clones for you. I don't love this pattern as it is hiding clones behind a function call, and I wonder if having a top level type to represent a resource, and a binding type that implements From<Resource> with options in the necessary places would be better. Not necessarily reimplementing pull/#313, but just taking those parts from it.

src/commands/publish/upload_form/mod.rs Show resolved Hide resolved
@ashleymichal
Copy link
Contributor Author

ashleymichal commented Jul 19, 2019

the To<Type> pattern in here smells of a reimplementation of https://doc.rust-lang.org/std/convert/trait.Into.html that clones for you. I don't love this pattern as it is hiding clones behind a function call, and I wonder if having a top level type to represent a resource, and a binding type that implements From<Resource> with options in the necessary places would be better. Not necessarily reimplementing pull/#313, but just taking those parts from it.

what's tricky about the From trait is that it consumes the first resource, but in the case of wasm modules i actually need two things: a file and a binding. perhaps the wording "ToThing" is misleading? and/or the use of traits is overkill and we could just duck type? 🤷‍♀ That is, the method WasmModule#file can be implemented without a ToFile trait, etc, which may just be better now since the trait isn't used in any other function definitions.

@ashleymichal ashleymichal changed the title [WIP] - feat generate metadata feat: unify upload form building Jul 19, 2019
@ashleymichal ashleymichal requested a review from xortive July 19, 2019 13:38
@ashleymichal ashleymichal added feature Feature requests and suggestions and removed status - work in progress labels Jul 19, 2019
@ashleymichal ashleymichal force-pushed the alewis/feat-generate-metadata branch from 7a6036a to 005f122 Compare July 23, 2019 15:02
@ashleymichal
Copy link
Contributor Author

rebased onto master. no merge conflicts.

* The preview service in particular streams the request form, and
requires that the "metadata" part be set first, so this order is important.
* Error out on 400+ status codes for Preview service responses to
provide better error messaging.
Copy link
Contributor

@ashleygwilliams ashleygwilliams left a comment

Choose a reason for hiding this comment

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

some nits but overall LGTM!

@@ -0,0 +1,5 @@
#[derive(Debug)]
pub struct File {
Copy link
Contributor

Choose a reason for hiding this comment

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

we should evaluate what we're doing here! we should probably use a rust builtin... but the "name" here seems like it needs sorting

Copy link
Contributor Author

Choose a reason for hiding this comment

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

got this out, getting what we need from the paths for all the things.

src/commands/publish/upload_form/mod.rs Outdated Show resolved Hide resolved
src/commands/publish/upload_form/mod.rs Outdated Show resolved Hide resolved
if bundle.has_wasm() {
let wasm_module = WasmModule {
path: bundle.wasm_path(),
filename: bundle.get_wasm_binding(),
Copy link
Contributor

Choose a reason for hiding this comment

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

so let's make filename/binding the same in Webpack as RustWasm and always point to the same thing - either wasm or wasmprogram - we can file another issue for it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

src/commands/publish/upload_form/mod.rs Show resolved Hide resolved
src/commands/publish/upload_form/wasm_module.rs Outdated Show resolved Hide resolved
src/commands/publish/upload_form/wasm_module.rs Outdated Show resolved Hide resolved
* namespace wranglerjs::Bundle for grep-ability
* don't clone
@ashleymichal ashleymichal force-pushed the alewis/feat-generate-metadata branch from 8702b0f to e81e6e6 Compare July 25, 2019 19:18
Copy link
Contributor

@ashleygwilliams ashleygwilliams left a comment

Choose a reason for hiding this comment

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

ready to merge once you remove the unwraps!

Ok(form)
}

fn filename_from_path(path: &String) -> String {
Copy link
Contributor

Choose a reason for hiding this comment

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

this should return a Result<String, failure::Error> and the unwraps should be replaced with ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

turns out the unwraps were unwrapping Option types, rather than Result types. do you think this fn should give an error if it gets back a None, bc I'm inclined to feel the caller should. maybe give ProjectAssets a new method that checks the path for a non-empty filename?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd probably make this return Option<String> in that case, and have the caller adapt the None to its own kind of error. I think there's good arguments both ways; I'm interested to hear what @ashleygwilliams says

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@steveklabnik i'm inclined to do something like this, the reasoning being that filename_from_path is kind of just a utility that i feel does not need to be opinionated about what a valid filename is, as it doesn't imply an application of the filename, whereas i could check either before constructing the ProjectAssets struct, or inside the constructor.

@ashleymichal ashleymichal force-pushed the alewis/feat-generate-metadata branch 3 times, most recently from 7456c19 to a72e109 Compare July 26, 2019 20:14
* return Option from filename_from_path
* add constructor methods to WasmModule and ProjectAssets
* add getter methods to WasmModule and ProjectAssets
@ashleymichal ashleymichal force-pushed the alewis/feat-generate-metadata branch from a72e109 to 9c71a34 Compare July 26, 2019 20:18
@ashleymichal ashleymichal merged commit 0e0e4c2 into master Jul 29, 2019
@delete-merged-branch delete-merged-branch bot deleted the alewis/feat-generate-metadata branch July 29, 2019 19:07
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature Feature requests and suggestions refactor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants