Skip to content
Merged

Enums #119

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 58 additions & 1 deletion PUBLISH.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,34 @@
# Publishing Guide

## Types Packages
## Automated Publishing (Recommended)

### Types Packages
```bash
pnpm run publish:types
```

This interactive script will:
- Check for uncommitted changes (will error if any exist)
- Let you select which versions to publish (or all)
- Ask for version bump type (patch or minor only)
- Build, prepare, and publish each selected version
- Optionally promote pg17 to latest

### Enums Packages
```bash
pnpm run publish:enums
```

This interactive script will:
- Check for uncommitted changes (will error if any exist)
- Let you select which versions to publish (or all)
- Ask for version bump type (patch or minor only)
- Build, prepare, and publish each selected version
- Optionally promote pg17 to latest

## Manual Publishing

### Types Packages

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

### Enums Packages

```bash
# Set the version (e.g. 17, 16, 15, etc.)
VERSION=17

cd enums/${VERSION}
pnpm version patch
git add . && git commit -m "release: bump @pgsql/enums${VERSION} version"
pnpm build
pnpm prepare:enums
pnpm publish --tag pg${VERSION}
```

Promote to latest (optional)

```bash
# Set the version (e.g. 17, 16, 15, etc.)
VERSION=17

# Promote pg${VERSION} tag to latest
npm dist-tag add @pgsql/enums@pg${VERSION} latest
```

### What it does
- Transforms `@libpg-query/enums17` → `@pgsql/enums` with tag `pg17`
- Transforms `@libpg-query/enums16` → `@pgsql/enums` with tag `pg16`
- etc.

## Version Packages

### Quick Publish
Expand Down
74 changes: 74 additions & 0 deletions enums/13/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# @pgsql/enums

<p align="center" width="100%">
<img height="120" src="https://github.com/launchql/pgsql-parser/assets/545047/6440fa7d-918b-4a3b-8d1b-755d85de8bea" />
</p>

<p align="center" width="100%">
<a href="https://github.com/launchql/libpg-query-node/actions/workflows/ci.yml">
<img height="20" src="https://github.com/launchql/libpg-query-node/actions/workflows/ci.yml/badge.svg" />
</a>
<a href="https://www.npmjs.com/package/@pgsql/enums"><img height="20" src="https://img.shields.io/npm/dt/@pgsql/enums"></a>
<a href="https://www.npmjs.com/package/@pgsql/enums"><img height="20" src="https://img.shields.io/npm/dw/@pgsql/enums"/></a>
<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>
<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>
</p>

`@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.


## Installation

Install the package via npm:

```bash
npm install @pgsql/enums
```

## Usage

Here's a simple example showing how to work with enums, converting between enum names and their numeric values:

```ts
import { ObjectType } from '@pgsql/enums';

// Get the numeric value of an enum
const tableValue = ObjectType.OBJECT_TABLE;
console.log(tableValue); // 41

// Convert from value back to enum name
const enumName = ObjectType[41];
console.log(enumName); // "OBJECT_TABLE"

// Use in comparisons
if (someNode.objectType === ObjectType.OBJECT_TABLE) {
console.log("This is a table object");
}
```

## Versions

Our latest is built with PostgreSQL 17 enum definitions.

| PG Major Version | libpg_query | npm dist-tag
|--------------------------|-------------|---------|
| 17 | 17-6.1.0 | [`pg17`](https://www.npmjs.com/package/@pgsql/enums/v/latest)
| 16 | 16-5.2.0 | [`pg16`](https://www.npmjs.com/package/@pgsql/enums/v/pg16)
| 15 | 15-4.2.4 | [`pg15`](https://www.npmjs.com/package/@pgsql/enums/v/pg15)
| 14 | 14-3.0.0 | [`pg14`](https://www.npmjs.com/package/@pgsql/enums/v/pg14)
| 13 | 13-2.2.0 | [`pg13`](https://www.npmjs.com/package/@pgsql/enums/v/pg13)

## 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/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.

## 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.
18 changes: 18 additions & 0 deletions enums/13/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
preset: "ts-jest",
testEnvironment: "node",
transform: {
"^.+\.tsx?$": [
"ts-jest",
{
babelConfig: false,
tsconfig: "tsconfig.json",
},
],
},
transformIgnorePatterns: [`/node_modules/*`],
testRegex: "(/__tests__/.*|(\.|/)(test|spec))\.(jsx?|tsx?)$",
moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node"],
modulePathIgnorePatterns: ["dist/*"]
};
39 changes: 39 additions & 0 deletions enums/13/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"name": "@libpg-query/enums13",
"version": "13.10.0",
"author": "Dan Lynch <[email protected]>",
"description": "PostgreSQL AST enums from the real Postgres parser",
"main": "index.js",
"module": "esm/index.js",
"types": "index.d.ts",
"homepage": "https://github.com/launchql/libpg-query-node",
"license": "SEE LICENSE IN LICENSE",
"publishConfig": {
"access": "public",
"directory": "dist"
},
"repository": {
"type": "git",
"url": "https://github.com/launchql/libpg-query-node"
},
"bugs": {
"url": "https://github.com/launchql/libpg-query-node/issues"
},
"x-publish": {
"publishName": "@pgsql/enums",
"distTag": "pg13"
},
"scripts": {
"copy": "copyfiles -f ../../LICENSE README.md package.json dist",
"clean": "rimraf dist",
"build": "pnpm run clean && tsc && tsc -p tsconfig.esm.json && pnpm run copy",
"build:dev": "pnpm run clean && tsc --declarationMap && tsc -p tsconfig.esm.json && pnpm run copy",
"build:proto": "ts-node scripts/pg-proto-parser",
"prepare:enums": "node -e \"require('../../scripts/prepare-enums.js').preparePackageForPublish('.')\"",
"lint": "eslint . --fix"
},
"keywords": [],
"devDependencies": {
"pg-proto-parser": "^1.28.2"
}
}
17 changes: 17 additions & 0 deletions enums/13/scripts/pg-proto-parser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { PgProtoParser, PgProtoParserOptions } from 'pg-proto-parser';
import { resolve, join } from 'path';

const inFile: string = join(__dirname, '../../../protos/13/pg_query.proto');
const outDir: string = resolve(join(__dirname, '../src'));

const options: PgProtoParserOptions = {
outDir,
enums: {
enabled: true,
enumsAsTypeUnion: false,
filename: 'index.ts'
}
};
const parser = new PgProtoParser(inFile, options);

parser.write();
Loading