Skip to content

NodeJS: Create with() method to chain objects - #4332

Merged
dolanor merged 4 commits into
dagger:mainfrom
slumbering:sdk-nodejs-chainable-utils
Feb 10, 2023
Merged

dolanor merged 4 commits into
dagger:mainfrom
slumbering:sdk-nodejs-chainable-utils

Conversation

@slumbering

@slumbering slumbering commented Jan 9, 2023 •

Copy link
Copy Markdown
Contributor

Close to the issue:

This first iteration is using the pattern proposed by @sipsma.

func AddAFewMounts(c *dagger.Container) *dagger.Container {
  return c.
    WithMountedDirectory("/foo", c.Host().Directory("foo").
    WithMountedDirectory("/bar", c.Host().Directory("bar")
}

func main() {
 output, err := Container().
    From("alpine").
    WithWorkdir("/foo").
    With(AddAFewMounts).
    Exec("blah").Stdout().Contents()
...
}

@dolanor I know that you're doing some refactoring with the codegen so I'll leave you this part (talking about adding the with() method). You can directly push on this PR. Thanks

Signed-off-by: jffarge [email protected]

@slumbering slumbering self-assigned this Jan 9, 2023
@slumbering
slumbering requested review from dolanor and sipsma January 9, 2023 10:29
@slumbering slumbering changed the title Create with method to chain objects Create with() method to chain objects Jan 9, 2023

@TomChv TomChv left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

That's an excellent new feature! About code generation, I think each type that is composed of a query could have the method with that with the same content as in the PR.

Why should we do this to all types composed of query?

For consistency and to avoid the particular case, it's more complex to generate a with only for containers that generate a with for all types with queries in.

WDYT @dolanor @slumbering ?

Comment thread sdk/nodejs/api/client.gen.ts Resolved
@slumbering

Copy link
Copy Markdown
Contributor Author

That's an excellent new feature! About code generation, I think each type that is composed of a query could have the method with that with the same content as in the PR.

Why should we do this to all types composed of query?

For consistency and to avoid the particular case, it's more complex to generate a with only for containers that generate a with for all types with queries in.

WDYT @dolanor @slumbering ?

Agreed with that. Every types should have a with() method.

@slumbering
slumbering force-pushed the sdk-nodejs-chainable-utils branch 2 times, most recently from a2a6220 to 996fd0b Compare January 17, 2023 09:25
@TomChv
TomChv force-pushed the sdk-nodejs-chainable-utils branch from 996fd0b to c8e6227 Compare January 19, 2023 17:48
@slumbering
slumbering force-pushed the sdk-nodejs-chainable-utils branch 2 times, most recently from bce5012 to e41f9fb Compare January 23, 2023 15:12
@slumbering

Copy link
Copy Markdown
Contributor Author

@TomChv I'm aware that you've did a significant refacto here on the codegen, so forgive me for the object.ts.tmpl update ;)

@slumbering

Copy link
Copy Markdown
Contributor Author

That's an excellent new feature! About code generation, I think each type that is composed of a query could have the method with that with the same content as in the PR.

Why should we do this to all types composed of query?

For consistency and to avoid the particular case, it's more complex to generate a with only for containers that generate a with for all types with queries in.

WDYT @dolanor @slumbering ?

I've just updated the template to get the with() method for every types

@slumbering
slumbering force-pushed the sdk-nodejs-chainable-utils branch from 0409ce5 to 6e577cb Compare January 23, 2023 16:20
@TomChv
TomChv force-pushed the sdk-nodejs-chainable-utils branch from c48affe to 4d619ce Compare January 26, 2023 04:32
@TomChv

TomChv commented Jan 26, 2023

Copy link
Copy Markdown
Member

I updated this PR with an implementation of the Go With too!

@helderco do you think you can do it for python?

@helderco

helderco commented Feb 1, 2023

Copy link
Copy Markdown
Contributor

Instead of multiple people being assigned to the same PR, especially for different SDKs, I prefer separate issues/PRs.

I want to do it, but the when depends of backlog priorities.

@helderco helderco removed their assignment Feb 1, 2023
@TomChv

TomChv commented Feb 1, 2023

Copy link
Copy Markdown
Member

@helderco So can we merge this PR if it's supports correctly With?

@TomChv
TomChv force-pushed the sdk-nodejs-chainable-utils branch from 4d619ce to 99c7db7 Compare February 1, 2023 23:17
@slumbering

Copy link
Copy Markdown
Contributor Author

Instead of multiple people being assigned to the same PR, especially for different SDKs, I prefer separate issues/PRs.

I want to do it, but the when depends of backlog priorities.

Agree with that. There is no rush and this is not a priority AFAIK. It was just a nice to have @TomChv.

@helderco

helderco commented Feb 2, 2023

Copy link
Copy Markdown
Contributor

@helderco So can we merge this PR if it's supports correctly With?

I think so, at which point it can become a priority to keep the SDKs in sync, but it doesn't take long to implement.

@TomChv
TomChv force-pushed the sdk-nodejs-chainable-utils branch from 99c7db7 to ff37b59 Compare February 2, 2023 23:38
@slumbering
slumbering force-pushed the sdk-nodejs-chainable-utils branch from ff37b59 to 15ec87d Compare February 9, 2023 12:37
@slumbering

slumbering commented Feb 9, 2023 •

Copy link
Copy Markdown
Contributor Author

Waiting for approval and once checks passed, I'll merge this PR

@dolanor

dolanor commented Feb 9, 2023

Copy link
Copy Markdown
Contributor

Why should we do this to all types composed of query?

For consistency and to avoid the particular case, it's more complex to generate a with only for containers that generate a with for all types with queries in.

WDYT @dolanor @slumbering ?

I might not understand what are types composed of query, but I don't understand what a secretA.with(secretB) is supposed to give me? secretA? secretB? A merge of both? What would that look like?
For me, this pattern only applies to types who already use withXxx() methods, which for now are Container and Directory.
Am I missing something?

@dolanor dolanor left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

remove with for the types that don't need it. Unless I'm wrong.

@slumbering

Copy link
Copy Markdown
Contributor Author

pes composed of que

Why should we do this to all types composed of query?
For consistency and to avoid the particular case, it's more complex to generate a with only for containers that generate a with for all types with queries in.
WDYT @dolanor @slumbering ?

I might not understand what are types composed of query, but I don't understand what a secretA.with(secretB) is supposed to give me? secretA? secretB? A merge of both? What would that look like? For me, this pattern only applies to types who already use withXxx() methods, which for now are Container and Directory. Am I missing something?

The purpose of .with() is to group chain objects and is not related to methods (like Container and Directory) that have withXxx(). For instance you could use it with Git:

function gitFunc(c) {
  return c
  .branch('foo')
  .tag('bar')
  ...
}

connect(async (client) => {
  const src = client.git("http").with(gitFunc)
})

We've also choose here to use with() in every methods for consistency.

@dolanor

dolanor commented Feb 10, 2023

Copy link
Copy Markdown
Contributor

Ok, I think I see now. Good for me!

@dolanor
dolanor merged commit 5d9218f into dagger:main Feb 10, 2023
@helderco helderco mentioned this pull request Mar 29, 2023
@helderco helderco changed the title Create with() method to chain objects NodeJS: Create with() method to chain objects Apr 10, 2023
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.

4 participants