diff --git a/samples/simple-ts/package-lock.json b/samples/simple-ts/package-lock.json index 2cbe85e..3a77aeb 100644 --- a/samples/simple-ts/package-lock.json +++ b/samples/simple-ts/package-lock.json @@ -9,7 +9,7 @@ "version": "1.0.0", "license": "MIT", "dependencies": { - "@event-driven-io/pongo": "0.15.0-alpha.1" + "@event-driven-io/pongo": "0.15.0-alpha.2" }, "devDependencies": { "@types/node": "^20.11.30", @@ -132,9 +132,9 @@ } }, "node_modules/@event-driven-io/dumbo": { - "version": "0.11.0-alpha.1", - "resolved": "https://registry.npmjs.org/@event-driven-io/dumbo/-/dumbo-0.11.0-alpha.1.tgz", - "integrity": "sha512-c0yXK+AWatyAliq9Xw5aircWOeHduAIDl5yWm173XFoYSPhI7a5kK+fMfnFz39bFZ6UiDJ3JrUWhKFve0eJsnA==", + "version": "0.11.0-alpha.2", + "resolved": "https://registry.npmjs.org/@event-driven-io/dumbo/-/dumbo-0.11.0-alpha.2.tgz", + "integrity": "sha512-YD34M6bXg+MuflL9lxx/EbBMlytgVp7hQ6CdGMNkcr0S1u8Y8Je7qFLX5MEsrJtyDgbRLVU7j5aFAnS6P5lxbw==", "peer": true, "peerDependencies": { "@types/pg": "^8.11.6", @@ -145,14 +145,14 @@ } }, "node_modules/@event-driven-io/pongo": { - "version": "0.15.0-alpha.1", - "resolved": "https://registry.npmjs.org/@event-driven-io/pongo/-/pongo-0.15.0-alpha.1.tgz", - "integrity": "sha512-6tjSGfG2LVRlFvTTl9OEtY/x7fahaV2xeo4xuXgLWcbeyT+lVpRCeris81U1GUa3O36oRhN/nosF9xjLE2Gdiw==", + "version": "0.15.0-alpha.2", + "resolved": "https://registry.npmjs.org/@event-driven-io/pongo/-/pongo-0.15.0-alpha.2.tgz", + "integrity": "sha512-xWlxyBF8XruspPQYvtgoMRafYDuKhpfbxT3nZwr0rxp2IefLFfY13Z/eWGuXcJ2HO9D0u+W8Lb6lzoiHqeJKAQ==", "bin": { "pongo": "dist/cli.js" }, "peerDependencies": { - "@event-driven-io/dumbo": "0.11.0-alpha.1", + "@event-driven-io/dumbo": "0.11.0-alpha.2", "@types/mongodb": "^4.0.7", "@types/pg": "^8.11.6", "@types/uuid": "^10.0.0", @@ -436,9 +436,9 @@ } }, "node_modules/@types/pg": { - "version": "8.11.9", - "resolved": "https://registry.npmjs.org/@types/pg/-/pg-8.11.9.tgz", - "integrity": "sha512-M4mYeJZRBD9lCBCGa72F44uKSV9eJrAFfjlPJagdA6pgIr2OPJULFB7nqnZzOdqXG0qzHlgtZKzTdIgbmHitSg==", + "version": "8.11.10", + "resolved": "https://registry.npmjs.org/@types/pg/-/pg-8.11.10.tgz", + "integrity": "sha512-LczQUW4dbOQzsH2RQ5qoeJ6qJPdrcM/DcMLoqWQkMLMsq83J5lAX3LXjdkWdpscFy67JSOWDnh7Ny/sPFykmkg==", "peer": true, "dependencies": { "@types/node": "*", @@ -2264,14 +2264,14 @@ } }, "node_modules/pg": { - "version": "8.12.0", - "resolved": "https://registry.npmjs.org/pg/-/pg-8.12.0.tgz", - "integrity": "sha512-A+LHUSnwnxrnL/tZ+OLfqR1SxLN3c/pgDztZ47Rpbsd4jUytsTtwQo/TLPRzPJMp/1pbhYVhH9cuSZLAajNfjQ==", + "version": "8.13.0", + "resolved": "https://registry.npmjs.org/pg/-/pg-8.13.0.tgz", + "integrity": "sha512-34wkUTh3SxTClfoHB3pQ7bIMvw9dpFU1audQQeZG837fmHfHpr14n/AELVDoOYVDW2h5RDWU78tFjkD+erSBsw==", "peer": true, "dependencies": { - "pg-connection-string": "^2.6.4", - "pg-pool": "^3.6.2", - "pg-protocol": "^1.6.1", + "pg-connection-string": "^2.7.0", + "pg-pool": "^3.7.0", + "pg-protocol": "^1.7.0", "pg-types": "^2.1.0", "pgpass": "1.x" }, @@ -2298,9 +2298,9 @@ "peer": true }, "node_modules/pg-connection-string": { - "version": "2.6.4", - "resolved": "https://registry.npmjs.org/pg-connection-string/-/pg-connection-string-2.6.4.tgz", - "integrity": "sha512-v+Z7W/0EO707aNMaAEfiGnGL9sxxumwLl2fJvCQtMn9Fxsg+lPpPkdcyBSv/KFgpGdYkMfn+EI1Or2EHjpgLCA==", + "version": "2.7.0", + "resolved": "https://registry.npmjs.org/pg-connection-string/-/pg-connection-string-2.7.0.tgz", + "integrity": "sha512-PI2W9mv53rXJQEOb8xNR8lH7Hr+EKa6oJa38zsK0S/ky2er16ios1wLKhZyxzD7jUReiWokc9WK5nxSnC7W1TA==", "peer": true }, "node_modules/pg-int8": { @@ -2322,18 +2322,18 @@ } }, "node_modules/pg-pool": { - "version": "3.6.2", - "resolved": "https://registry.npmjs.org/pg-pool/-/pg-pool-3.6.2.tgz", - "integrity": "sha512-Htjbg8BlwXqSBQ9V8Vjtc+vzf/6fVUuak/3/XXKA9oxZprwW3IMDQTGHP+KDmVL7rtd+R1QjbnCFPuTHm3G4hg==", + "version": "3.7.0", + "resolved": "https://registry.npmjs.org/pg-pool/-/pg-pool-3.7.0.tgz", + "integrity": "sha512-ZOBQForurqh4zZWjrgSwwAtzJ7QiRX0ovFkZr2klsen3Nm0aoh33Ls0fzfv3imeH/nw/O27cjdz5kzYJfeGp/g==", "peer": true, "peerDependencies": { "pg": ">=8.0" } }, "node_modules/pg-protocol": { - "version": "1.6.1", - "resolved": "https://registry.npmjs.org/pg-protocol/-/pg-protocol-1.6.1.tgz", - "integrity": "sha512-jPIlvgoD63hrEuihvIg+tJhoGjUsLPn6poJY9N5CnlPd91c2T18T/9zBtLxZSb1EhYxBRoZJtzScCaWlYLtktg==", + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/pg-protocol/-/pg-protocol-1.7.0.tgz", + "integrity": "sha512-hTK/mE36i8fDDhgDFjy6xNOG+LCorxLG3WO17tku+ij6sVHXh1jQUJ8hYAnRhNla4QVD2H8er/FOjc/+EgC6yQ==", "peer": true }, "node_modules/pg-types": { @@ -2385,7 +2385,7 @@ "integrity": "sha512-xy3pmLuQqRBZBXDULy7KbaitYqLcmxigw14Q5sj8QBVLqEwXfeybIKVWiqAXTlcvdvb0+xkOtDbfQMOf4lST1w==", "peer": true, "engines": { - "node": ">=0.11.0-alpha.1" + "node": ">=0.10.0" } }, "node_modules/pg/node_modules/postgres-date": { @@ -2394,7 +2394,7 @@ "integrity": "sha512-suDmjLVQg78nMK2UZ454hAG+OAW+HQPZ6n++TNDUX+L0+uUlLywnoxJKDou51Zm+zTCjrCl0Nq6J9C5hP9vK/Q==", "peer": true, "engines": { - "node": ">=0.11.0-alpha.1" + "node": ">=0.10.0" } }, "node_modules/pg/node_modules/postgres-interval": { @@ -2406,7 +2406,7 @@ "xtend": "^4.0.0" }, "engines": { - "node": ">=0.11.0-alpha.1" + "node": ">=0.10.0" } }, "node_modules/pgpass": { diff --git a/samples/simple-ts/package.json b/samples/simple-ts/package.json index 08d1599..7e66932 100644 --- a/samples/simple-ts/package.json +++ b/samples/simple-ts/package.json @@ -63,6 +63,6 @@ "dist" ], "dependencies": { - "@event-driven-io/pongo": "0.15.0-alpha.1" + "@event-driven-io/pongo": "0.15.0-alpha.2" } } diff --git a/src/package-lock.json b/src/package-lock.json index 7cb0036..49574a5 100644 --- a/src/package-lock.json +++ b/src/package-lock.json @@ -1,12 +1,12 @@ { "name": "@event-driven-io/pongo-core", - "version": "0.15.0-alpha.1", + "version": "0.15.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@event-driven-io/pongo-core", - "version": "0.15.0-alpha.1", + "version": "0.15.0", "workspaces": [ "packages/dumbo", "packages/pongo" @@ -8660,7 +8660,7 @@ }, "packages/dumbo": { "name": "@event-driven-io/dumbo", - "version": "0.11.0-alpha.2", + "version": "0.11.0", "devDependencies": { "@types/node": "22.4.1" }, @@ -8674,7 +8674,7 @@ }, "packages/pongo": { "name": "@event-driven-io/pongo", - "version": "0.15.0-alpha.1", + "version": "0.15.0", "bin": { "pongo": "dist/cli.js" }, @@ -8682,7 +8682,7 @@ "@types/node": "22.4.1" }, "peerDependencies": { - "@event-driven-io/dumbo": "0.11.0-alpha.2", + "@event-driven-io/dumbo": "0.11.0", "@types/mongodb": "^4.0.7", "@types/pg": "^8.11.6", "@types/uuid": "^10.0.0", diff --git a/src/package.json b/src/package.json index 92bd007..4e1bd72 100644 --- a/src/package.json +++ b/src/package.json @@ -1,6 +1,6 @@ { "name": "@event-driven-io/pongo-core", - "version": "0.15.0-alpha.2", + "version": "0.15.0", "description": "Pongo - Mongo with strong consistency on top of Postgres", "type": "module", "engines": { diff --git a/src/packages/dumbo/package.json b/src/packages/dumbo/package.json index e9cc6d8..71a2f90 100644 --- a/src/packages/dumbo/package.json +++ b/src/packages/dumbo/package.json @@ -1,6 +1,6 @@ { "name": "@event-driven-io/dumbo", - "version": "0.11.0-alpha.2", + "version": "0.11.0", "description": "Dumbo - tools for dealing with PostgreSQL", "type": "module", "scripts": { diff --git a/src/packages/pongo/package.json b/src/packages/pongo/package.json index 89d52f2..adf6459 100644 --- a/src/packages/pongo/package.json +++ b/src/packages/pongo/package.json @@ -1,6 +1,6 @@ { "name": "@event-driven-io/pongo", - "version": "0.15.0-alpha.2", + "version": "0.15.0", "description": "Pongo - Mongo with strong consistency on top of Postgres", "type": "module", "scripts": { @@ -87,7 +87,7 @@ "pongo": "./dist/cli.js" }, "peerDependencies": { - "@event-driven-io/dumbo": "0.11.0-alpha.2", + "@event-driven-io/dumbo": "0.11.0", "@types/mongodb": "^4.0.7", "@types/pg": "^8.11.6", "@types/uuid": "^10.0.0", diff --git a/src/packages/pongo/src/commandLine/shell.ts b/src/packages/pongo/src/commandLine/shell.ts index c735a88..9dd5d76 100644 --- a/src/packages/pongo/src/commandLine/shell.ts +++ b/src/packages/pongo/src/commandLine/shell.ts @@ -1,8 +1,11 @@ +import { JSONSerializer } from '@event-driven-io/dumbo'; import chalk from 'chalk'; import Table from 'cli-table3'; import { Command } from 'commander'; import repl from 'node:repl'; -import { pongoClient, pongoSchema } from '../core'; +import { pongoClient, pongoSchema, type PongoClient } from '../core'; + +let pongo: PongoClient; const calculateColumnWidths = ( // eslint-disable-next-line @typescript-eslint/no-explicit-any @@ -23,10 +26,16 @@ const calculateColumnWidths = ( }; // eslint-disable-next-line @typescript-eslint/no-explicit-any -const displayResultsAsTable = (results: any[]) => { +const printOutput = (obj: any): string => { + return Array.isArray(obj) + ? displayResultsAsTable(obj) + : JSONSerializer.serialize(obj); +}; + +// eslint-disable-next-line @typescript-eslint/no-explicit-any +const displayResultsAsTable = (results: any[]): string => { if (results.length === 0) { - console.log(chalk.yellow('No documents found.')); - return; + return chalk.yellow('No documents found.'); } // eslint-disable-next-line @typescript-eslint/no-unsafe-argument @@ -48,7 +57,7 @@ const displayResultsAsTable = (results: any[]) => { ); }); - console.log(table.toString()); + return table.toString(); }; const startRepl = (options: { @@ -61,6 +70,8 @@ const startRepl = (options: { const r = repl.start({ prompt: chalk.green('pongo> '), useGlobal: true, + breakEvalOnSigint: true, + writer: printOutput, }); const schema = @@ -72,23 +83,34 @@ const startRepl = (options: { }) : undefined; - const pongo = pongoClient(options.connectionString, { + pongo = pongoClient(options.connectionString, { ...(schema ? { schema: { definition: schema } } : {}), }); - // Expose the db object to the REPL context - r.context.db = schema ? pongo.database : pongo.db(options.schema.database); + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment + const db = schema + ? // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any + (pongo as any).database + : pongo.db(options.schema.database); - // Handle default output formatting - r.context.displayResults = displayResultsAsTable; + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment + r.context.db = db; // Intercept REPL output to display results as a table if they are arrays - r.on('exit', () => { - console.log(chalk.yellow('Exiting Pongo Shell...')); + r.on('exit', async () => { + await teardown(); process.exit(); }); }; +const teardown = async () => { + console.log(chalk.yellow('Exiting Pongo Shell...')); + await pongo.close(); +}; + +process.on('uncaughtException', teardown); +process.on('SIGINT', teardown); + interface ShellOptions { database: string; collection: string[];