Skip to content

Commit

Permalink
Updates to convex-js
Browse files Browse the repository at this point in the history
GitOrigin-RevId: 6b39042aa0a0ede67cb4137c485669825225ca5d
  • Loading branch information
Convex, Inc authored and nipunn1313 committed Feb 28, 2024
1 parent 250cf79 commit 3e58952
Show file tree
Hide file tree
Showing 132 changed files with 2,600 additions and 1,938 deletions.
1 change: 1 addition & 0 deletions .prettierrc.cjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
module.exports = {
proseWrap: "always",
trailingComma: "all",
};
43 changes: 24 additions & 19 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
{
"name": "convex",
"description": "Client for the Convex Cloud",
"version": "1.9.0",
"version": "1.10.0",
"author": "Convex, Inc. <team@convex.dev>",
"homepage": "https://convex.dev",
"repository": {
"type": "git",
"url": "git+https://github.com/get-convex/convex-js.git"
},
"main": "./dist/cjs/index.js",
"module": "./dist/esm/index.js",
"types": "./dist/cjs-types/index.d.ts",
Expand Down Expand Up @@ -135,8 +139,6 @@
"bundle-server": "node scripts/bundle-server.mjs",
"clean": "shx rm -rf dist tmpDist*",
"lint": "eslint . --ext .js,.jsx,.ts,.tsx",
"format": "prettier -w . && eslint --fix .",
"format-check": "prettier -c . && eslint . --ext .js,.jsx,.ts,.tsx",
"prepare": "npm run build",
"prepack": "node scripts/prepack.mjs",
"postpack": "node scripts/postpack.mjs",
Expand All @@ -157,14 +159,14 @@
],
"dependencies": {
"esbuild": "^0.17.5",
"node-fetch": "^2.6.1",
"jwt-decode": "^3.1.2"
"jwt-decode": "^3.1.2",
"node-fetch": "^2.6.1"
},
"peerDependencies": {
"react": "^17.0.2 || ^18.0.0",
"react-dom": "^17.0.2 || ^18.0.0",
"@auth0/auth0-react": "^2.0.1",
"@clerk/clerk-react": "^4.12.8"
"@clerk/clerk-react": "^4.12.8",
"react": "^17.0.2 || ^18.0.0",
"react-dom": "^17.0.2 || ^18.0.0"
},
"peerDependenciesMeta": {
"react": {
Expand All @@ -186,16 +188,20 @@
],
"devDependencies": {
"@auth0/auth0-react": "2.0.1",
"@clerk/clerk-react": "4.18.0",
"@babel/parser": "^7.21.3",
"@microsoft/api-extractor": "~7.36.4",
"@clerk/clerk-react": "4.18.0",
"@commander-js/extra-typings": "~11.1.0",
"@jest/globals": "^28.1.0",
"@microsoft/api-extractor": "~7.36.4",
"@sentry/node": "^7.23.0",
"@sentry/tracing": "^7.23.0",
"@swc/core": "1.3.107",
"@testing-library/react": "~14.0.0",
"@types/deep-equal": "1.0.1",
"@types/http-proxy": "~1.17.9",
"@types/inquirer": "^8.2.0",
"@types/jest": "^27.0.0",
"@types/jwt-encode": "~1.0.0",
"@types/node": "^16.11.12",
"@types/node-fetch": "^2.6.1",
"@types/prettier": "^2.7.1",
Expand All @@ -205,24 +211,26 @@
"@types/ws": "^8.5.3",
"@typescript-eslint/eslint-plugin": "^6.7.4",
"@typescript-eslint/parser": "^6.7.4",
"@swc/core": "1.3.82",
"axios": "1.6.2",
"axios-retry": "^3.2.4",
"bufferutil": "^4.0.7",
"chalk": "4",
"chokidar": "3.5.3",
"commander": "^9.4.1",
"deep-equal": "2.1.0",
"depcheck": "~1.4.3",
"depcheck": "~1.4.7",
"dotenv": "^16.0.3",
"dprint": "0.45.0",
"encoding": "^0.1.13",
"envfile": "6.18.0",
"esbuild": "^0.17.5",
"esbuild-plugin-external-global": "~1.0.1",
"eslint": "^8.29.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-jest": "~27.2.1",
"eslint-plugin-react": "^7.31.11",
"eslint-plugin-react-hooks": "^4.6.0",
"fetch-retry": "~5.0.6",
"find-up": "^6.3.0",
"http-proxy": "~1.18.1",
"inquirer": "^9.1.4",
Expand All @@ -232,23 +240,20 @@
"open": "^8.3.0",
"openid-client": "^5.3.1",
"ora": "^6.1.0",
"prettier": "2.8.7",
"prettier": "2.8.8",
"react": "^18.0.0",
"react-dom": "^18.0.0",
"semver": "^7.5.4",
"semver": "^7.6.0",
"shx": "~0.3.4",
"strip-ansi": "^7.0.1",
"ts-jest": "^29.1.1",
"ts-node": "~10.9.1",
"typedoc": "^0.24.6",
"typescript": "~5.0.3",
"utf-8-validate": "^5.0.10",
"ws": "^8.11.0",
"zod": "^3.21.4",
"@testing-library/react": "~14.0.0",
"@types/jwt-encode": "~1.0.0",
"wait-for-expect": "~3.0.2",
"eslint-plugin-jest": "~27.2.1"
"ws": "^8.11.0",
"zod": "^3.21.4"
},
"engines": {
"npm": ">=7.0.0",
Expand Down
4 changes: 2 additions & 2 deletions scripts/build.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const [tempDir] = process.argv
if (process.argv.includes("esm")) {
const opts = {
entryPoints: allSourceFiles.filter(
(f) => !f.includes("simple_client-node")
(f) => !f.includes("simple_client-node"),
),
bundle: false,
sourcemap: true,
Expand Down Expand Up @@ -71,7 +71,7 @@ if (process.argv.includes("esm")) {
if (process.argv.includes("cjs")) {
const opts = {
entryPoints: allSourceFiles.filter(
(f) => !f.includes("simple_client-node")
(f) => !f.includes("simple_client-node"),
),
format: "cjs",
bundle: false,
Expand Down
6 changes: 3 additions & 3 deletions scripts/bundle-server.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import path from "path";

if (process.argv.length < 3) {
throw new Error(
"USAGE: node bundle-server.mjs <udf system dir> <system dir>*"
"USAGE: node bundle-server.mjs <udf system dir> <system dir>*",
);
}
const systemDirs = process.argv.slice(3);
Expand All @@ -29,15 +29,15 @@ for (const systemDir of systemDirs) {
const entryPoints = await entryPointsByEnvironment(
oneoffContext,
systemDir,
false
false,
);
const bundles = (
await bundle(
oneoffContext,
systemDir,
entryPoints.isolate,
false,
"browser"
"browser",
)
).modules;
out.push(...bundles);
Expand Down
4 changes: 2 additions & 2 deletions scripts/checkdeps.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ const options = {
depcheck(root, options).then((unused) => {
if (unused.dependencies.length) {
console.log(
"Some package.json dependencies are only used in CLI (or not at all):"
"Some package.json dependencies are only used in CLI (or not at all):",
);
console.log(
"If a dependency is only used in the CLI, add it to devDependencies instead."
"If a dependency is only used in the CLI, add it to devDependencies instead.",
);
console.log(unused.dependencies);
process.exit(1);
Expand Down
4 changes: 2 additions & 2 deletions scripts/node-browser.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ const cjsBrowserIndexNode = path.join(
distDir,
"cjs",
"browser",
"index-node.js"
"index-node.js",
);
const esmBrowserIndexNode = path.join(
distDir,
"esm",
"browser",
"index-node.js"
"index-node.js",
);

let output = fs.readFileSync(cjsBrowserIndex, { encoding: "utf-8" });
Expand Down
41 changes: 10 additions & 31 deletions scripts/postpack.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const tarball = getOnlyTarball(convexDir);

const tmpDir = path.join(
convexDir,
"tmpPackage" + ("" + Math.random()).slice(2, 8)
"tmpPackage" + ("" + Math.random()).slice(2, 8),
);
console.log("creating temp folder", tmpDir);
fs.rmSync(tmpDir, { force: true, recursive: true });
Expand All @@ -23,7 +23,7 @@ const tmpPackage = path.join(tmpDir, "package");

console.log("modifying package.json");
let packageJson = JSON.parse(
fs.readFileSync(path.join(tmpPackage, "package.json"))
fs.readFileSync(path.join(tmpPackage, "package.json")),
);
pointToPublic(packageJson.exports);
pointToPublic(packageJson.typesVersions);
Expand All @@ -35,7 +35,7 @@ delete packageJson.bin["//"];

fs.writeFileSync(
path.join(tmpPackage, "package.json"),
JSON.stringify(packageJson, null, 2) + "\n"
JSON.stringify(packageJson, null, 2) + "\n",
);

console.log("modifying stub directories");
Expand All @@ -44,7 +44,7 @@ for (const [dirname, contents] of Object.entries(stubs)) {
pointToPublic(contents);
fs.writeFileSync(
path.join(tmpPackage, dirname, "package.json"),
JSON.stringify(contents, null, 2) + "\n"
JSON.stringify(contents, null, 2) + "\n",
);
}

Expand All @@ -69,7 +69,7 @@ function getOnlyTarball(dirname) {
if (tarballs.length < 1) throw new Error("No tarball found.");
if (tarballs.length > 1) {
throw new Error(
"Multiple tarballs found, please `rm *.tgz` and run again. `--pack-destination` is not allowed."
"Multiple tarballs found, please `rm *.tgz` and run again. `--pack-destination` is not allowed.",
);
}
return path.join(dirname, tarballs[0]);
Expand Down Expand Up @@ -98,9 +98,9 @@ function getStubDirectories(dirname) {
JSON.parse(
fs.readFileSync(path.join(dirname, d, "package.json"), {
encoding: "utf-8",
})
}),
),
])
]),
);
}

Expand All @@ -122,28 +122,7 @@ function rewriteDtsToRemoveInternal(dirname) {
`/** @internal */
record<K extends string, ValueValidator extends Validator<any, any, any>>(keys: Validator<K, false, any>, values: ValueValidator): RecordValidator<K, ValueValidator>;`,
`/* internal record
record<K extends string, ValueValidator extends Validator<any, any, any>>(keys: Validator<K, false, any>, values: ValueValidator): RecordValidator<K, ValueValidator>; */`
);
// Parameters aren't removed by tsc --removeInternal
replaceType(
dirname,
"values/value.d.ts",
`export declare function jsonToConvex(value: JSONValue,
/** @internal */
allowMapsAndSets?: boolean): Value;`,
`export declare function jsonToConvex(value: JSONValue,
/* internal allowMapsAndSets */
): Value;`
);
replaceType(
dirname,
"values/value.d.ts",
`export declare function convexToJson(value: Value,
/** @internal */
allowMapsAndSets?: boolean): JSONValue;`,
`export declare function convexToJson(value: Value,
/* internal allowMapsAndSets */
): JSONValue;`
record<K extends string, ValueValidator extends Validator<any, any, any>>(keys: Validator<K, false, any>, values: ValueValidator): RecordValidator<K, ValueValidator>; */`,
);
auditForInternal(path.join(dirname, "dist", "cjs-types"));
auditForInternal(path.join(dirname, "dist", "esm-types"));
Expand Down Expand Up @@ -180,10 +159,10 @@ function auditForInternal(dir) {
console.log(
"found @internal type in",
file,
`\n\`\`\`\n${match}\`\`\``
`\n\`\`\`\n${match}\`\`\``,
);
throw new Error(
"Found @internal type in published types! Until we switch to api-extractor you need to add a pattern for this in scripts/postpack.mjs in rewriteDtsToRemoveInternal()."
"Found @internal type in published types! Until we switch to api-extractor you need to add a pattern for this in scripts/postpack.mjs in rewriteDtsToRemoveInternal().",
);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/browser/http_client-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { ConvexHttpClient, setFetch } from "./http_client.js";
if (typeof globalThis.fetch === "undefined") {
setFetch((...args) =>
import("node-fetch").then(({ default: fetch }) =>
(fetch as unknown as typeof globalThis.fetch)(...args)
)
(fetch as unknown as typeof globalThis.fetch)(...args),
),
);
}

Expand Down
18 changes: 9 additions & 9 deletions src/browser/http_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,12 @@ export class ConvexHttpClient {
}
switch (respJSON.status) {
case "success":
return jsonToConvex(respJSON.value, true);
return jsonToConvex(respJSON.value);
case "error":
if (respJSON.errorData !== undefined) {
throw forwardErrorData(
respJSON.errorData,
new ConvexError(respJSON.errorMessage)
new ConvexError(respJSON.errorMessage),
);
}
throw new Error(respJSON.errorMessage);
Expand Down Expand Up @@ -221,12 +221,12 @@ export class ConvexHttpClient {
}
switch (respJSON.status) {
case "success":
return jsonToConvex(respJSON.value, true);
return jsonToConvex(respJSON.value);
case "error":
if (respJSON.errorData !== undefined) {
throw forwardErrorData(
respJSON.errorData,
new ConvexError(respJSON.errorMessage)
new ConvexError(respJSON.errorMessage),
);
}
throw new Error(respJSON.errorMessage);
Expand Down Expand Up @@ -282,12 +282,12 @@ export class ConvexHttpClient {
}
switch (respJSON.status) {
case "success":
return jsonToConvex(respJSON.value, true);
return jsonToConvex(respJSON.value);
case "error":
if (respJSON.errorData !== undefined) {
throw forwardErrorData(
respJSON.errorData,
new ConvexError(respJSON.errorMessage)
new ConvexError(respJSON.errorMessage),
);
}
throw new Error(respJSON.errorMessage);
Expand All @@ -307,7 +307,7 @@ export class ConvexHttpClient {
* @internal
*/
async function<
AnyFunction extends FunctionReference<"query" | "mutation" | "action">
AnyFunction extends FunctionReference<"query" | "mutation" | "action">,
>(
anyFunction: AnyFunction | string,
...args: OptionalRestArgs<AnyFunction>
Expand Down Expand Up @@ -350,12 +350,12 @@ export class ConvexHttpClient {
}
switch (respJSON.status) {
case "success":
return jsonToConvex(respJSON.value, true);
return jsonToConvex(respJSON.value);
case "error":
if (respJSON.errorData !== undefined) {
throw forwardErrorData(
respJSON.errorData,
new ConvexError(respJSON.errorMessage)
new ConvexError(respJSON.errorMessage),
);
}
throw new Error(respJSON.errorMessage);
Expand Down
Loading

0 comments on commit 3e58952

Please sign in to comment.