dzql 0.5.33 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (142) hide show
  1. package/.env.sample +28 -0
  2. package/compose.yml +28 -0
  3. package/dist/client/index.ts +1 -0
  4. package/dist/client/stores/useMyProfileStore.ts +114 -0
  5. package/dist/client/stores/useOrgDashboardStore.ts +131 -0
  6. package/dist/client/stores/useVenueDetailStore.ts +117 -0
  7. package/dist/client/ws.ts +716 -0
  8. package/dist/db/migrations/000_core.sql +92 -0
  9. package/dist/db/migrations/20251229T212912022Z_schema.sql +3020 -0
  10. package/dist/db/migrations/20251229T212912022Z_subscribables.sql +371 -0
  11. package/dist/runtime/manifest.json +1562 -0
  12. package/docs/README.md +309 -36
  13. package/docs/feature-requests/applyPatch-bug-report.md +85 -0
  14. package/docs/feature-requests/connection-ready-profile.md +57 -0
  15. package/docs/feature-requests/hidden-bug-report.md +111 -0
  16. package/docs/feature-requests/hidden-fields-subscribables.md +34 -0
  17. package/docs/feature-requests/subscribable-param-key-bug.md +38 -0
  18. package/docs/feature-requests/todo.md +146 -0
  19. package/docs/for_ai.md +653 -0
  20. package/docs/project-setup.md +456 -0
  21. package/examples/blog.ts +50 -0
  22. package/examples/invalid.ts +18 -0
  23. package/examples/venues.js +485 -0
  24. package/package.json +23 -60
  25. package/src/cli/codegen/client.ts +99 -0
  26. package/src/cli/codegen/manifest.ts +95 -0
  27. package/src/cli/codegen/pinia.ts +174 -0
  28. package/src/cli/codegen/realtime.ts +58 -0
  29. package/src/cli/codegen/sql.ts +698 -0
  30. package/src/cli/codegen/subscribable_sql.ts +547 -0
  31. package/src/cli/codegen/subscribable_store.ts +184 -0
  32. package/src/cli/codegen/types.ts +142 -0
  33. package/src/cli/compiler/analyzer.ts +52 -0
  34. package/src/cli/compiler/graph_rules.ts +251 -0
  35. package/src/cli/compiler/ir.ts +233 -0
  36. package/src/cli/compiler/loader.ts +132 -0
  37. package/src/cli/compiler/permissions.ts +227 -0
  38. package/src/cli/index.ts +166 -0
  39. package/src/client/index.ts +1 -0
  40. package/src/client/ws.ts +286 -0
  41. package/src/runtime/auth.ts +39 -0
  42. package/src/runtime/db.ts +33 -0
  43. package/src/runtime/errors.ts +51 -0
  44. package/src/runtime/index.ts +98 -0
  45. package/src/runtime/js_functions.ts +63 -0
  46. package/src/runtime/manifest_loader.ts +29 -0
  47. package/src/runtime/namespace.ts +483 -0
  48. package/src/runtime/server.ts +87 -0
  49. package/src/runtime/ws.ts +197 -0
  50. package/src/shared/ir.ts +197 -0
  51. package/tests/client.test.ts +38 -0
  52. package/tests/codegen.test.ts +71 -0
  53. package/tests/compiler.test.ts +45 -0
  54. package/tests/graph_rules.test.ts +173 -0
  55. package/tests/integration/db.test.ts +174 -0
  56. package/tests/integration/e2e.test.ts +65 -0
  57. package/tests/integration/features.test.ts +922 -0
  58. package/tests/integration/full_stack.test.ts +262 -0
  59. package/tests/integration/setup.ts +45 -0
  60. package/tests/ir.test.ts +32 -0
  61. package/tests/namespace.test.ts +395 -0
  62. package/tests/permissions.test.ts +55 -0
  63. package/tests/pinia.test.ts +48 -0
  64. package/tests/realtime.test.ts +22 -0
  65. package/tests/runtime.test.ts +80 -0
  66. package/tests/subscribable_gen.test.ts +72 -0
  67. package/tests/subscribable_reactivity.test.ts +258 -0
  68. package/tests/venues_gen.test.ts +25 -0
  69. package/tsconfig.json +20 -0
  70. package/tsconfig.tsbuildinfo +1 -0
  71. package/README.md +0 -90
  72. package/bin/cli.js +0 -727
  73. package/docs/compiler/ADVANCED_FILTERS.md +0 -183
  74. package/docs/compiler/CODING_STANDARDS.md +0 -415
  75. package/docs/compiler/COMPARISON.md +0 -673
  76. package/docs/compiler/QUICKSTART.md +0 -326
  77. package/docs/compiler/README.md +0 -134
  78. package/docs/examples/README.md +0 -38
  79. package/docs/examples/blog.sql +0 -160
  80. package/docs/examples/venue-detail-simple.sql +0 -8
  81. package/docs/examples/venue-detail-subscribable.sql +0 -45
  82. package/docs/for-ai/claude-guide.md +0 -1210
  83. package/docs/getting-started/quickstart.md +0 -125
  84. package/docs/getting-started/subscriptions-quick-start.md +0 -203
  85. package/docs/getting-started/tutorial.md +0 -1104
  86. package/docs/guides/atomic-updates.md +0 -299
  87. package/docs/guides/client-stores.md +0 -730
  88. package/docs/guides/composite-primary-keys.md +0 -158
  89. package/docs/guides/custom-functions.md +0 -362
  90. package/docs/guides/drop-semantics.md +0 -554
  91. package/docs/guides/field-defaults.md +0 -240
  92. package/docs/guides/interpreter-vs-compiler.md +0 -237
  93. package/docs/guides/many-to-many.md +0 -929
  94. package/docs/guides/subscriptions.md +0 -537
  95. package/docs/reference/api.md +0 -1373
  96. package/docs/reference/client.md +0 -224
  97. package/src/client/stores/index.js +0 -8
  98. package/src/client/stores/useAppStore.js +0 -285
  99. package/src/client/stores/useWsStore.js +0 -289
  100. package/src/client/ws.js +0 -762
  101. package/src/compiler/cli/compile-example.js +0 -33
  102. package/src/compiler/cli/compile-subscribable.js +0 -43
  103. package/src/compiler/cli/debug-compile.js +0 -44
  104. package/src/compiler/cli/debug-parse.js +0 -26
  105. package/src/compiler/cli/debug-path-parser.js +0 -18
  106. package/src/compiler/cli/debug-subscribable-parser.js +0 -21
  107. package/src/compiler/cli/index.js +0 -174
  108. package/src/compiler/codegen/auth-codegen.js +0 -153
  109. package/src/compiler/codegen/drop-semantics-codegen.js +0 -553
  110. package/src/compiler/codegen/graph-rules-codegen.js +0 -450
  111. package/src/compiler/codegen/notification-codegen.js +0 -232
  112. package/src/compiler/codegen/operation-codegen.js +0 -1382
  113. package/src/compiler/codegen/permission-codegen.js +0 -318
  114. package/src/compiler/codegen/subscribable-codegen.js +0 -827
  115. package/src/compiler/compiler.js +0 -371
  116. package/src/compiler/index.js +0 -11
  117. package/src/compiler/parser/entity-parser.js +0 -440
  118. package/src/compiler/parser/path-parser.js +0 -290
  119. package/src/compiler/parser/subscribable-parser.js +0 -244
  120. package/src/database/dzql-core.sql +0 -161
  121. package/src/database/migrations/001_schema.sql +0 -60
  122. package/src/database/migrations/002_functions.sql +0 -890
  123. package/src/database/migrations/003_operations.sql +0 -1135
  124. package/src/database/migrations/004_search.sql +0 -581
  125. package/src/database/migrations/005_entities.sql +0 -730
  126. package/src/database/migrations/006_auth.sql +0 -94
  127. package/src/database/migrations/007_events.sql +0 -133
  128. package/src/database/migrations/008_hello.sql +0 -18
  129. package/src/database/migrations/008a_meta.sql +0 -172
  130. package/src/database/migrations/009_subscriptions.sql +0 -240
  131. package/src/database/migrations/010_atomic_updates.sql +0 -157
  132. package/src/database/migrations/010_fix_m2m_events.sql +0 -94
  133. package/src/index.js +0 -40
  134. package/src/server/api.js +0 -9
  135. package/src/server/db.js +0 -442
  136. package/src/server/index.js +0 -317
  137. package/src/server/logger.js +0 -259
  138. package/src/server/mcp.js +0 -594
  139. package/src/server/meta-route.js +0 -251
  140. package/src/server/namespace.js +0 -292
  141. package/src/server/subscriptions.js +0 -351
  142. package/src/server/ws.js +0 -573
@@ -1,371 +0,0 @@
1
- /**
2
- * DZQL Compiler
3
- * Main compiler class that orchestrates parsing and code generation
4
- */
5
-
6
- import { EntityParser, parseEntitiesFromSQL } from './parser/entity-parser.js';
7
- import { SubscribableParser } from './parser/subscribable-parser.js';
8
- import { generatePermissionFunctions } from './codegen/permission-codegen.js';
9
- import { generateOperations } from './codegen/operation-codegen.js';
10
- import { generateNotificationFunction } from './codegen/notification-codegen.js';
11
- import { generateGraphRuleFunctions } from './codegen/graph-rules-codegen.js';
12
- import { generateSubscribable } from './codegen/subscribable-codegen.js';
13
- import { generateAuthFunctions } from './codegen/auth-codegen.js';
14
- import { generateDropSemantics } from './codegen/drop-semantics-codegen.js';
15
- import crypto from 'crypto';
16
-
17
- export class DZQLCompiler {
18
- constructor(options = {}) {
19
- this.options = {
20
- includeComments: true,
21
- includeChecksums: true,
22
- ...options
23
- };
24
- this.parser = new EntityParser();
25
- this.subscribableParser = new SubscribableParser();
26
- }
27
-
28
- /**
29
- * Compile an entity definition to SQL
30
- * @param {Object} entity - Entity configuration
31
- * @returns {Object} Compilation result
32
- */
33
- compile(entity) {
34
- const startTime = Date.now();
35
-
36
- // Normalize entity configuration
37
- const normalizedEntity = this.parser.parseFromObject(entity);
38
-
39
- // Generate SQL sections
40
- const sections = [];
41
-
42
- // Header
43
- if (this.options.includeComments) {
44
- sections.push(this._generateHeader(normalizedEntity));
45
- }
46
-
47
- // Permission functions
48
- const permissionSQL = generatePermissionFunctions(
49
- normalizedEntity.tableName,
50
- normalizedEntity.permissionPaths
51
- );
52
- sections.push(permissionSQL);
53
-
54
- // Operation functions
55
- const operationSQL = generateOperations(normalizedEntity);
56
- sections.push(operationSQL);
57
-
58
- // Auth functions (only for users table)
59
- const authSQL = generateAuthFunctions(normalizedEntity);
60
- if (authSQL) {
61
- sections.push(authSQL);
62
- }
63
-
64
- // Notification path resolution (if needed)
65
- if (normalizedEntity.notificationPaths &&
66
- Object.keys(normalizedEntity.notificationPaths).length > 0) {
67
- sections.push(this._generateNotificationFunction(normalizedEntity));
68
- }
69
-
70
- // Graph rules (if needed)
71
- if (normalizedEntity.graphRules &&
72
- Object.keys(normalizedEntity.graphRules).length > 0) {
73
- sections.push(this._generateGraphRuleFunctions(normalizedEntity));
74
- }
75
-
76
- // Custom functions (pass-through from entity definition)
77
- if (normalizedEntity.customFunctions &&
78
- normalizedEntity.customFunctions.length > 0) {
79
- sections.push(this._generateCustomFunctionsSection(normalizedEntity));
80
- }
81
-
82
- // Combine all sections
83
- const sql = sections.join('\n\n');
84
-
85
- // Calculate checksum
86
- const checksum = this._calculateChecksum(sql);
87
-
88
- const result = {
89
- tableName: normalizedEntity.tableName,
90
- sql,
91
- checksum,
92
- compilationTime: Date.now() - startTime,
93
- generatedAt: new Date().toISOString()
94
- };
95
-
96
- return result;
97
- }
98
-
99
- /**
100
- * Compile a subscribable definition to SQL
101
- * @param {Object} subscribable - Subscribable configuration
102
- * @returns {Object} Compilation result
103
- */
104
- compileSubscribable(subscribable) {
105
- const startTime = Date.now();
106
-
107
- // Normalize subscribable configuration
108
- const normalized = typeof subscribable.name === 'string'
109
- ? subscribable
110
- : this.subscribableParser.parseFromObject(subscribable);
111
-
112
- // Generate SQL
113
- const sql = generateSubscribable(normalized);
114
-
115
- // Calculate checksum
116
- const checksum = this._calculateChecksum(sql);
117
-
118
- return {
119
- name: normalized.name,
120
- sql,
121
- checksum,
122
- compilationTime: Date.now() - startTime,
123
- generatedAt: new Date().toISOString()
124
- };
125
- }
126
-
127
- /**
128
- * Compile multiple entities
129
- * @param {Array} entities - Array of entity configurations
130
- * @returns {Object} Compilation results
131
- */
132
- compileAll(entities) {
133
- const results = [];
134
- const errors = [];
135
-
136
- for (const entity of entities) {
137
- try {
138
- const result = this.compile(entity);
139
- results.push(result);
140
- } catch (error) {
141
- errors.push({
142
- entity: entity.tableName || 'unknown',
143
- error: error.message
144
- });
145
- }
146
- }
147
-
148
- return {
149
- results,
150
- errors,
151
- summary: {
152
- total: entities.length,
153
- successful: results.length,
154
- failed: errors.length
155
- }
156
- };
157
- }
158
-
159
- /**
160
- * Compile multiple subscribables
161
- * @param {Array} subscribables - Array of subscribable configurations
162
- * @returns {Object} Compilation results
163
- */
164
- compileAllSubscribables(subscribables) {
165
- const results = [];
166
- const errors = [];
167
-
168
- for (const subscribable of subscribables) {
169
- try {
170
- const result = this.compileSubscribable(subscribable);
171
- results.push(result);
172
- } catch (error) {
173
- errors.push({
174
- subscribable: subscribable.name || 'unknown',
175
- error: error.message
176
- });
177
- }
178
- }
179
-
180
- return {
181
- results,
182
- errors,
183
- summary: {
184
- total: subscribables.length,
185
- successful: results.length,
186
- failed: errors.length
187
- }
188
- };
189
- }
190
-
191
- /**
192
- * Compile from SQL file
193
- * @param {string} sqlContent - SQL file content
194
- * @returns {Object} Compilation results with dropSemantics
195
- */
196
- compileFromSQL(sqlContent) {
197
- // Use parseEntitiesFromSQL to properly extract custom functions
198
- const entities = parseEntitiesFromSQL(sqlContent);
199
-
200
- if (entities.length === 0) {
201
- return {
202
- results: [],
203
- errors: [],
204
- summary: { total: 0, successful: 0, failed: 0 },
205
- dropSemantics: { entities: {} }
206
- };
207
- }
208
-
209
- const compilationResult = this.compileAll(entities);
210
-
211
- // Generate drop semantics from all parsed entities
212
- const dropSemantics = generateDropSemantics(entities);
213
-
214
- return {
215
- ...compilationResult,
216
- dropSemantics
217
- };
218
- }
219
-
220
- /**
221
- * Compile subscribables from SQL file
222
- * @param {string} sqlContent - SQL file content
223
- * @returns {Object} Compilation results
224
- */
225
- compileSubscribablesFromSQL(sqlContent) {
226
- const subscribables = this.subscribableParser.parseAllFromSQL(sqlContent);
227
-
228
- if (subscribables.length === 0) {
229
- return {
230
- results: [],
231
- errors: [],
232
- summary: { total: 0, successful: 0, failed: 0 }
233
- };
234
- }
235
-
236
- return this.compileAllSubscribables(subscribables);
237
- }
238
-
239
- /**
240
- * Generate file header
241
- * @private
242
- */
243
- _generateHeader(entity) {
244
- return `-- ============================================================================
245
- -- DZQL Compiled Functions for: ${entity.tableName}
246
- -- Generated: ${new Date().toISOString()}
247
- --
248
- -- This file was automatically generated by the DZQL Compiler.
249
- -- Do not edit directly - regenerate from entity definition.
250
- -- ============================================================================`;
251
- }
252
-
253
- /**
254
- * Generate notification path resolution function
255
- * @private
256
- */
257
- _generateNotificationFunction(entity) {
258
- return generateNotificationFunction(
259
- entity.tableName,
260
- entity.notificationPaths
261
- );
262
- }
263
-
264
- /**
265
- * Generate graph rule functions
266
- * @private
267
- */
268
- _generateGraphRuleFunctions(entity) {
269
- return generateGraphRuleFunctions(
270
- entity.tableName,
271
- entity.graphRules,
272
- entity.primaryKey
273
- );
274
- }
275
-
276
- /**
277
- * Generate custom functions section (pass-through from entity definition)
278
- * @private
279
- */
280
- _generateCustomFunctionsSection(entity) {
281
- const header = `-- ============================================================================
282
- -- Custom Functions for: ${entity.tableName}
283
- -- Pass-through from entity definition
284
- -- ============================================================================`;
285
-
286
- return header + '\n\n' + entity.customFunctions.join('\n\n');
287
- }
288
-
289
- /**
290
- * Calculate SHA-256 checksum of SQL
291
- * @private
292
- */
293
- _calculateChecksum(sql) {
294
- return crypto.createHash('sha256').update(sql).digest('hex');
295
- }
296
-
297
- /**
298
- * Format SQL with proper indentation (basic)
299
- * @private
300
- */
301
- _formatSQL(sql) {
302
- // Basic formatting - could be enhanced
303
- return sql.trim();
304
- }
305
- }
306
-
307
- /**
308
- * Compile a single entity
309
- * @param {Object} entity - Entity configuration
310
- * @param {Object} options - Compiler options
311
- * @returns {Object} Compilation result
312
- */
313
- export function compile(entity, options = {}) {
314
- const compiler = new DZQLCompiler(options);
315
- return compiler.compile(entity);
316
- }
317
-
318
- /**
319
- * Compile multiple entities
320
- * @param {Array} entities - Array of entity configurations
321
- * @param {Object} options - Compiler options
322
- * @returns {Object} Compilation results
323
- */
324
- export function compileAll(entities, options = {}) {
325
- const compiler = new DZQLCompiler(options);
326
- return compiler.compileAll(entities);
327
- }
328
-
329
- /**
330
- * Compile from SQL file content
331
- * @param {string} sqlContent - SQL file content
332
- * @param {Object} options - Compiler options
333
- * @returns {Object} Compilation results
334
- */
335
- export function compileFromSQL(sqlContent, options = {}) {
336
- const compiler = new DZQLCompiler(options);
337
- return compiler.compileFromSQL(sqlContent);
338
- }
339
-
340
- /**
341
- * Compile a single subscribable
342
- * @param {Object} subscribable - Subscribable configuration
343
- * @param {Object} options - Compiler options
344
- * @returns {Object} Compilation result
345
- */
346
- export function compileSubscribable(subscribable, options = {}) {
347
- const compiler = new DZQLCompiler(options);
348
- return compiler.compileSubscribable(subscribable);
349
- }
350
-
351
- /**
352
- * Compile multiple subscribables
353
- * @param {Array} subscribables - Array of subscribable configurations
354
- * @param {Object} options - Compiler options
355
- * @returns {Object} Compilation results
356
- */
357
- export function compileAllSubscribables(subscribables, options = {}) {
358
- const compiler = new DZQLCompiler(options);
359
- return compiler.compileAllSubscribables(subscribables);
360
- }
361
-
362
- /**
363
- * Compile subscribables from SQL file content
364
- * @param {string} sqlContent - SQL file content
365
- * @param {Object} options - Compiler options
366
- * @returns {Object} Compilation results
367
- */
368
- export function compileSubscribablesFromSQL(sqlContent, options = {}) {
369
- const compiler = new DZQLCompiler(options);
370
- return compiler.compileSubscribablesFromSQL(sqlContent);
371
- }
@@ -1,11 +0,0 @@
1
- /**
2
- * DZQL Compiler
3
- * Transforms declarative entity definitions into optimized PostgreSQL stored procedures
4
- */
5
-
6
- export { DZQLCompiler, compile, compileAll, compileFromSQL } from './compiler.js';
7
- export { EntityParser, parseEntitiesFromSQL } from './parser/entity-parser.js';
8
- export { PathParser, parsePath, parsePaths } from './parser/path-parser.js';
9
- export { PermissionCodegen, generatePermissionFunctions } from './codegen/permission-codegen.js';
10
- export { OperationCodegen, generateOperations } from './codegen/operation-codegen.js';
11
- export { NotificationCodegen, generateNotificationFunction } from './codegen/notification-codegen.js';