Skip to content

Commit 657656f

Browse files
authored
Merge pull request #119 from launchql/enums
Enums
2 parents de48621 + 23add8e commit 657656f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+6759
-9
lines changed

PUBLISH.md

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,34 @@
11
# Publishing Guide
22

3-
## Types Packages
3+
## Automated Publishing (Recommended)
4+
5+
### Types Packages
6+
```bash
7+
pnpm run publish:types
8+
```
9+
10+
This interactive script will:
11+
- Check for uncommitted changes (will error if any exist)
12+
- Let you select which versions to publish (or all)
13+
- Ask for version bump type (patch or minor only)
14+
- Build, prepare, and publish each selected version
15+
- Optionally promote pg17 to latest
16+
17+
### Enums Packages
18+
```bash
19+
pnpm run publish:enums
20+
```
21+
22+
This interactive script will:
23+
- Check for uncommitted changes (will error if any exist)
24+
- Let you select which versions to publish (or all)
25+
- Ask for version bump type (patch or minor only)
26+
- Build, prepare, and publish each selected version
27+
- Optionally promote pg17 to latest
28+
29+
## Manual Publishing
30+
31+
### Types Packages
432

533
```bash
634
# Set the version (e.g. 17, 16, 15, etc.)
@@ -29,6 +57,35 @@ npm dist-tag add @pgsql/types@pg${VERSION} latest
2957
- Transforms `@libpg-query/types16``@pgsql/types` with tag `pg16`
3058
- etc.
3159

60+
### Enums Packages
61+
62+
```bash
63+
# Set the version (e.g. 17, 16, 15, etc.)
64+
VERSION=17
65+
66+
cd enums/${VERSION}
67+
pnpm version patch
68+
git add . && git commit -m "release: bump @pgsql/enums${VERSION} version"
69+
pnpm build
70+
pnpm prepare:enums
71+
pnpm publish --tag pg${VERSION}
72+
```
73+
74+
Promote to latest (optional)
75+
76+
```bash
77+
# Set the version (e.g. 17, 16, 15, etc.)
78+
VERSION=17
79+
80+
# Promote pg${VERSION} tag to latest
81+
npm dist-tag add @pgsql/enums@pg${VERSION} latest
82+
```
83+
84+
### What it does
85+
- Transforms `@libpg-query/enums17``@pgsql/enums` with tag `pg17`
86+
- Transforms `@libpg-query/enums16``@pgsql/enums` with tag `pg16`
87+
- etc.
88+
3289
## Version Packages
3390

3491
### Quick Publish

enums/13/README.md

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# @pgsql/enums
2+
3+
<p align="center" width="100%">
4+
<img height="120" src="https://github.com/launchql/pgsql-parser/assets/545047/6440fa7d-918b-4a3b-8d1b-755d85de8bea" />
5+
</p>
6+
7+
<p align="center" width="100%">
8+
<a href="https://github.com/launchql/libpg-query-node/actions/workflows/ci.yml">
9+
<img height="20" src="https://github.com/launchql/libpg-query-node/actions/workflows/ci.yml/badge.svg" />
10+
</a>
11+
<a href="https://www.npmjs.com/package/@pgsql/enums"><img height="20" src="https://img.shields.io/npm/dt/@pgsql/enums"></a>
12+
<a href="https://www.npmjs.com/package/@pgsql/enums"><img height="20" src="https://img.shields.io/npm/dw/@pgsql/enums"/></a>
13+
<a href="https://github.com/launchql/libpg-query-node/blob/main/LICENSE-MIT"><img height="20" src="https://img.shields.io/badge/license-MIT-blue.svg"/></a>
14+
<a href="https://www.npmjs.com/package/@pgsql/enums"><img height="20" src="https://img.shields.io/github/package-json/v/launchql/libpg-query-node?filename=packages%2F13%2Fpackage.json"/></a>
15+
</p>
16+
17+
`@pgsql/enums` is a TypeScript library providing enum definitions for PostgreSQL AST nodes, primarily used in conjunction with [`pgsql-parser`](https://github.com/launchql/pgsql-parser). It offers a comprehensive and type-safe way to work with PostgreSQL enum values in query parsing and AST manipulation.
18+
19+
20+
## Installation
21+
22+
Install the package via npm:
23+
24+
```bash
25+
npm install @pgsql/enums
26+
```
27+
28+
## Usage
29+
30+
Here's a simple example showing how to work with enums, converting between enum names and their numeric values:
31+
32+
```ts
33+
import { ObjectType } from '@pgsql/enums';
34+
35+
// Get the numeric value of an enum
36+
const tableValue = ObjectType.OBJECT_TABLE;
37+
console.log(tableValue); // 41
38+
39+
// Convert from value back to enum name
40+
const enumName = ObjectType[41];
41+
console.log(enumName); // "OBJECT_TABLE"
42+
43+
// Use in comparisons
44+
if (someNode.objectType === ObjectType.OBJECT_TABLE) {
45+
console.log("This is a table object");
46+
}
47+
```
48+
49+
## Versions
50+
51+
Our latest is built with PostgreSQL 17 enum definitions.
52+
53+
| PG Major Version | libpg_query | npm dist-tag
54+
|--------------------------|-------------|---------|
55+
| 17 | 17-6.1.0 | [`pg17`](https://www.npmjs.com/package/@pgsql/enums/v/latest)
56+
| 16 | 16-5.2.0 | [`pg16`](https://www.npmjs.com/package/@pgsql/enums/v/pg16)
57+
| 15 | 15-4.2.4 | [`pg15`](https://www.npmjs.com/package/@pgsql/enums/v/pg15)
58+
| 14 | 14-3.0.0 | [`pg14`](https://www.npmjs.com/package/@pgsql/enums/v/pg14)
59+
| 13 | 13-2.2.0 | [`pg13`](https://www.npmjs.com/package/@pgsql/enums/v/pg13)
60+
61+
## Related
62+
63+
* [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.
64+
* [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`.
65+
* [@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.
66+
* [@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.
67+
* [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.
68+
* [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.
69+
70+
## Disclaimer
71+
72+
AS DESCRIBED IN THE LICENSES, THE SOFTWARE IS PROVIDED "AS IS", AT YOUR OWN RISK, AND WITHOUT WARRANTIES OF ANY KIND.
73+
74+
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.

enums/13/jest.config.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/** @type {import('ts-jest').JestConfigWithTsJest} */
2+
module.exports = {
3+
preset: "ts-jest",
4+
testEnvironment: "node",
5+
transform: {
6+
"^.+\.tsx?$": [
7+
"ts-jest",
8+
{
9+
babelConfig: false,
10+
tsconfig: "tsconfig.json",
11+
},
12+
],
13+
},
14+
transformIgnorePatterns: [`/node_modules/*`],
15+
testRegex: "(/__tests__/.*|(\.|/)(test|spec))\.(jsx?|tsx?)$",
16+
moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node"],
17+
modulePathIgnorePatterns: ["dist/*"]
18+
};

enums/13/package.json

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"name": "@libpg-query/enums13",
3+
"version": "13.10.0",
4+
"author": "Dan Lynch <[email protected]>",
5+
"description": "PostgreSQL AST enums from the real Postgres parser",
6+
"main": "index.js",
7+
"module": "esm/index.js",
8+
"types": "index.d.ts",
9+
"homepage": "https://github.com/launchql/libpg-query-node",
10+
"license": "SEE LICENSE IN LICENSE",
11+
"publishConfig": {
12+
"access": "public",
13+
"directory": "dist"
14+
},
15+
"repository": {
16+
"type": "git",
17+
"url": "https://github.com/launchql/libpg-query-node"
18+
},
19+
"bugs": {
20+
"url": "https://github.com/launchql/libpg-query-node/issues"
21+
},
22+
"x-publish": {
23+
"publishName": "@pgsql/enums",
24+
"distTag": "pg13"
25+
},
26+
"scripts": {
27+
"copy": "copyfiles -f ../../LICENSE README.md package.json dist",
28+
"clean": "rimraf dist",
29+
"build": "pnpm run clean && tsc && tsc -p tsconfig.esm.json && pnpm run copy",
30+
"build:dev": "pnpm run clean && tsc --declarationMap && tsc -p tsconfig.esm.json && pnpm run copy",
31+
"build:proto": "ts-node scripts/pg-proto-parser",
32+
"prepare:enums": "node -e \"require('../../scripts/prepare-enums.js').preparePackageForPublish('.')\"",
33+
"lint": "eslint . --fix"
34+
},
35+
"keywords": [],
36+
"devDependencies": {
37+
"pg-proto-parser": "^1.28.2"
38+
}
39+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { PgProtoParser, PgProtoParserOptions } from 'pg-proto-parser';
2+
import { resolve, join } from 'path';
3+
4+
const inFile: string = join(__dirname, '../../../protos/13/pg_query.proto');
5+
const outDir: string = resolve(join(__dirname, '../src'));
6+
7+
const options: PgProtoParserOptions = {
8+
outDir,
9+
enums: {
10+
enabled: true,
11+
enumsAsTypeUnion: false,
12+
filename: 'index.ts'
13+
}
14+
};
15+
const parser = new PgProtoParser(inFile, options);
16+
17+
parser.write();

0 commit comments

Comments
 (0)