@medyll/idae-machine 0.121.0 → 0.122.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.
|
@@ -41,8 +41,8 @@ import {machine } from '../main/machine.js';
|
|
|
41
41
|
|
|
42
42
|
let collections = machine.collections;
|
|
43
43
|
let store = machine.store;
|
|
44
|
-
let fieldValues = machine.collections.
|
|
45
|
-
let index = collections.
|
|
44
|
+
let fieldValues = machine.collections.collection(collection).collectionValues() ;
|
|
45
|
+
let index = collections.collection(collection).getIndexName();
|
|
46
46
|
|
|
47
47
|
let qy = $derived(where ? store[collection].where(where) : store[collection].getAll());
|
|
48
48
|
|
|
@@ -34,8 +34,8 @@
|
|
|
34
34
|
data = data ?? ({} as COL);
|
|
35
35
|
|
|
36
36
|
// Initialisation des valeurs de champ de collection
|
|
37
|
-
const forge = machine.collections.
|
|
38
|
-
let collectionFieldValues = machine.collections.
|
|
37
|
+
const forge = machine.collections.collection(collection).fieldForge(String(fieldName), data)
|
|
38
|
+
let collectionFieldValues = machine.collections.collection(collection).collectionValues()
|
|
39
39
|
let inputDataset = collectionFieldValues.getInputDataSet(fieldName, data);
|
|
40
40
|
|
|
41
41
|
// Création d'une instance de forge de champ de collection
|
package/dist/main/machineDb.d.ts
CHANGED
|
@@ -45,20 +45,6 @@ export type IDbForge = {
|
|
|
45
45
|
*/
|
|
46
46
|
export declare class IDbBase {
|
|
47
47
|
#private;
|
|
48
|
-
/**
|
|
49
|
-
* Public: Get the foreign keys (fks) object for a collection.
|
|
50
|
-
*/
|
|
51
|
-
getCollectionTemplateFks(collection: TplCollectionName): {
|
|
52
|
-
[x: string]: {
|
|
53
|
-
code: string;
|
|
54
|
-
multiple: boolean;
|
|
55
|
-
rules: import("@medyll/idae-idbql").CombinedArgs;
|
|
56
|
-
} | undefined;
|
|
57
|
-
};
|
|
58
|
-
/**
|
|
59
|
-
* Public: Get the value of the index field for a given data object.
|
|
60
|
-
*/
|
|
61
|
-
indexValue(collection: TplCollectionName, data: object): unknown;
|
|
62
48
|
/**
|
|
63
49
|
* The database model (schema) used for introspection.
|
|
64
50
|
*/
|
|
@@ -71,7 +57,11 @@ export declare class IDbBase {
|
|
|
71
57
|
/**
|
|
72
58
|
* Get an IDbCollection instance for a collection name.
|
|
73
59
|
*/
|
|
74
|
-
|
|
60
|
+
collection(collection: TplCollectionName): IDbCollection;
|
|
61
|
+
/**
|
|
62
|
+
* Public: Get the value of the index field for a given data object.
|
|
63
|
+
*/
|
|
64
|
+
indexValue(collection: TplCollectionName, data: object): unknown;
|
|
75
65
|
/**
|
|
76
66
|
* Get an IDbCollectionValues instance for a collection name.
|
|
77
67
|
*/
|
|
@@ -88,10 +78,6 @@ export declare class IDbBase {
|
|
|
88
78
|
* Get an IDbFormValidate instance for a collection name.
|
|
89
79
|
*/
|
|
90
80
|
formValidate(collection: TplCollectionName): IDbFormValidate;
|
|
91
|
-
/**
|
|
92
|
-
* Parse all collections in the model and return their fields as IDbForge objects.
|
|
93
|
-
*/
|
|
94
|
-
parseAllCollections(): Record<string, Record<string, IDbForge | undefined> | undefined>;
|
|
95
81
|
/**
|
|
96
82
|
* Parse all fields of a given collection.
|
|
97
83
|
*/
|
|
@@ -100,17 +86,6 @@ export declare class IDbBase {
|
|
|
100
86
|
* Parse a single field of a collection and return its IDbForge metadata.
|
|
101
87
|
*/
|
|
102
88
|
parseCollectionFieldName(collection: TplCollectionName, fieldName: keyof TplFields): IDbForge | undefined;
|
|
103
|
-
/**
|
|
104
|
-
* Internal helper to construct an IDbForge object from its components.
|
|
105
|
-
*/
|
|
106
|
-
private forge;
|
|
107
|
-
getCollection(collection: TplCollectionName): CollectionModel;
|
|
108
|
-
getCollectionModel(collection: TplCollectionName): CollectionModel;
|
|
109
|
-
getCollectionModelTemplate(collection: TplCollectionName): Tpl;
|
|
110
|
-
getCollectionModelTemplateFks(collection: TplCollectionName): Tpl["fks"];
|
|
111
|
-
getIndexName(collection: TplCollectionName): string;
|
|
112
|
-
getCollectionTemplateFields(collection: TplCollectionName): TplFields;
|
|
113
|
-
getTemplatePresentation(collection: TplCollectionName): string;
|
|
114
89
|
getFkFieldType(string: `${string}.${string}`): IDbFieldRules | undefined;
|
|
115
90
|
getFkTemplateFields(string: `${string}.${string}`): {
|
|
116
91
|
[x: string]: import("@medyll/idae-idbql").TplFieldRules;
|
|
@@ -124,19 +99,22 @@ export declare class IDbBase {
|
|
|
124
99
|
reverseFks(targetCollection: TplCollectionName): Record<string, any>;
|
|
125
100
|
iterateArrayField(collection: TplCollectionName, fieldName: keyof TplFields, data: any[]): IDbForge[];
|
|
126
101
|
iterateObjectField(collection: TplCollectionName, fieldName: keyof TplFields, data: Record<string, any>): IDbForge[];
|
|
102
|
+
/**
|
|
103
|
+
* Internal helper to construct an IDbForge object from its components.
|
|
104
|
+
*/
|
|
105
|
+
private forge;
|
|
127
106
|
}
|
|
128
107
|
export declare class IDbCollection {
|
|
129
108
|
collection: TplCollectionName;
|
|
130
109
|
_dbCollections: IDbBase;
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
};
|
|
110
|
+
model: IdbqModel["Collection"];
|
|
111
|
+
constructor(collection: TplCollectionName, dbCollections: IDbBase, model: IdbqModel);
|
|
112
|
+
getModel(): CollectionModel<Record<string, any>>;
|
|
113
|
+
getFields(): TplFields;
|
|
114
|
+
getPresentation(): string;
|
|
115
|
+
getFieldRule(fieldName: keyof TplFields): IDbFieldRules | undefined;
|
|
116
|
+
getModelTemplate(): Tpl;
|
|
117
|
+
getModelTemplateFks(): Tpl["fks"];
|
|
140
118
|
getIndexName(): string;
|
|
141
119
|
collectionValues(): IDbCollectionValues<any>;
|
|
142
120
|
collectionFieldValues<T extends Record<string, any>>(data: T): IDbCollectionFieldValues<T>;
|
package/dist/main/machineDb.js
CHANGED
|
@@ -52,20 +52,6 @@ class IDbError extends Error {
|
|
|
52
52
|
* Used for dynamic UI generation, validation, and schema-driven logic.
|
|
53
53
|
*/
|
|
54
54
|
export class IDbBase {
|
|
55
|
-
/**
|
|
56
|
-
* Public: Get the foreign keys (fks) object for a collection.
|
|
57
|
-
*/
|
|
58
|
-
getCollectionTemplateFks(collection) {
|
|
59
|
-
return this.getCollectionModelTemplateFks(collection);
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Public: Get the value of the index field for a given data object.
|
|
63
|
-
*/
|
|
64
|
-
indexValue(collection, data) {
|
|
65
|
-
const indexName = this.getIndexName(collection);
|
|
66
|
-
// @ts-ignore
|
|
67
|
-
return data && typeof data === 'object' && indexName && data[indexName];
|
|
68
|
-
}
|
|
69
55
|
/**
|
|
70
56
|
* The database model (schema) used for introspection.
|
|
71
57
|
*/
|
|
@@ -80,8 +66,15 @@ export class IDbBase {
|
|
|
80
66
|
/**
|
|
81
67
|
* Get an IDbCollection instance for a collection name.
|
|
82
68
|
*/
|
|
83
|
-
|
|
84
|
-
return new IDbCollection(collection, this);
|
|
69
|
+
collection(collection) {
|
|
70
|
+
return new IDbCollection(collection, this, this.model);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Public: Get the value of the index field for a given data object.
|
|
74
|
+
*/
|
|
75
|
+
indexValue(collection, data) {
|
|
76
|
+
const indexName = new IDbCollection(collection, this, this.model).getIndexName();
|
|
77
|
+
return data && typeof data === 'object' && indexName && data[indexName];
|
|
85
78
|
}
|
|
86
79
|
/**
|
|
87
80
|
* Get an IDbCollectionValues instance for a collection name.
|
|
@@ -107,21 +100,11 @@ export class IDbBase {
|
|
|
107
100
|
formValidate(collection) {
|
|
108
101
|
return new IDbFormValidate(collection, this);
|
|
109
102
|
}
|
|
110
|
-
/**
|
|
111
|
-
* Parse all collections in the model and return their fields as IDbForge objects.
|
|
112
|
-
*/
|
|
113
|
-
parseAllCollections() {
|
|
114
|
-
let out = {};
|
|
115
|
-
Object.keys(this.model).forEach((collection) => {
|
|
116
|
-
out[collection] = this.parseRawCollection(collection);
|
|
117
|
-
});
|
|
118
|
-
return out;
|
|
119
|
-
}
|
|
120
103
|
/**
|
|
121
104
|
* Parse all fields of a given collection.
|
|
122
105
|
*/
|
|
123
106
|
parseRawCollection(collection) {
|
|
124
|
-
const fields = this.
|
|
107
|
+
const fields = new IDbCollection(collection, this, this.model).getFields();
|
|
125
108
|
if (!fields)
|
|
126
109
|
return;
|
|
127
110
|
const out = {};
|
|
@@ -149,38 +132,10 @@ export class IDbBase {
|
|
|
149
132
|
const fieldType = array ?? object ?? fk ?? primitive;
|
|
150
133
|
return this.forge({ collection, fieldName, ...fieldType });
|
|
151
134
|
}
|
|
152
|
-
|
|
153
|
-
* Internal helper to construct an IDbForge object from its components.
|
|
154
|
-
*/
|
|
155
|
-
forge({ collection, fieldName, fieldType, fieldRule, fieldArgs, is }) {
|
|
156
|
-
return { collection, fieldName, fieldType, fieldRule, fieldArgs, is };
|
|
157
|
-
}
|
|
158
|
-
#getModel() {
|
|
159
|
-
return this.model;
|
|
160
|
-
}
|
|
161
|
-
getCollection(collection) {
|
|
162
|
-
return this.#getModel()[String(collection)];
|
|
163
|
-
}
|
|
164
|
-
getCollectionModel(collection) {
|
|
165
|
-
return this.#getModel()[String(collection)];
|
|
166
|
-
}
|
|
167
|
-
getCollectionModelTemplate(collection) {
|
|
168
|
-
return this.getCollectionModel(collection)['template'];
|
|
169
|
-
}
|
|
170
|
-
getCollectionModelTemplateFks(collection) {
|
|
171
|
-
return this.getCollectionModel(collection)['template']?.fks;
|
|
172
|
-
}
|
|
173
|
-
getIndexName(collection) {
|
|
174
|
-
return this.getCollectionModel(collection)?.template?.index;
|
|
175
|
-
}
|
|
176
|
-
getCollectionTemplateFields(collection) {
|
|
177
|
-
return this.getCollectionModelTemplate(collection)?.fields;
|
|
178
|
-
}
|
|
179
|
-
getTemplatePresentation(collection) {
|
|
180
|
-
return this.getCollectionModelTemplate(collection)?.presentation;
|
|
181
|
-
}
|
|
135
|
+
// Toutes ces méthodes sont maintenant dans IDbCollection
|
|
182
136
|
#getTemplateFieldRule(collection, fieldName) {
|
|
183
|
-
|
|
137
|
+
// Utilise la nouvelle API orientée collection
|
|
138
|
+
return new IDbCollection(collection, this, this.model).getFieldRule(fieldName);
|
|
184
139
|
}
|
|
185
140
|
getFkFieldType(string) {
|
|
186
141
|
const [collection, field] = string.split('.');
|
|
@@ -189,7 +144,7 @@ export class IDbBase {
|
|
|
189
144
|
}
|
|
190
145
|
getFkTemplateFields(string) {
|
|
191
146
|
const [collection, field] = string.split('.');
|
|
192
|
-
return this.
|
|
147
|
+
return this.collection(collection).getModelTemplate()?.fields;
|
|
193
148
|
}
|
|
194
149
|
testIs(what, fieldRule) {
|
|
195
150
|
const typeMappings = { fk: 'fk-', array: 'array-of-', object: 'object-', primitive: '' };
|
|
@@ -246,7 +201,7 @@ export class IDbBase {
|
|
|
246
201
|
return { fieldType, fieldRule, fieldArgs, is: type };
|
|
247
202
|
}
|
|
248
203
|
fks(collection) {
|
|
249
|
-
let fks = this.
|
|
204
|
+
let fks = this.collection(collection).getModelTemplateFks();
|
|
250
205
|
let out = {};
|
|
251
206
|
if (fks) {
|
|
252
207
|
Object.keys(fks).forEach((collection) => {
|
|
@@ -257,7 +212,7 @@ export class IDbBase {
|
|
|
257
212
|
}
|
|
258
213
|
reverseFks(targetCollection) {
|
|
259
214
|
const result = {};
|
|
260
|
-
Object.entries(this
|
|
215
|
+
Object.entries(this.model).forEach(([collectionName, collectionModel]) => {
|
|
261
216
|
const template = collectionModel.template;
|
|
262
217
|
if (template && template.fks) {
|
|
263
218
|
Object.entries(template.fks).forEach(([fkName, fkConfig]) => {
|
|
@@ -286,23 +241,44 @@ export class IDbBase {
|
|
|
286
241
|
}
|
|
287
242
|
return Object.keys(data).map((key) => ({ ...fieldInfo, fieldName: `${String(fieldName)}.${key}` }));
|
|
288
243
|
}
|
|
244
|
+
/**
|
|
245
|
+
* Internal helper to construct an IDbForge object from its components.
|
|
246
|
+
*/
|
|
247
|
+
forge({ collection, fieldName, fieldType, fieldRule, fieldArgs, is }) {
|
|
248
|
+
return { collection, fieldName, fieldType, fieldRule, fieldArgs, is };
|
|
249
|
+
}
|
|
289
250
|
}
|
|
290
251
|
/* Single collection relies on IDbBase */
|
|
291
252
|
export class IDbCollection {
|
|
253
|
+
// --- NOUVELLES MÉTHODES MIGRÉES DE IDbBase ---
|
|
292
254
|
collection;
|
|
293
255
|
_dbCollections;
|
|
294
|
-
|
|
256
|
+
model;
|
|
257
|
+
constructor(collection, dbCollections, model) {
|
|
295
258
|
this.collection = collection;
|
|
296
259
|
this._dbCollections = dbCollections;
|
|
260
|
+
this.model = model[String(collection)];
|
|
261
|
+
}
|
|
262
|
+
getModel() {
|
|
263
|
+
return this.model;
|
|
264
|
+
}
|
|
265
|
+
getFields() {
|
|
266
|
+
return this.getModelTemplate()?.fields;
|
|
267
|
+
}
|
|
268
|
+
getPresentation() {
|
|
269
|
+
return this.getModelTemplate()?.presentation;
|
|
270
|
+
}
|
|
271
|
+
getFieldRule(fieldName) {
|
|
272
|
+
return this.getFields()?.[String(fieldName)];
|
|
297
273
|
}
|
|
298
|
-
|
|
299
|
-
return this.
|
|
274
|
+
getModelTemplate() {
|
|
275
|
+
return this.model['template'];
|
|
300
276
|
}
|
|
301
|
-
|
|
302
|
-
return this.
|
|
277
|
+
getModelTemplateFks() {
|
|
278
|
+
return this.model['template']?.fks;
|
|
303
279
|
}
|
|
304
280
|
getIndexName() {
|
|
305
|
-
return this.
|
|
281
|
+
return this.getModelTemplate()?.index;
|
|
306
282
|
}
|
|
307
283
|
collectionValues() {
|
|
308
284
|
return this._dbCollections.collectionValues(this.collection);
|
|
@@ -367,7 +343,7 @@ export class IDbCollectionValues {
|
|
|
367
343
|
presentation(data) {
|
|
368
344
|
try {
|
|
369
345
|
this.#checkError(!this.#checkAccess(), 'Access denied', 'ACCESS_DENIED');
|
|
370
|
-
const presentation = this.idbBase.
|
|
346
|
+
const presentation = this.idbBase.collection(this.collectionName).getPresentation();
|
|
371
347
|
this.#checkError(!presentation, 'Presentation template not found', 'TEMPLATE_NOT_FOUND');
|
|
372
348
|
const fields = presentation.split(' ');
|
|
373
349
|
return fields
|
|
@@ -390,7 +366,7 @@ export class IDbCollectionValues {
|
|
|
390
366
|
indexValue(data) {
|
|
391
367
|
try {
|
|
392
368
|
this.#checkError(!this.#checkAccess(), 'Access denied', 'ACCESS_DENIED');
|
|
393
|
-
const indexName = this.idbBase.
|
|
369
|
+
const indexName = this.idbBase.collection(this.collectionName).getIndexName();
|
|
394
370
|
this.#checkError(!indexName, 'Index not found for collection', 'INDEX_NOT_FOUND');
|
|
395
371
|
this.#checkError(!(indexName in data), `Index field ${indexName} not found in data`, 'FIELD_NOT_FOUND');
|
|
396
372
|
return data[indexName];
|
|
@@ -441,7 +417,7 @@ export class IDbCollectionValues {
|
|
|
441
417
|
const fieldInfo = this.idbBase.parseCollectionFieldName(this.collectionName, fieldName);
|
|
442
418
|
const fieldType = fieldInfo?.fieldType ?? '';
|
|
443
419
|
const fieldArgs = fieldInfo?.fieldArgs?.join(' ') ?? '';
|
|
444
|
-
const indexName = this.idbBase.
|
|
420
|
+
const indexName = this.idbBase.collection(this.collectionName).getIndexName();
|
|
445
421
|
return {
|
|
446
422
|
'data-collection': this.collectionName,
|
|
447
423
|
'data-collectionId': indexName && data?.[indexName] !== undefined ? String(data?.[indexName]) : '',
|
|
@@ -712,7 +688,7 @@ export class IDbFormValidate {
|
|
|
712
688
|
const errors = {};
|
|
713
689
|
const invalidFields = [];
|
|
714
690
|
let isValid = true;
|
|
715
|
-
const fields = this.idbCollections.
|
|
691
|
+
const fields = this.idbCollections.collection(this.collection).getModelTemplate().fields;
|
|
716
692
|
if (!fields) {
|
|
717
693
|
return {
|
|
718
694
|
isValid: false,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@medyll/idae-machine",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.122.0",
|
|
4
4
|
"files": [
|
|
5
5
|
"dist",
|
|
6
6
|
"!dist/**/*.test.*",
|
|
@@ -49,8 +49,8 @@
|
|
|
49
49
|
"scope": "@medyll",
|
|
50
50
|
"dependencies": {
|
|
51
51
|
"@huggingface/prettier-plugin-vertical-align": "^0.2.3",
|
|
52
|
-
"@medyll/idae-slotui-svelte": "0.
|
|
53
|
-
"@medyll/idae-idbql": "0.
|
|
52
|
+
"@medyll/idae-slotui-svelte": "0.175.0",
|
|
53
|
+
"@medyll/idae-idbql": "0.172.0"
|
|
54
54
|
},
|
|
55
55
|
"scripts": {
|
|
56
56
|
"dev": "vite dev",
|