Skip to content

Commit

Permalink
refactor: extract sequence field identification logic
Browse files Browse the repository at this point in the history
  • Loading branch information
p5quared committed Oct 17, 2024
1 parent 2c89d64 commit 759789e
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ const createProperty = (field: Field): ts.Node => {
* @returns Typescript data schema type in TS Node format
*/
const createDataType = (field: Field): ts.Node => {
const sequenceRegex = /^nextval\(.+::regclass\)$/;
if (field.default?.kind === 'DB_GENERATED' && sequenceRegex.test(field.default.value.toString())) {
if (isSequenceField(field)) {
const baseTypeExpression =
field.type.kind === 'NonNull'
? createDataType(new Field(field.name, field.type.type))
Expand Down Expand Up @@ -94,6 +93,11 @@ const createDataType = (field: Field): ts.Node => {
);
};

const isSequenceField = (field: Field): boolean => {
const sequenceRegex = /^nextval\(.+::regclass\)$/;
return field.default?.kind === 'DB_GENERATED' && sequenceRegex.test(field.default.value.toString());
};

const getTypescriptDataSchemaType = (type: string): string => {
const DEFAULT_DATATYPE = TYPESCRIPT_DATA_SCHEMA_CONSTANTS.STRING_METHOD;
const tsDataSchemaType = GQL_TYPESCRIPT_DATA_SCHEMA_TYPE_MAP[type.toLowerCase()];
Expand Down

0 comments on commit 759789e

Please sign in to comment.