@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.
Files changed (83) hide show
  1. package/.claude/settings.local.json +2 -5
  2. package/CLAUDE.md +72 -63
  3. package/dist/dao/VideoMinuteResultDAO.d.ts +149 -0
  4. package/dist/dao/VideoMinuteResultDAO.js +604 -0
  5. package/dist/dao/VideoMinuteResultDAO.js.map +1 -0
  6. package/dist/dao/auth/auth.dao.js +4 -1
  7. package/dist/dao/auth/auth.dao.js.map +1 -1
  8. package/dist/dao/chat/chat.dao.d.ts +1 -1
  9. package/dist/dao/chat/chat.dao.js +25 -35
  10. package/dist/dao/chat/chat.dao.js.map +1 -1
  11. package/dist/dao/folder/folder.dao.js +7 -2
  12. package/dist/dao/folder/folder.dao.js.map +1 -1
  13. package/dist/dao/message/message.dao.d.ts +1 -1
  14. package/dist/dao/message/message.dao.js +18 -26
  15. package/dist/dao/message/message.dao.js.map +1 -1
  16. package/dist/dao/study/study.dao.js +7 -2
  17. package/dist/dao/study/study.dao.js.map +1 -1
  18. package/dist/dao/user/user.dao.js +4 -1
  19. package/dist/dao/user/user.dao.js.map +1 -1
  20. package/dist/dao/user-push-notification-token/user-push-notification-token.dao.js +26 -8
  21. package/dist/dao/user-push-notification-token/user-push-notification-token.dao.js.map +1 -1
  22. package/dist/dao/video/video.dao.d.ts +8 -0
  23. package/dist/dao/video/video.dao.js +54 -7
  24. package/dist/dao/video/video.dao.js.map +1 -1
  25. package/dist/entities/BaseEntity.d.ts +4 -0
  26. package/dist/entities/BaseEntity.js +3 -0
  27. package/dist/entities/BaseEntity.js.map +1 -0
  28. package/dist/entities/VideoMinuteResult.d.ts +21 -0
  29. package/dist/entities/VideoMinuteResult.js +3 -0
  30. package/dist/entities/VideoMinuteResult.js.map +1 -0
  31. package/dist/index.d.ts +4 -2
  32. package/dist/index.js +3 -1
  33. package/dist/index.js.map +1 -1
  34. package/dist/interfaces/chat/chat.interfaces.d.ts +3 -3
  35. package/dist/interfaces/folder/folder.interfaces.d.ts +1 -1
  36. package/dist/interfaces/message/message.interfaces.d.ts +2 -2
  37. package/dist/interfaces/study/study.interfaces.d.ts +1 -1
  38. package/dist/interfaces/user/user.interfaces.d.ts +1 -1
  39. package/dist/interfaces/user-push-notification-token/user-push-notification-token.interfaces.d.ts +1 -1
  40. package/dist/interfaces/video/video.interfaces.d.ts +7 -2
  41. package/migrations/20250717160737_migration.ts +1 -1
  42. package/migrations/20250717160908_migration.ts +5 -2
  43. package/migrations/20250717161310_migration.ts +1 -1
  44. package/migrations/20250717161406_migration.ts +3 -3
  45. package/migrations/20250717162431_migration.ts +1 -1
  46. package/migrations/20250717173228_migration.ts +2 -2
  47. package/migrations/20250717204731_migration.ts +1 -1
  48. package/migrations/20250722210109_migration.ts +8 -4
  49. package/migrations/20250722211019_migration.ts +1 -1
  50. package/migrations/20250723153852_migration.ts +13 -10
  51. package/migrations/20250723162257_migration.ts +4 -7
  52. package/migrations/20250723171109_migration.ts +4 -7
  53. package/migrations/20250723205331_migration.ts +6 -9
  54. package/migrations/20250724191345_migration.ts +8 -11
  55. package/migrations/20250730180932_migration.ts +14 -13
  56. package/migrations/20250730213625_migration.ts +8 -11
  57. package/migrations/20250804124509_migration.ts +26 -21
  58. package/migrations/20250804132053_migration.ts +5 -8
  59. package/migrations/20250804164518_migration.ts +7 -7
  60. package/migrations/20250823223016_migration.ts +46 -0
  61. package/migrations/20250910015452_migration.ts +34 -0
  62. package/package.json +47 -47
  63. package/src/d.types.ts +22 -18
  64. package/src/dao/VideoMinuteResultDAO.ts +790 -0
  65. package/src/dao/auth/auth.dao.ts +58 -55
  66. package/src/dao/chat/chat.dao.ts +45 -43
  67. package/src/dao/folder/folder.dao.ts +75 -66
  68. package/src/dao/message/message.dao.ts +32 -32
  69. package/src/dao/study/study.dao.ts +75 -66
  70. package/src/dao/user/user.dao.ts +59 -57
  71. package/src/dao/user-push-notification-token/user-push-notification-token.dao.ts +83 -49
  72. package/src/dao/video/video.dao.ts +199 -120
  73. package/src/entities/BaseEntity.ts +4 -0
  74. package/src/entities/VideoMinuteResult.ts +24 -0
  75. package/src/index.ts +37 -23
  76. package/src/interfaces/auth/auth.interfaces.ts +10 -10
  77. package/src/interfaces/chat/chat.interfaces.ts +4 -4
  78. package/src/interfaces/folder/folder.interfaces.ts +13 -13
  79. package/src/interfaces/message/message.interfaces.ts +3 -3
  80. package/src/interfaces/study/study.interfaces.ts +12 -12
  81. package/src/interfaces/user/user.interfaces.ts +11 -11
  82. package/src/interfaces/user-push-notification-token/user-push-notification-token.interfaces.ts +9 -9
  83. package/src/interfaces/video/video.interfaces.ts +31 -21
@@ -1,9 +1,6 @@
1
1
  {
2
2
  "permissions": {
3
- "allow": [
4
- "Bash(npm run migrate:*)",
5
- "Bash(mkdir:*)"
6
- ],
3
+ "allow": ["Bash(npm run migrate:*)", "Bash(mkdir:*)"],
7
4
  "deny": []
8
5
  }
9
- }
6
+ }
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
- - `npm run build` - Compile TypeScript to JavaScript in dist/
13
- - `npm run format` - Format code with Prettier
14
- - `npm run clean` - Clean dist/, format, and rebuild
15
- - `npm test` - Run Jest tests
16
-
17
- ### Database Operations
18
- - `npm run migrate:create` - Create a new TypeScript migration file
19
- - `npm run migrate:deploy` - Run all pending migrations
20
- - `npm run seed:create` - Create a new TypeScript seed file
21
- - `npm run seed:run` - Execute all seed files
22
-
23
- ### Publishing
24
- - `npm run npm:publish` - Clean, build, and publish to npm
25
-
26
- ## Architecture
27
-
28
- ### Core Components
29
-
30
- **KnexManager** (`src/KnexConnection.ts`): Singleton connection manager
31
- - `connect(config?, connections?)` - Establish database connection
32
- - `getConnection()` - Get active connection instance
33
- - `disconnect()` - Close connection and cleanup
34
-
35
- **DAO Pattern**: All data access follows the `IBaseDAO<T>` interface with standard CRUD operations:
36
- - `create(item)`, `getById(id)`, `getByUuid(uuid)`, `getAll(page, limit)`, `update(id, item)`, `delete(id)`
37
- - Returns `IDataPaginator<T>` for paginated results
38
-
39
- **AuthDAO Additional Methods**:
40
- - `getByUserId(userId: number)` - Find auth record by user ID
41
- - `getByEmailToken(emailToken: string)` - Find auth record by email verification/reset token
42
-
43
- ### Entity Structure
44
-
45
- Each entity has:
46
- - Interface in `src/interfaces/[entity]/[entity].interfaces.ts`
47
- - DAO implementation in `src/dao/[entity]/[entity].dao.ts`
48
-
49
- Current entities: User, Study, Folder, Video
50
-
51
- ### Database Configuration
52
-
53
- Environment variables (for development):
54
- - `SQL_HOST`, `SQL_USER`, `SQL_PASSWORD`, `SQL_DB_NAME`, `SQL_PORT`
55
-
56
- Environment variables (for staging/production):
57
- - `PG_HOST`, `PG_USER`, `PG_PASSWORD`, `PG_DB`, `PG_PORT`
58
-
59
- Knex configuration supports development, staging, and production environments in `knexfile.ts`.
60
-
61
- ### Migrations
62
-
63
- Located in `migrations/` directory. Use TypeScript format with timestamp prefixes. Database uses `knex_migrations` table for tracking.
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;