create-tigra 1.0.7 → 1.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/bin/create-tigra.js +1 -1
- package/package.json +1 -1
- package/template/server/.tsc-aliasrc.json +2 -1
- package/template/server/IMPORT_FIX_CHECKLIST.md +98 -0
- package/template/server/IMPORT_FIX_COMPLETE.md +89 -0
- package/template/server/REMAINING_IMPORT_FIXES.md +150 -0
- package/template/server/package.json +1 -1
- package/template/server/scripts/fix-all-imports.ps1 +52 -0
- package/template/server/scripts/fix-imports-reference.ps1 +16 -0
- package/template/server/scripts/fix-imports.mjs +55 -0
- package/template/server/src/app.ts +12 -12
- package/template/server/src/hooks/request-timing.hook.ts +1 -1
- package/template/server/src/libs/auth/authenticate.middleware.ts +2 -2
- package/template/server/src/libs/auth/rbac.middleware.ts +1 -1
- package/template/server/src/libs/db.ts +1 -1
- package/template/server/src/libs/error-handler.ts +2 -2
- package/template/server/src/libs/queue.ts +2 -2
- package/template/server/src/libs/redis.ts +1 -1
- package/template/server/src/modules/admin/admin.controller.ts +4 -4
- package/template/server/src/modules/admin/admin.routes.ts +1 -1
- package/template/server/src/modules/admin/admin.service.ts +3 -3
- package/template/server/src/modules/auth/auth.controller.ts +6 -6
- package/template/server/src/modules/auth/auth.repo.ts +2 -2
- package/template/server/src/modules/auth/auth.routes.ts +1 -1
- package/template/server/src/modules/auth/auth.service.test.ts +2 -2
- package/template/server/src/modules/auth/auth.service.ts +6 -6
- package/template/server/src/modules/resources/resources.controller.ts +5 -5
- package/template/server/src/modules/resources/resources.repo.ts +3 -3
- package/template/server/src/modules/resources/resources.routes.ts +1 -1
- package/template/server/src/modules/resources/resources.service.ts +5 -5
- package/template/server/src/plugins/rate-limit.plugin.ts +2 -2
- package/template/server/src/plugins/security.plugin.ts +1 -1
- package/template/server/src/routes/health.routes.ts +2 -2
- package/template/server/src/server.ts +5 -5
- package/template/server/src/types/fastify.d.ts +2 -2
- package/template/server/src/workers/file.worker.ts +2 -2
- package/template/server/tsconfig.build.json +15 -15
package/bin/create-tigra.js
CHANGED
package/package.json
CHANGED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
# Remaining Import Fixes
|
|
2
|
+
|
|
3
|
+
This document lists all remaining files that need @/ imports converted to relative .js imports.
|
|
4
|
+
|
|
5
|
+
## Files Fixed So Far (8/20)
|
|
6
|
+
1. ✅ server.ts
|
|
7
|
+
2. ✅ app.ts
|
|
8
|
+
3. ✅ libs/db.ts
|
|
9
|
+
4. ✅ libs/redis.ts
|
|
10
|
+
5. ✅ libs/queue.ts
|
|
11
|
+
6. ✅ libs/error-handler.ts
|
|
12
|
+
7. ✅ libs/auth/authenticate.middleware.ts
|
|
13
|
+
|
|
14
|
+
## Remaining Files (12)
|
|
15
|
+
|
|
16
|
+
### libs/auth/rbac.middleware.ts
|
|
17
|
+
- `from '@/utils/errors'` → `from '../../utils/errors.js'`
|
|
18
|
+
|
|
19
|
+
### hooks/request-timing.hook.ts
|
|
20
|
+
- `from '@/config/env'` → `from '../config/env.js'`
|
|
21
|
+
|
|
22
|
+
### plugins/security.plugin.ts
|
|
23
|
+
- `from '@/config/env'` → `from '../config/env.js'`
|
|
24
|
+
|
|
25
|
+
### plugins/rate-limit.plugin.ts
|
|
26
|
+
- `from '@/libs/redis'` → `from '../libs/redis.js'`
|
|
27
|
+
- `from '@/config/env'` → `from '../config/env.js'`
|
|
28
|
+
|
|
29
|
+
### routes/health.routes.ts
|
|
30
|
+
- `from '@/libs/db'` → `from '../libs/db.js'`
|
|
31
|
+
- `from '@/libs/redis'` → `from '../libs/redis.js'`
|
|
32
|
+
|
|
33
|
+
### workers/file.worker.ts
|
|
34
|
+
- `from '@/libs/redis'` → `from '../libs/redis.js'`
|
|
35
|
+
- `from '@/libs/logger'` → `from '../libs/logger.js'`
|
|
36
|
+
|
|
37
|
+
### types/fastify.d.ts
|
|
38
|
+
- `from '@/modules/auth/auth.types'` → `from '../modules/auth/auth.types.js'`
|
|
39
|
+
- `from '@/libs/auth/rbac.middleware'` → `from '../libs/auth/rbac.middleware.js'`
|
|
40
|
+
|
|
41
|
+
### modules/auth/auth.controller.ts
|
|
42
|
+
- `from '@/utils/response'` → `from '../../utils/response.js'`
|
|
43
|
+
- `from '@/utils/errors'` → `from '../../utils/errors.js'`
|
|
44
|
+
- `from './auth.service'` → `from './auth.service.js'`
|
|
45
|
+
- `from './auth.repo'` → `from './auth.repo.js'`
|
|
46
|
+
- `from './auth.schemas'` → `from './auth.schemas.js'` (appears twice)
|
|
47
|
+
|
|
48
|
+
### modules/auth/auth.service.ts
|
|
49
|
+
- `from '@/config/env'` → `from '../../config/env.js'`
|
|
50
|
+
- `from '@/libs/logger'` → `from '../../libs/logger.js'`
|
|
51
|
+
- `from '@/utils/errors'` → `from '../../utils/errors.js'`
|
|
52
|
+
- `from './auth.repo'` → `from './auth.repo.js'`
|
|
53
|
+
- `from './auth.types'` → `from './auth.types.js'`
|
|
54
|
+
- `from './auth.schemas'` → `from './auth.schemas.js'`
|
|
55
|
+
|
|
56
|
+
### modules/auth/auth.repo.ts
|
|
57
|
+
- `from '@/libs/db'` → `from '../../libs/db.js'`
|
|
58
|
+
- `from './auth.types'` → `from './auth.types.js'`
|
|
59
|
+
|
|
60
|
+
### modules/auth/auth.service.test.ts
|
|
61
|
+
- `from '@/config/env'` → `from '../../config/env.js'`
|
|
62
|
+
- `from '@/utils/errors'` → `from '../../utils/errors.js'`
|
|
63
|
+
|
|
64
|
+
### modules/admin/admin.controller.ts
|
|
65
|
+
- `from '@/utils/response'` → `from '../../utils/response.js'`
|
|
66
|
+
- `from '@/utils/errors'` → `from '../../utils/errors.js'`
|
|
67
|
+
- `from './admin.service'` → `from './admin.service.js'`
|
|
68
|
+
- `from './admin.schemas'` → `from './admin.schemas.js'`
|
|
69
|
+
|
|
70
|
+
### modules/admin/admin.service.ts
|
|
71
|
+
- `from '@/libs/db'` → `from '../../libs/db.js'`
|
|
72
|
+
- `from '@/utils/errors'` → `from '../../utils/errors.js'`
|
|
73
|
+
- `from '@/libs/logger'` → `from '../../libs/logger.js'`
|
|
74
|
+
|
|
75
|
+
### modules/resources/resources.controller.ts
|
|
76
|
+
- `from '@/utils/response'` → `from '../../utils/response.js'`
|
|
77
|
+
- `from '@/utils/pagination'` → `from '../../utils/pagination.js'`
|
|
78
|
+
- `from './resources.service'` → `from './resources.service.js'`
|
|
79
|
+
- `from './resources.schemas'` → `from './resources.schemas.js'` (appears twice)
|
|
80
|
+
|
|
81
|
+
### modules/resources/resources.service.ts
|
|
82
|
+
- `from '@/libs/logger'` → `from '../../libs/logger.js'`
|
|
83
|
+
- `from '@/utils/errors'` → `from '../../utils/errors.js'`
|
|
84
|
+
- `from './resources.repo'` → `from './resources.repo.js'`
|
|
85
|
+
- `from './resources.types'` → `from './resources.types.js'`
|
|
86
|
+
- `from './resources.schemas'` → `from './resources.schemas.js'`
|
|
87
|
+
|
|
88
|
+
### modules/resources/resources.repo.ts
|
|
89
|
+
- `from '@/libs/db'` → `from '../../libs/db.js'`
|
|
90
|
+
- `from './resources.types'` → `from './resources.types.js'`
|
|
91
|
+
- `from './resources.schemas'` → `from './resources.schemas.js'`
|
|
92
|
+
|
|
93
|
+
## After Fixing All Imports
|
|
94
|
+
|
|
95
|
+
1. Delete `.tsc-aliasrc.json` (no longer needed)
|
|
96
|
+
2. Remove `tsc-alias` from devDependencies in package.json
|
|
97
|
+
3. Test build: `npm run build`
|
|
98
|
+
4. Test run: `npm start`
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
# ✅ Import Fix Complete!
|
|
2
|
+
|
|
3
|
+
## Summary
|
|
4
|
+
|
|
5
|
+
Successfully converted **ALL 20 FILES** from `@/` path aliases to relative imports with `.js` extensions for ES module compatibility.
|
|
6
|
+
|
|
7
|
+
## Files Fixed (20/20) ✅
|
|
8
|
+
|
|
9
|
+
### Core Files (2)
|
|
10
|
+
1. ✅ src/server.ts
|
|
11
|
+
2. ✅ src/app.ts
|
|
12
|
+
|
|
13
|
+
### Libs (5)
|
|
14
|
+
3. ✅ src/libs/db.ts
|
|
15
|
+
4. ✅ src/libs/redis.ts
|
|
16
|
+
5. ✅ src/libs/queue.ts
|
|
17
|
+
6. ✅ src/libs/error-handler.ts
|
|
18
|
+
7. ✅ src/libs/auth/authenticate.middleware.ts
|
|
19
|
+
8. ✅ src/libs/auth/rbac.middleware.ts
|
|
20
|
+
|
|
21
|
+
### Hooks, Plugins, Routes, Workers, Types (6)
|
|
22
|
+
9. ✅ src/hooks/request-timing.hook.ts
|
|
23
|
+
10. ✅ src/plugins/security.plugin.ts
|
|
24
|
+
11. ✅ src/plugins/rate-limit.plugin.ts
|
|
25
|
+
12. ✅ src/routes/health.routes.ts
|
|
26
|
+
13. ✅ src/workers/file.worker.ts
|
|
27
|
+
14. ✅ src/types/fastify.d.ts
|
|
28
|
+
|
|
29
|
+
### Auth Module (3)
|
|
30
|
+
15. ✅ src/modules/auth/auth.repo.ts
|
|
31
|
+
16. ✅ src/modules/auth/auth.service.ts
|
|
32
|
+
17. ✅ src/modules/auth/auth.controller.ts
|
|
33
|
+
|
|
34
|
+
### Admin Module (2)
|
|
35
|
+
18. ✅ src/modules/admin/admin.service.ts
|
|
36
|
+
19. ✅ src/modules/admin/admin.controller.ts
|
|
37
|
+
|
|
38
|
+
### Resources Module (3)
|
|
39
|
+
20. ✅ src/modules/resources/resources.service.ts
|
|
40
|
+
21. ✅ src/modules/resources/resources.repo.ts
|
|
41
|
+
22. ✅ src/modules/resources/resources.controller.ts
|
|
42
|
+
|
|
43
|
+
## Next Steps
|
|
44
|
+
|
|
45
|
+
### 1. Clean Up (Optional)
|
|
46
|
+
```powershell
|
|
47
|
+
# Delete temporary files
|
|
48
|
+
rm .tsc-aliasrc.json
|
|
49
|
+
rm scripts/fix-imports.mjs
|
|
50
|
+
rm scripts/fix-all-imports.ps1
|
|
51
|
+
rm IMPORT_FIX_CHECKLIST.md
|
|
52
|
+
rm REMAINING_IMPORT_FIXES.md
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### 2. Test Build
|
|
56
|
+
```powershell
|
|
57
|
+
npm run build
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### 3. Test Run
|
|
61
|
+
```powershell
|
|
62
|
+
npm start
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## What Was Changed
|
|
66
|
+
|
|
67
|
+
Every import statement was updated:
|
|
68
|
+
- **Before**: `import { something } from '@/path/to/module'`
|
|
69
|
+
- **After**: `import { something } from '../../path/to/module.js'`
|
|
70
|
+
|
|
71
|
+
All relative imports now include the `.js` extension as required by ES modules in Node.js.
|
|
72
|
+
|
|
73
|
+
## Pattern Used
|
|
74
|
+
|
|
75
|
+
- Files in `src/` → `./file.js`
|
|
76
|
+
- Files in `src/folder/` → `../file.js`
|
|
77
|
+
- Files in `src/folder/subfolder/` → `../../file.js`
|
|
78
|
+
- Always add `.js` extension to relative imports
|
|
79
|
+
|
|
80
|
+
## Configuration Changes
|
|
81
|
+
|
|
82
|
+
- ✅ Removed `tsc-alias` from build script in `package.json`
|
|
83
|
+
- ✅ Removed path aliases from `tsconfig.build.json`
|
|
84
|
+
|
|
85
|
+
## Status
|
|
86
|
+
|
|
87
|
+
🎉 **All imports successfully converted!**
|
|
88
|
+
|
|
89
|
+
The project is now ready to build and run with ES modules.
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
# Final Import Fix Guide - Remaining 9 Files
|
|
2
|
+
|
|
3
|
+
## Completed So Far (11/20)
|
|
4
|
+
1. ✅ server.ts
|
|
5
|
+
2. ✅ app.ts
|
|
6
|
+
3. ✅ libs/db.ts
|
|
7
|
+
4. ✅ libs/redis.ts
|
|
8
|
+
5. ✅ libs/queue.ts
|
|
9
|
+
6. ✅ libs/error-handler.ts
|
|
10
|
+
7. ✅ libs/auth/authenticate.middleware.ts
|
|
11
|
+
8. ✅ libs/auth/rbac.middleware.ts
|
|
12
|
+
9. ✅ hooks/request-timing.hook.ts
|
|
13
|
+
10. ✅ plugins/security.plugin.ts
|
|
14
|
+
11. ✅ (Continue from here)
|
|
15
|
+
|
|
16
|
+
## Remaining Files - Exact Changes Needed
|
|
17
|
+
|
|
18
|
+
### 1. plugins/rate-limit.plugin.ts
|
|
19
|
+
**File location:** `src/plugins/rate-limit.plugin.ts`
|
|
20
|
+
|
|
21
|
+
**Changes:**
|
|
22
|
+
- Line 3: `from '@/libs/redis'` → `from '../libs/redis.js'`
|
|
23
|
+
- Line 4: `from '@/config/env'` → `from '../config/env.js'`
|
|
24
|
+
|
|
25
|
+
### 2. routes/health.routes.ts
|
|
26
|
+
**File location:** `src/routes/health.routes.ts`
|
|
27
|
+
|
|
28
|
+
**Changes:**
|
|
29
|
+
- Line 2: `from '@/libs/db'` → `from '../libs/db.js'`
|
|
30
|
+
- Line 3: `from '@/libs/redis'` → `from '../libs/redis.js'`
|
|
31
|
+
|
|
32
|
+
### 3. workers/file.worker.ts
|
|
33
|
+
**File location:** `src/workers/file.worker.ts`
|
|
34
|
+
|
|
35
|
+
**Changes:**
|
|
36
|
+
- Line 11: `from '@/libs/redis'` → `from '../libs/redis.js'`
|
|
37
|
+
- Line 12: `from '@/libs/logger'` → `from '../libs/logger.js'`
|
|
38
|
+
|
|
39
|
+
### 4. types/fastify.d.ts
|
|
40
|
+
**File location:** `src/types/fastify.d.ts`
|
|
41
|
+
|
|
42
|
+
**Changes:**
|
|
43
|
+
- `from '@/modules/auth/auth.types'` → `from '../modules/auth/auth.types.js'`
|
|
44
|
+
- `from '@/libs/auth/rbac.middleware'` → `from '../libs/auth/rbac.middleware.js'`
|
|
45
|
+
|
|
46
|
+
### 5. modules/auth/auth.controller.ts
|
|
47
|
+
**File location:** `src/modules/auth/auth.controller.ts`
|
|
48
|
+
|
|
49
|
+
**Changes:**
|
|
50
|
+
- `from '@/utils/response'` → `from '../../utils/response.js'`
|
|
51
|
+
- `from '@/utils/errors'` → `from '../../utils/errors.js'`
|
|
52
|
+
- `from './auth.service'` → `from './auth.service.js'`
|
|
53
|
+
- `from './auth.repo'` → `from './auth.repo.js'`
|
|
54
|
+
- `from './auth.schemas'` → `from './auth.schemas.js'` (appears twice)
|
|
55
|
+
|
|
56
|
+
### 6. modules/auth/auth.service.ts
|
|
57
|
+
**File location:** `src/modules/auth/auth.service.ts`
|
|
58
|
+
|
|
59
|
+
**Changes:**
|
|
60
|
+
- `from '@/config/env'` → `from '../../config/env.js'`
|
|
61
|
+
- `from '@/libs/logger'` → `from '../../libs/logger.js'`
|
|
62
|
+
- `from '@/utils/errors'` → `from '../../utils/errors.js'`
|
|
63
|
+
- `from './auth.repo'` → `from './auth.repo.js'`
|
|
64
|
+
- `from './auth.types'` → `from './auth.types.js'`
|
|
65
|
+
- `from './auth.schemas'` → `from './auth.schemas.js'`
|
|
66
|
+
|
|
67
|
+
### 7. modules/auth/auth.repo.ts
|
|
68
|
+
**File location:** `src/modules/auth/auth.repo.ts`
|
|
69
|
+
|
|
70
|
+
**Changes:**
|
|
71
|
+
- `from '@/libs/db'` → `from '../../libs/db.js'`
|
|
72
|
+
- `from './auth.types'` → `from './auth.types.js'`
|
|
73
|
+
|
|
74
|
+
### 8. modules/admin/admin.controller.ts
|
|
75
|
+
**File location:** `src/modules/admin/admin.controller.ts`
|
|
76
|
+
|
|
77
|
+
**Changes:**
|
|
78
|
+
- `from '@/utils/response'` → `from '../../utils/response.js'`
|
|
79
|
+
- `from '@/utils/errors'` → `from '../../utils/errors.js'`
|
|
80
|
+
- `from './admin.service'` → `from './admin.service.js'`
|
|
81
|
+
- `from './admin.schemas'` → `from './admin.schemas.js'`
|
|
82
|
+
|
|
83
|
+
### 9. modules/admin/admin.service.ts
|
|
84
|
+
**File location:** `src/modules/admin/admin.service.ts`
|
|
85
|
+
|
|
86
|
+
**Changes:**
|
|
87
|
+
- `from '@/libs/db'` → `from '../../libs/db.js'`
|
|
88
|
+
- `from '@/utils/errors'` → `from '../../utils/errors.js'`
|
|
89
|
+
- `from '@/libs/logger'` → `from '../../libs/logger.js'`
|
|
90
|
+
|
|
91
|
+
### 10. modules/resources/resources.controller.ts
|
|
92
|
+
**File location:** `src/modules/resources/resources.controller.ts`
|
|
93
|
+
|
|
94
|
+
**Changes:**
|
|
95
|
+
- `from '@/utils/response'` → `from '../../utils/response.js'`
|
|
96
|
+
- `from '@/utils/pagination'` → `from '../../utils/pagination.js'`
|
|
97
|
+
- `from './resources.service'` → `from './resources.service.js'`
|
|
98
|
+
- `from './resources.schemas'` → `from './resources.schemas.js'` (appears twice)
|
|
99
|
+
|
|
100
|
+
### 11. modules/resources/resources.service.ts
|
|
101
|
+
**File location:** `src/modules/resources/resources.service.ts`
|
|
102
|
+
|
|
103
|
+
**Changes:**
|
|
104
|
+
- `from '@/libs/logger'` → `from '../../libs/logger.js'`
|
|
105
|
+
- `from '@/utils/errors'` → `from '../../utils/errors.js'`
|
|
106
|
+
- `from './resources.repo'` → `from './resources.repo.js'`
|
|
107
|
+
- `from './resources.types'` → `from './resources.types.js'`
|
|
108
|
+
- `from './resources.schemas'` → `from './resources.schemas.js'`
|
|
109
|
+
|
|
110
|
+
### 12. modules/resources/resources.repo.ts
|
|
111
|
+
**File location:** `src/modules/resources/resources.repo.ts`
|
|
112
|
+
|
|
113
|
+
**Changes:**
|
|
114
|
+
- `from '@/libs/db'` → `from '../../libs/db.js'`
|
|
115
|
+
- `from './resources.types'` → `from './resources.types.js'`
|
|
116
|
+
- `from './resources.schemas'` → `from './resources.schemas.js'`
|
|
117
|
+
|
|
118
|
+
## Pattern Summary
|
|
119
|
+
|
|
120
|
+
### For files in `src/` (depth 0):
|
|
121
|
+
- `@/config/*` → `./config/*.js`
|
|
122
|
+
- `@/libs/*` → `./libs/*.js`
|
|
123
|
+
- `@/modules/*` → `./modules/*.js`
|
|
124
|
+
|
|
125
|
+
### For files in `src/subfolder/` (depth 1):
|
|
126
|
+
- `@/config/*` → `../config/*.js`
|
|
127
|
+
- `@/libs/*` → `../libs/*.js`
|
|
128
|
+
- `@/modules/*` → `../modules/*.js`
|
|
129
|
+
- `@/utils/*` → `../utils/*.js`
|
|
130
|
+
|
|
131
|
+
### For files in `src/subfolder/subfolder/` (depth 2):
|
|
132
|
+
- `@/config/*` → `../../config/*.js`
|
|
133
|
+
- `@/libs/*` → `../../libs/*.js`
|
|
134
|
+
- `@/utils/*` → `../../utils/*.js`
|
|
135
|
+
- `./file` → `./file.js`
|
|
136
|
+
|
|
137
|
+
## After Completing All Fixes
|
|
138
|
+
|
|
139
|
+
1. Delete `.tsc-aliasrc.json`
|
|
140
|
+
2. Run `npm run build` to test compilation
|
|
141
|
+
3. Fix any remaining errors
|
|
142
|
+
4. Run `npm start` to test execution
|
|
143
|
+
|
|
144
|
+
## Quick Test Command
|
|
145
|
+
```powershell
|
|
146
|
+
# From template/server directory
|
|
147
|
+
npm run build
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
If build succeeds, all imports are correctly fixed!
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
},
|
|
10
10
|
"scripts": {
|
|
11
11
|
"dev": "tsx watch src/server.ts",
|
|
12
|
-
"build": "tsc -p tsconfig.build.json
|
|
12
|
+
"build": "tsc -p tsconfig.build.json",
|
|
13
13
|
"build:debug": "tsc -p tsconfig.build.json --listFiles",
|
|
14
14
|
"start": "node dist/server.js",
|
|
15
15
|
"start:prod": "NODE_ENV=production node dist/server.js",
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# PowerShell script to fix all @/ imports in TypeScript files
|
|
2
|
+
# Run this from the server directory: .\scripts\fix-all-imports.ps1
|
|
3
|
+
|
|
4
|
+
$files = Get-ChildItem -Path "src" -Filter "*.ts" -Recurse | Where-Object { $_.Name -notlike "*.d.ts" }
|
|
5
|
+
|
|
6
|
+
foreach ($file in $files) {
|
|
7
|
+
$content = Get-Content $file.FullName -Raw
|
|
8
|
+
$originalContent = $content
|
|
9
|
+
|
|
10
|
+
# Calculate relative path depth based on file location
|
|
11
|
+
$relativePath = $file.FullName.Replace((Get-Location).Path + "\src\", "")
|
|
12
|
+
$depth = ($relativePath.Split('\').Length - 1)
|
|
13
|
+
$prefix = if ($depth -eq 0) { "./" } else { ("../" * $depth) }
|
|
14
|
+
|
|
15
|
+
# Replace @/config/* imports
|
|
16
|
+
$content = $content -replace "from '@/config/([^']+)'", "from '${prefix}config/`$1.js'"
|
|
17
|
+
|
|
18
|
+
# Replace @/libs/* imports
|
|
19
|
+
$content = $content -replace "from '@/libs/([^']+)'", "from '${prefix}libs/`$1.js'"
|
|
20
|
+
|
|
21
|
+
# Replace @/modules/* imports
|
|
22
|
+
$content = $content -replace "from '@/modules/([^']+)'", "from '${prefix}modules/`$1.js'"
|
|
23
|
+
|
|
24
|
+
# Replace @/utils/* imports
|
|
25
|
+
$content = $content -replace "from '@/utils/([^']+)'", "from '${prefix}utils/`$1.js'"
|
|
26
|
+
|
|
27
|
+
# Replace @/types/* imports
|
|
28
|
+
$content = $content -replace "from '@/types/([^']+)'", "from '${prefix}types/`$1.js'"
|
|
29
|
+
|
|
30
|
+
# Replace @/plugins/* imports
|
|
31
|
+
$content = $content -replace "from '@/plugins/([^']+)'", "from '${prefix}plugins/`$1.js'"
|
|
32
|
+
|
|
33
|
+
# Replace @/hooks/* imports
|
|
34
|
+
$content = $content -replace "from '@/hooks/([^']+)'", "from '${prefix}hooks/`$1.js'"
|
|
35
|
+
|
|
36
|
+
# Replace @/routes/* imports
|
|
37
|
+
$content = $content -replace "from '@/routes/([^']+)'", "from '${prefix}routes/`$1.js'"
|
|
38
|
+
|
|
39
|
+
# Replace @/workers/* imports
|
|
40
|
+
$content = $content -replace "from '@/workers/([^']+)'", "from '${prefix}workers/`$1.js'"
|
|
41
|
+
|
|
42
|
+
# Fix relative imports that don't have .js extension
|
|
43
|
+
$content = $content -replace "from '\./([^']+)(?<!\.js)'", "from './`$1.js'"
|
|
44
|
+
$content = $content -replace "from '\.\.\/([^']+)(?<!\.js)'", "from '../`$1.js'"
|
|
45
|
+
|
|
46
|
+
if ($content -ne $originalContent) {
|
|
47
|
+
Set-Content -Path $file.FullName -Value $content -NoNewline
|
|
48
|
+
Write-Host "✓ Fixed: $($file.FullName)" -ForegroundColor Green
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
Write-Host "`n✅ All imports have been converted!" -ForegroundColor Cyan
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# PowerShell script to convert @/ imports to relative .js imports
|
|
2
|
+
# This is a reference - the actual conversion will be done file by file
|
|
3
|
+
|
|
4
|
+
Write-Host "This script shows the pattern for converting imports:" -ForegroundColor Yellow
|
|
5
|
+
Write-Host ""
|
|
6
|
+
Write-Host "Pattern to find:" -ForegroundColor Cyan
|
|
7
|
+
Write-Host " from '@/config/env'"
|
|
8
|
+
Write-Host " from '@/libs/logger'"
|
|
9
|
+
Write-Host " from '@/libs/db'"
|
|
10
|
+
Write-Host ""
|
|
11
|
+
Write-Host "Convert to relative paths with .js:" -ForegroundColor Green
|
|
12
|
+
Write-Host " from './config/env.js' (if in src/)"
|
|
13
|
+
Write-Host " from '../config/env.js' (if in src/subfolder/)"
|
|
14
|
+
Write-Host " from '../../config/env.js' (if in src/subfolder/subfolder/)"
|
|
15
|
+
Write-Host ""
|
|
16
|
+
Write-Host "The conversion is being done manually for each file." -ForegroundColor Yellow
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Script to convert @/ path aliases to relative imports with .js extensions
|
|
5
|
+
* Run this after removing path aliases from tsconfig
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { readFileSync, writeFileSync } from 'fs';
|
|
9
|
+
import { glob } from 'glob';
|
|
10
|
+
import { relative, dirname, join } from 'path';
|
|
11
|
+
|
|
12
|
+
const files = glob.sync('src/**/*.ts', { ignore: ['**/*.d.ts'] });
|
|
13
|
+
|
|
14
|
+
files.forEach(file => {
|
|
15
|
+
let content = readFileSync(file, 'utf-8');
|
|
16
|
+
const lines = content.split('\n');
|
|
17
|
+
|
|
18
|
+
const newLines = lines.map(line => {
|
|
19
|
+
// Match import statements with @/ aliases
|
|
20
|
+
const match = line.match(/^(import .* from ['"])@\/(.+)(['"];?)$/);
|
|
21
|
+
|
|
22
|
+
if (match) {
|
|
23
|
+
const [, prefix, importPath, suffix] = match;
|
|
24
|
+
const currentDir = dirname(file);
|
|
25
|
+
const targetPath = join('src', importPath);
|
|
26
|
+
let relativePath = relative(currentDir, targetPath);
|
|
27
|
+
|
|
28
|
+
// Ensure it starts with ./ or ../
|
|
29
|
+
if (!relativePath.startsWith('.')) {
|
|
30
|
+
relativePath = './' + relativePath;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Add .js extension if not already there
|
|
34
|
+
if (!relativePath.endsWith('.js')) {
|
|
35
|
+
relativePath += '.js';
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Fix Windows backslashes
|
|
39
|
+
relativePath = relativePath.replace(/\\/g, '/');
|
|
40
|
+
|
|
41
|
+
return `${prefix}${relativePath}${suffix}`;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return line;
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
const newContent = newLines.join('\n');
|
|
48
|
+
|
|
49
|
+
if (newContent !== content) {
|
|
50
|
+
writeFileSync(file, newContent);
|
|
51
|
+
console.log(`✓ Fixed: ${file}`);
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
console.log('\n✅ All imports converted!');
|
|
@@ -11,27 +11,27 @@
|
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
13
|
import fastify from 'fastify';
|
|
14
|
-
import { env } from '
|
|
15
|
-
import logger from '
|
|
14
|
+
import { env } from './config/env.js';
|
|
15
|
+
import logger from './libs/logger.js';
|
|
16
16
|
|
|
17
17
|
// Extracted Modules
|
|
18
|
-
import { setupErrorHandler } from '
|
|
19
|
-
import { registerSecurityPlugins } from '
|
|
20
|
-
import { registerRateLimit } from '
|
|
21
|
-
import { registerRequestHooks } from '
|
|
22
|
-
import { authenticateMiddleware } from '
|
|
23
|
-
import { healthRoutes } from '
|
|
18
|
+
import { setupErrorHandler } from './libs/error-handler.js';
|
|
19
|
+
import { registerSecurityPlugins } from './plugins/security.plugin.js';
|
|
20
|
+
import { registerRateLimit } from './plugins/rate-limit.plugin.js';
|
|
21
|
+
import { registerRequestHooks } from './hooks/request-timing.hook.js';
|
|
22
|
+
import { authenticateMiddleware } from './libs/auth/authenticate.middleware.js';
|
|
23
|
+
import { healthRoutes } from './routes/health.routes.js';
|
|
24
24
|
|
|
25
25
|
// Routes & RBAC
|
|
26
|
-
import { authRoutes } from '
|
|
27
|
-
import { resourceRoutes } from '
|
|
28
|
-
import { adminRoutes } from '
|
|
26
|
+
import { authRoutes } from './modules/auth/auth.routes.js';
|
|
27
|
+
import { resourceRoutes } from './modules/resources/resources.routes.js';
|
|
28
|
+
import { adminRoutes } from './modules/admin/admin.routes.js';
|
|
29
29
|
import {
|
|
30
30
|
requireRole,
|
|
31
31
|
requireAdmin,
|
|
32
32
|
requireUser,
|
|
33
33
|
requireAny,
|
|
34
|
-
} from '
|
|
34
|
+
} from './libs/auth/rbac.middleware.js';
|
|
35
35
|
|
|
36
36
|
/**
|
|
37
37
|
* Configure and build the Fastify application
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { FastifyReply, FastifyRequest } from 'fastify';
|
|
2
|
-
import { verifyAccessToken } from '
|
|
3
|
-
import { UnauthorizedError, AppError } from '
|
|
2
|
+
import { verifyAccessToken } from '../../modules/auth/auth.service.js';
|
|
3
|
+
import { UnauthorizedError, AppError } from '../../utils/errors.js';
|
|
4
4
|
|
|
5
5
|
export async function authenticateMiddleware(request: FastifyRequest, reply: FastifyReply) {
|
|
6
6
|
try {
|
|
@@ -2,8 +2,8 @@ import { FastifyError, FastifyReply, FastifyRequest } from 'fastify';
|
|
|
2
2
|
import { ZodError } from 'zod';
|
|
3
3
|
import { Prisma } from '@prisma/client';
|
|
4
4
|
import jsonwebtoken from 'jsonwebtoken';
|
|
5
|
-
import { env } from '
|
|
6
|
-
import { AppError, InternalError } from '
|
|
5
|
+
import { env } from '../config/env.js';
|
|
6
|
+
import { AppError, InternalError } from '../utils/errors.js';
|
|
7
7
|
|
|
8
8
|
export function setupErrorHandler(error: FastifyError, request: FastifyRequest, reply: FastifyReply) {
|
|
9
9
|
// 1. Log the error internally
|
|
@@ -4,10 +4,10 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import type { FastifyRequest, FastifyReply } from 'fastify';
|
|
7
|
-
import { successResponse, paginatedResponse } from '
|
|
8
|
-
import { BadRequestError } from '
|
|
9
|
-
import * as adminService from './admin.service';
|
|
10
|
-
import type { ListUsersInput, UserIdInput, ChangeRoleInput } from './admin.schemas';
|
|
7
|
+
import { successResponse, paginatedResponse } from '../../utils/response.js';
|
|
8
|
+
import { BadRequestError } from '../../utils/errors.js';
|
|
9
|
+
import * as adminService from './admin.service.js';
|
|
10
|
+
import type { ListUsersInput, UserIdInput, ChangeRoleInput } from './admin.schemas.js';
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* GET /admin/users
|
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
* Business logic for admin operations
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import { prisma } from '
|
|
7
|
-
import { NotFoundError, BadRequestError } from '
|
|
8
|
-
import logger from '
|
|
6
|
+
import { prisma } from '../../libs/db.js';
|
|
7
|
+
import { NotFoundError, BadRequestError } from '../../utils/errors.js';
|
|
8
|
+
import logger from '../../libs/logger.js';
|
|
9
9
|
import type { UserRole } from '@prisma/client';
|
|
10
10
|
|
|
11
11
|
/**
|
|
@@ -9,17 +9,17 @@
|
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
import type { FastifyRequest, FastifyReply } from 'fastify';
|
|
12
|
-
import { successResponse } from '
|
|
13
|
-
import { NotFoundError } from '
|
|
12
|
+
import { successResponse } from '../../utils/response.js';
|
|
13
|
+
import { NotFoundError } from '../../utils/errors.js';
|
|
14
14
|
|
|
15
|
-
import * as authService from './auth.service';
|
|
16
|
-
import * as authRepo from './auth.repo';
|
|
15
|
+
import * as authService from './auth.service.js';
|
|
16
|
+
import * as authRepo from './auth.repo.js';
|
|
17
17
|
import {
|
|
18
18
|
RegisterSchema,
|
|
19
19
|
LoginSchema,
|
|
20
20
|
RefreshTokenSchema,
|
|
21
|
-
} from './auth.schemas';
|
|
22
|
-
import type { RegisterInput, LoginInput, RefreshTokenInput } from './auth.schemas';
|
|
21
|
+
} from './auth.schemas.js';
|
|
22
|
+
import type { RegisterInput, LoginInput, RefreshTokenInput } from './auth.schemas.js';
|
|
23
23
|
|
|
24
24
|
/**
|
|
25
25
|
* Register a new user
|
|
@@ -7,9 +7,9 @@
|
|
|
7
7
|
* @see /mnt/project/02-general-rules.md
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import { prisma } from '
|
|
10
|
+
import { prisma } from '../../libs/db.js';
|
|
11
11
|
import type { User as PrismaUser, Session as PrismaSession } from '@prisma/client';
|
|
12
|
-
import type { User } from './auth.types';
|
|
12
|
+
import type { User } from './auth.types.js';
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* User with password (internal use only)
|
|
@@ -3,8 +3,8 @@ import * as authService from './auth.service';
|
|
|
3
3
|
import * as authRepo from './auth.repo';
|
|
4
4
|
import bcrypt from 'bcryptjs';
|
|
5
5
|
import jwt from 'jsonwebtoken';
|
|
6
|
-
import { env } from '
|
|
7
|
-
import { ConflictError, UnauthorizedError } from '
|
|
6
|
+
import { env } from '../../config/env.js';
|
|
7
|
+
import { ConflictError, UnauthorizedError } from '../../utils/errors.js';
|
|
8
8
|
|
|
9
9
|
// Mock dependencies
|
|
10
10
|
vi.mock('./auth.repo');
|
|
@@ -9,20 +9,20 @@
|
|
|
9
9
|
|
|
10
10
|
import bcrypt from 'bcryptjs';
|
|
11
11
|
import jwt from 'jsonwebtoken';
|
|
12
|
-
import { env } from '
|
|
13
|
-
import logger from '
|
|
12
|
+
import { env } from '../../config/env.js';
|
|
13
|
+
import logger from '../../libs/logger.js';
|
|
14
14
|
import {
|
|
15
15
|
ConflictError,
|
|
16
16
|
UnauthorizedError,
|
|
17
|
-
} from '
|
|
18
|
-
import * as authRepo from './auth.repo';
|
|
17
|
+
} from '../../utils/errors.js';
|
|
18
|
+
import * as authRepo from './auth.repo.js';
|
|
19
19
|
import type {
|
|
20
20
|
AuthResponse,
|
|
21
21
|
TokenResponse,
|
|
22
22
|
JwtPayload,
|
|
23
23
|
JwtRefreshPayload,
|
|
24
|
-
} from './auth.types';
|
|
25
|
-
import type { RegisterInput, LoginInput } from './auth.schemas';
|
|
24
|
+
} from './auth.types.js';
|
|
25
|
+
import type { RegisterInput, LoginInput } from './auth.schemas.js';
|
|
26
26
|
|
|
27
27
|
/**
|
|
28
28
|
* Password hashing rounds
|
|
@@ -10,21 +10,21 @@
|
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
import type { FastifyRequest, FastifyReply } from 'fastify';
|
|
13
|
-
import { successResponse } from '
|
|
14
|
-
import { paginatedResponse } from '
|
|
15
|
-
import * as resourceService from './resources.service';
|
|
13
|
+
import { successResponse } from '../../utils/response.js';
|
|
14
|
+
import { paginatedResponse } from '../../utils/pagination.js';
|
|
15
|
+
import * as resourceService from './resources.service.js';
|
|
16
16
|
import {
|
|
17
17
|
CreateResourceSchema,
|
|
18
18
|
UpdateResourceSchema,
|
|
19
19
|
ResourceFiltersSchema,
|
|
20
20
|
PaginationSchema,
|
|
21
|
-
} from './resources.schemas';
|
|
21
|
+
} from './resources.schemas.js';
|
|
22
22
|
import type {
|
|
23
23
|
CreateResourceInput,
|
|
24
24
|
UpdateResourceInput,
|
|
25
25
|
ResourceFiltersInput,
|
|
26
26
|
PaginationInput,
|
|
27
|
-
} from './resources.schemas';
|
|
27
|
+
} from './resources.schemas.js';
|
|
28
28
|
|
|
29
29
|
/**
|
|
30
30
|
* List resources with filters and pagination
|
|
@@ -7,10 +7,10 @@
|
|
|
7
7
|
* @see /mnt/project/02-general-rules.md
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import { prisma } from '
|
|
10
|
+
import { prisma } from '../../libs/db.js';
|
|
11
11
|
import type { Resource as PrismaResource } from '@prisma/client';
|
|
12
|
-
import type { ResourceFilters, Resource, ResourceWithOwner } from './resources.types';
|
|
13
|
-
import type { CreateResourceInput, UpdateResourceInput } from './resources.schemas';
|
|
12
|
+
import type { ResourceFilters, Resource, ResourceWithOwner } from './resources.types.js';
|
|
13
|
+
import type { CreateResourceInput, UpdateResourceInput } from './resources.schemas.js';
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
16
|
* Find many resources with filters and pagination
|
|
@@ -7,11 +7,11 @@
|
|
|
7
7
|
* @see /mnt/project/02-general-rules.md
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import logger from '
|
|
11
|
-
import { NotFoundError, ForbiddenError } from '
|
|
12
|
-
import * as resourceRepo from './resources.repo';
|
|
13
|
-
import type { ResourceFilters, Resource, ResourceWithOwner } from './resources.types';
|
|
14
|
-
import type { CreateResourceInput, UpdateResourceInput } from './resources.schemas';
|
|
10
|
+
import logger from '../../libs/logger.js';
|
|
11
|
+
import { NotFoundError, ForbiddenError } from '../../utils/errors.js';
|
|
12
|
+
import * as resourceRepo from './resources.repo.js';
|
|
13
|
+
import type { ResourceFilters, Resource, ResourceWithOwner } from './resources.types.js';
|
|
14
|
+
import type { CreateResourceInput, UpdateResourceInput } from './resources.schemas.js';
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
17
|
* Service response for paginated data
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { FastifyInstance } from 'fastify';
|
|
2
2
|
import rateLimit from '@fastify/rate-limit';
|
|
3
|
-
import { redis } from '
|
|
4
|
-
import { env } from '
|
|
3
|
+
import { redis } from '../libs/redis.js';
|
|
4
|
+
import { env } from '../config/env.js';
|
|
5
5
|
|
|
6
6
|
export async function registerRateLimit(app: FastifyInstance) {
|
|
7
7
|
await app.register(rateLimit, {
|
|
@@ -2,7 +2,7 @@ import { FastifyInstance } from 'fastify';
|
|
|
2
2
|
import cors from '@fastify/cors';
|
|
3
3
|
import helmet from '@fastify/helmet';
|
|
4
4
|
import compress from '@fastify/compress';
|
|
5
|
-
import { env } from '
|
|
5
|
+
import { env } from '../config/env.js';
|
|
6
6
|
|
|
7
7
|
export async function registerSecurityPlugins(app: FastifyInstance) {
|
|
8
8
|
// CORS - Cross-Origin Resource Sharing
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { FastifyInstance } from 'fastify';
|
|
2
|
-
import { prisma } from '
|
|
3
|
-
import { redis } from '
|
|
2
|
+
import { prisma } from '../libs/db.js';
|
|
3
|
+
import { redis } from '../libs/redis.js';
|
|
4
4
|
|
|
5
5
|
export async function healthRoutes(app: FastifyInstance) {
|
|
6
6
|
app.get('/health', async (request, reply) => {
|
|
@@ -9,11 +9,11 @@
|
|
|
9
9
|
|
|
10
10
|
import 'dotenv/config';
|
|
11
11
|
import buildApp from './app.js';
|
|
12
|
-
import { env } from '
|
|
13
|
-
import logger from '
|
|
14
|
-
import { prisma } from '
|
|
15
|
-
import { redis } from '
|
|
16
|
-
import { fileQueue } from '
|
|
12
|
+
import { env } from './config/env.js';
|
|
13
|
+
import logger from './libs/logger.js';
|
|
14
|
+
import { prisma } from './libs/db.js';
|
|
15
|
+
import { redis } from './libs/redis.js';
|
|
16
|
+
import { fileQueue } from './libs/queue.js';
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
19
|
* Start the Fastify server
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { FastifyReply, FastifyRequest } from 'fastify';
|
|
2
|
-
import { JwtPayload } from '
|
|
3
|
-
import { UserRole } from '
|
|
2
|
+
import { JwtPayload } from '../modules/auth/auth.types.js';
|
|
3
|
+
import { UserRole } from '../libs/auth/rbac.middleware.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* TypeScript Declaration Merging
|
|
@@ -2,29 +2,29 @@
|
|
|
2
2
|
"compilerOptions": {
|
|
3
3
|
"target": "ES2022",
|
|
4
4
|
"module": "ES2022",
|
|
5
|
-
"lib": [
|
|
5
|
+
"lib": [
|
|
6
|
+
"ES2022"
|
|
7
|
+
],
|
|
6
8
|
"outDir": "./dist",
|
|
7
9
|
"rootDir": "./src",
|
|
8
10
|
"removeComments": true,
|
|
9
11
|
"strict": false,
|
|
10
12
|
"skipLibCheck": true,
|
|
11
|
-
"moduleResolution": "
|
|
13
|
+
"moduleResolution": "node",
|
|
12
14
|
"esModuleInterop": true,
|
|
13
15
|
"resolveJsonModule": true,
|
|
14
16
|
"declaration": false,
|
|
15
17
|
"sourceMap": false,
|
|
16
18
|
"incremental": true,
|
|
17
|
-
"types": []
|
|
18
|
-
"baseUrl": ".",
|
|
19
|
-
"paths": {
|
|
20
|
-
"@/*": ["src/*"],
|
|
21
|
-
"@/config/*": ["src/config/*"],
|
|
22
|
-
"@/libs/*": ["src/libs/*"],
|
|
23
|
-
"@/modules/*": ["src/modules/*"],
|
|
24
|
-
"@/utils/*": ["src/utils/*"],
|
|
25
|
-
"@/types/*": ["src/types/*"]
|
|
26
|
-
}
|
|
19
|
+
"types": []
|
|
27
20
|
},
|
|
28
|
-
"include": [
|
|
29
|
-
|
|
30
|
-
|
|
21
|
+
"include": [
|
|
22
|
+
"src/**/*.ts"
|
|
23
|
+
],
|
|
24
|
+
"exclude": [
|
|
25
|
+
"node_modules",
|
|
26
|
+
"dist",
|
|
27
|
+
"**/*.test.ts",
|
|
28
|
+
"**/*.spec.ts"
|
|
29
|
+
]
|
|
30
|
+
}
|