Datasets:
Download instances/observability-java-sdk-1982/gold/js_sdk.patch from CrossSWE/CrossSWE-Bench: direct link, hf CLI and curl.
- Browser
- Download file 5.75 kB
-
https://huggingface.co/datasets/CrossSWE/CrossSWE-Bench/resolve/main/instances/observability-java-sdk-1982/gold/js_sdk.patch
- Command line
-
hf download hf://datasets/CrossSWE/CrossSWE-Bench/instances/observability-java-sdk-1982/gold/js_sdk.patch
-
curl -L -o js_sdk.patch https://huggingface.co/datasets/CrossSWE/CrossSWE-Bench/resolve/main/instances/observability-java-sdk-1982/gold/js_sdk.patch
5.75 kB
| diff --git a/packages/server/src/provider/multi-provider/multi-provider.ts b/packages/server/src/provider/multi-provider/multi-provider.ts | |
| index 783db72..e4eeafa 100644 | |
| --- a/packages/server/src/provider/multi-provider/multi-provider.ts | |
| +++ b/packages/server/src/provider/multi-provider/multi-provider.ts | |
| export class MultiProvider implements Provider { | |
| Object.freeze(this.providerEntriesByName); | |
| } | |
| - async initialize(context?: EvaluationContext): Promise<void> { | |
| + async initialize(context?: EvaluationContext, domain?: string): Promise<void> { | |
| const result = await Promise.allSettled( | |
| - this.providerEntries.map((provider) => provider.provider.initialize?.(context)), | |
| + this.providerEntries.map((provider) => provider.provider.initialize?.(context, domain)), | |
| ); | |
| throwAggregateErrorFromPromiseResults(result, this.providerEntries); | |
| } | |
| diff --git a/packages/shared/src/open-feature.ts b/packages/shared/src/open-feature.ts | |
| index 00142b5..78ac596 100644 | |
| --- a/packages/shared/src/open-feature.ts | |
| +++ b/packages/shared/src/open-feature.ts | |
| export abstract class OpenFeatureCommonAPI< | |
| const oldProvider = this.getProviderForClient(domain); | |
| const providerName = provider.metadata.name; | |
| + this.assertDomainScopedBindingAllowed(provider, domain); | |
| + | |
| // ignore no-ops | |
| if (oldProvider === provider) { | |
| this._logger.debug('Provider is already set, ignoring setProvider call'); | |
| export abstract class OpenFeatureCommonAPI< | |
| // initialize the provider if it implements "initialize" and it's not already registered | |
| if (typeof provider.initialize === 'function' && !this.allProviders.includes(provider)) { | |
| + const initContext = domain ? (this._domainScopedContext.get(domain) ?? this._context) : this._context; | |
| initializationPromise = provider | |
| - .initialize?.(domain ? (this._domainScopedContext.get(domain) ?? this._context) : this._context) | |
| + .initialize?.(initContext, domain) | |
| ?.then(() => { | |
| wrappedProvider.status = this._statusEnumType.READY; | |
| // fetch the most recent event emitters, some may have been added during init | |
| export abstract class OpenFeatureCommonAPI< | |
| } | |
| } | |
| + private getProviderInstanceBinding(provider: P): string | null { | |
| + if (this._defaultProvider.provider === provider) { | |
| + // Empty string represents the default (unbound) provider. | |
| + return ''; | |
| + } | |
| + | |
| + for (const [domain, wrapper] of this._domainScopedProviders) { | |
| + if (wrapper.provider === provider) { | |
| + return domain; | |
| + } | |
| + } | |
| + | |
| + return null; | |
| + } | |
| + | |
| + private assertDomainScopedBindingAllowed(provider: P, domain?: string): void { | |
| + if (!provider.domainScoped) { | |
| + return; | |
| + } | |
| + | |
| + const existingBinding = this.getProviderInstanceBinding(provider); | |
| + if (existingBinding === null) { | |
| + return; | |
| + } | |
| + | |
| + const requestedBinding = domain ?? ''; | |
| + if (existingBinding === requestedBinding) { | |
| + return; | |
| + } | |
| + | |
| + throw new GeneralError(`Cannot bind domain-scoped provider '${provider.metadata.name}' to more than one domain.`); | |
| + } | |
| + | |
| private get allProviders(): P[] { | |
| return [ | |
| ...[...this._domainScopedProviders.values()].map((wrappers) => wrappers.provider), | |
| diff --git a/packages/shared/src/provider/provider.ts b/packages/shared/src/provider/provider.ts | |
| index 74ae860..bab76c1 100644 | |
| --- a/packages/shared/src/provider/provider.ts | |
| +++ b/packages/shared/src/provider/provider.ts | |
| export interface CommonProvider<S extends ClientProviderStatus | ServerProviderS | |
| */ | |
| readonly runsOn?: Paradigm; | |
| + /** | |
| + * When true, the provider maintains state specific to a single domain (such as a | |
| + * persistent cache) and the SDK will bind it to at most one domain. | |
| + */ | |
| + readonly domainScoped?: boolean; | |
| + | |
| // TODO: in the future we could make this a never to force provider to remove it. | |
| /** | |
| * @deprecated the SDK now maintains the provider's state; there's no need for providers to implement this field. | |
| export interface CommonProvider<S extends ClientProviderStatus | ServerProviderS | |
| * When the returned promise resolves, the SDK fires the ProviderEvents.Ready event. | |
| * If the returned promise rejects, the SDK fires the ProviderEvents.Error event. | |
| * Use this function to perform any context-dependent setup within the provider. | |
| - * @param context | |
| + * @param context the global evaluation context | |
| + * @param domain the bound domain, if any | |
| */ | |
| - initialize?(context?: EvaluationContext): Promise<void>; | |
| + initialize?(context?: EvaluationContext, domain?: string): Promise<void>; | |
| /** | |
| * Track a user action or application state, usually representing a business objective or outcome. | |
| diff --git a/packages/web/src/provider/multi-provider/multi-provider-web.ts b/packages/web/src/provider/multi-provider/multi-provider-web.ts | |
| index e346efe..0a41a30 100644 | |
| --- a/packages/web/src/provider/multi-provider/multi-provider-web.ts | |
| +++ b/packages/web/src/provider/multi-provider/multi-provider-web.ts | |
| export class MultiProvider implements Provider { | |
| Object.freeze(this.providerEntriesByName); | |
| } | |
| - async initialize(context?: EvaluationContext): Promise<void> { | |
| + async initialize(context?: EvaluationContext, domain?: string): Promise<void> { | |
| const result = await Promise.allSettled( | |
| - this.providerEntries.map((provider) => provider.provider.initialize?.(context)), | |
| + this.providerEntries.map((provider) => provider.provider.initialize?.(context, domain)), | |
| ); | |
| throwAggregateErrorFromPromiseResults(result, this.providerEntries); | |
| } | |