dzql 0.4.4 → 0.4.6

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.
@@ -1,266 +0,0 @@
1
- # Compiler Development Session Summary
2
-
3
- ## Latest Session: Coding Standards Compliance (2025-11-16)
4
-
5
- This session enforced DZQL coding standards across all generated functions to ensure consistency, security, and proper WebSocket API protection.
6
-
7
- ### ✅ Coding Standards Fixes
8
-
9
- **What Changed**: Fixed the compiler to generate code compliant with DZQL conventions:
10
-
11
- 1. **Parameter Ordering** - `p_user_id INT` now FIRST in all functions
12
- - ✅ `get_*(p_user_id INT, p_id INT, ...)`
13
- - ✅ `save_*(p_user_id INT, p_data JSONB)`
14
- - ✅ `delete_*(p_user_id INT, p_id INT)`
15
- - ✅ `lookup_*(p_user_id INT, p_filter TEXT, ...)`
16
- - ✅ `search_*(p_user_id INT, p_filters JSONB, ...)`
17
-
18
- 2. **Helper Function Prefixes** - Internal functions now use `_` prefix
19
- - ✅ `_graph_*_on_create(p_user_id INT, p_record JSONB)`
20
- - ✅ `_resolve_notification_paths_*(p_user_id INT, p_record JSONB)`
21
- - Prevents direct websocket client access to internal functions
22
-
23
- 3. **Standard Permission Functions** - All 4 always generated
24
- - ✅ `can_view_*`, `can_create_*`, `can_update_*`, `can_delete_*`
25
- - Even for public access (returns `true`)
26
-
27
- 4. **Clean Function Names** - Fixed malformed names with embedded comments
28
- - ❌ Before: `can_-- Anyone can create...'update_organisations`
29
- - ✅ After: `can_update_organisations`
30
-
31
- **Files Modified**:
32
- - `src/codegen/permission-codegen.js` - Clean operation names, generate all 4 functions
33
- - `src/codegen/operation-codegen.js` - Fix parameter ordering, update helper calls
34
- - `src/codegen/notification-codegen.js` - Add underscore prefix, p_user_id first
35
- - `src/codegen/graph-rules-codegen.js` - Add underscore prefix, p_user_id first
36
- - `tests/sql-validation.test.js` - Update expectations to match standards
37
-
38
- **Documentation Added**:
39
- - `CODING_STANDARDS.md` - Complete coding standards reference
40
- - Updated `README.md` with correct function signatures
41
- - Updated `QUICKSTART.md` with correct examples
42
-
43
- **Test Results**: ✅ All 55 tests passing
44
-
45
- ---
46
-
47
- ## Previous Session: Graph Rules & Advanced Filters
48
-
49
- This session continued work on the DZQL Compiler from a previous session where the core compilation infrastructure was built.
50
-
51
- ## Completed Features
52
-
53
- ### 1. ✅ Graph Rules Compilation
54
-
55
- **What**: Transforms declarative graph rules into executable PostgreSQL functions
56
-
57
- **Implementation**:
58
- - Created `GraphRulesCodegen` class
59
- - Supports all action types: `create`, `update`, `delete`, `validate`, `execute`
60
- - Resolves special variables:
61
- - `@user_id` → `p_user_id`
62
- - `@today` → `CURRENT_DATE`
63
- - `@now` → `NOW()`
64
- - `@field` → `(p_record->>'field')`
65
- - Generates trigger-based functions: `graph_{table}_{on_create|on_update|on_delete}`
66
- - Integrated into SAVE and DELETE operations
67
-
68
- **Example Generated Code** (now with correct coding standards):
69
- ```sql
70
- CREATE OR REPLACE FUNCTION _graph_organisations_on_create(
71
- p_user_id INT,
72
- p_record JSONB
73
- ) RETURNS VOID AS $$
74
- BEGIN
75
- -- Creator becomes owner
76
- INSERT INTO acts_for (user_id, org_id, valid_from)
77
- VALUES (p_user_id, (p_record->>'id'), CURRENT_DATE);
78
- END;
79
- $$ LANGUAGE plpgsql SECURITY DEFINER;
80
- ```
81
-
82
- > Note: Helper functions now use `_` prefix and have `p_user_id` first
83
-
84
- **Files Changed**:
85
- - `src/codegen/graph-rules-codegen.js` (new)
86
- - `src/compiler.js` (integrated)
87
- - `src/codegen/operation-codegen.js` (calls graph functions)
88
-
89
- ### 2. ✅ Advanced SEARCH Filter Operators
90
-
91
- **What**: Comprehensive JSONB-based filtering with multiple operators
92
-
93
- **Operators Implemented**:
94
- - **Comparison**: `eq`, `ne`, `gt`, `gte`, `lt`, `lte`
95
- - **Array Membership**: `in`
96
- - **Pattern Matching**: `like`, `ilike`
97
-
98
- **Features**:
99
- - Dynamic WHERE clause builder
100
- - Type-safe value handling
101
- - SQL injection protection via `format()`
102
- - Combines with text search and temporal filters
103
- - Multiple operators per field
104
- - Multiple fields per query
105
-
106
- **Example Usage**:
107
- ```json
108
- {
109
- "age": {"gte": 18, "lte": 65},
110
- "status": {"in": ["active", "pending"]},
111
- "email": {"ilike": "%@company.com"}
112
- }
113
- ```
114
-
115
- **Generated SQL**:
116
- ```sql
117
- WHERE TRUE
118
- AND age >= '18'
119
- AND age <= '65'
120
- AND status = ANY(ARRAY['active', 'pending']::TEXT[])
121
- AND email ILIKE '%@company.com'
122
- ```
123
-
124
- **Files Changed**:
125
- - `src/codegen/operation-codegen.js` (enhanced SEARCH function)
126
- - `docs/ADVANCED_FILTERS.md` (comprehensive documentation)
127
-
128
- ### 3. ✅ Comprehensive Test Suite
129
-
130
- **SQL Validation Tests** (42 tests):
131
- - Function signature validation
132
- - Permission logic verification
133
- - CRUD operation structure
134
- - Graph rules generation
135
- - Filter operator inclusion
136
- - SQL syntax validation
137
- - Metadata verification
138
-
139
- **Integration Tests** (prepared):
140
- - Full workflow testing
141
- - Real database operations
142
- - Permission enforcement
143
- - Advanced filter testing
144
- - Graph rules execution
145
-
146
- **Test Organization**:
147
- ```bash
148
- bun test # Unit + validation (55 tests)
149
- bun test:integration # Integration tests (requires PostgreSQL)
150
- bun test:all # Everything
151
- ```
152
-
153
- **Files Added**:
154
- - `tests/sql-validation.test.js` (42 tests)
155
- - `tests/integration.test.skip.js` (prepared for PostgreSQL)
156
- - `tests/integration-README.md` (setup instructions)
157
-
158
- ## Test Results
159
-
160
- ✅ **55 tests passing** (13 compiler + 42 validation)
161
- - All core compiler functionality verified
162
- - All generated SQL validated
163
- - No regressions introduced
164
-
165
- ## Commits Made
166
-
167
- 1. **feat: Complete graph rules compilation** (95d4257)
168
- - Full graph rules compilation implementation
169
- - Integration with SAVE/DELETE operations
170
- - All action types supported
171
-
172
- 2. **feat: Add advanced SEARCH filter operators** (dc8b0fe)
173
- - 9 filter operators implemented
174
- - Dynamic WHERE clause building
175
- - Comprehensive documentation
176
-
177
- 3. **test: Add comprehensive test suite for compiled SQL** (1d14209)
178
- - 42 SQL validation tests
179
- - Integration test framework
180
- - Test documentation
181
-
182
- ## Code Statistics
183
-
184
- **Lines Added**: ~1,500 lines across:
185
- - Graph rules code generation
186
- - Advanced filter implementation
187
- - Test suites
188
- - Documentation
189
-
190
- **Files Created**: 6
191
- - `src/codegen/graph-rules-codegen.js`
192
- - `docs/ADVANCED_FILTERS.md`
193
- - `tests/sql-validation.test.js`
194
- - `tests/integration.test.skip.js`
195
- - `tests/integration-README.md`
196
- - `docs/SESSION_SUMMARY.md`
197
-
198
- **Files Modified**: 4
199
- - `src/compiler.js`
200
- - `src/codegen/operation-codegen.js`
201
- - `package.json`
202
- - (various generated files)
203
-
204
- ## Current Compiler Capabilities
205
-
206
- The DZQL Compiler now supports:
207
-
208
- ### ✅ Entity Definition Parsing
209
- - Complete DZQL entity syntax
210
- - Nested JSONB structures
211
- - Array parameters with depth tracking
212
-
213
- ### ✅ Permission Compilation
214
- - Direct field checks
215
- - Graph traversal with filters
216
- - Temporal filtering (`{active}`)
217
- - All CRUD operations (view, create, update, delete)
218
-
219
- ### ✅ Notification Path Compilation
220
- - User resolution via graph traversal
221
- - Temporal filtering
222
- - Multiple notification paths
223
-
224
- ### ✅ Graph Rules Compilation
225
- - on_create, on_update, on_delete triggers
226
- - All action types
227
- - Special variable resolution
228
- - Automatic integration with operations
229
-
230
- ### ✅ CRUD Operations
231
- - GET with FK expansion
232
- - SAVE with upsert logic
233
- - DELETE (soft or hard)
234
- - LOOKUP with filtering
235
- - SEARCH with advanced filters
236
-
237
- ### ✅ Advanced Features
238
- - 9 filter operators in SEARCH
239
- - Dynamic WHERE clause building
240
- - Reproducible builds (SHA-256 checksums)
241
- - Git-trackable output
242
- - Comprehensive error handling
243
-
244
- ## What's Next?
245
-
246
- Potential future enhancements:
247
- - [ ] Performance benchmarking vs runtime DZQL
248
- - [ ] Migration generator (schema changes)
249
- - [ ] Index recommendation based on paths
250
- - [ ] Query plan analysis
251
- - [ ] Incremental compilation
252
- - [ ] Type inference for better error messages
253
- - [ ] GraphQL/REST API generation from entities
254
-
255
- ## Branch Status
256
-
257
- Branch: `claude/new-features-planning-015GH92pzBxTkA1uWjnjJqbZ`
258
-
259
- All changes committed and pushed. Ready for review or PR creation.
260
-
261
- ---
262
-
263
- **Session Duration**: Continued from previous session
264
- **Total Tests**: 55 passing
265
- **Code Coverage**: All major compilation paths tested
266
- **Documentation**: Comprehensive docs for all features