From da182dfac43fbd7bca1437931dc07d601affe587 Mon Sep 17 00:00:00 2001 From: Mattt Zmuda Date: Tue, 11 Apr 2023 14:58:13 -0700 Subject: [PATCH 1/6] Replace tsconfig.json with jsconfig.json --- .eslintrc.js | 2 +- jsconfig.json | 15 +++++++++++++++ tsconfig.json | 3 --- 3 files changed, 16 insertions(+), 4 deletions(-) create mode 100644 jsconfig.json delete mode 100644 tsconfig.json diff --git a/.eslintrc.js b/.eslintrc.js index ed44ebca..57a44ddb 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -13,7 +13,7 @@ module.exports = { overrides: [], parserOptions: { ecmaVersion: 'latest', - project: './tsconfig.json', + project: './jsconfig.json', }, plugins: ['jest', 'jsdoc'], rules: { diff --git a/jsconfig.json b/jsconfig.json new file mode 100644 index 00000000..6ea54689 --- /dev/null +++ b/jsconfig.json @@ -0,0 +1,15 @@ +{ + "compilerOptions": { + "checkJs": true, + "module": "ESNext", + "moduleResolution": "Node", + "target": "ES2020", + "resolveJsonModule": true, + "strictNullChecks": true, + "strictFunctionTypes": true + }, + "exclude": [ + "node_modules", + "**/node_modules/*" + ] +} diff --git a/tsconfig.json b/tsconfig.json deleted file mode 100644 index 97cb33b3..00000000 --- a/tsconfig.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "extends": "@tsconfig/recommended/tsconfig.json" -} From ea6761cd011df6e57db86f383d66a4cda9db2e72 Mon Sep 17 00:00:00 2001 From: Mattt Zmuda Date: Tue, 11 Apr 2023 14:59:20 -0700 Subject: [PATCH 2/6] Remove @tsconfig/recommended dev dependency --- package-lock.json | 7 ------- package.json | 1 - 2 files changed, 8 deletions(-) diff --git a/package-lock.json b/package-lock.json index fedbb60e..4b38dfdf 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,6 @@ "version": "0.9.2", "license": "Apache-2.0", "devDependencies": { - "@tsconfig/recommended": "^1.0.2", "@types/jest": "^29.5.0", "@typescript-eslint/eslint-plugin": "^5.56.0", "cross-fetch": "^3.1.5", @@ -1234,12 +1233,6 @@ "@sinonjs/commons": "^2.0.0" } }, - "node_modules/@tsconfig/recommended": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/@tsconfig/recommended/-/recommended-1.0.2.tgz", - "integrity": "sha512-dbHBtbWBOjq0/otpopAE02NT2Cm05Qe2JsEKeCf/wjSYbI2hz8nCqnpnOJWHATgjDz4fd3dchs3Wy1gQGjfN6w==", - "dev": true - }, "node_modules/@types/babel__core": { "version": "7.20.0", "resolved": "https://registry.npmjs.org/@types/babel__core/-/babel__core-7.20.0.tgz", diff --git a/package.json b/package.json index c12e3bca..eb540063 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,6 @@ "test": "jest" }, "devDependencies": { - "@tsconfig/recommended": "^1.0.2", "@types/jest": "^29.5.0", "@typescript-eslint/eslint-plugin": "^5.56.0", "cross-fetch": "^3.1.5", From 70d91de1b625ff10999f66d962b0d1c8463b6f7d Mon Sep 17 00:00:00 2001 From: Mattt Zmuda Date: Tue, 11 Apr 2023 14:59:51 -0700 Subject: [PATCH 3/6] Fix Qualified name 'options.wait.maxAttempts' is not allowed without a leading '@param {object} options.wait'.ts(8032) --- index.js | 2 +- lib/predictions.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index eaa2f506..4b5df469 100644 --- a/index.js +++ b/index.js @@ -70,7 +70,7 @@ class Replicate { * @param {string} identifier - Required. The model version identifier in the format "{owner}/{name}:{version}" * @param {object} options * @param {object} options.input - Required. An object with the model inputs - * @param {boolean|object} [options.wait] - Whether to wait for the prediction to finish. Defaults to false + * @param {object} [options.wait] - Whether to wait for the prediction to finish. Defaults to false * @param {number} [options.wait.interval] - Polling interval in milliseconds. Defaults to 250 * @param {number} [options.wait.maxAttempts] - Maximum number of polling attempts. Defaults to no limit * @param {string} [options.webhook] - An HTTPS URL for receiving a webhook when the prediction has new output diff --git a/lib/predictions.js b/lib/predictions.js index b688feeb..d1276281 100644 --- a/lib/predictions.js +++ b/lib/predictions.js @@ -4,7 +4,7 @@ * @param {object} options * @param {string} options.version - Required. The model version * @param {object} options.input - Required. An object with the model inputs - * @param {boolean|object} [options.wait] - Whether to wait for the prediction to finish. Defaults to false + * @param {object} [options.wait] - Whether to wait for the prediction to finish. Defaults to false * @param {number} [options.wait.interval] - Polling interval in milliseconds. Defaults to 250 * @param {number} [options.wait.maxAttempts] - Maximum number of polling attempts. Defaults to no limit * @param {string} [options.webhook] - An HTTPS URL for receiving a webhook when the prediction has new output From 3b6b8cb705b22b9569f1554326b0ac295569a343 Mon Sep 17 00:00:00 2001 From: Mattt Zmuda Date: Tue, 11 Apr 2023 15:00:05 -0700 Subject: [PATCH 4/6] Fix Property 'interval' does not exist on type '{ interval?: number | undefined; maxAttempts?: number | undefined; } | undefined'.ts(2339) --- lib/predictions.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/predictions.js b/lib/predictions.js index d1276281..d654a734 100644 --- a/lib/predictions.js +++ b/lib/predictions.js @@ -20,7 +20,7 @@ async function createPrediction(options) { }); if (wait) { - const { maxAttempts, interval } = options.wait; + const { maxAttempts, interval } = wait; return this.wait(await prediction, { maxAttempts, interval }); } From 087ecae00b4ebbd8ba15b5408653aadbbe3afd51 Mon Sep 17 00:00:00 2001 From: Mattt Zmuda Date: Tue, 11 Apr 2023 15:01:33 -0700 Subject: [PATCH 5/6] Fix Property 'version' does not exist on type '{ [key: string]: string; } | undefined'.ts(2339) --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 4b5df469..85dc4acb 100644 --- a/index.js +++ b/index.js @@ -83,7 +83,7 @@ class Replicate { /^(?[a-zA-Z0-9-_]+?)\/(?[a-zA-Z0-9-_]+?):(?[0-9a-fA-F]+)$/; const match = identifier.match(pattern); - if (!match) { + if (!match || !match.groups) { throw new Error( 'Invalid version. It must be in the format "owner/name:version"' ); From ea85ab8d29b8ec68af6c254975de4606cbfe8114 Mon Sep 17 00:00:00 2001 From: Mattt Zmuda Date: Tue, 11 Apr 2023 15:17:33 -0700 Subject: [PATCH 6/6] Add tsconfig.json and configure with ts-jest --- jest.config.js | 5 +++++ tsconfig.json | 9 +++++++++ 2 files changed, 14 insertions(+) create mode 100644 tsconfig.json diff --git a/jest.config.js b/jest.config.js index 9ea9e367..36d66b5b 100644 --- a/jest.config.js +++ b/jest.config.js @@ -3,4 +3,9 @@ module.exports = { preset: 'ts-jest', testEnvironment: 'node', + transform: { + '^.+\\.ts?$': ['ts-jest', { + tsconfig: 'tsconfig.json' + }], + }, }; diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 00000000..073eb382 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,9 @@ +{ + "compilerOptions": { + "esModuleInterop": true + }, + "exclude": [ + "node_modules", + "**/node_modules/*" + ] +}