From c1237feaea9ca2d244720f2f75e023450a78019f Mon Sep 17 00:00:00 2001 From: Stainless Bot <107565488+stainless-bot@users.noreply.github.com> Date: Wed, 20 Sep 2023 18:05:10 -0400 Subject: [PATCH] feat(client): support importing node or web shims manually (#157) --- .prettierignore | 3 + README.md | 4 + build | 15 +- jest.config.js | 2 +- package.json | 94 ++--- release-please-config.json | 8 +- scripts/postprocess-files.cjs | 160 +++++++++ scripts/remove-triple-slash-references.js | 11 - scripts/replace-self-referencing-imports.js | 24 -- scripts/replace-shim-guards.js | 14 - scripts/resolve-full-paths.js | 16 - src/_shims/MultipartBody.ts | 9 + src/_shims/README.md | 46 +++ src/_shims/ReadableStream.d.ts | 38 --- src/_shims/ReadableStream.mjs | 7 - src/_shims/agent-node.ts | 22 -- src/_shims/agent.ts | 12 - .../runtime-bun.ts} | 3 +- .../runtime-deno.ts} | 4 +- src/_shims/auto/runtime-node.ts | 4 + src/_shims/auto/runtime.ts | 4 + src/_shims/auto/types-deno.ts | 4 + src/_shims/auto/types-node.ts | 4 + src/_shims/auto/types.d.ts | 99 ++++++ src/_shims/auto/types.js | 3 + src/_shims/auto/types.mjs | 3 + src/_shims/bun-runtime.ts | 14 + src/_shims/fetch-deno.ts | 27 -- src/_shims/fetch-node.d.ts | 64 ---- src/_shims/fetch-node.js | 12 - src/_shims/fetch-node.mjs | 14 - src/_shims/fetch.d.ts | 60 ---- src/_shims/fetch.js | 13 - src/_shims/fetch.mjs | 15 - src/_shims/fileFromPath-node.ts | 29 -- src/_shims/fileFromPath.ts | 29 -- src/_shims/form-data-deno.ts | 19 -- src/_shims/form-data-node.d.ts | 45 --- src/_shims/form-data-node.js | 11 - src/_shims/form-data-node.mjs | 9 - src/_shims/form-data.d.ts | 43 --- src/_shims/form-data.js | 17 - src/_shims/form-data.mjs | 20 -- src/_shims/getMultipartRequestOptions-node.ts | 25 -- src/_shims/getMultipartRequestOptions.ts | 14 - src/_shims/index-deno.ts | 110 ++++++ src/_shims/index.d.ts | 79 +++++ src/_shims/index.js | 13 + src/_shims/index.mjs | 7 + src/_shims/manual-types.d.ts | 12 + src/_shims/manual-types.js | 3 + src/_shims/manual-types.mjs | 3 + src/_shims/node-readable-node.ts | 10 - src/_shims/node-readable.ts | 30 -- src/_shims/node-runtime.ts | 79 +++++ src/_shims/node-types.d.ts | 42 +++ src/_shims/node-types.js | 3 + src/_shims/node-types.mjs | 3 + src/_shims/registry.ts | 64 ++++ src/_shims/web-runtime.ts | 91 +++++ src/_shims/web-types.d.ts | 82 +++++ src/_shims/web-types.js | 3 + src/_shims/web-types.mjs | 3 + src/core.ts | 41 ++- src/index.ts | 2 +- src/shims/node.ts | 50 +++ src/shims/web.ts | 50 +++ src/streaming.ts | 2 +- src/uploads.ts | 26 +- tests/form.test.ts | 2 +- tests/index.test.ts | 7 +- tests/responses.test.ts | 2 +- tests/uploads.test.ts | 2 +- tsconfig.build.json | 20 +- tsconfig.deno.json | 4 +- tsconfig.json | 6 +- yarn.lock | 322 +++++++----------- 77 files changed, 1275 insertions(+), 991 deletions(-) create mode 100644 scripts/postprocess-files.cjs delete mode 100644 scripts/remove-triple-slash-references.js delete mode 100644 scripts/replace-self-referencing-imports.js delete mode 100644 scripts/replace-shim-guards.js delete mode 100644 scripts/resolve-full-paths.js create mode 100644 src/_shims/MultipartBody.ts create mode 100644 src/_shims/README.md delete mode 100644 src/_shims/ReadableStream.d.ts delete mode 100644 src/_shims/ReadableStream.mjs delete mode 100644 src/_shims/agent-node.ts delete mode 100644 src/_shims/agent.ts rename src/_shims/{ReadableStream.js => auto/runtime-bun.ts} (67%) rename src/_shims/{ReadableStream-node.ts => auto/runtime-deno.ts} (50%) create mode 100644 src/_shims/auto/runtime-node.ts create mode 100644 src/_shims/auto/runtime.ts create mode 100644 src/_shims/auto/types-deno.ts create mode 100644 src/_shims/auto/types-node.ts create mode 100644 src/_shims/auto/types.d.ts create mode 100644 src/_shims/auto/types.js create mode 100644 src/_shims/auto/types.mjs create mode 100644 src/_shims/bun-runtime.ts delete mode 100644 src/_shims/fetch-deno.ts delete mode 100644 src/_shims/fetch-node.d.ts delete mode 100644 src/_shims/fetch-node.js delete mode 100644 src/_shims/fetch-node.mjs delete mode 100644 src/_shims/fetch.d.ts delete mode 100644 src/_shims/fetch.js delete mode 100644 src/_shims/fetch.mjs delete mode 100644 src/_shims/fileFromPath-node.ts delete mode 100644 src/_shims/fileFromPath.ts delete mode 100644 src/_shims/form-data-deno.ts delete mode 100644 src/_shims/form-data-node.d.ts delete mode 100644 src/_shims/form-data-node.js delete mode 100644 src/_shims/form-data-node.mjs delete mode 100644 src/_shims/form-data.d.ts delete mode 100644 src/_shims/form-data.js delete mode 100644 src/_shims/form-data.mjs delete mode 100644 src/_shims/getMultipartRequestOptions-node.ts delete mode 100644 src/_shims/getMultipartRequestOptions.ts create mode 100644 src/_shims/index-deno.ts create mode 100644 src/_shims/index.d.ts create mode 100644 src/_shims/index.js create mode 100644 src/_shims/index.mjs create mode 100644 src/_shims/manual-types.d.ts create mode 100644 src/_shims/manual-types.js create mode 100644 src/_shims/manual-types.mjs delete mode 100644 src/_shims/node-readable-node.ts delete mode 100644 src/_shims/node-readable.ts create mode 100644 src/_shims/node-runtime.ts create mode 100644 src/_shims/node-types.d.ts create mode 100644 src/_shims/node-types.js create mode 100644 src/_shims/node-types.mjs create mode 100644 src/_shims/registry.ts create mode 100644 src/_shims/web-runtime.ts create mode 100644 src/_shims/web-types.d.ts create mode 100644 src/_shims/web-types.js create mode 100644 src/_shims/web-types.mjs create mode 100644 src/shims/node.ts create mode 100644 src/shims/web.ts diff --git a/.prettierignore b/.prettierignore index 804a75c..fc6160f 100644 --- a/.prettierignore +++ b/.prettierignore @@ -2,3 +2,6 @@ CHANGELOG.md /ecosystem-tests /node_modules /deno + +# don't format tsc output, will break source maps +/dist diff --git a/README.md b/README.md index afa8776..fff3970 100644 --- a/README.md +++ b/README.md @@ -341,5 +341,9 @@ The following runtimes are supported: - Bun 1.0 or later. - Cloudflare Workers. - Vercel Edge Runtime. +- Jest 28 or greater with the `"node"` environment (`"jsdom"` is not supported at this time). +- Nitro v2.6 or greater. + +Note that React Native is not supported at this time. If you are interested in other runtime environments, please open or upvote an issue on GitHub. diff --git a/build b/build index acfd049..c967f41 100755 --- a/build +++ b/build @@ -12,7 +12,7 @@ rm -rf dist; mkdir dist # Copy src to dist/src and build from dist/src into dist, so that # the source map for index.js.map will refer to ./src/index.ts etc cp -rp src README.md dist -rm dist/src/_shims/*-deno.* +rm dist/src/_shims/*-deno.ts dist/src/_shims/auto/*-deno.ts for file in LICENSE CHANGELOG.md; do if [ -e "${file}" ]; then cp "${file}" dist; fi done @@ -27,8 +27,8 @@ node scripts/make-dist-package-json.cjs > dist/package.json # build to .js/.mjs/.d.ts files npm exec tsc-multi # copy over handwritten .js/.mjs/.d.ts files -cp src/_shims/*.{d.ts,js,mjs} dist/_shims -npm exec tsc-alias -- -p tsconfig.build.json +cp src/_shims/*.{d.ts,js,mjs,md} dist/_shims +cp src/_shims/auto/*.{d.ts,js,mjs} dist/_shims/auto # we need to add exports = module.exports = Anthropic TypeScript to index.js; # No way to get that from index.ts because it would cause compile errors # when building .mjs @@ -40,14 +40,7 @@ node scripts/fix-index-exports.cjs cp dist/index.d.ts dist/index.d.mts cp tsconfig.dist-src.json dist/src/tsconfig.json -# strip out lib="dom" and types="node" references; these are needed at build time, -# but would pollute the user's TS environment -find dist -type f -exec node scripts/remove-triple-slash-references.js {} + -# strip out `unknown extends RequestInit ? never :` from dist/src/_shims; -# these cause problems when viewing the .ts source files in go to definition -find dist/src/_shims -type f -exec node scripts/replace-shim-guards.js {} + - -npm exec prettier -- --loglevel=warn --write . +node scripts/postprocess-files.cjs # make sure that nothing crashes when we require the output CJS or # import the output ESM diff --git a/jest.config.js b/jest.config.js index b16b5b4..bd07f0a 100644 --- a/jest.config.js +++ b/jest.config.js @@ -4,7 +4,7 @@ module.exports = { testEnvironment: 'node', moduleNameMapper: { '^@anthropic-ai/sdk$': '/src/index.ts', - '^@anthropic-ai/sdk/_shims/(.*)$': '/src/_shims/$1-node', + '^@anthropic-ai/sdk/_shims/auto/(.*)$': '/src/_shims/auto/$1-node', '^@anthropic-ai/sdk/(.*)$': '/src/$1', }, modulePathIgnorePatterns: ['/ecosystem-tests/', '/dist/', '/deno_tests/'], diff --git a/package.json b/package.json index 38fa08e..6b3561d 100644 --- a/package.json +++ b/package.json @@ -9,76 +9,49 @@ "repository": "github:anthropics/anthropic-sdk-typescript", "license": "MIT", "private": false, + "sideEffects": [ + "./_shims/index.js", + "./_shims/index.mjs", + "./shims/node.js", + "./shims/node.mjs", + "./shims/web.js", + "./shims/web.mjs" + ], "exports": { - "./_shims/node-readable": { + "./_shims/auto/*": { "deno": { - "types": "./dist/_shims/node-readable.d.ts", - "require": "./dist/_shims/node-readable.js", - "default": "./dist/_shims/node-readable.mjs" + "types": "./dist/_shims/auto/*.d.ts", + "require": "./dist/_shims/auto/*.js", + "default": "./dist/_shims/auto/*.mjs" }, "bun": { - "types": "./dist/_shims/node-readable-node.d.ts", - "require": "./dist/_shims/node-readable-node.js", - "default": "./dist/_shims/node-readable-node.mjs" + "types": "./dist/_shims/auto/*.d.ts", + "require": "./dist/_shims/auto/*-bun.js", + "default": "./dist/_shims/auto/*-bun.mjs" }, "browser": { - "types": "./dist/_shims/node-readable.d.ts", - "require": "./dist/_shims/node-readable.js", - "default": "./dist/_shims/node-readable.mjs" + "types": "./dist/_shims/auto/*.d.ts", + "require": "./dist/_shims/auto/*.js", + "default": "./dist/_shims/auto/*.mjs" }, "worker": { - "types": "./dist/_shims/node-readable.d.ts", - "require": "./dist/_shims/node-readable.js", - "default": "./dist/_shims/node-readable.mjs" + "types": "./dist/_shims/auto/*.d.ts", + "require": "./dist/_shims/auto/*.js", + "default": "./dist/_shims/auto/*.mjs" }, "workerd": { - "types": "./dist/_shims/node-readable.d.ts", - "require": "./dist/_shims/node-readable.js", - "default": "./dist/_shims/node-readable.mjs" + "types": "./dist/_shims/auto/*.d.ts", + "require": "./dist/_shims/auto/*.js", + "default": "./dist/_shims/auto/*.mjs" }, "node": { - "types": "./dist/_shims/node-readable-node.d.ts", - "require": "./dist/_shims/node-readable-node.js", - "default": "./dist/_shims/node-readable-node.mjs" + "types": "./dist/_shims/auto/*-node.d.ts", + "require": "./dist/_shims/auto/*-node.js", + "default": "./dist/_shims/auto/*-node.mjs" }, - "types": "./dist/_shims/node-readable.d.ts", - "require": "./dist/_shims/node-readable.js", - "default": "./dist/_shims/node-readable.mjs" - }, - "./_shims/*": { - "deno": { - "types": "./dist/_shims/*.d.ts", - "require": "./dist/_shims/*.js", - "default": "./dist/_shims/*.mjs" - }, - "bun": { - "types": "./dist/_shims/*.d.ts", - "require": "./dist/_shims/*.js", - "default": "./dist/_shims/*.mjs" - }, - "browser": { - "types": "./dist/_shims/*.d.ts", - "require": "./dist/_shims/*.js", - "default": "./dist/_shims/*.mjs" - }, - "worker": { - "types": "./dist/_shims/*.d.ts", - "require": "./dist/_shims/*.js", - "default": "./dist/_shims/*.mjs" - }, - "workerd": { - "types": "./dist/_shims/*.d.ts", - "require": "./dist/_shims/*.js", - "default": "./dist/_shims/*.mjs" - }, - "node": { - "types": "./dist/_shims/*-node.d.ts", - "require": "./dist/_shims/*-node.js", - "default": "./dist/_shims/*-node.mjs" - }, - "types": "./dist/_shims/*.d.ts", - "require": "./dist/_shims/*.js", - "default": "./dist/_shims/*.mjs" + "types": "./dist/_shims/auto/*.d.ts", + "require": "./dist/_shims/auto/*.js", + "default": "./dist/_shims/auto/*.mjs" }, ".": { "require": { @@ -123,10 +96,10 @@ }, "devDependencies": { "@types/jest": "^29.4.0", - "@typescript-eslint/eslint-plugin": "^5.33.0", - "@typescript-eslint/parser": "^5.33.0", + "@typescript-eslint/eslint-plugin": "^6.7.0", + "@typescript-eslint/parser": "^6.7.0", "@anthropic-ai/sdk": "link:.", - "eslint": "^8.22.0", + "eslint": "^8.49.0", "eslint-plugin-prettier": "^4.0.0", "eslint-plugin-unused-imports": "^2.0.0", "jest": "^29.4.0", @@ -134,7 +107,6 @@ "ts-jest": "^29.1.0", "ts-morph": "^19.0.0", "ts-node": "^10.5.0", - "tsc-alias": "^1.8.6", "tsc-multi": "^1.1.0", "tsconfig-paths": "^4.0.0", "typescript": "^4.8.2" diff --git a/release-please-config.json b/release-please-config.json index a842d38..8ed0849 100644 --- a/release-please-config.json +++ b/release-please-config.json @@ -57,7 +57,11 @@ "hidden": true } ], - "reviewers": ["RobertCraigie"], + "reviewers": [ + "RobertCraigie" + ], "release-type": "node", - "extra-files": ["src/version.ts"] + "extra-files": [ + "src/version.ts" + ] } diff --git a/scripts/postprocess-files.cjs b/scripts/postprocess-files.cjs new file mode 100644 index 0000000..8eb455d --- /dev/null +++ b/scripts/postprocess-files.cjs @@ -0,0 +1,160 @@ +const fs = require('fs'); +const path = require('path'); +const { parse } = require('@typescript-eslint/parser'); + +const distDir = path.resolve(__dirname, '..', 'dist'); +const distSrcDir = path.join(distDir, 'src'); + +/** + * Quick and dirty AST traversal + */ +function traverse(node, visitor) { + if (!node || typeof node.type !== 'string') return; + visitor.node?.(node); + visitor[node.type]?.(node); + for (const key in node) { + const value = node[key]; + if (Array.isArray(value)) { + for (const elem of value) traverse(elem, visitor); + } else if (value instanceof Object) { + traverse(value, visitor); + } + } +} + +/** + * Helper method for replacing arbitrary ranges of text in input code. + * + * The `replacer` is a function that will be called with a mini-api. For example: + * + * replaceRanges('foobar', ({ replace }) => replace([0, 3], 'baz')) // 'bazbar' + * + * The replaced ranges must not be overlapping. + */ +function replaceRanges(code, replacer) { + const replacements = []; + replacer({ replace: (range, replacement) => replacements.push({ range, replacement }) }); + + if (!replacements.length) return code; + replacements.sort((a, b) => a.range[0] - b.range[0]); + const overlapIndex = replacements.findIndex( + (r, index) => index > 0 && replacements[index - 1].range[1] > r.range[0], + ); + if (overlapIndex >= 0) { + throw new Error( + `replacements overlap: ${JSON.stringify(replacements[overlapIndex - 1])} and ${JSON.stringify( + replacements[overlapIndex], + )}`, + ); + } + + const parts = []; + let end = 0; + for (const { + range: [from, to], + replacement, + } of replacements) { + if (from > end) parts.push(code.substring(end, from)); + parts.push(replacement); + end = to; + } + if (end < code.length) parts.push(code.substring(end)); + return parts.join(''); +} + +/** + * Like calling .map(), where the iteratee is called on the path in every import or export from statement. + * @returns the transformed code + */ +function mapModulePaths(code, iteratee) { + const ast = parse(code, { range: true }); + return replaceRanges(code, ({ replace }) => + traverse(ast, { + node(node) { + switch (node.type) { + case 'ImportDeclaration': + case 'ExportNamedDeclaration': + case 'ExportAllDeclaration': + case 'ImportExpression': + if (node.source) { + const { range, value } = node.source; + const transformed = iteratee(value); + if (transformed !== value) { + replace(range, JSON.stringify(transformed)); + } + } + } + }, + }), + ); +} + +async function* walk(dir) { + for await (const d of await fs.promises.opendir(dir)) { + const entry = path.join(dir, d.name); + if (d.isDirectory()) yield* walk(entry); + else if (d.isFile()) yield entry; + } +} + +async function postprocess() { + for await (const file of walk(path.resolve(__dirname, '..', 'dist'))) { + if (!/\.([cm]?js|(\.d)?[cm]?ts)$/.test(file)) continue; + + const code = await fs.promises.readFile(file, 'utf8'); + + let transformed = mapModulePaths(code, (importPath) => { + if (file.startsWith(distSrcDir)) { + if (importPath.startsWith('@anthropic-ai/sdk/')) { + // convert self-references in dist/src to relative paths + let relativePath = path.relative( + path.dirname(file), + path.join(distSrcDir, importPath.substring('openai/'.length)), + ); + if (!relativePath.startsWith('.')) relativePath = `./${relativePath}`; + return relativePath; + } + return importPath; + } + if (importPath.startsWith('.')) { + // add explicit file extensions to relative imports + const { dir, name } = path.parse(importPath); + const ext = /\.mjs$/.test(file) ? '.mjs' : '.js'; + return `${dir}/${name}${ext}`; + } + return importPath; + }); + + if (file.startsWith(distSrcDir) && !file.endsWith('_shims/index.d.ts')) { + // strip out `unknown extends Foo ? never :` shim guards in dist/src + // to prevent errors from appearing in Go To Source + transformed = transformed.replace( + new RegExp('unknown extends (typeof )?\\S+ \\? \\S+ :\\s*'.replace(/\s+/, '\\s+'), 'gm'), + // replace with same number of characters to avoid breaking source maps + (match) => ' '.repeat(match.length), + ); + } + + if (file.endsWith('.d.ts')) { + // work around bad tsc behavior + // if we have `import { type Readable } from '@anthropic-ai/sdk/_shims/index'`, + // tsc sometimes replaces `Readable` with `import("stream").Readable` inline + // in the output .d.ts + transformed = transformed.replace(/import\("stream"\).Readable/g, 'Readable'); + } + + // strip out lib="dom" and types="node" references; these are needed at build time, + // but would pollute the user's TS environment + transformed = transformed.replace( + /^ *\/\/\/ * ' '.repeat(match.length - 1) + '\n', + ); + + if (transformed !== code) { + await fs.promises.writeFile(file, transformed, 'utf8'); + console.error(`wrote ${path.relative(process.cwd(), file)}`); + } + } +} +postprocess(); diff --git a/scripts/remove-triple-slash-references.js b/scripts/remove-triple-slash-references.js deleted file mode 100644 index d47d45b..0000000 --- a/scripts/remove-triple-slash-references.js +++ /dev/null @@ -1,11 +0,0 @@ -// strip out lib="dom" and types="node" references; these are needed at build time, -// but would pollute the user's TS environment -const fs = require('fs'); -for (const file of process.argv.slice(2)) { - const before = fs.readFileSync(file, 'utf8'); - const after = before.replace(/^ *\/\/\/ * { - if (!importPath.startsWith('@anthropic-ai/sdk/')) return match; - if (!file.startsWith(distSrcDir)) return match; - let relativePath = path.relative( - path.dirname(file), - path.join(distSrcDir, importPath.substring('@anthropic-ai/sdk/'.length)), - ); - if (!relativePath.startsWith('.')) relativePath = `./${relativePath}`; - return JSON.stringify(relativePath); - }); -} -exports.default = replaceSelfReferencingImports; diff --git a/scripts/replace-shim-guards.js b/scripts/replace-shim-guards.js deleted file mode 100644 index 17bd9fb..0000000 --- a/scripts/replace-shim-guards.js +++ /dev/null @@ -1,14 +0,0 @@ -// strip out `unknown extends RequestInit ? never :` from dist/src/_shims; -// these cause problems when viewing the .ts source files in go to definition -const fs = require('fs'); -for (const file of process.argv.slice(2)) { - const before = fs.readFileSync(file, 'utf8'); - const after = before.replace( - new RegExp('unknown extends (typeof )?\\S+ \\? \\S+ :\\s*'.replace(/\s+/, '\\s+'), 'gm'), - '', - ); - if (after !== before) { - fs.writeFileSync(file, after, 'utf8'); - console.error('wrote', file); - } -} diff --git a/scripts/resolve-full-paths.js b/scripts/resolve-full-paths.js deleted file mode 100644 index f8f979a..0000000 --- a/scripts/resolve-full-paths.js +++ /dev/null @@ -1,16 +0,0 @@ -'use strict'; -Object.defineProperty(exports, '__esModule', { value: true }); - -const path = require('path'); - -// tsc-alias --resolveFullPaths is buggy, it replaces 'formdata-node' -// with 'formdata-node.js' because we have a file with that name -function resolveFullPaths({ orig, file, config }) { - return orig.replace(/['"]([^"'\r\n]+)['"]/, (match, importPath) => { - if (!importPath.startsWith('.')) return match; - const { dir, name } = path.parse(importPath); - const ext = /\.mjs$/.test(file) ? '.mjs' : '.js'; - return JSON.stringify(`${dir}/${name}${ext}`); - }); -} -exports.default = resolveFullPaths; diff --git a/src/_shims/MultipartBody.ts b/src/_shims/MultipartBody.ts new file mode 100644 index 0000000..af3b111 --- /dev/null +++ b/src/_shims/MultipartBody.ts @@ -0,0 +1,9 @@ +/** + * Disclaimer: modules in _shims aren't intended to be imported by SDK users. + */ +export class MultipartBody { + constructor(public body: any) {} + get [Symbol.toStringTag](): string { + return 'MultipartBody'; + } +} diff --git a/src/_shims/README.md b/src/_shims/README.md new file mode 100644 index 0000000..28efc3b --- /dev/null +++ b/src/_shims/README.md @@ -0,0 +1,46 @@ +# 👋 Wondering what everything in here does? + +`@anthropic-ai/sdk` supports a wide variety of runtime environments like Node.js, Deno, Bun, browsers, and various +edge runtimes, as well as both CommonJS (CJS) and EcmaScript Modules (ESM). + +To do this, `@anthropic-ai/sdk` provides shims for either using `node-fetch` when in Node (because `fetch` is still experimental there) or the global `fetch` API built into the environment when not in Node. + +It uses [conditional exports](https://nodejs.org/api/packages.html#conditional-exports) to +automatically select the correct shims for each environment. However, conditional exports are a fairly new +feature and not supported everywhere. For instance, the TypeScript `"moduleResolution": "node"` + +setting doesn't consult the `exports` map, compared to `"moduleResolution": "nodeNext"`, which does. +Unfortunately that's still the default setting, and it can result in errors like +getting the wrong raw `Response` type from `.asResponse()`, for example. + +The user can work around these issues by manually importing one of: + +- `import '@anthropic-ai/sdk/shims/node'` +- `import '@anthropic-ai/sdk/shims/web'` + +All of the code here in `_shims` handles selecting the automatic default shims or manual overrides. + +### How it works - Runtime + +Runtime shims get installed by calling `setShims` exported by `@anthropic-ai/sdk/_shims/registry`. + +Manually importing `@anthropic-ai/sdk/shims/node` or `@anthropic-ai/sdk/shims/web`, calls `setShims` with the respective runtime shims. + +All client code imports shims from `@anthropic-ai/sdk/_shims/index`, which: + +- checks if shims have been set manually +- if not, calls `setShims` with the shims from `@anthropic-ai/sdk/_shims/auto/runtime` +- re-exports the installed shims from `@anthropic-ai/sdk/_shims/registry`. + +`@anthropic-ai/sdk/_shims/auto/runtime` exports web runtime shims. +If the `node` export condition is set, the export map replaces it with `@anthropic-ai/sdk/_shims/auto/runtime-node`. + +### How it works - Type time + +All client code imports shim types from `@anthropic-ai/sdk/_shims/index`, which selects the manual types from `@anthropic-ai/sdk/_shims/manual-types` if they have been declared, otherwise it exports the auto types from `@anthropic-ai/sdk/_shims/auto/types`. + +`@anthropic-ai/sdk/_shims/manual-types` exports an empty namespace. +Manually importing `@anthropic-ai/sdk/shims/node` or `@anthropic-ai/sdk/shims/web` merges declarations into this empty namespace, so they get picked up by `@anthropic-ai/sdk/_shims/index`. + +`@anthropic-ai/sdk/_shims/auto/types` exports web type definitions. +If the `node` export condition is set, the export map replaces it with `@anthropic-ai/sdk/_shims/auto/types-node`, though TS only picks this up if `"moduleResolution": "nodenext"` or `"moduleResolution": "bundler"`. diff --git a/src/_shims/ReadableStream.d.ts b/src/_shims/ReadableStream.d.ts deleted file mode 100644 index b21d01c..0000000 --- a/src/_shims/ReadableStream.d.ts +++ /dev/null @@ -1,38 +0,0 @@ -/** - * Disclaimer: modules in _shims aren't intended to be imported by SDK users. - */ - -/** - * >>> Confused? <<< - * - * If you're getting errors from these types, try adding "lib": ["DOM"] - * to your tsconfig.json, or otherwise configure the appropriate builtin - * `ReadableStream` type for your environment. - */ - -// @ts-ignore -type _ReadableStream = unknown extends ReadableStream ? never : ReadableStream; -declare const _ReadableStream: { - prototype: _ReadableStream; - new ( - underlyingSource: _UnderlyingByteSource, - strategy?: { highWaterMark?: number }, - ): _ReadableStream; - new ( - underlyingSource: _UnderlyingDefaultSource, - strategy?: _QueuingStrategy, - ): _ReadableStream; - new (underlyingSource?: _UnderlyingSource, strategy?: _QueuingStrategy): _ReadableStream; -}; - -// @ts-ignore -type _UnderlyingSource = unknown extends UnderlyingSource ? never : UnderlyingSource; -// @ts-ignore -type _UnderlyingByteSource = unknown extends UnderlyingByteSource ? never : UnderlyingByteSource; -type _UnderlyingDefaultSource = - // @ts-ignore - unknown extends UnderlyingDefaultSource ? never : UnderlyingDefaultSource; -// @ts-ignore -type _QueuingStrategy = unknown extends QueuingStrategy ? never : QueuingStrategy; - -export { _ReadableStream as ReadableStream }; diff --git a/src/_shims/ReadableStream.mjs b/src/_shims/ReadableStream.mjs deleted file mode 100644 index a484d65..0000000 --- a/src/_shims/ReadableStream.mjs +++ /dev/null @@ -1,7 +0,0 @@ -/** - * Disclaimer: modules in _shims aren't intended to be imported by SDK users. - */ - -const _ReadableStream = ReadableStream; - -export { _ReadableStream as ReadableStream }; diff --git a/src/_shims/agent-node.ts b/src/_shims/agent-node.ts deleted file mode 100644 index 31f4d7c..0000000 --- a/src/_shims/agent-node.ts +++ /dev/null @@ -1,22 +0,0 @@ -/** - * Disclaimer: modules in _shims aren't intended to be imported by SDK users. - */ - -import KeepAliveAgent from 'agentkeepalive'; -import type { Agent } from 'node:http'; -import { AbortController as AbortControllerPolyfill } from 'abort-controller'; - -export type { Agent }; - -const defaultHttpAgent: Agent = new KeepAliveAgent({ keepAlive: true, timeout: 5 * 60 * 1000 }); -const defaultHttpsAgent: Agent = new KeepAliveAgent.HttpsAgent({ keepAlive: true, timeout: 5 * 60 * 1000 }); - -// Polyfill global object if needed. -if (typeof AbortController === 'undefined') { - AbortController = AbortControllerPolyfill as any as typeof AbortController; -} - -export const getDefaultAgent = (url: string): Agent | undefined => { - if (defaultHttpsAgent && url.startsWith('https')) return defaultHttpsAgent; - return defaultHttpAgent; -}; diff --git a/src/_shims/agent.ts b/src/_shims/agent.ts deleted file mode 100644 index 24e5bf7..0000000 --- a/src/_shims/agent.ts +++ /dev/null @@ -1,12 +0,0 @@ -/** - * Disclaimer: modules in _shims aren't intended to be imported by SDK users. - * - * This is a stub for non-node environments. - * In node environments, it gets replaced agent-node.ts by the package export map - */ - -export type Agent = any; - -export const getDefaultAgent = (url: string): any => { - return undefined; -}; diff --git a/src/_shims/ReadableStream.js b/src/_shims/auto/runtime-bun.ts similarity index 67% rename from src/_shims/ReadableStream.js rename to src/_shims/auto/runtime-bun.ts index 7c0dff1..e053254 100644 --- a/src/_shims/ReadableStream.js +++ b/src/_shims/auto/runtime-bun.ts @@ -1,5 +1,4 @@ /** * Disclaimer: modules in _shims aren't intended to be imported by SDK users. */ - -exports.ReadableStream = ReadableStream; +export * from '../bun-runtime'; diff --git a/src/_shims/ReadableStream-node.ts b/src/_shims/auto/runtime-deno.ts similarity index 50% rename from src/_shims/ReadableStream-node.ts rename to src/_shims/auto/runtime-deno.ts index adc5258..62b7a39 100644 --- a/src/_shims/ReadableStream-node.ts +++ b/src/_shims/auto/runtime-deno.ts @@ -1,6 +1,4 @@ /** * Disclaimer: modules in _shims aren't intended to be imported by SDK users. */ -import { ReadableStream } from 'web-streams-polyfill'; - -export { ReadableStream }; +export * from '../web-runtime'; diff --git a/src/_shims/auto/runtime-node.ts b/src/_shims/auto/runtime-node.ts new file mode 100644 index 0000000..0ae2216 --- /dev/null +++ b/src/_shims/auto/runtime-node.ts @@ -0,0 +1,4 @@ +/** + * Disclaimer: modules in _shims aren't intended to be imported by SDK users. + */ +export * from '../node-runtime'; diff --git a/src/_shims/auto/runtime.ts b/src/_shims/auto/runtime.ts new file mode 100644 index 0000000..62b7a39 --- /dev/null +++ b/src/_shims/auto/runtime.ts @@ -0,0 +1,4 @@ +/** + * Disclaimer: modules in _shims aren't intended to be imported by SDK users. + */ +export * from '../web-runtime'; diff --git a/src/_shims/auto/types-deno.ts b/src/_shims/auto/types-deno.ts new file mode 100644 index 0000000..226fb15 --- /dev/null +++ b/src/_shims/auto/types-deno.ts @@ -0,0 +1,4 @@ +/** + * Disclaimer: modules in _shims aren't intended to be imported by SDK users. + */ +export * from '../web-types'; diff --git a/src/_shims/auto/types-node.ts b/src/_shims/auto/types-node.ts new file mode 100644 index 0000000..2625a8b --- /dev/null +++ b/src/_shims/auto/types-node.ts @@ -0,0 +1,4 @@ +/** + * Disclaimer: modules in _shims aren't intended to be imported by SDK users. + */ +export * from '../node-types'; diff --git a/src/_shims/auto/types.d.ts b/src/_shims/auto/types.d.ts new file mode 100644 index 0000000..9c1cc25 --- /dev/null +++ b/src/_shims/auto/types.d.ts @@ -0,0 +1,99 @@ +/** + * Disclaimer: modules in _shims aren't intended to be imported by SDK users. + */ +export type Agent = any; + +// @ts-ignore +declare const _fetch: unknown extends typeof fetch ? never : typeof fetch; +export { _fetch as fetch }; + +// @ts-ignore +type _Request = unknown extends Request ? never : Request; +export { _Request as Request }; + +// @ts-ignore +type _RequestInfo = unknown extends RequestInfo ? never : RequestInfo; +export { type _RequestInfo as RequestInfo }; + +// @ts-ignore +type _RequestInit = unknown extends RequestInit ? never : RequestInit; +export { type _RequestInit as RequestInit }; + +// @ts-ignore +type _Response = unknown extends Response ? never : Response; +export { _Response as Response }; + +// @ts-ignore +type _ResponseInit = unknown extends ResponseInit ? never : ResponseInit; +export { type _ResponseInit as ResponseInit }; + +// @ts-ignore +type _ResponseType = unknown extends ResponseType ? never : ResponseType; +export { type _ResponseType as ResponseType }; + +// @ts-ignore +type _BodyInit = unknown extends BodyInit ? never : BodyInit; +export { type _BodyInit as BodyInit }; + +// @ts-ignore +type _Headers = unknown extends Headers ? never : Headers; +export { _Headers as Headers }; + +// @ts-ignore +type _HeadersInit = unknown extends HeadersInit ? never : HeadersInit; +export { type _HeadersInit as HeadersInit }; + +type EndingType = 'native' | 'transparent'; + +export interface BlobPropertyBag { + endings?: EndingType; + type?: string; +} + +export interface FilePropertyBag extends BlobPropertyBag { + lastModified?: number; +} + +export type FileFromPathOptions = Omit; + +// @ts-ignore +type _FormData = unknown extends FormData ? never : FormData; +// @ts-ignore +declare const _FormData: unknown extends typeof FormData ? never : typeof FormData; +export { _FormData as FormData }; + +// @ts-ignore +type _File = unknown extends File ? never : File; +// @ts-ignore +declare const _File: unknown extends typeof File ? never : typeof File; +export { _File as File }; + +// @ts-ignore +type _Blob = unknown extends Blob ? never : Blob; +// @ts-ignore +declare const _Blob: unknown extends typeof Blob ? never : typeof Blob; +export { _Blob as Blob }; + +export declare class Readable { + readable: boolean; + readonly readableEnded: boolean; + readonly readableFlowing: boolean | null; + readonly readableHighWaterMark: number; + readonly readableLength: number; + readonly readableObjectMode: boolean; + destroyed: boolean; + read(size?: number): any; + pause(): this; + resume(): this; + isPaused(): boolean; + destroy(error?: Error): this; + [Symbol.asyncIterator](): AsyncIterableIterator; +} + +export declare class FsReadStream extends Readable { + path: {}; // node type is string | Buffer +} + +// @ts-ignore +type _ReadableStream = unknown extends ReadableStream ? never : ReadableStream; +export { type _ReadableStream as ReadableStream }; diff --git a/src/_shims/auto/types.js b/src/_shims/auto/types.js new file mode 100644 index 0000000..ddbdb79 --- /dev/null +++ b/src/_shims/auto/types.js @@ -0,0 +1,3 @@ +/** + * Disclaimer: modules in _shims aren't intended to be imported by SDK users. + */ diff --git a/src/_shims/auto/types.mjs b/src/_shims/auto/types.mjs new file mode 100644 index 0000000..ddbdb79 --- /dev/null +++ b/src/_shims/auto/types.mjs @@ -0,0 +1,3 @@ +/** + * Disclaimer: modules in _shims aren't intended to be imported by SDK users. + */ diff --git a/src/_shims/bun-runtime.ts b/src/_shims/bun-runtime.ts new file mode 100644 index 0000000..8d5aaab --- /dev/null +++ b/src/_shims/bun-runtime.ts @@ -0,0 +1,14 @@ +/** + * Disclaimer: modules in _shims aren't intended to be imported by SDK users. + */ +import { type Shims } from './registry'; +import { getRuntime as getWebRuntime } from './web-runtime'; +import { ReadStream as FsReadStream } from 'node:fs'; + +export function getRuntime(): Shims { + const runtime = getWebRuntime(); + function isFsReadStream(value: any): value is FsReadStream { + return value instanceof FsReadStream; + } + return { ...runtime, isFsReadStream }; +} diff --git a/src/_shims/fetch-deno.ts b/src/_shims/fetch-deno.ts deleted file mode 100644 index c7ef4ff..0000000 --- a/src/_shims/fetch-deno.ts +++ /dev/null @@ -1,27 +0,0 @@ -const _fetch = fetch; -type _fetch = typeof fetch; -const _Request = Request; -type _Request = Request; -type _RequestInfo = RequestInfo; -type _RequestInit = RequestInit; -const _Response = Response; -type _Response = Response; -type _ResponseInit = ResponseInit; -type _BodyInit = BodyInit; -const _Headers = Headers; -type _Headers = Headers; -type _HeadersInit = HeadersInit; - -export const isPolyfilled = false; - -export { - _fetch as fetch, - _Request as Request, - type _RequestInfo as RequestInfo, - type _RequestInit as RequestInit, - _Response as Response, - type _ResponseInit as ResponseInit, - type _BodyInit as BodyInit, - _Headers as Headers, - type _HeadersInit as HeadersInit, -}; diff --git a/src/_shims/fetch-node.d.ts b/src/_shims/fetch-node.d.ts deleted file mode 100644 index 006f00d..0000000 --- a/src/_shims/fetch-node.d.ts +++ /dev/null @@ -1,64 +0,0 @@ -/** - * Disclaimer: modules in _shims aren't intended to be imported by SDK users. - */ - -import * as nf from 'node-fetch'; - -// Use builtin web types if present; else node-fetch types - -/** - * >>> Confused? <<< - * - * If you're getting errors from these types, try adding "lib": ["DOM"] - * to your tsconfig.json, or otherwise configure the appropriate builtin - * `fetch` types for your environment. - */ - -// @ts-ignore -type _fetch = unknown extends typeof fetch ? typeof nf.default : typeof fetch; -// @ts-ignore -type _Request = unknown extends Request ? nf.Request : Request; -// @ts-ignore -type _RequestInfo = unknown extends RequestInfo ? nf.RequestInfo : RequestInfo; -// @ts-ignore -type _RequestInit = unknown extends RequestInit ? nf.RequestInit : RequestInit; -// @ts-ignore -type _Response = unknown extends Response ? nf.Response : Response; -// @ts-ignore -type _ResponseInit = unknown extends ResponseInit ? nf.ResponseInit : ResponseInit; -type _ResponseType = - // @ts-ignore - unknown extends ResponseType ? 'basic' | 'cors' | 'default' | 'error' | 'opaque' | 'opaqueredirect' - : // @ts-ignore - ResponseType; -// @ts-ignore -type _BodyInit = unknown extends BodyInit ? nf.BodyInit : BodyInit; -// @ts-ignore -type _Headers = unknown extends Headers ? nf.Headers : Headers; -// @ts-ignore -type _HeadersInit = unknown extends HeadersInit ? nf.HeadersInit : HeadersInit; - -declare const _fetch: _fetch; -declare const _Request: { - prototype: _Request; - new (input: _RequestInfo | URL, init?: _RequestInit): _Request; -}; -declare const _Response: { - prototype: _Response; - new (body?: _BodyInit | null, init?: _ResponseInit): _Response; -}; -declare const _Headers: { - prototype: _Headers; - new (init?: _HeadersInit): _Headers; -}; - -export const isPolyfilled = false; - -export { _fetch as fetch, _Request as Request, _Response as Response, _Headers as Headers }; -export type { - _RequestInit as RequestInit, - _RequestInfo as RequestInfo, - _ResponseType as ResponseType, - _BodyInit as BodyInit, - _HeadersInit as HeadersInit, -}; diff --git a/src/_shims/fetch-node.js b/src/_shims/fetch-node.js deleted file mode 100644 index 15f8f8a..0000000 --- a/src/_shims/fetch-node.js +++ /dev/null @@ -1,12 +0,0 @@ -/** - * Disclaimer: modules in _shims aren't intended to be imported by SDK users. - */ - -const nf = require('node-fetch'); - -exports.fetch = nf.default; -exports.Request = nf.Request; -exports.Response = nf.Response; -exports.Headers = nf.Headers; - -exports.isPolyfilled = true; diff --git a/src/_shims/fetch-node.mjs b/src/_shims/fetch-node.mjs deleted file mode 100644 index d8543dc..0000000 --- a/src/_shims/fetch-node.mjs +++ /dev/null @@ -1,14 +0,0 @@ -/** - * Disclaimer: modules in _shims aren't intended to be imported by SDK users. - */ - -import * as nf from 'node-fetch'; - -const _fetch = nf.default; -const _Request = nf.Request; -const _Response = nf.Response; -const _Headers = nf.Headers; - -export { _fetch as fetch, _Request as Request, _Response as Response, _Headers as Headers }; - -export const isPolyfilled = true; diff --git a/src/_shims/fetch.d.ts b/src/_shims/fetch.d.ts deleted file mode 100644 index 772a6d9..0000000 --- a/src/_shims/fetch.d.ts +++ /dev/null @@ -1,60 +0,0 @@ -/** - * Disclaimer: modules in _shims aren't intended to be imported by SDK users. - */ - -// Use builtin web types if present; else never (user should -// add appropriate lib or types to tsconfig) - -/** - * >>> Confused? <<< - * - * If you're getting errors from these types, try adding "lib": ["DOM"] - * to your tsconfig.json, or otherwise configure the appropriate builtin - * `fetch` types for your environment. - */ - -// @ts-ignore -type _fetch = unknown extends typeof fetch ? never : typeof fetch; -// @ts-ignore -type _Request = unknown extends Request ? never : Request; -// @ts-ignore -type _RequestInfo = unknown extends RequestInfo ? never : RequestInfo; -// @ts-ignore -type _RequestInit = unknown extends RequestInit ? never : RequestInit; -// @ts-ignore -type _Response = unknown extends Response ? never : Response; -// @ts-ignore -type _ResponseInit = unknown extends ResponseInit ? never : ResponseInit; -// @ts-ignore -type _ResponseType = unknown extends ResponseType ? never : ResponseType; -// @ts-ignore -type _BodyInit = unknown extends BodyInit ? never : BodyInit; -// @ts-ignore -type _Headers = unknown extends Headers ? never : Headers; -// @ts-ignore -type _HeadersInit = unknown extends HeadersInit ? never : HeadersInit; - -declare const _fetch: _fetch; -declare const _Request: { - prototype: _Request; - new (input: _RequestInfo | URL, init?: _RequestInit): _Request; -}; -declare const _Response: { - prototype: _Response; - new (body?: _BodyInit | null, init?: _ResponseInit): _Response; -}; -declare const _Headers: { - prototype: _Headers; - new (init?: _HeadersInit): _Headers; -}; - -export const isPolyfilled = false; - -export { _fetch as fetch, _Request as Request, _Response as Response, _Headers as Headers }; -export type { - _RequestInit as RequestInit, - _RequestInfo as RequestInfo, - _ResponseType as ResponseType, - _BodyInit as BodyInit, - _HeadersInit as HeadersInit, -}; diff --git a/src/_shims/fetch.js b/src/_shims/fetch.js deleted file mode 100644 index 3c3821f..0000000 --- a/src/_shims/fetch.js +++ /dev/null @@ -1,13 +0,0 @@ -/** - * Disclaimer: modules in _shims aren't intended to be imported by SDK users. - */ - -// If we accidentally call fetch with the wrong this binding, -// in the browser it would throw: -// TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation -exports.fetch = fetch.bind(undefined); -exports.Request = Request; -exports.Response = Response; -exports.Headers = Headers; - -exports.isPolyfilled = false; diff --git a/src/_shims/fetch.mjs b/src/_shims/fetch.mjs deleted file mode 100644 index 6d539fb..0000000 --- a/src/_shims/fetch.mjs +++ /dev/null @@ -1,15 +0,0 @@ -/** - * Disclaimer: modules in _shims aren't intended to be imported by SDK users. - */ - -// If we accidentally call fetch with the wrong this binding, -// in the browser it would throw: -// TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation -const _fetch = fetch.bind(undefined); -const _Request = Request; -const _Response = Response; -const _Headers = Headers; - -export const isPolyfilled = false; - -export { _fetch as fetch, _Request as Request, _Response as Response, _Headers as Headers }; diff --git a/src/_shims/fileFromPath-node.ts b/src/_shims/fileFromPath-node.ts deleted file mode 100644 index 065fd7e..0000000 --- a/src/_shims/fileFromPath-node.ts +++ /dev/null @@ -1,29 +0,0 @@ -/** - * Disclaimer: modules in _shims aren't intended to be imported by SDK users. - */ - -import { fileFromPath as _fileFromPath } from 'formdata-node/file-from-path'; -import type { File, FilePropertyBag } from './form-data-node'; - -export type FileFromPathOptions = Omit; - -let warned = false; - -/** - * @deprecated use fs.createReadStream('./my/file.txt') instead - */ -export async function fileFromPath(path: string): Promise; -export async function fileFromPath(path: string, filename?: string): Promise; -export async function fileFromPath(path: string, options?: FileFromPathOptions): Promise; -export async function fileFromPath( - path: string, - filename?: string, - options?: FileFromPathOptions, -): Promise; -export async function fileFromPath(path: string, ...args: any[]): Promise { - if (!warned) { - console.warn(`fileFromPath is deprecated; use fs.createReadStream(${JSON.stringify(path)}) instead`); - warned = true; - } - return await _fileFromPath(path, ...args); -} diff --git a/src/_shims/fileFromPath.ts b/src/_shims/fileFromPath.ts deleted file mode 100644 index 0ec8a23..0000000 --- a/src/_shims/fileFromPath.ts +++ /dev/null @@ -1,29 +0,0 @@ -/** - * Disclaimer: modules in _shims aren't intended to be imported by SDK users. - * - * This is a stub that gets replaced by fileFromPath-node.js for node environments - * in the package export map - */ - -import type { FilePropertyBag, File } from './form-data'; - -export type FileFromPathOptions = Omit; - -/** - * This is a stub for non-node environments that just throws an error. - * In node environments, this module will be replaced by util/node/fileFromPath by the - * package import map. - */ -export async function fileFromPath(path: string): Promise; -export async function fileFromPath(path: string, filename?: string): Promise; -export async function fileFromPath(path: string, options?: FileFromPathOptions): Promise; -export async function fileFromPath( - path: string, - filename?: string, - options?: FileFromPathOptions, -): Promise; -export async function fileFromPath(): Promise { - throw new Error( - 'The `fileFromPath` function is only supported in Node. See the README for more details: https://www.github.com/anthropics/anthropic-sdk-typescript#file-uploads', - ); -} diff --git a/src/_shims/form-data-deno.ts b/src/_shims/form-data-deno.ts deleted file mode 100644 index ec0349e..0000000 --- a/src/_shims/form-data-deno.ts +++ /dev/null @@ -1,19 +0,0 @@ -type _BlobPropertyBag = BlobPropertyBag; -type _FilePropertyBag = FilePropertyBag; - -const _FormData = FormData; -type _FormData = FormData; -const _File = File; -type _File = File; -const _Blob = Blob; -type _Blob = Blob; - -export const isPolyfilled = false; - -export { - _FormData as FormData, - _File as File, - _Blob as Blob, - type _BlobPropertyBag as BlobPropertyBag, - type _FilePropertyBag as FilePropertyBag, -}; diff --git a/src/_shims/form-data-node.d.ts b/src/_shims/form-data-node.d.ts deleted file mode 100644 index 30eceea..0000000 --- a/src/_shims/form-data-node.d.ts +++ /dev/null @@ -1,45 +0,0 @@ -/** - * Disclaimer: modules in _shims aren't intended to be imported by SDK users. - */ - -import * as fd from 'formdata-node'; - -import type { BlobPart } from '../uploads'; - -type EndingType = 'native' | 'transparent'; - -export interface BlobPropertyBag { - endings?: EndingType; - /** MIME type, e.g., "text/plain" */ - type?: string; -} - -export interface FilePropertyBag extends BlobPropertyBag { - lastModified?: number; -} - -// Use builtin web types if present; else formdata-node types - -// @ts-ignore -type _FormData = unknown extends FormData ? fd.FormData : FormData; -// @ts-ignore -type _File = unknown extends File ? fd.File : File; -// @ts-ignore -type _Blob = unknown extends Blob ? fd.Blob : Blob; - -declare const _FormData: { - new (form?: any): _FormData; - prototype: _FormData; -}; -declare const _File: { - new (fileBits: BlobPart[], fileName: string, options?: FilePropertyBag | undefined): _File; - prototype: _File; -}; -declare const _Blob: { - new (blobParts?: BlobPart[] | undefined, options?: BlobPropertyBag | undefined): _Blob; - prototype: _Blob; -}; - -export const isPolyfilled = false; - -export { _FormData as FormData, _File as File, _Blob as Blob }; diff --git a/src/_shims/form-data-node.js b/src/_shims/form-data-node.js deleted file mode 100644 index 892aba5..0000000 --- a/src/_shims/form-data-node.js +++ /dev/null @@ -1,11 +0,0 @@ -/** - * Disclaimer: modules in _shims aren't intended to be imported by SDK users. - */ - -const fd = require('formdata-node'); - -exports.FormData = fd.FormData; -exports.File = fd.File; -exports.Blob = fd.Blob; - -exports.isPolyfilled = true; diff --git a/src/_shims/form-data-node.mjs b/src/_shims/form-data-node.mjs deleted file mode 100644 index b35ac4d..0000000 --- a/src/_shims/form-data-node.mjs +++ /dev/null @@ -1,9 +0,0 @@ -/** - * Disclaimer: modules in _shims aren't intended to be imported by SDK users. - */ - -import { FormData, File, Blob } from 'formdata-node'; - -export { FormData, File, Blob }; - -export const isPolyfilled = true; diff --git a/src/_shims/form-data.d.ts b/src/_shims/form-data.d.ts deleted file mode 100644 index 0fb24cc..0000000 --- a/src/_shims/form-data.d.ts +++ /dev/null @@ -1,43 +0,0 @@ -/** - * Disclaimer: modules in _shims aren't intended to be imported by SDK users. - */ - -import type { BlobPart } from '../uploads'; - -type EndingType = 'native' | 'transparent'; - -export interface BlobPropertyBag { - endings?: EndingType; - type?: string; -} - -export interface FilePropertyBag extends BlobPropertyBag { - lastModified?: number; -} - -// Use builtin web types if present; else never (user should -// add appropriate lib or types to tsconfig) - -// @ts-ignore -type _FormData = unknown extends FormData ? never : FormData; -// @ts-ignore -type _File = unknown extends File ? never : File; -// @ts-ignore -type _Blob = unknown extends Blob ? never : Blob; - -declare const _FormData: { - new (form?: any): _FormData; - prototype: _FormData; -}; -declare const _File: { - new (fileBits: BlobPart[], fileName: string, options?: FilePropertyBag | undefined): _File; - prototype: _File; -}; -declare const _Blob: { - new (blobParts?: BlobPart[] | undefined, options?: BlobPropertyBag | undefined): _Blob; - prototype: _Blob; -}; - -export const isPolyfilled = false; - -export { _FormData as FormData, _File as File, _Blob as Blob }; diff --git a/src/_shims/form-data.js b/src/_shims/form-data.js deleted file mode 100644 index 8cbe41c..0000000 --- a/src/_shims/form-data.js +++ /dev/null @@ -1,17 +0,0 @@ -/** - * Disclaimer: modules in _shims aren't intended to be imported by SDK users. - */ - -exports.FormData = FormData; -exports.Blob = Blob; -exports.File = - typeof File !== 'undefined' ? File : ( - // Bun doesn't implement File yet, so just make a shim that throws a helpful error message - class File extends Blob { - constructor() { - throw new Error(`file uploads aren't supported in this environment yet as 'File' is not defined`); - } - } - ); - -exports.isPolyfilled = false; diff --git a/src/_shims/form-data.mjs b/src/_shims/form-data.mjs deleted file mode 100644 index 3ee740b..0000000 --- a/src/_shims/form-data.mjs +++ /dev/null @@ -1,20 +0,0 @@ -/** - * Disclaimer: modules in _shims aren't intended to be imported by SDK users. - */ - -const _FormData = FormData; -const _Blob = Blob; - -const _File = - typeof File !== 'undefined' ? File : ( - // Bun doesn't implement File yet, so just make a shim that throws a helpful error message - class File extends Blob { - constructor() { - throw new Error(`file uploads aren't supported in this environment yet as 'File' is not defined`); - } - } - ); - -export { _FormData as FormData, _File as File, _Blob as Blob }; - -export const isPolyfilled = false; diff --git a/src/_shims/getMultipartRequestOptions-node.ts b/src/_shims/getMultipartRequestOptions-node.ts deleted file mode 100644 index ac13a07..0000000 --- a/src/_shims/getMultipartRequestOptions-node.ts +++ /dev/null @@ -1,25 +0,0 @@ -/** - * Disclaimer: modules in _shims aren't intended to be imported by SDK users. - */ - -import { FormData } from './form-data-node'; -import type { RequestOptions } from '../core'; -import { Readable } from 'node:stream'; -import { FormDataEncoder } from 'form-data-encoder'; -import { MultipartBody } from '../uploads'; - -export async function getMultipartRequestOptions>( - form: FormData, - opts: RequestOptions, -): Promise> { - const encoder = new FormDataEncoder(form); - const readable = Readable.from(encoder); - const body = new MultipartBody(readable); - const headers = { - ...opts.headers, - ...encoder.headers, - 'Content-Length': encoder.contentLength, - }; - - return { ...opts, body: body as any, headers }; -} diff --git a/src/_shims/getMultipartRequestOptions.ts b/src/_shims/getMultipartRequestOptions.ts deleted file mode 100644 index f74227d..0000000 --- a/src/_shims/getMultipartRequestOptions.ts +++ /dev/null @@ -1,14 +0,0 @@ -/** - * Disclaimer: modules in _shims aren't intended to be imported by SDK users. - */ - -import { FormData } from './form-data'; -import type { RequestOptions } from '../core'; -import { MultipartBody } from '../uploads'; - -export async function getMultipartRequestOptions>( - form: FormData, - opts: RequestOptions, -): Promise> { - return { ...opts, body: new MultipartBody(form) as any }; -} diff --git a/src/_shims/index-deno.ts b/src/_shims/index-deno.ts new file mode 100644 index 0000000..a7c74d4 --- /dev/null +++ b/src/_shims/index-deno.ts @@ -0,0 +1,110 @@ +import { MultipartBody } from './MultipartBody'; +import { type RequestOptions } from '../core'; + +export const kind: string = 'web'; + +export type Agent = any; + +const _fetch = fetch; +type _fetch = typeof fetch; +export { _fetch as fetch }; + +const _Request = Request; +type _Request = Request; +export { _Request as Request }; + +type _RequestInfo = RequestInfo; +export { type _RequestInfo as RequestInfo }; + +type _RequestInit = RequestInit; +export { type _RequestInit as RequestInit }; + +const _Response = Response; +type _Response = Response; +export { _Response as Response }; + +type _ResponseInit = ResponseInit; +export { type _ResponseInit as ResponseInit }; + +type _ResponseType = ResponseType; +export { type _ResponseType as ResponseType }; + +type _BodyInit = BodyInit; +export { type _BodyInit as BodyInit }; + +const _Headers = Headers; +type _Headers = Headers; +export { _Headers as Headers }; + +type _HeadersInit = HeadersInit; +export { type _HeadersInit as HeadersInit }; + +type EndingType = 'native' | 'transparent'; + +export interface BlobPropertyBag { + endings?: EndingType; + type?: string; +} + +export interface FilePropertyBag extends BlobPropertyBag { + lastModified?: number; +} + +export type FileFromPathOptions = Omit; + +const _FormData = FormData; +type _FormData = FormData; +export { _FormData as FormData }; + +const _File = File; +type _File = File; +export { _File as File }; + +const _Blob = Blob; +type _Blob = Blob; +export { _Blob as Blob }; + +export async function getMultipartRequestOptions>( + form: FormData, + opts: RequestOptions, +): Promise> { + return { + ...opts, + body: new MultipartBody(form) as any, + }; +} + +export function getDefaultAgent(url: string) { + return undefined; +} +export function fileFromPath() { + throw new Error( + 'The `fileFromPath` function is only supported in Node. See the README for more details: https://www.github.com/anthropics/anthropic-sdk-typescript#file-uploads', + ); +} + +export const isFsReadStream = (value: any) => false; + +export declare class Readable { + readable: boolean; + readonly readableEnded: boolean; + readonly readableFlowing: boolean | null; + readonly readableHighWaterMark: number; + readonly readableLength: number; + readonly readableObjectMode: boolean; + destroyed: boolean; + read(size?: number): any; + pause(): this; + resume(): this; + isPaused(): boolean; + destroy(error?: Error): this; + [Symbol.asyncIterator](): AsyncIterableIterator; +} + +export declare class FsReadStream extends Readable { + path: {}; // node type is string | Buffer +} + +const _ReadableStream = ReadableStream; +type _ReadableStream = ReadableStream; +export { _ReadableStream as ReadableStream }; diff --git a/src/_shims/index.d.ts b/src/_shims/index.d.ts new file mode 100644 index 0000000..eef346e --- /dev/null +++ b/src/_shims/index.d.ts @@ -0,0 +1,79 @@ +/** + * Disclaimer: modules in _shims aren't intended to be imported by SDK users. + */ +import { manual } from './manual-types'; +import * as auto from '@anthropic-ai/sdk/_shims/auto/types'; +import { type RequestOptions } from '../core'; + +type SelectType = unknown extends Manual ? Auto : Manual; + +export const kind: string; + +// @ts-ignore +export type Agent = SelectType; + +// @ts-ignore +export const fetch: SelectType; + +// @ts-ignore +export type Request = SelectType; +// @ts-ignore +export type RequestInfo = SelectType; +// @ts-ignore +export type RequestInit = SelectType; + +// @ts-ignore +export type Response = SelectType; +// @ts-ignore +export type ResponseInit = SelectType; +// @ts-ignore +export type ResponseType = SelectType; +// @ts-ignore +export type BodyInit = SelectType; +// @ts-ignore +export type Headers = SelectType; +// @ts-ignore +export const Headers: SelectType; +// @ts-ignore +export type HeadersInit = SelectType; + +// @ts-ignore +export type BlobPropertyBag = SelectType; +// @ts-ignore +export type FilePropertyBag = SelectType; +// @ts-ignore +export type FileFromPathOptions = SelectType; +// @ts-ignore +export type FormData = SelectType; +// @ts-ignore +export const FormData: SelectType; +// @ts-ignore +export type File = SelectType; +// @ts-ignore +export const File: SelectType; +// @ts-ignore +export type Blob = SelectType; +// @ts-ignore +export const Blob: SelectType; + +// @ts-ignore +export type Readable = SelectType; +// @ts-ignore +export type FsReadStream = SelectType; +// @ts-ignore +export type ReadableStream = SelectType; + +export function getMultipartRequestOptions>( + form: FormData, + opts: RequestOptions, +): Promise>; + +export function getDefaultAgent(url: string): any; + +// @ts-ignore +export type FileFromPathOptions = SelectType; + +export function fileFromPath(path: string, options?: FileFromPathOptions): Promise; +export function fileFromPath(path: string, filename?: string, options?: FileFromPathOptions): Promise; + +export function isFsReadStream(value: any): value is FsReadStream; diff --git a/src/_shims/index.js b/src/_shims/index.js new file mode 100644 index 0000000..f2db579 --- /dev/null +++ b/src/_shims/index.js @@ -0,0 +1,13 @@ +/** + * Disclaimer: modules in _shims aren't intended to be imported by SDK users. + */ +const shims = require('./registry'); +const auto = require('@anthropic-ai/sdk/_shims/auto/runtime'); +if (!shims.kind) shims.setShims(auto.getRuntime(), { auto: true }); +for (const property of Object.keys(shims)) { + Object.defineProperty(exports, property, { + get() { + return shims[property]; + }, + }); +} diff --git a/src/_shims/index.mjs b/src/_shims/index.mjs new file mode 100644 index 0000000..dfc2a41 --- /dev/null +++ b/src/_shims/index.mjs @@ -0,0 +1,7 @@ +/** + * Disclaimer: modules in _shims aren't intended to be imported by SDK users. + */ +import * as shims from './registry.mjs'; +import * as auto from '@anthropic-ai/sdk/_shims/auto/runtime'; +if (!shims.kind) shims.setShims(auto.getRuntime(), { auto: true }); +export * from './registry.mjs'; diff --git a/src/_shims/manual-types.d.ts b/src/_shims/manual-types.d.ts new file mode 100644 index 0000000..506ec04 --- /dev/null +++ b/src/_shims/manual-types.d.ts @@ -0,0 +1,12 @@ +/** + * Disclaimer: modules in _shims aren't intended to be imported by SDK users. + */ +/** + * Types will get added to this namespace when you import one of the following: + * + * import '@anthropic-ai/sdk/shims/node' + * import '@anthropic-ai/sdk/shims/web' + * + * Importing more than one will cause type and runtime errors. + */ +export namespace manual {} diff --git a/src/_shims/manual-types.js b/src/_shims/manual-types.js new file mode 100644 index 0000000..ddbdb79 --- /dev/null +++ b/src/_shims/manual-types.js @@ -0,0 +1,3 @@ +/** + * Disclaimer: modules in _shims aren't intended to be imported by SDK users. + */ diff --git a/src/_shims/manual-types.mjs b/src/_shims/manual-types.mjs new file mode 100644 index 0000000..ddbdb79 --- /dev/null +++ b/src/_shims/manual-types.mjs @@ -0,0 +1,3 @@ +/** + * Disclaimer: modules in _shims aren't intended to be imported by SDK users. + */ diff --git a/src/_shims/node-readable-node.ts b/src/_shims/node-readable-node.ts deleted file mode 100644 index 0355aa1..0000000 --- a/src/_shims/node-readable-node.ts +++ /dev/null @@ -1,10 +0,0 @@ -/** - * Disclaimer: modules in _shims aren't intended to be imported by SDK users. - */ -export type { Readable } from 'node:stream'; -import { ReadStream as FsReadStream } from 'node:fs'; -export type { FsReadStream }; - -export function isFsReadStream(value: any): value is FsReadStream { - return value instanceof FsReadStream; -} diff --git a/src/_shims/node-readable.ts b/src/_shims/node-readable.ts deleted file mode 100644 index fc3f2f5..0000000 --- a/src/_shims/node-readable.ts +++ /dev/null @@ -1,30 +0,0 @@ -/** - * Disclaimer: modules in _shims aren't intended to be imported by SDK users. - */ - -// shim these Node types to avoid importing @types/node and polluting the user's -// type environment in non-node projects - -export declare class Readable { - readable: boolean; - readonly readableEnded: boolean; - readonly readableFlowing: boolean | null; - readonly readableHighWaterMark: number; - readonly readableLength: number; - readonly readableObjectMode: boolean; - destroyed: boolean; - read(size?: number): any; - pause(): this; - resume(): this; - isPaused(): boolean; - destroy(error?: Error): this; - [Symbol.asyncIterator](): AsyncIterableIterator; -} - -export declare class FsReadStream extends Readable { - path: {}; // node type is string | Buffer -} - -export function isFsReadStream(value: any): value is FsReadStream { - return false; -} diff --git a/src/_shims/node-runtime.ts b/src/_shims/node-runtime.ts new file mode 100644 index 0000000..2e5ab56 --- /dev/null +++ b/src/_shims/node-runtime.ts @@ -0,0 +1,79 @@ +/** + * Disclaimer: modules in _shims aren't intended to be imported by SDK users. + */ +import * as nf from 'node-fetch'; +import * as fd from 'formdata-node'; +import { type File, type FilePropertyBag } from 'formdata-node'; +import KeepAliveAgent from 'agentkeepalive'; +import { AbortController as AbortControllerPolyfill } from 'abort-controller'; +import { ReadStream as FsReadStream } from 'node:fs'; +import { type Agent } from 'node:http'; +import { FormDataEncoder } from 'form-data-encoder'; +import { Readable } from 'node:stream'; +import { type RequestOptions } from '../core'; +import { MultipartBody } from './MultipartBody'; +import { type Shims } from './registry'; + +type FileFromPathOptions = Omit; + +let fileFromPathWarned = false; + +/** + * @deprecated use fs.createReadStream('./my/file.txt') instead + */ +async function fileFromPath(path: string): Promise; +async function fileFromPath(path: string, filename?: string): Promise; +async function fileFromPath(path: string, options?: FileFromPathOptions): Promise; +async function fileFromPath(path: string, filename?: string, options?: FileFromPathOptions): Promise; +async function fileFromPath(path: string, ...args: any[]): Promise { + // this import fails in environments that don't handle export maps correctly, like old versions of Jest + const { fileFromPath: _fileFromPath } = await import('formdata-node/file-from-path'); + + if (!fileFromPathWarned) { + console.warn(`fileFromPath is deprecated; use fs.createReadStream(${JSON.stringify(path)}) instead`); + fileFromPathWarned = true; + } + // @ts-ignore + return await _fileFromPath(path, ...args); +} + +const defaultHttpAgent: Agent = new KeepAliveAgent({ keepAlive: true, timeout: 5 * 60 * 1000 }); +const defaultHttpsAgent: Agent = new KeepAliveAgent.HttpsAgent({ keepAlive: true, timeout: 5 * 60 * 1000 }); + +async function getMultipartRequestOptions>( + form: fd.FormData, + opts: RequestOptions, +): Promise> { + const encoder = new FormDataEncoder(form); + const readable = Readable.from(encoder); + const body = new MultipartBody(readable); + const headers = { + ...opts.headers, + ...encoder.headers, + 'Content-Length': encoder.contentLength, + }; + + return { ...opts, body: body as any, headers }; +} + +export function getRuntime(): Shims { + // Polyfill global object if needed. + if (typeof AbortController === 'undefined') { + // @ts-ignore + AbortController = AbortControllerPolyfill; + } + return { + kind: 'node', + fetch: nf.default, + Request: nf.Request, + Response: nf.Response, + Headers: nf.Headers, + FormData: fd.FormData, + Blob: fd.Blob, + File: fd.File, + getMultipartRequestOptions, + getDefaultAgent: (url: string): Agent => (url.startsWith('https') ? defaultHttpsAgent : defaultHttpAgent), + fileFromPath, + isFsReadStream: (value: any): value is FsReadStream => value instanceof FsReadStream, + }; +} diff --git a/src/_shims/node-types.d.ts b/src/_shims/node-types.d.ts new file mode 100644 index 0000000..28fe604 --- /dev/null +++ b/src/_shims/node-types.d.ts @@ -0,0 +1,42 @@ +/** + * Disclaimer: modules in _shims aren't intended to be imported by SDK users. + */ +import * as nf from 'node-fetch'; +import * as fd from 'formdata-node'; + +export { type Agent } from 'node:http'; +export { type Readable } from 'node:stream'; +export { type ReadStream as FsReadStream } from 'node:fs'; +export { type ReadableStream } from 'web-streams-polyfill'; + +export const fetch: typeof nf.default; + +export type Request = nf.Request; +export type RequestInfo = nf.RequestInfo; +export type RequestInit = nf.RequestInit; + +export type Response = nf.Response; +export type ResponseInit = nf.ResponseInit; +export type ResponseType = nf.ResponseType; +export type BodyInit = nf.BodyInit; +export type Headers = nf.Headers; +export type HeadersInit = nf.HeadersInit; + +type EndingType = 'native' | 'transparent'; +export interface BlobPropertyBag { + endings?: EndingType; + type?: string; +} + +export interface FilePropertyBag extends BlobPropertyBag { + lastModified?: number; +} + +export type FileFromPathOptions = Omit; + +export type FormData = fd.FormData; +export const FormData: typeof fd.FormData; +export type File = fd.File; +export const File: typeof fd.File; +export type Blob = fd.Blob; +export const Blob: typeof fd.Blob; diff --git a/src/_shims/node-types.js b/src/_shims/node-types.js new file mode 100644 index 0000000..ddbdb79 --- /dev/null +++ b/src/_shims/node-types.js @@ -0,0 +1,3 @@ +/** + * Disclaimer: modules in _shims aren't intended to be imported by SDK users. + */ diff --git a/src/_shims/node-types.mjs b/src/_shims/node-types.mjs new file mode 100644 index 0000000..ddbdb79 --- /dev/null +++ b/src/_shims/node-types.mjs @@ -0,0 +1,3 @@ +/** + * Disclaimer: modules in _shims aren't intended to be imported by SDK users. + */ diff --git a/src/_shims/registry.ts b/src/_shims/registry.ts new file mode 100644 index 0000000..75b748f --- /dev/null +++ b/src/_shims/registry.ts @@ -0,0 +1,64 @@ +/** + * Disclaimer: modules in _shims aren't intended to be imported by SDK users. + */ +import { type RequestOptions } from '../core'; + +export interface Shims { + kind: string; + fetch: any; + Request: any; + Response: any; + Headers: any; + FormData: any; + Blob: any; + File: any; + getMultipartRequestOptions: >( + form: Shims['FormData'], + opts: RequestOptions, + ) => Promise>; + getDefaultAgent: (url: string) => any; + fileFromPath: + | ((path: string, filename?: string, options?: {}) => Promise) + | ((path: string, options?: {}) => Promise); + isFsReadStream: (value: any) => boolean; +} + +export let auto = false; +export let kind: Shims['kind'] | undefined = undefined; +export let fetch: Shims['fetch'] | undefined = undefined; +export let Request: Shims['Request'] | undefined = undefined; +export let Response: Shims['Response'] | undefined = undefined; +export let Headers: Shims['Headers'] | undefined = undefined; +export let FormData: Shims['FormData'] | undefined = undefined; +export let Blob: Shims['Blob'] | undefined = undefined; +export let File: Shims['File'] | undefined = undefined; +export let getMultipartRequestOptions: Shims['getMultipartRequestOptions'] | undefined = undefined; +export let getDefaultAgent: Shims['getDefaultAgent'] | undefined = undefined; +export let fileFromPath: Shims['fileFromPath'] | undefined = undefined; +export let isFsReadStream: Shims['isFsReadStream'] | undefined = undefined; + +export function setShims(shims: Shims, options: { auto: boolean } = { auto: false }) { + if (auto) { + throw new Error( + `you must \`import '@anthropic-ai/sdk/shims/${shims.kind}'\` before importing anything else from @anthropic-ai/sdk`, + ); + } + if (kind) { + throw new Error( + `can't \`import '@anthropic-ai/sdk/shims/${shims.kind}'\` after \`import '@anthropic-ai/sdk/shims/${kind}'\``, + ); + } + auto = options.auto; + kind = shims.kind; + fetch = shims.fetch; + Request = shims.Request; + Response = shims.Response; + Headers = shims.Headers; + FormData = shims.FormData; + Blob = shims.Blob; + File = shims.File; + getMultipartRequestOptions = shims.getMultipartRequestOptions; + getDefaultAgent = shims.getDefaultAgent; + fileFromPath = shims.fileFromPath; + isFsReadStream = shims.isFsReadStream; +} diff --git a/src/_shims/web-runtime.ts b/src/_shims/web-runtime.ts new file mode 100644 index 0000000..a7be5d9 --- /dev/null +++ b/src/_shims/web-runtime.ts @@ -0,0 +1,91 @@ +/** + * Disclaimer: modules in _shims aren't intended to be imported by SDK users. + */ +import { MultipartBody } from './MultipartBody'; +import { type RequestOptions } from '../core'; +import { type Shims } from './registry'; + +export function getRuntime({ manuallyImported }: { manuallyImported?: boolean } = {}): Shims { + const recommendation = + manuallyImported ? + `You may need to use polyfills` + : `Add one of these imports before your first \`import … from '@anthropic-ai/sdk'\`: +- \`import '@anthropic-ai/sdk/shims/node'\` (if you're running on Node) +- \`import '@anthropic-ai/sdk/shims/web'\` (otherwise) +`; + + let _fetch, _Request, _Response, _Headers; + try { + // @ts-ignore + _fetch = fetch; + // @ts-ignore + _Request = Request; + // @ts-ignore + _Response = Response; + // @ts-ignore + _Headers = Headers; + } catch (error) { + throw new Error( + `this environment is missing the following Web Fetch API type: ${ + (error as any).message + }. ${recommendation}`, + ); + } + + return { + kind: 'web', + fetch: _fetch, + Request: _Request, + Response: _Response, + Headers: _Headers, + FormData: + // @ts-ignore + typeof FormData !== 'undefined' ? FormData : ( + class FormData { + // @ts-ignore + constructor() { + throw new Error( + `file uploads aren't supported in this environment yet as 'FormData' is undefined. ${recommendation}`, + ); + } + } + ), + Blob: + typeof Blob !== 'undefined' ? Blob : ( + class Blob { + constructor() { + throw new Error( + `file uploads aren't supported in this environment yet as 'Blob' is undefined. ${recommendation}`, + ); + } + } + ), + File: + // @ts-ignore + typeof File !== 'undefined' ? File : ( + class File { + // @ts-ignore + constructor() { + throw new Error( + `file uploads aren't supported in this environment yet as 'File' is undefined. ${recommendation}`, + ); + } + } + ), + getMultipartRequestOptions: async >( + // @ts-ignore + form: FormData, + opts: RequestOptions, + ): Promise> => ({ + ...opts, + body: new MultipartBody(form) as any, + }), + getDefaultAgent: (url: string) => undefined, + fileFromPath: () => { + throw new Error( + 'The `fileFromPath` function is only supported in Node. See the README for more details: https://www.github.com/anthropics/anthropic-sdk-typescript#file-uploads', + ); + }, + isFsReadStream: (value: any) => false, + }; +} diff --git a/src/_shims/web-types.d.ts b/src/_shims/web-types.d.ts new file mode 100644 index 0000000..ec96cd8 --- /dev/null +++ b/src/_shims/web-types.d.ts @@ -0,0 +1,82 @@ +/** + * Disclaimer: modules in _shims aren't intended to be imported by SDK users. + */ +export type Agent = any; + +declare const _fetch: typeof fetch; +export { _fetch as fetch }; + +type _Request = Request; +export { _Request as Request }; + +type _RequestInfo = RequestInfo; +export { type _RequestInfo as RequestInfo }; + +type _RequestInit = RequestInit; +export { type _RequestInit as RequestInit }; + +type _Response = Response; +export { _Response as Response }; + +type _ResponseInit = ResponseInit; +export { type _ResponseInit as ResponseInit }; + +type _ResponseType = ResponseType; +export { type _ResponseType as ResponseType }; + +type _BodyInit = BodyInit; +export { type _BodyInit as BodyInit }; + +type _Headers = Headers; +export { _Headers as Headers }; + +type _HeadersInit = HeadersInit; +export { type _HeadersInit as HeadersInit }; + +type EndingType = 'native' | 'transparent'; + +export interface BlobPropertyBag { + endings?: EndingType; + type?: string; +} + +export interface FilePropertyBag extends BlobPropertyBag { + lastModified?: number; +} + +export type FileFromPathOptions = Omit; + +type _FormData = FormData; +declare const _FormData: typeof FormData; +export { _FormData as FormData }; + +type _File = File; +declare const _File: typeof File; +export { _File as File }; + +type _Blob = Blob; +declare const _Blob: typeof Blob; +export { _Blob as Blob }; + +export declare class Readable { + readable: boolean; + readonly readableEnded: boolean; + readonly readableFlowing: boolean | null; + readonly readableHighWaterMark: number; + readonly readableLength: number; + readonly readableObjectMode: boolean; + destroyed: boolean; + read(size?: number): any; + pause(): this; + resume(): this; + isPaused(): boolean; + destroy(error?: Error): this; + [Symbol.asyncIterator](): AsyncIterableIterator; +} + +export declare class FsReadStream extends Readable { + path: {}; // node type is string | Buffer +} + +type _ReadableStream = ReadableStream; +export { type _ReadableStream as ReadableStream }; diff --git a/src/_shims/web-types.js b/src/_shims/web-types.js new file mode 100644 index 0000000..ddbdb79 --- /dev/null +++ b/src/_shims/web-types.js @@ -0,0 +1,3 @@ +/** + * Disclaimer: modules in _shims aren't intended to be imported by SDK users. + */ diff --git a/src/_shims/web-types.mjs b/src/_shims/web-types.mjs new file mode 100644 index 0000000..ddbdb79 --- /dev/null +++ b/src/_shims/web-types.mjs @@ -0,0 +1,3 @@ +/** + * Disclaimer: modules in _shims aren't intended to be imported by SDK users. + */ diff --git a/src/core.ts b/src/core.ts index 3a578f2..0310311 100644 --- a/src/core.ts +++ b/src/core.ts @@ -1,16 +1,17 @@ import { VERSION } from './version'; import { Stream } from './streaming'; import { APIError, APIConnectionError, APIConnectionTimeoutError, APIUserAbortError } from './error'; -import type { Readable } from '@anthropic-ai/sdk/_shims/node-readable'; -import { getDefaultAgent, type Agent } from '@anthropic-ai/sdk/_shims/agent'; import { + kind as shimsKind, + type Readable, + getDefaultAgent, + type Agent, fetch, - isPolyfilled as fetchIsPolyfilled, type RequestInfo, type RequestInit, type Response, type HeadersInit, -} from '@anthropic-ai/sdk/_shims/fetch'; +} from './_shims/index'; export { type Response }; import { isMultipartBody } from './uploads'; export { @@ -84,6 +85,12 @@ export class APIPromise extends Promise { * * If you want to parse the response body but still get the `Response` * instance, you can use {@link withResponse()}. + * + * 👋 Getting the wrong TypeScript type for `Response`? + * Try setting `"moduleResolution": "NodeNext"` if you can, + * or add one of these imports before your first `import … from '@anthropic-ai/sdk'`: + * - `import '@anthropic-ai/sdk/shims/node'` (if you're running on Node) + * - `import '@anthropic-ai/sdk/shims/web'` (otherwise) */ asResponse(): Promise { return this.responsePromise.then((p) => p.response); @@ -93,6 +100,13 @@ export class APIPromise extends Promise { * * If you just want to get the raw `Response` instance without parsing it, * you can use {@link asResponse()}. + * + * + * 👋 Getting the wrong TypeScript type for `Response`? + * Try setting `"moduleResolution": "NodeNext"` if you can, + * or add one of these imports before your first `import … from '@anthropic-ai/sdk'`: + * - `import '@anthropic-ai/sdk/shims/node'` (if you're running on Node) + * - `import '@anthropic-ai/sdk/shims/web'` (otherwise) */ async withResponse(): Promise<{ data: T; response: Response }> { const [data, response] = await Promise.all([this.parse(), this.asResponse()]); @@ -277,7 +291,7 @@ export abstract class APIClient { ...headers, }; // let builtin fetch set the Content-Type for multipart bodies - if (isMultipartBody(options.body) && !fetchIsPolyfilled) { + if (isMultipartBody(options.body) && shimsKind !== 'node') { delete reqHeaders['Content-Type']; } @@ -444,11 +458,14 @@ export abstract class APIClient { const timeout = setTimeout(() => controller.abort(), ms); - return this.getRequestClient() - .fetch(url, { signal: controller.signal as any, ...options }) - .finally(() => { - clearTimeout(timeout); - }); + return ( + this.getRequestClient() + // use undefined this binding; fetch errors if bound to something else in browser/cloudflare + .fetch.call(undefined, url, { signal: controller.signal as any, ...options }) + .finally(() => { + clearTimeout(timeout); + }) + ); } protected getRequestClient(): RequestClient { @@ -592,7 +609,7 @@ export abstract class AbstractPage implements AsyncIterable { } else if ('url' in nextInfo) { const params = [...Object.entries(nextOptions.query || {}), ...nextInfo.url.searchParams.entries()]; for (const [key, value] of params) { - nextInfo.url.searchParams.set(key, value); + nextInfo.url.searchParams.set(key, value as any); } nextOptions.query = undefined; nextOptions.path = nextInfo.url.toString(); @@ -718,7 +735,7 @@ const requestOptionsKeys: KeysEnum = { idempotencyKey: true, }; -export const isRequestOptions = (obj: unknown): obj is RequestOptions => { +export const isRequestOptions = (obj: unknown): obj is RequestOptions | Readable> => { return ( typeof obj === 'object' && obj !== null && diff --git a/src/index.ts b/src/index.ts index 65ec88c..7a3d50c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -3,7 +3,7 @@ import * as Core from './core'; import * as API from './resources/index'; import * as Errors from './error'; -import type { Agent } from '@anthropic-ai/sdk/_shims/agent'; +import { type Agent } from './_shims/index'; import * as Uploads from './uploads'; export interface ClientOptions { diff --git a/src/shims/node.ts b/src/shims/node.ts new file mode 100644 index 0000000..9273d4e --- /dev/null +++ b/src/shims/node.ts @@ -0,0 +1,50 @@ +// @ts-ignore +import * as types from '../_shims/node-types'; +import { setShims } from '../_shims/registry'; +import { getRuntime } from '../_shims/node-runtime'; +setShims(getRuntime()); + +declare module '../_shims/manual-types' { + export namespace manual { + // @ts-ignore + export type Agent = types.Agent; + // @ts-ignore + export import fetch = types.fetch; + // @ts-ignore + export type Request = types.Request; + // @ts-ignore + export type RequestInfo = types.RequestInfo; + // @ts-ignore + export type RequestInit = types.RequestInit; + // @ts-ignore + export type Response = types.Response; + // @ts-ignore + export type ResponseInit = types.ResponseInit; + // @ts-ignore + export type ResponseType = types.ResponseType; + // @ts-ignore + export type BodyInit = types.BodyInit; + // @ts-ignore + export type Headers = types.Headers; + // @ts-ignore + export type HeadersInit = types.HeadersInit; + // @ts-ignore + export type BlobPropertyBag = types.BlobPropertyBag; + // @ts-ignore + export type FilePropertyBag = types.FilePropertyBag; + // @ts-ignore + export type FileFromPathOptions = types.FileFromPathOptions; + // @ts-ignore + export import FormData = types.FormData; + // @ts-ignore + export import File = types.File; + // @ts-ignore + export import Blob = types.Blob; + // @ts-ignore + export type Readable = types.Readable; + // @ts-ignore + export type FsReadStream = types.FsReadStream; + // @ts-ignore + export type ReadableStream = types.ReadableStream; + } +} diff --git a/src/shims/web.ts b/src/shims/web.ts new file mode 100644 index 0000000..9970f1d --- /dev/null +++ b/src/shims/web.ts @@ -0,0 +1,50 @@ +// @ts-ignore +import * as types from '../_shims/web-types'; +import { setShims } from '../_shims/registry'; +import { getRuntime } from '../_shims/web-runtime'; +setShims(getRuntime({ manuallyImported: true })); + +declare module '../_shims/manual-types' { + export namespace manual { + // @ts-ignore + export type Agent = types.Agent; + // @ts-ignore + export import fetch = types.fetch; + // @ts-ignore + export type Request = types.Request; + // @ts-ignore + export type RequestInfo = types.RequestInfo; + // @ts-ignore + export type RequestInit = types.RequestInit; + // @ts-ignore + export type Response = types.Response; + // @ts-ignore + export type ResponseInit = types.ResponseInit; + // @ts-ignore + export type ResponseType = types.ResponseType; + // @ts-ignore + export type BodyInit = types.BodyInit; + // @ts-ignore + export type Headers = types.Headers; + // @ts-ignore + export type HeadersInit = types.HeadersInit; + // @ts-ignore + export type BlobPropertyBag = types.BlobPropertyBag; + // @ts-ignore + export type FilePropertyBag = types.FilePropertyBag; + // @ts-ignore + export type FileFromPathOptions = types.FileFromPathOptions; + // @ts-ignore + export import FormData = types.FormData; + // @ts-ignore + export import File = types.File; + // @ts-ignore + export import Blob = types.Blob; + // @ts-ignore + export type Readable = types.Readable; + // @ts-ignore + export type FsReadStream = types.FsReadStream; + // @ts-ignore + export type ReadableStream = types.ReadableStream; + } +} diff --git a/src/streaming.ts b/src/streaming.ts index d74c457..7be74ab 100644 --- a/src/streaming.ts +++ b/src/streaming.ts @@ -1,4 +1,4 @@ -import type { Response } from '@anthropic-ai/sdk/_shims/fetch'; +import { type Response } from './_shims/index'; import { safeJSON, createResponseHeaders } from '@anthropic-ai/sdk/core'; import { APIError } from '@anthropic-ai/sdk/error'; diff --git a/src/uploads.ts b/src/uploads.ts index fd16f68..301d770 100644 --- a/src/uploads.ts +++ b/src/uploads.ts @@ -1,12 +1,15 @@ import { type RequestOptions } from './core'; -import { type Readable } from '@anthropic-ai/sdk/_shims/node-readable'; -import { type BodyInit } from '@anthropic-ai/sdk/_shims/fetch'; -import { FormData, File, type Blob, type FilePropertyBag } from '@anthropic-ai/sdk/_shims/form-data'; -import { getMultipartRequestOptions } from '@anthropic-ai/sdk/_shims/getMultipartRequestOptions'; -import { fileFromPath } from '@anthropic-ai/sdk/_shims/fileFromPath'; -import { type FsReadStream, isFsReadStream } from '@anthropic-ai/sdk/_shims/node-readable'; - -export { fileFromPath }; +import { + FormData, + File, + type Blob, + type FilePropertyBag, + getMultipartRequestOptions, + type FsReadStream, + isFsReadStream, +} from './_shims/index'; +import { MultipartBody } from './_shims/MultipartBody'; +export { fileFromPath } from './_shims/index'; type BlobLikePart = string | ArrayBuffer | ArrayBufferView | BlobLike | Uint8Array | DataView; export type BlobPart = string | ArrayBuffer | ArrayBufferView | Blob | Uint8Array | DataView; @@ -175,13 +178,6 @@ const getStringFromMaybeBuffer = (x: string | Buffer | unknown): string | undefi const isAsyncIterableIterator = (value: any): value is AsyncIterableIterator => value != null && typeof value === 'object' && typeof value[Symbol.asyncIterator] === 'function'; -export class MultipartBody { - constructor(public body: Readable | BodyInit) {} - get [Symbol.toStringTag](): string { - return 'MultipartBody'; - } -} - export const isMultipartBody = (body: any): body is MultipartBody => body && typeof body === 'object' && body.body && body[Symbol.toStringTag] === 'MultipartBody'; diff --git a/tests/form.test.ts b/tests/form.test.ts index 7628ddb..d3a8699 100644 --- a/tests/form.test.ts +++ b/tests/form.test.ts @@ -1,5 +1,5 @@ import { multipartFormRequestOptions, createForm } from '@anthropic-ai/sdk/core'; -import { Blob } from '@anthropic-ai/sdk/_shims/form-data'; +import { Blob } from '@anthropic-ai/sdk/_shims/index'; import { toFile } from '@anthropic-ai/sdk'; describe('form data validation', () => { diff --git a/tests/index.test.ts b/tests/index.test.ts index 1af9199..b32aeea 100644 --- a/tests/index.test.ts +++ b/tests/index.test.ts @@ -3,12 +3,7 @@ import Anthropic from '@anthropic-ai/sdk'; import { APIUserAbortError } from '@anthropic-ai/sdk'; import { Headers } from '@anthropic-ai/sdk/core'; -import { - Response, - fetch as defaultFetch, - type RequestInit, - type RequestInfo, -} from '@anthropic-ai/sdk/_shims/fetch'; +import defaultFetch, { Response, type RequestInit, type RequestInfo } from 'node-fetch'; describe('instantiate client', () => { const env = process.env; diff --git a/tests/responses.test.ts b/tests/responses.test.ts index dfc512c..d0db2b1 100644 --- a/tests/responses.test.ts +++ b/tests/responses.test.ts @@ -1,5 +1,5 @@ import { createResponseHeaders } from '@anthropic-ai/sdk/core'; -import { Headers } from '@anthropic-ai/sdk/_shims/fetch'; +import { Headers } from '@anthropic-ai/sdk/_shims/index'; describe('response parsing', () => { // TODO: test unicode characters diff --git a/tests/uploads.test.ts b/tests/uploads.test.ts index 85f8bef..2e3f905 100644 --- a/tests/uploads.test.ts +++ b/tests/uploads.test.ts @@ -1,6 +1,6 @@ import fs from 'fs'; import { toFile, type ResponseLike } from '@anthropic-ai/sdk/uploads'; -import { File } from '@anthropic-ai/sdk/_shims/form-data'; +import { File } from '@anthropic-ai/sdk/_shims/index'; class MyClass { name: string = 'foo'; diff --git a/tsconfig.build.json b/tsconfig.build.json index a83edac..6cbb72e 100644 --- a/tsconfig.build.json +++ b/tsconfig.build.json @@ -1,13 +1,12 @@ { "extends": "./tsconfig.json", "include": ["dist/src"], - "exclude": ["dist/src/_shims/*.deno.ts"], + "exclude": ["dist/src/_shims/*-deno.ts"], "compilerOptions": { "rootDir": "./dist/src", "paths": { - "@anthropic-ai/sdk/_shims/*": ["dist/src/_shims/*-node"], - "@anthropic-ai/sdk": ["dist/src/index.ts"], "@anthropic-ai/sdk/*": ["dist/src/*"], + "@anthropic-ai/sdk": ["dist/src/index.ts"], "digest-fetch": ["./typings/digest-fetch"] }, "noEmit": false, @@ -16,20 +15,5 @@ "outDir": "dist", "pretty": true, "sourceMap": true - }, - "tsc-alias": { - "fileExtensions": { - "inputGlob": "{mjs,cjs,js,jsx,mts,cts,ts,tsx}" - }, - "replacers": { - "replace-self-referencing-imports": { - "enabled": true, - "file": "./scripts/replace-self-referencing-imports.js" - }, - "resolve-full-paths": { - "enabled": true, - "file": "./scripts/resolve-full-paths.js" - } - } } } diff --git a/tsconfig.deno.json b/tsconfig.deno.json index 0c5e232..fb621a4 100644 --- a/tsconfig.deno.json +++ b/tsconfig.deno.json @@ -6,9 +6,9 @@ "rootDir": "./deno", "lib": ["es2020", "DOM"], "paths": { - "@anthropic-ai/sdk/_shims/*": ["deno/_shims/*"], - "@anthropic-ai/sdk": ["deno/index.ts"], + "@anthropic-ai/sdk/_shims/auto/*": ["deno/_shims/auto/*-deno"], "@anthropic-ai/sdk/*": ["deno/*"], + "@anthropic-ai/sdk": ["deno/index.ts"], "digest-fetch": ["./typings/digest-fetch"] }, "noEmit": true, diff --git a/tsconfig.json b/tsconfig.json index 70bb78e..7235f91 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,6 +1,6 @@ { "include": ["src", "tests", "examples"], - "exclude": ["src/_shims/*.deno.ts"], + "exclude": ["src/_shims/**/*-deno.ts"], "compilerOptions": { "target": "es2019", "lib": ["es2020"], @@ -9,9 +9,9 @@ "esModuleInterop": true, "baseUrl": "./", "paths": { - "@anthropic-ai/sdk/_shims/*": ["src/_shims/*-node"], - "@anthropic-ai/sdk": ["src/index.ts"], + "@anthropic-ai/sdk/_shims/auto/*": ["src/_shims/auto/*-node"], "@anthropic-ai/sdk/*": ["src/*"], + "@anthropic-ai/sdk": ["src/index.ts"], "digest-fetch": ["./typings/digest-fetch"] }, "noEmit": true, diff --git a/yarn.lock b/yarn.lock index 71a51f5..633f386 100644 --- a/yarn.lock +++ b/yarn.lock @@ -352,22 +352,27 @@ dependencies: "@cspotcode/source-map-consumer" "0.8.0" -"@eslint-community/eslint-utils@^4.2.0": +"@eslint-community/eslint-utils@^4.2.0", "@eslint-community/eslint-utils@^4.4.0": version "4.4.0" resolved "https://registry.yarnpkg.com/@eslint-community/eslint-utils/-/eslint-utils-4.4.0.tgz#a23514e8fb9af1269d5f7788aa556798d61c6b59" integrity sha512-1/sA4dwrzBAyeUoQ6oxahHKmrZvsnLCg4RfxW3ZFGGmQkSNQPFNLV9CUEFQP1x9EYXHTo5p6xdhZM1Ne9p/AfA== dependencies: eslint-visitor-keys "^3.3.0" -"@eslint-community/regexpp@^4.4.0", "@eslint-community/regexpp@^4.6.1": +"@eslint-community/regexpp@^4.5.1": + version "4.8.1" + resolved "https://registry.yarnpkg.com/@eslint-community/regexpp/-/regexpp-4.8.1.tgz#8c4bb756cc2aa7eaf13cfa5e69c83afb3260c20c" + integrity sha512-PWiOzLIUAjN/w5K17PoF4n6sKBw0gqLHPhywmYHP4t1VFQQVYeb1yWsJwnMVEMl3tUHME7X/SJPZLmtG7XBDxQ== + +"@eslint-community/regexpp@^4.6.1": version "4.6.2" resolved "https://registry.yarnpkg.com/@eslint-community/regexpp/-/regexpp-4.6.2.tgz#1816b5f6948029c5eaacb0703b850ee0cb37d8f8" integrity sha512-pPTNuaAG3QMH+buKyBIGJs3g/S5y0caxw0ygM3YyE6yJFySwiGGSzA+mM3KJ8QQvzeLh3blwgSonkFjgQdxzMw== -"@eslint/eslintrc@^2.1.1": - version "2.1.1" - resolved "https://registry.yarnpkg.com/@eslint/eslintrc/-/eslintrc-2.1.1.tgz#18d635e24ad35f7276e8a49d135c7d3ca6a46f93" - integrity sha512-9t7ZA7NGGK8ckelF0PQCfcxIUzs1Md5rrO6U/c+FIQNanea5UZC0wqKXH4vHBccmu4ZJgZ2idtPeW7+Q2npOEA== +"@eslint/eslintrc@^2.1.2": + version "2.1.2" + resolved "https://registry.yarnpkg.com/@eslint/eslintrc/-/eslintrc-2.1.2.tgz#c6936b4b328c64496692f76944e755738be62396" + integrity sha512-+wvgpDsrB1YqAMdEUCcnTlpfVBH7Vqn6A/NT3D8WVXFIaKMlErPIZT3oCIAVCOtarRpMtelZLqJeU3t7WY6X6g== dependencies: ajv "^6.12.4" debug "^4.3.2" @@ -379,10 +384,10 @@ minimatch "^3.1.2" strip-json-comments "^3.1.1" -"@eslint/js@^8.46.0": - version "8.46.0" - resolved "https://registry.yarnpkg.com/@eslint/js/-/js-8.46.0.tgz#3f7802972e8b6fe3f88ed1aabc74ec596c456db6" - integrity sha512-a8TLtmPi8xzPkCbp/OGFUo5yhRkHM2Ko9kOWP4znJr0WAhWyThaw3PnwX4vOTWOAMsV2uRt32PPDcEz63esSaA== +"@eslint/js@8.49.0": + version "8.49.0" + resolved "https://registry.yarnpkg.com/@eslint/js/-/js-8.49.0.tgz#86f79756004a97fa4df866835093f1df3d03c333" + integrity sha512-1S8uAY/MTJqVx0SC4epBq+N2yhuwtNwLbJYNZyhL2pO1ZVKn5HFXav5T41Ryzy9K9V7ZId2JB2oy/W4aCd9/2w== "@glimmer/env@0.1.7": version "0.1.7" @@ -420,10 +425,10 @@ resolved "https://registry.yarnpkg.com/@handlebars/parser/-/parser-2.0.0.tgz#5e8b7298f31ff8f7b260e6b7363c7e9ceed7d9c5" integrity sha512-EP9uEDZv/L5Qh9IWuMUGJRfwhXJ4h1dqKTT4/3+tY0eu7sPis7xh23j61SYUnNF4vqCQvvUXpDo9Bh/+q1zASA== -"@humanwhocodes/config-array@^0.11.10": - version "0.11.10" - resolved "https://registry.yarnpkg.com/@humanwhocodes/config-array/-/config-array-0.11.10.tgz#5a3ffe32cc9306365fb3fd572596cd602d5e12d2" - integrity sha512-KVVjQmNUepDVGXNuoRRdmmEjruj0KfiGSbS8LVc12LMsWDQzRXJ0qdhN8L8uUigKpfEHRhlaQFY0ib1tnUbNeQ== +"@humanwhocodes/config-array@^0.11.11": + version "0.11.11" + resolved "https://registry.yarnpkg.com/@humanwhocodes/config-array/-/config-array-0.11.11.tgz#88a04c570dbbc7dd943e4712429c3df09bc32844" + integrity sha512-N2brEuAadi0CcdeMXUkhbZB84eskAc8MEX1By6qEchoVywSgXPIjou4rYsl0V3Hj0ZnuGycGCjdNgockbzeWNA== dependencies: "@humanwhocodes/object-schema" "^1.2.1" debug "^4.1.1" @@ -843,10 +848,10 @@ expect "^29.0.0" pretty-format "^29.0.0" -"@types/json-schema@^7.0.9": - version "7.0.12" - resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.12.tgz#d70faba7039d5fca54c83c7dbab41051d2b6f6cb" - integrity sha512-Hr5Jfhc9eYOQNPYO5WLDq/n4jqijdHNlDXjuAQkkt+mWdQR+XJToOHrsD4cPaMXpn6KO7y2+wM8AZEs8VpBLVA== +"@types/json-schema@^7.0.12": + version "7.0.13" + resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.13.tgz#02c24f4363176d2d18fc8b70b9f3c54aba178a85" + integrity sha512-RbSSoHliUbnXj3ny0CNFOoxrIDV6SUGyStHsvDqosw6CkdPV8TtWGlfecuK4ToyMEAql6pzNxgCFKanovUzlgQ== "@types/node-fetch@^2.6.4": version "2.6.4" @@ -876,10 +881,10 @@ resolved "https://registry.yarnpkg.com/@types/prettier/-/prettier-2.6.0.tgz#efcbd41937f9ae7434c714ab698604822d890759" integrity sha512-G/AdOadiZhnJp0jXCaBQU449W2h716OW/EoXeYkCytxKL06X1WCXB4DZpp8TpZ8eyIJVS1cw4lrlkkSYU21cDw== -"@types/semver@^7.3.12": - version "7.5.0" - resolved "https://registry.yarnpkg.com/@types/semver/-/semver-7.5.0.tgz#591c1ce3a702c45ee15f47a42ade72c2fd78978a" - integrity sha512-G8hZ6XJiHnuhQKR7ZmysCeJWE08o8T0AXtk5darsCaTVsYZhhgUrq53jizaR2FvsoeCwJhlmwTjkXBY5Pn/ZHw== +"@types/semver@^7.5.0": + version "7.5.2" + resolved "https://registry.yarnpkg.com/@types/semver/-/semver-7.5.2.tgz#31f6eec1ed7ec23f4f05608d3a2d381df041f564" + integrity sha512-7aqorHYgdNO4DM36stTiGO3DvKoex9TQRwsJU6vMaFGyqpBA1MNZkz+PG3gaNUPpTAOYhT1WR7M1JyA3fbS9Cw== "@types/stack-utils@^2.0.0": version "2.0.1" @@ -903,59 +908,61 @@ dependencies: "@types/yargs-parser" "*" -"@typescript-eslint/eslint-plugin@^5.33.0": - version "5.62.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-5.62.0.tgz#aeef0328d172b9e37d9bab6dbc13b87ed88977db" - integrity sha512-TiZzBSJja/LbhNPvk6yc0JrX9XqhQ0hdh6M2svYfsHGejaKFIAGd9MQ+ERIMzLGlN/kZoYIgdxFV0PuljTKXag== +"@typescript-eslint/eslint-plugin@^6.7.0": + version "6.7.2" + resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-6.7.2.tgz#f18cc75c9cceac8080a9dc2e7d166008c5207b9f" + integrity sha512-ooaHxlmSgZTM6CHYAFRlifqh1OAr3PAQEwi7lhYhaegbnXrnh7CDcHmc3+ihhbQC7H0i4JF0psI5ehzkF6Yl6Q== dependencies: - "@eslint-community/regexpp" "^4.4.0" - "@typescript-eslint/scope-manager" "5.62.0" - "@typescript-eslint/type-utils" "5.62.0" - "@typescript-eslint/utils" "5.62.0" + "@eslint-community/regexpp" "^4.5.1" + "@typescript-eslint/scope-manager" "6.7.2" + "@typescript-eslint/type-utils" "6.7.2" + "@typescript-eslint/utils" "6.7.2" + "@typescript-eslint/visitor-keys" "6.7.2" debug "^4.3.4" graphemer "^1.4.0" - ignore "^5.2.0" - natural-compare-lite "^1.4.0" - semver "^7.3.7" - tsutils "^3.21.0" - -"@typescript-eslint/parser@^5.33.0": - version "5.62.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-5.62.0.tgz#1b63d082d849a2fcae8a569248fbe2ee1b8a56c7" - integrity sha512-VlJEV0fOQ7BExOsHYAGrgbEiZoi8D+Bl2+f6V2RrXerRSylnp+ZBHmPvaIa8cz0Ajx7WO7Z5RqfgYg7ED1nRhA== - dependencies: - "@typescript-eslint/scope-manager" "5.62.0" - "@typescript-eslint/types" "5.62.0" - "@typescript-eslint/typescript-estree" "5.62.0" + ignore "^5.2.4" + natural-compare "^1.4.0" + semver "^7.5.4" + ts-api-utils "^1.0.1" + +"@typescript-eslint/parser@^6.7.0": + version "6.7.2" + resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-6.7.2.tgz#e0ae93771441b9518e67d0660c79e3a105497af4" + integrity sha512-KA3E4ox0ws+SPyxQf9iSI25R6b4Ne78ORhNHeVKrPQnoYsb9UhieoiRoJgrzgEeKGOXhcY1i8YtOeCHHTDa6Fw== + dependencies: + "@typescript-eslint/scope-manager" "6.7.2" + "@typescript-eslint/types" "6.7.2" + "@typescript-eslint/typescript-estree" "6.7.2" + "@typescript-eslint/visitor-keys" "6.7.2" debug "^4.3.4" -"@typescript-eslint/scope-manager@5.62.0": - version "5.62.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-5.62.0.tgz#d9457ccc6a0b8d6b37d0eb252a23022478c5460c" - integrity sha512-VXuvVvZeQCQb5Zgf4HAxc04q5j+WrNAtNh9OwCsCgpKqESMTu3tF/jhZ3xG6T4NZwWl65Bg8KuS2uEvhSfLl0w== +"@typescript-eslint/scope-manager@6.7.2": + version "6.7.2" + resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-6.7.2.tgz#cf59a2095d2f894770c94be489648ad1c78dc689" + integrity sha512-bgi6plgyZjEqapr7u2mhxGR6E8WCzKNUFWNh6fkpVe9+yzRZeYtDTbsIBzKbcxI+r1qVWt6VIoMSNZ4r2A+6Yw== dependencies: - "@typescript-eslint/types" "5.62.0" - "@typescript-eslint/visitor-keys" "5.62.0" + "@typescript-eslint/types" "6.7.2" + "@typescript-eslint/visitor-keys" "6.7.2" -"@typescript-eslint/type-utils@5.62.0": - version "5.62.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/type-utils/-/type-utils-5.62.0.tgz#286f0389c41681376cdad96b309cedd17d70346a" - integrity sha512-xsSQreu+VnfbqQpW5vnCJdq1Z3Q0U31qiWmRhr98ONQmcp/yhiPJFPq8MXiJVLiksmOKSjIldZzkebzHuCGzew== +"@typescript-eslint/type-utils@6.7.2": + version "6.7.2" + resolved "https://registry.yarnpkg.com/@typescript-eslint/type-utils/-/type-utils-6.7.2.tgz#ed921c9db87d72fa2939fee242d700561454f367" + integrity sha512-36F4fOYIROYRl0qj95dYKx6kybddLtsbmPIYNK0OBeXv2j9L5nZ17j9jmfy+bIDHKQgn2EZX+cofsqi8NPATBQ== dependencies: - "@typescript-eslint/typescript-estree" "5.62.0" - "@typescript-eslint/utils" "5.62.0" + "@typescript-eslint/typescript-estree" "6.7.2" + "@typescript-eslint/utils" "6.7.2" debug "^4.3.4" - tsutils "^3.21.0" + ts-api-utils "^1.0.1" "@typescript-eslint/types@5.45.0": version "5.45.0" resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-5.45.0.tgz#794760b9037ee4154c09549ef5a96599621109c5" integrity sha512-QQij+u/vgskA66azc9dCmx+rev79PzX8uDHpsqSjEFtfF2gBUTRCpvYMh2gw2ghkJabNkPlSUCimsyBEQZd1DA== -"@typescript-eslint/types@5.62.0": - version "5.62.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-5.62.0.tgz#258607e60effa309f067608931c3df6fed41fd2f" - integrity sha512-87NVngcbVXUahrRTqIK27gD2t5Cu1yuCXxbLcFtCzZGlfyVWWh8mLHkoxzjsB6DDNnvdL+fW8MiwPEJyGJQDgQ== +"@typescript-eslint/types@6.7.2": + version "6.7.2" + resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-6.7.2.tgz#75a615a6dbeca09cafd102fe7f465da1d8a3c066" + integrity sha512-flJYwMYgnUNDAN9/GAI3l8+wTmvTYdv64fcH8aoJK76Y+1FCZ08RtI5zDerM/FYT5DMkAc+19E4aLmd5KqdFyg== "@typescript-eslint/typescript-estree@5.45.0": version "5.45.0" @@ -970,32 +977,31 @@ semver "^7.3.7" tsutils "^3.21.0" -"@typescript-eslint/typescript-estree@5.62.0": - version "5.62.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-5.62.0.tgz#7d17794b77fabcac615d6a48fb143330d962eb9b" - integrity sha512-CmcQ6uY7b9y694lKdRB8FEel7JbU/40iSAPomu++SjLMntB+2Leay2LO6i8VnJk58MtE9/nQSFIH6jpyRWyYzA== +"@typescript-eslint/typescript-estree@6.7.2": + version "6.7.2" + resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-6.7.2.tgz#ce5883c23b581a5caf878af641e49dd0349238c7" + integrity sha512-kiJKVMLkoSciGyFU0TOY0fRxnp9qq1AzVOHNeN1+B9erKFCJ4Z8WdjAkKQPP+b1pWStGFqezMLltxO+308dJTQ== dependencies: - "@typescript-eslint/types" "5.62.0" - "@typescript-eslint/visitor-keys" "5.62.0" + "@typescript-eslint/types" "6.7.2" + "@typescript-eslint/visitor-keys" "6.7.2" debug "^4.3.4" globby "^11.1.0" is-glob "^4.0.3" - semver "^7.3.7" - tsutils "^3.21.0" - -"@typescript-eslint/utils@5.62.0": - version "5.62.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/utils/-/utils-5.62.0.tgz#141e809c71636e4a75daa39faed2fb5f4b10df86" - integrity sha512-n8oxjeb5aIbPFEtmQxQYOLI0i9n5ySBEY/ZEHHZqKQSFnxio1rv6dthascc9dLuwrL0RC5mPCxB7vnAVGAYWAQ== - dependencies: - "@eslint-community/eslint-utils" "^4.2.0" - "@types/json-schema" "^7.0.9" - "@types/semver" "^7.3.12" - "@typescript-eslint/scope-manager" "5.62.0" - "@typescript-eslint/types" "5.62.0" - "@typescript-eslint/typescript-estree" "5.62.0" - eslint-scope "^5.1.1" - semver "^7.3.7" + semver "^7.5.4" + ts-api-utils "^1.0.1" + +"@typescript-eslint/utils@6.7.2": + version "6.7.2" + resolved "https://registry.yarnpkg.com/@typescript-eslint/utils/-/utils-6.7.2.tgz#b9ef0da6f04932167a9222cb4ac59cb187165ebf" + integrity sha512-ZCcBJug/TS6fXRTsoTkgnsvyWSiXwMNiPzBUani7hDidBdj1779qwM1FIAmpH4lvlOZNF3EScsxxuGifjpLSWQ== + dependencies: + "@eslint-community/eslint-utils" "^4.4.0" + "@types/json-schema" "^7.0.12" + "@types/semver" "^7.5.0" + "@typescript-eslint/scope-manager" "6.7.2" + "@typescript-eslint/types" "6.7.2" + "@typescript-eslint/typescript-estree" "6.7.2" + semver "^7.5.4" "@typescript-eslint/visitor-keys@5.45.0": version "5.45.0" @@ -1005,13 +1011,13 @@ "@typescript-eslint/types" "5.45.0" eslint-visitor-keys "^3.3.0" -"@typescript-eslint/visitor-keys@5.62.0": - version "5.62.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-5.62.0.tgz#2174011917ce582875954ffe2f6912d5931e353e" - integrity sha512-07ny+LHRzQXepkGg6w0mFY41fVUNBrL2Roj/++7V1txKugfjm/Ci/qSND03r2RhlJhJYMcTn9AhhSSqQp0Ysyw== +"@typescript-eslint/visitor-keys@6.7.2": + version "6.7.2" + resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-6.7.2.tgz#4cb2bd786f1f459731b0ad1584c9f73e1c7a4d5c" + integrity sha512-uVw9VIMFBUTz8rIeaUT3fFe8xIUx8r4ywAdlQv1ifH+6acn/XF8Y6rwJ7XNmkNMDrTW+7+vxFFPIF40nJCVsMQ== dependencies: - "@typescript-eslint/types" "5.62.0" - eslint-visitor-keys "^3.3.0" + "@typescript-eslint/types" "6.7.2" + eslint-visitor-keys "^3.4.1" abort-controller@^3.0.0: version "3.0.0" @@ -1136,14 +1142,6 @@ anymatch@^3.0.3: normalize-path "^3.0.0" picomatch "^2.0.4" -anymatch@~3.1.2: - version "3.1.3" - resolved "https://registry.yarnpkg.com/anymatch/-/anymatch-3.1.3.tgz#790c58b19ba1720a84205b57c618d5ad8524973e" - integrity sha512-KMReFUr0B4t+D+OBkjR3KYqvocp2XaSzO55UcB6mgQMd3KbcE+mWTyvVV7D/zsdEbNnV6acZUutkiHQXvTr1Rw== - dependencies: - normalize-path "^3.0.0" - picomatch "^2.0.4" - arg@^4.1.0: version "4.1.3" resolved "https://registry.yarnpkg.com/arg/-/arg-4.1.3.tgz#269fc7ad5b8e42cb63c896d5666017261c144089" @@ -1246,11 +1244,6 @@ base-64@^0.1.0: resolved "https://registry.yarnpkg.com/base-64/-/base-64-0.1.0.tgz#780a99c84e7d600260361511c4877613bf24f6bb" integrity sha512-Y5gU45svrR5tI2Vt/X9GPd3L0HNIKzGu202EjxrXMpuc2V2CiKgemAbUUsqYmZJvPtCXoUKjNZwBJzsNScUbXA== -binary-extensions@^2.0.0: - version "2.2.0" - resolved "https://registry.yarnpkg.com/binary-extensions/-/binary-extensions-2.2.0.tgz#75f502eeaf9ffde42fc98829645be4ea76bd9e2d" - integrity sha512-jDctJ/IVQbZoJykoeHbhXpOlNBqGNcwXJKJog42E5HDPUwQTSdjCHdihjj0DlnheQ7blbT6dHOafNAiS8ooQKA== - brace-expansion@^1.1.7: version "1.1.11" resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-1.1.11.tgz#3c7fcbf529d87226f3d2f52b966ff5271eb441dd" @@ -1266,7 +1259,7 @@ brace-expansion@^2.0.1: dependencies: balanced-match "^1.0.0" -braces@^3.0.2, braces@~3.0.2: +braces@^3.0.2: version "3.0.2" resolved "https://registry.yarnpkg.com/braces/-/braces-3.0.2.tgz#3454e1a462ee8d599e236df336cd9ea4f8afe107" integrity sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A== @@ -1375,21 +1368,6 @@ charenc@0.0.2: resolved "https://registry.yarnpkg.com/charenc/-/charenc-0.0.2.tgz#c0a1d2f3a7092e03774bfa83f14c0fc5790a8667" integrity sha512-yrLQ/yVUFXkzg7EDQsPieE/53+0RlaWTs+wBrvW36cyilJ2SaDWfl4Yj7MtLTXleV9uEKefbAGUPv2/iWSooRA== -chokidar@^3.5.3: - version "3.5.3" - resolved "https://registry.yarnpkg.com/chokidar/-/chokidar-3.5.3.tgz#1cf37c8707b932bd1af1ae22c0432e2acd1903bd" - integrity sha512-Dr3sfKRP6oTcjf2JmUmFJfeVMvXBdegxB0iVQ5eb2V10uFJUCAS8OByZdVAyVb8xXNz3GjjTgj9kLWsZTqE6kw== - dependencies: - anymatch "~3.1.2" - braces "~3.0.2" - glob-parent "~5.1.2" - is-binary-path "~2.1.0" - is-glob "~4.0.1" - normalize-path "~3.0.0" - readdirp "~3.6.0" - optionalDependencies: - fsevents "~2.3.2" - ci-info@3.3.0, ci-info@^3.2.0: version "3.3.0" resolved "https://registry.yarnpkg.com/ci-info/-/ci-info-3.3.0.tgz#b4ed1fb6818dea4803a55c623041f9165d2066b2" @@ -1492,11 +1470,6 @@ commander@^2.19.0: resolved "https://registry.yarnpkg.com/commander/-/commander-2.20.3.tgz#fd485e84c03eb4881c20722ba48035e8531aeb33" integrity sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ== -commander@^9.0.0: - version "9.5.0" - resolved "https://registry.yarnpkg.com/commander/-/commander-9.5.0.tgz#bc08d1eb5cedf7ccb797a96199d41c7bc3e60d30" - integrity sha512-KRs7WVDKg86PWiuAqhDrAQnTXZKraVcCc6vFdL14qrZ/DcWwuRo7VoiYXalXO7S5GKpqYiVEwCbgFDfxNHKJBQ== - commondir@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/commondir/-/commondir-1.0.1.tgz#ddd800da0c66127393cca5950ea968a3aaf1253b" @@ -1733,14 +1706,6 @@ eslint-rule-composer@^0.3.0: resolved "https://registry.yarnpkg.com/eslint-rule-composer/-/eslint-rule-composer-0.3.0.tgz#79320c927b0c5c0d3d3d2b76c8b4a488f25bbaf9" integrity sha512-bt+Sh8CtDmn2OajxvNO+BX7Wn4CIWMpTRm3MaiKPCQcnnlm0CS2mhui6QaoeQugs+3Kj2ESKEEGJUdVafwhiCg== -eslint-scope@^5.1.1: - version "5.1.1" - resolved "https://registry.yarnpkg.com/eslint-scope/-/eslint-scope-5.1.1.tgz#e786e59a66cb92b3f6c1fb0d508aab174848f48c" - integrity sha512-2NxwbF/hZ0KpepYN0cNbo+FN6XoK7GaHlQhgx/hIZl6Va0bF45RQOOwhLIy8lQDbuCiadSLCBnH2CFYquit5bw== - dependencies: - esrecurse "^4.3.0" - estraverse "^4.1.1" - eslint-scope@^7.2.2: version "7.2.2" resolved "https://registry.yarnpkg.com/eslint-scope/-/eslint-scope-7.2.2.tgz#deb4f92563390f32006894af62a22dba1c46423f" @@ -1749,21 +1714,26 @@ eslint-scope@^7.2.2: esrecurse "^4.3.0" estraverse "^5.2.0" -eslint-visitor-keys@^3.3.0, eslint-visitor-keys@^3.4.1, eslint-visitor-keys@^3.4.2: +eslint-visitor-keys@^3.3.0, eslint-visitor-keys@^3.4.1: version "3.4.2" resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-3.4.2.tgz#8c2095440eca8c933bedcadf16fefa44dbe9ba5f" integrity sha512-8drBzUEyZ2llkpCA67iYrgEssKDUu68V8ChqqOfFupIaG/LCVPUT+CoGJpT77zJprs4T/W7p07LP7zAIMuweVw== -eslint@^8.22.0: - version "8.46.0" - resolved "https://registry.yarnpkg.com/eslint/-/eslint-8.46.0.tgz#a06a0ff6974e53e643acc42d1dcf2e7f797b3552" - integrity sha512-cIO74PvbW0qU8e0mIvk5IV3ToWdCq5FYG6gWPHHkx6gNdjlbAYvtfHmlCMXxjcoVaIdwy/IAt3+mDkZkfvb2Dg== +eslint-visitor-keys@^3.4.3: + version "3.4.3" + resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-3.4.3.tgz#0cd72fe8550e3c2eae156a96a4dddcd1c8ac5800" + integrity sha512-wpc+LXeiyiisxPlEkUzU6svyS1frIO3Mgxj1fdy7Pm8Ygzguax2N3Fa/D/ag1WqbOprdI+uY6wMUl8/a2G+iag== + +eslint@^8.49.0: + version "8.49.0" + resolved "https://registry.yarnpkg.com/eslint/-/eslint-8.49.0.tgz#09d80a89bdb4edee2efcf6964623af1054bf6d42" + integrity sha512-jw03ENfm6VJI0jA9U+8H5zfl5b+FvuU3YYvZRdZHOlU2ggJkxrlkJH4HcDrZpj6YwD8kuYqvQM8LyesoazrSOQ== dependencies: "@eslint-community/eslint-utils" "^4.2.0" "@eslint-community/regexpp" "^4.6.1" - "@eslint/eslintrc" "^2.1.1" - "@eslint/js" "^8.46.0" - "@humanwhocodes/config-array" "^0.11.10" + "@eslint/eslintrc" "^2.1.2" + "@eslint/js" "8.49.0" + "@humanwhocodes/config-array" "^0.11.11" "@humanwhocodes/module-importer" "^1.0.1" "@nodelib/fs.walk" "^1.2.8" ajv "^6.12.4" @@ -1773,7 +1743,7 @@ eslint@^8.22.0: doctrine "^3.0.0" escape-string-regexp "^4.0.0" eslint-scope "^7.2.2" - eslint-visitor-keys "^3.4.2" + eslint-visitor-keys "^3.4.3" espree "^9.6.1" esquery "^1.4.2" esutils "^2.0.2" @@ -1834,11 +1804,6 @@ esrecurse@^4.3.0: dependencies: estraverse "^5.2.0" -estraverse@^4.1.1: - version "4.3.0" - resolved "https://registry.yarnpkg.com/estraverse/-/estraverse-4.3.0.tgz#398ad3f3c5a24948be7725e83d11a7de28cdbd1d" - integrity sha512-39nnKffWz8xN1BU/2c79n9nB9HDzo0niYUqx6xyqUnyoAnQyyWpOTdZEeiCch8BBu515t4wp9ZmgVfVhn9EBpw== - estraverse@^5.1.0, estraverse@^5.2.0: version "5.3.0" resolved "https://registry.yarnpkg.com/estraverse/-/estraverse-5.3.0.tgz#2eea5290702f26ab8fe5370370ff86c965d21123" @@ -2040,7 +2005,7 @@ fs.realpath@^1.0.0: resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f" integrity sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw== -fsevents@^2.3.2, fsevents@~2.3.2: +fsevents@^2.3.2: version "2.3.2" resolved "https://registry.yarnpkg.com/fsevents/-/fsevents-2.3.2.tgz#8a526f78b8fdf4623b709e0b975c52c24c02fd1a" integrity sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA== @@ -2075,7 +2040,7 @@ get-stream@^6.0.0: resolved "https://registry.yarnpkg.com/get-stream/-/get-stream-6.0.1.tgz#a262d8eef67aced57c2852ad6167526a43cbf7b7" integrity sha512-ts6Wi+2j3jQjqi70w5AlN8DFnkSwC+MqmxEzdEALB2qXZYV3X/b1CTfgPLGJNMeAWxdPfU8FO1ms3NUfaHCPYg== -glob-parent@^5.1.2, glob-parent@~5.1.2: +glob-parent@^5.1.2: version "5.1.2" resolved "https://registry.yarnpkg.com/glob-parent/-/glob-parent-5.1.2.tgz#869832c58034fe68a4093c17dc15e8340d8401c4" integrity sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow== @@ -2125,7 +2090,7 @@ globals@^13.19.0: dependencies: type-fest "^0.20.2" -globby@^11.0.4, globby@^11.1.0: +globby@^11.1.0: version "11.1.0" resolved "https://registry.yarnpkg.com/globby/-/globby-11.1.0.tgz#bd4be98bb042f83d796f7e3811991fbe82a0d34b" integrity sha512-jhIXaOzy1sb8IyocaruWSn1TjmnBVs8Ayhcy83rmxNJ8q2uWKCAj3CnJY+KpGSXCueAPc0i05kVvVKtP1t9S3g== @@ -2211,7 +2176,7 @@ ignore@5.2.0: resolved "https://registry.yarnpkg.com/ignore/-/ignore-5.2.0.tgz#6d3bac8fa7fe0d45d9f9be7bac2fc279577e345a" integrity sha512-CmxgYGiEPCLhfLnpPp1MoRmifwEIOgjcHXxOBjv7mY96c+eWScsOP9c112ZyLdWHi0FxHjI+4uVhKYp/gcdRmQ== -ignore@^5.2.0: +ignore@^5.2.0, ignore@^5.2.4: version "5.2.4" resolved "https://registry.yarnpkg.com/ignore/-/ignore-5.2.4.tgz#a291c0c6178ff1b960befe47fcdec301674a6324" integrity sha512-MAb38BcSbH0eHNBxn7ql2NH/kX33OkB3lZ1BNdh7ENeRChHTYsTvWrMubiIAMNS2llXEEgZ1MUOBtXChP3kaFQ== @@ -2278,13 +2243,6 @@ is-arrayish@^0.2.1: resolved "https://registry.yarnpkg.com/is-arrayish/-/is-arrayish-0.2.1.tgz#77c99840527aa8ecb1a8ba697b80645a7a926a9d" integrity sha1-d8mYQFJ6qOyxqLppe4BkWnqSap0= -is-binary-path@~2.1.0: - version "2.1.0" - resolved "https://registry.yarnpkg.com/is-binary-path/-/is-binary-path-2.1.0.tgz#ea1f7f3b80f064236e83470f86c09c254fb45b09" - integrity sha512-ZMERYes6pDydyuGidse7OsHxtbI7WVeUEozgR/g7rd0xUimYNlvZRE/K2MgZTjWy725IfelLeVcEM97mmtRGXw== - dependencies: - binary-extensions "^2.0.0" - is-buffer@^2.0.0: version "2.0.5" resolved "https://registry.yarnpkg.com/is-buffer/-/is-buffer-2.0.5.tgz#ebc252e400d22ff8d77fa09888821a24a658c191" @@ -2334,7 +2292,7 @@ is-generator-fn@^2.0.0: resolved "https://registry.yarnpkg.com/is-generator-fn/-/is-generator-fn-2.1.0.tgz#7d140adc389aaf3011a8f2a2a4cfa6faadffb118" integrity sha512-cTIB4yPYL/Grw0EaSzASzg6bBy9gqCofvWN8okThAYIxKJZC+udlRAmGbM0XLeniEJSs8uEgHPGuHSe1XsOLSQ== -is-glob@^4.0.0, is-glob@^4.0.1, is-glob@^4.0.3, is-glob@~4.0.1: +is-glob@^4.0.0, is-glob@^4.0.1, is-glob@^4.0.3: version "4.0.3" resolved "https://registry.yarnpkg.com/is-glob/-/is-glob-4.0.3.tgz#64f61e42cbbb2eec2071a9dac0b28ba1e65d5084" integrity sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg== @@ -3050,21 +3008,11 @@ ms@^2.0.0: resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.3.tgz#574c8138ce1d2b5861f0b44579dbadd60c6615b2" integrity sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA== -mylas@^2.1.9: - version "2.1.13" - resolved "https://registry.yarnpkg.com/mylas/-/mylas-2.1.13.tgz#1e23b37d58fdcc76e15d8a5ed23f9ae9fc0cbdf4" - integrity sha512-+MrqnJRtxdF+xngFfUUkIMQrUUL0KsxbADUkn23Z/4ibGg192Q+z+CQyiYwvWTsYjJygmMR8+w3ZDa98Zh6ESg== - n-readlines@1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/n-readlines/-/n-readlines-1.0.1.tgz#bbb7364d38bc31a170a199f986fcacfa76b95f6e" integrity sha512-z4SyAIVgMy7CkgsoNw7YVz40v0g4+WWvvqy8+ZdHrCtgevcEO758WQyrYcw3XPxcLxF+//RszTz/rO48nzD0wQ== -natural-compare-lite@^1.4.0: - version "1.4.0" - resolved "https://registry.yarnpkg.com/natural-compare-lite/-/natural-compare-lite-1.4.0.tgz#17b09581988979fddafe0201e931ba933c96cbb4" - integrity sha512-Tj+HTDSJJKaZnfiuw+iaF9skdPpTo2GtEly5JHnWV/hfv2Qj/9RKsGISQtLh2ox3l5EAGw487hnBee0sIJ6v2g== - natural-compare@^1.4.0: version "1.4.0" resolved "https://registry.yarnpkg.com/natural-compare/-/natural-compare-1.4.0.tgz#4abebfeed7541f2c27acfb29bdbbd15c8d5ba4f7" @@ -3092,7 +3040,7 @@ node-releases@^2.0.3: resolved "https://registry.yarnpkg.com/node-releases/-/node-releases-2.0.4.tgz#f38252370c43854dc48aa431c766c6c398f40476" integrity sha512-gbMzqQtTtDz/00jQzZ21PQzdI9PyLYqUSvD0p3naOhX4odFji0ZxYdnVwPTxmSwkmxhcFImpozceidSG+AgoPQ== -normalize-path@^3.0.0, normalize-path@~3.0.0: +normalize-path@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/normalize-path/-/normalize-path-3.0.0.tgz#0dcd69ff23a1c9b11fd0978316644a0388216a65" integrity sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA== @@ -3260,7 +3208,7 @@ picocolors@^1.0.0: resolved "https://registry.yarnpkg.com/picocolors/-/picocolors-1.0.0.tgz#cb5bdc74ff3f51892236eaf79d68bc44564ab81c" integrity sha512-1fygroTLlHu66zi26VoTDv8yRgm0Fccecssto+MhsZ0D/DGW2sm8E8AjW7NU5VVTRt5GxbeZ5qBuJr+HyLYkjQ== -picomatch@^2.0.4, picomatch@^2.2.1, picomatch@^2.2.3, picomatch@^2.3.1: +picomatch@^2.0.4, picomatch@^2.2.3, picomatch@^2.3.1: version "2.3.1" resolved "https://registry.yarnpkg.com/picomatch/-/picomatch-2.3.1.tgz#3ba3833733646d9d3e4995946c1365a67fb07a42" integrity sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA== @@ -3284,13 +3232,6 @@ please-upgrade-node@3.2.0: dependencies: semver-compare "^1.0.0" -plimit-lit@^1.2.6: - version "1.5.0" - resolved "https://registry.yarnpkg.com/plimit-lit/-/plimit-lit-1.5.0.tgz#f66df8a7041de1e965c4f1c0697ab486968a92a5" - integrity sha512-Eb/MqCb1Iv/ok4m1FqIXqvUKPISufcjZ605hl3KM/n8GaX8zfhtgdLwZU3vKjuHGh2O9Rjog/bHTq8ofIShdng== - dependencies: - queue-lit "^1.5.0" - postcss-less@3.1.4: version "3.1.4" resolved "https://registry.yarnpkg.com/postcss-less/-/postcss-less-3.1.4.tgz#369f58642b5928ef898ffbc1a6e93c958304c5ad" @@ -3455,11 +3396,6 @@ pure-rand@^6.0.0: resolved "https://registry.yarnpkg.com/pure-rand/-/pure-rand-6.0.2.tgz#a9c2ddcae9b68d736a8163036f088a2781c8b306" integrity sha512-6Yg0ekpKICSjPswYOuC5sku/TSWaRYlA0qsXqJgM/d/4pLPHPuTxK7Nbf7jFKzAeedUhR8C7K9Uv63FBsSo8xQ== -queue-lit@^1.5.0: - version "1.5.0" - resolved "https://registry.yarnpkg.com/queue-lit/-/queue-lit-1.5.0.tgz#8197fdafda1edd615c8a0fc14c48353626e5160a" - integrity sha512-IslToJ4eiCEE9xwMzq3viOO5nH8sUWUCwoElrhNMozzr9IIt2qqvB4I+uHu/zJTQVqc9R5DFwok4ijNK1pU3fA== - queue-microtask@^1.2.2: version "1.2.3" resolved "https://registry.yarnpkg.com/queue-microtask/-/queue-microtask-1.2.3.tgz#4929228bbc724dfac43e0efb058caf7b6cfb6243" @@ -3479,13 +3415,6 @@ readable-stream@^3.4.0: string_decoder "^1.1.1" util-deprecate "^1.0.1" -readdirp@~3.6.0: - version "3.6.0" - resolved "https://registry.yarnpkg.com/readdirp/-/readdirp-3.6.0.tgz#74a370bd857116e245b29cc97340cd431a02a6c7" - integrity sha512-hOS089on8RduqdbhvQ5Z37A0ESjsqz6qnRcffsMU3495FuTdqSm+7bhJ29JvIOsBDEEnan5DPu9t3To9VRlMzA== - dependencies: - picomatch "^2.2.1" - regexp-util@1.2.2, regexp-util@^1.2.0, regexp-util@^1.2.1: version "1.2.2" resolved "https://registry.yarnpkg.com/regexp-util/-/regexp-util-1.2.2.tgz#5cf599134921eb0d776e41d41e9c0da33f0fa2fc" @@ -3631,7 +3560,7 @@ semver@^6.0.0, semver@^6.3.0: resolved "https://registry.yarnpkg.com/semver/-/semver-6.3.0.tgz#ee0a64c8af5e8ceea67687b133761e1becbd1d3d" integrity sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw== -semver@^7.3.7: +semver@^7.3.7, semver@^7.5.4: version "7.5.4" resolved "https://registry.yarnpkg.com/semver/-/semver-7.5.4.tgz#483986ec4ed38e1c6c48c34894a9182dbff68a6e" integrity sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA== @@ -3861,6 +3790,11 @@ trough@^1.0.0: resolved "https://registry.yarnpkg.com/trough/-/trough-1.0.5.tgz#b8b639cefad7d0bb2abd37d433ff8293efa5f406" integrity sha512-rvuRbTarPXmMb79SmzEp8aqXNKcK+y0XaB298IXueQ8I2PsrATcPBCSPyK/dDNa2iWOhKlfNnOjdAOTBU/nkFA== +ts-api-utils@^1.0.1: + version "1.0.3" + resolved "https://registry.yarnpkg.com/ts-api-utils/-/ts-api-utils-1.0.3.tgz#f12c1c781d04427313dbac808f453f050e54a331" + integrity sha512-wNMeqtMz5NtwpT/UZGY5alT+VoKdSsOOP/kqHFcUW1P/VRhH2wJ48+DN2WwUliNbQ976ETwDL0Ifd2VVvgonvg== + ts-jest@^29.1.0: version "29.1.0" resolved "https://registry.yarnpkg.com/ts-jest/-/ts-jest-29.1.0.tgz#4a9db4104a49b76d2b368ea775b6c9535c603891" @@ -3902,18 +3836,6 @@ ts-node@^10.5.0: v8-compile-cache-lib "^3.0.0" yn "3.1.1" -tsc-alias@^1.8.6: - version "1.8.6" - resolved "https://registry.yarnpkg.com/tsc-alias/-/tsc-alias-1.8.6.tgz#28300ed398e90b1c600548ed956f58dfbecc1589" - integrity sha512-vq+i6VpE83IeMsSJVcFN03ZBofADhr8/gIJXjxpbnTRfN/MFXy0+SBaKG2o7p95QqXBGkeG98HYz3IkOOveFbg== - dependencies: - chokidar "^3.5.3" - commander "^9.0.0" - globby "^11.0.4" - mylas "^2.1.9" - normalize-path "^3.0.0" - plimit-lit "^1.2.6" - tsc-multi@^1.1.0: version "1.1.0" resolved "https://registry.yarnpkg.com/tsc-multi/-/tsc-multi-1.1.0.tgz#0e2b03c0ed0ac58ecb556f11709441102d202680"