Skip to content

Commit 6a15f3a

Browse files
committed
cleanup: remove duplicated case helpers, use inflekt consistently
- pg-codegen: replace local toPascalCase with import from inflekt - codegen CLI: simplify camelizeArgv (toCamelCase already handles hyphens) - naming-helpers: use toScreamingSnake from inflekt instead of inline regex
1 parent 55c91c9 commit 6a15f3a

5 files changed

Lines changed: 8 additions & 17 deletions

File tree

graphql/codegen/src/cli/shared.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -150,14 +150,7 @@ const skipNonTopLevel = (key: string, path: string[]) =>
150150
!isTopLevel(key, path) || key === '_' || key.startsWith('_');
151151

152152
export const camelizeArgv = (argv: Record<string, any>): Record<string, any> =>
153-
inflektTree(
154-
argv,
155-
(key) => {
156-
const underscored = key.replace(/-/g, '_');
157-
return toCamelCase(underscored);
158-
},
159-
{ skip: skipNonTopLevel },
160-
);
153+
inflektTree(argv, toCamelCase, { skip: skipNonTopLevel });
161154

162155
export const hyphenateKeys = (obj: Record<string, any>): Record<string, any> =>
163156
inflektTree(

graphql/query/src/generators/naming-helpers.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
* Back-ported from Dashboard's `packages/data/src/query-generator.ts`.
99
*/
10-
import { toCamelCase, pluralize } from 'inflekt';
10+
import { toCamelCase, toScreamingSnake, pluralize } from 'inflekt';
1111

1212
import type { Table } from '../types/schema';
1313

@@ -206,9 +206,7 @@ export function toOrderByEnumValue(
206206
fieldName: string,
207207
direction: 'asc' | 'desc',
208208
): string {
209-
const screaming = fieldName
210-
.replace(/([a-z0-9])([A-Z])/g, '$1_$2')
211-
.toUpperCase();
209+
const screaming = toScreamingSnake(fieldName);
212210
return `${screaming}_${direction.toUpperCase()}`;
213211
}
214212

pnpm-lock.yaml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

postgres/pg-codegen/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
"@pgpmjs/logger": "workspace:^",
4545
"@pgpmjs/server-utils": "workspace:^",
4646
"@pgpmjs/types": "workspace:^",
47+
"inflekt": "^0.5.0",
4748
"pg": "^8.20.0",
4849
"pg-cache": "workspace:^",
4950
"pg-env": "workspace:^",

postgres/pg-codegen/src/codegen/codegen.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import generate from '@babel/generator';
22
import * as t from '@babel/types';
3+
import { toPascalCase } from 'inflekt';
34

45
import { DatabaseObject } from '../types';
56

@@ -162,11 +163,6 @@ export const generateCodeTree = (
162163
return fileTree;
163164
};
164165

165-
const toPascalCase = (str: string): string =>
166-
str
167-
.replace(/[_-](\w)/g, (_, c) => c.toUpperCase())
168-
.replace(/^\w/, (c) => c.toUpperCase());
169-
170166
const mapPostgresTypeToTSType = (typeId: string, isNotNull: boolean): t.TSType => {
171167
const optionalType = (type: t.TSType): t.TSType =>
172168
isNotNull ? type : t.tsUnionType([type, t.tsNullKeyword()]);

0 commit comments

Comments
 (0)