Skip to content
This repository was archived by the owner on Jun 23, 2025. It is now read-only.

Feat/runtime schema #12

Open
wants to merge 21 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
a191985
protos
pyramation Jun 15, 2025
9cf8c06
feat: implement runtime schema generator and SPECIAL_TYPES analysis
pyramation Jun 15, 2025
8f71c9b
feat: complete runtime schema implementation with CLI and documentation
pyramation Jun 15, 2025
75182be
feat: finalize runtime schema implementation
pyramation Jun 15, 2025
b873aac
feat: eliminate SPECIAL_TYPES pattern using runtime schema
pyramation Jun 15, 2025
781cc06
fix: cast ReflectionObject to Namespace for RuntimeSchemaGenerator
pyramation Jun 15, 2025
d90403a
fix: use export type for isolatedModules compatibility
pyramation Jun 15, 2025
a86b482
feat: add comprehensive runtime schema tests
pyramation Jun 15, 2025
fc305b8
feat: add comprehensive runtime schema test outputs
pyramation Jun 15, 2025
b651f3f
fix: correct namespace navigation in RuntimeSchemaGenerator
pyramation Jun 15, 2025
f7bd7f9
cleanup: remove temporary test files and examples folder
pyramation Jun 15, 2025
9a69dc2
cleanup: remove PROTO.md and sample-runtime-schema.json
pyramation Jun 15, 2025
a5b189c
docs: add runtime schema options to README and inline interfaces
pyramation Jun 15, 2025
8ab2238
update: include test output files with inlined interfaces
pyramation Jun 15, 2025
6485c04
feat: integrate strfy-js for improved TypeScript formatting
pyramation Jun 15, 2025
6c038fc
feat: migrate runtime schema CLI to dedicated CLI package
pyramation Jun 15, 2025
9a225dd
chore: update lock files after dependency changes
pyramation Jun 15, 2025
9724f87
feat: remove commander dependency and legacy CLI
pyramation Jun 16, 2025
00f816c
fix: restore conditional logic for non-wrapped types in AST helpers
pyramation Jun 16, 2025
237eee6
feat: remove wrapped type detection from AST helper generation
pyramation Jun 16, 2025
2ddcb00
chore: update generated files and remove obsolete type declarations
pyramation Jun 16, 2025
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
1,816 changes: 1,816 additions & 0 deletions __fixtures__/output/runtime-schema/disabled/types.ts

Large diffs are not rendered by default.

2,330 changes: 2,330 additions & 0 deletions __fixtures__/output/runtime-schema/full-features/asts.ts

Large diffs are not rendered by default.

10,637 changes: 10,637 additions & 0 deletions __fixtures__/output/runtime-schema/full-features/complete-schema.json

Large diffs are not rendered by default.

69 changes: 69 additions & 0 deletions __fixtures__/output/runtime-schema/full-features/enums.ts

Large diffs are not rendered by default.

1,816 changes: 1,816 additions & 0 deletions __fixtures__/output/runtime-schema/full-features/types.ts

Large diffs are not rendered by default.

1,822 changes: 1,822 additions & 0 deletions __fixtures__/output/runtime-schema/full-features/wrapped.ts

Large diffs are not rendered by default.

10,637 changes: 10,637 additions & 0 deletions __fixtures__/output/runtime-schema/json/custom-filename/custom-node-specs.json

Large diffs are not rendered by default.

10,637 changes: 10,637 additions & 0 deletions __fixtures__/output/runtime-schema/json/enabled/runtime-schema.json

Large diffs are not rendered by default.

11,404 changes: 11,404 additions & 0 deletions __fixtures__/output/runtime-schema/latest-proto/latest-schema.json

Large diffs are not rendered by default.

10,659 changes: 10,659 additions & 0 deletions __fixtures__/output/runtime-schema/typescript/custom-filename/custom-node-specs.ts

Large diffs are not rendered by default.

10,659 changes: 10,659 additions & 0 deletions __fixtures__/output/runtime-schema/typescript/enabled/runtime-schema.ts

Large diffs are not rendered by default.

2,330 changes: 2,330 additions & 0 deletions __fixtures__/output/runtime-schema/typescript/full-features/asts.ts

Large diffs are not rendered by default.

10,659 changes: 10,659 additions & 0 deletions __fixtures__/output/runtime-schema/typescript/full-features/complete-schema.ts

Large diffs are not rendered by default.

Large diffs are not rendered by default.

1,816 changes: 1,816 additions & 0 deletions __fixtures__/output/runtime-schema/typescript/full-features/types.ts

Large diffs are not rendered by default.

1,822 changes: 1,822 additions & 0 deletions __fixtures__/output/runtime-schema/typescript/full-features/wrapped.ts

Large diffs are not rendered by default.

3,076 changes: 1,287 additions & 1,789 deletions __fixtures__/output/types/wrapped/wrapped.ts

Large diffs are not rendered by default.

5,116 changes: 2,304 additions & 2,812 deletions __fixtures__/output/utils/astHelpers/enabled/asts.ts

Large diffs are not rendered by default.

5,116 changes: 2,304 additions & 2,812 deletions __fixtures__/output/utils/astHelpers/inlineNestedObj/asts.ts

Large diffs are not rendered by default.

3,076 changes: 1,287 additions & 1,789 deletions __fixtures__/output/utils/astHelpers/inlineNestedObj/wrapped.ts

Large diffs are not rendered by default.

3,581 changes: 3,581 additions & 0 deletions __fixtures__/proto/14-latest.proto

Large diffs are not rendered by default.

4,110 changes: 4,110 additions & 0 deletions __fixtures__/proto/17-latest.proto

Large diffs are not rendered by default.

16,618 changes: 16,618 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

20 changes: 20 additions & 0 deletions packages/cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,26 @@ pg-proto-parser protogen --protoUrl <URL to proto file> \
| `--help`, `-h` | Show this help message. | |
| `--version`, `-v` | Show the version number. | |

### runtime-schema

Generate runtime schema for PostgreSQL AST nodes:

```bash
pg-proto-parser runtime-schema --inFile <path-to-proto> --outDir <output-directory> \
[--format <json|typescript>] [--filename <filename>]
```

#### Options for runtime-schema

| Option | Description | Default Value |
|---------------------|-------------------------------------------------------------------------------------|---------------|
| `--inFile` | Path to the `.proto` file to be parsed. | *Required* |
| `--outDir` | Directory to save the generated runtime schema files. | *Required* |
| `--format` | Output format for runtime schema ('json' or 'typescript'). | `json` |
| `--filename` | Filename for the runtime schema file (without extension). | `runtime-schema` |
| `--help`, `-h` | Show this help message and exit. | |
| `--version`, `-v` | Show the version number and exit. | |


## Related

Expand Down
12 changes: 10 additions & 2 deletions packages/cli/src/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ import { ParsedArgs } from 'minimist';

import { commands as codegen } from './codegen';
import { commands as protogen } from './protogen';
import { commands as runtimeSchema } from './runtime-schema';

import { help as codegenHelp } from './codegen/cli';
import { help as protogenHelp } from './protogen/cli';
import { help as runtimeSchemaHelp } from './runtime-schema/cli';

export const commands = async (argv: Partial<ParsedArgs>, prompter: Inquirerer, _options: CLIOptions) => {
let command;
Expand All @@ -21,6 +23,7 @@ export const commands = async (argv: Partial<ParsedArgs>, prompter: Inquirerer,
if (argv.help || argv.h) {
codegenHelp();
protogenHelp();
runtimeSchemaHelp();
process.exit(0);
}

Expand All @@ -32,7 +35,8 @@ export const commands = async (argv: Partial<ParsedArgs>, prompter: Inquirerer,
message: 'choose a command',
options: [
'protogen',
'codegen'
'codegen',
'runtime-schema'
]
}
];
Expand All @@ -54,11 +58,15 @@ export const commands = async (argv: Partial<ParsedArgs>, prompter: Inquirerer,
argv = await codegen(argv, prompter, _options);
break;

case 'runtime-schema':
argv = await runtimeSchema(argv, prompter, _options);
break;

default:
console.log(`No recognized command provided or no command given: ${command}`);
break;
}

return argv;

};
};
62 changes: 62 additions & 0 deletions packages/cli/src/commands/runtime-schema/cli.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { readAndParsePackageJson } from '../../package';
import { PgProtoParser, PgProtoParserOptions, getOptionsWithDefaults } from 'pg-proto-parser';
import o from 'nested-obj';

export const help = (): void => {
console.log(`
Usage:

pg-proto-parser runtime-schema --inFile <path-to-proto> --outDir <output-directory>
[--format <json|typescript>] [--filename <filename>]

Options:

--help, -h Show this help message and exit.
--inFile Path to the .proto file to be parsed.
--outDir Directory to save the generated runtime schema files.
--format Output format for runtime schema ('json' or 'typescript').
--filename Filename for the runtime schema file (without extension).
--version, -v Show the version number and exit.
`);
}

export default async (argv) => {

if (argv.help || argv.h) {
help();
process.exit(0);
}

if (argv.version || argv.v) {
console.log(`Version: ${readAndParsePackageJson().version}`);
process.exit(0);
}

if (!argv.inFile || !argv.outDir) {
console.log('Input Error: inFile and outDir are required!');
help();
process.exit(1);
}

const options: PgProtoParserOptions = getOptionsWithDefaults({
outDir: argv.outDir
});

o.set(options, 'runtimeSchema.enabled', true);
o.set(options, 'runtimeSchema.format', argv.format || 'json');
o.set(options, 'runtimeSchema.filename', argv.filename || 'runtime-schema');

o.set(options, 'types.enabled', false);
o.set(options, 'enums.enabled', false);
o.set(options, 'utils.astHelpers.enabled', false);
o.set(options, 'utils.enums.enabled', false);

console.log(`Generating runtime schema from ${argv.inFile}...`);
const parser = new PgProtoParser(argv.inFile, options);
await parser.write();

const extension = argv.format === 'typescript' ? 'ts' : 'json';
console.log(`Runtime schema generated successfully in ${argv.outDir}/${argv.filename || 'runtime-schema'}.${extension}`);

return argv;
};
43 changes: 43 additions & 0 deletions packages/cli/src/commands/runtime-schema/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { CLIOptions, Inquirerer } from 'inquirerer'
import { ParsedArgs } from 'minimist';
import cli, { help } from './cli';

export const commands = async (argv: Partial<ParsedArgs>, prompter: Inquirerer, _options: CLIOptions) => {

if (argv.help || argv.h) {
help();
process.exit(0);
}

argv = await prompter.prompt(argv, [
{
type: 'text',
name: 'inFile',
message: 'provide inFile (./path/to/proto.proto):'
},
{
type: 'text',
name: 'outDir',
message: 'provide outDir (./outputDir):'
},
{
type: 'autocomplete',
name: 'format',
message: 'Choose output format:',
options: ['json', 'typescript'],
default: 'json',
useDefault: true
},
{
type: 'text',
name: 'filename',
message: 'Filename for runtime schema (without extension):',
default: 'runtime-schema',
useDefault: true
}
]);

argv = await cli(argv);

return argv;
};
5 changes: 4 additions & 1 deletion packages/parser/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ This table describes the options available for `PgProtoParserOptions`, their fun
| `enums.json.toIntOutFile` | Output file name for the JSON mapping of enum names to integer values. | `'enums2int.json'` |
| `enums.json.toStrOutFile` | Output file name for the JSON mapping of integer values to enum names. | `'enums2str.json'` |
| `enums.removeUndefinedAt0` | Removes the initial `UNDEFINED` enum entry and adjusts the subsequent values by decrementing them. | `true` |
| `runtimeSchema.enabled` | Whether to generate runtime schema for AST nodes with metadata about node types and field specifications. | `false` |
| `runtimeSchema.filename` | Filename for the generated runtime schema file. | `'runtime-schema'` |
| `runtimeSchema.format` | Output format for runtime schema generation ('json' or 'typescript'). | `'json'` |
| `includeHeader` | Includes a header at the top of generated TypeScript files to avoid manual manipulation which could cause issues in CI/CD pipelines. | `true` |


Expand Down Expand Up @@ -165,4 +168,4 @@ ast.selectStmt({

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 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.
Loading