diff --git a/.github/workflows/run-tests.yaml b/.github/workflows/run-tests.yaml index a9d609e..97b00a5 100644 --- a/.github/workflows/run-tests.yaml +++ b/.github/workflows/run-tests.yaml @@ -57,6 +57,14 @@ jobs: POSTGRES_HOST: localhost POSTGRES_PORT: 5432 + - name: pgsql-parser + run: cd ./packages/pgsql-parser && yarn test + env: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: password + POSTGRES_HOST: localhost + POSTGRES_PORT: 5432 + - name: deparser run: cd ./packages/deparser && yarn test env: @@ -65,6 +73,9 @@ jobs: POSTGRES_HOST: localhost POSTGRES_PORT: 5432 + - name: pgsql-enums + run: cd ./packages/pgsql-enums && yarn test + - name: enums run: cd ./packages/enums && yarn test diff --git a/README.md b/README.md index 00bce00..07f5d6d 100644 --- a/README.md +++ b/README.md @@ -150,7 +150,7 @@ Our latest is built with `13-latest` branch from libpg_query * [pgsql-parser](https://github.com/launchql/pgsql-parser): The real PostgreSQL parser for Node.js, providing symmetric parsing and deparsing of SQL statements with actual PostgreSQL parser integration. * [pgsql-deparser](https://github.com/launchql/pgsql-parser/tree/main/packages/deparser): A streamlined tool designed for converting PostgreSQL ASTs back into SQL queries, focusing solely on deparser functionality to complement `pgsql-parser`. -* [pgsql-enums](https://github.com/launchql/pgsql-parser/tree/main/packages/enums-json): A utility package offering easy access to PostgreSQL enumeration types in JSON format, aiding in string and integer conversions of enums used within ASTs to compliment `pgsql-parser` +* [pgsql-enums](https://github.com/launchql/pgsql-parser/tree/main/packages/pgsql-enums): A utility package offering easy access to PostgreSQL enumeration types in JSON format, aiding in string and integer conversions of enums used within ASTs to compliment `pgsql-parser` * [@pgsql/enums](https://github.com/launchql/pgsql-parser/tree/main/packages/enums): Provides PostgreSQL AST enums in TypeScript, enhancing type safety and usability in projects interacting with PostgreSQL AST nodes. * [@pgsql/types](https://github.com/launchql/pgsql-parser/tree/main/packages/types): Offers TypeScript type definitions for PostgreSQL AST nodes, facilitating type-safe construction, analysis, and manipulation of ASTs. * [@pgsql/utils](https://github.com/launchql/pgsql-parser/tree/main/packages/utils): A comprehensive utility library for PostgreSQL, offering type-safe AST node creation and enum value conversions, simplifying the construction and manipulation of PostgreSQL ASTs. diff --git a/packages/deparser/README.md b/packages/deparser/README.md index 4fa7df8..4bc754b 100644 --- a/packages/deparser/README.md +++ b/packages/deparser/README.md @@ -89,7 +89,7 @@ Our latest is built with `13-latest` branch from libpg_query * [pgsql-parser](https://github.com/launchql/pgsql-parser): The real PostgreSQL parser for Node.js, providing symmetric parsing and deparsing of SQL statements with actual PostgreSQL parser integration. * [pgsql-deparser](https://github.com/launchql/pgsql-parser/tree/main/packages/deparser): A streamlined tool designed for converting PostgreSQL ASTs back into SQL queries, focusing solely on deparser functionality to complement `pgsql-parser`. -* [pgsql-enums](https://github.com/launchql/pgsql-parser/tree/main/packages/enums-json): A utility package offering easy access to PostgreSQL enumeration types in JSON format, aiding in string and integer conversions of enums used within ASTs to compliment `pgsql-parser` +* [pgsql-enums](https://github.com/launchql/pgsql-parser/tree/main/packages/pgsql-enums): A utility package offering easy access to PostgreSQL enumeration types in JSON format, aiding in string and integer conversions of enums used within ASTs to compliment `pgsql-parser` * [@pgsql/enums](https://github.com/launchql/pgsql-parser/tree/main/packages/enums): Provides PostgreSQL AST enums in TypeScript, enhancing type safety and usability in projects interacting with PostgreSQL AST nodes. * [@pgsql/types](https://github.com/launchql/pgsql-parser/tree/main/packages/types): Offers TypeScript type definitions for PostgreSQL AST nodes, facilitating type-safe construction, analysis, and manipulation of ASTs. * [@pgsql/utils](https://github.com/launchql/pgsql-parser/tree/main/packages/utils): A comprehensive utility library for PostgreSQL, offering type-safe AST node creation and enum value conversions, simplifying the construction and manipulation of PostgreSQL ASTs. diff --git a/packages/enums/README.md b/packages/enums/README.md index 5157731..9c0ffa0 100644 --- a/packages/enums/README.md +++ b/packages/enums/README.md @@ -50,7 +50,7 @@ In this example, `A_Expr_Kind` is an enum imported from `@pgsql/enums`, and expr * [pgsql-parser](https://github.com/launchql/pgsql-parser): The real PostgreSQL parser for Node.js, providing symmetric parsing and deparsing of SQL statements with actual PostgreSQL parser integration. * [pgsql-deparser](https://github.com/launchql/pgsql-parser/tree/main/packages/deparser): A streamlined tool designed for converting PostgreSQL ASTs back into SQL queries, focusing solely on deparser functionality to complement `pgsql-parser`. -* [pgsql-enums](https://github.com/launchql/pgsql-parser/tree/main/packages/enums-json): A utility package offering easy access to PostgreSQL enumeration types in JSON format, aiding in string and integer conversions of enums used within ASTs to compliment `pgsql-parser` +* [pgsql-enums](https://github.com/launchql/pgsql-parser/tree/main/packages/pgsql-enums): A utility package offering easy access to PostgreSQL enumeration types in JSON format, aiding in string and integer conversions of enums used within ASTs to compliment `pgsql-parser` * [@pgsql/enums](https://github.com/launchql/pgsql-parser/tree/main/packages/enums): Provides PostgreSQL AST enums in TypeScript, enhancing type safety and usability in projects interacting with PostgreSQL AST nodes. * [@pgsql/types](https://github.com/launchql/pgsql-parser/tree/main/packages/types): Offers TypeScript type definitions for PostgreSQL AST nodes, facilitating type-safe construction, analysis, and manipulation of ASTs. * [@pgsql/utils](https://github.com/launchql/pgsql-parser/tree/main/packages/utils): A comprehensive utility library for PostgreSQL, offering type-safe AST node creation and enum value conversions, simplifying the construction and manipulation of PostgreSQL ASTs. diff --git a/packages/parser/README.md b/packages/parser/README.md index 00bce00..19cc679 100644 --- a/packages/parser/README.md +++ b/packages/parser/README.md @@ -1,4 +1,4 @@ -# pgsql-parser +# @pgsql/parser

@@ -14,12 +14,14 @@

-The real PostgreSQL parser for Node.js, `pgsql-parser` provides symmetric parsing and deparsing of SQL statements using the actual [PostgreSQL parser](https://github.com/pganalyze/libpg_query). It allows you to parse SQL queries into AST and modify or reconstruct SQL queries from the AST. +**NOTE:** This version of `@pgsql/parser` only contains the parsing functionality, optimized for users who do not require deparsing capabilities. This version is specifically tailored for PostgreSQL 16. + +The real PostgreSQL parser for Node.js, `@pgsql/parser` offers the ability to parse SQL statements into ASTs using the actual [PostgreSQL parser](https://github.com/pganalyze/libpg_query). It enables users to parse SQL queries into AST format for further manipulation and analysis. Deparsing functionality is (yet) not included in this package. ## Installation ```sh -npm install pgsql-parser +npm install @pgsql/parser ``` ## Key Features @@ -33,61 +35,15 @@ npm install pgsql-parser Rewrite part of a SQL query: ```js -import { parse, deparse } from 'pgsql-parser'; +import { parse } from '@pgsql/parser'; const stmts = parse('SELECT * FROM test_table'); - -// Assuming the structure of stmts is known and matches the expected type -stmts[0].RawStmt.stmt.SelectStmt.fromClause[0].RangeVar.relname = 'another_table'; - -console.log(deparse(stmts)); - -// SELECT * FROM "another_table" -``` - -## Deparser Example - -The `pgsql-deparser` module serializes ASTs to SQL in pure TypeScript, avoiding the full parser's native dependencies. It's useful when only SQL string conversion from ASTs is needed, and is written in pure TypeScript for easy cross-environment deployment. - -Here's how you can use the deparser in your TypeScript code, using [`@pgsql/utils`](https://github.com/launchql/pgsql-parser/tree/main/packages/utils) to create an AST for `deparse`: - -```ts -import ast, { SelectStmt } from '@pgsql/utils'; -import { deparse } from 'pgsql-deparser'; - -// This could have been obtained from any JSON or AST, not necessarily @pgsql/utils -const stmt: SelectStmt = ast.selectStmt({ - targetList: [ - ast.resTarget({ - val: ast.columnRef({ - fields: [ast.aStar()] - }) - }) - ], - fromClause: [ - ast.rangeVar({ - relname: 'some_table', - inh: true, - relpersistence: 'p' - }) - ], - limitOption: 'LIMIT_OPTION_DEFAULT', - op: 'SETOP_NONE' -}); - -// Modify the AST if needed -stmt.SelectStmt.fromClause[0].RangeVar.relname = 'another_table'; - -// Deparse the modified AST back to a SQL string -console.log(deparse(stmts)); - -// Output: SELECT * FROM another_table ``` ## CLI ``` -npm install -g pgsql-parser +npm install -g @pgsql/parser ``` ### usage @@ -140,7 +96,10 @@ Our latest is built with `13-latest` branch from libpg_query | PostgreSQL Major Version | libpg_query | Status | npm |--------------------------|-------------|---------------------|---------| -| 13 | 13-latest | Active development | `latest` +| 16 | 16-latest | Active development | `latest` +| 15 | (n/a) | Not supported | +| 14 | (n/a) | Not supported | +| 13 | 13-latest | use `pgsql-parser` | | 12 | (n/a) | Not supported | | 11 | (n/a) | Not supported | | 10 | 10-latest | Not supported | `@1.3.1` ([tree](https://github.com/launchql/pgsql-parser/tree/39b7b1adc8914253226e286a48105785219a81ca)) | @@ -150,7 +109,7 @@ Our latest is built with `13-latest` branch from libpg_query * [pgsql-parser](https://github.com/launchql/pgsql-parser): The real PostgreSQL parser for Node.js, providing symmetric parsing and deparsing of SQL statements with actual PostgreSQL parser integration. * [pgsql-deparser](https://github.com/launchql/pgsql-parser/tree/main/packages/deparser): A streamlined tool designed for converting PostgreSQL ASTs back into SQL queries, focusing solely on deparser functionality to complement `pgsql-parser`. -* [pgsql-enums](https://github.com/launchql/pgsql-parser/tree/main/packages/enums-json): A utility package offering easy access to PostgreSQL enumeration types in JSON format, aiding in string and integer conversions of enums used within ASTs to compliment `pgsql-parser` +* [pgsql-enums](https://github.com/launchql/pgsql-parser/tree/main/packages/pgsql-enums): A utility package offering easy access to PostgreSQL enumeration types in JSON format, aiding in string and integer conversions of enums used within ASTs to compliment `pgsql-parser` * [@pgsql/enums](https://github.com/launchql/pgsql-parser/tree/main/packages/enums): Provides PostgreSQL AST enums in TypeScript, enhancing type safety and usability in projects interacting with PostgreSQL AST nodes. * [@pgsql/types](https://github.com/launchql/pgsql-parser/tree/main/packages/types): Offers TypeScript type definitions for PostgreSQL AST nodes, facilitating type-safe construction, analysis, and manipulation of ASTs. * [@pgsql/utils](https://github.com/launchql/pgsql-parser/tree/main/packages/utils): A comprehensive utility library for PostgreSQL, offering type-safe AST node creation and enum value conversions, simplifying the construction and manipulation of PostgreSQL ASTs. diff --git a/packages/parser/__tests__/__snapshots__/async.test.ts.snap b/packages/parser/__tests__/__snapshots__/async.test.ts.snap index 447442d..00aeb59 100644 --- a/packages/parser/__tests__/__snapshots__/async.test.ts.snap +++ b/packages/parser/__tests__/__snapshots__/async.test.ts.snap @@ -46,7 +46,7 @@ exports[`works 1`] = ` "fields": [ { "String": { - "str": "health_grade", + "sval": "health_grade", }, }, ], @@ -57,17 +57,15 @@ exports[`works 1`] = ` "name": [ { "String": { - "str": "=", + "sval": "=", }, }, ], "rexpr": { "A_Const": { "location": undefined, - "val": { - "String": { - "str": "A", - }, + "sval": { + "sval": "A", }, }, }, @@ -81,7 +79,7 @@ exports[`works 1`] = ` "fields": [ { "String": { - "str": "average_rating", + "sval": "average_rating", }, }, ], @@ -92,18 +90,16 @@ exports[`works 1`] = ` "name": [ { "String": { - "str": ">=", + "sval": ">=", }, }, ], "rexpr": { "A_Const": { - "location": undefined, - "val": { - "Float": { - "str": "4.5", - }, + "fval": { + "fval": "4.5", }, + "location": undefined, }, }, }, diff --git a/packages/parser/__tests__/__snapshots__/funcs.test.ts.snap b/packages/parser/__tests__/__snapshots__/funcs.test.ts.snap index 9b25a67..741e6ba 100644 --- a/packages/parser/__tests__/__snapshots__/funcs.test.ts.snap +++ b/packages/parser/__tests__/__snapshots__/funcs.test.ts.snap @@ -11,7 +11,8 @@ exports[`works 1`] = ` "PLpgSQL_stmt_assign": { "expr": { "PLpgSQL_expr": { - "query": "SELECT ast.jsonb_set(result, '{IndexElem, name}', to_jsonb(v_name))", + "parseMode": 3, + "query": "result = ast.jsonb_set(result, '{IndexElem, name}', to_jsonb(v_name))", }, }, "lineno": 5, @@ -22,7 +23,8 @@ exports[`works 1`] = ` "PLpgSQL_stmt_assign": { "expr": { "PLpgSQL_expr": { - "query": "SELECT ast.jsonb_set(result, '{IndexElem, ordering}', to_jsonb(v_ordering))", + "parseMode": 3, + "query": "result = ast.jsonb_set(result, '{IndexElem, ordering}', to_jsonb(v_ordering))", }, }, "lineno": 6, @@ -33,7 +35,8 @@ exports[`works 1`] = ` "PLpgSQL_stmt_assign": { "expr": { "PLpgSQL_expr": { - "query": "SELECT ast.jsonb_set(result, '{IndexElem, nulls_ordering}', to_jsonb(v_nulls_ordering))", + "parseMode": 3, + "query": "result = ast.jsonb_set(result, '{IndexElem, nulls_ordering}', to_jsonb(v_nulls_ordering))", }, }, "lineno": 7, @@ -44,7 +47,8 @@ exports[`works 1`] = ` "PLpgSQL_stmt_assign": { "expr": { "PLpgSQL_expr": { - "query": "SELECT ast.jsonb_set(result, '{IndexElem, expr}', v_expr)", + "parseMode": 3, + "query": "result = ast.jsonb_set(result, '{IndexElem, expr}', v_expr)", }, }, "lineno": 8, @@ -55,7 +59,8 @@ exports[`works 1`] = ` "PLpgSQL_stmt_assign": { "expr": { "PLpgSQL_expr": { - "query": "SELECT ast.jsonb_set(result, '{IndexElem, opclass}', v_opclass)", + "parseMode": 3, + "query": "result = ast.jsonb_set(result, '{IndexElem, opclass}', v_opclass)", }, }, "lineno": 9, @@ -66,7 +71,8 @@ exports[`works 1`] = ` "PLpgSQL_stmt_assign": { "expr": { "PLpgSQL_expr": { - "query": "SELECT ast.jsonb_set(result, '{IndexElem, collation}', v_collation)", + "parseMode": 3, + "query": "result = ast.jsonb_set(result, '{IndexElem, collation}', v_collation)", }, }, "lineno": 10, @@ -77,7 +83,8 @@ exports[`works 1`] = ` "PLpgSQL_stmt_return": { "expr": { "PLpgSQL_expr": { - "query": "SELECT result", + "parseMode": 2, + "query": "result", }, }, "lineno": 11, @@ -167,7 +174,8 @@ exports[`works 1`] = ` }, "default_val": { "PLpgSQL_expr": { - "query": "SELECT '{"IndexElem":{}}'::jsonb", + "parseMode": 2, + "query": "'{"IndexElem":{}}'::jsonb", }, }, "lineno": 3, diff --git a/packages/parser/package.json b/packages/parser/package.json index b42c29c..1b116d6 100644 --- a/packages/parser/package.json +++ b/packages/parser/package.json @@ -1,6 +1,6 @@ { - "name": "pgsql-parser", - "version": "13.15.0", + "name": "@pgsql/parser", + "version": "16.0.0-testing", "description": "The real PostgreSQL query parser", "author": "Dan Lynch ", "homepage": "https://github.com/launchql/pgsql-parser", @@ -84,9 +84,8 @@ "typescript": "^5.0.4" }, "dependencies": { - "libpg-query": "13.3.2", + "libpg-query": "16.1.0", "minimist": "^1.2.6", - "pgsql-deparser": "^13.14.0", - "pgsql-enums": "^13.9.0" + "@pgsql/types": "13.8.0" } } diff --git a/packages/parser/src/index.ts b/packages/parser/src/index.ts index 31cc43e..6696d3a 100644 --- a/packages/parser/src/index.ts +++ b/packages/parser/src/index.ts @@ -1,4 +1,5 @@ -import { Deparser, deparse } from 'pgsql-deparser'; +import { Node } from '@pgsql/types'; + import { parseQuery, parseQuerySync, @@ -15,7 +16,7 @@ function mapStmt({ stmt, stmt_len, stmt_location }) { }; } -export const parse = (sql) => { +export const parse = (sql): Node => { if (!sql) throw new Error('no SQL provided to parser'); const result = parseQuerySync(sql); return result.stmts.map(mapStmt); @@ -27,4 +28,4 @@ export const parseAsync = async (sql) => { return result.stmts.map(mapStmt); }; -export { deparse, Deparser, parseFunction }; +export { parseFunction }; diff --git a/packages/enums-json/.editorconfig b/packages/pgsql-enums/.editorconfig similarity index 100% rename from packages/enums-json/.editorconfig rename to packages/pgsql-enums/.editorconfig diff --git a/packages/enums-json/.eslintignore b/packages/pgsql-enums/.eslintignore similarity index 100% rename from packages/enums-json/.eslintignore rename to packages/pgsql-enums/.eslintignore diff --git a/packages/enums-json/.eslintrc.js b/packages/pgsql-enums/.eslintrc.js similarity index 100% rename from packages/enums-json/.eslintrc.js rename to packages/pgsql-enums/.eslintrc.js diff --git a/packages/enums-json/.gitignore b/packages/pgsql-enums/.gitignore similarity index 100% rename from packages/enums-json/.gitignore rename to packages/pgsql-enums/.gitignore diff --git a/packages/enums-json/.npmignore b/packages/pgsql-enums/.npmignore similarity index 100% rename from packages/enums-json/.npmignore rename to packages/pgsql-enums/.npmignore diff --git a/packages/enums-json/.npmrc b/packages/pgsql-enums/.npmrc similarity index 100% rename from packages/enums-json/.npmrc rename to packages/pgsql-enums/.npmrc diff --git a/packages/enums-json/CHANGELOG.md b/packages/pgsql-enums/CHANGELOG.md similarity index 100% rename from packages/enums-json/CHANGELOG.md rename to packages/pgsql-enums/CHANGELOG.md diff --git a/packages/enums-json/LICENSE b/packages/pgsql-enums/LICENSE similarity index 100% rename from packages/enums-json/LICENSE rename to packages/pgsql-enums/LICENSE diff --git a/packages/enums-json/README.md b/packages/pgsql-enums/README.md similarity index 96% rename from packages/enums-json/README.md rename to packages/pgsql-enums/README.md index a3346e6..d0bc944 100644 --- a/packages/enums-json/README.md +++ b/packages/pgsql-enums/README.md @@ -110,7 +110,7 @@ console.log(getConstraintFromConstrType('CONSTR_CHECK')); // Outputs 'CHECK' * [pgsql-parser](https://github.com/launchql/pgsql-parser): The real PostgreSQL parser for Node.js, providing symmetric parsing and deparsing of SQL statements with actual PostgreSQL parser integration. * [pgsql-deparser](https://github.com/launchql/pgsql-parser/tree/main/packages/deparser): A streamlined tool designed for converting PostgreSQL ASTs back into SQL queries, focusing solely on deparser functionality to complement `pgsql-parser`. -* [pgsql-enums](https://github.com/launchql/pgsql-parser/tree/main/packages/enums-json): A utility package offering easy access to PostgreSQL enumeration types in JSON format, aiding in string and integer conversions of enums used within ASTs to compliment `pgsql-parser` +* [pgsql-enums](https://github.com/launchql/pgsql-parser/tree/main/packages/pgsql-enums): A utility package offering easy access to PostgreSQL enumeration types in JSON format, aiding in string and integer conversions of enums used within ASTs to compliment `pgsql-parser` * [@pgsql/enums](https://github.com/launchql/pgsql-parser/tree/main/packages/enums): Provides PostgreSQL AST enums in TypeScript, enhancing type safety and usability in projects interacting with PostgreSQL AST nodes. * [@pgsql/types](https://github.com/launchql/pgsql-parser/tree/main/packages/types): Offers TypeScript type definitions for PostgreSQL AST nodes, facilitating type-safe construction, analysis, and manipulation of ASTs. * [@pgsql/utils](https://github.com/launchql/pgsql-parser/tree/main/packages/utils): A comprehensive utility library for PostgreSQL, offering type-safe AST node creation and enum value conversions, simplifying the construction and manipulation of PostgreSQL ASTs. diff --git a/packages/enums-json/__test__/enums.test.ts b/packages/pgsql-enums/__test__/enums.test.ts similarity index 100% rename from packages/enums-json/__test__/enums.test.ts rename to packages/pgsql-enums/__test__/enums.test.ts diff --git a/packages/enums-json/package.json b/packages/pgsql-enums/package.json similarity index 100% rename from packages/enums-json/package.json rename to packages/pgsql-enums/package.json diff --git a/packages/enums-json/scripts/index.js b/packages/pgsql-enums/scripts/index.js similarity index 100% rename from packages/enums-json/scripts/index.js rename to packages/pgsql-enums/scripts/index.js diff --git a/packages/enums-json/scripts/libpg_enums.js b/packages/pgsql-enums/scripts/libpg_enums.js similarity index 100% rename from packages/enums-json/scripts/libpg_enums.js rename to packages/pgsql-enums/scripts/libpg_enums.js diff --git a/packages/enums-json/scripts/libpg_structs.js b/packages/pgsql-enums/scripts/libpg_structs.js similarity index 100% rename from packages/enums-json/scripts/libpg_structs.js rename to packages/pgsql-enums/scripts/libpg_structs.js diff --git a/packages/enums-json/scripts/pg-proto-parser.ts b/packages/pgsql-enums/scripts/pg-proto-parser.ts similarity index 100% rename from packages/enums-json/scripts/pg-proto-parser.ts rename to packages/pgsql-enums/scripts/pg-proto-parser.ts diff --git a/packages/enums-json/src/enums2int.json b/packages/pgsql-enums/src/enums2int.json similarity index 100% rename from packages/enums-json/src/enums2int.json rename to packages/pgsql-enums/src/enums2int.json diff --git a/packages/enums-json/src/enums2str.json b/packages/pgsql-enums/src/enums2str.json similarity index 100% rename from packages/enums-json/src/enums2str.json rename to packages/pgsql-enums/src/enums2str.json diff --git a/packages/enums-json/src/index.ts b/packages/pgsql-enums/src/index.ts similarity index 100% rename from packages/enums-json/src/index.ts rename to packages/pgsql-enums/src/index.ts diff --git a/packages/enums-json/src/nodes.json b/packages/pgsql-enums/src/nodes.json similarity index 100% rename from packages/enums-json/src/nodes.json rename to packages/pgsql-enums/src/nodes.json diff --git a/packages/enums-json/src/types.ts b/packages/pgsql-enums/src/types.ts similarity index 100% rename from packages/enums-json/src/types.ts rename to packages/pgsql-enums/src/types.ts diff --git a/packages/enums-json/tsconfig.json b/packages/pgsql-enums/tsconfig.json similarity index 100% rename from packages/enums-json/tsconfig.json rename to packages/pgsql-enums/tsconfig.json diff --git a/packages/enums-json/types/enums/enums.d.ts b/packages/pgsql-enums/types/enums/enums.d.ts similarity index 100% rename from packages/enums-json/types/enums/enums.d.ts rename to packages/pgsql-enums/types/enums/enums.d.ts diff --git a/packages/enums-json/types/index.d.ts b/packages/pgsql-enums/types/index.d.ts similarity index 100% rename from packages/enums-json/types/index.d.ts rename to packages/pgsql-enums/types/index.d.ts diff --git a/packages/enums-json/types/nodes.d.ts b/packages/pgsql-enums/types/nodes.d.ts similarity index 100% rename from packages/enums-json/types/nodes.d.ts rename to packages/pgsql-enums/types/nodes.d.ts diff --git a/packages/enums-json/types/types.d.ts b/packages/pgsql-enums/types/types.d.ts similarity index 100% rename from packages/enums-json/types/types.d.ts rename to packages/pgsql-enums/types/types.d.ts diff --git a/packages/pgsql-parser/.editorconfig b/packages/pgsql-parser/.editorconfig new file mode 100644 index 0000000..4a7ea30 --- /dev/null +++ b/packages/pgsql-parser/.editorconfig @@ -0,0 +1,12 @@ +root = true + +[*] +indent_style = space +indent_size = 2 +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true + +[*.md] +trim_trailing_whitespace = false diff --git a/packages/pgsql-parser/.eslintignore b/packages/pgsql-parser/.eslintignore new file mode 100644 index 0000000..38ba484 --- /dev/null +++ b/packages/pgsql-parser/.eslintignore @@ -0,0 +1,5 @@ +node_modules/ +dist/ +main/ +module/ +coverage/ \ No newline at end of file diff --git a/packages/pgsql-parser/.eslintrc.js b/packages/pgsql-parser/.eslintrc.js new file mode 100644 index 0000000..4935e71 --- /dev/null +++ b/packages/pgsql-parser/.eslintrc.js @@ -0,0 +1,71 @@ +module.exports = { + plugins: ['prettier'], + extends: ['eslint:recommended', 'prettier'], + parser: 'esprima', + parserOptions: { + ecmaVersion: 11, + requireConfigFile: false, + sourceType: 'module', + ecmaFeatures: { + jsx: true + } + }, + env: { + es6: true, + browser: true, + node: true, + jest: true + }, + rules: { + 'no-debugger': 2, + 'no-alert': 2, + 'no-await-in-loop': 0, + 'no-prototype-builtins': 0, + 'no-return-assign': ['error', 'except-parens'], + 'no-restricted-syntax': [ + 2, + 'ForInStatement', + 'LabeledStatement', + 'WithStatement' + ], + 'no-unused-vars': [ + 0, + { + ignoreSiblings: true, + argsIgnorePattern: 'React|res|next|^_' + } + ], + 'prefer-const': [ + 'error', + { + destructuring: 'all' + } + ], + 'no-unused-expressions': [ + 2, + { + allowTaggedTemplates: true + } + ], + 'no-console': 1, + 'comma-dangle': 2, + 'jsx-quotes': [2, 'prefer-double'], + 'linebreak-style': ['error', 'unix'], + quotes: [ + 2, + 'single', + { + avoidEscape: true, + allowTemplateLiterals: true + } + ], + 'prettier/prettier': [ + 'error', + { + trailingComma: 'none', + singleQuote: true, + printWidth: 80 + } + ] + } +}; diff --git a/packages/pgsql-parser/.gitignore b/packages/pgsql-parser/.gitignore new file mode 100644 index 0000000..d93985e --- /dev/null +++ b/packages/pgsql-parser/.gitignore @@ -0,0 +1,48 @@ +# Logs +logs +*.log +npm-debug.log* + +# Runtime data +pids +*.pid +*.seed + +# dist +main +module + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage + +# nyc test coverage +.nyc_output + +# Compiled binary addons (http://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules +jspm_packages + +# Optional npm cache directory +.npm + +# Optional REPL history +.node_repl_history + +# Editors +.idea + +# Lib +lib + +# npm package lock +package-lock.json +yarn.lock + +# others +.DS_Store \ No newline at end of file diff --git a/packages/pgsql-parser/.npmignore b/packages/pgsql-parser/.npmignore new file mode 100644 index 0000000..b8f6a37 --- /dev/null +++ b/packages/pgsql-parser/.npmignore @@ -0,0 +1,33 @@ +*.log +npm-debug.log* + +protobuf +out +*.proto + +# snapshots +*.snap + +# Coverage directory used by tools like istanbul +coverage +.nyc_output + +# Dependency directories +node_modules + +# npm package lock +package-lock.json +yarn.lock + +# project files +__snapshots__ +__fixtures__ +__tests__ +.editorconfig +.eslintignore +.eslintrc.js +.gitignore +.travis.yml +.vscode +CHANGELOG.md +package.json diff --git a/packages/pgsql-parser/.npmrc b/packages/pgsql-parser/.npmrc new file mode 100644 index 0000000..a21347f --- /dev/null +++ b/packages/pgsql-parser/.npmrc @@ -0,0 +1 @@ +scripts-prepend-node-path=true \ No newline at end of file diff --git a/packages/parser/CHANGELOG.md b/packages/pgsql-parser/CHANGELOG.md similarity index 100% rename from packages/parser/CHANGELOG.md rename to packages/pgsql-parser/CHANGELOG.md diff --git a/packages/pgsql-parser/LICENSE b/packages/pgsql-parser/LICENSE new file mode 100644 index 0000000..d9141ef --- /dev/null +++ b/packages/pgsql-parser/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2020 Dan Lynch + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/packages/pgsql-parser/README.md b/packages/pgsql-parser/README.md new file mode 100644 index 0000000..07f5d6d --- /dev/null +++ b/packages/pgsql-parser/README.md @@ -0,0 +1,178 @@ +# pgsql-parser + +

+ +

+ +

+ + + + + + + +

+ +The real PostgreSQL parser for Node.js, `pgsql-parser` provides symmetric parsing and deparsing of SQL statements using the actual [PostgreSQL parser](https://github.com/pganalyze/libpg_query). It allows you to parse SQL queries into AST and modify or reconstruct SQL queries from the AST. + +## Installation + +```sh +npm install pgsql-parser +``` + +## Key Features + +- **True PostgreSQL Parsing:** Utilizes the real PostgreSQL source code for accurate parsing. +- **Symmetric Parsing and Deparsing:** Convert SQL to AST and back, enabling query manipulation. +- **AST Manipulation:** Easily modify parts of a SQL statement through the AST. + +## Parser Example + +Rewrite part of a SQL query: + +```js +import { parse, deparse } from 'pgsql-parser'; + +const stmts = parse('SELECT * FROM test_table'); + +// Assuming the structure of stmts is known and matches the expected type +stmts[0].RawStmt.stmt.SelectStmt.fromClause[0].RangeVar.relname = 'another_table'; + +console.log(deparse(stmts)); + +// SELECT * FROM "another_table" +``` + +## Deparser Example + +The `pgsql-deparser` module serializes ASTs to SQL in pure TypeScript, avoiding the full parser's native dependencies. It's useful when only SQL string conversion from ASTs is needed, and is written in pure TypeScript for easy cross-environment deployment. + +Here's how you can use the deparser in your TypeScript code, using [`@pgsql/utils`](https://github.com/launchql/pgsql-parser/tree/main/packages/utils) to create an AST for `deparse`: + +```ts +import ast, { SelectStmt } from '@pgsql/utils'; +import { deparse } from 'pgsql-deparser'; + +// This could have been obtained from any JSON or AST, not necessarily @pgsql/utils +const stmt: SelectStmt = ast.selectStmt({ + targetList: [ + ast.resTarget({ + val: ast.columnRef({ + fields: [ast.aStar()] + }) + }) + ], + fromClause: [ + ast.rangeVar({ + relname: 'some_table', + inh: true, + relpersistence: 'p' + }) + ], + limitOption: 'LIMIT_OPTION_DEFAULT', + op: 'SETOP_NONE' +}); + +// Modify the AST if needed +stmt.SelectStmt.fromClause[0].RangeVar.relname = 'another_table'; + +// Deparse the modified AST back to a SQL string +console.log(deparse(stmts)); + +// Output: SELECT * FROM another_table +``` + +## CLI + +``` +npm install -g pgsql-parser +``` + +### usage + +```sh +pgsql-parser +``` + +### Documentation + +### `parser.parse(sql)` + +Parses the query and returns a parse object. + +### Parameters + +| parameter | type | description | +| -------------------- | ------------------ | --------------------------------------------------------- | +| `query` | String | SQL query | + +Returns an object in the format: + +``` +{ query: , + error: { message: , + fileName: , + lineNumber: , + cursorPosition: } +``` + +### `parser.deparse(query)` + +Deparses the query tree and returns a formatted SQL statement. This function takes as input a query AST +in the same format as the `query` property of on the result of the `parse` method. This is the primary +functionality of this module. + +### Parameters + +| parameter | type | description | +| -------------------- | ------------------ | --------------------------------------------------------- | +| `query` | Object | Query tree obtained from `parse` | + +Returns a normalized formatted SQL string. + +## Versions + +As of PG 13, PG majors versions maintained will have a matching dedicated major npm version. Only the latest Postgres stable release receives active updates. + +Our latest is built with `13-latest` branch from libpg_query + +| PostgreSQL Major Version | libpg_query | Status | npm +|--------------------------|-------------|---------------------|---------| +| 13 | 13-latest | Active development | `latest` +| 12 | (n/a) | Not supported | +| 11 | (n/a) | Not supported | +| 10 | 10-latest | Not supported | `@1.3.1` ([tree](https://github.com/launchql/pgsql-parser/tree/39b7b1adc8914253226e286a48105785219a81ca)) | + + +## Related + +* [pgsql-parser](https://github.com/launchql/pgsql-parser): The real PostgreSQL parser for Node.js, providing symmetric parsing and deparsing of SQL statements with actual PostgreSQL parser integration. +* [pgsql-deparser](https://github.com/launchql/pgsql-parser/tree/main/packages/deparser): A streamlined tool designed for converting PostgreSQL ASTs back into SQL queries, focusing solely on deparser functionality to complement `pgsql-parser`. +* [pgsql-enums](https://github.com/launchql/pgsql-parser/tree/main/packages/pgsql-enums): A utility package offering easy access to PostgreSQL enumeration types in JSON format, aiding in string and integer conversions of enums used within ASTs to compliment `pgsql-parser` +* [@pgsql/enums](https://github.com/launchql/pgsql-parser/tree/main/packages/enums): Provides PostgreSQL AST enums in TypeScript, enhancing type safety and usability in projects interacting with PostgreSQL AST nodes. +* [@pgsql/types](https://github.com/launchql/pgsql-parser/tree/main/packages/types): Offers TypeScript type definitions for PostgreSQL AST nodes, facilitating type-safe construction, analysis, and manipulation of ASTs. +* [@pgsql/utils](https://github.com/launchql/pgsql-parser/tree/main/packages/utils): A comprehensive utility library for PostgreSQL, offering type-safe AST node creation and enum value conversions, simplifying the construction and manipulation of PostgreSQL ASTs. +* [pg-proto-parser](https://github.com/launchql/pg-proto-parser): A TypeScript tool that parses PostgreSQL Protocol Buffers definitions to generate TypeScript interfaces, utility functions, and JSON mappings for enums. +* [libpg-query](https://github.com/launchql/libpg-query-node): The real PostgreSQL parser exposed for Node.js, used primarily in `pgsql-parser` for parsing and deparsing SQL queries. + +Thanks [@lfittl](https://github.com/lfittl) for building the core `libpg_query` suite: + +* [libpg_query](https://github.com/pganalyze/libpg_query) +* [pg_query](https://github.com/lfittl/pg_query) +* [pg_query.go](https://github.com/lfittl/pg_query.go) + +## Credits + +Thanks to [@zhm](https://github.com/zhm) for the OG parser that started it all: + +* [pg-query-parser](https://github.com/zhm/pg-query-parser) +* [pg-query-native](https://github.com/zhm/node-pg-query-native) +* [Original LICENSE](https://github.com/zhm/pg-query-parser/blob/master/LICENSE.md) + +## Disclaimer + +AS DESCRIBED IN THE LICENSES, THE SOFTWARE IS PROVIDED “AS IS”, AT YOUR OWN RISK, AND WITHOUT WARRANTIES OF ANY KIND. + +No developer or entity involved in creating Software will be liable for any claims or damages whatsoever associated with your use, inability to use, or your interaction with other users of the Software code or Software CLI, including any direct, indirect, incidental, special, exemplary, punitive or consequential damages, or loss of profits, cryptocurrencies, tokens, or anything else of value. \ No newline at end of file diff --git a/packages/pgsql-parser/__tests__/__snapshots__/async.test.ts.snap b/packages/pgsql-parser/__tests__/__snapshots__/async.test.ts.snap new file mode 100644 index 0000000..447442d --- /dev/null +++ b/packages/pgsql-parser/__tests__/__snapshots__/async.test.ts.snap @@ -0,0 +1,123 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`works 1`] = ` +[ + { + "RawStmt": { + "stmt": { + "SelectStmt": { + "fromClause": [ + { + "RangeVar": { + "inh": true, + "location": undefined, + "relname": "restaurants", + "relpersistence": "p", + }, + }, + ], + "limitOption": "LIMIT_OPTION_DEFAULT", + "op": "SETOP_NONE", + "targetList": [ + { + "ResTarget": { + "location": undefined, + "val": { + "ColumnRef": { + "fields": [ + { + "A_Star": {}, + }, + ], + "location": undefined, + }, + }, + }, + }, + ], + "whereClause": { + "BoolExpr": { + "args": [ + { + "A_Expr": { + "kind": "AEXPR_OP", + "lexpr": { + "ColumnRef": { + "fields": [ + { + "String": { + "str": "health_grade", + }, + }, + ], + "location": undefined, + }, + }, + "location": undefined, + "name": [ + { + "String": { + "str": "=", + }, + }, + ], + "rexpr": { + "A_Const": { + "location": undefined, + "val": { + "String": { + "str": "A", + }, + }, + }, + }, + }, + }, + { + "A_Expr": { + "kind": "AEXPR_OP", + "lexpr": { + "ColumnRef": { + "fields": [ + { + "String": { + "str": "average_rating", + }, + }, + ], + "location": undefined, + }, + }, + "location": undefined, + "name": [ + { + "String": { + "str": ">=", + }, + }, + ], + "rexpr": { + "A_Const": { + "location": undefined, + "val": { + "Float": { + "str": "4.5", + }, + }, + }, + }, + }, + }, + ], + "boolop": "AND_EXPR", + "location": undefined, + }, + }, + }, + }, + "stmt_len": undefined, + "stmt_location": undefined, + }, + }, +] +`; diff --git a/packages/pgsql-parser/__tests__/__snapshots__/funcs.test.ts.snap b/packages/pgsql-parser/__tests__/__snapshots__/funcs.test.ts.snap new file mode 100644 index 0000000..9b25a67 --- /dev/null +++ b/packages/pgsql-parser/__tests__/__snapshots__/funcs.test.ts.snap @@ -0,0 +1,181 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`works 1`] = ` +[ + { + "PLpgSQL_function": { + "action": { + "PLpgSQL_stmt_block": { + "body": [ + { + "PLpgSQL_stmt_assign": { + "expr": { + "PLpgSQL_expr": { + "query": "SELECT ast.jsonb_set(result, '{IndexElem, name}', to_jsonb(v_name))", + }, + }, + "lineno": 5, + "varno": 7, + }, + }, + { + "PLpgSQL_stmt_assign": { + "expr": { + "PLpgSQL_expr": { + "query": "SELECT ast.jsonb_set(result, '{IndexElem, ordering}', to_jsonb(v_ordering))", + }, + }, + "lineno": 6, + "varno": 7, + }, + }, + { + "PLpgSQL_stmt_assign": { + "expr": { + "PLpgSQL_expr": { + "query": "SELECT ast.jsonb_set(result, '{IndexElem, nulls_ordering}', to_jsonb(v_nulls_ordering))", + }, + }, + "lineno": 7, + "varno": 7, + }, + }, + { + "PLpgSQL_stmt_assign": { + "expr": { + "PLpgSQL_expr": { + "query": "SELECT ast.jsonb_set(result, '{IndexElem, expr}', v_expr)", + }, + }, + "lineno": 8, + "varno": 7, + }, + }, + { + "PLpgSQL_stmt_assign": { + "expr": { + "PLpgSQL_expr": { + "query": "SELECT ast.jsonb_set(result, '{IndexElem, opclass}', v_opclass)", + }, + }, + "lineno": 9, + "varno": 7, + }, + }, + { + "PLpgSQL_stmt_assign": { + "expr": { + "PLpgSQL_expr": { + "query": "SELECT ast.jsonb_set(result, '{IndexElem, collation}', v_collation)", + }, + }, + "lineno": 10, + "varno": 7, + }, + }, + { + "PLpgSQL_stmt_return": { + "expr": { + "PLpgSQL_expr": { + "query": "SELECT result", + }, + }, + "lineno": 11, + }, + }, + ], + "lineno": 4, + }, + }, + "datums": [ + { + "PLpgSQL_var": { + "datatype": { + "PLpgSQL_type": { + "typname": "UNKNOWN", + }, + }, + "refname": "v_name", + }, + }, + { + "PLpgSQL_var": { + "datatype": { + "PLpgSQL_type": { + "typname": "UNKNOWN", + }, + }, + "refname": "v_ordering", + }, + }, + { + "PLpgSQL_var": { + "datatype": { + "PLpgSQL_type": { + "typname": "UNKNOWN", + }, + }, + "refname": "v_nulls_ordering", + }, + }, + { + "PLpgSQL_var": { + "datatype": { + "PLpgSQL_type": { + "typname": "UNKNOWN", + }, + }, + "refname": "v_expr", + }, + }, + { + "PLpgSQL_var": { + "datatype": { + "PLpgSQL_type": { + "typname": "UNKNOWN", + }, + }, + "refname": "v_opclass", + }, + }, + { + "PLpgSQL_var": { + "datatype": { + "PLpgSQL_type": { + "typname": "UNKNOWN", + }, + }, + "refname": "v_collation", + }, + }, + { + "PLpgSQL_var": { + "datatype": { + "PLpgSQL_type": { + "typname": "UNKNOWN", + }, + }, + "refname": "found", + }, + }, + { + "PLpgSQL_var": { + "datatype": { + "PLpgSQL_type": { + "typname": "jsonb ", + }, + }, + "default_val": { + "PLpgSQL_expr": { + "query": "SELECT '{"IndexElem":{}}'::jsonb", + }, + }, + "lineno": 3, + "refname": "result", + }, + }, + ], + }, + }, +] +`; diff --git a/packages/parser/__tests__/__snapshots__/kitchen-sink.test.ts.snap b/packages/pgsql-parser/__tests__/__snapshots__/kitchen-sink.test.ts.snap similarity index 100% rename from packages/parser/__tests__/__snapshots__/kitchen-sink.test.ts.snap rename to packages/pgsql-parser/__tests__/__snapshots__/kitchen-sink.test.ts.snap diff --git a/packages/pgsql-parser/__tests__/async.test.ts b/packages/pgsql-parser/__tests__/async.test.ts new file mode 100644 index 0000000..0e4d67e --- /dev/null +++ b/packages/pgsql-parser/__tests__/async.test.ts @@ -0,0 +1,14 @@ +import { parseAsync } from '../src'; +import { cleanTree } from '../src/utils'; + +const testQuery = ` + SELECT * + FROM restaurants + WHERE health_grade = 'A' + AND average_rating >= 4.5; +`; + +it('works', async () => { + const results = await parseAsync(testQuery); + expect(cleanTree(results)).toMatchSnapshot(); +}); diff --git a/packages/pgsql-parser/__tests__/funcs.test.ts b/packages/pgsql-parser/__tests__/funcs.test.ts new file mode 100644 index 0000000..b4cbf7d --- /dev/null +++ b/packages/pgsql-parser/__tests__/funcs.test.ts @@ -0,0 +1,30 @@ +import { parseFunction } from '../src'; +import { cleanTree } from '../src/utils'; + +const testFunction = ` +CREATE FUNCTION ast.index_elem ( + v_name text DEFAULT NULL, + v_ordering int DEFAULT NULL, + v_nulls_ordering int DEFAULT NULL, + v_expr jsonb DEFAULT NULL, + v_opclass jsonb DEFAULT NULL, + v_collation jsonb DEFAULT NULL +) RETURNS jsonb AS $EOFCODE$ +DECLARE + result jsonb = '{"IndexElem":{}}'::jsonb; +BEGIN + result = ast.jsonb_set(result, '{IndexElem, name}', to_jsonb(v_name)); + result = ast.jsonb_set(result, '{IndexElem, ordering}', to_jsonb(v_ordering)); + result = ast.jsonb_set(result, '{IndexElem, nulls_ordering}', to_jsonb(v_nulls_ordering)); + result = ast.jsonb_set(result, '{IndexElem, expr}', v_expr); + result = ast.jsonb_set(result, '{IndexElem, opclass}', v_opclass); + result = ast.jsonb_set(result, '{IndexElem, collation}', v_collation); + RETURN result; +END; +$EOFCODE$ LANGUAGE plpgsql IMMUTABLE; + `; + +it('works', async () => { + const results = parseFunction(testFunction); + expect(cleanTree(results)).toMatchSnapshot(); +}); diff --git a/packages/parser/__tests__/kitchen-sink.test.ts b/packages/pgsql-parser/__tests__/kitchen-sink.test.ts similarity index 100% rename from packages/parser/__tests__/kitchen-sink.test.ts rename to packages/pgsql-parser/__tests__/kitchen-sink.test.ts diff --git a/packages/pgsql-parser/package.json b/packages/pgsql-parser/package.json new file mode 100644 index 0000000..b42c29c --- /dev/null +++ b/packages/pgsql-parser/package.json @@ -0,0 +1,92 @@ +{ + "name": "pgsql-parser", + "version": "13.15.0", + "description": "The real PostgreSQL query parser", + "author": "Dan Lynch ", + "homepage": "https://github.com/launchql/pgsql-parser", + "license": "SEE LICENSE IN LICENSE", + "main": "main/index.js", + "module": "module/index.js", + "typings": "types/index.d.ts", + "directories": { + "lib": "src", + "test": "__tests__" + }, + "files": [ + "types", + "module", + "src", + "main" + ], + "bin": { + "pgsql-parser": "main/cli.js" + }, + "publishConfig": { + "access": "public" + }, + "keywords": [ + "sql", + "postgres", + "postgresql", + "pg", + "parser", + "query", + "database" + ], + "repository": { + "type": "git", + "url": "https://github.com/launchql/pgsql-parser" + }, + "scripts": { + "build:main": "yarn tsc -p tsconfig.json --outDir main --module commonjs", + "build:module": "yarn tsc -p tsconfig.json --outDir module --module es2022", + "build": "npm run build:module && npm run build:main", + "buidl": "npm run build", + "buidl:clean": "npm run clean && npm run buidl", + "clean": "rimraf ./types", + "prepare": "npm run build", + "lint": "eslint .", + "format": "eslint . --fix", + "test": "jest", + "test:watch": "jest --watch", + "test:debug": "node --inspect node_modules/.bin/jest --runInBand" + }, + "bugs": { + "url": "https://github.com/launchql/pgsql-parser/issues" + }, + "jest": { + "preset": "ts-jest", + "testEnvironment": "node", + "transform": { + "^.+\\.ts?$": "ts-jest" + }, + "transformIgnorePatterns": [ + "/node_modules/" + ], + "testPathIgnorePatterns": [ + "main/", + "module/", + "types/" + ] + }, + "devDependencies": { + "@types/jest": "^29.5.0", + "eslint": "8.38.0", + "eslint-config-prettier": "^8.8.0", + "eslint-plugin-prettier": "^4.0.0", + "esprima": "4.0.1", + "glob": "8.0.3", + "jest": "^29.5.0", + "prettier": "^2.8.7", + "rimraf": "5.0.5", + "ts-jest": "^29.1.0", + "ts-node": "10.9.2", + "typescript": "^5.0.4" + }, + "dependencies": { + "libpg-query": "13.3.2", + "minimist": "^1.2.6", + "pgsql-deparser": "^13.14.0", + "pgsql-enums": "^13.9.0" + } +} diff --git a/packages/pgsql-parser/src/cli.js b/packages/pgsql-parser/src/cli.js new file mode 100644 index 0000000..aa56c4e --- /dev/null +++ b/packages/pgsql-parser/src/cli.js @@ -0,0 +1,25 @@ +#!/usr/bin/env node +import { resolve, join } from 'path'; +import { readFileSync } from 'fs'; +import { parse, parseFunction } from './index'; +import { cleanTreeWithStmt } from './utils'; +const argv = require('minimist')(process.argv.slice(2)); +const args = argv._; +if (args.length !== 1) { + console.log(argv); + console.warn('Usage: pgsql-parser '); + process.exit(1); +} +const pth = args[0].startsWith('/') + ? args[0] + : resolve(join(process.cwd(), args[0])); +const content = readFileSync(pth, 'utf-8'); +let query; +if (argv.pl) { + // plpgsql ONLY + query = parseFunction(content); +} else { + query = parse(content); +} + +process.stdout.write(JSON.stringify(cleanTreeWithStmt(query), null, 2)); diff --git a/packages/pgsql-parser/src/index.ts b/packages/pgsql-parser/src/index.ts new file mode 100644 index 0000000..31cc43e --- /dev/null +++ b/packages/pgsql-parser/src/index.ts @@ -0,0 +1,30 @@ +import { Deparser, deparse } from 'pgsql-deparser'; +import { + parseQuery, + parseQuerySync, + parsePlPgSQLSync as parseFunction +} from 'libpg-query'; + +function mapStmt({ stmt, stmt_len, stmt_location }) { + return { + RawStmt: { + stmt, + stmt_len, + stmt_location: stmt_location || 0 + } + }; +} + +export const parse = (sql) => { + if (!sql) throw new Error('no SQL provided to parser'); + const result = parseQuerySync(sql); + return result.stmts.map(mapStmt); +}; + +export const parseAsync = async (sql) => { + if (!sql) throw new Error('no SQL provided to parser'); + const result = await parseQuery(sql); + return result.stmts.map(mapStmt); +}; + +export { deparse, Deparser, parseFunction }; diff --git a/packages/pgsql-parser/src/utils/index.ts b/packages/pgsql-parser/src/utils/index.ts new file mode 100644 index 0000000..ed7603a --- /dev/null +++ b/packages/pgsql-parser/src/utils/index.ts @@ -0,0 +1,92 @@ +/* eslint-disable no-restricted-syntax */ + +export const cleanLines = (sql) => { + return sql + .split('\n') + .map((l) => l.trim()) + .filter((a) => a) + .join('\n'); +}; + +export const transform = (obj, props) => { + let copy = null; + // Handle the 3 simple types, and null or undefined + if (obj == null || typeof obj !== 'object') { + return obj; + } + + // Handle Date + if (obj instanceof Date) { + copy = new Date(); + copy.setTime(obj.getTime()); + return copy; + } + + // Handle Array + if (obj instanceof Array) { + copy = []; + for (let i = 0, len = obj.length; i < len; i++) { + copy[i] = transform(obj[i], props); + } + return copy; + } + + // Handle Object + if (obj instanceof Object || typeof obj === 'object') { + copy = {}; + for (const attr in obj) { + if (obj.hasOwnProperty(attr)) { + if (props.hasOwnProperty(attr)) { + if (typeof props[attr] === 'function') { + copy[attr] = props[attr](obj[attr]); + } else if (props[attr].hasOwnProperty(obj[attr])) { + copy[attr] = props[attr][obj[attr]]; + } else { + copy[attr] = transform(obj[attr], props); + } + } else { + copy[attr] = transform(obj[attr], props); + } + } else { + copy[attr] = transform(obj[attr], props); + } + } + return copy; + } + + throw new Error("Unable to copy obj! Its type isn't supported."); +}; + +const noop = () => undefined; + +export const cleanTree = (tree) => { + return transform(tree, { + stmt_len: noop, + stmt_location: noop, + location: noop, + DefElem: (obj) => { + if (obj.defname === 'as') { + if (Array.isArray(obj.arg) && obj.arg.length) { + // function + obj.arg[0].String.str = obj.arg[0].String.str.trim(); + } else if (obj.arg.List && obj.arg.List.items) { + // function + obj.arg.List.items[0].String.str = obj.arg.List.items[0].String.str.trim(); + } else { + // do stmt + obj.arg.String.str = obj.arg.String.str.trim(); + } + return cleanTree(obj); + } else { + return cleanTree(obj); + } + } + }); +}; + +export const cleanTreeWithStmt = (tree) => { + return transform(tree, { + stmt_location: noop, + location: noop + }); +}; diff --git a/packages/pgsql-parser/tsconfig.json b/packages/pgsql-parser/tsconfig.json new file mode 100644 index 0000000..16edd76 --- /dev/null +++ b/packages/pgsql-parser/tsconfig.json @@ -0,0 +1,22 @@ +{ + "compilerOptions": { + "baseUrl": ".", + "rootDir": "src", + "skipLibCheck": true, + "declaration": true, + "declarationDir": "./types", + "emitDeclarationOnly": false, + "isolatedModules": true, + "allowJs": true, + + "esModuleInterop": true, + "target": "es2022", + "lib": ["es2022", "DOM"], + "downlevelIteration": true, + "moduleResolution": "node", + "resolveJsonModule": true + }, + "include": ["src/**/*"], + "exclude": ["node_modules"] + } + \ No newline at end of file diff --git a/packages/pgsql-parser/types/cli.d.ts b/packages/pgsql-parser/types/cli.d.ts new file mode 100644 index 0000000..b798801 --- /dev/null +++ b/packages/pgsql-parser/types/cli.d.ts @@ -0,0 +1,2 @@ +#!/usr/bin/env node +export {}; diff --git a/packages/pgsql-parser/types/index.d.ts b/packages/pgsql-parser/types/index.d.ts new file mode 100644 index 0000000..490549b --- /dev/null +++ b/packages/pgsql-parser/types/index.d.ts @@ -0,0 +1,5 @@ +import { Deparser, deparse } from 'pgsql-deparser'; +import { parsePlPgSQLSync as parseFunction } from 'libpg-query'; +export declare const parse: (sql: any) => any; +export declare const parseAsync: (sql: any) => Promise; +export { deparse, Deparser, parseFunction }; diff --git a/packages/pgsql-parser/types/utils/index.d.ts b/packages/pgsql-parser/types/utils/index.d.ts new file mode 100644 index 0000000..181afd2 --- /dev/null +++ b/packages/pgsql-parser/types/utils/index.d.ts @@ -0,0 +1,4 @@ +export declare const cleanLines: (sql: any) => any; +export declare const transform: (obj: any, props: any) => any; +export declare const cleanTree: (tree: any) => any; +export declare const cleanTreeWithStmt: (tree: any) => any; diff --git a/packages/types/README.md b/packages/types/README.md index e807e40..ac87727 100644 --- a/packages/types/README.md +++ b/packages/types/README.md @@ -75,7 +75,7 @@ console.log(createStmt); * [pgsql-parser](https://github.com/launchql/pgsql-parser): The real PostgreSQL parser for Node.js, providing symmetric parsing and deparsing of SQL statements with actual PostgreSQL parser integration. * [pgsql-deparser](https://github.com/launchql/pgsql-parser/tree/main/packages/deparser): A streamlined tool designed for converting PostgreSQL ASTs back into SQL queries, focusing solely on deparser functionality to complement `pgsql-parser`. -* [pgsql-enums](https://github.com/launchql/pgsql-parser/tree/main/packages/enums-json): A utility package offering easy access to PostgreSQL enumeration types in JSON format, aiding in string and integer conversions of enums used within ASTs to compliment `pgsql-parser` +* [pgsql-enums](https://github.com/launchql/pgsql-parser/tree/main/packages/pgsql-enums): A utility package offering easy access to PostgreSQL enumeration types in JSON format, aiding in string and integer conversions of enums used within ASTs to compliment `pgsql-parser` * [@pgsql/enums](https://github.com/launchql/pgsql-parser/tree/main/packages/enums): Provides PostgreSQL AST enums in TypeScript, enhancing type safety and usability in projects interacting with PostgreSQL AST nodes. * [@pgsql/types](https://github.com/launchql/pgsql-parser/tree/main/packages/types): Offers TypeScript type definitions for PostgreSQL AST nodes, facilitating type-safe construction, analysis, and manipulation of ASTs. * [@pgsql/utils](https://github.com/launchql/pgsql-parser/tree/main/packages/utils): A comprehensive utility library for PostgreSQL, offering type-safe AST node creation and enum value conversions, simplifying the construction and manipulation of PostgreSQL ASTs. diff --git a/packages/utils/README.md b/packages/utils/README.md index 5c75b11..f85b03b 100644 --- a/packages/utils/README.md +++ b/packages/utils/README.md @@ -213,7 +213,7 @@ console.log(enumName); // Outputs 'SORTBY_ASC' if 1 corresponds to 'SORTBY_ASC' * [pgsql-parser](https://github.com/launchql/pgsql-parser): The real PostgreSQL parser for Node.js, providing symmetric parsing and deparsing of SQL statements with actual PostgreSQL parser integration. * [pgsql-deparser](https://github.com/launchql/pgsql-parser/tree/main/packages/deparser): A streamlined tool designed for converting PostgreSQL ASTs back into SQL queries, focusing solely on deparser functionality to complement `pgsql-parser`. -* [pgsql-enums](https://github.com/launchql/pgsql-parser/tree/main/packages/enums-json): A utility package offering easy access to PostgreSQL enumeration types in JSON format, aiding in string and integer conversions of enums used within ASTs to compliment `pgsql-parser` +* [pgsql-enums](https://github.com/launchql/pgsql-parser/tree/main/packages/pgsql-enums): A utility package offering easy access to PostgreSQL enumeration types in JSON format, aiding in string and integer conversions of enums used within ASTs to compliment `pgsql-parser` * [@pgsql/enums](https://github.com/launchql/pgsql-parser/tree/main/packages/enums): Provides PostgreSQL AST enums in TypeScript, enhancing type safety and usability in projects interacting with PostgreSQL AST nodes. * [@pgsql/types](https://github.com/launchql/pgsql-parser/tree/main/packages/types): Offers TypeScript type definitions for PostgreSQL AST nodes, facilitating type-safe construction, analysis, and manipulation of ASTs. * [@pgsql/utils](https://github.com/launchql/pgsql-parser/tree/main/packages/utils): A comprehensive utility library for PostgreSQL, offering type-safe AST node creation and enum value conversions, simplifying the construction and manipulation of PostgreSQL ASTs. diff --git a/yarn.lock b/yarn.lock index 44794ba..130b8fb 100644 --- a/yarn.lock +++ b/yarn.lock @@ -968,6 +968,17 @@ "@nodelib/fs.scandir" "2.1.5" fastq "^1.6.0" +"@npmcli/agent@^2.0.0": + version "2.2.2" + resolved "https://registry.npmjs.org/@npmcli/agent/-/agent-2.2.2.tgz#967604918e62f620a648c7975461c9c9e74fc5d5" + integrity sha512-OrcNPXdpSl9UX7qPVRWbmWMCSXrcDa2M9DvrbOTj7ao1S4PlqVFYv9/yLKMkrJKZ/V5A/kDBC690or307i26Og== + dependencies: + agent-base "^7.1.0" + http-proxy-agent "^7.0.0" + https-proxy-agent "^7.0.1" + lru-cache "^10.0.1" + socks-proxy-agent "^8.0.3" + "@npmcli/fs@^1.0.0": version "1.1.1" resolved "https://registry.npmjs.org/@npmcli/fs/-/fs-1.1.1.tgz#72f719fe935e687c56a4faecf3c03d06ba593257" @@ -1552,6 +1563,11 @@ abbrev@1, abbrev@^1.0.0: resolved "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz#f8f2c887ad10bf67f634f005b6987fed3179aac8" integrity sha512-nne9/IiQ/hzIhY6pdDnbBtz7DjPTKrY00P/zvPSm5pOFkl6xuGrGnXn/VtTNNfNtAfZ9/1RtehkszU9qcTii0Q== +abbrev@^2.0.0: + version "2.0.0" + resolved "https://registry.npmjs.org/abbrev/-/abbrev-2.0.0.tgz#cf59829b8b4f03f89dda2771cb7f3653828c89bf" + integrity sha512-6/mh1E2u2YgEsCHdY0Yx5oW+61gZU+1vXaoiHHrpKeuRNNgFvS+/jrwHiQhB5apAf5oB7UB7E19ol2R2LKH8hQ== + acorn-jsx@^5.3.2: version "5.3.2" resolved "https://registry.npmjs.org/acorn-jsx/-/acorn-jsx-5.3.2.tgz#7ed5bb55908b3b2f1bc55c6af1653bada7f07937" @@ -1579,6 +1595,13 @@ agent-base@6, agent-base@^6.0.2: dependencies: debug "4" +agent-base@^7.0.2, agent-base@^7.1.0, agent-base@^7.1.1: + version "7.1.1" + resolved "https://registry.npmjs.org/agent-base/-/agent-base-7.1.1.tgz#bdbded7dfb096b751a2a087eeeb9664725b2e317" + integrity sha512-H0TSyFNDMomMNJQBn8wFV5YC/2eJ+VXECwOadZJT554xP6cODZHPX3H9QMQECxvrgiSOP1pHjy1sMWQVYJOUOA== + dependencies: + debug "^4.3.4" + agentkeepalive@^4.1.3, agentkeepalive@^4.2.1: version "4.5.0" resolved "https://registry.npmjs.org/agentkeepalive/-/agentkeepalive-4.5.0.tgz#2673ad1389b3c418c5a20c5d7364f93ca04be923" @@ -1994,6 +2017,24 @@ cacache@^17.0.0: tar "^6.1.11" unique-filename "^3.0.0" +cacache@^18.0.0: + version "18.0.2" + resolved "https://registry.npmjs.org/cacache/-/cacache-18.0.2.tgz#fd527ea0f03a603be5c0da5805635f8eef00c60c" + integrity sha512-r3NU8h/P+4lVUHfeRw1dtgQYar3DZMm4/cm2bZgOvrFC/su7budSOeqh52VJIC4U4iG1WWwV6vRW0znqBvxNuw== + dependencies: + "@npmcli/fs" "^3.1.0" + fs-minipass "^3.0.0" + glob "^10.2.2" + lru-cache "^10.0.1" + minipass "^7.0.3" + minipass-collect "^2.0.1" + minipass-flush "^1.0.5" + minipass-pipeline "^1.2.4" + p-map "^4.0.0" + ssri "^10.0.0" + tar "^6.1.11" + unique-filename "^3.0.0" + callsites@^3.0.0: version "3.1.0" resolved "https://registry.npmjs.org/callsites/-/callsites-3.1.0.tgz#b3630abd8943432f54b3f0519238e33cd7df2f73" @@ -3179,7 +3220,7 @@ glob@8.0.3: minimatch "^5.0.1" once "^1.3.0" -glob@^10.2.2, glob@^10.3.7: +glob@^10.2.2, glob@^10.3.10, glob@^10.3.7: version "10.3.12" resolved "https://registry.npmjs.org/glob/-/glob-10.3.12.tgz#3a65c363c2e9998d220338e88a5f6ac97302960b" integrity sha512-TCNv8vJ+xz4QiqTpfOJA7HvYv+tNIRHKfUWw/q+v2jdgN4ebz+KY9tGx5J4rHP0o84mNP+ApH66HRX8us3Khqg== @@ -3379,6 +3420,14 @@ http-proxy-agent@^5.0.0: agent-base "6" debug "4" +http-proxy-agent@^7.0.0: + version "7.0.2" + resolved "https://registry.npmjs.org/http-proxy-agent/-/http-proxy-agent-7.0.2.tgz#9a8b1f246866c028509486585f62b8f2c18c270e" + integrity sha512-T1gkAiYYDWYx3V5Bmyu7HcfcvL7mUrTWiM6yOfa3PIphViJ/gFPbvidQ+veqSOHci/PxBcDabeUNCzpOODJZig== + dependencies: + agent-base "^7.1.0" + debug "^4.3.4" + https-proxy-agent@^5.0.0: version "5.0.0" resolved "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-5.0.0.tgz#e2a90542abb68a762e0a0850f6c9edadfd8506b2" @@ -3387,6 +3436,14 @@ https-proxy-agent@^5.0.0: agent-base "6" debug "4" +https-proxy-agent@^7.0.1: + version "7.0.4" + resolved "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-7.0.4.tgz#8e97b841a029ad8ddc8731f26595bad868cb4168" + integrity sha512-wlwpilI7YdjSkWaQ/7omYBMTliDcmCN8OLihO6I9B86g06lMyAoqgoDpV0XqoaPOKj+0DIdAvnsWfyAAhmimcg== + dependencies: + agent-base "^7.0.2" + debug "4" + human-signals@^2.1.0: version "2.1.0" resolved "https://registry.npmjs.org/human-signals/-/human-signals-2.1.0.tgz#dc91fcba42e4d06e4abaed33b3e7a3c02f514ea0" @@ -3684,6 +3741,11 @@ isexe@^2.0.0: resolved "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz#e8fbf374dc556ff8947a10dcb0572d633f2cfa10" integrity sha1-6PvzdNxVb/iUehDcsFctYz8s+hA= +isexe@^3.1.1: + version "3.1.1" + resolved "https://registry.npmjs.org/isexe/-/isexe-3.1.1.tgz#4a407e2bd78ddfb14bea0c27c6f7072dde775f0d" + integrity sha512-LpB/54B+/2J5hqQ7imZHfdU31OlgQqx7ZicVlkm9kzg9/w8GKLEcFfJl/t7DCEDueOyBAD6zCCwTO6Fzs0NoEQ== + isobject@^3.0.1: version "3.0.1" resolved "https://registry.npmjs.org/isobject/-/isobject-3.0.1.tgz#4e431e92b11a9731636aa1f9c8d1ccbcfdab78df" @@ -4364,6 +4426,15 @@ libpg-query@13.3.2: node-addon-api "^1.6.3" node-gyp "^8.0.0" +libpg-query@16.1.0: + version "16.1.0" + resolved "https://registry.npmjs.org/libpg-query/-/libpg-query-16.1.0.tgz#fc3068be91284f2113d36bdb8b9ab4d6d7701ccb" + integrity sha512-8UHEwWEU++ZQ0mnLjW0ZueVuZEJSxchWGCsg04ZWEXDLmmfg9Cpa968ShfHFmDXKsB1ugQGppEqSa9iwaGsCMg== + dependencies: + "@mapbox/node-pre-gyp" "^1.0.8" + node-addon-api "^1.6.3" + node-gyp "^10.0.1" + lines-and-columns@^1.1.6: version "1.1.6" resolved "https://registry.npmjs.org/lines-and-columns/-/lines-and-columns-1.1.6.tgz#1c00c743b433cd0a4e80758f7b64a57440d9ff00" @@ -4449,7 +4520,7 @@ long@^4.0.0: resolved "https://registry.npmjs.org/long/-/long-4.0.0.tgz#9a7b71cfb7d361a194ea555241c92f7468d5bf28" integrity sha512-XsP+KhQif4bjX1kbuSiySJFNAehNxgLb6hPRGJ9QsUr8ajHkuXGdrHmFUTUUXhDwVX2R5bY4JNZEwbUiMhV+MA== -lru-cache@^10.2.0: +lru-cache@^10.0.1, lru-cache@^10.2.0: version "10.2.0" resolved "https://registry.npmjs.org/lru-cache/-/lru-cache-10.2.0.tgz#0bd445ca57363465900f4d1f9bd8db343a4d95c3" integrity sha512-2bIM8x+VAf6JT4bKAljS1qUWgMsqZRPGJS6FSahIMPVvctcNhyVp7AJu7quxOW9jwkryBReKZY5tY5JYv2n/7Q== @@ -4536,6 +4607,23 @@ make-fetch-happen@^11.0.0, make-fetch-happen@^11.0.1, make-fetch-happen@^11.1.1: socks-proxy-agent "^7.0.0" ssri "^10.0.0" +make-fetch-happen@^13.0.0: + version "13.0.0" + resolved "https://registry.npmjs.org/make-fetch-happen/-/make-fetch-happen-13.0.0.tgz#705d6f6cbd7faecb8eac2432f551e49475bfedf0" + integrity sha512-7ThobcL8brtGo9CavByQrQi+23aIfgYU++wg4B87AIS8Rb2ZBt/MEaDqzA00Xwv/jUjAjYkLHjVolYuTLKda2A== + dependencies: + "@npmcli/agent" "^2.0.0" + cacache "^18.0.0" + http-cache-semantics "^4.1.1" + is-lambda "^1.0.1" + minipass "^7.0.2" + minipass-fetch "^3.0.0" + minipass-flush "^1.0.5" + minipass-pipeline "^1.2.4" + negotiator "^0.6.3" + promise-retry "^2.0.1" + ssri "^10.0.0" + make-fetch-happen@^9.1.0: version "9.1.0" resolved "https://registry.npmjs.org/make-fetch-happen/-/make-fetch-happen-9.1.0.tgz#53085a09e7971433e6765f7971bf63f4e05cb968" @@ -4693,6 +4781,13 @@ minipass-collect@^1.0.2: dependencies: minipass "^3.0.0" +minipass-collect@^2.0.1: + version "2.0.1" + resolved "https://registry.npmjs.org/minipass-collect/-/minipass-collect-2.0.1.tgz#1621bc77e12258a12c60d34e2276ec5c20680863" + integrity sha512-D7V8PO9oaz7PWGLbCACuI1qEOsq7UKfLotx/C0Aet43fCUB/wfQ7DYeq2oR/svFJGYDHPr38SHATeaj/ZoKHKw== + dependencies: + minipass "^7.0.3" + minipass-fetch@^1.3.2: version "1.4.1" resolved "https://registry.npmjs.org/minipass-fetch/-/minipass-fetch-1.4.1.tgz#d75e0091daac1b0ffd7e9d41629faff7d0c1f1b6" @@ -4779,7 +4874,7 @@ minipass@^5.0.0: resolved "https://registry.npmjs.org/minipass/-/minipass-5.0.0.tgz#3e9788ffb90b694a5d0ec94479a45b5d8738133d" integrity sha512-3FnjYuehv9k6ovOEbyOswadCDPX1piCfhV8ncmYtHOjuPwylVWsghTLo7rabjC3Rx5xD4HDx8Wm1xnMF7S5qFQ== -"minipass@^5.0.0 || ^6.0.2 || ^7.0.0", minipass@^7.0.3, minipass@^7.0.4: +"minipass@^5.0.0 || ^6.0.2 || ^7.0.0", minipass@^7.0.2, minipass@^7.0.3, minipass@^7.0.4: version "7.0.4" resolved "https://registry.npmjs.org/minipass/-/minipass-7.0.4.tgz#dbce03740f50a4786ba994c1fb908844d27b038c" integrity sha512-jYofLM5Dam9279rdkWzqHozUo4ybjdZmCsDHePy5V/PbBcVMiSZR97gmAy45aqi8CK1lG2ECd356FU86avfwUQ== @@ -4882,6 +4977,22 @@ node-gyp-build@^4.3.0: resolved "https://registry.npmjs.org/node-gyp-build/-/node-gyp-build-4.8.0.tgz#3fee9c1731df4581a3f9ead74664369ff00d26dd" integrity sha512-u6fs2AEUljNho3EYTJNBfImO5QTo/J/1Etd+NVdCj7qWKUSN/bSLkZwhDv7I+w/MSC6qJ4cknepkAYykDdK8og== +node-gyp@^10.0.1: + version "10.1.0" + resolved "https://registry.npmjs.org/node-gyp/-/node-gyp-10.1.0.tgz#75e6f223f2acb4026866c26a2ead6aab75a8ca7e" + integrity sha512-B4J5M1cABxPc5PwfjhbV5hoy2DP9p8lFXASnEN6hugXOa61416tnTZ29x9sSwAd0o99XNIcpvDDy1swAExsVKA== + dependencies: + env-paths "^2.2.0" + exponential-backoff "^3.1.1" + glob "^10.3.10" + graceful-fs "^4.2.6" + make-fetch-happen "^13.0.0" + nopt "^7.0.0" + proc-log "^3.0.0" + semver "^7.3.5" + tar "^6.1.2" + which "^4.0.0" + node-gyp@^8.0.0: version "8.4.1" resolved "https://registry.npmjs.org/node-gyp/-/node-gyp-8.4.1.tgz#3d49308fc31f768180957d6b5746845fbd429937" @@ -4957,6 +5068,13 @@ nopt@^6.0.0: dependencies: abbrev "^1.0.0" +nopt@^7.0.0: + version "7.2.0" + resolved "https://registry.npmjs.org/nopt/-/nopt-7.2.0.tgz#067378c68116f602f552876194fd11f1292503d7" + integrity sha512-CVDtwCdhYIvnAzFoJ6NJ6dX3oga9/HyciQDnG1vQDjSLMeKLJ4A93ZqYKDrgYSr1FBY5/hMYC+2VCi24pgpkGA== + dependencies: + abbrev "^2.0.0" + normalize-package-data@^2.3.2, normalize-package-data@^2.5.0: version "2.5.0" resolved "https://registry.npmjs.org/normalize-package-data/-/normalize-package-data-2.5.0.tgz#e66db1838b200c1dfc233225d12cb36520e234a8" @@ -5965,7 +6083,16 @@ socks-proxy-agent@^7.0.0: debug "^4.3.3" socks "^2.6.2" -socks@^2.6.2: +socks-proxy-agent@^8.0.3: + version "8.0.3" + resolved "https://registry.npmjs.org/socks-proxy-agent/-/socks-proxy-agent-8.0.3.tgz#6b2da3d77364fde6292e810b496cb70440b9b89d" + integrity sha512-VNegTZKhuGq5vSD6XNKlbqWhyt/40CgoEw8XxD6dhnm8Jq9IEa3nIa4HwnM8XOqU0CdB0BwWVXusqiFXfHB3+A== + dependencies: + agent-base "^7.1.1" + debug "^4.3.4" + socks "^2.7.1" + +socks@^2.6.2, socks@^2.7.1: version "2.8.1" resolved "https://registry.npmjs.org/socks/-/socks-2.8.1.tgz#22c7d9dd7882649043cba0eafb49ae144e3457af" integrity sha512-B6w7tkwNid7ToxjZ08rQMT8M9BJAf8DKx8Ft4NivzH0zBUfd6jldGcisJn/RLgxcX3FPNDdNQCUEMMT79b+oCQ== @@ -6601,6 +6728,13 @@ which@^3.0.0: dependencies: isexe "^2.0.0" +which@^4.0.0: + version "4.0.0" + resolved "https://registry.npmjs.org/which/-/which-4.0.0.tgz#cd60b5e74503a3fbcfbf6cd6b4138a8bae644c1a" + integrity sha512-GlaYyEb07DPxYCKhKzplCWBJtvxZcZMrL+4UkrTSJHHPyZU4mYYTv3qaOe77H7EODLSSopAUFAc6W8U4yqvscg== + dependencies: + isexe "^3.1.1" + wide-align@^1.1.2, wide-align@^1.1.5: version "1.1.5" resolved "https://registry.npmjs.org/wide-align/-/wide-align-1.1.5.tgz#df1d4c206854369ecf3c9a4898f1b23fbd9d15d3"