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.
- package/.env.sample +28 -0
- package/compose.yml +28 -0
- package/dist/client/index.ts +1 -0
- package/dist/client/stores/useMyProfileStore.ts +114 -0
- package/dist/client/stores/useOrgDashboardStore.ts +131 -0
- package/dist/client/stores/useVenueDetailStore.ts +117 -0
- package/dist/client/ws.ts +716 -0
- package/dist/db/migrations/000_core.sql +92 -0
- package/dist/db/migrations/20251229T212912022Z_schema.sql +3020 -0
- package/dist/db/migrations/20251229T212912022Z_subscribables.sql +371 -0
- package/dist/runtime/manifest.json +1562 -0
- package/docs/README.md +309 -36
- package/docs/feature-requests/applyPatch-bug-report.md +85 -0
- package/docs/feature-requests/connection-ready-profile.md +57 -0
- package/docs/feature-requests/hidden-bug-report.md +111 -0
- package/docs/feature-requests/hidden-fields-subscribables.md +34 -0
- package/docs/feature-requests/subscribable-param-key-bug.md +38 -0
- package/docs/feature-requests/todo.md +146 -0
- package/docs/for_ai.md +653 -0
- package/docs/project-setup.md +456 -0
- package/examples/blog.ts +50 -0
- package/examples/invalid.ts +18 -0
- package/examples/venues.js +485 -0
- package/package.json +23 -60
- package/src/cli/codegen/client.ts +99 -0
- package/src/cli/codegen/manifest.ts +95 -0
- package/src/cli/codegen/pinia.ts +174 -0
- package/src/cli/codegen/realtime.ts +58 -0
- package/src/cli/codegen/sql.ts +698 -0
- package/src/cli/codegen/subscribable_sql.ts +547 -0
- package/src/cli/codegen/subscribable_store.ts +184 -0
- package/src/cli/codegen/types.ts +142 -0
- package/src/cli/compiler/analyzer.ts +52 -0
- package/src/cli/compiler/graph_rules.ts +251 -0
- package/src/cli/compiler/ir.ts +233 -0
- package/src/cli/compiler/loader.ts +132 -0
- package/src/cli/compiler/permissions.ts +227 -0
- package/src/cli/index.ts +166 -0
- package/src/client/index.ts +1 -0
- package/src/client/ws.ts +286 -0
- package/src/runtime/auth.ts +39 -0
- package/src/runtime/db.ts +33 -0
- package/src/runtime/errors.ts +51 -0
- package/src/runtime/index.ts +98 -0
- package/src/runtime/js_functions.ts +63 -0
- package/src/runtime/manifest_loader.ts +29 -0
- package/src/runtime/namespace.ts +483 -0
- package/src/runtime/server.ts +87 -0
- package/src/runtime/ws.ts +197 -0
- package/src/shared/ir.ts +197 -0
- package/tests/client.test.ts +38 -0
- package/tests/codegen.test.ts +71 -0
- package/tests/compiler.test.ts +45 -0
- package/tests/graph_rules.test.ts +173 -0
- package/tests/integration/db.test.ts +174 -0
- package/tests/integration/e2e.test.ts +65 -0
- package/tests/integration/features.test.ts +922 -0
- package/tests/integration/full_stack.test.ts +262 -0
- package/tests/integration/setup.ts +45 -0
- package/tests/ir.test.ts +32 -0
- package/tests/namespace.test.ts +395 -0
- package/tests/permissions.test.ts +55 -0
- package/tests/pinia.test.ts +48 -0
- package/tests/realtime.test.ts +22 -0
- package/tests/runtime.test.ts +80 -0
- package/tests/subscribable_gen.test.ts +72 -0
- package/tests/subscribable_reactivity.test.ts +258 -0
- package/tests/venues_gen.test.ts +25 -0
- package/tsconfig.json +20 -0
- package/tsconfig.tsbuildinfo +1 -0
- package/README.md +0 -90
- package/bin/cli.js +0 -727
- package/docs/compiler/ADVANCED_FILTERS.md +0 -183
- package/docs/compiler/CODING_STANDARDS.md +0 -415
- package/docs/compiler/COMPARISON.md +0 -673
- package/docs/compiler/QUICKSTART.md +0 -326
- package/docs/compiler/README.md +0 -134
- package/docs/examples/README.md +0 -38
- package/docs/examples/blog.sql +0 -160
- package/docs/examples/venue-detail-simple.sql +0 -8
- package/docs/examples/venue-detail-subscribable.sql +0 -45
- package/docs/for-ai/claude-guide.md +0 -1210
- package/docs/getting-started/quickstart.md +0 -125
- package/docs/getting-started/subscriptions-quick-start.md +0 -203
- package/docs/getting-started/tutorial.md +0 -1104
- package/docs/guides/atomic-updates.md +0 -299
- package/docs/guides/client-stores.md +0 -730
- package/docs/guides/composite-primary-keys.md +0 -158
- package/docs/guides/custom-functions.md +0 -362
- package/docs/guides/drop-semantics.md +0 -554
- package/docs/guides/field-defaults.md +0 -240
- package/docs/guides/interpreter-vs-compiler.md +0 -237
- package/docs/guides/many-to-many.md +0 -929
- package/docs/guides/subscriptions.md +0 -537
- package/docs/reference/api.md +0 -1373
- package/docs/reference/client.md +0 -224
- package/src/client/stores/index.js +0 -8
- package/src/client/stores/useAppStore.js +0 -285
- package/src/client/stores/useWsStore.js +0 -289
- package/src/client/ws.js +0 -762
- package/src/compiler/cli/compile-example.js +0 -33
- package/src/compiler/cli/compile-subscribable.js +0 -43
- package/src/compiler/cli/debug-compile.js +0 -44
- package/src/compiler/cli/debug-parse.js +0 -26
- package/src/compiler/cli/debug-path-parser.js +0 -18
- package/src/compiler/cli/debug-subscribable-parser.js +0 -21
- package/src/compiler/cli/index.js +0 -174
- package/src/compiler/codegen/auth-codegen.js +0 -153
- package/src/compiler/codegen/drop-semantics-codegen.js +0 -553
- package/src/compiler/codegen/graph-rules-codegen.js +0 -450
- package/src/compiler/codegen/notification-codegen.js +0 -232
- package/src/compiler/codegen/operation-codegen.js +0 -1382
- package/src/compiler/codegen/permission-codegen.js +0 -318
- package/src/compiler/codegen/subscribable-codegen.js +0 -827
- package/src/compiler/compiler.js +0 -371
- package/src/compiler/index.js +0 -11
- package/src/compiler/parser/entity-parser.js +0 -440
- package/src/compiler/parser/path-parser.js +0 -290
- package/src/compiler/parser/subscribable-parser.js +0 -244
- package/src/database/dzql-core.sql +0 -161
- package/src/database/migrations/001_schema.sql +0 -60
- package/src/database/migrations/002_functions.sql +0 -890
- package/src/database/migrations/003_operations.sql +0 -1135
- package/src/database/migrations/004_search.sql +0 -581
- package/src/database/migrations/005_entities.sql +0 -730
- package/src/database/migrations/006_auth.sql +0 -94
- package/src/database/migrations/007_events.sql +0 -133
- package/src/database/migrations/008_hello.sql +0 -18
- package/src/database/migrations/008a_meta.sql +0 -172
- package/src/database/migrations/009_subscriptions.sql +0 -240
- package/src/database/migrations/010_atomic_updates.sql +0 -157
- package/src/database/migrations/010_fix_m2m_events.sql +0 -94
- package/src/index.js +0 -40
- package/src/server/api.js +0 -9
- package/src/server/db.js +0 -442
- package/src/server/index.js +0 -317
- package/src/server/logger.js +0 -259
- package/src/server/mcp.js +0 -594
- package/src/server/meta-route.js +0 -251
- package/src/server/namespace.js +0 -292
- package/src/server/subscriptions.js +0 -351
- package/src/server/ws.js +0 -573
|
@@ -1,289 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Canonical DZQL WebSocket Pinia Store
|
|
3
|
-
*
|
|
4
|
-
* Manages WebSocket connection with three-phase lifecycle:
|
|
5
|
-
* 1. CONNECTING - Initial connection to server
|
|
6
|
-
* 2. AUTHENTICATING - After connection, waiting for profile (login if needed)
|
|
7
|
-
* 3. READY - Connected and authenticated, ready for use
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
* // In your app
|
|
11
|
-
* import { useWsStore } from 'dzql/client/stores'
|
|
12
|
-
*
|
|
13
|
-
* const wsStore = useWsStore()
|
|
14
|
-
* await wsStore.connect() // or connect with custom URL
|
|
15
|
-
*
|
|
16
|
-
* // Access profile
|
|
17
|
-
* console.log(wsStore.profile) // null if not authenticated
|
|
18
|
-
*
|
|
19
|
-
* // Login
|
|
20
|
-
* await wsStore.login({ email: 'user@example.com', password: 'pass' })
|
|
21
|
-
*
|
|
22
|
-
* // Logout
|
|
23
|
-
* await wsStore.logout()
|
|
24
|
-
*/
|
|
25
|
-
import { defineStore } from 'pinia'
|
|
26
|
-
import { ref, computed } from 'vue'
|
|
27
|
-
import { WebSocketManager } from '../ws.js'
|
|
28
|
-
|
|
29
|
-
export const useWsStore = defineStore('dzql-ws', () => {
|
|
30
|
-
// ===== State =====
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Connection state: 'disconnected' | 'connecting' | 'connected' | 'error'
|
|
34
|
-
*/
|
|
35
|
-
const connectionState = ref('disconnected')
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* App state: 'connecting' | 'login' | 'ready'
|
|
39
|
-
* - connecting: Initial connection phase
|
|
40
|
-
* - login: Connected but needs authentication
|
|
41
|
-
* - ready: Connected and authenticated
|
|
42
|
-
*/
|
|
43
|
-
const appState = ref('connecting')
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* User profile (null if not authenticated)
|
|
47
|
-
*/
|
|
48
|
-
const profile = ref(null)
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Last error message
|
|
52
|
-
*/
|
|
53
|
-
const error = ref(null)
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* WebSocket manager instance
|
|
57
|
-
*/
|
|
58
|
-
const ws = new WebSocketManager()
|
|
59
|
-
|
|
60
|
-
// ===== Computed =====
|
|
61
|
-
|
|
62
|
-
const isConnected = computed(() => connectionState.value === 'connected')
|
|
63
|
-
const isAuthenticated = computed(() => profile.value !== null)
|
|
64
|
-
const isReady = computed(() => appState.value === 'ready')
|
|
65
|
-
const needsLogin = computed(() => appState.value === 'login')
|
|
66
|
-
const isConnecting = computed(() => appState.value === 'connecting')
|
|
67
|
-
|
|
68
|
-
// ===== Actions =====
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* Connect to WebSocket server
|
|
72
|
-
*
|
|
73
|
-
* @param {string|null} url - WebSocket URL (auto-detected if null)
|
|
74
|
-
* @param {number} timeout - Connection timeout in ms
|
|
75
|
-
* @returns {Promise<void>}
|
|
76
|
-
*
|
|
77
|
-
* @example
|
|
78
|
-
* // Auto-detect URL
|
|
79
|
-
* await wsStore.connect()
|
|
80
|
-
*
|
|
81
|
-
* @example
|
|
82
|
-
* // Custom URL for development
|
|
83
|
-
* await wsStore.connect('ws://localhost:3000/ws')
|
|
84
|
-
*/
|
|
85
|
-
async function connect(url = null, timeout = 5000) {
|
|
86
|
-
try {
|
|
87
|
-
appState.value = 'connecting'
|
|
88
|
-
connectionState.value = 'connecting'
|
|
89
|
-
error.value = null
|
|
90
|
-
|
|
91
|
-
// Set up broadcast listener for connection events BEFORE connecting
|
|
92
|
-
ws.onBroadcast((method, params) => {
|
|
93
|
-
if (method === 'connected') {
|
|
94
|
-
connectionState.value = 'connected'
|
|
95
|
-
profile.value = params.profile || null
|
|
96
|
-
|
|
97
|
-
// Determine app state based on profile
|
|
98
|
-
if (params.profile) {
|
|
99
|
-
appState.value = 'ready'
|
|
100
|
-
} else {
|
|
101
|
-
appState.value = 'login'
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
console.log('[WsStore] Connected:', {
|
|
105
|
-
profile: params.profile,
|
|
106
|
-
appState: appState.value
|
|
107
|
-
})
|
|
108
|
-
}
|
|
109
|
-
})
|
|
110
|
-
|
|
111
|
-
// Connect to WebSocket
|
|
112
|
-
await ws.connect(url, timeout)
|
|
113
|
-
|
|
114
|
-
// Note: appState will be updated when 'connected' broadcast arrives
|
|
115
|
-
|
|
116
|
-
} catch (err) {
|
|
117
|
-
console.error('[WsStore] Connection failed:', err)
|
|
118
|
-
connectionState.value = 'error'
|
|
119
|
-
error.value = err.message
|
|
120
|
-
throw err
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
* Login with email and password
|
|
126
|
-
*
|
|
127
|
-
* @param {Object} credentials
|
|
128
|
-
* @param {string} credentials.email
|
|
129
|
-
* @param {string} credentials.password
|
|
130
|
-
* @returns {Promise<Object>} Login result with token and profile
|
|
131
|
-
*
|
|
132
|
-
* @example
|
|
133
|
-
* const result = await wsStore.login({
|
|
134
|
-
* email: 'user@example.com',
|
|
135
|
-
* password: 'password123'
|
|
136
|
-
* })
|
|
137
|
-
*/
|
|
138
|
-
async function login({ email, password }) {
|
|
139
|
-
try {
|
|
140
|
-
error.value = null
|
|
141
|
-
|
|
142
|
-
const result = await ws.call('login_user', { email, password })
|
|
143
|
-
|
|
144
|
-
if (result.token) {
|
|
145
|
-
// Store token in localStorage
|
|
146
|
-
if (typeof localStorage !== 'undefined') {
|
|
147
|
-
localStorage.setItem('dzql_token', result.token)
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
// Update profile
|
|
151
|
-
profile.value = result.profile
|
|
152
|
-
appState.value = 'ready'
|
|
153
|
-
|
|
154
|
-
console.log('[WsStore] Login successful:', result.profile)
|
|
155
|
-
|
|
156
|
-
return result
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
throw new Error('No token received')
|
|
160
|
-
|
|
161
|
-
} catch (err) {
|
|
162
|
-
console.error('[WsStore] Login failed:', err)
|
|
163
|
-
error.value = err.message
|
|
164
|
-
throw err
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
/**
|
|
169
|
-
* Register a new user
|
|
170
|
-
*
|
|
171
|
-
* @param {Object} credentials
|
|
172
|
-
* @param {string} credentials.email
|
|
173
|
-
* @param {string} credentials.password
|
|
174
|
-
* @returns {Promise<Object>} Registration result with token and profile
|
|
175
|
-
*
|
|
176
|
-
* @example
|
|
177
|
-
* const result = await wsStore.register({
|
|
178
|
-
* email: 'newuser@example.com',
|
|
179
|
-
* password: 'securepass123'
|
|
180
|
-
* })
|
|
181
|
-
*/
|
|
182
|
-
async function register({ email, password }) {
|
|
183
|
-
try {
|
|
184
|
-
error.value = null
|
|
185
|
-
|
|
186
|
-
const result = await ws.call('register_user', { email, password })
|
|
187
|
-
|
|
188
|
-
if (result.token) {
|
|
189
|
-
// Store token in localStorage
|
|
190
|
-
if (typeof localStorage !== 'undefined') {
|
|
191
|
-
localStorage.setItem('dzql_token', result.token)
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
// Update profile
|
|
195
|
-
profile.value = result.profile
|
|
196
|
-
appState.value = 'ready'
|
|
197
|
-
|
|
198
|
-
console.log('[WsStore] Registration successful:', result.profile)
|
|
199
|
-
|
|
200
|
-
return result
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
throw new Error('No token received')
|
|
204
|
-
|
|
205
|
-
} catch (err) {
|
|
206
|
-
console.error('[WsStore] Registration failed:', err)
|
|
207
|
-
error.value = err.message
|
|
208
|
-
throw err
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
/**
|
|
213
|
-
* Logout and clear session
|
|
214
|
-
*
|
|
215
|
-
* @returns {Promise<void>}
|
|
216
|
-
*
|
|
217
|
-
* @example
|
|
218
|
-
* await wsStore.logout()
|
|
219
|
-
*/
|
|
220
|
-
async function logout() {
|
|
221
|
-
try {
|
|
222
|
-
// Call server logout
|
|
223
|
-
await ws.call('logout')
|
|
224
|
-
} catch (err) {
|
|
225
|
-
console.warn('[WsStore] Server logout failed:', err)
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
// Clear local state
|
|
229
|
-
if (typeof localStorage !== 'undefined') {
|
|
230
|
-
localStorage.removeItem('dzql_token')
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
profile.value = null
|
|
234
|
-
appState.value = 'login'
|
|
235
|
-
|
|
236
|
-
// Reconnect to get fresh state
|
|
237
|
-
await connect()
|
|
238
|
-
|
|
239
|
-
console.log('[WsStore] Logged out')
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
/**
|
|
243
|
-
* Disconnect from WebSocket
|
|
244
|
-
*/
|
|
245
|
-
function disconnect() {
|
|
246
|
-
ws.disconnect()
|
|
247
|
-
connectionState.value = 'disconnected'
|
|
248
|
-
appState.value = 'connecting'
|
|
249
|
-
console.log('[WsStore] Disconnected')
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
/**
|
|
253
|
-
* Get the WebSocket manager instance for direct API calls
|
|
254
|
-
*
|
|
255
|
-
* @returns {WebSocketManager}
|
|
256
|
-
*
|
|
257
|
-
* @example
|
|
258
|
-
* const ws = wsStore.getWs()
|
|
259
|
-
* const venue = await ws.api.get.venues({ id: 1 })
|
|
260
|
-
*/
|
|
261
|
-
function getWs() {
|
|
262
|
-
return ws
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
// ===== Return Public API =====
|
|
266
|
-
|
|
267
|
-
return {
|
|
268
|
-
// State
|
|
269
|
-
connectionState,
|
|
270
|
-
appState,
|
|
271
|
-
profile,
|
|
272
|
-
error,
|
|
273
|
-
|
|
274
|
-
// Computed
|
|
275
|
-
isConnected,
|
|
276
|
-
isAuthenticated,
|
|
277
|
-
isReady,
|
|
278
|
-
needsLogin,
|
|
279
|
-
isConnecting,
|
|
280
|
-
|
|
281
|
-
// Actions
|
|
282
|
-
connect,
|
|
283
|
-
login,
|
|
284
|
-
register,
|
|
285
|
-
logout,
|
|
286
|
-
disconnect,
|
|
287
|
-
getWs
|
|
288
|
-
}
|
|
289
|
-
})
|