diff --git a/.eslintrc.js b/.eslintrc.js index ed44ebc..57a44dd 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/index.js b/index.js index eaa2f50..85dc4ac 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 @@ -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"' ); diff --git a/jest.config.js b/jest.config.js index 9ea9e36..36d66b5 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/jsconfig.json b/jsconfig.json new file mode 100644 index 0000000..6ea5468 --- /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/lib/predictions.js b/lib/predictions.js index b688fee..d654a73 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 @@ -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 }); } diff --git a/package-lock.json b/package-lock.json index fedbb60..4b38dfd 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 c12e3bc..eb54006 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", diff --git a/tsconfig.json b/tsconfig.json index 97cb33b..073eb38 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,3 +1,9 @@ { - "extends": "@tsconfig/recommended/tsconfig.json" + "compilerOptions": { + "esModuleInterop": true + }, + "exclude": [ + "node_modules", + "**/node_modules/*" + ] }