@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.
Files changed (101) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +360 -393
  3. package/cli.js +46 -0
  4. package/dist/demo/dbSchema.d.ts +446 -0
  5. package/dist/demo/dbSchema.js +449 -0
  6. package/dist/demo/testScheme.d.ts +56 -0
  7. package/dist/demo/testScheme.js +42 -0
  8. package/dist/form/CreateUpdate.svelte +219 -0
  9. package/dist/{demo/form → form}/CreateUpdate.svelte.d.ts +5 -7
  10. package/dist/form/DataProvider.svelte +23 -0
  11. package/dist/form/DataProvider.svelte.d.ts +7 -0
  12. package/dist/form/FieldInPlace.svelte +98 -0
  13. package/dist/form/FieldInPlace.svelte.d.ts +14 -0
  14. package/dist/form/FieldValue.svelte +148 -0
  15. package/dist/{demo/form → form}/FieldValue.svelte.d.ts +8 -9
  16. package/dist/fragments/Confirm.svelte +73 -58
  17. package/dist/fragments/Confirm.svelte.d.ts +4 -8
  18. package/dist/fragments/Frame.svelte +19 -19
  19. package/dist/fragments/InfoLine.svelte +21 -21
  20. package/dist/fragments/Selector.svelte +26 -26
  21. package/dist/fragments/Skeleton.svelte +21 -21
  22. package/dist/index.d.ts +20 -28
  23. package/dist/index.js +20 -28
  24. package/dist/main/machine/MachineError.d.ts +33 -0
  25. package/dist/main/machine/MachineError.js +49 -0
  26. package/dist/main/machine/MachineErrorValidation.d.ts +19 -0
  27. package/dist/main/machine/MachineErrorValidation.js +24 -0
  28. package/dist/main/machine/MachineFieldType.d.ts +121 -0
  29. package/dist/main/machine/MachineFieldType.js +250 -0
  30. package/dist/main/machine/MachineScheme.d.ts +84 -0
  31. package/dist/main/machine/MachineScheme.js +146 -0
  32. package/dist/main/machine/MachineSchemeField.d.ts +19 -0
  33. package/dist/main/machine/MachineSchemeField.js +51 -0
  34. package/dist/main/machine/MachineSchemeFieldForge.d.ts +84 -0
  35. package/dist/main/machine/MachineSchemeFieldForge.js +128 -0
  36. package/dist/main/machine/MachineSchemeFieldValues.d.ts +69 -0
  37. package/dist/main/machine/MachineSchemeFieldValues.js +94 -0
  38. package/dist/main/machine/MachineSchemeValidate.d.ts +51 -0
  39. package/dist/main/machine/MachineSchemeValidate.js +120 -0
  40. package/dist/main/machine/MachineSchemeValues.d.ts +109 -0
  41. package/dist/main/machine/{IDbCollectionValues.js → MachineSchemeValues.js} +116 -41
  42. package/dist/main/machine/SchemeFieldDefaultValues.d.ts +74 -0
  43. package/dist/main/machine/SchemeFieldDefaultValues.js +98 -0
  44. package/dist/main/machine.d.ts +71 -44
  45. package/dist/main/machine.js +74 -43
  46. package/dist/main/machineDb.d.ts +14 -56
  47. package/dist/main/machineDb.js +15 -98
  48. package/dist/main/{machineForge.d.ts → machineParserForge.d.ts} +15 -25
  49. package/dist/main/{machineForge.js → machineParserForge.js} +16 -10
  50. package/dist/ui/CollectionButton.svelte +29 -26
  51. package/dist/ui/CollectionButton.svelte.d.ts +3 -3
  52. package/dist/ui/CollectionFks.svelte +24 -24
  53. package/dist/ui/CollectionFks.svelte.d.ts +2 -2
  54. package/dist/ui/CollectionList.svelte +100 -95
  55. package/dist/ui/CollectionList.svelte.d.ts +1 -2
  56. package/dist/ui/CollectionListFieldValues.svelte +59 -0
  57. package/dist/ui/CollectionListFieldValues.svelte.d.ts +9 -0
  58. package/dist/ui/CollectionListMenu.svelte +39 -47
  59. package/dist/ui/CollectionListMenu.svelte.d.ts +1 -1
  60. package/dist/ui/CollectionReverseFks.svelte +37 -56
  61. package/dist/ui/CollectionReverseFks.svelte.d.ts +4 -8
  62. package/package.json +18 -5
  63. package/dist/db/dbSchema.d.ts +0 -201
  64. package/dist/db/dbSchema.js +0 -205
  65. package/dist/db/fieldTypes.d.ts +0 -13
  66. package/dist/db/fieldTypes.js +0 -67
  67. package/dist/db/types.d.ts +0 -124
  68. package/dist/demo/form/CreateUpdate.svelte +0 -198
  69. package/dist/demo/form/CrudZone.svelte +0 -22
  70. package/dist/demo/form/CrudZone.svelte.d.ts +0 -29
  71. package/dist/demo/form/DataProvider.svelte +0 -20
  72. package/dist/demo/form/DataProvider.svelte.d.ts +0 -9
  73. package/dist/demo/form/FieldInPlace.svelte +0 -49
  74. package/dist/demo/form/FieldInPlace.svelte.d.ts +0 -11
  75. package/dist/demo/form/FieldValue.svelte +0 -212
  76. package/dist/demo/form/types.js +0 -1
  77. package/dist/demo/testDbSchema.d.ts +0 -6
  78. package/dist/demo/testDbSchema.js +0 -58
  79. package/dist/demo/types.d.ts +0 -140
  80. package/dist/demo/types.js +0 -1
  81. package/dist/fragments/List.svelte +0 -21
  82. package/dist/fragments/List.svelte.d.ts +0 -38
  83. package/dist/main/machine/IDbCollection.d.ts +0 -71
  84. package/dist/main/machine/IDbCollection.js +0 -102
  85. package/dist/main/machine/IDbCollectionFieldForge.d.ts +0 -42
  86. package/dist/main/machine/IDbCollectionFieldForge.js +0 -74
  87. package/dist/main/machine/IDbCollectionFieldValues.d.ts +0 -57
  88. package/dist/main/machine/IDbCollectionFieldValues.js +0 -82
  89. package/dist/main/machine/IDbCollectionValues.d.ts +0 -78
  90. package/dist/main/machine/IDbError.d.ts +0 -6
  91. package/dist/main/machine/IDbError.js +0 -61
  92. package/dist/main/machine/IDbFormValidate.d.ts +0 -55
  93. package/dist/main/machine/IDbFormValidate.js +0 -183
  94. package/dist/main/machine/IDbValidationError.d.ts +0 -19
  95. package/dist/main/machine/IDbValidationError.js +0 -24
  96. package/dist/main/machine/types.d.ts +0 -1
  97. package/dist/main/machine/types.js +0 -1
  98. package/dist/ui/CollectionFieldGuess.svelte +0 -29
  99. package/dist/ui/CollectionFieldGuess.svelte.d.ts +0 -11
  100. /package/dist/{demo/form → form}/types.d.ts +0 -0
  101. /package/dist/{db → form}/types.js +0 -0
package/README.md CHANGED
@@ -1,393 +1,360 @@
1
- ## 🏗️ Model & Template Structure
2
-
3
- Un modèle (template) pour `idae-machine` doit définir les collections, les champs, et les relations. Voici un exemple minimal :
4
-
5
- ```typescript
6
- // Exemple de schemeModel pour Machine
7
- export const schemeModel = {
8
- agents: {
9
- keyPath: 'id',
10
- ts: {} as Agent, // Typage optionnel pour l'autocomplétion
11
- template: {
12
- index: 'id',
13
- presentation: 'name',
14
- fields: {
15
- id: 'id (readonly)',
16
- name: 'text (required)',
17
- active: 'boolean',
18
- created_at: 'date'
19
- },
20
- fks: {
21
- group: { code: 'group', multiple: false, rules: '' }
22
- }
23
- }
24
- },
25
- groups: {
26
- keyPath: 'id',
27
- ts: {} as Group,
28
- template: {
29
- index: 'id',
30
- presentation: 'label',
31
- fields: {
32
- id: 'id (readonly)',
33
- label: 'text (required)'
34
- }
35
- }
36
- }
37
- };
38
- ```
39
-
40
- ## 🔍 Query Examples (via Machine)
41
-
42
- Après avoir instancié et démarré Machine :
43
-
44
- ```typescript
45
- import { machine, schemeModel } from '@medyll/idae-machine';
46
-
47
- // Initialisation du singleton
48
- machine.init({ dbName: 'my-db', version: 1, model: schemeModel });
49
- machine.start();
50
-
51
- // Ajouter un agent
52
- await machine.idbql.agents.add({ name: 'Alice', active: true });
53
-
54
- // Requête simple
55
- const activeAgents = await machine.idbql.agents.where({ active: true }).toArray();
56
-
57
- // Mise à jour
58
- await machine.idbql.agents.put({ id: 1, name: 'Alice Cooper', active: true });
59
-
60
- // Suppression
61
- await machine.idbql.agents.delete(1);
62
-
63
- // Transaction multi-collections
64
- const result = await machine.idbql.transaction([
65
- 'agents', 'groups'
66
- ], 'readwrite', async (tx) => {
67
- const agentStore = tx.objectStore('agents');
68
- const groupStore = tx.objectStore('groups');
69
- const groupId = await groupStore.add({ label: 'Admins' });
70
- const agentId = await agentStore.add({ name: 'Bob', active: true, group: groupId });
71
- return { groupId, agentId };
72
- });
73
- ```
74
- ## ⚡ Advanced Data & Reactivity
75
-
76
- `idae-machine` s’appuie sur la puissance de [@medyll/idae-idbql](https://github.com/medyll/idae-idbql) pour offrir :
77
- - Un moteur de requêtes IndexedDB inspiré de MongoDB
78
- - Transactions complexes multi-collections
79
- - State réactif Svelte 5 (`idbqlState`) pour des UI en temps réel
80
- - Gestion des migrations et versioning
81
- - Robustesse et gestion d’erreur avancée
82
-
83
- ### Svelte 5: State Réactif
84
-
85
- Utilisez `idbqlState` pour des listes ou des vues réactives :
86
-
87
- ```svelte
88
- <script lang="ts">
89
- import { machine } from './store'; // ou créez votre instance
90
- // Liste réactive des agents actifs
91
- const activeAgents = $derived(() => machine.idbqlState.agents.where({ active: true }));
92
- </script>
93
-
94
- <h2>Agents actifs</h2>
95
- {#each $activeAgents as agent}
96
- <p>{agent.name}</p>
97
- {/each}
98
- ```
99
-
100
- ### Transactions & Migrations
101
-
102
- Vous pouvez effectuer des transactions complexes et gérer les migrations de schéma :
103
-
104
- ```typescript
105
- const result = await machine.idbql.transaction([
106
- "users", "posts"
107
- ], "readwrite", async (tx) => {
108
- const userStore = tx.objectStore("users");
109
- const postStore = tx.objectStore("posts");
110
- const userId = await userStore.add({ name: "Alice" });
111
- const postId = await postStore.add({ userId, title: "Hello" });
112
- return { userId, postId };
113
- });
114
-
115
- // Migration
116
- const { indexedb } = machine;
117
- indexedb.upgrade(oldVersion, newVersion, transaction => {
118
- if (oldVersion < 2) {
119
- transaction.objectStore("users").createIndex("emailIndex", "email", { unique: true });
120
- }
121
- });
122
- ```
123
-
124
- ### Error Handling
125
-
126
- ```typescript
127
- try {
128
- await machine.idbql.users.add({ username: "existing_user" });
129
- } catch (error) {
130
- if (error instanceof UniqueConstraintError) {
131
- console.error("Username already exists");
132
- } else {
133
- console.error("Unexpected error", error);
134
- }
135
- }
136
- ```
137
-
138
- ### Performance Tips
139
- - Utilisez les indexes pour accélérer les requêtes
140
- - Limitez les résultats avec `.limit(n)`
141
- - Préférez `.count()` à `.toArray().length`
142
- - Optimisez vos schémas pour la recherche
143
- # @medyll/idae-machine
144
-
145
- **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.
146
-
147
- ## 🎯 Purpose
148
-
149
- `idae-machine` bridges the gap between **data modeling** (`@medyll/idae-idbql`) and **rich UI components** (`@medyll/idae-slotui-svelte`). It provides:
150
- - **Schema-driven UI generation**: Declare your data model, get form components for free
151
- - **CRUD Zone**: Pre-built "Create-Read-Update-Delete" interface for any collection
152
- - **Relational support**: Foreign key and reverse foreign key visualization
153
- - **In-place editing**: Edit records inline without modal dialogs
154
- - **Field-level validation**: Type-safe field rules (required, readonly, private)
155
-
156
- ## 📦 Core Architecture
157
-
158
- ### Layer Stack
159
-
160
- ```
161
- UI Components (Svelte 5 Components)
162
-
163
- Form Management & Validation Logic
164
-
165
- Database Schema Definition (TypeScript Types)
166
-
167
- IndexedDB Abstraction (@medyll/idae-idbql)
168
- ```
169
-
170
- ### Key Modules
171
-
172
- | Module | Purpose |
173
-
174
-
175
- ## 🚀 Quick Start: App Initialization
176
-
177
- The recommended way to initialize your app is to use the `Machine` class, which centralizes schema, collections, and IndexedDB access.
178
-
179
-
180
- ```typescript
181
- import { machine, schemeModel } from '@medyll/idae-machine';
182
-
183
- // Initialisation du singleton
184
- machine.init({ dbName: 'my-db', version: 1, model: schemeModel });
185
- machine.start();
186
-
187
- // Accès aux collections, à la base et au modèle
188
- const collections = machine.collections;
189
- const idbql = machine.idbql;
190
- const idbqlState = machine.idbqlState;
191
- const db = machine.indexedb;
192
- const model = machine.idbqModel;
193
- ```
194
-
195
- You can now pass `collections` and other instances to Svelte components for CRUD, data listing, and editing.
196
-
197
- ---
198
-
199
- ### Legacy/Direct Usage (not recommended)
200
- You can still use `createIdbqDb` directly if you need low-level access:
201
-
202
- ```typescript
203
- import { createIdbqDb, type IdbqModel } from '@medyll/idae-idbql';
204
- const idbqlState = createIdbqDb(schemeModel);
205
- ```
206
-
207
- ### 2. Use CRUD Components
208
-
209
- ```svelte
210
- <script lang="ts">
211
- import { CrudZone, CreateUpdate, DataList } from '@medyll/idae-machine';
212
- </script>
213
-
214
- <!-- Full CRUD interface -->
215
- <CrudZone collection="agents" />
216
-
217
- <!-- Or compose individually -->
218
- <DataList collection="agents" />
219
- <CreateUpdate collection="agents" mode="create" />
220
- ```
221
-
222
- ## 📋 Component Guide
223
-
224
- ### `<CrudZone>`
225
- Unified CRUD interface with sidebar list and detail editing.
226
- ```svelte
227
- <CrudZone collection="agents" style="height: 600px; min-width: 750px" />
228
- ```
229
-
230
- ### `<DataList>`
231
- Displays collection records as grid with click-to-edit.
232
- ```svelte
233
- <DataList
234
- collection="agents"
235
- displayMode="grid"
236
- where={{ active: { $eq: true } }}
237
- onclick={(data, idx) => console.log(data)}
238
- />
239
- ```
240
-
241
- ### `<CreateUpdate>`
242
- Form for creating/updating/viewing records.
243
- ```svelte
244
- <CreateUpdate
245
- collection="agents"
246
- mode="show"
247
- dataId={1}
248
- showFields={['name', 'code', 'model']}
249
- inPlaceEdit={true}
250
- showFks={true}
251
- />
252
- ```
253
-
254
- ### `<FieldValue>`
255
- Renders a single field with intelligent type detection.
256
- ```svelte
257
- <FieldValue
258
- collection="agents"
259
- fieldName="name"
260
- data={formData}
261
- mode="edit"
262
- editInPlace={true}
263
- />
264
- ```
265
-
266
- ### Relational Components
267
- ```svelte
268
- <!-- Foreign Keys (refs TO other collections) -->
269
- <CollectionFks collection="agents" />
270
-
271
- <!-- Reverse Foreign Keys (records pointing TO this one) -->
272
- <CollectionReverseFks collection="agents">
273
- {#snippet children({ collection, template })}
274
- <div>{collection} references this agent</div>
275
- {/snippet}
276
- </CollectionReverseFks>
277
- ```
278
-
279
- ## 🔧 Schema Definition (dbFields.ts)
280
-
281
- Field types are declared using string-based DSL:
282
-
283
- ```typescript
284
- fields: {
285
- // Primitives
286
- id: 'id (readonly)',
287
- name: 'text (required)',
288
- age: 'number',
289
- active: 'boolean',
290
- email: 'email',
291
- created: 'date',
292
-
293
- // Text variants
294
- bio: 'text-long',
295
- note: 'text-area',
296
-
297
- // Relations
298
- categoryId: 'fk-category.id (required)',
299
-
300
- // Collections
301
- tagIds: 'array-of-number',
302
-
303
- // Modifiers
304
- password: 'password (private)',
305
- system_field: 'text (readonly private)'
306
- }
307
- ```
308
-
309
-
310
-
311
- ## 🛡️ Robustness, Coverage & Performance
312
-
313
- Tout le cœur métier (`dbFields.ts`, `machine.ts`, etc.) est testé et optimisé :
314
- - **Parsing de schéma** : tous les types et modificateurs sont gérés
315
- - **Relations** : FK et reverse-FK typés et testés
316
- - **Tests unitaires** : chaque méthode exportée est couverte (Vitest)
317
- - **Svelte 5** : conformité stricte aux conventions
318
- - **Gestion d’erreur** : exceptions typées, robustesse transactionnelle
319
- - **Performance** : indexes, requêtes optimisées, conseils intégrés
320
-
321
- ### Focus actuel
322
- - ✅ Déclaration de schéma & typage
323
- - Intégration IndexedDB avancée
324
- - ✅ Export de composants & structure modulaire
325
- - Couverture de tests exhaustive
326
- - Politique Svelte 5
327
- - 🔄 Validation de formulaire (en cours)
328
- - 🔄 Pipeline de rendu de champ
329
- - Workflows CRUD end-to-end
330
-
331
- ## 🧪 Testing Policy
332
-
333
- All logic in `dbFields.ts` and related modules is covered by unit tests:
334
-
335
- - **Test schema**: All tests use a realistic, complex schema (see `testDbSchema.ts`).
336
- - **Coverage**: Every method of every exported class is tested, including edge cases (array/object/fk/required/readonly).
337
- - **Continuous validation**: All tests must pass before merge. See `CHANGELOG.md` for test and coverage history.
338
-
339
- ## 🦄 Svelte 5 Coding Policy
340
-
341
- All UI code must strictly follow Svelte 5 syntax and conventions. See `AGENTS.md` for details and migration rules.
342
-
343
- ## 🔗 Dependencies
344
-
345
- - **@medyll/idae-idbql**: IndexedDB abstraction with schema support
346
- - **@medyll/idae-slotui-svelte**: UI component library (Button, MenuList, Looper, etc.)
347
- - **svelte**: ^5.0.0 (uses Svelte 5 runes)
348
- ### Build
349
- ```bash
350
- ### Development Server
351
- ```bash
352
- npm run dev # Start dev server on localhost
353
- npm run dev -- --open # Auto-open in browser
354
- ```
355
-
356
- ### Quality Assurance
357
- ```bash
358
- npm run check # Svelte type checking
359
- npm run lint # ESLint + Prettier check
360
- npm run format # Auto-format code
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/`