@trafficgroup/knex-rel 0.0.28 → 0.1.0
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/.claude/settings.local.json +2 -5
- package/CLAUDE.md +72 -63
- package/dist/dao/VideoMinuteResultDAO.d.ts +149 -0
- package/dist/dao/VideoMinuteResultDAO.js +604 -0
- package/dist/dao/VideoMinuteResultDAO.js.map +1 -0
- package/dist/dao/auth/auth.dao.js +4 -1
- package/dist/dao/auth/auth.dao.js.map +1 -1
- package/dist/dao/chat/chat.dao.d.ts +1 -1
- package/dist/dao/chat/chat.dao.js +25 -35
- package/dist/dao/chat/chat.dao.js.map +1 -1
- package/dist/dao/folder/folder.dao.js +7 -2
- package/dist/dao/folder/folder.dao.js.map +1 -1
- package/dist/dao/message/message.dao.d.ts +1 -1
- package/dist/dao/message/message.dao.js +18 -26
- package/dist/dao/message/message.dao.js.map +1 -1
- package/dist/dao/study/study.dao.js +7 -2
- package/dist/dao/study/study.dao.js.map +1 -1
- package/dist/dao/user/user.dao.js +4 -1
- package/dist/dao/user/user.dao.js.map +1 -1
- package/dist/dao/user-push-notification-token/user-push-notification-token.dao.js +26 -8
- package/dist/dao/user-push-notification-token/user-push-notification-token.dao.js.map +1 -1
- package/dist/dao/video/video.dao.d.ts +8 -0
- package/dist/dao/video/video.dao.js +54 -7
- package/dist/dao/video/video.dao.js.map +1 -1
- package/dist/entities/BaseEntity.d.ts +4 -0
- package/dist/entities/BaseEntity.js +3 -0
- package/dist/entities/BaseEntity.js.map +1 -0
- package/dist/entities/VideoMinuteResult.d.ts +21 -0
- package/dist/entities/VideoMinuteResult.js +3 -0
- package/dist/entities/VideoMinuteResult.js.map +1 -0
- package/dist/index.d.ts +4 -2
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/interfaces/chat/chat.interfaces.d.ts +3 -3
- package/dist/interfaces/folder/folder.interfaces.d.ts +1 -1
- package/dist/interfaces/message/message.interfaces.d.ts +2 -2
- package/dist/interfaces/study/study.interfaces.d.ts +1 -1
- package/dist/interfaces/user/user.interfaces.d.ts +1 -1
- package/dist/interfaces/user-push-notification-token/user-push-notification-token.interfaces.d.ts +1 -1
- package/dist/interfaces/video/video.interfaces.d.ts +7 -2
- package/migrations/20250717160737_migration.ts +1 -1
- package/migrations/20250717160908_migration.ts +5 -2
- package/migrations/20250717161310_migration.ts +1 -1
- package/migrations/20250717161406_migration.ts +3 -3
- package/migrations/20250717162431_migration.ts +1 -1
- package/migrations/20250717173228_migration.ts +2 -2
- package/migrations/20250717204731_migration.ts +1 -1
- package/migrations/20250722210109_migration.ts +8 -4
- package/migrations/20250722211019_migration.ts +1 -1
- package/migrations/20250723153852_migration.ts +13 -10
- package/migrations/20250723162257_migration.ts +4 -7
- package/migrations/20250723171109_migration.ts +4 -7
- package/migrations/20250723205331_migration.ts +6 -9
- package/migrations/20250724191345_migration.ts +8 -11
- package/migrations/20250730180932_migration.ts +14 -13
- package/migrations/20250730213625_migration.ts +8 -11
- package/migrations/20250804124509_migration.ts +26 -21
- package/migrations/20250804132053_migration.ts +5 -8
- package/migrations/20250804164518_migration.ts +7 -7
- package/migrations/20250823223016_migration.ts +46 -0
- package/migrations/20250910015452_migration.ts +34 -0
- package/package.json +47 -47
- package/src/d.types.ts +22 -18
- package/src/dao/VideoMinuteResultDAO.ts +790 -0
- package/src/dao/auth/auth.dao.ts +58 -55
- package/src/dao/chat/chat.dao.ts +45 -43
- package/src/dao/folder/folder.dao.ts +75 -66
- package/src/dao/message/message.dao.ts +32 -32
- package/src/dao/study/study.dao.ts +75 -66
- package/src/dao/user/user.dao.ts +59 -57
- package/src/dao/user-push-notification-token/user-push-notification-token.dao.ts +83 -49
- package/src/dao/video/video.dao.ts +199 -120
- package/src/entities/BaseEntity.ts +4 -0
- package/src/entities/VideoMinuteResult.ts +24 -0
- package/src/index.ts +37 -23
- package/src/interfaces/auth/auth.interfaces.ts +10 -10
- package/src/interfaces/chat/chat.interfaces.ts +4 -4
- package/src/interfaces/folder/folder.interfaces.ts +13 -13
- package/src/interfaces/message/message.interfaces.ts +3 -3
- package/src/interfaces/study/study.interfaces.ts +12 -12
- package/src/interfaces/user/user.interfaces.ts +11 -11
- package/src/interfaces/user-push-notification-token/user-push-notification-token.interfaces.ts +9 -9
- package/src/interfaces/video/video.interfaces.ts +31 -21
package/CLAUDE.md
CHANGED
|
@@ -1,63 +1,72 @@
|
|
|
1
|
-
# CLAUDE.md
|
|
2
|
-
|
|
3
|
-
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
|
4
|
-
|
|
5
|
-
## Project Overview
|
|
6
|
-
|
|
7
|
-
This is `@trafficgroup/knex-rel` - a TypeScript-based Knex.js module for database operations with PostgreSQL. It provides a standardized data access layer with DAOs (Data Access Objects) and interfaces for various entities.
|
|
8
|
-
|
|
9
|
-
## Development Commands
|
|
10
|
-
|
|
11
|
-
### Building and Formatting
|
|
12
|
-
|
|
13
|
-
- `npm run
|
|
14
|
-
- `npm run
|
|
15
|
-
- `npm
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
- `npm run
|
|
21
|
-
- `npm run
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
- `
|
|
37
|
-
-
|
|
38
|
-
|
|
39
|
-
**
|
|
40
|
-
|
|
41
|
-
- `
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
-
|
|
47
|
-
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
1
|
+
# CLAUDE.md
|
|
2
|
+
|
|
3
|
+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
|
4
|
+
|
|
5
|
+
## Project Overview
|
|
6
|
+
|
|
7
|
+
This is `@trafficgroup/knex-rel` - a TypeScript-based Knex.js module for database operations with PostgreSQL. It provides a standardized data access layer with DAOs (Data Access Objects) and interfaces for various entities.
|
|
8
|
+
|
|
9
|
+
## Development Commands
|
|
10
|
+
|
|
11
|
+
### Building and Formatting
|
|
12
|
+
|
|
13
|
+
- `npm run build` - Compile TypeScript to JavaScript in dist/
|
|
14
|
+
- `npm run format` - Format code with Prettier
|
|
15
|
+
- `npm run clean` - Clean dist/, format, and rebuild
|
|
16
|
+
- `npm test` - Run Jest tests
|
|
17
|
+
|
|
18
|
+
### Database Operations
|
|
19
|
+
|
|
20
|
+
- `npm run migrate:create` - Create a new TypeScript migration file
|
|
21
|
+
- `npm run migrate:deploy` - Run all pending migrations
|
|
22
|
+
- `npm run seed:create` - Create a new TypeScript seed file
|
|
23
|
+
- `npm run seed:run` - Execute all seed files
|
|
24
|
+
|
|
25
|
+
### Publishing
|
|
26
|
+
|
|
27
|
+
- `npm run npm:publish` - Clean, build, and publish to npm
|
|
28
|
+
|
|
29
|
+
## Architecture
|
|
30
|
+
|
|
31
|
+
### Core Components
|
|
32
|
+
|
|
33
|
+
**KnexManager** (`src/KnexConnection.ts`): Singleton connection manager
|
|
34
|
+
|
|
35
|
+
- `connect(config?, connections?)` - Establish database connection
|
|
36
|
+
- `getConnection()` - Get active connection instance
|
|
37
|
+
- `disconnect()` - Close connection and cleanup
|
|
38
|
+
|
|
39
|
+
**DAO Pattern**: All data access follows the `IBaseDAO<T>` interface with standard CRUD operations:
|
|
40
|
+
|
|
41
|
+
- `create(item)`, `getById(id)`, `getByUuid(uuid)`, `getAll(page, limit)`, `update(id, item)`, `delete(id)`
|
|
42
|
+
- Returns `IDataPaginator<T>` for paginated results
|
|
43
|
+
|
|
44
|
+
**AuthDAO Additional Methods**:
|
|
45
|
+
|
|
46
|
+
- `getByUserId(userId: number)` - Find auth record by user ID
|
|
47
|
+
- `getByEmailToken(emailToken: string)` - Find auth record by email verification/reset token
|
|
48
|
+
|
|
49
|
+
### Entity Structure
|
|
50
|
+
|
|
51
|
+
Each entity has:
|
|
52
|
+
|
|
53
|
+
- Interface in `src/interfaces/[entity]/[entity].interfaces.ts`
|
|
54
|
+
- DAO implementation in `src/dao/[entity]/[entity].dao.ts`
|
|
55
|
+
|
|
56
|
+
Current entities: User, Study, Folder, Video
|
|
57
|
+
|
|
58
|
+
### Database Configuration
|
|
59
|
+
|
|
60
|
+
Environment variables (for development):
|
|
61
|
+
|
|
62
|
+
- `SQL_HOST`, `SQL_USER`, `SQL_PASSWORD`, `SQL_DB_NAME`, `SQL_PORT`
|
|
63
|
+
|
|
64
|
+
Environment variables (for staging/production):
|
|
65
|
+
|
|
66
|
+
- `PG_HOST`, `PG_USER`, `PG_PASSWORD`, `PG_DB`, `PG_PORT`
|
|
67
|
+
|
|
68
|
+
Knex configuration supports development, staging, and production environments in `knexfile.ts`.
|
|
69
|
+
|
|
70
|
+
### Migrations
|
|
71
|
+
|
|
72
|
+
Located in `migrations/` directory. Use TypeScript format with timestamp prefixes. Database uses `knex_migrations` table for tracking.
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { IBaseDAO, IDataPaginator } from "../d.types";
|
|
2
|
+
import { IVideoMinuteResult, IVideoMinuteResultInput } from "../entities/VideoMinuteResult";
|
|
3
|
+
interface ITMCTurnMovements {
|
|
4
|
+
straight: number;
|
|
5
|
+
left: number;
|
|
6
|
+
right: number;
|
|
7
|
+
"u-turn": number;
|
|
8
|
+
[key: string]: number;
|
|
9
|
+
}
|
|
10
|
+
interface ITMCDirections {
|
|
11
|
+
[direction: string]: ITMCTurnMovements;
|
|
12
|
+
}
|
|
13
|
+
interface ITMCVehicles {
|
|
14
|
+
[vehicleClass: string]: ITMCDirections;
|
|
15
|
+
}
|
|
16
|
+
interface ITMCResult {
|
|
17
|
+
vehicles: ITMCVehicles;
|
|
18
|
+
counts: {
|
|
19
|
+
total_vehicles: number;
|
|
20
|
+
entry_vehicles: number;
|
|
21
|
+
};
|
|
22
|
+
total: number;
|
|
23
|
+
totalcount: number;
|
|
24
|
+
detected_classes: {
|
|
25
|
+
[vehicleClass: string]: number;
|
|
26
|
+
};
|
|
27
|
+
study_type: "TMC";
|
|
28
|
+
}
|
|
29
|
+
interface IATRVehicles {
|
|
30
|
+
[vehicleClass: string]: {
|
|
31
|
+
[lane: string]: number;
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
interface IATRResult {
|
|
35
|
+
vehicles: IATRVehicles;
|
|
36
|
+
lane_counts: {
|
|
37
|
+
[lane: string]: number;
|
|
38
|
+
};
|
|
39
|
+
total_count: number;
|
|
40
|
+
detected_classes: {
|
|
41
|
+
[vehicleClass: string]: number;
|
|
42
|
+
};
|
|
43
|
+
study_type: "ATR";
|
|
44
|
+
}
|
|
45
|
+
interface IGroupedResult {
|
|
46
|
+
groupIndex: number;
|
|
47
|
+
startMinute: number;
|
|
48
|
+
endMinute: number;
|
|
49
|
+
label: string;
|
|
50
|
+
results: ITMCResult | IATRResult;
|
|
51
|
+
minuteCount: number;
|
|
52
|
+
}
|
|
53
|
+
interface IGroupedResponse {
|
|
54
|
+
success: boolean;
|
|
55
|
+
data: IGroupedResult[];
|
|
56
|
+
groupingMinutes: number;
|
|
57
|
+
video: {
|
|
58
|
+
uuid: string;
|
|
59
|
+
name: string;
|
|
60
|
+
videoType: string;
|
|
61
|
+
status: string;
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
export declare class VideoMinuteResultDAO implements IBaseDAO<IVideoMinuteResult> {
|
|
65
|
+
private knex;
|
|
66
|
+
private tableName;
|
|
67
|
+
getAll(page?: number, limit?: number): Promise<IDataPaginator<IVideoMinuteResult>>;
|
|
68
|
+
getById(id: number): Promise<IVideoMinuteResult | null>;
|
|
69
|
+
getByUuid(uuid: string): Promise<IVideoMinuteResult | null>;
|
|
70
|
+
create(data: IVideoMinuteResultInput): Promise<IVideoMinuteResult>;
|
|
71
|
+
update(id: number, data: IVideoMinuteResult): Promise<IVideoMinuteResult | null>;
|
|
72
|
+
delete(id: number): Promise<boolean>;
|
|
73
|
+
/**
|
|
74
|
+
* Get minute results for a specific video with optional time range filtering
|
|
75
|
+
*/
|
|
76
|
+
getMinuteResultsForVideo(videoId: number, startMinute?: number, endMinute?: number, page?: number, limit?: number): Promise<IDataPaginator<IVideoMinuteResult>>;
|
|
77
|
+
/**
|
|
78
|
+
* Create batch of minute results for efficient bulk insertion
|
|
79
|
+
*/
|
|
80
|
+
createBatch(videoId: number, minuteResults: IVideoMinuteResultInput[]): Promise<IVideoMinuteResult[]>;
|
|
81
|
+
/**
|
|
82
|
+
* Delete all minute results for a specific video
|
|
83
|
+
*/
|
|
84
|
+
deleteByVideoId(videoId: number): Promise<boolean>;
|
|
85
|
+
/**
|
|
86
|
+
* Get the minute range for a video (min and max minute numbers)
|
|
87
|
+
*/
|
|
88
|
+
getVideoMinuteRange(videoId: number): Promise<{
|
|
89
|
+
minMinute: number;
|
|
90
|
+
maxMinute: number;
|
|
91
|
+
} | null>;
|
|
92
|
+
/**
|
|
93
|
+
* Map database row to entity (snake_case -> camelCase)
|
|
94
|
+
*/
|
|
95
|
+
private mapDbRowToEntity;
|
|
96
|
+
/**
|
|
97
|
+
* Map multiple database rows to entities
|
|
98
|
+
*/
|
|
99
|
+
private mapDbRowsToEntities;
|
|
100
|
+
/**
|
|
101
|
+
* Map entity to database row (camelCase -> snake_case)
|
|
102
|
+
*/
|
|
103
|
+
private mapEntityToDbRow;
|
|
104
|
+
/**
|
|
105
|
+
* Get minute results by video UUID (convenience method)
|
|
106
|
+
*/
|
|
107
|
+
getMinuteResultsByVideoUuid(videoUuid: string, startMinute?: number, endMinute?: number, page?: number, limit?: number): Promise<IDataPaginator<IVideoMinuteResult>>;
|
|
108
|
+
/**
|
|
109
|
+
* Get grouped minute results by video UUID with time block aggregation
|
|
110
|
+
* @param videoUuid - The UUID of the video
|
|
111
|
+
* @param groupingMinutes - Number of minutes to group together (1, 5, 10, 15, 30, 60)
|
|
112
|
+
* @param startMinute - Optional start minute filter
|
|
113
|
+
* @param endMinute - Optional end minute filter
|
|
114
|
+
*/
|
|
115
|
+
getGroupedMinuteResultsByVideoUuid(videoUuid: string, groupingMinutes?: number, startMinute?: number, endMinute?: number): Promise<IGroupedResponse>;
|
|
116
|
+
/**
|
|
117
|
+
* Aggregate minute results based on video type (TMC or ATR)
|
|
118
|
+
*/
|
|
119
|
+
private aggregateMinuteResults;
|
|
120
|
+
/**
|
|
121
|
+
* Aggregate TMC (Turning Movement Count) results
|
|
122
|
+
*/
|
|
123
|
+
private aggregateTMCResults;
|
|
124
|
+
/**
|
|
125
|
+
* Aggregate ATR (Automatic Traffic Recorder) results
|
|
126
|
+
*/
|
|
127
|
+
private aggregateATRResults;
|
|
128
|
+
/**
|
|
129
|
+
* Generic aggregation for other video types
|
|
130
|
+
*/
|
|
131
|
+
private aggregateGenericResults;
|
|
132
|
+
/**
|
|
133
|
+
* Recursively sum numeric values in nested objects
|
|
134
|
+
*/
|
|
135
|
+
private sumNumericValues;
|
|
136
|
+
/**
|
|
137
|
+
* Deep clone a result structure, setting all numeric values to 0
|
|
138
|
+
*/
|
|
139
|
+
private deepCloneStructure;
|
|
140
|
+
/**
|
|
141
|
+
* Normalize ATR vehicle class names to standard format for frontend compatibility
|
|
142
|
+
*/
|
|
143
|
+
private normalizeATRVehicleClass;
|
|
144
|
+
/**
|
|
145
|
+
* Format time label for display (HH:MM:SS format)
|
|
146
|
+
*/
|
|
147
|
+
private formatTimeLabel;
|
|
148
|
+
}
|
|
149
|
+
export default VideoMinuteResultDAO;
|