MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / boundedProvider

Function boundedProvider

packages/core/sdk/src/executor.ts:2135–2166  ·  view source on GitHub ↗
(provider: CredentialProvider, key: string)

Source from the content-addressed store, hash-verified

2133 * Optional methods stay optional — a provider that cannot enumerate must not
2134 * appear to. */
2135 const boundedProvider = (provider: CredentialProvider, key: string): CredentialProvider => {
2136 // Wrapping must change neither how the provider's methods are CALLED nor what the
2137 // object LOOKS like.
2138 //
2139 // Spreading would break the second: a spread copies only own ENUMERABLE properties, so
2140 // everything on a class's prototype — its methods, and accessors like `writable` — is
2141 // dropped silently. Nothing raises; the wrapper simply appears not to have the capability
2142 // and the caller takes a path the provider meant to own. `Object.create` keeps the whole
2143 // object reachable, including anything added to the interface later.
2144 //
2145 // Each bounded method is invoked ON the provider, which is the first half: a destructured
2146 // binding called bare loses `this`, and a class-based provider throws TypeError on its
2147 // first call. Every provider in this repo is an object literal and cannot notice either
2148 // problem, but "wrap any provider" is the whole point of this funnel.
2149 const bounded: Record<string, unknown> = {
2150 get: (id: ProviderItemId) => boundedCall(provider.get(id), key, "get"),
2151 };
2152 if (provider.has) {
2153 bounded.has = (id: ProviderItemId) => boundedCall(provider.has!(id), key, "has");
2154 }
2155 if (provider.set) {
2156 bounded.set = (id: ProviderItemId, value: string) =>
2157 boundedCall(provider.set!(id, value), key, "set");
2158 }
2159 if (provider.delete) {
2160 bounded.delete = (id: ProviderItemId) => boundedCall(provider.delete!(id), key, "delete");
2161 }
2162 if (provider.list) {
2163 bounded.list = () => boundedCall(provider.list!(), key, "list");
2164 }
2165 return Object.assign(Object.create(provider) as CredentialProvider, bounded);
2166 };
2167
2168 const registerCredentialProvider = (
2169 provider: CredentialProvider,

Callers 1

Calls 2

boundedCallFunction · 0.85
getMethod · 0.65

Tested by

no test coverage detected