diff --git a/node/DEVELOPER.md b/node/DEVELOPER.md index 3725d369a8..0140a636d0 100644 --- a/node/DEVELOPER.md +++ b/node/DEVELOPER.md @@ -134,6 +134,33 @@ To run the integration tests with existing servers, run the following command: npm run test -- --cluster-endpoints=localhost:7000 --standalone-endpoints=localhost:6379 ``` +### REPL (interactive shell) + +It is possible to run an interactive shell synced with the currect client code to test and debug it: + +```bash +npx ts-node --project tsconfig.json +``` + +This shell allows executing typescript and javascript code line by line: + +```typescript +import { GlideClient, GlideClusterClient } from "."; +let client = await GlideClient.createClient({ + addresses: [{ host: "localhost", port: 6379 }], +}); +let clusterClient = await GlideClusterClient.createClient({ + addresses: [{ host: "localhost", port: 7000 }], +}); +await client.ping(); +``` + +After applying changes in client code you need to restart the shell. + +It has command history and bash-like search (`Ctrl+R`). + +Shell hangs on exit (`Ctrl+D`) if you don't close the clients. Use `Ctrl+C` to kill it and/or close clients before exit. + ### Submodules After pulling new changes, ensure that you update the submodules by running the following command: @@ -166,7 +193,7 @@ Development on the Node wrapper may involve changes in either the TypeScript or # Run from the node folder npm run lint # To automatically apply ESLint and/or prettier recommendations - npx run lint:fix + npm run lint:fix ``` 2. Rust diff --git a/node/package.json b/node/package.json index 20dbeea80b..b52e6f540f 100644 --- a/node/package.json +++ b/node/package.json @@ -56,7 +56,8 @@ "semver": "^7.6.3", "ts-jest": "^29.2.5", "typescript": "^5.5.4", - "uuid": "^10.0.0" + "uuid": "^10.0.0", + "ts-node": "^10.9.2" }, "author": "Valkey GLIDE Maintainers", "license": "Apache-2.0", diff --git a/node/tsconfig.json b/node/tsconfig.json index 4cd744701c..a1824416be 100644 --- a/node/tsconfig.json +++ b/node/tsconfig.json @@ -25,6 +25,15 @@ ] /* Specify a set of bundled library declaration files that describe the target runtime environment. */, "outDir": "./build-ts" /* Specify an output folder for all emitted files.*/ }, + "ts-node": { + "transpileOnly": true, + "compilerOptions": { + "module": "CommonJS", + "target": "ES2018", + "esModuleInterop": true + }, + "esm": true + }, "compileOnSave": false, "include": ["./*.ts", "src/*.ts", "src/*.js"], "exclude": ["node_modules", "build-ts"]