Skip to content

ProviderId ignored when calling ResourceAPI from plugin via Server API #2827

Description

@jeyrb

Noticed this when adding a second tides provider - internal calls to ResourceAPI returned empty extremes because it called all the providers and let the second one override the populated array with its empty array. This happens whether or not the preferred provider Id is given.

My plugin now reverts to calling the Resources API over HTTP, which works fine.

What looks like the problem:

api/resources/index.ts

async listResources(
  resType: SignalKResourceType,
  params: { [key: string]: any },
  providerId?: string
) {
  const provider = this.checkForProvider(resType, providerId)
  if (!provider) {
    return Promise.reject(new Error(`No provider for ${resType}`))
  }
  return this.listFromAll(resType, params)   // <-- providerId is discarded here
}

providerId is only used to validate that some provider exists (checkForProvider) — the actual data comes from listFromAll() line 364-388, which ignores providerId entirely and queries every registered provider for that resource type, then merges results:

private async listFromAll(resType: string, params: { [key: string]: any }) {
  const result = {}
  const req: Promise<any>[] = []
  this.resProvider[resType].forEach((v) => {
    req.push(v.listResources(params))
  })
  const resp = await Promise.allSettled(req)
  resp.forEach((r) => {
    if (r.status === 'fulfilled') {
      Object.assign(result, r.value)   // <-- last provider to settle wins for any shared key
    }
  })
  return result
}

Two separate problems compound here:

providerId is dropped — even if you explicitly ask for provider=tides, listFromAll still calls every provider (e.g. mareas-ihm too) instead of just the one requested.
Merge order is nondeterministic — providers are iterated in Map insertion order (registration order), not by any priority, and Promise.allSettled + Object.assign means whichever provider's promise is listed last simply overwrites earlier ones for any resource ID they both return. There's no guarantee the preferred/specified provider's values survive the merge.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions