@medyll/idae-machine 0.109.0 → 0.111.0
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/README.md +186 -39
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,3 +1,143 @@
|
|
|
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
|
+
const machine = new Machine('my-db', 1, schemeModel);
|
|
47
|
+
machine.start();
|
|
48
|
+
|
|
49
|
+
// Ajouter un agent
|
|
50
|
+
await machine.idbql.agents.add({ name: 'Alice', active: true });
|
|
51
|
+
|
|
52
|
+
// Requête simple
|
|
53
|
+
const activeAgents = await machine.idbql.agents.where({ active: true }).toArray();
|
|
54
|
+
|
|
55
|
+
// Mise à jour
|
|
56
|
+
await machine.idbql.agents.put({ id: 1, name: 'Alice Cooper', active: true });
|
|
57
|
+
|
|
58
|
+
// Suppression
|
|
59
|
+
await machine.idbql.agents.delete(1);
|
|
60
|
+
|
|
61
|
+
// Transaction multi-collections
|
|
62
|
+
const result = await machine.idbql.transaction([
|
|
63
|
+
'agents', 'groups'
|
|
64
|
+
], 'readwrite', async (tx) => {
|
|
65
|
+
const agentStore = tx.objectStore('agents');
|
|
66
|
+
const groupStore = tx.objectStore('groups');
|
|
67
|
+
const groupId = await groupStore.add({ label: 'Admins' });
|
|
68
|
+
const agentId = await agentStore.add({ name: 'Bob', active: true, group: groupId });
|
|
69
|
+
return { groupId, agentId };
|
|
70
|
+
});
|
|
71
|
+
```
|
|
72
|
+
## ⚡ Advanced Data & Reactivity
|
|
73
|
+
|
|
74
|
+
`idae-machine` s’appuie sur la puissance de [@medyll/idae-idbql](https://github.com/medyll/idae-idbql) pour offrir :
|
|
75
|
+
- Un moteur de requêtes IndexedDB inspiré de MongoDB
|
|
76
|
+
- Transactions complexes multi-collections
|
|
77
|
+
- State réactif Svelte 5 (`idbqlState`) pour des UI en temps réel
|
|
78
|
+
- Gestion des migrations et versioning
|
|
79
|
+
- Robustesse et gestion d’erreur avancée
|
|
80
|
+
|
|
81
|
+
### Svelte 5: State Réactif
|
|
82
|
+
|
|
83
|
+
Utilisez `idbqlState` pour des listes ou des vues réactives :
|
|
84
|
+
|
|
85
|
+
```svelte
|
|
86
|
+
<script lang="ts">
|
|
87
|
+
import { machine } from './store'; // ou créez votre instance
|
|
88
|
+
// Liste réactive des agents actifs
|
|
89
|
+
const activeAgents = $derived(() => machine.idbqlState.agents.where({ active: true }));
|
|
90
|
+
</script>
|
|
91
|
+
|
|
92
|
+
<h2>Agents actifs</h2>
|
|
93
|
+
{#each $activeAgents as agent}
|
|
94
|
+
<p>{agent.name}</p>
|
|
95
|
+
{/each}
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### Transactions & Migrations
|
|
99
|
+
|
|
100
|
+
Vous pouvez effectuer des transactions complexes et gérer les migrations de schéma :
|
|
101
|
+
|
|
102
|
+
```typescript
|
|
103
|
+
const result = await machine.idbql.transaction([
|
|
104
|
+
"users", "posts"
|
|
105
|
+
], "readwrite", async (tx) => {
|
|
106
|
+
const userStore = tx.objectStore("users");
|
|
107
|
+
const postStore = tx.objectStore("posts");
|
|
108
|
+
const userId = await userStore.add({ name: "Alice" });
|
|
109
|
+
const postId = await postStore.add({ userId, title: "Hello" });
|
|
110
|
+
return { userId, postId };
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
// Migration
|
|
114
|
+
const { indexedb } = machine;
|
|
115
|
+
indexedb.upgrade(oldVersion, newVersion, transaction => {
|
|
116
|
+
if (oldVersion < 2) {
|
|
117
|
+
transaction.objectStore("users").createIndex("emailIndex", "email", { unique: true });
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
### Error Handling
|
|
123
|
+
|
|
124
|
+
```typescript
|
|
125
|
+
try {
|
|
126
|
+
await machine.idbql.users.add({ username: "existing_user" });
|
|
127
|
+
} catch (error) {
|
|
128
|
+
if (error instanceof UniqueConstraintError) {
|
|
129
|
+
console.error("Username already exists");
|
|
130
|
+
} else {
|
|
131
|
+
console.error("Unexpected error", error);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
### Performance Tips
|
|
137
|
+
- Utilisez les indexes pour accélérer les requêtes
|
|
138
|
+
- Limitez les résultats avec `.limit(n)`
|
|
139
|
+
- Préférez `.count()` à `.toArray().length`
|
|
140
|
+
- Optimisez vos schémas pour la recherche
|
|
1
141
|
# @medyll/idae-machine
|
|
2
142
|
|
|
3
143
|
**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.
|
|
@@ -29,32 +169,37 @@ IndexedDB Abstraction (@medyll/idae-idbql)
|
|
|
29
169
|
|
|
30
170
|
| Module | Purpose |
|
|
31
171
|
|
|
32
|
-
## 🚀 Quick Start
|
|
33
|
-
import { createIdbqDb, type IdbqModel } from '@medyll/idae-idbql';
|
|
34
172
|
|
|
35
|
-
|
|
36
|
-
index: 'id',
|
|
37
|
-
presentation: 'name',
|
|
38
|
-
fields: {
|
|
39
|
-
id: 'id (readonly)',
|
|
40
|
-
name: 'text (required)',
|
|
41
|
-
code: 'text (required)',
|
|
42
|
-
model: 'text',
|
|
43
|
-
prompt: 'text-long',
|
|
44
|
-
created_at: 'date (private)',
|
|
45
|
-
ia_lock: 'boolean (private)'
|
|
46
|
-
},
|
|
47
|
-
fks: {
|
|
48
|
-
agentPrompt: {
|
|
49
|
-
code: 'agentPrompt',
|
|
50
|
-
multiple: true,
|
|
51
|
-
rules: 'readonly private'
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
}
|
|
173
|
+
## 🚀 Quick Start: App Initialization
|
|
56
174
|
|
|
57
|
-
|
|
175
|
+
The recommended way to initialize your app is to use the `Machine` class, which centralizes schema, collections, and IndexedDB access.
|
|
176
|
+
|
|
177
|
+
```typescript
|
|
178
|
+
import { Machine } from '@medyll/idae-machine';
|
|
179
|
+
import { schemeModel } from '@medyll/idae-machine'; // Or your own model
|
|
180
|
+
|
|
181
|
+
// Create and start the machine
|
|
182
|
+
const machine = new Machine('my-db', 1, schemeModel);
|
|
183
|
+
machine.start();
|
|
184
|
+
|
|
185
|
+
// Access collections, database, and models
|
|
186
|
+
const collections = machine.collections;
|
|
187
|
+
const idbql = machine.idbql;
|
|
188
|
+
const idbqlState = machine.idbqlState;
|
|
189
|
+
const db = machine.indexedb;
|
|
190
|
+
const model = machine.idbqModel;
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
You can now pass `collections` and other instances to Svelte components for CRUD, data listing, and editing.
|
|
194
|
+
|
|
195
|
+
---
|
|
196
|
+
|
|
197
|
+
### Legacy/Direct Usage (not recommended)
|
|
198
|
+
You can still use `createIdbqDb` directly if you need low-level access:
|
|
199
|
+
|
|
200
|
+
```typescript
|
|
201
|
+
import { createIdbqDb, type IdbqModel } from '@medyll/idae-idbql';
|
|
202
|
+
const idbqlState = createIdbqDb(schemeModel);
|
|
58
203
|
```
|
|
59
204
|
|
|
60
205
|
### 2. Use CRUD Components
|
|
@@ -160,24 +305,26 @@ fields: {
|
|
|
160
305
|
```
|
|
161
306
|
|
|
162
307
|
|
|
163
|
-
## 🛡️ Robustness & Test Coverage
|
|
164
308
|
|
|
165
|
-
|
|
309
|
+
## 🛡️ Robustness, Coverage & Performance
|
|
166
310
|
|
|
167
|
-
|
|
168
|
-
- **
|
|
169
|
-
- **
|
|
170
|
-
- **
|
|
311
|
+
Tout le cœur métier (`dbFields.ts`, `machine.ts`, etc.) est testé et optimisé :
|
|
312
|
+
- **Parsing de schéma** : tous les types et modificateurs sont gérés
|
|
313
|
+
- **Relations** : FK et reverse-FK typés et testés
|
|
314
|
+
- **Tests unitaires** : chaque méthode exportée est couverte (Vitest)
|
|
315
|
+
- **Svelte 5** : conformité stricte aux conventions
|
|
316
|
+
- **Gestion d’erreur** : exceptions typées, robustesse transactionnelle
|
|
317
|
+
- **Performance** : indexes, requêtes optimisées, conseils intégrés
|
|
171
318
|
|
|
172
|
-
###
|
|
173
|
-
- ✅
|
|
174
|
-
- ✅
|
|
175
|
-
- ✅
|
|
176
|
-
- ✅
|
|
177
|
-
- ✅ Svelte 5
|
|
178
|
-
- 🔄
|
|
179
|
-
- 🔄
|
|
180
|
-
- ⏳
|
|
319
|
+
### Focus actuel
|
|
320
|
+
- ✅ Déclaration de schéma & typage
|
|
321
|
+
- ✅ Intégration IndexedDB avancée
|
|
322
|
+
- ✅ Export de composants & structure modulaire
|
|
323
|
+
- ✅ Couverture de tests exhaustive
|
|
324
|
+
- ✅ Politique Svelte 5
|
|
325
|
+
- 🔄 Validation de formulaire (en cours)
|
|
326
|
+
- 🔄 Pipeline de rendu de champ
|
|
327
|
+
- ⏳ Workflows CRUD end-to-end
|
|
181
328
|
|
|
182
329
|
## 🧪 Testing Policy
|
|
183
330
|
|