Skip to content

Commit de397b1

Browse files
committed
fix(pr): pr review comments
1 parent 77037f7 commit de397b1

File tree

17 files changed

+58
-124
lines changed

17 files changed

+58
-124
lines changed

src/lib/db/queryModifiers/applyPagination.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { SelectQueryBuilder, Selectable } from "kysely";
2-
import { SupportedDatabases } from "../../../services/database/strategies/QueryStrategy.js";
2+
import { SupportedDatabase } from "../../../services/database/strategies/QueryStrategy.js";
33

44
/**
55
* Type definition for pagination parameters
@@ -36,7 +36,7 @@ type PaginationArgs = {
3636
* ```
3737
*/
3838
export function applyPagination<
39-
DB extends SupportedDatabases,
39+
DB extends SupportedDatabase,
4040
T extends keyof DB & string,
4141
Args extends PaginationArgs,
4242
>(

src/lib/db/queryModifiers/applySort.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { SelectQueryBuilder, Selectable } from "kysely";
22
import { SortOrder } from "../../../graphql/schemas/enums/sortEnums.js";
3-
import { SupportedDatabases } from "../../../services/database/strategies/QueryStrategy.js";
3+
import { SupportedDatabase } from "../../../services/database/strategies/QueryStrategy.js";
44

55
/**
66
* Applies sorting to a query based on the provided arguments.
@@ -35,7 +35,7 @@ import { SupportedDatabases } from "../../../services/database/strategies/QueryS
3535
* ```
3636
*/
3737
export function applySort<
38-
DB extends SupportedDatabases,
38+
DB extends SupportedDatabase,
3939
T extends keyof DB & string,
4040
Args extends {
4141
sortBy?: { [K in keyof DB[T]]?: SortOrder | null | undefined };

src/lib/db/queryModifiers/applyWhere.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { expressionBuilder, SelectQueryBuilder, Selectable } from "kysely";
2-
import { SupportedDatabases } from "../../../services/database/strategies/QueryStrategy.js";
2+
import { SupportedDatabase } from "../../../services/database/strategies/QueryStrategy.js";
33
import { BaseQueryArgsType } from "../../graphql/BaseQueryArgs.js";
44
import { SortOrder } from "../../../graphql/schemas/enums/sortEnums.js";
55
import {
@@ -40,7 +40,7 @@ import {
4040
* ```
4141
*/
4242
export function applyWhere<
43-
DB extends SupportedDatabases,
43+
DB extends SupportedDatabase,
4444
T extends keyof DB & string,
4545
// TODO: cleaner typing than object, object. We'd need to have a general where input type
4646
Args extends BaseQueryArgsType<

src/lib/db/queryModifiers/buildWhereCondition.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Expression, ExpressionBuilder, sql, SqlBool } from "kysely";
2-
import { SupportedDatabases } from "../../../services/database/strategies/QueryStrategy.js";
2+
import { SupportedDatabase } from "../../../services/database/strategies/QueryStrategy.js";
33
import { getRelation, hasRelation } from "./tableRelations.js";
44

55
// Define more specific types for our filter values
@@ -195,7 +195,7 @@ const filterBuilders: Record<FilterOperator, FilterBuilder> = {
195195
* - Undefined values in filter conditions are ignored
196196
*/
197197
export function buildWhereCondition<
198-
DB extends SupportedDatabases,
198+
DB extends SupportedDatabase,
199199
T extends keyof DB,
200200
>(
201201
tableName: T,

src/lib/db/queryModifiers/queryModifiers.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { SelectQueryBuilder, Selectable } from "kysely";
22
import { SortOrder } from "../../../graphql/schemas/enums/sortEnums.js";
3-
import { SupportedDatabases } from "../../../services/database/strategies/QueryStrategy.js";
3+
import { SupportedDatabase } from "../../../services/database/strategies/QueryStrategy.js";
44
import { BaseQueryArgsType } from "../../graphql/BaseQueryArgs.js";
55
import { applyPagination } from "./applyPagination.js";
66
import { applySort } from "./applySort.js";
@@ -27,7 +27,7 @@ import { applyWhere } from "./applyWhere.js";
2727
* ```
2828
*/
2929
export type QueryModifier<
30-
DB extends SupportedDatabases,
30+
DB extends SupportedDatabase,
3131
T extends keyof DB & string,
3232
Args,
3333
> = (
@@ -64,7 +64,7 @@ export type QueryModifier<
6464
* ```
6565
*/
6666
export function composeQueryModifiers<
67-
DB extends SupportedDatabases,
67+
DB extends SupportedDatabase,
6868
T extends keyof DB & string,
6969
Args,
7070
>(...modifiers: QueryModifier<DB, T, Args>[]) {
@@ -105,7 +105,7 @@ export function composeQueryModifiers<
105105
* ```
106106
*/
107107
export function createStandardQueryModifier<
108-
DB extends SupportedDatabases,
108+
DB extends SupportedDatabase,
109109
T extends keyof DB & string,
110110
Args extends BaseQueryArgsType<
111111
object,

src/services/database/entities/EntityServiceFactory.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
import { BaseQueryArgsType } from "../../../lib/graphql/BaseQueryArgs.js";
99
import {
1010
QueryStrategy,
11-
SupportedDatabases,
11+
SupportedDatabase,
1212
} from "../strategies/QueryStrategy.js";
1313
import { QueryStrategyFactory } from "../strategies/QueryStrategyFactory.js";
1414

@@ -45,7 +45,7 @@ export interface EntityService<TEntity, TArgs> {
4545
* @throws {Error} If the strategy for the table cannot be found
4646
*/
4747
export function createEntityService<
48-
DB extends SupportedDatabases,
48+
DB extends SupportedDatabase,
4949
T extends keyof DB & string,
5050
Args extends BaseQueryArgsType<
5151
Record<string, unknown>,

src/services/database/strategies/QueryStrategy.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Kysely, Selectable, SelectQueryBuilder } from "kysely";
33
import type { CachingDatabase } from "../../../types/kyselySupabaseCaching.js";
44
import type { DataDatabase } from "../../../types/kyselySupabaseData.js";
55

6-
export type SupportedDatabases = CachingDatabase | DataDatabase;
6+
export type SupportedDatabase = CachingDatabase | DataDatabase;
77

88
/**
99
* Abstract base class for building database queries with a consistent interface.
@@ -38,7 +38,7 @@ export type SupportedDatabases = CachingDatabase | DataDatabase;
3838
* }
3939
*/
4040
export abstract class QueryStrategy<
41-
DB extends SupportedDatabases,
41+
DB extends SupportedDatabase,
4242
T extends keyof DB & string,
4343
Args = void,
4444
Selection = Selectable<DB[T]>,

src/services/database/strategies/QueryStrategyFactory.ts

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { FractionsQueryStrategy } from "./FractionsQueryStrategy.js";
99
import { HyperboardsQueryStrategy } from "./HyperboardsQueryStrategy.js";
1010
import { MarketplaceOrdersQueryStrategy } from "./MarketplaceOrdersQueryStrategy.js";
1111
import { MetadataQueryStrategy } from "./MetadataQueryStrategy.js";
12-
import { QueryStrategy, SupportedDatabases } from "./QueryStrategy.js";
12+
import { QueryStrategy, SupportedDatabase } from "./QueryStrategy.js";
1313
import { SalesQueryStrategy } from "./SalesQueryStrategy.js";
1414
import { SignatureRequestsQueryStrategy } from "./SignatureRequestsQueryStrategy.js";
1515
import { SupportedSchemasQueryStrategy } from "./SupportedSchemasQueryStrategy.js";
@@ -29,7 +29,7 @@ type QueryArgs = BaseQueryArgsType<
2929
* Type for strategy constructors to ensure they match the QueryStrategy interface
3030
*/
3131
type QueryStrategyConstructor<
32-
DB extends SupportedDatabases = SupportedDatabases,
32+
DB extends SupportedDatabase = SupportedDatabase,
3333
T extends keyof DB & string = keyof DB & string,
3434
Args extends QueryArgs = QueryArgs,
3535
> = new () => QueryStrategy<DB, T, Args>;
@@ -38,8 +38,8 @@ type QueryStrategyConstructor<
3838
* Type for the strategy registry mapping table names to their constructors
3939
*/
4040
type StrategyRegistry = {
41-
[K in keyof SupportedDatabases & string]: QueryStrategyConstructor<
42-
SupportedDatabases,
41+
[K in keyof SupportedDatabase & string]: QueryStrategyConstructor<
42+
SupportedDatabase,
4343
K
4444
>;
4545
};
@@ -48,10 +48,7 @@ type StrategyRegistry = {
4848
* Type for the strategy cache mapping table names to their instances
4949
*/
5050
type StrategyCache = {
51-
[K in keyof SupportedDatabases & string]?: QueryStrategy<
52-
SupportedDatabases,
53-
K
54-
>;
51+
[K in keyof SupportedDatabase & string]?: QueryStrategy<SupportedDatabase, K>;
5552
};
5653

5754
/**
@@ -91,13 +88,13 @@ export class QueryStrategyFactory {
9188
* Cache of strategy instances
9289
* @private
9390
*/
94-
private static strategies: StrategyCache = new Proxy<StrategyCache>(
91+
private static strategies = new Proxy<StrategyCache>(
9592
{},
9693
{
97-
get<K extends keyof SupportedDatabases & string>(
94+
get<K extends keyof SupportedDatabase & string>(
9895
target: StrategyCache,
9996
prop: K | string | symbol,
100-
): QueryStrategy<SupportedDatabases, K> | undefined {
97+
): QueryStrategy<SupportedDatabase, K> | undefined {
10198
if (typeof prop !== "string") {
10299
return undefined;
103100
}
@@ -106,7 +103,7 @@ export class QueryStrategyFactory {
106103

107104
// Check if we already have a cached instance
108105
if (key in target && target[key]) {
109-
return target[key] as QueryStrategy<SupportedDatabases, K>;
106+
return target[key] as QueryStrategy<SupportedDatabase, K>;
110107
}
111108

112109
// Get the constructor from the registry
@@ -121,10 +118,10 @@ export class QueryStrategyFactory {
121118

122119
// Create and cache a new instance
123120
const strategy = new Constructor() as QueryStrategy<
124-
SupportedDatabases,
121+
SupportedDatabase,
125122
K
126123
>;
127-
(target as Record<K, QueryStrategy<SupportedDatabases, K>>)[key] =
124+
(target as Record<K, QueryStrategy<SupportedDatabase, K>>)[key] =
128125
strategy;
129126
return strategy;
130127
},
@@ -140,18 +137,17 @@ export class QueryStrategyFactory {
140137
* @throws Error if no strategy is registered for the table
141138
*/
142139
static getStrategy<
143-
DB extends SupportedDatabases,
140+
DB extends SupportedDatabase,
144141
T extends keyof DB & string,
145142
Args extends QueryArgs = QueryArgs,
146143
>(tableName: T): QueryStrategy<DB, T, Args> {
147-
const strategy = (this.strategies as Record<T, QueryStrategy<DB, T, Args>>)[
148-
tableName
149-
];
144+
const strategy =
145+
this.strategies[tableName as keyof SupportedDatabase & string];
150146
if (!strategy) {
151147
throw new Error(
152148
`Failed to get strategy for table "${tableName}". This might be a type mismatch or the strategy is not properly registered.`,
153149
);
154150
}
155-
return strategy;
151+
return strategy as QueryStrategy<DB, T, Args>;
156152
}
157153
}

src/services/graphql/resolvers/collectionResolver.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { User } from "../../../graphql/schemas/typeDefs/userTypeDefs.js";
1010

1111
import { inject, injectable } from "tsyringe";
1212
import { CollectionService } from "../../database/entities/CollectionEntityService.js";
13-
import { Hypercert } from "../../../graphql/schemas/typeDefs/hypercertTypeDefs.js";
13+
import { GetHypercertsResponse } from "../../../graphql/schemas/typeDefs/hypercertTypeDefs.js";
1414

1515
/**
1616
* GraphQL resolver for Collection operations.
@@ -113,7 +113,7 @@ class CollectionResolver {
113113
* }
114114
* ```
115115
*/
116-
@FieldResolver(() => [Hypercert])
116+
@FieldResolver(() => GetHypercertsResponse)
117117
async hypercerts(@Root() collection: Collection) {
118118
if (!collection.id) {
119119
console.error(

src/types/argTypes.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,6 @@ import {
99
SignatureRequestStatusSearchOptions,
1010
} from "../graphql/schemas/inputs/searchOptions.js";
1111

12-
export type SearchOptionType = {
13-
string: typeof StringSearchOptions;
14-
number: typeof NumberSearchOptions;
15-
bigint: typeof BigIntSearchOptions;
16-
id: typeof IdSearchOptions;
17-
boolean: typeof BooleanSearchOptions;
18-
stringArray: typeof StringArraySearchOptions;
19-
numberArray: typeof NumberArraySearchOptions;
20-
enum: typeof SignatureRequestStatusSearchOptions;
21-
};
22-
2312
export const SearchOptionMap = {
2413
string: StringSearchOptions,
2514
number: NumberSearchOptions,

0 commit comments

Comments
 (0)