Skip to content

Commit 183d39c

Browse files
chore(internal): add pure annotations, make base APIResource abstract
1 parent c4a6666 commit 183d39c

File tree

11 files changed

+34
-16
lines changed

11 files changed

+34
-16
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
"publint": "^0.2.12",
4343
"ts-jest": "^29.1.0",
4444
"ts-node": "^10.5.0",
45-
"tsc-multi": "https://github.com/stainless-api/tsc-multi/releases/download/v1.1.4/tsc-multi-1.1.4.tgz",
45+
"tsc-multi": "https://github.com/stainless-api/tsc-multi/releases/download/v1.1.7/tsc-multi.tgz",
4646
"tsconfig-paths": "^4.0.0",
4747
"typescript": "5.8.3"
4848
},

scripts/build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ fi
3131
node scripts/utils/make-dist-package-json.cjs > dist/package.json
3232

3333
# build to .js/.mjs/.d.ts files
34-
npm exec tsc-multi
34+
./node_modules/.bin/tsc-multi
3535
# we need to patch index.js so that `new module.exports()` works for cjs backwards
3636
# compat. No way to get that from index.ts because it would cause compile errors
3737
# when building .mjs

src/client.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,9 @@ export interface ClientOptions {
227227
logger?: Logger | undefined;
228228
}
229229

230+
/**
231+
* Base class for Anthropic API clients.
232+
*/
230233
export class BaseAnthropic {
231234
apiKey: string | null;
232235
authToken: string | null;
@@ -277,7 +280,7 @@ export class BaseAnthropic {
277280
}
278281

279282
this.baseURL = options.baseURL!;
280-
this.timeout = options.timeout ?? Anthropic.DEFAULT_TIMEOUT /* 10 minutes */;
283+
this.timeout = options.timeout ?? BaseAnthropic.DEFAULT_TIMEOUT /* 10 minutes */;
281284
this.logger = options.logger ?? console;
282285
const defaultLogLevel = 'warn';
283286
// Set default logLevel early so that we can log a warning in parseLogLevel.

src/core/resource.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import { BaseAnthropic } from '../client';
44

5-
export class APIResource {
5+
export abstract class APIResource {
66
protected _client: BaseAnthropic;
77

88
constructor(client: BaseAnthropic) {

src/internal/headers.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
22

3+
import { isReadonlyArray } from './utils/values';
4+
35
type HeaderValue = string | undefined | null;
46
export type HeadersLike =
57
| Headers
@@ -9,9 +11,13 @@ export type HeadersLike =
911
| null
1012
| NullableHeaders;
1113

14+
<<<<<<< generated--merge-conflict
15+
const brand_privateNullableHeaders = /* @__PURE__ */ Symbol('brand.privateNullableHeaders');
16+
=======
1217
const brand_privateNullableHeaders = Symbol.for('brand.privateNullableHeaders') as symbol & {
1318
description: 'brand.privateNullableHeaders';
1419
};
20+
>>>>>>> integrated--merge-conflict
1521

1622
/**
1723
* @internal
@@ -27,8 +33,6 @@ export type NullableHeaders = {
2733
nulls: Set<string>;
2834
};
2935

30-
const isArray = Array.isArray as (val: unknown) => val is readonly unknown[];
31-
3236
function* iterateHeaders(headers: HeadersLike): IterableIterator<readonly [string, string | null]> {
3337
if (!headers) return;
3438

@@ -45,7 +49,7 @@ function* iterateHeaders(headers: HeadersLike): IterableIterator<readonly [strin
4549
let iter: Iterable<readonly (HeaderValue | readonly HeaderValue[])[]>;
4650
if (headers instanceof Headers) {
4751
iter = headers.entries();
48-
} else if (isArray(headers)) {
52+
} else if (isReadonlyArray(headers)) {
4953
iter = headers;
5054
} else {
5155
shouldClear = true;
@@ -54,7 +58,7 @@ function* iterateHeaders(headers: HeadersLike): IterableIterator<readonly [strin
5458
for (let row of iter) {
5559
const name = row[0];
5660
if (typeof name !== 'string') throw new TypeError('expected header name to be a string');
57-
const values = isArray(row[1]) ? row[1] : [row[1]];
61+
const values = isReadonlyArray(row[1]) ? row[1] : [row[1]];
5862
let didClear = false;
5963
for (const value of values) {
6064
if (value === undefined) continue;

src/internal/uploads.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export const multipartFormRequestOptions = async (
9090
return { ...opts, body: await createForm(opts.body, fetch) };
9191
};
9292

93-
const supportsFormDataMap = new WeakMap<Fetch, Promise<boolean>>();
93+
const supportsFormDataMap = /** @__PURE__ */ new WeakMap<Fetch, Promise<boolean>>();
9494

9595
/**
9696
* node-fetch doesn't support the global FormData object in recent node versions. Instead of sending

src/internal/utils/log.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ const noopLogger = {
5858
debug: noop,
5959
};
6060

61-
let cachedLoggers = new WeakMap<Logger, [LogLevel, Logger]>();
61+
let cachedLoggers = /** @__PURE__ */ new WeakMap<Logger, [LogLevel, Logger]>();
6262

6363
export function loggerFor(client: BaseAnthropic): Logger {
6464
const logger = client.logger;

src/internal/utils/path.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,4 @@ export const createPathTagFunction = (pathEncoder = encodeURIPath) =>
6262
/**
6363
* URI-encodes path params and ensures no unsafe /./ or /../ path segments are introduced.
6464
*/
65-
export const path = createPathTagFunction(encodeURIPath);
65+
export const path = /* @__PURE__ */ createPathTagFunction(encodeURIPath);

src/internal/utils/values.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ export const isAbsoluteURL = (url: string): boolean => {
99
return startsWithSchemeRegexp.test(url);
1010
};
1111

12+
export let isArray = (val: unknown): val is unknown[] => ((isArray = Array.isArray), isArray(val));
13+
export let isReadonlyArray = isArray as (val: unknown) => val is readonly unknown[];
14+
1215
/** Returns an object if the given value isn't an object, otherwise returns as-is */
1316
export function maybeObj(x: unknown): object {
1417
if (typeof x !== 'object') {

tsc-multi.json

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
{
22
"targets": [
3-
{ "extname": ".js", "module": "commonjs", "shareHelpers": "internal/tslib.js" },
4-
{ "extname": ".mjs", "module": "esnext", "shareHelpers": "internal/tslib.mjs" }
3+
{
4+
"extname": ".js",
5+
"module": "commonjs",
6+
"shareHelpers": "internal/tslib.js"
7+
},
8+
{
9+
"extname": ".mjs",
10+
"module": "esnext",
11+
"shareHelpers": "internal/tslib.mjs"
12+
}
513
],
614
"projects": ["tsconfig.build.json"]
715
}

0 commit comments

Comments
 (0)