Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/core/nest-cli.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"sourceRoot": "src",
"compilerOptions": {
"builder": "swc",
"typeCheck": true,
"typeCheck": false,
Copy link

Copilot AI Apr 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typeCheck is turned off for the Nest CLI SWC builder. This removes a build-time safety net and can let type errors ship even if CI doesn’t run pnpm typecheck for this app. If there’s a specific performance reason to disable it, consider keeping it enabled in CI builds (or re-enabling it here) and relying on pnpm -C apps/core run typecheck for local speed instead.

Suggested change
"typeCheck": false,
"typeCheck": true,

Copilot uses AI. Check for mistakes.
"plugins": [],
"assets": [
"**/*.json"
Expand Down
6 changes: 3 additions & 3 deletions apps/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@
"@babel/plugin-transform-modules-commonjs": "7.28.6",
"@babel/plugin-transform-typescript": "7.28.6",
"@babel/types": "^7.29.0",
"@better-auth/api-key": "^1.5.1",
"@better-auth/passkey": "^1.5.1",
"@better-auth/api-key": "^1.6.2",
"@better-auth/passkey": "^1.6.2",
"@fastify/cookie": "11.0.2",
"@fastify/multipart": "10.0.0",
"@fastify/static": "9.1.0",
Expand Down Expand Up @@ -92,7 +92,7 @@
"axios": "^1.13.3",
"axios-retry": "4.5.0",
"bcryptjs": "^3.0.3",
"better-auth": "^1.5.1",
"better-auth": "^1.6.2",
"blurhash": "2.0.5",
"cache-manager": "7.2.8",
"commander": "14.0.3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const TRANSLATE_FIELDS_KEY = 'translate_fields'
export interface TranslateFieldRule {
path: string
keyPath: TranslationEntryKeyPath
idField?: string
idField?: 'id'
}

export const TranslateFields = (...rules: TranslateFieldRule[]) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ export class TranslationEntryInterceptor implements NestInterceptor {
private collectEntityIds(
data: any,
path: string,
idField: string,
idField: 'id',
ids: Set<string>,
): void {
this.visitMatches(data, path, ({ parent }) => {
Expand All @@ -297,7 +297,7 @@ export class TranslationEntryInterceptor implements NestInterceptor {
private replaceEntityValues(
data: any,
path: string,
idField: string,
idField: 'id',
map: Map<string, string>,
): void {
this.visitMatches(data, path, ({ parent, property }) => {
Expand Down
1 change: 1 addition & 0 deletions apps/core/src/common/zod/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,6 @@ export {
ExtendedZodValidationPipe,
extendedZodValidationPipeInstance,
} from './validation.pipe'
export { zObjectIdString } from '~/shared/id'
export { createZodDto } from 'nestjs-zod'
export { z } from 'zod'
8 changes: 4 additions & 4 deletions apps/core/src/common/zod/primitives.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { z } from 'zod'

import { zObjectIdString } from '~/shared/id'

// MongoDB Types

export const zMongoId = z
.string()
.regex(/^[0-9a-f]{24}$/i, 'Invalid MongoDB ObjectId')
export const zMongoId = zObjectIdString

export const zMongoIdOrInt = z.union([
zMongoId,
Expand All @@ -24,7 +24,7 @@ export const zNilOrString = z.string().nullable().optional()

export const zHexColor = z
.string()
.regex(/^#([0-9a-f]{3}|[0-9a-f]{6})$/i, 'Invalid hex color')
.regex(/^#([\da-f]{3}|[\da-f]{6})$/i, 'Invalid hex color')

// URL Types

Expand Down
13 changes: 10 additions & 3 deletions apps/core/src/migration/version/v10.4.3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
SEARCH_DOCUMENT_COLLECTION_NAME,
} from '~/constants/db.constant'
import { buildSearchDocument } from '~/modules/search/search-document.util'
import { normalizeDocumentIds } from '~/shared/model/plugins/lean-id'

import { defineMigration } from '../helper'

Expand Down Expand Up @@ -73,9 +74,15 @@ export default defineMigration(
])

const documents = [
...posts.map((doc) => buildSearchDocument('post', doc)),
...pages.map((doc) => buildSearchDocument('page', doc)),
...notes.map((doc) => buildSearchDocument('note', doc)),
...posts.map((doc) =>
buildSearchDocument('post', normalizeDocumentIds(doc)),
),
...pages.map((doc) =>
buildSearchDocument('page', normalizeDocumentIds(doc)),
),
...notes.map((doc) =>
buildSearchDocument('note', normalizeDocumentIds(doc)),
),
]

const collection = db.collection(SEARCH_DOCUMENT_COLLECTION_NAME)
Expand Down
30 changes: 14 additions & 16 deletions apps/core/src/modules/activity/activity.controller.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import { Body, Delete, Get, Param, Post, Query } from '@nestjs/common'
import { keyBy, pick } from 'es-toolkit/compat'

import { ApiController } from '~/common/decorators/api-controller.decorator'
import { Auth } from '~/common/decorators/auth.decorator'
import { HttpCache } from '~/common/decorators/cache.decorator'
import { HTTPDecorators } from '~/common/decorators/http.decorator'
import { IpLocation } from '~/common/decorators/ip.decorator'
import type { IpRecord } from '~/common/decorators/ip.decorator'
import { IpLocation } from '~/common/decorators/ip.decorator'
import { Lang } from '~/common/decorators/lang.decorator'
import { CollectionRefTypes } from '~/constants/db.constant'
import { TranslationService } from '~/processors/helper/helper.translation.service'
import { PagerDto } from '~/shared/dto/pager.dto'
import { snakecaseKeysWithCompat } from '~/utils/case.util'
import { keyBy, pick } from 'es-toolkit/compat'

import { ReaderService } from '../reader/reader.service'
import { Activity } from './activity.constant'
import {
Expand Down Expand Up @@ -74,11 +76,13 @@ export class ActivityController {
const { page, size, type } = pager

switch (type) {
case Activity.Like:
case Activity.Like: {
return this.service.getLikeActivities(page, size)
}

case Activity.ReadDuration:
case Activity.ReadDuration: {
return this.service.getReadDurationActivities(page, size)
}
}
}

Expand All @@ -103,10 +107,7 @@ export class ActivityController {
.findReaderInIds(readerIds)
.then((arr) => {
return arr.map((item) => {
return snakecaseKeysWithCompat({
...item,
id: item._id.toHexString(),
})
return snakecaseKeysWithCompat(item)
})
})

Expand Down Expand Up @@ -159,7 +160,7 @@ export class ActivityController {
targetLang: lang,
translationFields: ['title', 'translationMeta'] as const,
getInput: (item: any) => ({
id: item.id ?? item._id?.toString?.() ?? '',
id: item.id ?? '',
title: item.title ?? '',
created: item.created,
}),
Expand Down Expand Up @@ -340,7 +341,7 @@ export class ActivityController {
targetLang: lang,
translationFields: ['title'] as const,
getInput: (item) => ({
id: item._id?.toString?.() ?? '',
id: item.id ?? '',
title: item.title ?? '',
created: item.created,
modified: item.modified,
Expand All @@ -356,7 +357,7 @@ export class ActivityController {
targetLang: lang,
translationFields: ['title'] as const,
getInput: (item) => ({
id: item._id?.toString?.() ?? '',
id: item.id ?? '',
title: item.title ?? '',
created: item.created,
modified: item.modified,
Expand Down Expand Up @@ -438,7 +439,7 @@ export class ActivityController {
targetLang: lang,
translationFields: ['title', 'translationMeta'] as const,
getInput: (item: any) => ({
id: item._id?.toString?.() ?? item.id ?? '',
id: item.id ?? '',
title: item.title ?? '',
created: item.created,
}),
Expand All @@ -462,10 +463,7 @@ export class ActivityController {
targetLang: lang,
translationFields: ['title', 'translationMeta'] as const,
getInput: (item: any) => ({
id:
item.title === '未公开的日记'
? ''
: (item._id?.toString?.() ?? ''),
id: item.title === '未公开的日记' ? '' : (item.id ?? ''),
title: item.title ?? '',
created: item.created,
}),
Expand Down
17 changes: 9 additions & 8 deletions apps/core/src/modules/activity/activity.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { GatewayService } from '~/processors/gateway/gateway.service'
import { WebEventsGateway } from '~/processors/gateway/web/events.gateway'
import { CountingService } from '~/processors/helper/helper.counting.service'
import { EventManagerService } from '~/processors/helper/helper.event.service'
import { normalizeDocumentIds } from '~/shared/model/plugins/lean-id'
import { InjectModel } from '~/transformers/model.transformer'
import { transformDataToPaginate } from '~/transformers/paginate.transformer'
import { checkRefModelCollectionType } from '~/utils/biz.util'
Expand Down Expand Up @@ -204,7 +205,7 @@ export class ActivityService implements OnModuleInit, OnModuleDestroy {

const readerMap = new Map<string, ReaderModel>()
for (const reader of readers) {
readerMap.set(reader._id.toHexString(), reader)
readerMap.set(reader.id, reader)
}

const type2Collection = {
Expand All @@ -231,7 +232,8 @@ export class ActivityService implements OnModuleInit, OnModuleDestroy {
.toArray()

for (const doc of docs) {
refModelData.set(doc._id.toHexString(), doc)
normalizeDocumentIds(doc)
refModelData.set(doc.id, doc)
}
}

Expand Down Expand Up @@ -337,7 +339,6 @@ export class ActivityService implements OnModuleInit, OnModuleDestroy {
reader,
ref: pick(refModel, [
'id',
'_id',
'title',
'nid',
'slug',
Expand Down Expand Up @@ -395,11 +396,7 @@ export class ActivityService implements OnModuleInit, OnModuleDestroy {
const reader = await this.readerService.findReaderInIds([data.readerId])
if (reader.length) {
Object.assign(serializedPresenceData, {
reader: camelcaseKeys({
...reader[0],
_id: undefined,
id: reader[0]._id.toHexString(),
}),
reader: camelcaseKeys(reader[0]),
})
}
}
Expand Down Expand Up @@ -635,6 +632,10 @@ export class ActivityService implements OnModuleInit, OnModuleDestroy {
.toArray(),
])

normalizeDocumentIds(recent)
normalizeDocumentIds(post)
normalizeDocumentIds(note)

const postCategoryIds = post.map((p: any) => p.categoryId).filter(Boolean)
const categories =
postCategoryIds.length > 0
Expand Down
13 changes: 5 additions & 8 deletions apps/core/src/modules/aggregate/aggregate.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@ export class AggregateController {

if (lang) {
type TopItem = {
_id?: any
id?: string
title?: string
created?: Date | null
Expand All @@ -183,7 +182,7 @@ export class AggregateController {
targetLang: lang,
translationFields: ['title', 'translationMeta'] as const,
getInput: (item) => ({
id: item._id?.toString?.() ?? item.id ?? '',
id: item.id ?? '',
title: item.title ?? '',
created: item.created,
modified: item.modified,
Expand All @@ -206,7 +205,7 @@ export class AggregateController {
targetLang: lang,
translationFields: ['title', 'translationMeta'] as const,
getInput: (item) => ({
id: item._id?.toString?.() ?? item.id ?? '',
id: item.id ?? '',
title: item.title ?? '',
created: item.created,
modified: item.modified,
Expand Down Expand Up @@ -241,7 +240,6 @@ export class AggregateController {
if (!lang) return result

type LatestItem = {
_id?: any
id?: string
title?: string
created?: Date | null
Expand All @@ -254,7 +252,7 @@ export class AggregateController {
targetLang: lang,
translationFields: ['title', 'translationMeta'] as const,
getInput: (item) => ({
id: item._id?.toString?.() ?? item.id ?? '',
id: item.id ?? '',
title: item.title ?? '',
created: item.created,
modified: item.modified,
Expand Down Expand Up @@ -298,7 +296,6 @@ export class AggregateController {
const { sort = 1, type, year } = query
const data = await this.aggregateService.getTimeline(year, type, sort)
type TimelineItem = {
_id?: { toString?: () => string } | string
id?: string
title: string
created?: Date | null
Expand All @@ -313,7 +310,7 @@ export class AggregateController {
targetLang: lang,
translationFields: ['title', 'translationMeta'] as const,
getInput: (post) => ({
id: post._id?.toString?.() ?? post.id ?? String(post._id),
id: post.id ?? '',
title: post.title,
modified: post.modified,
created: post.created,
Expand All @@ -338,7 +335,7 @@ export class AggregateController {
targetLang: lang,
translationFields: ['title', 'translationMeta'] as const,
getInput: (note) => ({
id: note._id?.toString?.() ?? note.id ?? String(note._id),
id: note.id ?? '',
title: note.title,
modified: note.modified,
created: note.created,
Expand Down
6 changes: 3 additions & 3 deletions apps/core/src/modules/aggregate/aggregate.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export class AggregateService {
.then((list) =>
list.map((item) => ({
...pick(item, [
'_id',
'id',
'title',
'slug',
'created',
Expand Down Expand Up @@ -220,7 +220,7 @@ export class AggregateService {

.then((list) =>
list.map((item) => ({
...pick(item, ['_id', 'title', 'slug', 'created', 'modified']),
...pick(item, ['id', 'title', 'slug', 'created', 'modified']),
category: item.category,
url: encodeURI(
`/posts/${(item.category as CategoryModel).slug}/${item.slug}`,
Expand Down Expand Up @@ -740,7 +740,7 @@ export class AggregateService {
.lean()

return posts.map((post) => ({
id: post._id,
id: post.id,
title: post.title,
slug: post.slug,
reads: post.count?.read || 0,
Expand Down
4 changes: 2 additions & 2 deletions apps/core/src/modules/ai/ai-summary/ai-summary.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -456,8 +456,8 @@ export class AiSummaryService implements OnModuleInit {
])

matchedRefIds = [
...matchedPosts.map((p) => p._id.toString()),
...matchedNotes.map((n) => n._id.toString()),
...matchedPosts.map((post) => post.id),
...matchedNotes.map((note) => note.id),
]

if (matchedRefIds.length === 0) {
Expand Down
Loading
Loading