@sundaysf/cli-v2 1.0.1 → 1.0.3
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/README.md +178 -178
- package/dist/README.md +178 -178
- package/dist/bin/generators/class.js.map +1 -1
- package/dist/bin/generators/postman.js.map +1 -1
- package/dist/bin/index.js +1 -1
- package/dist/bin/index.js.map +1 -1
- package/dist/templates/backend/.claude/agents/knex-table-implementer.md +113 -113
- package/dist/templates/backend/.claude/agents/sundays-backend-builder.md +70 -70
- package/dist/templates/backend/.claude/settings.local.json +13 -13
- package/dist/templates/backend/.env.example +13 -13
- package/dist/templates/backend/.prettierignore +2 -2
- package/dist/templates/backend/.prettierrc +9 -9
- package/dist/templates/backend/CLAUDE.md +348 -348
- package/dist/templates/backend/Dockerfile +14 -14
- package/dist/templates/backend/README.md +18 -18
- package/dist/templates/backend/eslint.config.js +20 -20
- package/dist/templates/backend/src/app.ts +34 -34
- package/dist/templates/backend/src/common/config/origins/origins.config.ts +11 -11
- package/dist/templates/backend/src/common/utils/environment.resolver.ts +3 -3
- package/dist/templates/backend/src/common/utils/version.resolver.ts +4 -4
- package/dist/templates/backend/src/controllers/health/health.controller.ts +23 -23
- package/dist/templates/backend/src/middlewares/error/error.middleware.ts +21 -21
- package/dist/templates/backend/src/routes/health/health.router.ts +16 -16
- package/dist/templates/backend/src/routes/index.ts +57 -57
- package/dist/templates/backend/src/server.ts +16 -16
- package/dist/templates/backend/src/types.d.ts +10 -10
- package/dist/templates/backend/tsconfig.json +16 -16
- package/dist/templates/backend-db-sql/.claude/agents/knex-table-implementer.md +114 -114
- package/dist/templates/backend-db-sql/.claude/agents/sundays-backend-builder.md +70 -70
- package/dist/templates/backend-db-sql/.claude/settings.local.json +19 -19
- package/dist/templates/backend-db-sql/.env.example +13 -13
- package/dist/templates/backend-db-sql/.prettierignore +2 -2
- package/dist/templates/backend-db-sql/.prettierrc +9 -9
- package/dist/templates/backend-db-sql/CLAUDE.md +374 -374
- package/dist/templates/backend-db-sql/Dockerfile +17 -17
- package/dist/templates/backend-db-sql/README.md +34 -34
- package/dist/templates/backend-db-sql/db/knexfile.ts +33 -33
- package/dist/templates/backend-db-sql/db/migrations/001_create_sundays_package_version.ts +12 -12
- package/dist/templates/backend-db-sql/db/seeds/001_sundays_package_version_seed.ts +10 -10
- package/dist/templates/backend-db-sql/db/src/KnexConnection.ts +74 -74
- package/dist/templates/backend-db-sql/db/src/d.types.ts +18 -18
- package/dist/templates/backend-db-sql/db/src/dao/sundays-package-version/sundays-package-version.dao.ts +71 -71
- package/dist/templates/backend-db-sql/db/src/index.ts +9 -9
- package/dist/templates/backend-db-sql/db/src/interfaces/sundays-package-version/sundays-package-version.interfaces.ts +6 -6
- package/dist/templates/backend-db-sql/db/tsconfig.json +16 -16
- package/dist/templates/backend-db-sql/eslint.config.js +20 -20
- package/dist/templates/backend-db-sql/src/app.ts +34 -34
- package/dist/templates/backend-db-sql/src/common/config/origins/origins.config.ts +11 -11
- package/dist/templates/backend-db-sql/src/common/utils/environment.resolver.ts +3 -3
- package/dist/templates/backend-db-sql/src/common/utils/version.resolver.ts +4 -4
- package/dist/templates/backend-db-sql/src/controllers/health/health.controller.ts +23 -23
- package/dist/templates/backend-db-sql/src/middlewares/error/error.middleware.ts +21 -21
- package/dist/templates/backend-db-sql/src/routes/health/health.router.ts +16 -16
- package/dist/templates/backend-db-sql/src/routes/index.ts +57 -57
- package/dist/templates/backend-db-sql/src/server.ts +18 -18
- package/dist/templates/backend-db-sql/src/types.d.ts +10 -10
- package/dist/templates/backend-db-sql/tsconfig.json +16 -16
- package/dist/templates/backend-embedded-db-sql/.claude/agents/knex-table-implementer.md +116 -0
- package/dist/templates/backend-embedded-db-sql/.claude/agents/sundays-backend-builder.md +70 -0
- package/dist/templates/backend-embedded-db-sql/.claude/settings.local.json +18 -0
- package/dist/templates/backend-embedded-db-sql/.env.example +14 -0
- package/dist/templates/backend-embedded-db-sql/.prettierignore +3 -0
- package/dist/templates/backend-embedded-db-sql/.prettierrc +9 -0
- package/dist/templates/backend-embedded-db-sql/CLAUDE.md +371 -0
- package/dist/templates/backend-embedded-db-sql/Dockerfile +14 -0
- package/dist/templates/backend-embedded-db-sql/README.md +32 -0
- package/dist/templates/backend-embedded-db-sql/eslint.config.js +20 -0
- package/dist/templates/backend-embedded-db-sql/knexfile.ts +37 -0
- package/dist/templates/backend-embedded-db-sql/migrations/.gitkeep +0 -0
- package/dist/templates/backend-embedded-db-sql/migrations/001_create_sundays_package_version.ts +13 -0
- package/dist/templates/backend-embedded-db-sql/seeds/001_sundays_package_version_seed.ts +11 -0
- package/dist/templates/backend-embedded-db-sql/src/app.ts +35 -0
- package/dist/templates/backend-embedded-db-sql/src/common/config/origins/origins.config.ts +11 -0
- package/dist/templates/backend-embedded-db-sql/src/common/utils/environment.resolver.ts +4 -0
- package/dist/templates/backend-embedded-db-sql/src/common/utils/version.resolver.ts +5 -0
- package/dist/templates/backend-embedded-db-sql/src/controllers/health/health.controller.ts +24 -0
- package/dist/templates/backend-embedded-db-sql/src/db/KnexConnection.ts +74 -0
- package/dist/templates/backend-embedded-db-sql/src/db/d.types.ts +18 -0
- package/dist/templates/backend-embedded-db-sql/src/db/dao/sundays-package-version/sundays-package-version.dao.ts +71 -0
- package/dist/templates/backend-embedded-db-sql/src/db/index.ts +9 -0
- package/dist/templates/backend-embedded-db-sql/src/db/interfaces/sundays-package-version/sundays-package-version.interfaces.ts +6 -0
- package/dist/templates/backend-embedded-db-sql/src/middlewares/error/error.middleware.ts +21 -0
- package/dist/templates/backend-embedded-db-sql/src/routes/health/health.router.ts +17 -0
- package/dist/templates/backend-embedded-db-sql/src/routes/index.ts +57 -0
- package/dist/templates/backend-embedded-db-sql/src/server.ts +18 -0
- package/dist/templates/backend-embedded-db-sql/src/types.d.ts +10 -0
- package/dist/templates/backend-embedded-db-sql/tsconfig.json +16 -0
- package/dist/templates/db-sql/.claude/agents/knex-table-implementer.md +113 -113
- package/dist/templates/db-sql/.claude/agents/sundays-backend-builder.md +70 -70
- package/dist/templates/db-sql/.claude/settings.local.json +10 -10
- package/dist/templates/db-sql/.env.example +8 -8
- package/dist/templates/db-sql/CLAUDE.md +105 -105
- package/dist/templates/db-sql/knexfile.ts +33 -33
- package/dist/templates/db-sql/migrations/001_create_sundays_package_version.ts +12 -12
- package/dist/templates/db-sql/seeds/001_sundays_package_version_seed.ts +10 -10
- package/dist/templates/db-sql/src/KnexConnection.ts +74 -74
- package/dist/templates/db-sql/src/d.types.ts +18 -18
- package/dist/templates/db-sql/src/dao/sundays-package-version/sundays-package-version.dao.ts +71 -71
- package/dist/templates/db-sql/src/index.ts +9 -9
- package/dist/templates/db-sql/src/interfaces/sundays-package-version/sundays-package-version.interfaces.ts +6 -6
- package/dist/templates/db-sql/tsconfig.json +16 -16
- package/dist/templates/module/.claude/agents/knex-table-implementer.md +113 -113
- package/dist/templates/module/.claude/agents/sundays-backend-builder.md +70 -70
- package/dist/templates/module/.claude/settings.local.json +10 -10
- package/dist/templates/module/CLAUDE.md +158 -158
- package/dist/templates/module/src/index.ts +9 -9
- package/dist/templates/module/tsconfig.json +19 -19
- package/package.json +40 -40
|
@@ -1,70 +1,70 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: sundays-backend-builder
|
|
3
|
-
description: Use this agent when you need to create or modify backend components in a Sundays Framework project. This includes creating new controllers, routers, services, implementing CRUD operations, or ensuring existing code follows the framework's strict architectural patterns. <example>Context: User needs to create a new API endpoint for managing products. user: 'I need to create a products API with full CRUD operations' assistant: 'I'll use the sundays-backend-builder agent to create the products API following the Sundays Framework standards' <commentary>Since the user needs to create backend components following Sundays Framework patterns, use the sundays-backend-builder agent to ensure proper structure and implementation.</commentary></example> <example>Context: User wants to add pagination to an existing controller. user: 'Add pagination to the orders controller getAll method' assistant: 'Let me use the sundays-backend-builder agent to implement proper pagination using IBasePaginator' <commentary>The user needs to modify a controller to follow Sundays Framework pagination patterns, so the sundays-backend-builder agent should be used.</commentary></example> <example>Context: User needs to fix a controller that doesn't follow standards. user: 'The customer controller isn't following our standards, can you fix it?' assistant: 'I'll use the sundays-backend-builder agent to refactor the customer controller to match our Sundays Framework standards' <commentary>Since the controller needs to be refactored to follow framework standards, the sundays-backend-builder agent is appropriate.</commentary></example>
|
|
4
|
-
model: sonnet
|
|
5
|
-
color: blue
|
|
6
|
-
---
|
|
7
|
-
|
|
8
|
-
You are an expert backend developer specializing in the Sundays Framework architecture. Your mission is to build and maintain backend components that strictly adhere to the framework's established patterns and conventions.
|
|
9
|
-
|
|
10
|
-
**Core Responsibilities:**
|
|
11
|
-
|
|
12
|
-
1. **Component Creation**: When creating new backend components, ALWAYS use `npm run create:controller` to scaffold the initial structure. This ensures consistency across the codebase.
|
|
13
|
-
|
|
14
|
-
2. **Strict Structure Adherence**: You must follow these exact directory structures without deviation:
|
|
15
|
-
- Routes: `routes/<name>/<name>.router.ts`
|
|
16
|
-
- Controllers: `controllers/<name>/<name>.controller.ts`
|
|
17
|
-
- Services: `services/<name>/<name>.service.ts`
|
|
18
|
-
- DTOs: `dto/input/<entity>/<entity>.create.dto.ts` and `dto/input/<entity>/<entity>.update.dto.ts`
|
|
19
|
-
|
|
20
|
-
3. **Interface Implementation**:
|
|
21
|
-
- ALL controllers MUST implement `IBaseController`
|
|
22
|
-
- ALL paginated getAll methods MUST use `IDataPaginator` (not IBasePaginator)
|
|
23
|
-
- ALWAYS use `paginationHelper` from `@sundaysf/utils` to extract page and limit from request
|
|
24
|
-
|
|
25
|
-
4. **DAO/Service Pattern**:
|
|
26
|
-
- Initialize DAOs as private class members: `private _<entity>DAO: <Entity>DAO = new <Entity>DAO()`
|
|
27
|
-
- Follow the same pattern for services when applicable
|
|
28
|
-
- Use underscore prefix for private members
|
|
29
|
-
|
|
30
|
-
5. **Method Implementation Standards**:
|
|
31
|
-
- **getAll**: Return paginated results using `IDataPaginator`, extract pagination with `paginationHelper(req)`
|
|
32
|
-
- **getByUuid**: Use UUID in params, convert to ID for DAO operations
|
|
33
|
-
- **create**: Validate with DTOs, generate UUID with `uuidv4()` in controller
|
|
34
|
-
- **update**: Get entity by UUID first to find ID, then update using DAO
|
|
35
|
-
- **delete**: Get entity by UUID first to find ID, then delete using DAO
|
|
36
|
-
|
|
37
|
-
6. **Response Format**: ALL responses must follow:
|
|
38
|
-
```json
|
|
39
|
-
{
|
|
40
|
-
"success": boolean,
|
|
41
|
-
"data": {...} // or "message": string
|
|
42
|
-
}
|
|
43
|
-
```
|
|
44
|
-
Note: `IDataPaginator` already includes these fields, so don't double-wrap paginated responses.
|
|
45
|
-
|
|
46
|
-
7. **Router Binding**: ALWAYS use `.bind(this._<entity>Controller)` when assigning controller methods to routes to maintain proper context.
|
|
47
|
-
|
|
48
|
-
8. **Quality Checks**:
|
|
49
|
-
- Verify all imports are correct and from the right packages
|
|
50
|
-
- Ensure TypeScript types are properly defined
|
|
51
|
-
- Check that error handling uses `next(err)` pattern
|
|
52
|
-
- Validate that DTOs properly sanitize input data
|
|
53
|
-
- Confirm UUID generation happens in controller, not DTO or client-side
|
|
54
|
-
|
|
55
|
-
**Working Process**:
|
|
56
|
-
|
|
57
|
-
1. When creating new components, first run `npm run create:controller` command
|
|
58
|
-
2. Analyze existing similar components in the project for pattern reference
|
|
59
|
-
3. Implement following the exact structure found in existing code
|
|
60
|
-
4. Ensure all naming conventions match (camelCase for variables, PascalCase for classes)
|
|
61
|
-
5. Test that all CRUD operations follow the established patterns
|
|
62
|
-
|
|
63
|
-
**Critical Rules**:
|
|
64
|
-
- NEVER deviate from the established folder structure
|
|
65
|
-
- NEVER create custom patterns - follow existing examples exactly
|
|
66
|
-
- ALWAYS check existing implementations before creating new ones
|
|
67
|
-
- ALWAYS maintain consistency with the project's CLAUDE.md guidelines
|
|
68
|
-
- Be extremely meticulous about structure - it must be perfect
|
|
69
|
-
|
|
70
|
-
Your code must be production-ready, following all Sundays Framework conventions to the letter. Every component you create or modify should seamlessly integrate with the existing architecture without requiring any adjustments to other parts of the system.
|
|
1
|
+
---
|
|
2
|
+
name: sundays-backend-builder
|
|
3
|
+
description: Use this agent when you need to create or modify backend components in a Sundays Framework project. This includes creating new controllers, routers, services, implementing CRUD operations, or ensuring existing code follows the framework's strict architectural patterns. <example>Context: User needs to create a new API endpoint for managing products. user: 'I need to create a products API with full CRUD operations' assistant: 'I'll use the sundays-backend-builder agent to create the products API following the Sundays Framework standards' <commentary>Since the user needs to create backend components following Sundays Framework patterns, use the sundays-backend-builder agent to ensure proper structure and implementation.</commentary></example> <example>Context: User wants to add pagination to an existing controller. user: 'Add pagination to the orders controller getAll method' assistant: 'Let me use the sundays-backend-builder agent to implement proper pagination using IBasePaginator' <commentary>The user needs to modify a controller to follow Sundays Framework pagination patterns, so the sundays-backend-builder agent should be used.</commentary></example> <example>Context: User needs to fix a controller that doesn't follow standards. user: 'The customer controller isn't following our standards, can you fix it?' assistant: 'I'll use the sundays-backend-builder agent to refactor the customer controller to match our Sundays Framework standards' <commentary>Since the controller needs to be refactored to follow framework standards, the sundays-backend-builder agent is appropriate.</commentary></example>
|
|
4
|
+
model: sonnet
|
|
5
|
+
color: blue
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
You are an expert backend developer specializing in the Sundays Framework architecture. Your mission is to build and maintain backend components that strictly adhere to the framework's established patterns and conventions.
|
|
9
|
+
|
|
10
|
+
**Core Responsibilities:**
|
|
11
|
+
|
|
12
|
+
1. **Component Creation**: When creating new backend components, ALWAYS use `npm run create:controller` to scaffold the initial structure. This ensures consistency across the codebase.
|
|
13
|
+
|
|
14
|
+
2. **Strict Structure Adherence**: You must follow these exact directory structures without deviation:
|
|
15
|
+
- Routes: `routes/<name>/<name>.router.ts`
|
|
16
|
+
- Controllers: `controllers/<name>/<name>.controller.ts`
|
|
17
|
+
- Services: `services/<name>/<name>.service.ts`
|
|
18
|
+
- DTOs: `dto/input/<entity>/<entity>.create.dto.ts` and `dto/input/<entity>/<entity>.update.dto.ts`
|
|
19
|
+
|
|
20
|
+
3. **Interface Implementation**:
|
|
21
|
+
- ALL controllers MUST implement `IBaseController`
|
|
22
|
+
- ALL paginated getAll methods MUST use `IDataPaginator` (not IBasePaginator)
|
|
23
|
+
- ALWAYS use `paginationHelper` from `@sundaysf/utils` to extract page and limit from request
|
|
24
|
+
|
|
25
|
+
4. **DAO/Service Pattern**:
|
|
26
|
+
- Initialize DAOs as private class members: `private _<entity>DAO: <Entity>DAO = new <Entity>DAO()`
|
|
27
|
+
- Follow the same pattern for services when applicable
|
|
28
|
+
- Use underscore prefix for private members
|
|
29
|
+
|
|
30
|
+
5. **Method Implementation Standards**:
|
|
31
|
+
- **getAll**: Return paginated results using `IDataPaginator`, extract pagination with `paginationHelper(req)`
|
|
32
|
+
- **getByUuid**: Use UUID in params, convert to ID for DAO operations
|
|
33
|
+
- **create**: Validate with DTOs, generate UUID with `uuidv4()` in controller
|
|
34
|
+
- **update**: Get entity by UUID first to find ID, then update using DAO
|
|
35
|
+
- **delete**: Get entity by UUID first to find ID, then delete using DAO
|
|
36
|
+
|
|
37
|
+
6. **Response Format**: ALL responses must follow:
|
|
38
|
+
```json
|
|
39
|
+
{
|
|
40
|
+
"success": boolean,
|
|
41
|
+
"data": {...} // or "message": string
|
|
42
|
+
}
|
|
43
|
+
```
|
|
44
|
+
Note: `IDataPaginator` already includes these fields, so don't double-wrap paginated responses.
|
|
45
|
+
|
|
46
|
+
7. **Router Binding**: ALWAYS use `.bind(this._<entity>Controller)` when assigning controller methods to routes to maintain proper context.
|
|
47
|
+
|
|
48
|
+
8. **Quality Checks**:
|
|
49
|
+
- Verify all imports are correct and from the right packages
|
|
50
|
+
- Ensure TypeScript types are properly defined
|
|
51
|
+
- Check that error handling uses `next(err)` pattern
|
|
52
|
+
- Validate that DTOs properly sanitize input data
|
|
53
|
+
- Confirm UUID generation happens in controller, not DTO or client-side
|
|
54
|
+
|
|
55
|
+
**Working Process**:
|
|
56
|
+
|
|
57
|
+
1. When creating new components, first run `npm run create:controller` command
|
|
58
|
+
2. Analyze existing similar components in the project for pattern reference
|
|
59
|
+
3. Implement following the exact structure found in existing code
|
|
60
|
+
4. Ensure all naming conventions match (camelCase for variables, PascalCase for classes)
|
|
61
|
+
5. Test that all CRUD operations follow the established patterns
|
|
62
|
+
|
|
63
|
+
**Critical Rules**:
|
|
64
|
+
- NEVER deviate from the established folder structure
|
|
65
|
+
- NEVER create custom patterns - follow existing examples exactly
|
|
66
|
+
- ALWAYS check existing implementations before creating new ones
|
|
67
|
+
- ALWAYS maintain consistency with the project's CLAUDE.md guidelines
|
|
68
|
+
- Be extremely meticulous about structure - it must be perfect
|
|
69
|
+
|
|
70
|
+
Your code must be production-ready, following all Sundays Framework conventions to the letter. Every component you create or modify should seamlessly integrate with the existing architecture without requiring any adjustments to other parts of the system.
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
{
|
|
2
|
-
"permissions": {
|
|
3
|
-
"allow": [
|
|
4
|
-
"Bash(npm run migrate:create:*)",
|
|
5
|
-
"Bash(npm run migrate:deploy:*)",
|
|
6
|
-
"Bash(npm run build:*)"
|
|
7
|
-
],
|
|
8
|
-
"deny": [],
|
|
9
|
-
"ask": []
|
|
10
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"permissions": {
|
|
3
|
+
"allow": [
|
|
4
|
+
"Bash(npm run migrate:create:*)",
|
|
5
|
+
"Bash(npm run migrate:deploy:*)",
|
|
6
|
+
"Bash(npm run build:*)"
|
|
7
|
+
],
|
|
8
|
+
"deny": [],
|
|
9
|
+
"ask": []
|
|
10
|
+
}
|
|
11
11
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
SQL_HOST=localhost
|
|
2
|
-
SQL_PORT=5432
|
|
3
|
-
SQL_USER=postgres
|
|
4
|
-
SQL_PASSWORD=
|
|
5
|
-
SQL_DB_NAME=mydb
|
|
6
|
-
|
|
7
|
-
# Set to 'false' to disable SSL certificate verification (not recommended for production)
|
|
8
|
-
# SQL_REJECT_UNAUTHORIZED=false
|
|
1
|
+
SQL_HOST=localhost
|
|
2
|
+
SQL_PORT=5432
|
|
3
|
+
SQL_USER=postgres
|
|
4
|
+
SQL_PASSWORD=
|
|
5
|
+
SQL_DB_NAME=mydb
|
|
6
|
+
|
|
7
|
+
# Set to 'false' to disable SSL certificate verification (not recommended for production)
|
|
8
|
+
# SQL_REJECT_UNAUTHORIZED=false
|
|
@@ -1,106 +1,106 @@
|
|
|
1
|
-
# CLAUDE.md
|
|
2
|
-
|
|
3
|
-
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
|
4
|
-
|
|
5
|
-
## File Structure Conventions
|
|
6
|
-
|
|
7
|
-
**Interfaces**: All interfaces should be placed in `src/interfaces/{entity}/{entity}.interfaces.ts`
|
|
8
|
-
- Example: `src/interfaces/company/company.interfaces.ts`
|
|
9
|
-
|
|
10
|
-
**DAOs**: All DAO classes should be placed in `src/dao/{entity}/{entity}.dao.ts`
|
|
11
|
-
- Example: `src/dao/company/company.dao.ts`
|
|
12
|
-
|
|
13
|
-
This convention maintains consistency with the existing structure (e.g., sundays-package-version).
|
|
14
|
-
|
|
15
|
-
## Common Development Commands
|
|
16
|
-
|
|
17
|
-
**Build**: `npm run build` - Compiles TypeScript to JavaScript in the `dist` directory
|
|
18
|
-
|
|
19
|
-
**Format**: `npm run format` - Formats code using Prettier
|
|
20
|
-
|
|
21
|
-
**Test**: `npm test` - Runs Jest tests
|
|
22
|
-
|
|
23
|
-
**Clean Build**: `npm run clean` - Removes dist, formats code, and rebuilds
|
|
24
|
-
|
|
25
|
-
**Database Migrations**:
|
|
26
|
-
- Create migration: `npm run migrate:create` - Creates a new migration file in TypeScript
|
|
27
|
-
- Run migrations: `npm run migrate:deploy` - Applies pending migrations
|
|
28
|
-
|
|
29
|
-
**Database Seeds**:
|
|
30
|
-
- Create seed: `npm run seed:create` - Creates a new seed file in TypeScript
|
|
31
|
-
- Run seeds: `npm run seed:run` - Executes seed files
|
|
32
|
-
|
|
33
|
-
## Architecture Overview
|
|
34
|
-
|
|
35
|
-
This is a Knex.js database module (`@dupin/knex-v2`) that provides a PostgreSQL connection manager and data access layer.
|
|
36
|
-
|
|
37
|
-
**Key Components**:
|
|
38
|
-
|
|
39
|
-
1. **KnexManager** (`src/KnexConnection.ts`): Singleton pattern for managing database connections
|
|
40
|
-
- Handles connection pooling with configurable min/max connections
|
|
41
|
-
- Uses environment variables for database configuration (SQL_HOST, SQL_USER, SQL_PASSWORD, SQL_DB_NAME, SQL_PORT)
|
|
42
|
-
- Supports SSL connections with `rejectUnauthorized: false`
|
|
43
|
-
|
|
44
|
-
2. **DAO Pattern**: Data Access Objects implement the `IBaseDAO<T>` interface
|
|
45
|
-
- Example: `SundaysPackageVersionDAO` provides CRUD operations
|
|
46
|
-
- All DAOs use the shared KnexManager connection
|
|
47
|
-
- Includes pagination support via `IDataPaginator`
|
|
48
|
-
|
|
49
|
-
3. **Database Configuration** (`knexfile.ts`): Supports development, staging, and production environments
|
|
50
|
-
- All environments use PostgreSQL client
|
|
51
|
-
- Configuration reads from environment variables
|
|
52
|
-
- Migration table: `knex_migrations`
|
|
53
|
-
|
|
54
|
-
4. **Type System**:
|
|
55
|
-
- Interfaces in `src/interfaces/` define data models
|
|
56
|
-
- Common types in `src/d.types.ts` (IBaseDAO, IDataPaginator)
|
|
57
|
-
- All exports centralized in `src/index.ts`
|
|
58
|
-
|
|
59
|
-
**Environment Requirements**:
|
|
60
|
-
- SQL_HOST: PostgreSQL host
|
|
61
|
-
- SQL_USER: Database user
|
|
62
|
-
- SQL_PASSWORD: Database password
|
|
63
|
-
- SQL_DB_NAME: Database name
|
|
64
|
-
- SQL_PORT: Database port (defaults to 5432)
|
|
65
|
-
|
|
66
|
-
## DAO Implementation Patterns
|
|
67
|
-
|
|
68
|
-
### Join Pattern for Related Entities
|
|
69
|
-
|
|
70
|
-
When implementing DAOs that need to include related entities, use PostgreSQL's `to_jsonb()` function for clean and efficient joins:
|
|
71
|
-
|
|
72
|
-
```typescript
|
|
73
|
-
async getById(id: number): Promise<IEntity | null> {
|
|
74
|
-
const result = await this._knex("entity as e")
|
|
75
|
-
.leftJoin("related as r", "e.relatedId", "r.id")
|
|
76
|
-
.select("e.*", this._knex.raw("to_jsonb(r.*) as related"))
|
|
77
|
-
.where("e.id", id)
|
|
78
|
-
.first();
|
|
79
|
-
return result || null;
|
|
80
|
-
}
|
|
81
|
-
```
|
|
82
|
-
|
|
83
|
-
**Key Points:**
|
|
84
|
-
- Use table aliases for clarity (`as e`, `as r`)
|
|
85
|
-
- `to_jsonb(r.*)` automatically converts the joined row to JSON
|
|
86
|
-
- Returns `null` if no related entity is found (with leftJoin)
|
|
87
|
-
- No manual mapping required - PostgreSQL handles the conversion
|
|
88
|
-
|
|
89
|
-
**For paginated results:**
|
|
90
|
-
```typescript
|
|
91
|
-
const query = this._knex("entity as e")
|
|
92
|
-
.leftJoin("related as r", "e.relatedId", "r.id")
|
|
93
|
-
.select("e.*", this._knex.raw("to_jsonb(r.*) as related"));
|
|
94
|
-
|
|
95
|
-
const data = await query
|
|
96
|
-
.clone()
|
|
97
|
-
.limit(limit)
|
|
98
|
-
.offset(offset)
|
|
99
|
-
.orderBy("e.id", "desc");
|
|
100
|
-
```
|
|
101
|
-
|
|
102
|
-
## Known Issues and Solutions
|
|
103
|
-
|
|
104
|
-
**Migration Error "require is not defined"**: The knexfile.ts uses ES module syntax. If you encounter this error, ensure the file uses:
|
|
105
|
-
- `import dotenv from "dotenv"` instead of `require("dotenv")`
|
|
1
|
+
# CLAUDE.md
|
|
2
|
+
|
|
3
|
+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
|
4
|
+
|
|
5
|
+
## File Structure Conventions
|
|
6
|
+
|
|
7
|
+
**Interfaces**: All interfaces should be placed in `src/interfaces/{entity}/{entity}.interfaces.ts`
|
|
8
|
+
- Example: `src/interfaces/company/company.interfaces.ts`
|
|
9
|
+
|
|
10
|
+
**DAOs**: All DAO classes should be placed in `src/dao/{entity}/{entity}.dao.ts`
|
|
11
|
+
- Example: `src/dao/company/company.dao.ts`
|
|
12
|
+
|
|
13
|
+
This convention maintains consistency with the existing structure (e.g., sundays-package-version).
|
|
14
|
+
|
|
15
|
+
## Common Development Commands
|
|
16
|
+
|
|
17
|
+
**Build**: `npm run build` - Compiles TypeScript to JavaScript in the `dist` directory
|
|
18
|
+
|
|
19
|
+
**Format**: `npm run format` - Formats code using Prettier
|
|
20
|
+
|
|
21
|
+
**Test**: `npm test` - Runs Jest tests
|
|
22
|
+
|
|
23
|
+
**Clean Build**: `npm run clean` - Removes dist, formats code, and rebuilds
|
|
24
|
+
|
|
25
|
+
**Database Migrations**:
|
|
26
|
+
- Create migration: `npm run migrate:create` - Creates a new migration file in TypeScript
|
|
27
|
+
- Run migrations: `npm run migrate:deploy` - Applies pending migrations
|
|
28
|
+
|
|
29
|
+
**Database Seeds**:
|
|
30
|
+
- Create seed: `npm run seed:create` - Creates a new seed file in TypeScript
|
|
31
|
+
- Run seeds: `npm run seed:run` - Executes seed files
|
|
32
|
+
|
|
33
|
+
## Architecture Overview
|
|
34
|
+
|
|
35
|
+
This is a Knex.js database module (`@dupin/knex-v2`) that provides a PostgreSQL connection manager and data access layer.
|
|
36
|
+
|
|
37
|
+
**Key Components**:
|
|
38
|
+
|
|
39
|
+
1. **KnexManager** (`src/KnexConnection.ts`): Singleton pattern for managing database connections
|
|
40
|
+
- Handles connection pooling with configurable min/max connections
|
|
41
|
+
- Uses environment variables for database configuration (SQL_HOST, SQL_USER, SQL_PASSWORD, SQL_DB_NAME, SQL_PORT)
|
|
42
|
+
- Supports SSL connections with `rejectUnauthorized: false`
|
|
43
|
+
|
|
44
|
+
2. **DAO Pattern**: Data Access Objects implement the `IBaseDAO<T>` interface
|
|
45
|
+
- Example: `SundaysPackageVersionDAO` provides CRUD operations
|
|
46
|
+
- All DAOs use the shared KnexManager connection
|
|
47
|
+
- Includes pagination support via `IDataPaginator`
|
|
48
|
+
|
|
49
|
+
3. **Database Configuration** (`knexfile.ts`): Supports development, staging, and production environments
|
|
50
|
+
- All environments use PostgreSQL client
|
|
51
|
+
- Configuration reads from environment variables
|
|
52
|
+
- Migration table: `knex_migrations`
|
|
53
|
+
|
|
54
|
+
4. **Type System**:
|
|
55
|
+
- Interfaces in `src/interfaces/` define data models
|
|
56
|
+
- Common types in `src/d.types.ts` (IBaseDAO, IDataPaginator)
|
|
57
|
+
- All exports centralized in `src/index.ts`
|
|
58
|
+
|
|
59
|
+
**Environment Requirements**:
|
|
60
|
+
- SQL_HOST: PostgreSQL host
|
|
61
|
+
- SQL_USER: Database user
|
|
62
|
+
- SQL_PASSWORD: Database password
|
|
63
|
+
- SQL_DB_NAME: Database name
|
|
64
|
+
- SQL_PORT: Database port (defaults to 5432)
|
|
65
|
+
|
|
66
|
+
## DAO Implementation Patterns
|
|
67
|
+
|
|
68
|
+
### Join Pattern for Related Entities
|
|
69
|
+
|
|
70
|
+
When implementing DAOs that need to include related entities, use PostgreSQL's `to_jsonb()` function for clean and efficient joins:
|
|
71
|
+
|
|
72
|
+
```typescript
|
|
73
|
+
async getById(id: number): Promise<IEntity | null> {
|
|
74
|
+
const result = await this._knex("entity as e")
|
|
75
|
+
.leftJoin("related as r", "e.relatedId", "r.id")
|
|
76
|
+
.select("e.*", this._knex.raw("to_jsonb(r.*) as related"))
|
|
77
|
+
.where("e.id", id)
|
|
78
|
+
.first();
|
|
79
|
+
return result || null;
|
|
80
|
+
}
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
**Key Points:**
|
|
84
|
+
- Use table aliases for clarity (`as e`, `as r`)
|
|
85
|
+
- `to_jsonb(r.*)` automatically converts the joined row to JSON
|
|
86
|
+
- Returns `null` if no related entity is found (with leftJoin)
|
|
87
|
+
- No manual mapping required - PostgreSQL handles the conversion
|
|
88
|
+
|
|
89
|
+
**For paginated results:**
|
|
90
|
+
```typescript
|
|
91
|
+
const query = this._knex("entity as e")
|
|
92
|
+
.leftJoin("related as r", "e.relatedId", "r.id")
|
|
93
|
+
.select("e.*", this._knex.raw("to_jsonb(r.*) as related"));
|
|
94
|
+
|
|
95
|
+
const data = await query
|
|
96
|
+
.clone()
|
|
97
|
+
.limit(limit)
|
|
98
|
+
.offset(offset)
|
|
99
|
+
.orderBy("e.id", "desc");
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## Known Issues and Solutions
|
|
103
|
+
|
|
104
|
+
**Migration Error "require is not defined"**: The knexfile.ts uses ES module syntax. If you encounter this error, ensure the file uses:
|
|
105
|
+
- `import dotenv from "dotenv"` instead of `require("dotenv")`
|
|
106
106
|
- `export default config` instead of `module.exports = config`
|
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
import type { Knex } from "knex";
|
|
2
|
-
import dotenv from "dotenv";
|
|
3
|
-
dotenv.config();
|
|
4
|
-
|
|
5
|
-
const isLocalhost = process.env.SQL_HOST === 'localhost' || process.env.SQL_HOST === '127.0.0.1';
|
|
6
|
-
const rejectUnauthorized = process.env.SQL_REJECT_UNAUTHORIZED !== 'false';
|
|
7
|
-
|
|
8
|
-
const sharedConfig: Knex.Config = {
|
|
9
|
-
client: "postgresql",
|
|
10
|
-
connection: {
|
|
11
|
-
database: process.env.SQL_DB_NAME,
|
|
12
|
-
user: process.env.SQL_USER,
|
|
13
|
-
password: process.env.SQL_PASSWORD,
|
|
14
|
-
host: process.env.SQL_HOST,
|
|
15
|
-
port: process.env.SQL_PORT ? +process.env.SQL_PORT : 5432,
|
|
16
|
-
ssl: isLocalhost ? false : { rejectUnauthorized },
|
|
17
|
-
},
|
|
18
|
-
pool: {
|
|
19
|
-
min: 2,
|
|
20
|
-
max: 10,
|
|
21
|
-
},
|
|
22
|
-
migrations: {
|
|
23
|
-
tableName: "knex_migrations",
|
|
24
|
-
},
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
const config: { [key: string]: Knex.Config } = {
|
|
28
|
-
development: sharedConfig,
|
|
29
|
-
staging: sharedConfig,
|
|
30
|
-
production: sharedConfig,
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
export default config;
|
|
1
|
+
import type { Knex } from "knex";
|
|
2
|
+
import dotenv from "dotenv";
|
|
3
|
+
dotenv.config();
|
|
4
|
+
|
|
5
|
+
const isLocalhost = process.env.SQL_HOST === 'localhost' || process.env.SQL_HOST === '127.0.0.1';
|
|
6
|
+
const rejectUnauthorized = process.env.SQL_REJECT_UNAUTHORIZED !== 'false';
|
|
7
|
+
|
|
8
|
+
const sharedConfig: Knex.Config = {
|
|
9
|
+
client: "postgresql",
|
|
10
|
+
connection: {
|
|
11
|
+
database: process.env.SQL_DB_NAME,
|
|
12
|
+
user: process.env.SQL_USER,
|
|
13
|
+
password: process.env.SQL_PASSWORD,
|
|
14
|
+
host: process.env.SQL_HOST,
|
|
15
|
+
port: process.env.SQL_PORT ? +process.env.SQL_PORT : 5432,
|
|
16
|
+
ssl: isLocalhost ? false : { rejectUnauthorized },
|
|
17
|
+
},
|
|
18
|
+
pool: {
|
|
19
|
+
min: 2,
|
|
20
|
+
max: 10,
|
|
21
|
+
},
|
|
22
|
+
migrations: {
|
|
23
|
+
tableName: "knex_migrations",
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const config: { [key: string]: Knex.Config } = {
|
|
28
|
+
development: sharedConfig,
|
|
29
|
+
staging: sharedConfig,
|
|
30
|
+
production: sharedConfig,
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export default config;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import type { Knex } from "knex";
|
|
2
|
-
|
|
3
|
-
export async function up(knex: Knex): Promise<void> {
|
|
4
|
-
await knex.schema.createTable("sundays_package_version", (table) => {
|
|
5
|
-
table.increments("id").primary();
|
|
6
|
-
table.string("versionName").notNullable();
|
|
7
|
-
table.timestamps(true, true); // created_at, updated_at
|
|
8
|
-
});
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export async function down(knex: Knex): Promise<void> {
|
|
12
|
-
await knex.schema.dropTableIfExists("sundays_package_version");
|
|
1
|
+
import type { Knex } from "knex";
|
|
2
|
+
|
|
3
|
+
export async function up(knex: Knex): Promise<void> {
|
|
4
|
+
await knex.schema.createTable("sundays_package_version", (table) => {
|
|
5
|
+
table.increments("id").primary();
|
|
6
|
+
table.string("versionName").notNullable();
|
|
7
|
+
table.timestamps(true, true); // created_at, updated_at
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export async function down(knex: Knex): Promise<void> {
|
|
12
|
+
await knex.schema.dropTableIfExists("sundays_package_version");
|
|
13
13
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { Knex } from "knex";
|
|
2
|
-
|
|
3
|
-
export async function seed(knex: Knex): Promise<void> {
|
|
4
|
-
// Deletes ALL existing entries
|
|
5
|
-
await knex("sundays_package_version").del();
|
|
6
|
-
|
|
7
|
-
// Inserts seed entries
|
|
8
|
-
await knex("sundays_package_version").insert([
|
|
9
|
-
{ versionName: "1.0.0" }
|
|
10
|
-
]);
|
|
1
|
+
import { Knex } from "knex";
|
|
2
|
+
|
|
3
|
+
export async function seed(knex: Knex): Promise<void> {
|
|
4
|
+
// Deletes ALL existing entries
|
|
5
|
+
await knex("sundays_package_version").del();
|
|
6
|
+
|
|
7
|
+
// Inserts seed entries
|
|
8
|
+
await knex("sundays_package_version").insert([
|
|
9
|
+
{ versionName: "1.0.0" }
|
|
10
|
+
]);
|
|
11
11
|
}
|