🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
♻️ refactor(database): remove dead fallbacks behind v8 ignore in userMemory/model (#21887)
Arvin Xubc02a8317d7d
diff --git a/packages/database/src/models/userMemory/identity.ts b/packages/database/src/models/userMemory/identity.tsindex 05d6c7ed8e9..47fa6d7d5f8 100644--- a/packages/database/src/models/userMemory/identity.ts+++ b/packages/database/src/models/userMemory/identity.ts@@ -124,11 +124,7 @@ export class UserMemoryIdentityModel {: undefined,];- const filters = conditions.filter((condition): condition is SQL => condition !== undefined);- const whereClause =- filters.length > 0- ? and(...filters)- : /* v8 ignore next -- unreachable: eq()/inArray() always yield SQL, so filters is never empty */ undefined;+ const whereClause = and(...conditions);// Build ORDER BYconst applyOrder = order === 'asc' ? asc : desc;diff --git a/packages/database/src/models/userMemory/model/identities.ts b/packages/database/src/models/userMemory/model/identities.tsindex 156d476a26c..5b2c2de9150 100644--- a/packages/database/src/models/userMemory/model/identities.ts+++ b/packages/database/src/models/userMemory/model/identities.ts@@ -21,8 +21,6 @@ import type {import { coerceDate } from './utils';const normalizeRelationshipValue = (input: unknown): RelationshipEnum | null => {- /* v8 ignore next -- unreachable: every caller maps null to null before normalizing */- if (input === null) return null;if (typeof input !== 'string') return null;const normalized = input.trim().toLowerCase();return Object.values(RelationshipEnum).includes(normalized as RelationshipEnum)@@ -31,8 +29,6 @@ const normalizeRelationshipValue = (input: unknown): RelationshipEnum | null =>};const normalizeIdentityTypeValue = (input: unknown): IdentityTypeEnum | null => {- /* v8 ignore next -- unreachable: every caller maps null to null before normalizing */- if (input === null) return null;if (typeof input !== 'string') return null;const normalized = input.trim().toLowerCase();return Object.values(IdentityTypeEnum).includes(normalized as IdentityTypeEnum)diff --git a/packages/database/src/models/userMemory/model/listMemories.ts b/packages/database/src/models/userMemory/model/listMemories.tsindex 0e82383f2b9..9d8e966cf73 100644--- a/packages/database/src/models/userMemory/model/listMemories.ts+++ b/packages/database/src/models/userMemory/model/listMemories.ts@@ -79,11 +79,7 @@ export const listMemories = async <const preferenceSelection = selectNonVectorColumns(userMemoriesPreferences);// TODO(@nekomeowww): extract a shared selection for the activity branch.- const baseConditions: Array<SQL | undefined> = [- ctx.memoryWhere(userMemories),- eq(userMemories.memoryLayer, layer),- ];- const baseWhere = baseConditions.filter(Boolean) as SQL[];+ const baseWhere = and(ctx.memoryWhere(userMemories), eq(userMemories.memoryLayer, layer));const buildOrderBy = (updatedAtColumn: AnyColumn | SQL, createdAtColumn: AnyColumn | SQL) =>[applyOrder(updatedAtColumn), applyOrder(createdAtColumn)].filter(@@ -103,13 +99,6 @@ export const listMemories = async <`,);- const contextFilters: Array<SQL | undefined> = [- baseWhere.length- ? and(...baseWhere)- : /* v8 ignore next -- unreachable: baseWhere always holds the memoryLayer eq() */ undefined,- ];- const contextWhere = contextFilters.filter(Boolean) as SQL[];-const rows = await ctx.db.select({context: contextSelection,@@ -117,11 +106,7 @@ export const listMemories = async <}).from(userMemories).innerJoin(userMemoriesContexts, joinCondition)- .where(- contextWhere.length- ? and(...contextWhere)- : /* v8 ignore next -- unreachable: always holds the non-empty baseWhere and() */ undefined,- )+ .where(baseWhere).orderBy(...orderByClauses).limit(normalizedPageSize).offset(offset);@@ -142,13 +127,6 @@ export const listMemories = async <ctx.memoryWhere(userMemoriesExperiences),);- const experienceFilters: Array<SQL | undefined> = [- baseWhere.length- ? and(...baseWhere)- : /* v8 ignore next -- unreachable: baseWhere always holds the memoryLayer eq() */ undefined,- ];- const experienceWhere = experienceFilters.filter(Boolean) as SQL[];-const rows = await ctx.db.select({experience: experienceSelection,@@ -156,11 +134,7 @@ export const listMemories = async <}).from(userMemories).innerJoin(userMemoriesExperiences, joinCondition)- .where(- experienceWhere.length- ? and(...experienceWhere)- : /* v8 ignore next -- unreachable: always holds the non-empty baseWhere and() */ undefined,- )+ .where(baseWhere).orderBy(...orderByClauses).limit(normalizedPageSize).offset(offset);@@ -181,13 +155,6 @@ export const listMemories = async <ctx.memoryWhere(userMemoriesIdentities),);- const identityFilters: Array<SQL | undefined> = [- baseWhere.length- ? and(...baseWhere)- : /* v8 ignore next -- unreachable: baseWhere always holds the memoryLayer eq() */ undefined,- ];- const identityWhere = identityFilters.filter(Boolean) as SQL[];-const rows = await ctx.db.select({identity: identitySelection,@@ -195,11 +162,7 @@ export const listMemories = async <}).from(userMemories).innerJoin(userMemoriesIdentities, joinCondition)- .where(- identityWhere.length- ? and(...identityWhere)- : /* v8 ignore next -- unreachable: always holds the non-empty baseWhere and() */ undefined,- )+ .where(baseWhere).orderBy(...orderByClauses).limit(normalizedPageSize).offset(offset);@@ -220,13 +183,6 @@ export const listMemories = async <ctx.memoryWhere(userMemoriesPreferences),);- const preferenceFilters: Array<SQL | undefined> = [- baseWhere.length- ? and(...baseWhere)- : /* v8 ignore next -- unreachable: baseWhere always holds the memoryLayer eq() */ undefined,- ];- const preferenceWhere = preferenceFilters.filter(Boolean) as SQL[];-const rows = await ctx.db.select({memory: baseSelection,@@ -234,11 +190,7 @@ export const listMemories = async <}).from(userMemories).innerJoin(userMemoriesPreferences, joinCondition)- .where(- preferenceWhere.length- ? and(...preferenceWhere)- : /* v8 ignore next -- unreachable: always holds the non-empty baseWhere and() */ undefined,- )+ .where(baseWhere).orderBy(...orderByClauses).limit(normalizedPageSize).offset(offset);diff --git a/packages/database/src/models/userMemory/model/queryMemories.ts b/packages/database/src/models/userMemory/model/queryMemories.tsindex 56c67b25051..279aeb19fa9 100644--- a/packages/database/src/models/userMemory/model/queryMemories.ts+++ b/packages/database/src/models/userMemory/model/queryMemories.ts@@ -146,11 +146,7 @@ export const queryMemories = async (eq(userMemories.memoryLayer, resolvedLayer),];- const filters = conditions.filter((condition): condition is SQL => condition !== undefined);- const whereClause =- filters.length > 0- ? and(...filters)- : /* v8 ignore next -- unreachable: eq()/inArray() always yield SQL, so filters is never empty */ undefined;+ const whereClause = and(...conditions);const applyOrder = order === 'asc' ? asc : desc;@@ -245,15 +241,7 @@ export const queryMemories = async (): undefined,];- const contextWhereClause = contextFilters.some(- (condition): condition is SQL => condition !== undefined,- )- ? and(- ...(contextFilters.filter(- (condition): condition is SQL => condition !== undefined,- ) as SQL[]),- )- : /* v8 ignore next -- unreachable: the first filter is the always-defined layer whereClause */ undefined;+ const contextWhereClause = and(...contextFilters);const rowsQuery = ctx.db.select({@@ -355,15 +343,7 @@ export const queryMemories = async (): undefined,];- const activityWhereClause = activityFilters.some(- (condition): condition is SQL => condition !== undefined,- )- ? and(- ...(activityFilters.filter(- (condition): condition is SQL => condition !== undefined,- ) as SQL[]),- )- : /* v8 ignore next -- unreachable: the first filter is the always-defined layer whereClause */ undefined;+ const activityWhereClause = and(...activityFilters);const rowsQuery = ctx.db.select({@@ -463,15 +443,7 @@ export const queryMemories = async (? or(...tags.map((tag) => sql<boolean>`${tag} = ANY(${userMemoriesExperiences.tags})`)): undefined,];- const experienceWhereClause = experienceFilters.some(- (condition): condition is SQL => condition !== undefined,- )- ? and(- ...(experienceFilters.filter(- (condition): condition is SQL => condition !== undefined,- ) as SQL[]),- )- : /* v8 ignore next -- unreachable: the first filter is the always-defined layer whereClause */ undefined;+ const experienceWhereClause = and(...experienceFilters);const rowsQuery = ctx.db.select({@@ -559,15 +531,7 @@ export const queryMemories = async (? or(...tags.map((tag) => sql<boolean>`${tag} = ANY(${userMemoriesIdentities.tags})`)): undefined,];- const identityWhereClause = identityFilters.some(- (condition): condition is SQL => condition !== undefined,- )- ? and(- ...(identityFilters.filter(- (condition): condition is SQL => condition !== undefined,- ) as SQL[]),- )- : /* v8 ignore next -- unreachable: the first filter is the always-defined layer whereClause */ undefined;+ const identityWhereClause = and(...identityFilters);const rowsQuery = ctx.db.select({@@ -662,15 +626,7 @@ export const queryMemories = async (? or(...tags.map((tag) => sql<boolean>`${tag} = ANY(${userMemoriesPreferences.tags})`)): undefined,];- const preferenceWhereClause = preferenceFilters.some(- (condition): condition is SQL => condition !== undefined,- )- ? and(- ...(preferenceFilters.filter(- (condition): condition is SQL => condition !== undefined,- ) as SQL[]),- )- : /* v8 ignore next -- unreachable: the first filter is the always-defined layer whereClause */ undefined;+ const preferenceWhereClause = and(...preferenceFilters);const rowsQuery = ctx.db.select({diff --git a/packages/database/src/models/userMemory/model/utils.ts b/packages/database/src/models/userMemory/model/utils.tsindex db306d68eb7..ec2d0e6c640 100644--- a/packages/database/src/models/userMemory/model/utils.ts+++ b/packages/database/src/models/userMemory/model/utils.ts@@ -36,14 +36,7 @@ export const isPGliteDatabase = (db: LobeChatDatabase) => {}).$client;- return (- 'waitReady' in (client ?? {}) &&- 'dataDir' in- (client ??- // v8 ignore start -- unreachable: a nullish client already failed the waitReady check- {})- // v8 ignore stop- );+ return !!client && 'waitReady' in client && 'dataDir' in client;};export const buildTextSearchCondition = (params: {@@ -75,6 +68,3 @@ export const buildTextSearchCondition = (params: {return conditions.length > 0 ? or(...conditions) : undefined;};--/* v8 ignore next -- unreachable: module-private helper with no callers */-const _pickSingleSearchType = (types?: string[]) => (types?.length === 1 ? types[0] : undefined);