11import { Kysely } from "kysely" ;
22import { GetMetadataArgs } from "../../../graphql/schemas/args/metadataArgs.js" ;
3- import { isWhereEmpty } from "../../../lib/strategies/isWhereEmpty.js" ;
43import { CachingDatabase } from "../../../types/kyselySupabaseCaching.js" ;
54import { MetadataSelect } from "../entities/MetadataEntityService.js" ;
65import { QueryStrategy } from "./QueryStrategy.js" ;
@@ -27,8 +26,24 @@ const supportedColumns = [
2726type MetadataSelection = Omit < MetadataSelect , "image" > ;
2827
2928/**
30- * Strategy for querying metadata
31- * Handles joins with claims table and selects all columns except for the image column
29+ * Strategy for building database queries for metadata records.
30+ * Implements query logic for metadata retrieval and counting.
31+ *
32+ * This strategy handles:
33+ * - Basic metadata queries without filtering
34+ * - Selective column fetching (excludes large fields like 'image' by default)
35+ *
36+ * The strategy is designed to work with the metadata table schema:
37+ * - id: Unique identifier
38+ * - name: Hypercert name
39+ * - description: Detailed description
40+ * - work_scope, impact_scope: Scope definitions
41+ * - timeframe fields: Work and impact time ranges
42+ * - uri: IPFS or other content identifier
43+ * - properties: Additional custom properties
44+ *
45+ * Note: This strategy provides direct table access only. Any relationship
46+ * filtering (e.g., hypercert relationships) should be handled at the service level.
3247 */
3348export class MetadataQueryStrategy extends QueryStrategy <
3449 CachingDatabase ,
@@ -38,33 +53,39 @@ export class MetadataQueryStrategy extends QueryStrategy<
3853> {
3954 protected readonly tableName = "metadata" as const ;
4055
41- buildDataQuery ( db : Kysely < CachingDatabase > , args ?: GetMetadataArgs ) {
42- if ( ! args ) {
43- return db . selectFrom ( this . tableName ) . select ( supportedColumns ) ;
44- }
45-
46- return db
47- . selectFrom ( this . tableName )
48- . $if ( ! isWhereEmpty ( args . where ?. hypercerts ) , ( qb ) =>
49- qb . innerJoin ( "claims" , "claims.uri" , "metadata.uri" ) ,
50- )
51- . select ( supportedColumns ) ;
56+ /**
57+ * Builds a query to retrieve metadata records.
58+ * Returns all records with supported columns.
59+ *
60+ * @param db - Kysely database instance
61+ * @returns A query builder for retrieving metadata data
62+ *
63+ * @example
64+ * ```typescript
65+ * buildDataQuery(db);
66+ * // SELECT supported_columns FROM metadata
67+ * ```
68+ */
69+ buildDataQuery ( db : Kysely < CachingDatabase > ) {
70+ return db . selectFrom ( this . tableName ) . select ( supportedColumns ) ;
5271 }
5372
54- buildCountQuery ( db : Kysely < CachingDatabase > , args ?: GetMetadataArgs ) {
55- if ( ! args ) {
56- return db . selectFrom ( this . tableName ) . select ( ( eb ) => {
57- return eb . fn . countAll ( ) . as ( "count" ) ;
58- } ) ;
59- }
60-
61- return db
62- . selectFrom ( this . tableName )
63- . $if ( ! isWhereEmpty ( args . where ?. hypercerts ) , ( qb ) =>
64- qb . innerJoin ( "claims" , "claims.uri" , "metadata.uri" ) ,
65- )
66- . select ( ( eb ) => {
67- return eb . fn . countAll ( ) . as ( "count" ) ;
68- } ) ;
73+ /**
74+ * Builds a query to count metadata records.
75+ * Returns total count of all records.
76+ *
77+ * @param db - Kysely database instance
78+ * @returns A query builder for counting metadata records
79+ *
80+ * @example
81+ * ```typescript
82+ * buildCountQuery(db);
83+ * // SELECT COUNT(*) as count FROM metadata
84+ * ```
85+ */
86+ buildCountQuery ( db : Kysely < CachingDatabase > ) {
87+ return db . selectFrom ( this . tableName ) . select ( ( eb ) => {
88+ return eb . fn . countAll ( ) . as ( "count" ) ;
89+ } ) ;
6990 }
7091}
0 commit comments