Exposing services in different versions

Using only default versions

Parent


expose({
  services: {
    foo: {
      bar: () => 'Hi from parents default impl'
    }
  }
})
        

Child


expose({
  services: {
    foo: {
      bar: () => 'Hi from childs default impl'
    }
  }
}).then(({services: {foo}}) => {
  // expecting 'Hi from parents default impl'
  showResult(foo.bar())
})
        

Example

Using matching versions

Parent


expose({
  services: {
    foo: {
      versions: {
        '1.0.0': { bar: () => 'Hi from parents first impl' }
        '2.0.0': { bar: () => 'Hi from parents better impl' }
      }
    }
  }
})
        

Child


expose({
  services: {
    foo: {
      versions: {
        '1.0.0': { bar: () => 'Hi from childs first impl' }
        '1.2.0': { bar: () => 'Hi from childs other impl' }
      }
    }
  }
}).then(({services: {foo: {'1.0.0': foo, '1.2.0': otherFoo}}}) => {
  // expecting 'Hi from parents first impl'
  showResult(foo.bar())

  // expecting 'Hi from childs other impl' since the parent did not
  // override version 1.2.0
  showResult2(otherFoo.bar())
})
        

Example

On automatic version matching

The Collage will NOT support any form of automatic version matching. Here is why.

There are a few different concepts in use, to automatically match versions to compatible counterparts. The most known being sem-ver.

We debated, putting some form of that into the api but descided against it for the reason of simplicity.

Given the context of the Collage, there is not really a realistic use case for trying to match versions together in any automated form. Doing so does however needlesly complicate the implementation and the concepts used in the code.

So until there are some solid use cases for it, the Collage will only support direct version matching, treating the versionless service implementation as a kind of default version that itself will only match other default versions of the same service.

If that setup is to restrictive for your usecase and you are already using semver as version identifiers, consider leaving the last diget from the version you describe in the Collage.
So instead of defining version 1.3.15, consider only describing version 1.3. This way, any implementation on a minor version will automatically match the one your are exposing.