@medyll/idae-machine 0.128.0 → 0.135.2
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/LICENSE +21 -21
- package/README.md +360 -393
- package/cli.js +46 -0
- package/dist/demo/dbSchema.d.ts +446 -0
- package/dist/demo/dbSchema.js +449 -0
- package/dist/demo/testScheme.d.ts +56 -0
- package/dist/demo/testScheme.js +42 -0
- package/dist/form/CreateUpdate.svelte +219 -0
- package/dist/{demo/form → form}/CreateUpdate.svelte.d.ts +5 -7
- package/dist/form/DataProvider.svelte +23 -0
- package/dist/form/DataProvider.svelte.d.ts +7 -0
- package/dist/form/FieldInPlace.svelte +98 -0
- package/dist/form/FieldInPlace.svelte.d.ts +14 -0
- package/dist/form/FieldValue.svelte +148 -0
- package/dist/{demo/form → form}/FieldValue.svelte.d.ts +8 -9
- package/dist/fragments/Confirm.svelte +73 -58
- package/dist/fragments/Confirm.svelte.d.ts +4 -8
- package/dist/fragments/Frame.svelte +19 -19
- package/dist/fragments/InfoLine.svelte +21 -21
- package/dist/fragments/Selector.svelte +26 -26
- package/dist/fragments/Skeleton.svelte +21 -21
- package/dist/index.d.ts +20 -28
- package/dist/index.js +20 -28
- package/dist/main/machine/MachineError.d.ts +33 -0
- package/dist/main/machine/MachineError.js +49 -0
- package/dist/main/machine/MachineErrorValidation.d.ts +19 -0
- package/dist/main/machine/MachineErrorValidation.js +24 -0
- package/dist/main/machine/MachineFieldType.d.ts +121 -0
- package/dist/main/machine/MachineFieldType.js +250 -0
- package/dist/main/machine/MachineScheme.d.ts +84 -0
- package/dist/main/machine/MachineScheme.js +146 -0
- package/dist/main/machine/MachineSchemeField.d.ts +19 -0
- package/dist/main/machine/MachineSchemeField.js +51 -0
- package/dist/main/machine/MachineSchemeFieldForge.d.ts +84 -0
- package/dist/main/machine/MachineSchemeFieldForge.js +128 -0
- package/dist/main/machine/MachineSchemeFieldValues.d.ts +69 -0
- package/dist/main/machine/MachineSchemeFieldValues.js +94 -0
- package/dist/main/machine/MachineSchemeValidate.d.ts +51 -0
- package/dist/main/machine/MachineSchemeValidate.js +120 -0
- package/dist/main/machine/MachineSchemeValues.d.ts +109 -0
- package/dist/main/machine/{IDbCollectionValues.js → MachineSchemeValues.js} +116 -41
- package/dist/main/machine/SchemeFieldDefaultValues.d.ts +74 -0
- package/dist/main/machine/SchemeFieldDefaultValues.js +98 -0
- package/dist/main/machine.d.ts +71 -44
- package/dist/main/machine.js +74 -43
- package/dist/main/machineDb.d.ts +14 -56
- package/dist/main/machineDb.js +15 -98
- package/dist/main/{machineForge.d.ts → machineParserForge.d.ts} +15 -25
- package/dist/main/{machineForge.js → machineParserForge.js} +16 -10
- package/dist/ui/CollectionButton.svelte +29 -26
- package/dist/ui/CollectionButton.svelte.d.ts +3 -3
- package/dist/ui/CollectionFks.svelte +24 -24
- package/dist/ui/CollectionFks.svelte.d.ts +2 -2
- package/dist/ui/CollectionList.svelte +100 -95
- package/dist/ui/CollectionList.svelte.d.ts +1 -2
- package/dist/ui/CollectionListFieldValues.svelte +59 -0
- package/dist/ui/CollectionListFieldValues.svelte.d.ts +9 -0
- package/dist/ui/CollectionListMenu.svelte +39 -47
- package/dist/ui/CollectionListMenu.svelte.d.ts +1 -1
- package/dist/ui/CollectionReverseFks.svelte +37 -56
- package/dist/ui/CollectionReverseFks.svelte.d.ts +4 -8
- package/package.json +18 -5
- package/dist/db/dbSchema.d.ts +0 -201
- package/dist/db/dbSchema.js +0 -205
- package/dist/db/fieldTypes.d.ts +0 -13
- package/dist/db/fieldTypes.js +0 -67
- package/dist/db/types.d.ts +0 -124
- package/dist/demo/form/CreateUpdate.svelte +0 -198
- package/dist/demo/form/CrudZone.svelte +0 -22
- package/dist/demo/form/CrudZone.svelte.d.ts +0 -29
- package/dist/demo/form/DataProvider.svelte +0 -20
- package/dist/demo/form/DataProvider.svelte.d.ts +0 -9
- package/dist/demo/form/FieldInPlace.svelte +0 -49
- package/dist/demo/form/FieldInPlace.svelte.d.ts +0 -11
- package/dist/demo/form/FieldValue.svelte +0 -212
- package/dist/demo/form/types.js +0 -1
- package/dist/demo/testDbSchema.d.ts +0 -6
- package/dist/demo/testDbSchema.js +0 -58
- package/dist/demo/types.d.ts +0 -140
- package/dist/demo/types.js +0 -1
- package/dist/fragments/List.svelte +0 -21
- package/dist/fragments/List.svelte.d.ts +0 -38
- package/dist/main/machine/IDbCollection.d.ts +0 -71
- package/dist/main/machine/IDbCollection.js +0 -102
- package/dist/main/machine/IDbCollectionFieldForge.d.ts +0 -42
- package/dist/main/machine/IDbCollectionFieldForge.js +0 -74
- package/dist/main/machine/IDbCollectionFieldValues.d.ts +0 -57
- package/dist/main/machine/IDbCollectionFieldValues.js +0 -82
- package/dist/main/machine/IDbCollectionValues.d.ts +0 -78
- package/dist/main/machine/IDbError.d.ts +0 -6
- package/dist/main/machine/IDbError.js +0 -61
- package/dist/main/machine/IDbFormValidate.d.ts +0 -55
- package/dist/main/machine/IDbFormValidate.js +0 -183
- package/dist/main/machine/IDbValidationError.d.ts +0 -19
- package/dist/main/machine/IDbValidationError.js +0 -24
- package/dist/main/machine/types.d.ts +0 -1
- package/dist/main/machine/types.js +0 -1
- package/dist/ui/CollectionFieldGuess.svelte +0 -29
- package/dist/ui/CollectionFieldGuess.svelte.d.ts +0 -11
- /package/dist/{demo/form → form}/types.d.ts +0 -0
- /package/dist/{db → form}/types.js +0 -0
package/README.md
CHANGED
|
@@ -1,393 +1,360 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
machine.
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
const
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
-
|
|
79
|
-
-
|
|
80
|
-
-
|
|
81
|
-
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
{
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
```
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
```
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
##
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
- **
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
npm run test:unit # Run Vitest unit tests
|
|
362
|
-
npm run test # Single-run test mode
|
|
363
|
-
```
|
|
364
|
-
|
|
365
|
-
## 📚 Code Structure
|
|
366
|
-
|
|
367
|
-
```
|
|
368
|
-
src/lib/
|
|
369
|
-
├── db/ # Schema & field layers
|
|
370
|
-
│ ├── dbSchema.ts # Collection templates
|
|
371
|
-
│ ├── dbFields.ts # Field rules & validation
|
|
372
|
-
│ └── dataModel.ts # TypeScript types
|
|
373
|
-
│ ├── CollectionFks.svelte # Forward relations
|
|
374
|
-
│ ├── CollectionReverseFks.svelte # Back-references
|
|
375
|
-
│ └── ...
|
|
376
|
-
└── index.ts # Main exports
|
|
377
|
-
```
|
|
378
|
-
|
|
379
|
-
## 🎓 Example Projects
|
|
380
|
-
|
|
381
|
-
See `src/routes/` for a working showcase of all components in action.
|
|
382
|
-
|
|
383
|
-
## 📄 License
|
|
384
|
-
|
|
385
|
-
MIT - See LICENSE file
|
|
386
|
-
|
|
387
|
-
---
|
|
388
|
-
|
|
389
|
-
**Next Steps for Contributors:**
|
|
390
|
-
1. Stabilize form validation pipeline
|
|
391
|
-
2. Add comprehensive test suite
|
|
392
|
-
3. Document TypeScript schema inference
|
|
393
|
-
4. Create migration guides from legacy code in `src/_old/`
|
|
1
|
+
|
|
2
|
+
## 🏗️ Model & Template Structure
|
|
3
|
+
|
|
4
|
+
A template for `idae-machine` must define collections, fields, and relationships. Here is a minimal example:
|
|
5
|
+
|
|
6
|
+
```typescript
|
|
7
|
+
// Example schemeModel for Machine
|
|
8
|
+
export const schemeModel = {
|
|
9
|
+
agents: {
|
|
10
|
+
keyPath: 'id',
|
|
11
|
+
ts: {} as Agent, // Optional typing for autocompletion
|
|
12
|
+
template: {
|
|
13
|
+
index: 'id',
|
|
14
|
+
presentation: 'name',
|
|
15
|
+
fields: {
|
|
16
|
+
id: 'id (readonly)',
|
|
17
|
+
name: 'text (required)',
|
|
18
|
+
active: 'boolean',
|
|
19
|
+
created_at: 'date'
|
|
20
|
+
},
|
|
21
|
+
fks: {
|
|
22
|
+
group: { code: 'group', multiple: false, rules: '' }
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
groups: {
|
|
27
|
+
keyPath: 'id',
|
|
28
|
+
ts: {} as Group,
|
|
29
|
+
template: {
|
|
30
|
+
index: 'id',
|
|
31
|
+
presentation: 'label',
|
|
32
|
+
fields: {
|
|
33
|
+
id: 'id (readonly)',
|
|
34
|
+
label: 'text (required)'
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## 🔍 Query Examples (via Machine)
|
|
42
|
+
|
|
43
|
+
After instantiating and starting Machine:
|
|
44
|
+
|
|
45
|
+
```typescript
|
|
46
|
+
import { machine, schemeModel } from '@medyll/idae-machine';
|
|
47
|
+
|
|
48
|
+
// Singleton initialization
|
|
49
|
+
machine.init({ dbName: 'my-db', version: 1, model: schemeModel });
|
|
50
|
+
machine.start();
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
// Add an agent
|
|
54
|
+
await machine.idbql.agents.add({ name: 'Alice', active: true });
|
|
55
|
+
|
|
56
|
+
// Simple query
|
|
57
|
+
const activeAgents = await machine.idbql.agents.where({ active: true }).toArray();
|
|
58
|
+
|
|
59
|
+
// Update
|
|
60
|
+
await machine.idbql.agents.put({ id: 1, name: 'Alice Cooper', active: true });
|
|
61
|
+
|
|
62
|
+
// Delete
|
|
63
|
+
await machine.idbql.agents.delete(1);
|
|
64
|
+
|
|
65
|
+
// Multi-collection transaction
|
|
66
|
+
const result = await machine.idbql.transaction([
|
|
67
|
+
'agents', 'groups'
|
|
68
|
+
], 'readwrite', async (tx) => {
|
|
69
|
+
const agentStore = tx.objectStore('agents');
|
|
70
|
+
const groupStore = tx.objectStore('groups');
|
|
71
|
+
const groupId = await groupStore.add({ label: 'Admins' });
|
|
72
|
+
const agentId = await agentStore.add({ name: 'Bob', active: true, group: groupId });
|
|
73
|
+
return { groupId, agentId };
|
|
74
|
+
});
|
|
75
|
+
```
|
|
76
|
+
## ⚡ Advanced Data & Reactivity
|
|
77
|
+
|
|
78
|
+
`idae-machine` leverages the power of [@medyll/idae-idbql](https://github.com/medyll/idae-idbql) to provide:
|
|
79
|
+
- A MongoDB-inspired IndexedDB query engine
|
|
80
|
+
- Complex multi-collection transactions
|
|
81
|
+
- Svelte 5 reactive state (`idbqlState`) for real-time UIs
|
|
82
|
+
- Migration and versioning management
|
|
83
|
+
- Robustness and advanced error handling
|
|
84
|
+
|
|
85
|
+
### Svelte 5: Reactive State
|
|
86
|
+
|
|
87
|
+
Use `store` for reactive lists or views:
|
|
88
|
+
|
|
89
|
+
```svelte
|
|
90
|
+
<script lang="ts">
|
|
91
|
+
import { machine } from './store'; // or create your own instance
|
|
92
|
+
// Reactive list of active agents
|
|
93
|
+
const activeAgents = $derived(() => machine.idbqlState.agents.where({ active: true }));
|
|
94
|
+
</script>
|
|
95
|
+
|
|
96
|
+
<h2>Active agents</h2>
|
|
97
|
+
{#each $activeAgents as agent}
|
|
98
|
+
<p>{agent.name}</p>
|
|
99
|
+
{/each}
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
# @medyll/idae-machine
|
|
104
|
+
|
|
105
|
+
**Low-code UI framework** for rapid data structure visualization and CRUD operations in Svelte 5. Declare your database schema once, automatically generate rich UI components for displaying, creating, and updating structured data in IndexedDB.
|
|
106
|
+
|
|
107
|
+
## 🎯 Purpose
|
|
108
|
+
|
|
109
|
+
`idae-machine` bridges the gap between **data modeling** (`@medyll/idae-idbql`) and **rich UI components** (`@medyll/idae-slotui-svelte`). It provides:
|
|
110
|
+
- **Schema-driven UI generation**: Declare your data model, get form components for free
|
|
111
|
+
- **CRUD Zone**: Pre-built "Create-Read-Update-Delete" interface for any collection
|
|
112
|
+
- **Relational support**: Foreign key and reverse foreign key visualization
|
|
113
|
+
- **In-place editing**: Edit records inline without modal dialogs
|
|
114
|
+
- **Field-level validation**: Type-safe field rules (required, readonly, private)
|
|
115
|
+
|
|
116
|
+
## 📦 Core Architecture
|
|
117
|
+
|
|
118
|
+
### Layer Stack
|
|
119
|
+
|
|
120
|
+
```
|
|
121
|
+
UI Components (Svelte 5 Components)
|
|
122
|
+
↓
|
|
123
|
+
Form Management & Validation Logic
|
|
124
|
+
↓
|
|
125
|
+
Database Schema Definition (TypeScript Types)
|
|
126
|
+
↓
|
|
127
|
+
IndexedDB Abstraction (@medyll/idae-idbql)
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
### Key Modules
|
|
131
|
+
|
|
132
|
+
| Module | Purpose |
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
## 🚀 Quick Start: App Initialization
|
|
136
|
+
|
|
137
|
+
The recommended way to initialize your app is to use the `Machine` class, which centralizes schema, collections, and IndexedDB access.
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
```typescript
|
|
141
|
+
import { machine, schemeModel } from '@medyll/idae-machine';
|
|
142
|
+
|
|
143
|
+
// Singleton initialization
|
|
144
|
+
machine.init({ dbName: 'my-db', version: 1, model: schemeModel });
|
|
145
|
+
machine.start();
|
|
146
|
+
|
|
147
|
+
// Access collections, db, and model
|
|
148
|
+
const collections = machine.collections;
|
|
149
|
+
const idbql = machine.idbql;
|
|
150
|
+
const idbqlState = machine.idbqlState;
|
|
151
|
+
const db = machine.indexedb;
|
|
152
|
+
const model = machine.idbqModel;
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
You can now pass `collections` and other instances to Svelte components for CRUD, data listing, and editing.
|
|
156
|
+
|
|
157
|
+
### Legacy/Direct Usage (not recommended)
|
|
158
|
+
You can still use `createIdbqDb` directly if you need low-level access:
|
|
159
|
+
|
|
160
|
+
```typescript
|
|
161
|
+
import { createIdbqDb, type IdbqModel } from '@medyll/idae-idbql';
|
|
162
|
+
const idbqlState = createIdbqDb(schemeModel);
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
### 2. Use CRUD Components
|
|
166
|
+
|
|
167
|
+
```svelte
|
|
168
|
+
<script lang="ts">
|
|
169
|
+
import { CrudZone, CreateUpdate, DataList } from '@medyll/idae-machine';
|
|
170
|
+
</script>
|
|
171
|
+
|
|
172
|
+
<!-- Full CRUD interface -->
|
|
173
|
+
<CrudZone collection="agents" />
|
|
174
|
+
|
|
175
|
+
<!-- Or compose individually -->
|
|
176
|
+
<DataList collection="agents" />
|
|
177
|
+
<CreateUpdate collection="agents" mode="create" />
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
## 📋 Component Guide
|
|
181
|
+
|
|
182
|
+
### `<CrudZone>`
|
|
183
|
+
Unified CRUD interface with sidebar list and detail editing.
|
|
184
|
+
```svelte
|
|
185
|
+
<CrudZone collection="agents" style="height: 600px; min-width: 750px" />
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
### `<DataList>`
|
|
189
|
+
Displays collection records as grid with click-to-edit.
|
|
190
|
+
```svelte
|
|
191
|
+
<DataList
|
|
192
|
+
collection="agents"
|
|
193
|
+
displayMode="grid"
|
|
194
|
+
where={{ active: { $eq: true } }}
|
|
195
|
+
onclick={(data, idx) => console.log(data)}
|
|
196
|
+
/>
|
|
197
|
+
```
|
|
198
|
+
mode="show"
|
|
199
|
+
dataId={1}
|
|
200
|
+
showFields={['name', 'code', 'model']}
|
|
201
|
+
inPlaceEdit={true}
|
|
202
|
+
showFks={true}
|
|
203
|
+
/>
|
|
204
|
+
```
|
|
205
|
+
```svelte
|
|
206
|
+
collection="agents"
|
|
207
|
+
fieldName="name"
|
|
208
|
+
data={formData}
|
|
209
|
+
mode="edit"
|
|
210
|
+
editInPlace={true}
|
|
211
|
+
/>
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
### Relational Components
|
|
215
|
+
```svelte
|
|
216
|
+
<!-- Foreign Keys (refs TO other collections) -->
|
|
217
|
+
<CollectionFks collection="agents" />
|
|
218
|
+
|
|
219
|
+
<!-- Reverse Foreign Keys (records pointing TO this one) -->
|
|
220
|
+
<CollectionReverseFks collection="agents">
|
|
221
|
+
{#snippet children({ collection, template })}
|
|
222
|
+
<div>{collection} references this agent</div>
|
|
223
|
+
{/snippet}
|
|
224
|
+
</CollectionReverseFks>
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
## 🔧 Schema Definition (dbFields.ts)
|
|
228
|
+
|
|
229
|
+
Field types are declared using a string-based DSL:
|
|
230
|
+
|
|
231
|
+
```typescript
|
|
232
|
+
fields: {
|
|
233
|
+
// Primitives
|
|
234
|
+
id: 'id (readonly)',
|
|
235
|
+
name: 'text (required)',
|
|
236
|
+
age: 'number',
|
|
237
|
+
active: 'boolean',
|
|
238
|
+
email: 'email',
|
|
239
|
+
created: 'date',
|
|
240
|
+
|
|
241
|
+
// Text variants
|
|
242
|
+
bio: 'text-long',
|
|
243
|
+
note: 'text-area',
|
|
244
|
+
|
|
245
|
+
// Relations
|
|
246
|
+
categoryId: 'fk-category.id (required)',
|
|
247
|
+
|
|
248
|
+
// Collections
|
|
249
|
+
tagIds: 'array-of-number',
|
|
250
|
+
|
|
251
|
+
// Modifiers
|
|
252
|
+
password: 'password (private)',
|
|
253
|
+
system_field: 'text (readonly private)'
|
|
254
|
+
}
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
## 🛡️ Robustness, Coverage & Performance
|
|
260
|
+
|
|
261
|
+
All core logic (`dbFields.ts`, `machine.ts`, etc.) is tested and optimized:
|
|
262
|
+
- **Schema parsing**: all types and modifiers are handled
|
|
263
|
+
- **Relations**: typed and tested FK and reverse-FK
|
|
264
|
+
- **Unit tests**: every exported method is covered (Vitest)
|
|
265
|
+
- **Svelte 5**: strict convention compliance
|
|
266
|
+
- **Error handling**: typed exceptions, transactional robustness
|
|
267
|
+
- **Performance**: indexes, optimized queries, built-in tips
|
|
268
|
+
|
|
269
|
+
### Current Focus
|
|
270
|
+
- ✅ Schema declaration & typing
|
|
271
|
+
- ✅ Advanced IndexedDB integration
|
|
272
|
+
- ✅ Component export & modular structure
|
|
273
|
+
- ✅ Exhaustive test coverage
|
|
274
|
+
- ✅ Svelte 5 policy
|
|
275
|
+
- 🔄 Form validation (in progress)
|
|
276
|
+
- 🔄 Field rendering pipeline
|
|
277
|
+
- ⏳ End-to-end CRUD workflows
|
|
278
|
+
|
|
279
|
+
## 🧪 Testing Policy
|
|
280
|
+
|
|
281
|
+
All logic in `dbFields.ts` and related modules is covered by unit tests:
|
|
282
|
+
|
|
283
|
+
- **Test schema**: All tests use a realistic, complex schema (see `testDbSchema.ts`).
|
|
284
|
+
- **Coverage**: Every method of every exported class is tested, including edge cases (array/object/fk/required/readonly).
|
|
285
|
+
- **Continuous validation**: All tests must pass before merge. See `CHANGELOG.md` for test and coverage history.
|
|
286
|
+
|
|
287
|
+
|
|
288
|
+
## 🦄 Svelte 5 Coding Policy
|
|
289
|
+
|
|
290
|
+
All UI code must strictly follow Svelte 5 syntax and conventions. See `AGENTS.md` for details and migration rules.
|
|
291
|
+
|
|
292
|
+
## 📖 Developer & Documentation Policy
|
|
293
|
+
|
|
294
|
+
- All classes and methods in the codebase are fully documented with jsDoc, including `@role`, `@param`, and `@return` in English.
|
|
295
|
+
- Internal imports use `$lib` alias for consistency and maintainability.
|
|
296
|
+
- All code is strictly compliant with Svelte 5 standards (see `AGENTS.md`).
|
|
297
|
+
- Pull requests must respect documentation and Svelte 5 rules, or will be rejected.
|
|
298
|
+
|
|
299
|
+
### Example jsDoc
|
|
300
|
+
```typescript
|
|
301
|
+
/**
|
|
302
|
+
* @class MachineDb
|
|
303
|
+
* @role Central class for parsing, introspecting, and extracting metadata from the database schema.
|
|
304
|
+
* @param {IdbqModel} model Custom model to use.
|
|
305
|
+
*/
|
|
306
|
+
```
|
|
307
|
+
|
|
308
|
+
See source files for full jsDoc coverage.
|
|
309
|
+
|
|
310
|
+
## 🔗 Dependencies
|
|
311
|
+
|
|
312
|
+
- **@medyll/idae-idbql**: IndexedDB abstraction with schema support
|
|
313
|
+
- **@medyll/idae-slotui-svelte**: UI component library (Button, MenuList, Looper, etc.)
|
|
314
|
+
- **svelte**: ^5.0.0 (uses Svelte 5 runes)
|
|
315
|
+
### Build
|
|
316
|
+
```bash
|
|
317
|
+
### Development Server
|
|
318
|
+
```bash
|
|
319
|
+
npm run dev # Start dev server on localhost
|
|
320
|
+
npm run dev -- --open # Auto-open in browser
|
|
321
|
+
```
|
|
322
|
+
|
|
323
|
+
### Quality Assurance
|
|
324
|
+
```bash
|
|
325
|
+
npm run check # Svelte type checking
|
|
326
|
+
npm run lint # ESLint + Prettier check
|
|
327
|
+
npm run format # Auto-format code
|
|
328
|
+
npm run test:unit # Run Vitest unit tests
|
|
329
|
+
npm run test # Single-run test mode
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
## 📚 Code Structure
|
|
333
|
+
|
|
334
|
+
```
|
|
335
|
+
src/lib/
|
|
336
|
+
├── db/ # Schema & field layers
|
|
337
|
+
│ ├── dbSchema.ts # Collection templates
|
|
338
|
+
│ ├── dbFields.ts # Field rules & validation
|
|
339
|
+
│ └── dataModel.ts # TypeScript types
|
|
340
|
+
│ ├── CollectionFks.svelte # Forward relations
|
|
341
|
+
│ ├── CollectionReverseFks.svelte # Back-references
|
|
342
|
+
│ └── ...
|
|
343
|
+
└── index.ts # Main exports
|
|
344
|
+
```
|
|
345
|
+
|
|
346
|
+
## 🎓 Example Projects
|
|
347
|
+
|
|
348
|
+
See `src/routes/` for a working showcase of all components in action.
|
|
349
|
+
|
|
350
|
+
## 📄 License
|
|
351
|
+
|
|
352
|
+
MIT - See LICENSE file
|
|
353
|
+
|
|
354
|
+
---
|
|
355
|
+
|
|
356
|
+
**Next Steps for Contributors:**
|
|
357
|
+
1. Stabilize form validation pipeline
|
|
358
|
+
2. Add comprehensive test suite
|
|
359
|
+
3. Document TypeScript schema inference
|
|
360
|
+
4. Create migration guides from legacy code in `src/_old/`
|