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

Make services API public #5165

Closed
Closed

Description

@nathansobo
No description provided.

Activity

  1. lee-dohm commented on Jan 21, 2015

    @lee-dohm
    Contributor

    👍

  2. maxbrunsfeld commented on Jan 21, 2015

    @maxbrunsfeld
    Contributor

    @nathansobo raised the concern that if we make the ServiceHub public, we won't have a way to figure out a package's provided or consumed services without activating the package. We could have some alternative scheme where the package's package.json file somehow declares a list of provided and consumed services. One possibility:

    package.json:

    {
      "providedServices": {
        "order-pizza": ["0.2.0", "./lib/order-pizza.coffee"]
      },
      "serviceDependencies": {
        "status-bar": ["^0.3.0", "./lib/init-status-bar.coffee"]
      }
    }

    order-pizza.coffee:

    module.exports =
      placeOrder: ->
        # provide service

    init-status-bar.coffee:

    module.exports = (statusBarService) ->
      # use the service
    
      new Disposable ->
        # stop using the service

    I'm guessing this is too complicated. How important is it to be able to determine a package's service relationships statically? It could allow us to do interesting things like automatically install dependent packages, or warn users about incompatibilities.

  3. nathansobo commented on Jan 21, 2015

    @nathansobo
    ContributorAuthor

    @maxbrunsfeld I'd be down for this design, but I'm thinking it should look like this:

    package.json:

    {
      "serviceProvisions": {
        "order-pizza": {
          "0.2.0": "./lib/order-pizza.coffee"
        }
      },
      "serviceDependencies": {
        "status-bar": {
          "order-pizza": "^0.2.0"
        }
      }
    }

    With this design, packages would still call atom.services.consume in code with a callback on activate. If we didn't like that we could point to a path in the dependencies hash and combine the service name and version into a single string like order-pizza@^0.2.0.

    My big question is whether we should/could still offer a programmatic interface to atom.services.provide. Do we always want services to be offered statically? What if a package wants to add and remove services dynamically? Perhaps we hold off on that case until we see a compelling need.

    /cc @bolinfest

  4. lee-dohm commented on Jan 21, 2015

    @lee-dohm
    Contributor

    I think if a package provided services dynamically, it could provide them through an initially static service. For example:

    package.json:

    {
      "serviceProvisions": {
        "query-something": {
          "0.2.0": "./lib/query-something.coffee"
        }
      }
    }

    query-something.coffee:

    module.exports =
      querySomething: (somethings...) ->
        # Sets up a service for each something that can then be called
        #   atom.services.provide 'query-something.something1', '0.2.0',
        #     etc etc etc

    I think that this pattern could be documented for people to use if they want to provide dynamic services.

  5. park9140 commented on Jan 24, 2015

    @park9140

    I like the idea of having the services registered via package json so that package dependencies can be located. A couple things on this.

    In https://github.com/atom-community/autocomplete-plus/tree/singleton-autocomplete-manager @joefitzgerald and I are working on implementation that does a many to one sort of service dependency. We are requesting "autocomplete:provider-api" services, and then doing requests for suggetions to the provided services.

    In these many to one cases could we could perhaps offer up suggestions in the install list for packages that provide the dependent service. We could also list packages that implement the services on the package info page, so that authors would not need to manually maintain lists like in https://github.com/AtomLinter/Linter/blob/master/README.md

    When we consume services, maybe we should do some automatic binding as is suggested for the "serviceProvisions" above.

    "serviceDependencies": {
        "status-bar": {
          "order-pizza":  {
            "^0.2.0": "registerPizzaProvider"
            "~0.1.0": "registerLegacyPizzaProvider"
        }
      }
    }
    

    In the main package you would then implement registerPizzaProvider and registerLegacyPizzaProvider as methods that are called when a serviceDependency is located. It would execute the consume for the services when a package is activated, and dispose the consumer on package deactivation.

  6. joefitzgerald commented on Jan 24, 2015

    @joefitzgerald
    Contributor

    I would definitely like to retain programmatic access for registration of consumers and providers. The primary reason: in go-plus I allow my users to flip a config flag indicating they would like to have my autocomplete-plus provider activated, or deactivated. If I can only express service dependencies in package.json, I can't provide a way to toggle the feature associated with the provider registration.

  7. park9140 commented on Jan 24, 2015

    @park9140

    I had some earlier comments about that any resolution to this issue should resolve. Just for reference check out #2412

  8. bolinfest commented on Jan 26, 2015

    @bolinfest
    Contributor

    @maxbrunsfeld @nathansobo For the schema, I think that it should satisfy the following design requirements:

    • Is namespaced with atom so it is does not conflict with other properties in the "npm namespace."
    • Multiple providers can be specified for a service.
    • Service definitions have room to declare associated metadata.
      "atomServiceProviders": {
        "nameOfServiceProvider": [ // There are two providers for this keyPath.
          {
            "name": "JS Autocomplete Provider", // For debugging? For display in Preferences?
            "version": "0.2.0",
            "path": "./lib/js-autocomplete-provider.js",
            "config": {
              // Not 100% how this will be used, but could be a good escape hatch later.
            }
          }
          {
            "name": "CSS Autocomplete Provider",
            "version": "0.2.0",
            "path": "./lib/css-autocomplete-provider.js",
            "config": {
            }
          }
        ]
      },

    I think an important question is whether a initializing a service requires activating the package that contains it (I want to be sensitive to the startup time of Atom, and some service providers may be appropriate to use before package activation). Maybe a provider specifies whether activation is required in its metadata? And is there any risk of introducing circular dependencies if activation is required? Presumably it's no worse than ordinary circular dependencies in CommonJS.

    In terms of the ergonomics of ServiceHub.consume(), personally, instead of passing a callback that receives providers one at a time, I would rather it return a Promise that contains an array of providers. As a consumer, I would rather know what my array of provider options is up front rather than "waiting to see" what gets registered in the future. Admittedly, this would require a separate API for registering a listener on changes to the space of providers for a (keyPath, versionRange) tuple.

    @joefitzgerald provides a good example of why developers should also be able to register service providers dynamically. Though consumers of service providers (for convenience) may end up implementing services that expect all providers to be declared statically. For example, if consume() returned an array as I described, I would probably default to implementing a consumer as calling consume() once and being done with it. Maybe it's bad to encourage that behavior.

  9. park9140 commented on Jan 27, 2015

    @park9140

    @bolinfest,
    I really feel like services shouldn't be registered unless a package is activated. Just as packages should avoid doing work outside of activation, services shouldn't be isolated behind their containing package being active.

    As for the consuming providers via promise, that would enforce a pattern of use that would disallow @joefitzgerald's dynamic registration. In order to resolve the promise we would need a known list of services we are expecting, and we would not necessarily be getting a dynamically registered service. That said, I do think some methodology to efficiently retrieve all active services of a particular version would be nice.

    I like the inclusion of meta data about the service, could have things like short and long descriptions that would be shown in the package list when searching for implementations of a given service.

  10. maxbrunsfeld commented on Jan 27, 2015

    @maxbrunsfeld
    Contributor

    In go-plus I allow my users to flip a config flag indicating they would like to have my autocomplete-plus provider activated, or deactivated

    @bolinfest @joefitzgerald I'm reluctant to add both static and dynamic service registration to the API right away. It seems to me like autocomplete-plus and/or go-plus could work out a solution to this problem without dynamic service registration. For example, could the autocomplete-provider in go-plus be extracted into a separate package that can simply be enabled or disabled?

    I really feel like services shouldn't be registered unless a package is activated. Just as packages should avoid doing work outside of activation, services shouldn't be isolated behind their containing package being active.

    I agree with @park9140 here.

    I would rather it return a Promise that contains an array of providers.

    @bolinfest I think the API needs to acknowledge that packages could be activated or deactivated at any time, so there's no single moment in time where all the providers for a given service are known to be available. In my mind, the current callback-based approach is better for that reason.

  11. maxbrunsfeld commented on Jan 27, 2015

    @maxbrunsfeld
    Contributor

    I like @park9140's idea of specifying method names rather than file paths. We could avoid specifying file paths altogether. This would allow service hooks to share data with the main module with less boilerplate:

    In the package.json:

    {
      "serviceProvisions": {
        "order-pizza": {
          "description": "Displays a GIF of a piping-hot Pizza",
          "versions": {
            "0.2.8": "orderPizza",
            "0.1.3": "orderLegacyPizza"
          }
        }
      },
    
      "serviceDependencies": {
        "status-bar": {
          "^0.2.0": "manageStatusBar",
          "^0.1.0": "manageLegacyStatusBar"
        }
      }
    }

    In the main module:

    module.exports =
      activate: ->
        # ...
    
      orderPizza: ->
        # ...
    
      orderLegacyPizza: ->
        # ...
    
      manageStatusBar: (statusBarService) ->
         # ...
    
      manageLegacyStatusBar: (statusBarService) ->
        # ...

    This adds more code to the main module, but I think that's ok. It's analogous to the way npm modules all have one main 'index' source file that requires all of the others.

  12. 3 remaining items

  13. lee-dohm commented on Jan 27, 2015

    @lee-dohm
    Contributor

    Great! Other than that, I agree with @maxbrunsfeld's proposal too. I think it is quite elegant. One question ...

    Let's say I have a package, foo-bar, like the one in @maxbrunsfeld's proposal:

    {
      "serviceProvisions": {
        "order-pizza": {
          "description": "Displays a GIF of a piping-hot Pizza",
          "versions": {
            "0.2.8": "orderPizza",
            "0.1.3": "orderLegacyPizza"
          }
        }
      },
    
      "serviceDependencies": {
        "status-bar": {
          "^0.2.0": "manageStatusBar",
          "^0.1.0": "manageLegacyStatusBar"
        }
      }
    }

    What is the expected behavior in the following situations when I install or upgrade foo-bar?

    1. status-bar is not installed
    2. status-bar v0.0.5 is installed
    3. status-bar v0.1.5 is installed
    4. status-bar v0.2.2 is installed

    Is the expected behavior to always install/update to the latest version of status-bar that is compatible with the version/service dependencies? Will we issue a warning if someone attempts to update to a version of status-bar that will break a service dependency?

  14. joefitzgerald commented on Jan 27, 2015

    @joefitzgerald
    Contributor

    Why is there such a reluctance to having a programmatic API? There as a litany of use cases that will pop up that would be served by programmatic use, and I don't understand why we're moving to config-only registration.

  15. lee-dohm commented on Jan 27, 2015

    @lee-dohm
    Contributor

    One of the things that you and others have requested @joefitzgerald is a method of specifying package dependencies. The configuration-based registration does not have to be a config-only registration, but it does make package dependencies accessible at install/upgrade time ... whereas a programmatic-only approach does not.

  16. joefitzgerald commented on Jan 27, 2015

    @joefitzgerald
    Contributor

    I am very much for a way to specify package dependencies in config. But I think we're conflating the notion of package dependencies and services. I might require autocomplete-plus and need it installed and provide a service to it.

    I might also provide a service for something that will be optionally used only if that package is installed.

    It's possible that we're over-complicating both aspects by conflating them.

  17. maxbrunsfeld commented on Jan 27, 2015

    @maxbrunsfeld
    Contributor

    There as a litany of use cases that will pop up that would be served by programmatic use.

    @joefitzgerald Could you expand on that? I'm open to arguments for why this feature needs to be added to core right away, but so far I don't see a good reason to add it and commit to supporting it indefinitely. In my mind, it's a perfect candidate for deferral; it is completely additive and doesn't affect the design of our package.json-based system.

  18. nathansobo commented on Jan 27, 2015

    @nathansobo
    ContributorAuthor

    By "config-based" do we mean statically specified in the package.json?

    The main reason I favor declaring service dependencies rather than package dependencies is that it provides flexion points in the ecosystem. Packages other than the original service provider can step in and implement a named service, so long as they don't change the API. I can't think of a way I'd want packages to interact other than via services, so it seems redundant to me to separate the concepts right now. But my thinking has changed multiple times on this issue, so I'm open to being convinced.

  19. park9140 commented on Jan 27, 2015

    @park9140

    @joefitzgerald, even with the config based method we could implement hooks in order to dynamically enable/disable the provider. When the services are automatically enabled by the config we could register the service disposable onto the main module so it could be dynamically torn down. We would also need a simple way to re-enable the service as declared in the config.

  20. nathansobo commented on Jan 27, 2015

    @nathansobo
    ContributorAuthor

    Going through the entire API and deprecating things I once thought were good ideas has made me more conservative.

    Maybe we keep the atom.services global and just keep it private and don't advertise it. My goal would be to only have people that a) have a real need and b) are willing to roll with the punches use it. Not sure if that's a sound strategy sociologically.

  21. joefitzgerald commented on Jan 27, 2015

    @joefitzgerald
    Contributor

    Well for what it's worth, the atom.services global is brilliant and it unwinds a ton of hackery via atom.packages whereby packages try to do stuff with other packages. It has been a true pleasure integrating autocomplete-plus with it. I'm still unsure why there's hesitance around it? What danger lies here?

    Loosely coupling the package dependencies is far preferable to the current technique.

    My advice is to separate the notion of package dependencies (I.e. I am the author of go-plus and I require users of go-plus to have autocomplete-plus installed) from the notion service providers (I.e. I optionally provide this service if someone has a consumer that knows what to do with it).

    I might want to specify a package dependency without providing a service. I might want to provide a service without specifying a package dependency (maybe there are 5 options of consumers?).

  22. lee-dohm commented on Jan 27, 2015

    @lee-dohm
    Contributor

    My personal take:

    1. Service dependencies as opposed to package dependencies is a great idea
    2. So long as atom.services is available and used by Atom for sensible things, I'm not too worried about whether it is classified as Essential, Experimental or Private. (I'd like to see it used by the status-bar package, since I have a couple status bar dependent packages.)

    Making this available to the enthusiasts in the community I think will be a big win.

    I think the rest of it can be shaken out over time.

  23. nathansobo commented on Jan 27, 2015

    @nathansobo
    ContributorAuthor

    I might want to specify a package dependency without providing a service. I might want to provide a service without specifying a package dependency (maybe there are 5 options of consumers?).

    It seems like the quoted statement has the relationship inverted. I'm thinking that a package dependency will be expressed as a service dependency.

    By having this information statically available, we can present the user with a list of 5 packages that provide an autocomplete view when they install the go completion provider package. If we have to execute JavaScript to find out the relationship, all of a sudden we can't be as helpful.

    I admit the programmatic interface is a bit nicer in some ways, but I think it's nicer by ignoring an important aspect of the problem, which is analyzing the relationship between packages in order to make the user experience better. That's what I'm worried about by presenting an API that we can't efficiently analyze. I don't want you to install the go completion provider without warning you that it needs autocomplete-plus.

    It's like a Settlers of Catan expansion pack. They warn you loud and clear on the box that it can't be played without the original game.

  24. lock commented on Jan 22, 2019

    @lock

    This issue has been automatically locked since there has not been any recent activity after it was closed. If you can still reproduce this issue in Safe Mode then please open a new issue and fill out the entire issue template to ensure that we have enough information to address your issue. Thanks!

  25. locked as resolved and limited conversation to collaborators on Jan 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions