Skip to content

options should be a typed interface instead of an a pain object #85

@sjpotter

Description

@sjpotter

By using a plain object, one does make it easy on the developer of the library to serialize whatever the user provides, but makes it difficult on the actual user of the library to know how to use it (one has to hit the docker documentation, instead of having typescript provide the necessary info).

Now, I can imagine an advantage of the object approach is that it will "future proof" against docker additions, where an interface wouldn't.

I think an interface can cover that though.

i.e. lets take container.create(). Instead of taking an optional opts object, it takes an optional opts interface, where the interface can be something like

interface CreateOpts {
    Image?: string;
    Cmd?: Array<string>;
    EntryPoint?: Array<string>;
    Hostconfig?: HostConfigInterfaceOrType;
    NetworkMode?: string;
///    ...OtherPossibleUseful settings...
    GenericOpts?: Object;

Instead of just serializing GenericOpts into a json object (if it exists). we would so something like

const createObj = {}

if (opts.GenericOpts !== undefined) {
    createObj = {...opts.GenericOpts};
}

if (opts.Image !== undefined) {
   createObj.Image = opts.Image
}
// and so forth

while this is a bit verbose for the library writer, I think it would make the library much more usable for the user.

The only negative I can see is that if docker makes backwards incompatible chagnes to the API, but the user of the library is just as screwed then as thir existing code (i.e. how they define the ppts object), could just as easily break, and I'd argue much easier to provide proper bacwards compatability in the method I described.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions