@gblikas/querykit 0.0.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/.cursor/BUGBOT.md +21 -0
- package/.cursor/rules/01-project-structure.mdc +77 -0
- package/.cursor/rules/02-typescript-standards.mdc +105 -0
- package/.cursor/rules/03-testing-standards.mdc +78 -0
- package/.cursor/rules/04-query-language.mdc +79 -0
- package/.cursor/rules/05-solid-principles.mdc +118 -0
- package/.cursor/rules/liqe-readme-docs.mdc +438 -0
- package/.devcontainer/devcontainer.json +25 -0
- package/.eslintignore +1 -0
- package/.eslintrc.js +39 -0
- package/.github/dependabot.yml +12 -0
- package/.github/workflows/ci.yml +114 -0
- package/.github/workflows/publish.yml +61 -0
- package/.husky/pre-commit +30 -0
- package/.prettierrc +10 -0
- package/CONTRIBUTING.md +187 -0
- package/LICENSE +674 -0
- package/README.md +237 -0
- package/dist/adapters/drizzle/index.d.ts +122 -0
- package/dist/adapters/drizzle/index.js +166 -0
- package/dist/adapters/index.d.ts +7 -0
- package/dist/adapters/index.js +25 -0
- package/dist/adapters/types.d.ts +60 -0
- package/dist/adapters/types.js +8 -0
- package/dist/index.d.ts +75 -0
- package/dist/index.js +118 -0
- package/dist/parser/index.d.ts +2 -0
- package/dist/parser/index.js +18 -0
- package/dist/parser/parser.d.ts +51 -0
- package/dist/parser/parser.js +201 -0
- package/dist/parser/types.d.ts +68 -0
- package/dist/parser/types.js +5 -0
- package/dist/query/builder.d.ts +61 -0
- package/dist/query/builder.js +188 -0
- package/dist/query/index.d.ts +2 -0
- package/dist/query/index.js +18 -0
- package/dist/query/types.d.ts +79 -0
- package/dist/query/types.js +2 -0
- package/dist/security/index.d.ts +2 -0
- package/dist/security/index.js +18 -0
- package/dist/security/types.d.ts +181 -0
- package/dist/security/types.js +43 -0
- package/dist/security/validator.d.ts +191 -0
- package/dist/security/validator.js +344 -0
- package/dist/translators/drizzle/index.d.ts +73 -0
- package/dist/translators/drizzle/index.js +260 -0
- package/dist/translators/index.d.ts +8 -0
- package/dist/translators/index.js +27 -0
- package/dist/translators/sql/index.d.ts +108 -0
- package/dist/translators/sql/index.js +252 -0
- package/dist/translators/types.d.ts +39 -0
- package/dist/translators/types.js +8 -0
- package/examples/qk-next/README.md +35 -0
- package/examples/qk-next/app/favicon.ico +0 -0
- package/examples/qk-next/app/globals.css +122 -0
- package/examples/qk-next/app/layout.tsx +121 -0
- package/examples/qk-next/app/page.tsx +813 -0
- package/examples/qk-next/app/providers.tsx +80 -0
- package/examples/qk-next/components/aurora-background.tsx +12 -0
- package/examples/qk-next/components/github-stars.tsx +51 -0
- package/examples/qk-next/components/mode-toggle.tsx +27 -0
- package/examples/qk-next/components/reactbits/blocks/Backgrounds/Aurora/Aurora.tsx +217 -0
- package/examples/qk-next/components/reactbits/blocks/Backgrounds/LightRays/LightRays.tsx +474 -0
- package/examples/qk-next/components/theme-provider.tsx +11 -0
- package/examples/qk-next/components/ui/card.tsx +92 -0
- package/examples/qk-next/components/ui/command.tsx +184 -0
- package/examples/qk-next/components/ui/dialog.tsx +143 -0
- package/examples/qk-next/components/ui/drawer.tsx +135 -0
- package/examples/qk-next/components/ui/hover-card.tsx +44 -0
- package/examples/qk-next/components/ui/icons.tsx +148 -0
- package/examples/qk-next/components/ui/sonner.tsx +26 -0
- package/examples/qk-next/components/ui/table.tsx +117 -0
- package/examples/qk-next/components.json +21 -0
- package/examples/qk-next/eslint.config.mjs +21 -0
- package/examples/qk-next/jsrepo.json +13 -0
- package/examples/qk-next/lib/utils.ts +6 -0
- package/examples/qk-next/next.config.ts +8 -0
- package/examples/qk-next/package.json +48 -0
- package/examples/qk-next/pnpm-lock.yaml +5558 -0
- package/examples/qk-next/postcss.config.mjs +5 -0
- package/examples/qk-next/public/file.svg +1 -0
- package/examples/qk-next/public/globe.svg +1 -0
- package/examples/qk-next/public/next.svg +1 -0
- package/examples/qk-next/public/vercel.svg +1 -0
- package/examples/qk-next/public/window.svg +1 -0
- package/examples/qk-next/tsconfig.json +42 -0
- package/examples/qk-next/types/sonner.d.ts +3 -0
- package/jest.config.js +26 -0
- package/package.json +51 -0
- package/src/adapters/drizzle/drizzle-adapter.test.ts +115 -0
- package/src/adapters/drizzle/index.ts +299 -0
- package/src/adapters/index.ts +11 -0
- package/src/adapters/types.ts +72 -0
- package/src/index.ts +194 -0
- package/src/integration.test.ts +202 -0
- package/src/parser/index.ts +2 -0
- package/src/parser/parser.test.ts +1056 -0
- package/src/parser/parser.ts +268 -0
- package/src/parser/types.ts +97 -0
- package/src/query/builder.test.ts +272 -0
- package/src/query/builder.ts +274 -0
- package/src/query/index.ts +2 -0
- package/src/query/types.ts +107 -0
- package/src/security/index.ts +2 -0
- package/src/security/types.ts +210 -0
- package/src/security/validator.test.ts +459 -0
- package/src/security/validator.ts +395 -0
- package/src/security.test.ts +366 -0
- package/src/translators/drizzle/drizzle-translator.test.ts +128 -0
- package/src/translators/drizzle/index.test.ts +45 -0
- package/src/translators/drizzle/index.ts +346 -0
- package/src/translators/index.ts +14 -0
- package/src/translators/sql/index.test.ts +45 -0
- package/src/translators/sql/index.ts +331 -0
- package/src/translators/sql/sql-translator.test.ts +419 -0
- package/src/translators/types.ts +44 -0
- package/src/types/sonner.d.ts +3 -0
- package/tsconfig.json +34 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Project review guidelines
|
|
2
|
+
|
|
3
|
+
Bellow is a list of generally accepted best-practices to prevent bugs in projects. Not all guidelines may apply to the current project; please make sure to read any README.md files in order to correlate goals for bug detection.
|
|
4
|
+
|
|
5
|
+
## Security focus areas
|
|
6
|
+
|
|
7
|
+
- Validate user input in API endpoints
|
|
8
|
+
- Check for SQL injection vulnerabilities in database queries
|
|
9
|
+
- Ensure proper authentication on protected routes
|
|
10
|
+
|
|
11
|
+
## Architecture patterns
|
|
12
|
+
|
|
13
|
+
- Use dependency injection for services
|
|
14
|
+
- Follow the repository pattern for data access
|
|
15
|
+
- Implement proper error handling with custom error classes
|
|
16
|
+
|
|
17
|
+
## Common issues
|
|
18
|
+
|
|
19
|
+
- Memory leaks in React components (check useEffect cleanup)
|
|
20
|
+
- Missing error boundaries in UI components
|
|
21
|
+
- Inconsistent naming conventions (use camelCase for functions)
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
---
|
|
2
|
+
description:
|
|
3
|
+
globs:
|
|
4
|
+
alwaysApply: true
|
|
5
|
+
---
|
|
6
|
+
# QueryKit Project Structure
|
|
7
|
+
|
|
8
|
+
QueryKit is organized into several key architectural components, each with a specific responsibility. This guide outlines where different types of code should be located and how they relate to each other.
|
|
9
|
+
|
|
10
|
+
## Core Components
|
|
11
|
+
|
|
12
|
+
### Parser
|
|
13
|
+
- Location: `src/parser`
|
|
14
|
+
- Purpose: Core query parsing engine that converts QueryKit DSL expressions into structured internal format
|
|
15
|
+
- Key files:
|
|
16
|
+
- Parser implementation
|
|
17
|
+
- AST type definitions
|
|
18
|
+
- Validation logic
|
|
19
|
+
|
|
20
|
+
### Translators
|
|
21
|
+
- Location: `src/translators`
|
|
22
|
+
- Purpose: Convert parsed queries into target-specific formats
|
|
23
|
+
- Each translator should be in its own subdirectory
|
|
24
|
+
- Must implement the standard translator interface
|
|
25
|
+
|
|
26
|
+
### Adapters
|
|
27
|
+
- Location: `src/adapters`
|
|
28
|
+
- Purpose: Connect QueryKit to external systems/libraries
|
|
29
|
+
- Each adapter (e.g. Drizzle) has its own subdirectory
|
|
30
|
+
- Must implement the standard adapter interface
|
|
31
|
+
|
|
32
|
+
### CLI
|
|
33
|
+
- Location: `src/cli`
|
|
34
|
+
- Purpose: Command-line interface for QueryKit
|
|
35
|
+
- Includes commands for:
|
|
36
|
+
- Query parsing/testing
|
|
37
|
+
- Query translation debugging
|
|
38
|
+
- Code generation utilities
|
|
39
|
+
|
|
40
|
+
### Frontend Utilities
|
|
41
|
+
- Location: `src/frontend`
|
|
42
|
+
- Purpose: Browser-specific implementations and components
|
|
43
|
+
- Includes:
|
|
44
|
+
- Query builder components
|
|
45
|
+
- Client-side filtering utilities
|
|
46
|
+
- Browser-optimized query parsing
|
|
47
|
+
|
|
48
|
+
### Server Helpers
|
|
49
|
+
- Location: `src/server`
|
|
50
|
+
- Purpose: Server-side integration utilities
|
|
51
|
+
- Includes:
|
|
52
|
+
- Middleware implementations
|
|
53
|
+
- Request parsing helpers
|
|
54
|
+
- Database integration utilities
|
|
55
|
+
|
|
56
|
+
## Code Organization Guidelines
|
|
57
|
+
|
|
58
|
+
1. Each major component should have its own directory
|
|
59
|
+
2. Shared utilities go in `src/common`
|
|
60
|
+
3. Types and interfaces should be in `types.ts` files within their relevant component
|
|
61
|
+
4. Tests should be co-located with the code they test
|
|
62
|
+
5. Examples should be in an `examples` directory at the root
|
|
63
|
+
|
|
64
|
+
## TypeScript Guidelines
|
|
65
|
+
|
|
66
|
+
1. Use strict TypeScript configuration
|
|
67
|
+
2. Explicit return types on exported functions
|
|
68
|
+
3. Prefer interfaces over type aliases for public APIs
|
|
69
|
+
4. Use generics to ensure type safety across query operations
|
|
70
|
+
|
|
71
|
+
## Testing Guidelines
|
|
72
|
+
|
|
73
|
+
1. Jest for unit and integration tests
|
|
74
|
+
2. Co-locate test files with implementation
|
|
75
|
+
3. Use `.test.ts` or `.spec.ts` suffix
|
|
76
|
+
4. Include both unit and integration tests
|
|
77
|
+
5. Mock external dependencies appropriately
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
---
|
|
2
|
+
description:
|
|
3
|
+
globs:
|
|
4
|
+
alwaysApply: true
|
|
5
|
+
---
|
|
6
|
+
# TypeScript Coding Standards
|
|
7
|
+
|
|
8
|
+
## Basic Principles
|
|
9
|
+
|
|
10
|
+
1. Use English for all code and documentation
|
|
11
|
+
2. Always declare explicit types
|
|
12
|
+
3. Document public APIs with JSDoc
|
|
13
|
+
4. One export per file
|
|
14
|
+
5. Avoid blank lines within functions
|
|
15
|
+
6. Follow SOLID principles (see `05-solid-principles.mdc`)
|
|
16
|
+
|
|
17
|
+
## Naming Conventions
|
|
18
|
+
|
|
19
|
+
### Case Styles
|
|
20
|
+
- `PascalCase` for:
|
|
21
|
+
- Classes
|
|
22
|
+
- Interfaces
|
|
23
|
+
- Type aliases
|
|
24
|
+
- Enums
|
|
25
|
+
- `camelCase` for:
|
|
26
|
+
- Variables
|
|
27
|
+
- Functions
|
|
28
|
+
- Methods
|
|
29
|
+
- Properties
|
|
30
|
+
- `kebab-case` for:
|
|
31
|
+
- File names
|
|
32
|
+
- Directory names
|
|
33
|
+
- `UPPERCASE` for:
|
|
34
|
+
- Constants
|
|
35
|
+
- Environment variables
|
|
36
|
+
- `I` prefix for interfaces (e.g., `ITranslator`)
|
|
37
|
+
|
|
38
|
+
### Naming Rules
|
|
39
|
+
1. Start boolean variables with verbs:
|
|
40
|
+
- `isLoading`
|
|
41
|
+
- `hasError`
|
|
42
|
+
- `canDelete`
|
|
43
|
+
2. Start functions with verbs
|
|
44
|
+
3. Use complete words (no abbreviations except standard ones)
|
|
45
|
+
- Allowed: `API`, `URL`, `i` (loop), `err`, `ctx`, `req`, `res`
|
|
46
|
+
4. Interface names should describe capabilities
|
|
47
|
+
|
|
48
|
+
## Function Guidelines
|
|
49
|
+
|
|
50
|
+
1. Keep functions short (< 20 instructions)
|
|
51
|
+
2. Single responsibility principle
|
|
52
|
+
3. Use early returns to avoid nesting
|
|
53
|
+
4. Prefer higher-order functions (`map`, `filter`, `reduce`)
|
|
54
|
+
5. Use default parameters instead of null checks
|
|
55
|
+
6. Follow RO-RO (Receive Object, Return Object) pattern
|
|
56
|
+
7. Maintain single level of abstraction
|
|
57
|
+
8. Design for extension (OCP)
|
|
58
|
+
|
|
59
|
+
## Interface and Class Design
|
|
60
|
+
|
|
61
|
+
1. Program to interfaces, not implementations
|
|
62
|
+
2. Keep interfaces focused and cohesive (ISP)
|
|
63
|
+
3. Use composition over inheritance
|
|
64
|
+
4. Implement dependency injection (DIP)
|
|
65
|
+
5. Ensure proper interface segregation
|
|
66
|
+
6. Make base classes substitutable (LSP)
|
|
67
|
+
|
|
68
|
+
## Type Safety
|
|
69
|
+
|
|
70
|
+
1. Avoid `any` type
|
|
71
|
+
2. Create specific types/interfaces
|
|
72
|
+
3. Use generics for reusable components
|
|
73
|
+
4. Prefer `unknown` over `any` when type is uncertain
|
|
74
|
+
5. Use union types for finite possibilities
|
|
75
|
+
6. Leverage TypeScript's strict mode
|
|
76
|
+
|
|
77
|
+
## Error Handling
|
|
78
|
+
|
|
79
|
+
1. Use typed errors
|
|
80
|
+
2. Prefer error objects over strings
|
|
81
|
+
3. Handle async errors with try/catch
|
|
82
|
+
4. Document error cases in JSDoc
|
|
83
|
+
5. Create specific error types for different cases
|
|
84
|
+
|
|
85
|
+
## Code Organization
|
|
86
|
+
|
|
87
|
+
1. Group related types together
|
|
88
|
+
2. Export types from dedicated type files
|
|
89
|
+
3. Keep circular dependencies in check
|
|
90
|
+
4. Use barrel exports for public APIs
|
|
91
|
+
5. Separate interfaces from implementations
|
|
92
|
+
6. Use dependency injection containers where appropriate
|
|
93
|
+
|
|
94
|
+
## Documentation
|
|
95
|
+
|
|
96
|
+
1. JSDoc for all public APIs
|
|
97
|
+
2. Include example usage in docs
|
|
98
|
+
3. Document generic type parameters
|
|
99
|
+
4. Note any side effects
|
|
100
|
+
5. Specify error cases and conditions
|
|
101
|
+
6. Document interface contracts and invariants
|
|
102
|
+
|
|
103
|
+
## Additional Context
|
|
104
|
+
|
|
105
|
+
1. Use pnpm
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
---
|
|
2
|
+
description:
|
|
3
|
+
globs:
|
|
4
|
+
alwaysApply: true
|
|
5
|
+
---
|
|
6
|
+
# Testing Standards
|
|
7
|
+
|
|
8
|
+
## Test Organization
|
|
9
|
+
|
|
10
|
+
1. Co-locate tests with source files
|
|
11
|
+
2. Use descriptive test file names:
|
|
12
|
+
- `[feature].test.ts`
|
|
13
|
+
- `[feature].spec.ts`
|
|
14
|
+
3. Group related tests in describe blocks
|
|
15
|
+
4. Use clear test case descriptions
|
|
16
|
+
|
|
17
|
+
## Test Structure
|
|
18
|
+
|
|
19
|
+
### Unit Tests
|
|
20
|
+
1. Follow Arrange-Act-Assert pattern
|
|
21
|
+
2. One assertion per test when possible
|
|
22
|
+
3. Clear setup and teardown
|
|
23
|
+
4. Mock external dependencies
|
|
24
|
+
|
|
25
|
+
### Integration Tests
|
|
26
|
+
1. Test component interactions
|
|
27
|
+
2. Focus on public APIs
|
|
28
|
+
3. Minimize mocking where possible
|
|
29
|
+
4. Test error cases and edge conditions
|
|
30
|
+
|
|
31
|
+
## Naming Conventions
|
|
32
|
+
|
|
33
|
+
1. Test variables:
|
|
34
|
+
- `inputX` for test inputs
|
|
35
|
+
- `expectedX` for expected results
|
|
36
|
+
- `actualX` for actual results
|
|
37
|
+
- `mockX` for mocks
|
|
38
|
+
2. Test descriptions:
|
|
39
|
+
- Should describe the scenario
|
|
40
|
+
- Include expected behavior
|
|
41
|
+
- Mention important conditions
|
|
42
|
+
|
|
43
|
+
## Test Coverage
|
|
44
|
+
|
|
45
|
+
1. Required coverage:
|
|
46
|
+
- Public APIs: 100%
|
|
47
|
+
- Internal implementation: 80%
|
|
48
|
+
- Edge cases and error conditions
|
|
49
|
+
2. Types of tests needed:
|
|
50
|
+
- Unit tests for individual components
|
|
51
|
+
- Integration tests for component interaction
|
|
52
|
+
- E2E tests for critical paths
|
|
53
|
+
|
|
54
|
+
## Mocking Guidelines
|
|
55
|
+
|
|
56
|
+
1. Mock external dependencies
|
|
57
|
+
2. Use Jest mock functions
|
|
58
|
+
3. Clear mock setup and verification
|
|
59
|
+
4. Reset mocks between tests
|
|
60
|
+
5. Document mock behavior
|
|
61
|
+
|
|
62
|
+
## Best Practices
|
|
63
|
+
|
|
64
|
+
1. Keep tests focused and simple
|
|
65
|
+
2. Avoid test interdependence
|
|
66
|
+
3. Clean up test resources
|
|
67
|
+
4. Use appropriate assertions
|
|
68
|
+
5. Test both success and failure cases
|
|
69
|
+
6. Include performance tests where relevant
|
|
70
|
+
7. Attempt feature-first development
|
|
71
|
+
|
|
72
|
+
## Test Data
|
|
73
|
+
|
|
74
|
+
1. Use factories for test data
|
|
75
|
+
2. Keep test data minimal
|
|
76
|
+
3. Make test data intention clear
|
|
77
|
+
4. Avoid sharing mutable test data
|
|
78
|
+
5. Use meaningful test values
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
---
|
|
2
|
+
description:
|
|
3
|
+
globs:
|
|
4
|
+
alwaysApply: true
|
|
5
|
+
---
|
|
6
|
+
# Query Language Design Principles
|
|
7
|
+
|
|
8
|
+
## Core Concepts
|
|
9
|
+
|
|
10
|
+
1. QueryKit DSL should be:
|
|
11
|
+
- Readable and intuitive
|
|
12
|
+
- Consistent across environments
|
|
13
|
+
- Type-safe
|
|
14
|
+
- Extensible
|
|
15
|
+
|
|
16
|
+
## Query Structure
|
|
17
|
+
|
|
18
|
+
### Filtering
|
|
19
|
+
1. Basic operators:
|
|
20
|
+
- Comparison: `==`, `!=`, `>`, `>=`, `<`, `<=`
|
|
21
|
+
- Logical: `&&`, `||`, `!`
|
|
22
|
+
2. Complex operations:
|
|
23
|
+
- String matching
|
|
24
|
+
- Array operations
|
|
25
|
+
- Nested property access
|
|
26
|
+
|
|
27
|
+
### Sorting
|
|
28
|
+
1. Sort syntax:
|
|
29
|
+
- Single field: `field ASC|DESC`
|
|
30
|
+
- Multiple fields: `field1 ASC, field2 DESC`
|
|
31
|
+
2. Sort priorities respected in order
|
|
32
|
+
|
|
33
|
+
## Type Safety
|
|
34
|
+
|
|
35
|
+
1. All queries must be type-safe
|
|
36
|
+
2. Runtime validation must match compile-time types
|
|
37
|
+
3. Clear error messages for type mismatches
|
|
38
|
+
4. Generic type parameters for reusability
|
|
39
|
+
|
|
40
|
+
## Parser Implementation
|
|
41
|
+
|
|
42
|
+
1. Clear separation of:
|
|
43
|
+
- Lexical analysis
|
|
44
|
+
- Syntax parsing
|
|
45
|
+
- Semantic validation
|
|
46
|
+
2. Detailed error reporting
|
|
47
|
+
3. Performance optimization
|
|
48
|
+
4. Extensible grammar
|
|
49
|
+
|
|
50
|
+
## Translation Layer
|
|
51
|
+
|
|
52
|
+
1. Consistent translation interface
|
|
53
|
+
2. Support for multiple targets:
|
|
54
|
+
- SQL (via Drizzle)
|
|
55
|
+
- In-memory filtering
|
|
56
|
+
- Future adapters
|
|
57
|
+
3. Optimization opportunities
|
|
58
|
+
4. Type preservation
|
|
59
|
+
|
|
60
|
+
## Error Handling
|
|
61
|
+
|
|
62
|
+
1. Clear error messages
|
|
63
|
+
2. Validation at parse time
|
|
64
|
+
3. Runtime safety checks
|
|
65
|
+
4. Debugging support
|
|
66
|
+
|
|
67
|
+
## Security
|
|
68
|
+
|
|
69
|
+
1. Input validation
|
|
70
|
+
2. Query size limits
|
|
71
|
+
3. Resource usage controls
|
|
72
|
+
4. Safe evaluation
|
|
73
|
+
|
|
74
|
+
## Performance
|
|
75
|
+
|
|
76
|
+
1. Efficient parsing
|
|
77
|
+
2. Optimized translation
|
|
78
|
+
3. Caching where appropriate
|
|
79
|
+
4. Resource management
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
---
|
|
2
|
+
description:
|
|
3
|
+
globs:
|
|
4
|
+
alwaysApply: true
|
|
5
|
+
---
|
|
6
|
+
# SOLID Principles in QueryKit
|
|
7
|
+
|
|
8
|
+
## Single Responsibility Principle (SRP)
|
|
9
|
+
|
|
10
|
+
1. Each module should have one reason to change
|
|
11
|
+
2. Implementation guidelines:
|
|
12
|
+
- Parser only handles parsing
|
|
13
|
+
- Translators only handle translation
|
|
14
|
+
- Adapters only handle integration
|
|
15
|
+
3. Examples:
|
|
16
|
+
- `Parser` class focuses only on converting DSL to AST
|
|
17
|
+
- `DrizzleTranslator` only handles Drizzle-specific translation
|
|
18
|
+
- `ValidationService` only handles query validation
|
|
19
|
+
|
|
20
|
+
## Open/Closed Principle (OCP)
|
|
21
|
+
|
|
22
|
+
1. Software entities should be open for extension but closed for modification
|
|
23
|
+
2. Implementation guidelines:
|
|
24
|
+
- Use interfaces for core components
|
|
25
|
+
- Implement new features through extension
|
|
26
|
+
- Avoid modifying existing, tested code
|
|
27
|
+
3. Examples:
|
|
28
|
+
- New query operators via operator registry
|
|
29
|
+
- Custom translators via translator interface
|
|
30
|
+
- New adapters via adapter interface
|
|
31
|
+
|
|
32
|
+
## Liskov Substitution Principle (LSP)
|
|
33
|
+
|
|
34
|
+
1. Subtypes must be substitutable for their base types
|
|
35
|
+
2. Implementation guidelines:
|
|
36
|
+
- Maintain contract consistency
|
|
37
|
+
- Preserve invariants
|
|
38
|
+
- Follow interface specifications
|
|
39
|
+
3. Examples:
|
|
40
|
+
- All translators must preserve query semantics
|
|
41
|
+
- Custom operators must maintain type safety
|
|
42
|
+
- Adapters must handle all valid queries
|
|
43
|
+
|
|
44
|
+
## Interface Segregation Principle (ISP)
|
|
45
|
+
|
|
46
|
+
1. Clients should not depend on interfaces they don't use
|
|
47
|
+
2. Implementation guidelines:
|
|
48
|
+
- Split large interfaces
|
|
49
|
+
- Create focused, cohesive interfaces
|
|
50
|
+
- Allow selective implementation
|
|
51
|
+
3. Examples:
|
|
52
|
+
```typescript
|
|
53
|
+
// Instead of one large interface:
|
|
54
|
+
interface QueryProcessor {
|
|
55
|
+
parse(): AST;
|
|
56
|
+
validate(): boolean;
|
|
57
|
+
translate(): string;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Split into focused interfaces:
|
|
61
|
+
interface Parser {
|
|
62
|
+
parse(): AST;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
interface Validator {
|
|
66
|
+
validate(): boolean;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
interface Translator {
|
|
70
|
+
translate(): string;
|
|
71
|
+
}
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## Dependency Inversion Principle (DIP)
|
|
75
|
+
|
|
76
|
+
1. High-level modules should not depend on low-level modules
|
|
77
|
+
2. Implementation guidelines:
|
|
78
|
+
- Depend on abstractions
|
|
79
|
+
- Use dependency injection
|
|
80
|
+
- Define clear interfaces
|
|
81
|
+
3. Examples:
|
|
82
|
+
```typescript
|
|
83
|
+
// Instead of:
|
|
84
|
+
class QueryExecutor {
|
|
85
|
+
private drizzleTranslator = new DrizzleTranslator();
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// Use:
|
|
89
|
+
class QueryExecutor {
|
|
90
|
+
constructor(private translator: ITranslator) {}
|
|
91
|
+
}
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## Practical Application
|
|
95
|
+
|
|
96
|
+
### Component Design
|
|
97
|
+
1. Create interfaces before implementations
|
|
98
|
+
2. Use abstract factories for component creation
|
|
99
|
+
3. Implement dependency injection
|
|
100
|
+
4. Design for extensibility
|
|
101
|
+
|
|
102
|
+
### Code Organization
|
|
103
|
+
1. Group related interfaces together
|
|
104
|
+
2. Separate interface definitions from implementations
|
|
105
|
+
3. Use meaningful namespaces
|
|
106
|
+
4. Maintain clear dependency hierarchy
|
|
107
|
+
|
|
108
|
+
### Testing
|
|
109
|
+
1. Test against interfaces, not implementations
|
|
110
|
+
2. Use mock implementations for testing
|
|
111
|
+
3. Verify LSP compliance
|
|
112
|
+
4. Test extension points
|
|
113
|
+
|
|
114
|
+
### Documentation
|
|
115
|
+
1. Document interface contracts
|
|
116
|
+
2. Specify invariants
|
|
117
|
+
3. Explain extension points
|
|
118
|
+
4. Provide implementation examples
|