diff --git a/.changeset/smooth-years-work.md b/.changeset/smooth-years-work.md new file mode 100644 index 000000000..6a32288c7 --- /dev/null +++ b/.changeset/smooth-years-work.md @@ -0,0 +1,5 @@ +--- +'@xata.io/cli': patch +--- + +Add version checks for SDK and CLI to be in sync diff --git a/cli/package-lock.json b/cli/package-lock.json index 341ae3310..d1f8678f0 100644 --- a/cli/package-lock.json +++ b/cli/package-lock.json @@ -1,12 +1,12 @@ { "name": "@xata.io/cli", - "version": "0.11.0", + "version": "0.11.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@xata.io/cli", - "version": "0.11.0", + "version": "0.11.1", "license": "Apache-2.0", "dependencies": { "@babel/core": "^7.20.2", @@ -23,6 +23,9 @@ "@rollup/plugin-virtual": "^3.0.1", "@types/ini": "^1.3.31", "@types/prompts": "^2.4.1", + "@xata.io/client": "^0.21.2", + "@xata.io/codegen": "^0.21.0", + "@xata.io/importer": "^0.3.2", "ansi-regex": "^6.0.1", "babel-plugin-module-extension-resolver": "^1.0.0-rc.2", "chalk": "^5.1.2", @@ -46,6 +49,7 @@ "rollup-plugin-esbuild": "^5.0.0", "rollup-plugin-hypothetical": "^2.1.1", "rollup-plugin-virtual-fs": "^4.0.1-alpha.0", + "semver": "^7.3.8", "text-table": "^0.2.0", "tmp": "^0.2.1", "which": "^3.0.0", @@ -1969,6 +1973,36 @@ "node": ">= 6" } }, + "node_modules/@ts-morph/common": { + "version": "0.17.0", + "resolved": "https://registry.npmjs.org/@ts-morph/common/-/common-0.17.0.tgz", + "integrity": "sha512-RMSSvSfs9kb0VzkvQ2NWobwnj7TxCA9vI/IjR9bDHqgAyVbu2T0DN4wiKVqomyDWqO7dPr/tErSfq7urQ1Q37g==", + "dependencies": { + "fast-glob": "^3.2.11", + "minimatch": "^5.1.0", + "mkdirp": "^1.0.4", + "path-browserify": "^1.0.1" + } + }, + "node_modules/@ts-morph/common/node_modules/brace-expansion": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz", + "integrity": "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==", + "dependencies": { + "balanced-match": "^1.0.0" + } + }, + "node_modules/@ts-morph/common/node_modules/minimatch": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-5.1.0.tgz", + "integrity": "sha512-9TPBGGak4nHfGZsPBohm9AWg6NoT7QTCehS3BIJABslyZbzxfV78QM2Y6+i741OPZIafFAaiiEMh5OyIrJPgtg==", + "dependencies": { + "brace-expansion": "^2.0.1" + }, + "engines": { + "node": ">=10" + } + }, "node_modules/@tsconfig/node10": { "version": "1.0.8", "dev": true, @@ -2283,6 +2317,37 @@ "url": "https://opencollective.com/typescript-eslint" } }, + "node_modules/@xata.io/client": { + "version": "0.21.2", + "resolved": "https://registry.npmjs.org/@xata.io/client/-/client-0.21.2.tgz", + "integrity": "sha512-+ZoAgGGy6+In6HDjqSRCzxKcsodFZDd6stGgvtpATt+bUyL8glkk61EYh3iKKrlWBtfG5lZPK9LEQcVEdf6icg==", + "peerDependencies": { + "typescript": ">=4.5" + } + }, + "node_modules/@xata.io/codegen": { + "version": "0.21.0", + "resolved": "https://registry.npmjs.org/@xata.io/codegen/-/codegen-0.21.0.tgz", + "integrity": "sha512-XxfQ9/+gVwjXFeFWSzJ83SEi/VkIf87kp9m+2cg/F3BDZMqwfmXPvEYGjXloJzomdE3uOKK1Tln5ycTs2+Dh7w==", + "dependencies": { + "case": "^1.6.3", + "prettier": "^2.7.1", + "ts-morph": "^16.0.0", + "typescript": "^4.8.4", + "zod": "^3.19.1" + } + }, + "node_modules/@xata.io/importer": { + "version": "0.3.2", + "resolved": "https://registry.npmjs.org/@xata.io/importer/-/importer-0.3.2.tgz", + "integrity": "sha512-Y++eUgQXbJZYsauPsFN4N0nGIGrfGorzn0zzMoaOztMjnBu4GsQdxEBYl7X8OezUipHI8NRYn0cg64BjUsLSDg==", + "dependencies": { + "@xata.io/client": "^0.21.0", + "camelcase": "^7.0.0", + "csvtojson": "^2.0.10", + "transliteration": "^2.3.5" + } + }, "node_modules/abbrev": { "version": "1.1.1", "dev": true, @@ -7612,6 +7677,11 @@ "ieee754": "^1.1.13" } }, + "node_modules/bluebird": { + "version": "3.7.2", + "resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.7.2.tgz", + "integrity": "sha512-XpNj6GDQzdfW+r2Wnn7xiSAd7TM3jzkxGXBGTtWKuSXv1xUV+azxAm8jdWZN06QTQk+2N2XB9jRDkvbmQmcRtg==" + }, "node_modules/brace-expansion": { "version": "1.1.11", "license": "MIT", @@ -7742,6 +7812,17 @@ "node": ">=6" } }, + "node_modules/camelcase": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-7.0.0.tgz", + "integrity": "sha512-JToIvOmz6nhGsUhAYScbo2d6Py5wojjNfoxoc2mEVLUdJ70gJK2gnd+ABY1Tc3sVMyK7QDPtN0T/XdlCQWITyQ==", + "engines": { + "node": ">=14.16" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/caniuse-lite": { "version": "1.0.30001431", "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001431.tgz", @@ -7768,6 +7849,14 @@ "cdl": "bin/cdl.js" } }, + "node_modules/case": { + "version": "1.6.3", + "resolved": "https://registry.npmjs.org/case/-/case-1.6.3.tgz", + "integrity": "sha512-mzDSXIPaFwVDvZAHqZ9VlbyF4yyXRuX6IvB06WvPYkqJVO24kX1PPhv9bfpKNFZyxYFmmgo03HUiD8iklmJYRQ==", + "engines": { + "node": ">= 0.8.0" + } + }, "node_modules/chalk": { "version": "5.1.2", "resolved": "https://registry.npmjs.org/chalk/-/chalk-5.1.2.tgz", @@ -7912,7 +8001,6 @@ }, "node_modules/cliui": { "version": "7.0.4", - "dev": true, "license": "ISC", "dependencies": { "string-width": "^4.2.0", @@ -7984,6 +8072,11 @@ "node": "^12.13.0 || ^14.15.0 || >=16.0.0" } }, + "node_modules/code-block-writer": { + "version": "11.0.3", + "resolved": "https://registry.npmjs.org/code-block-writer/-/code-block-writer-11.0.3.tgz", + "integrity": "sha512-NiujjUFB4SwScJq2bwbYUtXbZhBSlY6vYzm++3Q6oC+U+injTqfPYFK8wS9COOmb2lueqp0ZRB4nK1VYeHgNyw==" + }, "node_modules/code-point-at": { "version": "1.1.0", "dev": true, @@ -8206,6 +8299,33 @@ "node": ">= 8" } }, + "node_modules/csvtojson": { + "version": "2.0.10", + "resolved": "https://registry.npmjs.org/csvtojson/-/csvtojson-2.0.10.tgz", + "integrity": "sha512-lUWFxGKyhraKCW8Qghz6Z0f2l/PqB1W3AO0HKJzGIQ5JRSlR651ekJDiGJbBT4sRNNv5ddnSGVEnsxP9XRCVpQ==", + "dependencies": { + "bluebird": "^3.5.1", + "lodash": "^4.17.3", + "strip-bom": "^2.0.0" + }, + "bin": { + "csvtojson": "bin/csvtojson" + }, + "engines": { + "node": ">=4.0.0" + } + }, + "node_modules/csvtojson/node_modules/strip-bom": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/strip-bom/-/strip-bom-2.0.0.tgz", + "integrity": "sha512-kwrX1y7czp1E69n2ajbG65mIo9dqvJ+8aBQXOGVxqwvNbsXdFM6Lq37dLAY3mknUwru8CfcCbfOLL/gMo+fi3g==", + "dependencies": { + "is-utf8": "^0.2.0" + }, + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/dargs": { "version": "7.0.0", "dev": true, @@ -10131,7 +10251,6 @@ }, "node_modules/get-caller-file": { "version": "2.0.5", - "dev": true, "license": "ISC", "engines": { "node": "6.* || 8.* || >= 10.*" @@ -10753,7 +10872,6 @@ }, "node_modules/is-utf8": { "version": "0.2.1", - "dev": true, "license": "MIT" }, "node_modules/is-wsl": { @@ -11412,7 +11530,6 @@ }, "node_modules/mkdirp": { "version": "1.0.4", - "dev": true, "license": "MIT", "bin": { "mkdirp": "bin/cmd.js" @@ -12565,6 +12682,11 @@ "which": "bin/which" } }, + "node_modules/path-browserify": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/path-browserify/-/path-browserify-1.0.1.tgz", + "integrity": "sha512-b7uo2UCUOYZcnF/3ID0lulOJi/bafxa1xPe7ZPsammBSpjSWQkjNxlt635YGS2MiR9GjvuXCtz2emr3jbsz98g==" + }, "node_modules/path-exists": { "version": "4.0.0", "dev": true, @@ -12709,6 +12831,20 @@ "node": ">= 0.8.0" } }, + "node_modules/prettier": { + "version": "2.8.0", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.8.0.tgz", + "integrity": "sha512-9Lmg8hTFZKG0Asr/kW9Bp8tJjRVluO8EJQVfY2T7FMw9T5jy4I/Uvx0Rca/XWf50QQ1/SS48+6IJWnrb+2yemA==", + "bin": { + "prettier": "bin-prettier.js" + }, + "engines": { + "node": ">=10.13.0" + }, + "funding": { + "url": "https://github.com/prettier/prettier?sponsor=1" + } + }, "node_modules/pretty-bytes": { "version": "5.6.0", "license": "MIT", @@ -13373,7 +13509,6 @@ }, "node_modules/require-directory": { "version": "2.1.1", - "dev": true, "license": "MIT", "engines": { "node": ">=0.10.0" @@ -14181,6 +14316,21 @@ "integrity": "sha1-gYT9NH2snNwYWZLzpmIuFLnZq2o=", "dev": true }, + "node_modules/transliteration": { + "version": "2.3.5", + "resolved": "https://registry.npmjs.org/transliteration/-/transliteration-2.3.5.tgz", + "integrity": "sha512-HAGI4Lq4Q9dZ3Utu2phaWgtm3vB6PkLUFqWAScg/UW+1eZ/Tg6Exo4oC0/3VUol/w4BlefLhUUSVBr/9/ZGQOw==", + "dependencies": { + "yargs": "^17.5.1" + }, + "bin": { + "slugify": "dist/bin/slugify", + "transliterate": "dist/bin/transliterate" + }, + "engines": { + "node": ">=6.0.0" + } + }, "node_modules/tree-kill": { "version": "1.2.2", "dev": true, @@ -14194,6 +14344,15 @@ "dev": true, "license": "ISC" }, + "node_modules/ts-morph": { + "version": "16.0.0", + "resolved": "https://registry.npmjs.org/ts-morph/-/ts-morph-16.0.0.tgz", + "integrity": "sha512-jGNF0GVpFj0orFw55LTsQxVYEUOCWBAbR5Ls7fTYE5pQsbW18ssTb/6UXx/GYAEjS+DQTp8VoTw0vqYMiaaQuw==", + "dependencies": { + "@ts-morph/common": "~0.17.0", + "code-block-writer": "^11.0.3" + } + }, "node_modules/ts-node": { "version": "10.9.1", "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-10.9.1.tgz", @@ -14312,7 +14471,6 @@ "version": "4.9.3", "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.9.3.tgz", "integrity": "sha512-CIfGzTelbKNEnLpLdGFgdyKhG23CKdKgQPOBc+OUNrkJ2vr+KSzsSV5kq5iWhEQbok+quxgGzrAtGWCyU7tHnA==", - "dev": true, "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" @@ -14675,7 +14833,6 @@ }, "node_modules/y18n": { "version": "5.0.8", - "dev": true, "license": "ISC", "engines": { "node": ">=10" @@ -14697,7 +14854,6 @@ "version": "17.5.1", "resolved": "https://registry.npmjs.org/yargs/-/yargs-17.5.1.tgz", "integrity": "sha512-t6YAJcxDkNX7NFYiVtKvWUz8l+PaKTLiL63mJYWR2GnHq2gjEWISzsLp9wg3aY36dY1j+gfIEL3pIF+XlJJfbA==", - "dev": true, "dependencies": { "cliui": "^7.0.2", "escalade": "^3.1.1", @@ -14715,7 +14871,6 @@ "version": "21.1.1", "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-21.1.1.tgz", "integrity": "sha512-tVpsJW7DdjecAiFpbIB1e3qxIQsE6NoPc5/eTdrbbIC4h0LVsWhnoa3g+m2HclBIujHzsxZ4VJVA+GUuc2/LBw==", - "dev": true, "engines": { "node": ">=12" } @@ -16516,6 +16671,35 @@ "version": "1.1.2", "dev": true }, + "@ts-morph/common": { + "version": "0.17.0", + "resolved": "https://registry.npmjs.org/@ts-morph/common/-/common-0.17.0.tgz", + "integrity": "sha512-RMSSvSfs9kb0VzkvQ2NWobwnj7TxCA9vI/IjR9bDHqgAyVbu2T0DN4wiKVqomyDWqO7dPr/tErSfq7urQ1Q37g==", + "requires": { + "fast-glob": "^3.2.11", + "minimatch": "^5.1.0", + "mkdirp": "^1.0.4", + "path-browserify": "^1.0.1" + }, + "dependencies": { + "brace-expansion": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz", + "integrity": "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==", + "requires": { + "balanced-match": "^1.0.0" + } + }, + "minimatch": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-5.1.0.tgz", + "integrity": "sha512-9TPBGGak4nHfGZsPBohm9AWg6NoT7QTCehS3BIJABslyZbzxfV78QM2Y6+i741OPZIafFAaiiEMh5OyIrJPgtg==", + "requires": { + "brace-expansion": "^2.0.1" + } + } + } + }, "@tsconfig/node10": { "version": "1.0.8", "dev": true @@ -16766,6 +16950,35 @@ "eslint-visitor-keys": "^2.0.0" } }, + "@xata.io/client": { + "version": "0.21.2", + "resolved": "https://registry.npmjs.org/@xata.io/client/-/client-0.21.2.tgz", + "integrity": "sha512-+ZoAgGGy6+In6HDjqSRCzxKcsodFZDd6stGgvtpATt+bUyL8glkk61EYh3iKKrlWBtfG5lZPK9LEQcVEdf6icg==", + "requires": {} + }, + "@xata.io/codegen": { + "version": "0.21.0", + "resolved": "https://registry.npmjs.org/@xata.io/codegen/-/codegen-0.21.0.tgz", + "integrity": "sha512-XxfQ9/+gVwjXFeFWSzJ83SEi/VkIf87kp9m+2cg/F3BDZMqwfmXPvEYGjXloJzomdE3uOKK1Tln5ycTs2+Dh7w==", + "requires": { + "case": "^1.6.3", + "prettier": "^2.7.1", + "ts-morph": "^16.0.0", + "typescript": "^4.8.4", + "zod": "^3.19.1" + } + }, + "@xata.io/importer": { + "version": "0.3.2", + "resolved": "https://registry.npmjs.org/@xata.io/importer/-/importer-0.3.2.tgz", + "integrity": "sha512-Y++eUgQXbJZYsauPsFN4N0nGIGrfGorzn0zzMoaOztMjnBu4GsQdxEBYl7X8OezUipHI8NRYn0cg64BjUsLSDg==", + "requires": { + "@xata.io/client": "^0.21.0", + "camelcase": "^7.0.0", + "csvtojson": "^2.0.10", + "transliteration": "^2.3.5" + } + }, "abbrev": { "version": "1.1.1", "dev": true @@ -22028,6 +22241,11 @@ } } }, + "bluebird": { + "version": "3.7.2", + "resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.7.2.tgz", + "integrity": "sha512-XpNj6GDQzdfW+r2Wnn7xiSAd7TM3jzkxGXBGTtWKuSXv1xUV+azxAm8jdWZN06QTQk+2N2XB9jRDkvbmQmcRtg==" + }, "brace-expansion": { "version": "1.1.11", "requires": { @@ -22116,6 +22334,11 @@ "resolved": "https://registry.npmjs.org/callsites/-/callsites-3.1.0.tgz", "integrity": "sha512-P8BjAsXvZS+VIDUI11hHCQEv74YT67YUi5JJFNWIqL235sBmjX4+qx9Muvls5ivyNENctx46xQLQ3aTuE7ssaQ==" }, + "camelcase": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-7.0.0.tgz", + "integrity": "sha512-JToIvOmz6nhGsUhAYScbo2d6Py5wojjNfoxoc2mEVLUdJ70gJK2gnd+ABY1Tc3sVMyK7QDPtN0T/XdlCQWITyQ==" + }, "caniuse-lite": { "version": "1.0.30001431", "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001431.tgz", @@ -22128,6 +22351,11 @@ "redeyed": "~2.1.0" } }, + "case": { + "version": "1.6.3", + "resolved": "https://registry.npmjs.org/case/-/case-1.6.3.tgz", + "integrity": "sha512-mzDSXIPaFwVDvZAHqZ9VlbyF4yyXRuX6IvB06WvPYkqJVO24kX1PPhv9bfpKNFZyxYFmmgo03HUiD8iklmJYRQ==" + }, "chalk": { "version": "5.1.2", "resolved": "https://registry.npmjs.org/chalk/-/chalk-5.1.2.tgz", @@ -22213,7 +22441,6 @@ }, "cliui": { "version": "7.0.4", - "dev": true, "requires": { "string-width": "^4.2.0", "strip-ansi": "^6.0.0", @@ -22270,6 +22497,11 @@ "mkdirp-infer-owner": "^2.0.0" } }, + "code-block-writer": { + "version": "11.0.3", + "resolved": "https://registry.npmjs.org/code-block-writer/-/code-block-writer-11.0.3.tgz", + "integrity": "sha512-NiujjUFB4SwScJq2bwbYUtXbZhBSlY6vYzm++3Q6oC+U+injTqfPYFK8wS9COOmb2lueqp0ZRB4nK1VYeHgNyw==" + }, "code-point-at": { "version": "1.1.0", "dev": true @@ -22426,6 +22658,26 @@ } } }, + "csvtojson": { + "version": "2.0.10", + "resolved": "https://registry.npmjs.org/csvtojson/-/csvtojson-2.0.10.tgz", + "integrity": "sha512-lUWFxGKyhraKCW8Qghz6Z0f2l/PqB1W3AO0HKJzGIQ5JRSlR651ekJDiGJbBT4sRNNv5ddnSGVEnsxP9XRCVpQ==", + "requires": { + "bluebird": "^3.5.1", + "lodash": "^4.17.3", + "strip-bom": "^2.0.0" + }, + "dependencies": { + "strip-bom": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/strip-bom/-/strip-bom-2.0.0.tgz", + "integrity": "sha512-kwrX1y7czp1E69n2ajbG65mIo9dqvJ+8aBQXOGVxqwvNbsXdFM6Lq37dLAY3mknUwru8CfcCbfOLL/gMo+fi3g==", + "requires": { + "is-utf8": "^0.2.0" + } + } + } + }, "dargs": { "version": "7.0.0", "dev": true @@ -23642,8 +23894,7 @@ "version": "1.0.0-beta.2" }, "get-caller-file": { - "version": "2.0.5", - "dev": true + "version": "2.0.5" }, "get-package-type": { "version": "0.1.0" @@ -24033,8 +24284,7 @@ "dev": true }, "is-utf8": { - "version": "0.2.1", - "dev": true + "version": "0.2.1" }, "is-wsl": { "version": "2.2.0", @@ -24475,8 +24725,7 @@ } }, "mkdirp": { - "version": "1.0.4", - "dev": true + "version": "1.0.4" }, "mkdirp-classic": { "version": "0.5.3", @@ -25244,6 +25493,11 @@ } } }, + "path-browserify": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/path-browserify/-/path-browserify-1.0.1.tgz", + "integrity": "sha512-b7uo2UCUOYZcnF/3ID0lulOJi/bafxa1xPe7ZPsammBSpjSWQkjNxlt635YGS2MiR9GjvuXCtz2emr3jbsz98g==" + }, "path-exists": { "version": "4.0.0", "dev": true @@ -25327,6 +25581,11 @@ "version": "1.2.1", "dev": true }, + "prettier": { + "version": "2.8.0", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.8.0.tgz", + "integrity": "sha512-9Lmg8hTFZKG0Asr/kW9Bp8tJjRVluO8EJQVfY2T7FMw9T5jy4I/Uvx0Rca/XWf50QQ1/SS48+6IJWnrb+2yemA==" + }, "pretty-bytes": { "version": "5.6.0" }, @@ -25772,8 +26031,7 @@ "dev": true }, "require-directory": { - "version": "2.1.1", - "dev": true + "version": "2.1.1" }, "require-from-string": { "version": "2.0.2", @@ -26298,6 +26556,14 @@ "integrity": "sha1-gYT9NH2snNwYWZLzpmIuFLnZq2o=", "dev": true }, + "transliteration": { + "version": "2.3.5", + "resolved": "https://registry.npmjs.org/transliteration/-/transliteration-2.3.5.tgz", + "integrity": "sha512-HAGI4Lq4Q9dZ3Utu2phaWgtm3vB6PkLUFqWAScg/UW+1eZ/Tg6Exo4oC0/3VUol/w4BlefLhUUSVBr/9/ZGQOw==", + "requires": { + "yargs": "^17.5.1" + } + }, "tree-kill": { "version": "1.2.2", "dev": true @@ -26306,6 +26572,15 @@ "version": "1.0.4", "dev": true }, + "ts-morph": { + "version": "16.0.0", + "resolved": "https://registry.npmjs.org/ts-morph/-/ts-morph-16.0.0.tgz", + "integrity": "sha512-jGNF0GVpFj0orFw55LTsQxVYEUOCWBAbR5Ls7fTYE5pQsbW18ssTb/6UXx/GYAEjS+DQTp8VoTw0vqYMiaaQuw==", + "requires": { + "@ts-morph/common": "~0.17.0", + "code-block-writer": "^11.0.3" + } + }, "ts-node": { "version": "10.9.1", "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-10.9.1.tgz", @@ -26377,8 +26652,7 @@ "typescript": { "version": "4.9.3", "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.9.3.tgz", - "integrity": "sha512-CIfGzTelbKNEnLpLdGFgdyKhG23CKdKgQPOBc+OUNrkJ2vr+KSzsSV5kq5iWhEQbok+quxgGzrAtGWCyU7tHnA==", - "dev": true + "integrity": "sha512-CIfGzTelbKNEnLpLdGFgdyKhG23CKdKgQPOBc+OUNrkJ2vr+KSzsSV5kq5iWhEQbok+quxgGzrAtGWCyU7tHnA==" }, "undici": { "version": "5.9.1", @@ -26625,8 +26899,7 @@ "dev": true }, "y18n": { - "version": "5.0.8", - "dev": true + "version": "5.0.8" }, "yallist": { "version": "4.0.0" @@ -26640,7 +26913,6 @@ "version": "17.5.1", "resolved": "https://registry.npmjs.org/yargs/-/yargs-17.5.1.tgz", "integrity": "sha512-t6YAJcxDkNX7NFYiVtKvWUz8l+PaKTLiL63mJYWR2GnHq2gjEWISzsLp9wg3aY36dY1j+gfIEL3pIF+XlJJfbA==", - "dev": true, "requires": { "cliui": "^7.0.2", "escalade": "^3.1.1", @@ -26654,8 +26926,7 @@ "yargs-parser": { "version": "21.1.1", "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-21.1.1.tgz", - "integrity": "sha512-tVpsJW7DdjecAiFpbIB1e3qxIQsE6NoPc5/eTdrbbIC4h0LVsWhnoa3g+m2HclBIujHzsxZ4VJVA+GUuc2/LBw==", - "dev": true + "integrity": "sha512-tVpsJW7DdjecAiFpbIB1e3qxIQsE6NoPc5/eTdrbbIC4h0LVsWhnoa3g+m2HclBIujHzsxZ4VJVA+GUuc2/LBw==" }, "yarn": { "version": "1.22.18" diff --git a/cli/package.json b/cli/package.json index d37c58d98..363b6160e 100644 --- a/cli/package.json +++ b/cli/package.json @@ -59,6 +59,7 @@ "rollup-plugin-esbuild": "^5.0.0", "rollup-plugin-hypothetical": "^2.1.1", "rollup-plugin-virtual-fs": "^4.0.1-alpha.0", + "semver": "^7.3.8", "text-table": "^0.2.0", "tmp": "^0.2.1", "which": "^3.0.0", diff --git a/cli/src/commands/codegen/index.ts b/cli/src/commands/codegen/index.ts index e9fedda6b..1e9e67ed1 100644 --- a/cli/src/commands/codegen/index.ts +++ b/cli/src/commands/codegen/index.ts @@ -4,6 +4,9 @@ import chalk from 'chalk'; import { mkdir, writeFile } from 'fs/promises'; import path, { dirname, extname, relative } from 'path'; import { BaseCommand, ProjectConfig } from '../../base.js'; +import { readJSON } from '../../utils.js'; +import { VERSION as sdkVersion } from '@xata.io/client'; +import semver from 'semver'; export const languages: Record = { '.js': 'javascript', @@ -72,6 +75,24 @@ export default class Codegen extends BaseCommand { ); } + const packageJSON = await readJSON('package.json'); + if (!packageJSON) { + return this.error('Could not find package.json. Please run this command in the root of your project.'); + } + + const installedVersion: string | undefined = packageJSON.dependencies['@xata.io/client']; + if (!installedVersion) { + return this.error( + `Could not find @xata.io/client in your package.json. Please install it to use the codegen command.` + ); + } + + if (!semver.satisfies(installedVersion, `^${sdkVersion}`)) { + return this.error( + `The installed version of @xata.io/client (${installedVersion}) does not satisfy the required version (${sdkVersion}). Please update your package.json.` + ); + } + const ext = extname(output); const dir = dirname(output); const language = languages[ext]; diff --git a/cli/src/commands/init/index.ts b/cli/src/commands/init/index.ts index 55974fe2b..a28432fb9 100644 --- a/cli/src/commands/init/index.ts +++ b/cli/src/commands/init/index.ts @@ -1,19 +1,22 @@ import { Flags } from '@oclif/core'; +import { VERSION as sdkVersion } from '@xata.io/client'; import { ModuleType } from '@xata.io/codegen'; import chalk from 'chalk'; -import { access, readFile, writeFile } from 'fs/promises'; +import dotenv from 'dotenv'; +import { readFile, writeFile } from 'fs/promises'; import path, { extname } from 'path'; +import semver from 'semver'; import which from 'which'; import { createAPIKeyThroughWebUI } from '../../auth-server.js'; import { BaseCommand, ENV_FILES } from '../../base.js'; import { isIgnored } from '../../git.js'; import { xataDatabaseSchema } from '../../schema.js'; +import { existsFile, readJSON } from '../../utils.js'; import Browse from '../browse/index.js'; import Codegen, { languages, unsupportedExtensionError } from '../codegen/index.js'; import RandomData from '../random-data/index.js'; import EditSchema from '../schema/edit.js'; import Shell from '../shell/index.js'; -import dotenv from 'dotenv'; const moduleTypeOptions = ['cjs', 'esm']; export default class Init extends BaseCommand { @@ -180,7 +183,7 @@ export default class Init extends BaseCommand { } if (output || sdk) { - await this.installPackage('@xata.io/client'); + await this.installSDK(); } } @@ -201,32 +204,38 @@ export default class Init extends BaseCommand { } async guessPackageManager() { - if (await this.access('package-lock.json')) { + if (await existsFile('package-lock.json')) { return { name: 'npm', args: ['install', '--save'] }; - } else if (await this.access('yarn.lock')) { + } else if (await existsFile('yarn.lock')) { return { name: 'yarn', args: ['add'] }; - } else if (await this.access('pnpm-lock.yaml')) { + } else if (await existsFile('pnpm-lock.yaml')) { return { name: 'pnpm', args: ['add'] }; } else { return null; } } - async access(path: string) { - try { - await access(path); - return true; - } catch (err) { - return false; - } - } + async installSDK() { + const pkg = '@xata.io/client'; - async installPackage(pkg: string) { const packageManager = await this.getPackageManager(); if (!packageManager) return; - const { name, args } = packageManager; - await this.runCommand(name, [...args, pkg]); + const packageJSON = await readJSON('package.json'); + if (!packageJSON) { + throw new Error('Could not find package.json. Please run this command in the root of your project.'); + } + + const installedVersion: string | undefined = packageJSON.dependencies[pkg]; + + if (installedVersion === undefined || semver.lt(installedVersion, sdkVersion)) { + const { name, args } = packageManager; + await this.runCommand(name, [...args, `${pkg}@${sdkVersion}`]); + } else if (semver.gt(installedVersion, sdkVersion)) { + this.warn( + `The CLI is not up to date. Please update it with ${chalk.bold('npm install -g @xata.io/cli')} to avoid errors.` + ); + } } async writeConfig() { @@ -240,7 +249,7 @@ export default class Init extends BaseCommand { async writeEnvFile(workspace: string, region: string, database: string) { let envFile = ENV_FILES[ENV_FILES.length - 1]; for (const file of ENV_FILES) { - if (await this.access(file)) { + if (await existsFile(file)) { envFile = file; break; } @@ -322,7 +331,7 @@ export default class Init extends BaseCommand { const ignored = await isIgnored(envFile); if (ignored) return; - const exists = await this.access('.gitignore'); + const exists = await existsFile('.gitignore'); const { confirm } = await this.prompt({ type: 'confirm', diff --git a/cli/src/utils.ts b/cli/src/utils.ts index 5b9901628..dee217c3e 100644 --- a/cli/src/utils.ts +++ b/cli/src/utils.ts @@ -1,3 +1,5 @@ +import { access, readFile } from 'fs/promises'; + export function pluralize(word: string, count: number) { return `${word}${count === 1 ? '' : 's'}`; } @@ -7,3 +9,21 @@ export function reportBugURL(title: string) { title )}`; } + +export async function existsFile(path: string) { + try { + await access(path); + return true; + } catch (err) { + return false; + } +} + +export async function readJSON(path: string) { + try { + const content = await readFile(path); + return JSON.parse(content.toString()); + } catch (err) { + return null; + } +} diff --git a/packages/client/src/index.ts b/packages/client/src/index.ts index 03ab00b62..dfff3e6d2 100644 --- a/packages/client/src/index.ts +++ b/packages/client/src/index.ts @@ -16,3 +16,4 @@ export * from './serializer'; export * from './util/config'; export * from './util/apiKey'; export * from './workers'; +export * from './version';