Skip to content

Commit 6ee0fdf

Browse files
committed
fix: snapshot supported client options once
1 parent 91ce99c commit 6ee0fdf

2 files changed

Lines changed: 20 additions & 14 deletions

File tree

src/client.ts

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,32 @@ type UnsupportedCometAPIOption = (typeof UNSUPPORTED_COMETAPI_OPTIONS)[number];
1212
function sanitizeOptions<T extends Partial<ClientOptions>>(
1313
options: T,
1414
): Omit<T, UnsupportedCometAPIOption> {
15-
const {
16-
provider,
17-
workloadIdentity,
18-
dangerouslyAllowBrowser,
19-
...supportedOptions
20-
} = options;
21-
const unsupportedOptions = {
22-
provider,
23-
workloadIdentity,
24-
dangerouslyAllowBrowser,
25-
};
26-
2715
for (const option of UNSUPPORTED_COMETAPI_OPTIONS) {
28-
if (unsupportedOptions[option] !== undefined) {
16+
if (Reflect.get(options, option) !== undefined) {
2917
throw new OpenAIError(
3018
`The \`${option}\` option is not supported by CometAPI.`,
3119
);
3220
}
3321
}
3422

23+
const supportedOptions = {} as Omit<T, UnsupportedCometAPIOption>;
24+
for (const option of Reflect.ownKeys(options)) {
25+
if (
26+
UNSUPPORTED_COMETAPI_OPTIONS.includes(
27+
option as UnsupportedCometAPIOption,
28+
) ||
29+
!Object.prototype.propertyIsEnumerable.call(options, option)
30+
) {
31+
continue;
32+
}
33+
Object.defineProperty(supportedOptions, option, {
34+
configurable: true,
35+
enumerable: true,
36+
value: Reflect.get(options, option),
37+
writable: true,
38+
});
39+
}
40+
3541
return supportedOptions;
3642
}
3743

tests/config.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ describe("CometAPI configuration", () => {
309309
options as unknown as CometAPIOptions,
310310
);
311311

312-
expect(reads).toBeGreaterThan(0);
312+
expect(reads).toBe(1);
313313
expect(error.message).toMatch(/browser-like environment/i);
314314
expectSecretFreeError(error, [browserKey], logger);
315315
});

0 commit comments

Comments
 (0)