dzql 0.6.3 → 0.6.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.
Files changed (41) hide show
  1. package/README.md +33 -0
  2. package/docs/for_ai.md +14 -18
  3. package/docs/project-setup.md +15 -14
  4. package/package.json +28 -6
  5. package/src/cli/codegen/client.ts +5 -6
  6. package/src/cli/codegen/subscribable_store.ts +5 -5
  7. package/src/runtime/ws.ts +16 -15
  8. package/.env.sample +0 -28
  9. package/compose.yml +0 -28
  10. package/dist/client/index.ts +0 -1
  11. package/dist/client/stores/useMyProfileStore.ts +0 -114
  12. package/dist/client/stores/useOrgDashboardStore.ts +0 -131
  13. package/dist/client/stores/useVenueDetailStore.ts +0 -117
  14. package/dist/client/ws.ts +0 -716
  15. package/dist/db/migrations/000_core.sql +0 -92
  16. package/dist/db/migrations/20260101T235039268Z_schema.sql +0 -3020
  17. package/dist/db/migrations/20260101T235039268Z_subscribables.sql +0 -371
  18. package/dist/runtime/manifest.json +0 -1562
  19. package/examples/blog.ts +0 -50
  20. package/examples/invalid.ts +0 -18
  21. package/examples/venues.js +0 -485
  22. package/tests/client.test.ts +0 -38
  23. package/tests/codegen.test.ts +0 -71
  24. package/tests/compiler.test.ts +0 -45
  25. package/tests/graph_rules.test.ts +0 -173
  26. package/tests/integration/db.test.ts +0 -174
  27. package/tests/integration/e2e.test.ts +0 -65
  28. package/tests/integration/features.test.ts +0 -922
  29. package/tests/integration/full_stack.test.ts +0 -262
  30. package/tests/integration/setup.ts +0 -45
  31. package/tests/ir.test.ts +0 -32
  32. package/tests/namespace.test.ts +0 -395
  33. package/tests/permissions.test.ts +0 -55
  34. package/tests/pinia.test.ts +0 -48
  35. package/tests/realtime.test.ts +0 -22
  36. package/tests/runtime.test.ts +0 -80
  37. package/tests/subscribable_gen.test.ts +0 -72
  38. package/tests/subscribable_reactivity.test.ts +0 -258
  39. package/tests/venues_gen.test.ts +0 -25
  40. package/tsconfig.json +0 -20
  41. package/tsconfig.tsbuildinfo +0 -1
@@ -1,258 +0,0 @@
1
- import { describe, test, expect, beforeEach } from "bun:test";
2
- import { ref, isRef, isReactive, nextTick, watch } from "vue";
3
- import { createPinia, setActivePinia, defineStore } from "pinia";
4
- import { generateSubscribableStore } from "../src/cli/codegen/subscribable_store.js";
5
- import { generateManifest } from "../src/cli/codegen/manifest.js";
6
- import { generateIR } from "../src/cli/compiler/ir.js";
7
- import { entities, subscribables } from "../examples/venues.js";
8
-
9
- // Mock WebSocket manager
10
- const mockWs = {
11
- api: {
12
- subscribe_venue_detail: (params: any, callback: (data: any) => void) => {
13
- // Simulate async subscription response
14
- setTimeout(() => {
15
- callback({
16
- id: 1,
17
- name: "Test Venue",
18
- sites: [
19
- { id: 1, name: "Site A", allocations: [] },
20
- { id: 2, name: "Site B", allocations: [] }
21
- ]
22
- });
23
- }, 10);
24
- }
25
- },
26
- registerStore: (listener: (event: any) => void) => {
27
- // Store the listener so tests can dispatch events
28
- mockWs._storeListener = listener;
29
- return () => {};
30
- },
31
- _storeListener: null as ((event: any) => void) | null,
32
- dispatchEvent: (event: any) => {
33
- if (mockWs._storeListener) {
34
- mockWs._storeListener(event);
35
- }
36
- }
37
- };
38
-
39
- describe("Subscribable Store Reactivity", () => {
40
- beforeEach(() => {
41
- setActivePinia(createPinia());
42
- mockWs._storeListener = null;
43
- });
44
-
45
- test("generated store code structure is correct", () => {
46
- const ir = generateIR({ entities, subscribables });
47
- const manifest = generateManifest(ir);
48
- const code = generateSubscribableStore(manifest, "venue_detail");
49
-
50
- // Should use typed ref for documents
51
- expect(code).toContain("const documents: Ref<Record<string, DocumentWrapper<Record<string, unknown>>>> = ref({});");
52
-
53
- // Should add plain object with empty data object to documents.value (preserves reactivity)
54
- expect(code).toContain("documents.value[key] = { data: {}, loading: true, ready };");
55
-
56
- // Should merge initial data into existing object via Object.assign (preserves reactivity)
57
- expect(code).toContain("Object.assign(documents.value[key].data, eventData");
58
- expect(code).toContain("documents.value[key].loading = false;");
59
-
60
- // Should have typed unbind function
61
- expect(code).toContain("function unbind(params: VenueDetailParams)");
62
-
63
- // Should NOT pre-wrap in ref()
64
- expect(code).not.toContain("const docState = ref(");
65
- expect(code).not.toContain("const loading = ref(");
66
- });
67
-
68
- test("documents.value entries become reactive when added as plain objects", async () => {
69
- // Simulate what the generated store does
70
- const documents = ref<Record<string, any>>({});
71
-
72
- // Add a plain object - Vue should make it reactive
73
- documents.value["test-key"] = { data: null, loading: true };
74
-
75
- // The entry should be reactive
76
- expect(isReactive(documents.value["test-key"])).toBe(true);
77
-
78
- // Assign data
79
- documents.value["test-key"].data = { id: 1, name: "Test" };
80
- documents.value["test-key"].loading = false;
81
-
82
- // Data should also be reactive
83
- expect(isReactive(documents.value["test-key"].data)).toBe(true);
84
- });
85
-
86
- test("mutations to document data trigger reactivity", async () => {
87
- const documents = ref<Record<string, any>>({});
88
-
89
- // Setup
90
- documents.value["key1"] = {
91
- data: { id: 1, name: "Original", items: [{ id: 1, value: "a" }] },
92
- loading: false
93
- };
94
-
95
- let changeCount = 0;
96
-
97
- // Watch for changes
98
- watch(
99
- () => documents.value["key1"]?.data?.name,
100
- () => { changeCount++; },
101
- { flush: 'sync' }
102
- );
103
-
104
- // Mutate via Object.assign (like applyPatch does)
105
- Object.assign(documents.value["key1"].data, { name: "Updated" });
106
-
107
- expect(changeCount).toBe(1);
108
- expect(documents.value["key1"].data.name).toBe("Updated");
109
- });
110
-
111
- test("array mutations trigger reactivity", async () => {
112
- const documents = ref<Record<string, any>>({});
113
-
114
- documents.value["key1"] = {
115
- data: {
116
- id: 1,
117
- sites: [
118
- { id: 1, name: "Site A" },
119
- { id: 2, name: "Site B" }
120
- ]
121
- },
122
- loading: false
123
- };
124
-
125
- let changeCount = 0;
126
-
127
- watch(
128
- () => documents.value["key1"]?.data?.sites?.length,
129
- () => { changeCount++; },
130
- { flush: 'sync' }
131
- );
132
-
133
- // Insert (push)
134
- documents.value["key1"].data.sites.push({ id: 3, name: "Site C" });
135
- expect(changeCount).toBe(1);
136
- expect(documents.value["key1"].data.sites.length).toBe(3);
137
-
138
- // Delete (splice)
139
- documents.value["key1"].data.sites.splice(0, 1);
140
- expect(changeCount).toBe(2);
141
- expect(documents.value["key1"].data.sites.length).toBe(2);
142
- });
143
-
144
- test("Object.assign on array items triggers reactivity", async () => {
145
- const documents = ref<Record<string, any>>({});
146
-
147
- documents.value["key1"] = {
148
- data: {
149
- sites: [{ id: 1, name: "Original" }]
150
- },
151
- loading: false
152
- };
153
-
154
- let changeCount = 0;
155
-
156
- watch(
157
- () => documents.value["key1"]?.data?.sites?.[0]?.name,
158
- () => { changeCount++; },
159
- { flush: 'sync' }
160
- );
161
-
162
- // Update via Object.assign (like handleArrayPatch does)
163
- Object.assign(documents.value["key1"].data.sites[0], { name: "Updated" });
164
-
165
- expect(changeCount).toBe(1);
166
- expect(documents.value["key1"].data.sites[0].name).toBe("Updated");
167
- });
168
-
169
- test("applyPatch simulation works with reactivity", async () => {
170
- const documents = ref<Record<string, any>>({});
171
-
172
- // Simulate bind() adding the document
173
- documents.value["venue-1"] = {
174
- data: {
175
- id: 1,
176
- name: "Test Venue",
177
- sites: [
178
- { id: 1, name: "Site A", allocations: [] }
179
- ]
180
- },
181
- loading: false
182
- };
183
-
184
- // Simulate applyPatch for root entity update
185
- function applyPatch(doc: any, event: any) {
186
- if (!doc) return;
187
- switch (event.table) {
188
- case 'venues':
189
- if (event.op === 'update') Object.assign(doc, event.data);
190
- break;
191
- case 'sites':
192
- handleArrayPatch(doc.sites, event);
193
- break;
194
- }
195
- }
196
-
197
- function handleArrayPatch(arr: any[], event: any) {
198
- if (!arr) return;
199
- const pkValue = event.pk?.id;
200
- const idx = arr.findIndex(i => i.id === pkValue);
201
- if (event.op === 'insert') {
202
- if (idx === -1) arr.push(event.data);
203
- } else if (event.op === 'update') {
204
- if (idx !== -1) Object.assign(arr[idx], event.data);
205
- } else if (event.op === 'delete') {
206
- if (idx !== -1) arr.splice(idx, 1);
207
- }
208
- }
209
-
210
- let venueNameChanges = 0;
211
- let sitesLengthChanges = 0;
212
-
213
- watch(
214
- () => documents.value["venue-1"]?.data?.name,
215
- () => { venueNameChanges++; },
216
- { flush: 'sync' }
217
- );
218
-
219
- watch(
220
- () => documents.value["venue-1"]?.data?.sites?.length,
221
- () => { sitesLengthChanges++; },
222
- { flush: 'sync' }
223
- );
224
-
225
- // Test root entity update
226
- applyPatch(documents.value["venue-1"].data, {
227
- table: 'venues',
228
- op: 'update',
229
- data: { name: "Updated Venue" },
230
- pk: { id: 1 }
231
- });
232
-
233
- expect(venueNameChanges).toBe(1);
234
- expect(documents.value["venue-1"].data.name).toBe("Updated Venue");
235
-
236
- // Test insert into nested array
237
- applyPatch(documents.value["venue-1"].data, {
238
- table: 'sites',
239
- op: 'insert',
240
- data: { id: 2, name: "Site B", allocations: [] },
241
- pk: { id: 2 }
242
- });
243
-
244
- expect(sitesLengthChanges).toBe(1);
245
- expect(documents.value["venue-1"].data.sites.length).toBe(2);
246
-
247
- // Test delete from nested array
248
- applyPatch(documents.value["venue-1"].data, {
249
- table: 'sites',
250
- op: 'delete',
251
- data: { id: 1 },
252
- pk: { id: 1 }
253
- });
254
-
255
- expect(sitesLengthChanges).toBe(2);
256
- expect(documents.value["venue-1"].data.sites.length).toBe(1);
257
- });
258
- });
@@ -1,25 +0,0 @@
1
- import { describe, test, expect } from "bun:test";
2
- import { generatePiniaStore } from "../src/cli/codegen/pinia.js";
3
- import { generateManifest } from "../src/cli/codegen/manifest.js";
4
- import { generateIR } from "../src/cli/compiler/ir.js";
5
- import { entities, subscribables } from "../examples/venues.js";
6
-
7
- const venuesDomain = { entities, subscribables };
8
-
9
- describe("Venues Store Generation", () => {
10
- test("should generate venues store", () => {
11
- const ir = generateIR(venuesDomain);
12
- const manifest = generateManifest(ir);
13
-
14
- // Generate the store for the 'venues' entity
15
- const code = generatePiniaStore(manifest, "venues");
16
-
17
- console.log("--- GENERATED VENUES STORE ---");
18
- console.log(code);
19
- console.log("------------------------------");
20
-
21
- expect(code).toContain("useVenuesStore");
22
- expect(code).toContain("ws.api.save_venues");
23
- expect(code).toContain("table_changed");
24
- });
25
- });
package/tsconfig.json DELETED
@@ -1,20 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "lib": ["ESNext"],
4
- "module": "esnext",
5
- "target": "esnext",
6
- "moduleResolution": "bundler",
7
- "moduleDetection": "force",
8
- "allowImportingTsExtensions": true,
9
- "noEmit": true,
10
- "composite": true,
11
- "strict": true,
12
- "downlevelIteration": true,
13
- "skipLibCheck": true,
14
- "jsx": "preserve",
15
- "allowSyntheticDefaultImports": true,
16
- "forceConsistentCasingInFileNames": true,
17
- "allowJs": true,
18
- "types": ["bun-types"]
19
- }
20
- }