clhq-postgres-module 1.1.0-alpha.106 → 1.1.0-alpha.108
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/entities/index.d.ts +2 -0
- package/dist/entities/index.js +2 -0
- package/dist/entities/project-scene-job.entity.d.ts +38 -0
- package/dist/entities/project-scene-job.entity.js +103 -0
- package/dist/entities/project-scene.entity.d.ts +27 -0
- package/dist/entities/project-scene.entity.js +93 -0
- package/dist/repositories/ai-embedding.repository.d.ts +38 -0
- package/dist/repositories/ai-embedding.repository.js +146 -0
- package/dist/repositories/asset-metadata.repository.d.ts +39 -0
- package/dist/repositories/asset-metadata.repository.js +195 -0
- package/dist/repositories/index.d.ts +6 -0
- package/dist/repositories/index.js +13 -1
- package/dist/repositories/metadata-activity-log.repository.d.ts +41 -0
- package/dist/repositories/metadata-activity-log.repository.js +220 -0
- package/dist/repositories/project-metadata.repository.d.ts +32 -0
- package/dist/repositories/project-metadata.repository.js +186 -0
- package/dist/repositories/project-scene.repository.d.ts +17 -0
- package/dist/repositories/project-scene.repository.js +65 -0
- package/dist/repositories/repository.module.js +10 -0
- package/dist/repositories/user-context.repository.d.ts +66 -0
- package/dist/repositories/user-context.repository.js +161 -0
- package/package.json +1 -1
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.AssetMetadataRepository = void 0;
|
|
16
|
+
const typeorm_1 = require("typeorm");
|
|
17
|
+
const common_1 = require("@nestjs/common");
|
|
18
|
+
const typeorm_2 = require("@nestjs/typeorm");
|
|
19
|
+
const base_repository_1 = require("./base.repository");
|
|
20
|
+
const asset_metadata_entity_1 = require("../entities/asset-metadata.entity");
|
|
21
|
+
let AssetMetadataRepository = class AssetMetadataRepository extends base_repository_1.BaseRepository {
|
|
22
|
+
constructor(assetMetadataRepository) {
|
|
23
|
+
super(assetMetadataRepository);
|
|
24
|
+
this.assetMetadataRepository = assetMetadataRepository;
|
|
25
|
+
}
|
|
26
|
+
async findByAssetId(assetId) {
|
|
27
|
+
return this.assetMetadataRepository.findOne({
|
|
28
|
+
where: { assetId },
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
async findByUserId(userId) {
|
|
32
|
+
return this.assetMetadataRepository.find({
|
|
33
|
+
where: { userId },
|
|
34
|
+
order: { createdAt: 'DESC' },
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
async findByWorkspaceId(workspaceId) {
|
|
38
|
+
return this.assetMetadataRepository.find({
|
|
39
|
+
where: { workspaceId },
|
|
40
|
+
order: { createdAt: 'DESC' },
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
async findByStatus(status) {
|
|
44
|
+
return this.assetMetadataRepository.find({
|
|
45
|
+
where: { status },
|
|
46
|
+
order: { createdAt: 'ASC' },
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
async findPendingForProcessing(limit = 50) {
|
|
50
|
+
return this.assetMetadataRepository.find({
|
|
51
|
+
where: { status: asset_metadata_entity_1.AssetMetadataStatus.PENDING },
|
|
52
|
+
order: { createdAt: 'ASC' },
|
|
53
|
+
take: limit,
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
async updateStatus(id, status, error) {
|
|
57
|
+
const updateData = { status };
|
|
58
|
+
if (error) {
|
|
59
|
+
updateData.processingError = error;
|
|
60
|
+
}
|
|
61
|
+
if (status === asset_metadata_entity_1.AssetMetadataStatus.COMPLETED) {
|
|
62
|
+
updateData.aiProcessedAt = new Date();
|
|
63
|
+
}
|
|
64
|
+
await this.assetMetadataRepository.update(id, updateData);
|
|
65
|
+
return this.findById(id);
|
|
66
|
+
}
|
|
67
|
+
async updateEmbedding(id, embedding, model, version) {
|
|
68
|
+
await this.assetMetadataRepository.update(id, {
|
|
69
|
+
contentEmbedding: embedding,
|
|
70
|
+
embeddingModel: model,
|
|
71
|
+
embeddingVersion: version,
|
|
72
|
+
embeddingGeneratedAt: new Date(),
|
|
73
|
+
});
|
|
74
|
+
return this.findById(id);
|
|
75
|
+
}
|
|
76
|
+
async updateContent(id, content) {
|
|
77
|
+
await this.assetMetadataRepository.update(id, {
|
|
78
|
+
content,
|
|
79
|
+
aiProcessedAt: new Date(),
|
|
80
|
+
});
|
|
81
|
+
return this.findById(id);
|
|
82
|
+
}
|
|
83
|
+
async updateTechnical(id, technical) {
|
|
84
|
+
await this.assetMetadataRepository.update(id, { technical });
|
|
85
|
+
return this.findById(id);
|
|
86
|
+
}
|
|
87
|
+
async findSimilarByEmbedding(embedding, userId, limit = 20, excludeAssetId, minSimilarity = 0.0) {
|
|
88
|
+
const embeddingStr = `[${embedding.join(',')}]`;
|
|
89
|
+
let query = this.assetMetadataRepository
|
|
90
|
+
.createQueryBuilder('am')
|
|
91
|
+
.select('am.*')
|
|
92
|
+
.addSelect(`1 - (COALESCE(am.content_embedding_vec, am.content_embedding::vector(1536)) <=> '${embeddingStr}'::vector(1536))`, 'similarity')
|
|
93
|
+
.where('am.user_id = :userId', { userId })
|
|
94
|
+
.andWhere('(am.content_embedding_vec IS NOT NULL OR am.content_embedding IS NOT NULL)');
|
|
95
|
+
if (excludeAssetId) {
|
|
96
|
+
query = query.andWhere('am.asset_id != :excludeAssetId', { excludeAssetId });
|
|
97
|
+
}
|
|
98
|
+
if (minSimilarity > 0) {
|
|
99
|
+
query = query.andWhere(`1 - (COALESCE(am.content_embedding_vec, am.content_embedding::vector(1536)) <=> '${embeddingStr}'::vector(1536)) >= :minSimilarity`, { minSimilarity });
|
|
100
|
+
}
|
|
101
|
+
const results = await query
|
|
102
|
+
.orderBy(`COALESCE(am.content_embedding_vec, am.content_embedding::vector(1536)) <=> '${embeddingStr}'::vector(1536)`, 'ASC')
|
|
103
|
+
.limit(limit)
|
|
104
|
+
.getRawMany();
|
|
105
|
+
return results;
|
|
106
|
+
}
|
|
107
|
+
async findSimilarByEmbeddingOptimized(embedding, userId, limit = 20, minSimilarity = 0.5) {
|
|
108
|
+
const embeddingStr = `[${embedding.join(',')}]`;
|
|
109
|
+
const results = await this.assetMetadataRepository.query(`SELECT * FROM search_similar_assets_optimized($1::vector(1536), $2, $3, $4)`, [embeddingStr, userId, limit, minSimilarity]);
|
|
110
|
+
return results.map((r) => ({
|
|
111
|
+
assetId: r.asset_id,
|
|
112
|
+
similarity: r.similarity,
|
|
113
|
+
category: r.category,
|
|
114
|
+
tags: r.tags,
|
|
115
|
+
description: r.description,
|
|
116
|
+
usageCount: r.usage_count,
|
|
117
|
+
lastUsedAt: r.last_used_at,
|
|
118
|
+
}));
|
|
119
|
+
}
|
|
120
|
+
async findByTags(userId, tags) {
|
|
121
|
+
return this.assetMetadataRepository
|
|
122
|
+
.createQueryBuilder('am')
|
|
123
|
+
.where('am.user_id = :userId', { userId })
|
|
124
|
+
.andWhere('am.tags && :tags', { tags })
|
|
125
|
+
.orderBy('am.created_at', 'DESC')
|
|
126
|
+
.getMany();
|
|
127
|
+
}
|
|
128
|
+
async searchByKeywords(userId, searchTerm) {
|
|
129
|
+
return this.assetMetadataRepository
|
|
130
|
+
.createQueryBuilder('am')
|
|
131
|
+
.where('am.user_id = :userId', { userId })
|
|
132
|
+
.andWhere(`(
|
|
133
|
+
am.description ILIKE :term
|
|
134
|
+
OR am.category ILIKE :term
|
|
135
|
+
OR :term = ANY(am.tags)
|
|
136
|
+
OR am.content->>'transcription' ILIKE :term
|
|
137
|
+
OR am.content->'keywords' ? :exactTerm
|
|
138
|
+
)`, { term: `%${searchTerm}%`, exactTerm: searchTerm })
|
|
139
|
+
.orderBy('am.created_at', 'DESC')
|
|
140
|
+
.getMany();
|
|
141
|
+
}
|
|
142
|
+
async incrementUsageCount(assetId, projectId) {
|
|
143
|
+
const metadata = await this.findByAssetId(assetId);
|
|
144
|
+
if (!metadata)
|
|
145
|
+
return;
|
|
146
|
+
const projectsUsedIn = metadata.projectsUsedIn || [];
|
|
147
|
+
if (projectId && !projectsUsedIn.includes(projectId)) {
|
|
148
|
+
projectsUsedIn.push(projectId);
|
|
149
|
+
}
|
|
150
|
+
await this.assetMetadataRepository
|
|
151
|
+
.createQueryBuilder()
|
|
152
|
+
.update()
|
|
153
|
+
.set({
|
|
154
|
+
usageCount: () => 'usage_count + 1',
|
|
155
|
+
lastUsedAt: new Date(),
|
|
156
|
+
projectsUsedIn,
|
|
157
|
+
})
|
|
158
|
+
.where('asset_id = :assetId', { assetId })
|
|
159
|
+
.execute();
|
|
160
|
+
}
|
|
161
|
+
async findWithoutEmbeddings(limit = 100) {
|
|
162
|
+
return this.assetMetadataRepository.find({
|
|
163
|
+
where: {
|
|
164
|
+
contentEmbedding: null,
|
|
165
|
+
status: asset_metadata_entity_1.AssetMetadataStatus.COMPLETED,
|
|
166
|
+
},
|
|
167
|
+
order: { createdAt: 'ASC' },
|
|
168
|
+
take: limit,
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
async getStatsForUser(userId) {
|
|
172
|
+
const stats = await this.assetMetadataRepository
|
|
173
|
+
.createQueryBuilder('am')
|
|
174
|
+
.select('COUNT(*)', 'total')
|
|
175
|
+
.addSelect(`COUNT(*) FILTER (WHERE am.status = 'pending')`, 'pending')
|
|
176
|
+
.addSelect(`COUNT(*) FILTER (WHERE am.status = 'completed')`, 'completed')
|
|
177
|
+
.addSelect(`COUNT(*) FILTER (WHERE am.status = 'failed')`, 'failed')
|
|
178
|
+
.addSelect(`COUNT(*) FILTER (WHERE am.content_embedding IS NOT NULL)`, 'withEmbeddings')
|
|
179
|
+
.where('am.user_id = :userId', { userId })
|
|
180
|
+
.getRawOne();
|
|
181
|
+
return {
|
|
182
|
+
total: parseInt(stats.total, 10),
|
|
183
|
+
pending: parseInt(stats.pending, 10),
|
|
184
|
+
completed: parseInt(stats.completed, 10),
|
|
185
|
+
failed: parseInt(stats.failed, 10),
|
|
186
|
+
withEmbeddings: parseInt(stats.withEmbeddings, 10),
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
exports.AssetMetadataRepository = AssetMetadataRepository;
|
|
191
|
+
exports.AssetMetadataRepository = AssetMetadataRepository = __decorate([
|
|
192
|
+
(0, common_1.Injectable)(),
|
|
193
|
+
__param(0, (0, typeorm_2.InjectRepository)(asset_metadata_entity_1.AssetMetadata)),
|
|
194
|
+
__metadata("design:paramtypes", [typeorm_1.Repository])
|
|
195
|
+
], AssetMetadataRepository);
|
|
@@ -24,3 +24,9 @@ export { VideoTranscodeRepository } from './video-transcode.repository';
|
|
|
24
24
|
export { VideoRenderRepository } from './video-render.repository';
|
|
25
25
|
export { VideoFilmstripRepository } from './video-filmstrip.repository';
|
|
26
26
|
export { AudioWaveformRepository } from './audio-waveform.repository';
|
|
27
|
+
export { AssetMetadataRepository } from './asset-metadata.repository';
|
|
28
|
+
export { ProjectMetadataRepository } from './project-metadata.repository';
|
|
29
|
+
export { UserContextRepository } from './user-context.repository';
|
|
30
|
+
export { AiEmbeddingRepository } from './ai-embedding.repository';
|
|
31
|
+
export { MetadataActivityLogRepository } from './metadata-activity-log.repository';
|
|
32
|
+
export { ProjectSceneRepository } from './project-scene.repository';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AudioWaveformRepository = exports.VideoFilmstripRepository = exports.VideoRenderRepository = exports.VideoTranscodeRepository = exports.EffectRepository = exports.AssetRepository = exports.AiUsageRepository = exports.ReferralEventRepository = exports.RewardRuleRepository = exports.CreditTransactionRepository = exports.StripeWebhookRepository = exports.PaymentTransactionRepository = exports.SubscriptionUsageRepository = exports.UserSubscriptionRepository = exports.PlanRepository = exports.SubscriptionPlanRepository = exports.CommentRepository = exports.EditorProjectRepository = exports.InviteRepository = exports.WorkspaceMemberRepository = exports.WorkspaceRepository = exports.AuthSessionRepository = exports.UserOnboardingRepository = exports.UserProfileRepository = exports.UserRepository = exports.BaseRepository = void 0;
|
|
3
|
+
exports.ProjectSceneRepository = exports.MetadataActivityLogRepository = exports.AiEmbeddingRepository = exports.UserContextRepository = exports.ProjectMetadataRepository = exports.AssetMetadataRepository = exports.AudioWaveformRepository = exports.VideoFilmstripRepository = exports.VideoRenderRepository = exports.VideoTranscodeRepository = exports.EffectRepository = exports.AssetRepository = exports.AiUsageRepository = exports.ReferralEventRepository = exports.RewardRuleRepository = exports.CreditTransactionRepository = exports.StripeWebhookRepository = exports.PaymentTransactionRepository = exports.SubscriptionUsageRepository = exports.UserSubscriptionRepository = exports.PlanRepository = exports.SubscriptionPlanRepository = exports.CommentRepository = exports.EditorProjectRepository = exports.InviteRepository = exports.WorkspaceMemberRepository = exports.WorkspaceRepository = exports.AuthSessionRepository = exports.UserOnboardingRepository = exports.UserProfileRepository = exports.UserRepository = exports.BaseRepository = void 0;
|
|
4
4
|
var base_repository_1 = require("./base.repository");
|
|
5
5
|
Object.defineProperty(exports, "BaseRepository", { enumerable: true, get: function () { return base_repository_1.BaseRepository; } });
|
|
6
6
|
var user_repository_1 = require("./user.repository");
|
|
@@ -53,3 +53,15 @@ var video_filmstrip_repository_1 = require("./video-filmstrip.repository");
|
|
|
53
53
|
Object.defineProperty(exports, "VideoFilmstripRepository", { enumerable: true, get: function () { return video_filmstrip_repository_1.VideoFilmstripRepository; } });
|
|
54
54
|
var audio_waveform_repository_1 = require("./audio-waveform.repository");
|
|
55
55
|
Object.defineProperty(exports, "AudioWaveformRepository", { enumerable: true, get: function () { return audio_waveform_repository_1.AudioWaveformRepository; } });
|
|
56
|
+
var asset_metadata_repository_1 = require("./asset-metadata.repository");
|
|
57
|
+
Object.defineProperty(exports, "AssetMetadataRepository", { enumerable: true, get: function () { return asset_metadata_repository_1.AssetMetadataRepository; } });
|
|
58
|
+
var project_metadata_repository_1 = require("./project-metadata.repository");
|
|
59
|
+
Object.defineProperty(exports, "ProjectMetadataRepository", { enumerable: true, get: function () { return project_metadata_repository_1.ProjectMetadataRepository; } });
|
|
60
|
+
var user_context_repository_1 = require("./user-context.repository");
|
|
61
|
+
Object.defineProperty(exports, "UserContextRepository", { enumerable: true, get: function () { return user_context_repository_1.UserContextRepository; } });
|
|
62
|
+
var ai_embedding_repository_1 = require("./ai-embedding.repository");
|
|
63
|
+
Object.defineProperty(exports, "AiEmbeddingRepository", { enumerable: true, get: function () { return ai_embedding_repository_1.AiEmbeddingRepository; } });
|
|
64
|
+
var metadata_activity_log_repository_1 = require("./metadata-activity-log.repository");
|
|
65
|
+
Object.defineProperty(exports, "MetadataActivityLogRepository", { enumerable: true, get: function () { return metadata_activity_log_repository_1.MetadataActivityLogRepository; } });
|
|
66
|
+
var project_scene_repository_1 = require("./project-scene.repository");
|
|
67
|
+
Object.defineProperty(exports, "ProjectSceneRepository", { enumerable: true, get: function () { return project_scene_repository_1.ProjectSceneRepository; } });
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Repository } from 'typeorm';
|
|
2
|
+
import { BaseRepository } from './base.repository';
|
|
3
|
+
import { MetadataActivityLog, MetadataActivityAction, MetadataActivitySource } from '../entities/metadata-activity-log.entity';
|
|
4
|
+
export declare class MetadataActivityLogRepository extends BaseRepository<MetadataActivityLog> {
|
|
5
|
+
private readonly activityLogRepository;
|
|
6
|
+
constructor(activityLogRepository: Repository<MetadataActivityLog>);
|
|
7
|
+
logActivity(data: {
|
|
8
|
+
userId: string;
|
|
9
|
+
workspaceId?: string;
|
|
10
|
+
sessionId?: string;
|
|
11
|
+
entityType: string;
|
|
12
|
+
entityId: string;
|
|
13
|
+
action: MetadataActivityAction;
|
|
14
|
+
source?: MetadataActivitySource;
|
|
15
|
+
metadataBefore?: Record<string, any>;
|
|
16
|
+
metadataAfter?: Record<string, any>;
|
|
17
|
+
details?: Record<string, any>;
|
|
18
|
+
projectId?: string;
|
|
19
|
+
durationMs?: number;
|
|
20
|
+
}): Promise<MetadataActivityLog>;
|
|
21
|
+
findByUserId(userId: string, limit?: number): Promise<MetadataActivityLog[]>;
|
|
22
|
+
findByEntity(entityType: string, entityId: string, limit?: number): Promise<MetadataActivityLog[]>;
|
|
23
|
+
findByProjectId(projectId: string, limit?: number): Promise<MetadataActivityLog[]>;
|
|
24
|
+
findByAction(action: MetadataActivityAction, userId?: string, limit?: number): Promise<MetadataActivityLog[]>;
|
|
25
|
+
findByDateRange(userId: string, startDate: Date, endDate: Date): Promise<MetadataActivityLog[]>;
|
|
26
|
+
findRecentEditActions(userId: string, limit?: number): Promise<MetadataActivityLog[]>;
|
|
27
|
+
findAiInteractions(userId: string, limit?: number): Promise<MetadataActivityLog[]>;
|
|
28
|
+
getActionCounts(userId: string, startDate?: Date): Promise<Record<string, number>>;
|
|
29
|
+
getEffectUsageFromLogs(userId: string, startDate?: Date): Promise<Record<string, number>>;
|
|
30
|
+
getTransitionUsageFromLogs(userId: string, startDate?: Date): Promise<Record<string, number>>;
|
|
31
|
+
getActivityHeatmap(userId: string, days?: number): Promise<{
|
|
32
|
+
hourOfDay: Record<number, number>;
|
|
33
|
+
dayOfWeek: Record<number, number>;
|
|
34
|
+
}>;
|
|
35
|
+
cleanupOldLogs(retentionDays?: number): Promise<number>;
|
|
36
|
+
getSessionSummary(sessionId: string): Promise<{
|
|
37
|
+
actions: number;
|
|
38
|
+
duration: number;
|
|
39
|
+
actionBreakdown: Record<string, number>;
|
|
40
|
+
}>;
|
|
41
|
+
}
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.MetadataActivityLogRepository = void 0;
|
|
16
|
+
const typeorm_1 = require("typeorm");
|
|
17
|
+
const common_1 = require("@nestjs/common");
|
|
18
|
+
const typeorm_2 = require("@nestjs/typeorm");
|
|
19
|
+
const base_repository_1 = require("./base.repository");
|
|
20
|
+
const metadata_activity_log_entity_1 = require("../entities/metadata-activity-log.entity");
|
|
21
|
+
let MetadataActivityLogRepository = class MetadataActivityLogRepository extends base_repository_1.BaseRepository {
|
|
22
|
+
constructor(activityLogRepository) {
|
|
23
|
+
super(activityLogRepository);
|
|
24
|
+
this.activityLogRepository = activityLogRepository;
|
|
25
|
+
}
|
|
26
|
+
async logActivity(data) {
|
|
27
|
+
return this.create({
|
|
28
|
+
...data,
|
|
29
|
+
source: data.source || metadata_activity_log_entity_1.MetadataActivitySource.USER,
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
async findByUserId(userId, limit = 100) {
|
|
33
|
+
return this.activityLogRepository.find({
|
|
34
|
+
where: { userId },
|
|
35
|
+
order: { createdAt: 'DESC' },
|
|
36
|
+
take: limit,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
async findByEntity(entityType, entityId, limit = 50) {
|
|
40
|
+
return this.activityLogRepository.find({
|
|
41
|
+
where: { entityType, entityId },
|
|
42
|
+
order: { createdAt: 'DESC' },
|
|
43
|
+
take: limit,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
async findByProjectId(projectId, limit = 100) {
|
|
47
|
+
return this.activityLogRepository.find({
|
|
48
|
+
where: { projectId },
|
|
49
|
+
order: { createdAt: 'DESC' },
|
|
50
|
+
take: limit,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
async findByAction(action, userId, limit = 100) {
|
|
54
|
+
const where = { action };
|
|
55
|
+
if (userId) {
|
|
56
|
+
where.userId = userId;
|
|
57
|
+
}
|
|
58
|
+
return this.activityLogRepository.find({
|
|
59
|
+
where,
|
|
60
|
+
order: { createdAt: 'DESC' },
|
|
61
|
+
take: limit,
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
async findByDateRange(userId, startDate, endDate) {
|
|
65
|
+
return this.activityLogRepository.find({
|
|
66
|
+
where: {
|
|
67
|
+
userId,
|
|
68
|
+
createdAt: (0, typeorm_1.Between)(startDate, endDate),
|
|
69
|
+
},
|
|
70
|
+
order: { createdAt: 'ASC' },
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
async findRecentEditActions(userId, limit = 500) {
|
|
74
|
+
const editActions = [
|
|
75
|
+
metadata_activity_log_entity_1.MetadataActivityAction.EDIT_CLIP_ADDED,
|
|
76
|
+
metadata_activity_log_entity_1.MetadataActivityAction.EDIT_TRANSITION_ADDED,
|
|
77
|
+
metadata_activity_log_entity_1.MetadataActivityAction.EDIT_EFFECT_ADDED,
|
|
78
|
+
metadata_activity_log_entity_1.MetadataActivityAction.EDIT_TEXT_ADDED,
|
|
79
|
+
metadata_activity_log_entity_1.MetadataActivityAction.EDIT_AUDIO_ADDED,
|
|
80
|
+
metadata_activity_log_entity_1.MetadataActivityAction.EDIT_TRIM,
|
|
81
|
+
];
|
|
82
|
+
return this.activityLogRepository
|
|
83
|
+
.createQueryBuilder('al')
|
|
84
|
+
.where('al.user_id = :userId', { userId })
|
|
85
|
+
.andWhere('al.action IN (:...actions)', { actions: editActions })
|
|
86
|
+
.orderBy('al.created_at', 'DESC')
|
|
87
|
+
.limit(limit)
|
|
88
|
+
.getMany();
|
|
89
|
+
}
|
|
90
|
+
async findAiInteractions(userId, limit = 100) {
|
|
91
|
+
const aiActions = [
|
|
92
|
+
metadata_activity_log_entity_1.MetadataActivityAction.AI_CONTEXT_REQUESTED,
|
|
93
|
+
metadata_activity_log_entity_1.MetadataActivityAction.AI_SUGGESTION_ACCEPTED,
|
|
94
|
+
metadata_activity_log_entity_1.MetadataActivityAction.AI_SUGGESTION_REJECTED,
|
|
95
|
+
metadata_activity_log_entity_1.MetadataActivityAction.AI_CONTENT_GENERATED,
|
|
96
|
+
];
|
|
97
|
+
return this.activityLogRepository
|
|
98
|
+
.createQueryBuilder('al')
|
|
99
|
+
.where('al.user_id = :userId', { userId })
|
|
100
|
+
.andWhere('al.action IN (:...actions)', { actions: aiActions })
|
|
101
|
+
.orderBy('al.created_at', 'DESC')
|
|
102
|
+
.limit(limit)
|
|
103
|
+
.getMany();
|
|
104
|
+
}
|
|
105
|
+
async getActionCounts(userId, startDate) {
|
|
106
|
+
let query = this.activityLogRepository
|
|
107
|
+
.createQueryBuilder('al')
|
|
108
|
+
.select('al.action', 'action')
|
|
109
|
+
.addSelect('COUNT(*)', 'count')
|
|
110
|
+
.where('al.user_id = :userId', { userId })
|
|
111
|
+
.groupBy('al.action');
|
|
112
|
+
if (startDate) {
|
|
113
|
+
query = query.andWhere('al.created_at >= :startDate', { startDate });
|
|
114
|
+
}
|
|
115
|
+
const results = await query.getRawMany();
|
|
116
|
+
return results.reduce((acc, row) => {
|
|
117
|
+
acc[row.action] = parseInt(row.count, 10);
|
|
118
|
+
return acc;
|
|
119
|
+
}, {});
|
|
120
|
+
}
|
|
121
|
+
async getEffectUsageFromLogs(userId, startDate) {
|
|
122
|
+
let query = this.activityLogRepository
|
|
123
|
+
.createQueryBuilder('al')
|
|
124
|
+
.where('al.user_id = :userId', { userId })
|
|
125
|
+
.andWhere('al.action = :action', {
|
|
126
|
+
action: metadata_activity_log_entity_1.MetadataActivityAction.EDIT_EFFECT_ADDED,
|
|
127
|
+
});
|
|
128
|
+
if (startDate) {
|
|
129
|
+
query = query.andWhere('al.created_at >= :startDate', { startDate });
|
|
130
|
+
}
|
|
131
|
+
const logs = await query.getMany();
|
|
132
|
+
const effectCounts = {};
|
|
133
|
+
for (const log of logs) {
|
|
134
|
+
const effectName = log.details?.effectName || log.details?.effect || 'unknown';
|
|
135
|
+
effectCounts[effectName] = (effectCounts[effectName] || 0) + 1;
|
|
136
|
+
}
|
|
137
|
+
return effectCounts;
|
|
138
|
+
}
|
|
139
|
+
async getTransitionUsageFromLogs(userId, startDate) {
|
|
140
|
+
let query = this.activityLogRepository
|
|
141
|
+
.createQueryBuilder('al')
|
|
142
|
+
.where('al.user_id = :userId', { userId })
|
|
143
|
+
.andWhere('al.action = :action', {
|
|
144
|
+
action: metadata_activity_log_entity_1.MetadataActivityAction.EDIT_TRANSITION_ADDED,
|
|
145
|
+
});
|
|
146
|
+
if (startDate) {
|
|
147
|
+
query = query.andWhere('al.created_at >= :startDate', { startDate });
|
|
148
|
+
}
|
|
149
|
+
const logs = await query.getMany();
|
|
150
|
+
const transitionCounts = {};
|
|
151
|
+
for (const log of logs) {
|
|
152
|
+
const transitionName = log.details?.transitionName || log.details?.transition || 'unknown';
|
|
153
|
+
transitionCounts[transitionName] =
|
|
154
|
+
(transitionCounts[transitionName] || 0) + 1;
|
|
155
|
+
}
|
|
156
|
+
return transitionCounts;
|
|
157
|
+
}
|
|
158
|
+
async getActivityHeatmap(userId, days = 30) {
|
|
159
|
+
const startDate = new Date(Date.now() - days * 24 * 60 * 60 * 1000);
|
|
160
|
+
const logs = await this.activityLogRepository.find({
|
|
161
|
+
where: {
|
|
162
|
+
userId,
|
|
163
|
+
createdAt: (0, typeorm_1.MoreThan)(startDate),
|
|
164
|
+
},
|
|
165
|
+
select: ['createdAt'],
|
|
166
|
+
});
|
|
167
|
+
const hourOfDay = {};
|
|
168
|
+
const dayOfWeek = {};
|
|
169
|
+
for (const log of logs) {
|
|
170
|
+
const date = new Date(log.createdAt);
|
|
171
|
+
const hour = date.getHours();
|
|
172
|
+
const day = date.getDay();
|
|
173
|
+
hourOfDay[hour] = (hourOfDay[hour] || 0) + 1;
|
|
174
|
+
dayOfWeek[day] = (dayOfWeek[day] || 0) + 1;
|
|
175
|
+
}
|
|
176
|
+
return { hourOfDay, dayOfWeek };
|
|
177
|
+
}
|
|
178
|
+
async cleanupOldLogs(retentionDays = 90) {
|
|
179
|
+
const cutoffDate = new Date(Date.now() - retentionDays * 24 * 60 * 60 * 1000);
|
|
180
|
+
const result = await this.activityLogRepository.delete({
|
|
181
|
+
createdAt: (0, typeorm_1.LessThan)(cutoffDate),
|
|
182
|
+
});
|
|
183
|
+
return result.affected ?? 0;
|
|
184
|
+
}
|
|
185
|
+
async getSessionSummary(sessionId) {
|
|
186
|
+
const logs = await this.activityLogRepository.find({
|
|
187
|
+
where: { sessionId },
|
|
188
|
+
order: { createdAt: 'ASC' },
|
|
189
|
+
});
|
|
190
|
+
if (logs.length === 0) {
|
|
191
|
+
return { actions: 0, duration: 0, actionBreakdown: {} };
|
|
192
|
+
}
|
|
193
|
+
const actionBreakdown = {};
|
|
194
|
+
let totalDuration = 0;
|
|
195
|
+
for (const log of logs) {
|
|
196
|
+
actionBreakdown[log.action] = (actionBreakdown[log.action] || 0) + 1;
|
|
197
|
+
if (log.durationMs) {
|
|
198
|
+
totalDuration += log.durationMs;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
if (totalDuration === 0 && logs.length > 1) {
|
|
202
|
+
const firstLog = logs[0];
|
|
203
|
+
const lastLog = logs[logs.length - 1];
|
|
204
|
+
totalDuration =
|
|
205
|
+
new Date(lastLog.createdAt).getTime() -
|
|
206
|
+
new Date(firstLog.createdAt).getTime();
|
|
207
|
+
}
|
|
208
|
+
return {
|
|
209
|
+
actions: logs.length,
|
|
210
|
+
duration: totalDuration,
|
|
211
|
+
actionBreakdown,
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
exports.MetadataActivityLogRepository = MetadataActivityLogRepository;
|
|
216
|
+
exports.MetadataActivityLogRepository = MetadataActivityLogRepository = __decorate([
|
|
217
|
+
(0, common_1.Injectable)(),
|
|
218
|
+
__param(0, (0, typeorm_2.InjectRepository)(metadata_activity_log_entity_1.MetadataActivityLog)),
|
|
219
|
+
__metadata("design:paramtypes", [typeorm_1.Repository])
|
|
220
|
+
], MetadataActivityLogRepository);
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Repository } from 'typeorm';
|
|
2
|
+
import { BaseRepository } from './base.repository';
|
|
3
|
+
import { ProjectMetadata } from '../entities/project-metadata.entity';
|
|
4
|
+
export declare class ProjectMetadataRepository extends BaseRepository<ProjectMetadata> {
|
|
5
|
+
private readonly projectMetadataRepository;
|
|
6
|
+
constructor(projectMetadataRepository: Repository<ProjectMetadata>);
|
|
7
|
+
findByProjectId(projectId: string): Promise<ProjectMetadata | null>;
|
|
8
|
+
findByUserId(userId: string): Promise<ProjectMetadata[]>;
|
|
9
|
+
findByWorkspaceId(workspaceId: string): Promise<ProjectMetadata[]>;
|
|
10
|
+
findByProjectType(userId: string, projectType: string): Promise<ProjectMetadata[]>;
|
|
11
|
+
updateComposition(projectId: string, composition: ProjectMetadata['composition']): Promise<ProjectMetadata | null>;
|
|
12
|
+
updateStyleFingerprint(projectId: string, styleFingerprint: ProjectMetadata['styleFingerprint']): Promise<ProjectMetadata | null>;
|
|
13
|
+
updateEmbedding(projectId: string, embedding: number[]): Promise<ProjectMetadata | null>;
|
|
14
|
+
recordEditSession(projectId: string, sessionDurationMs: number): Promise<void>;
|
|
15
|
+
addAssetUsed(projectId: string, assetId: string): Promise<void>;
|
|
16
|
+
incrementEffectUsage(projectId: string, effectName: string): Promise<void>;
|
|
17
|
+
addExportToHistory(projectId: string, exportData: {
|
|
18
|
+
format: string;
|
|
19
|
+
resolution: string;
|
|
20
|
+
fileSize?: number;
|
|
21
|
+
}): Promise<void>;
|
|
22
|
+
recordAiSuggestion(projectId: string, suggestionType: string, accepted: boolean): Promise<void>;
|
|
23
|
+
findSimilarByEmbedding(embedding: number[], userId: string, limit?: number, excludeProjectId?: string): Promise<Array<ProjectMetadata & {
|
|
24
|
+
similarity: number;
|
|
25
|
+
}>>;
|
|
26
|
+
getStylePreferencesForUser(userId: string): Promise<{
|
|
27
|
+
topTransitions: Record<string, number>;
|
|
28
|
+
topEffects: Record<string, number>;
|
|
29
|
+
avgClipDuration: number;
|
|
30
|
+
preferredPacing: string;
|
|
31
|
+
}>;
|
|
32
|
+
}
|