@medyll/idae-machine 0.105.0 → 0.107.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.
@@ -38,46 +38,220 @@ export type IDbForge = {
38
38
  fieldArgs?: IDbForgeArgs | undefined;
39
39
  is: any;
40
40
  };
41
+ /**
42
+ * Central class for parsing, introspecting, and extracting metadata from the database schema.
43
+ * Provides methods to access collections, templates, fields, foreign keys, and type information.
44
+ * Used for dynamic UI generation, validation, and schema-driven logic.
45
+ */
41
46
  export declare class IDbCollections {
42
47
  #private;
48
+ /**
49
+ * The database model (schema) used for introspection.
50
+ */
43
51
  model: IdbqModel;
52
+ /**
53
+ * Create a new IDbCollections instance.
54
+ * @param model Optional custom model to use (default: schemeModel)
55
+ */
44
56
  constructor(model?: IdbqModel);
57
+ /**
58
+ * Parse all collections in the model and return their fields as IDbForge objects.
59
+ * @returns An object mapping collection names to their parsed fields.
60
+ */
45
61
  parseAllCollections(): Record<string, Record<string, IDbForge | undefined> | undefined>;
62
+ /**
63
+ * Parse all fields of a given collection.
64
+ * @param collection The collection name.
65
+ * @returns An object mapping field names to their IDbForge representation.
66
+ */
46
67
  parseRawCollection(collection: TplCollectionName): Record<string, IDbForge | undefined> | undefined;
68
+ /**
69
+ * Parse a single field of a collection and return its IDbForge metadata.
70
+ * @param collection The collection name.
71
+ * @param fieldName The field name.
72
+ * @returns The IDbForge object for the field, or throws if not found.
73
+ */
47
74
  parseCollectionFieldName(collection: TplCollectionName, fieldName: keyof TplFields): IDbForge | undefined;
75
+ /**
76
+ * Parse a field rule string and extract its type and arguments.
77
+ * @param fieldRule The field rule string.
78
+ * @returns Partial IDbForge info for the rule.
79
+ */
48
80
  parsFieldRule(fieldRule: IDbFieldRules): Partial<IDbForge> | undefined;
81
+ /**
82
+ * Internal helper to construct an IDbForge object from its components.
83
+ * @param params The IDbForge properties (collection, fieldName, fieldType, fieldRule, fieldArgs, is).
84
+ * @returns The constructed IDbForge object.
85
+ */
49
86
  private forge;
87
+ /**
88
+ * Get the collection object from the model.
89
+ * @param collection The collection name.
90
+ * @returns The collection object.
91
+ */
50
92
  getCollection(collection: TplCollectionName): CollectionModel;
93
+ /**
94
+ * Get the template object for a collection.
95
+ * @param collection The collection name.
96
+ * @returns The template object.
97
+ */
51
98
  getCollectionTemplate(collection: TplCollectionName): Tpl;
99
+ /**
100
+ * Get the foreign keys (fks) object for a collection.
101
+ * @param collection The collection name.
102
+ * @returns The fks object.
103
+ */
52
104
  getCollectionTemplateFks(collection: TplCollectionName): Tpl["fks"];
105
+ /**
106
+ * Get the index field name for a collection.
107
+ * @param collection The collection name.
108
+ * @returns The index field name.
109
+ */
53
110
  getIndexName(collection: string): string;
111
+ /**
112
+ * Get the fields object for a collection.
113
+ * @param collection The collection name.
114
+ * @returns The fields object.
115
+ */
54
116
  getCollectionTemplateFields(collection: TplCollectionName): TplFields;
117
+ /**
118
+ * Get the presentation string for a collection (used for display).
119
+ * @param collection The collection name.
120
+ * @returns The presentation string.
121
+ */
55
122
  getTemplatePresentation(collection: TplCollectionName): string;
123
+ /**
124
+ * Get the field rule for a foreign key field (e.g. 'collection.field').
125
+ * @param string The string in the form 'collection.field'.
126
+ * @returns The field rule string, or undefined.
127
+ */
56
128
  getFkFieldType(string: `${string}.${string}`): IDbFieldRules | undefined;
129
+ /**
130
+ * Get the fields object for a foreign key collection.
131
+ * @param string The string in the form 'collection.field'.
132
+ * @returns The fields object for the referenced collection.
133
+ */
57
134
  getFkTemplateFields(string: `${string}.${string}`): {
58
135
  [x: string]: import("@medyll/idae-idbql").TplFieldRules;
59
136
  };
137
+ /**
138
+ * Test if a field rule matches a given type (primitive, array, object, fk).
139
+ * @param what The type to test ('primitive', 'array', 'object', 'fk').
140
+ * @param fieldRule The field rule string.
141
+ * @returns Partial IDbForge info if match, else undefined.
142
+ */
60
143
  private testIs;
144
+ /**
145
+ * Extract type information for a field rule.
146
+ * @param what The type to extract ('primitive', 'array', 'object', 'fk').
147
+ * @param fieldRule The field rule string.
148
+ * @returns Partial IDbForge info.
149
+ */
61
150
  is(what: 'array' | 'object' | 'fk' | 'primitive', fieldRule: IDbFieldRules): Partial<IDbForge>;
151
+ /**
152
+ * Get the value of the index field for a given data object.
153
+ * @param collection The collection name.
154
+ * @param data The data object.
155
+ * @returns The value of the index field.
156
+ */
62
157
  indexValue(collection: TplCollectionName, data: Record<string, any>): any;
158
+ /**
159
+ * Extracts type, rule, and argument information from a field rule string.
160
+ * @param type The type to extract ('primitive', 'array', 'object', 'fk').
161
+ * @param fieldRule The field rule string.
162
+ * @returns Partial IDbForge info.
163
+ */
63
164
  extract(type: 'array' | 'object' | 'fk' | 'primitive', fieldRule: IDbFieldRules): Partial<IDbForge>;
165
+ /**
166
+ * Parse and return all foreign key collections referenced by a collection.
167
+ * @param collection The collection name.
168
+ * @returns An object mapping referenced collection names to their parsed fields.
169
+ */
64
170
  fks(collection: string): {
65
171
  [collection: string]: Tpl;
66
172
  };
173
+ /**
174
+ * Find all collections that reference the target collection via a foreign key.
175
+ * @param targetCollection The collection name to search for as a target.
176
+ * @returns An object mapping referencing collections to their fk configs.
177
+ */
67
178
  reverseFks(targetCollection: TplCollectionName): Record<string, any>;
179
+ /**
180
+ * Iterate over an array field and return an array of IDbForge objects for each element.
181
+ * @param collection The collection name.
182
+ * @param fieldName The field name.
183
+ * @param data The array data.
184
+ * @returns An array of IDbForge objects.
185
+ */
68
186
  iterateArrayField(collection: TplCollectionName, fieldName: keyof TplFields, data: any[]): IDbForge[];
187
+ /**
188
+ * Iterate over an object field and return an array of IDbForge objects for each property.
189
+ * @param collection The collection name.
190
+ * @param fieldName The field name.
191
+ * @param data The object data.
192
+ * @returns An array of IDbForge objects.
193
+ */
69
194
  iterateObjectField(collection: TplCollectionName, fieldName: keyof TplFields, data: Record<string, any>): IDbForge[];
70
195
  }
196
+ /**
197
+ * Utility class to display and format field values for a collection, based on the schema and provided data.
198
+ * Used for dynamic UI rendering, presentation, and extracting metadata for form generation.
199
+ * @template T The data type for the collection.
200
+ */
71
201
  export declare class IDbCollectionValues<T extends Record<string, any>> {
72
202
  #private;
203
+ /**
204
+ * The IDbCollections instance used for schema introspection.
205
+ */
73
206
  dbCollections: IDbCollections;
207
+ /**
208
+ * The collection name this instance operates on.
209
+ */
74
210
  private collection;
211
+ /**
212
+ * Create a new IDbCollectionValues instance for a given collection.
213
+ * @param collection The collection name.
214
+ */
75
215
  constructor(collection: TplCollectionName);
216
+ /**
217
+ * Get the presentation string for a data object, using the collection's presentation template.
218
+ * @param data The data object.
219
+ * @returns The formatted presentation string.
220
+ */
76
221
  presentation(data: Record<string, any>): string;
222
+ /**
223
+ * Get the value of the index field for a data object.
224
+ * @param data The data object.
225
+ * @returns The value of the index field, or null if not found.
226
+ */
77
227
  indexValue(data: Record<string, any>): any | null;
228
+ /**
229
+ * Format a field value for display, using the field type and schema.
230
+ * @param fieldName The field name.
231
+ * @param data The data object.
232
+ * @returns The formatted value as a string.
233
+ */
78
234
  format(fieldName: keyof T, data: T): string;
235
+ /**
236
+ * Get a set of data-* attributes for a field, for use in form generation or UI.
237
+ * @param fieldName The field name.
238
+ * @param data The data object.
239
+ * @returns An object with data-* attributes for the field.
240
+ */
79
241
  getInputDataSet(fieldName: string, data: T): Record<`data-${'collection' | 'collectionId' | 'fieldName' | 'fieldType' | 'fieldArgs'}`, string>;
242
+ /**
243
+ * Iterate over an array field and return an array of IDbForge objects for each element.
244
+ * @param fieldName The field name.
245
+ * @param data The array data.
246
+ * @returns An array of IDbForge objects.
247
+ */
80
248
  iterateArrayField(fieldName: keyof TplFields, data: any[]): IDbForge[];
249
+ /**
250
+ * Iterate over an object field and return an array of IDbForge objects for each property.
251
+ * @param fieldName The field name.
252
+ * @param data The object data.
253
+ * @returns An array of IDbForge objects.
254
+ */
81
255
  iterateObjectField(fieldName: keyof TplFields, data: Record<string, any>): IDbForge[];
82
256
  }
83
257
  export declare class IDbCollectionFieldValues<T extends Record<string, any>> {
@@ -85,7 +259,6 @@ export declare class IDbCollectionFieldValues<T extends Record<string, any>> {
85
259
  constructor(collection: TplCollectionName, data: T);
86
260
  format(fieldName: keyof T): string | string[];
87
261
  getInputDataSet(fieldName: keyof T): Record<"data-collection" | "data-fieldName" | "data-fieldType" | "data-fieldArgs" | "data-collectionId", string>;
88
- getForge(fieldName: keyof T): IDbForge | undefined;
89
262
  iterateArray(fieldName: string, data: any[]): IDbForge[];
90
263
  iterateObject(fieldName: string, data: Record<string, any>): IDbForge[];
91
264
  }
@@ -114,6 +287,12 @@ export declare class IDbFormValidate {
114
287
  isValid: boolean;
115
288
  error?: string;
116
289
  };
290
+ /**
291
+ * Validate a single field value for a collection.
292
+ * @param fieldName The field name.
293
+ * @param value The value to validate.
294
+ * @returns True if valid, false otherwise.
295
+ */
117
296
  validateFieldValue(fieldName: keyof TplFields, value: any): boolean;
118
297
  validateForm(formData: Record<string, any>, options?: {
119
298
  ignoreFields?: string[] | undefined;
@@ -46,12 +46,27 @@ class IDbError extends Error {
46
46
  }
47
47
  }
48
48
  }
49
- // renammed from IDbFields to IDbCollections
49
+ /**
50
+ * Central class for parsing, introspecting, and extracting metadata from the database schema.
51
+ * Provides methods to access collections, templates, fields, foreign keys, and type information.
52
+ * Used for dynamic UI generation, validation, and schema-driven logic.
53
+ */
50
54
  export class IDbCollections {
55
+ /**
56
+ * The database model (schema) used for introspection.
57
+ */
51
58
  model = schemeModel;
59
+ /**
60
+ * Create a new IDbCollections instance.
61
+ * @param model Optional custom model to use (default: schemeModel)
62
+ */
52
63
  constructor(model) {
53
- this.model = schemeModel; //model ?? this.model;
64
+ this.model = model ?? schemeModel;
54
65
  }
66
+ /**
67
+ * Parse all collections in the model and return their fields as IDbForge objects.
68
+ * @returns An object mapping collection names to their parsed fields.
69
+ */
55
70
  parseAllCollections() {
56
71
  let out = {};
57
72
  Object.keys(this.model).forEach((collection) => {
@@ -59,6 +74,11 @@ export class IDbCollections {
59
74
  });
60
75
  return out;
61
76
  }
77
+ /**
78
+ * Parse all fields of a given collection.
79
+ * @param collection The collection name.
80
+ * @returns An object mapping field names to their IDbForge representation.
81
+ */
62
82
  parseRawCollection(collection) {
63
83
  const fields = this.getCollectionTemplateFields(collection);
64
84
  if (!fields)
@@ -72,18 +92,30 @@ export class IDbCollections {
72
92
  });
73
93
  return out;
74
94
  }
95
+ /**
96
+ * Parse a single field of a collection and return its IDbForge metadata.
97
+ * @param collection The collection name.
98
+ * @param fieldName The field name.
99
+ * @returns The IDbForge object for the field, or throws if not found.
100
+ */
75
101
  parseCollectionFieldName(collection, fieldName) {
76
102
  const field = this.#getTemplateFieldRule(collection, fieldName);
77
103
  if (!field) {
78
104
  IDbError.throwError(`Field ${fieldName} not found in collection ${collection}`, 'FIELD_NOT_FOUND');
79
105
  return undefined;
80
106
  }
81
- const fieldType = this.testIs('primitive', field) ??
82
- this.testIs('array', field) ??
83
- this.testIs('object', field) ??
84
- this.testIs('fk', field);
107
+ const array = this.testIs('array', field);
108
+ const object = this.testIs('object', field);
109
+ const fk = this.testIs('fk', field);
110
+ const primitive = this.testIs('primitive', field);
111
+ const fieldType = array ?? object ?? fk ?? primitive;
85
112
  return this.forge({ collection, fieldName, ...fieldType });
86
113
  }
114
+ /**
115
+ * Parse a field rule string and extract its type and arguments.
116
+ * @param fieldRule The field rule string.
117
+ * @returns Partial IDbForge info for the rule.
118
+ */
87
119
  parsFieldRule(fieldRule) {
88
120
  if (!fieldRule)
89
121
  return;
@@ -93,6 +125,11 @@ export class IDbCollections {
93
125
  this.testIs('fk', fieldRule);
94
126
  return fieldType;
95
127
  }
128
+ /**
129
+ * Internal helper to construct an IDbForge object from its components.
130
+ * @param params The IDbForge properties (collection, fieldName, fieldType, fieldRule, fieldArgs, is).
131
+ * @returns The constructed IDbForge object.
132
+ */
96
133
  forge({ collection, fieldName, fieldType, fieldRule, fieldArgs, is }) {
97
134
  return {
98
135
  collection,
@@ -106,36 +143,82 @@ export class IDbCollections {
106
143
  #getModel() {
107
144
  return this.model;
108
145
  }
146
+ /**
147
+ * Get the collection object from the model.
148
+ * @param collection The collection name.
149
+ * @returns The collection object.
150
+ */
109
151
  getCollection(collection) {
110
152
  return this.#getModel()[String(collection)];
111
153
  }
154
+ /**
155
+ * Get the template object for a collection.
156
+ * @param collection The collection name.
157
+ * @returns The template object.
158
+ */
112
159
  getCollectionTemplate(collection) {
113
160
  return this.getCollection(collection)['template'];
114
161
  }
162
+ /**
163
+ * Get the foreign keys (fks) object for a collection.
164
+ * @param collection The collection name.
165
+ * @returns The fks object.
166
+ */
115
167
  getCollectionTemplateFks(collection) {
116
168
  return this.getCollection(collection)['template']?.fks;
117
169
  }
170
+ /**
171
+ * Get the index field name for a collection.
172
+ * @param collection The collection name.
173
+ * @returns The index field name.
174
+ */
118
175
  getIndexName(collection) {
119
176
  return this.getCollection(collection)?.template?.index;
120
177
  }
178
+ /**
179
+ * Get the fields object for a collection.
180
+ * @param collection The collection name.
181
+ * @returns The fields object.
182
+ */
121
183
  getCollectionTemplateFields(collection) {
122
184
  return this.getCollectionTemplate(collection)?.fields;
123
185
  }
186
+ /**
187
+ * Get the presentation string for a collection (used for display).
188
+ * @param collection The collection name.
189
+ * @returns The presentation string.
190
+ */
124
191
  getTemplatePresentation(collection) {
125
192
  return this.getCollectionTemplate(collection)?.presentation;
126
193
  }
127
194
  #getTemplateFieldRule(collection, fieldName) {
128
195
  return this.getCollectionTemplateFields(collection)?.[String(fieldName)];
129
196
  }
197
+ /**
198
+ * Get the field rule for a foreign key field (e.g. 'collection.field').
199
+ * @param string The string in the form 'collection.field'.
200
+ * @returns The field rule string, or undefined.
201
+ */
130
202
  getFkFieldType(string) {
131
203
  const [collection, field] = string.split('.');
132
204
  let template = this.#getTemplateFieldRule(collection, field);
133
205
  return template;
134
206
  }
207
+ /**
208
+ * Get the fields object for a foreign key collection.
209
+ * @param string The string in the form 'collection.field'.
210
+ * @returns The fields object for the referenced collection.
211
+ */
135
212
  getFkTemplateFields(string) {
136
213
  const [collection, field] = string.split('.');
137
214
  return this.getCollection(collection).template?.fields;
138
215
  }
216
+ /**
217
+ * Test if a field rule matches a given type (primitive, array, object, fk).
218
+ * @param what The type to test ('primitive', 'array', 'object', 'fk').
219
+ * @param fieldRule The field rule string.
220
+ * @returns Partial IDbForge info if match, else undefined.
221
+ */
139
222
  testIs(what, fieldRule) {
140
223
  const typeMappings = {
141
224
  fk: 'fk-',
@@ -144,18 +227,45 @@ export class IDbCollections {
144
227
  primitive: ''
145
228
  };
146
229
  const prefix = typeMappings[what];
230
+ if (what === 'primitive') {
231
+ // Un type primitif ne doit pas commencer par un préfixe array/object/fk
232
+ if (!fieldRule.startsWith('array-of-') &&
233
+ !fieldRule.startsWith('object-') &&
234
+ !fieldRule.startsWith('fk-')) {
235
+ return this.is(what, fieldRule);
236
+ }
237
+ return undefined;
238
+ }
147
239
  if (fieldRule.startsWith(prefix)) {
148
240
  return this.is(what, fieldRule);
149
241
  }
150
242
  return undefined;
151
243
  }
244
+ /**
245
+ * Extract type information for a field rule.
246
+ * @param what The type to extract ('primitive', 'array', 'object', 'fk').
247
+ * @param fieldRule The field rule string.
248
+ * @returns Partial IDbForge info.
249
+ */
152
250
  is(what, fieldRule) {
153
251
  return this.extract(what, fieldRule);
154
252
  }
253
+ /**
254
+ * Get the value of the index field for a given data object.
255
+ * @param collection The collection name.
256
+ * @param data The data object.
257
+ * @returns The value of the index field.
258
+ */
155
259
  indexValue(collection, data) {
156
260
  let presentation = this.getIndexName(collection);
157
261
  return data[presentation];
158
262
  }
263
+ /**
264
+ * Extracts type, rule, and argument information from a field rule string.
265
+ * @param type The type to extract ('primitive', 'array', 'object', 'fk').
266
+ * @param fieldRule The field rule string.
267
+ * @returns Partial IDbForge info.
268
+ */
159
269
  extract(type, fieldRule) {
160
270
  // fieldType
161
271
  function extractAfter(pattern, source) {
@@ -196,6 +306,11 @@ export class IDbCollections {
196
306
  }
197
307
  return { fieldType, fieldRule, fieldArgs, is: type };
198
308
  }
309
+ /**
310
+ * Parse and return all foreign key collections referenced by a collection.
311
+ * @param collection The collection name.
312
+ * @returns An object mapping referenced collection names to their parsed fields.
313
+ */
199
314
  fks(collection) {
200
315
  let fks = this.getCollectionTemplateFks(collection);
201
316
  let out = {};
@@ -207,6 +322,11 @@ export class IDbCollections {
207
322
  }
208
323
  return out;
209
324
  }
325
+ /**
326
+ * Find all collections that reference the target collection via a foreign key.
327
+ * @param targetCollection The collection name to search for as a target.
328
+ * @returns An object mapping referencing collections to their fk configs.
329
+ */
210
330
  reverseFks(targetCollection) {
211
331
  const result = {};
212
332
  Object.entries(this.#getModel()).forEach(([collectionName, collectionModel]) => {
@@ -225,31 +345,70 @@ export class IDbCollections {
225
345
  return result;
226
346
  }
227
347
  // iterate base
348
+ /**
349
+ * Iterate over an array field and return an array of IDbForge objects for each element.
350
+ * @param collection The collection name.
351
+ * @param fieldName The field name.
352
+ * @param data The array data.
353
+ * @returns An array of IDbForge objects.
354
+ */
228
355
  iterateArrayField(collection, fieldName, data) {
229
356
  const fieldInfo = this.parseCollectionFieldName(collection, fieldName);
230
357
  if (fieldInfo?.is !== 'array' || !Array.isArray(data)) {
231
358
  return [];
232
359
  }
233
- return data.map(() => this.parseCollectionFieldName(collection, fieldName));
360
+ // Retourne un tableau d'objets IDbForge génériques pour chaque élément
361
+ return data.map((_, idx) => ({
362
+ ...fieldInfo,
363
+ fieldName: `${String(fieldName)}[${idx}]`,
364
+ }));
234
365
  }
366
+ /**
367
+ * Iterate over an object field and return an array of IDbForge objects for each property.
368
+ * @param collection The collection name.
369
+ * @param fieldName The field name.
370
+ * @param data The object data.
371
+ * @returns An array of IDbForge objects.
372
+ */
235
373
  iterateObjectField(collection, fieldName, data) {
236
374
  const fieldInfo = this.parseCollectionFieldName(collection, fieldName);
237
- if (fieldInfo?.is !== 'object' || typeof data !== 'object') {
375
+ if (fieldInfo?.is !== 'object' || typeof data !== 'object' || data === null) {
238
376
  return [];
239
377
  }
240
- return Object.keys(data).map((key) => this.parseCollectionFieldName(collection, key));
378
+ // Retourne un tableau d'objets IDbForge génériques pour chaque clé
379
+ return Object.keys(data).map((key) => ({
380
+ ...fieldInfo,
381
+ fieldName: `${String(fieldName)}.${key}`,
382
+ }));
241
383
  }
242
384
  }
243
- // display field values, based on schema and provided data
244
- // renamed from iDBFieldValues to iDbCollectionValues
245
- // path D:\boulot\python\wollama\src\lib\db\dbFields.ts
385
+ /**
386
+ * Utility class to display and format field values for a collection, based on the schema and provided data.
387
+ * Used for dynamic UI rendering, presentation, and extracting metadata for form generation.
388
+ * @template T The data type for the collection.
389
+ */
246
390
  export class IDbCollectionValues {
391
+ /**
392
+ * The IDbCollections instance used for schema introspection.
393
+ */
247
394
  dbCollections;
395
+ /**
396
+ * The collection name this instance operates on.
397
+ */
248
398
  collection;
399
+ /**
400
+ * Create a new IDbCollectionValues instance for a given collection.
401
+ * @param collection The collection name.
402
+ */
249
403
  constructor(collection) {
250
404
  this.collection = collection;
251
405
  this.dbCollections = new IDbCollections();
252
406
  }
407
+ /**
408
+ * Get the presentation string for a data object, using the collection's presentation template.
409
+ * @param data The data object.
410
+ * @returns The formatted presentation string.
411
+ */
253
412
  presentation(data) {
254
413
  try {
255
414
  this.#checkError(!this.#checkAccess(), 'Access denied', 'ACCESS_DENIED');
@@ -268,6 +427,11 @@ export class IDbCollectionValues {
268
427
  return '';
269
428
  }
270
429
  }
430
+ /**
431
+ * Get the value of the index field for a data object.
432
+ * @param data The data object.
433
+ * @returns The value of the index field, or null if not found.
434
+ */
271
435
  indexValue(data) {
272
436
  try {
273
437
  this.#checkError(!this.#checkAccess(), 'Access denied', 'ACCESS_DENIED');
@@ -281,6 +445,12 @@ export class IDbCollectionValues {
281
445
  return null;
282
446
  }
283
447
  }
448
+ /**
449
+ * Format a field value for display, using the field type and schema.
450
+ * @param fieldName The field name.
451
+ * @param data The data object.
452
+ * @returns The formatted value as a string.
453
+ */
284
454
  format(fieldName, data) {
285
455
  try {
286
456
  this.#checkError(!this.#checkAccess(), 'Access denied', 'ACCESS_DENIED');
@@ -306,6 +476,12 @@ export class IDbCollectionValues {
306
476
  return '';
307
477
  }
308
478
  }
479
+ /**
480
+ * Get a set of data-* attributes for a field, for use in form generation or UI.
481
+ * @param fieldName The field name.
482
+ * @param data The data object.
483
+ * @returns An object with data-* attributes for the field.
484
+ */
309
485
  getInputDataSet(fieldName, data) {
310
486
  const fieldInfo = this.dbCollections.parseCollectionFieldName(this.collection, fieldName);
311
487
  const fieldType = fieldInfo?.fieldType ?? '';
@@ -319,16 +495,39 @@ export class IDbCollectionValues {
319
495
  'data-fieldArgs': fieldArgs
320
496
  };
321
497
  }
498
+ /**
499
+ * Iterate over an array field and return an array of IDbForge objects for each element.
500
+ * @param fieldName The field name.
501
+ * @param data The array data.
502
+ * @returns An array of IDbForge objects.
503
+ */
322
504
  iterateArrayField(fieldName, data) {
323
505
  return this.dbCollections.iterateArrayField(this.collection, fieldName, data);
324
506
  }
507
+ /**
508
+ * Iterate over an object field and return an array of IDbForge objects for each property.
509
+ * @param fieldName The field name.
510
+ * @param data The object data.
511
+ * @returns An array of IDbForge objects.
512
+ */
325
513
  iterateObjectField(fieldName, data) {
326
514
  return this.dbCollections.iterateObjectField(this.collection, fieldName, data);
327
515
  }
516
+ /**
517
+ * Internal: Format a number field for display.
518
+ * @param value The number value.
519
+ * @returns The formatted string.
520
+ */
328
521
  #formatNumberField(value) {
329
522
  // Implement number formatting logic here
330
523
  return value.toString();
331
524
  }
525
+ /**
526
+ * Internal: Format a text field for display, with length limits by type.
527
+ * @param value The string value.
528
+ * @param type The text type (e.g. 'text-short').
529
+ * @returns The formatted string.
530
+ */
332
531
  #formatTextField(value, type) {
333
532
  const lengths = {
334
533
  'text-tiny': 10,
@@ -340,10 +539,20 @@ export class IDbCollectionValues {
340
539
  const maxLength = lengths[type] || value.length;
341
540
  return value.substring(0, maxLength);
342
541
  }
542
+ /**
543
+ * Internal: Check if access is allowed (override for custom logic).
544
+ * @returns True if access is allowed.
545
+ */
343
546
  #checkAccess() {
344
547
  // Implement access check logic here
345
548
  return true;
346
549
  }
550
+ /**
551
+ * Internal: Throw an error if a condition is met.
552
+ * @param condition The condition to check.
553
+ * @param message The error message.
554
+ * @param code The error code.
555
+ */
347
556
  #checkError(condition, message, code) {
348
557
  if (condition) {
349
558
  IDbError.throwError(message, code);
@@ -373,9 +582,9 @@ export class IDbCollectionFieldValues {
373
582
  return this.#collectionValues.getInputDataSet(String(fieldName), this.#data);
374
583
  }
375
584
  // renamed from parseCollectionFieldName
376
- getForge(fieldName) {
377
- return this.#collectionValues.dbCollections.parseCollectionFieldName(this.#collection, String(fieldName));
378
- }
585
+ // get forge(): IDbForge | undefined {
586
+ // return undefined; // Pas de #fieldName dans cette classe, getter non pertinent
587
+ // }
379
588
  iterateArray(fieldName, data) {
380
589
  return this.#collectionValues.iterateArrayField(fieldName, data);
381
590
  }
@@ -509,14 +718,15 @@ export class IDbFormValidate {
509
718
  throw error;
510
719
  }
511
720
  }
721
+ /**
722
+ * Validate a single field value for a collection.
723
+ * @param fieldName The field name.
724
+ * @param value The value to validate.
725
+ * @returns True if valid, false otherwise.
726
+ */
512
727
  validateFieldValue(fieldName, value) {
513
- try {
514
- this.validateField(fieldName, value);
515
- return true;
516
- }
517
- catch {
518
- return false;
519
- }
728
+ const result = this.validateField(fieldName, value);
729
+ return !!result.isValid;
520
730
  }
521
731
  validateForm(formData, options = {}) {
522
732
  const errors = {};
@@ -0,0 +1,56 @@
1
+ import type { DBAgent, DbAgentPrompt } from '$types/db';
2
+ import { type IdbqModel } from '@medyll/idae-idbql';
3
+ import type { DbDataModelTs } from './dataModel.js';
4
+ export declare const schemeModelTestDb: {
5
+ agent: {
6
+ keyPath: string;
7
+ model: DBAgent;
8
+ ts: DBAgent;
9
+ template: {
10
+ index: string;
11
+ presentation: string;
12
+ fields: {
13
+ id: string;
14
+ name: string;
15
+ code: string;
16
+ model: string;
17
+ prompt: string;
18
+ created_at: string;
19
+ ia_lock: string;
20
+ agentPromptId: string;
21
+ tags: string;
22
+ meta: string;
23
+ relatedAgents: string;
24
+ status: string;
25
+ };
26
+ fks: {
27
+ agentPrompt: {
28
+ code: string;
29
+ rules: string;
30
+ multiple: boolean;
31
+ };
32
+ };
33
+ };
34
+ };
35
+ agentPrompt: {
36
+ keyPath: string;
37
+ model: DbAgentPrompt;
38
+ ts: DbAgentPrompt;
39
+ template: {
40
+ index: string;
41
+ presentation: string;
42
+ fields: {
43
+ id: string;
44
+ created_at: string;
45
+ value: string;
46
+ name: string;
47
+ code: string;
48
+ ia_lock: string;
49
+ };
50
+ fks: {};
51
+ };
52
+ };
53
+ };
54
+ export declare const schemeModelTest: IdbqModel;
55
+ export type DataModelTestFinal = DbDataModelTs<typeof schemeModelTestDb>;
56
+ export declare const idbql: import("@medyll/idae-idbql").ReadonlyCollections<IdbqModel<Record<string, Record<string, any>>>>, idbqlState: import("@medyll/idae-idbql").StateCollections<IdbqModel<Record<string, Record<string, any>>>>, idbDatabase: import("@medyll/idae-idbql").IdbqlIndexedCore<IdbqModel<Record<string, Record<string, any>>>>, idbqModel: IdbqModel<Record<string, Record<string, any>>>;
@@ -0,0 +1,58 @@
1
+ import { createIdbqDb } from '@medyll/idae-idbql';
2
+ // Schéma de test (copie explicite de schemeModelDb)
3
+ export const schemeModelTestDb = {
4
+ agent: {
5
+ keyPath: '++id, promptId, created_at',
6
+ model: {},
7
+ ts: {},
8
+ template: {
9
+ index: 'id',
10
+ presentation: 'name model',
11
+ fields: {
12
+ id: 'id (readonly)',
13
+ name: 'text (private)',
14
+ code: 'text',
15
+ model: 'text',
16
+ prompt: 'text-long',
17
+ created_at: 'date (private)',
18
+ ia_lock: 'boolean (private)',
19
+ agentPromptId: 'fk-agentPrompt.id (required)',
20
+ tags: 'array-of-text', // array field
21
+ meta: 'object-any', // object field
22
+ relatedAgents: 'array-of-fk-agent.id', // fk multiple
23
+ status: 'text (required readonly)'
24
+ },
25
+ fks: {
26
+ agentPrompt: {
27
+ code: 'agentPrompt',
28
+ rules: 'readonly private',
29
+ multiple: true
30
+ }
31
+ }
32
+ }
33
+ },
34
+ agentPrompt: {
35
+ keyPath: '++id, created_at',
36
+ model: {},
37
+ ts: {},
38
+ template: {
39
+ index: 'id',
40
+ presentation: 'name',
41
+ fields: {
42
+ id: 'id (readonly)',
43
+ created_at: 'date (private)',
44
+ value: 'text-long (required)',
45
+ name: 'text (required)',
46
+ code: 'text (required)',
47
+ ia_lock: 'boolean (private)'
48
+ },
49
+ fks: {}
50
+ }
51
+ }
52
+ // Ajoute ici d'autres collections si besoin pour les tests
53
+ };
54
+ export const schemeModelTest = {
55
+ ...schemeModelTestDb
56
+ };
57
+ const idbqStore = createIdbqDb(schemeModelTest, 99);
58
+ export const { idbql, idbqlState, idbDatabase, idbqModel } = idbqStore.create('idae-machine-test');
@@ -4,7 +4,7 @@
4
4
  -->
5
5
  <script lang="ts" generics="COL">
6
6
  import { Button, openWindow } from '@medyll/idae-slotui-svelte';
7
- import CreateUpdate from '$components/form/CreateUpdate.svelte';
7
+ import CreateUpdate from './CreateUpdate.svelte';
8
8
  import { type CreateUpdateProps } from './types';
9
9
 
10
10
  type CollectionButtonProps = {
@@ -14,7 +14,7 @@
14
14
  }
15
15
  -->
16
16
  <script lang="ts">
17
- import { IDbCollections } from '../db/dbFields';
17
+ import { IDbCollections } from '../db/dbFields.js';
18
18
  import { schemeModel, idbqlState } from '../db/dbSchema';
19
19
  import type { Tpl, TplCollectionName, Where } from '@medyll/idae-idbql';
20
20
  import { Looper } from '@medyll/idae-slotui-svelte';
@@ -1,7 +1,7 @@
1
1
  <!-- Component: CollectionFieldValue.svelte (ancien nom CollectionFieldInput.svelte) -->
2
2
  <script lang="ts" generics="COL = Record<string,any>">
3
3
  // Importation des types et composants nécessaires
4
- import { IDbCollectionFieldForge, IDbCollectionValues } from '../db/dbFields';
4
+ import { IDbCollectionFieldForge, IDbCollectionValues } from '../db/dbFields.js';
5
5
  import type { TplCollectionName } from '@medyll/idae-idbql';
6
6
  import { IconButton } from '@medyll/idae-slotui-svelte';
7
7
  import { getAllContexts, getContext } from 'svelte';
package/dist/index.d.ts CHANGED
@@ -5,17 +5,13 @@ export { default as List } from './fragments/List.svelte';
5
5
  export { default as InfoLine } from './fragments/InfoLine.svelte';
6
6
  export { default as Frame } from './fragments/Frame.svelte';
7
7
  export { default as Confirm } from './fragments/Confirm.svelte';
8
- export * from './db/types.js';
9
- export * from './db/dbSchema.js';
10
- export * from './db/dbFields.js';
11
- export * from './db/dataModel.js';
12
- export * from './db/CrudService.js';
13
8
  export * from './form/types.js';
14
9
  export { default as FieldValue } from './form/FieldValue.svelte';
15
10
  export { default as FieldInPlace } from './form/FieldInPlace.svelte';
16
11
  export { default as DataProvider } from './form/DataProvider.svelte';
17
12
  export { default as DataList } from './form/DataList.svelte';
18
13
  export { default as CrudZone } from './form/CrudZone.svelte';
14
+ export * from './form/CrudZone.spec.js';
19
15
  export { default as CreateUpdate } from './form/CreateUpdate.svelte';
20
16
  export { default as CollectionReverseFks } from './form/CollectionReverseFks.svelte';
21
17
  export { default as CollectionListMenu } from './form/CollectionListMenu.svelte';
@@ -23,3 +19,16 @@ export { default as CollectionList } from './form/CollectionList.svelte';
23
19
  export { default as CollectionFks } from './form/CollectionFks.svelte';
24
20
  export { default as CollectionFieldGuess } from './form/CollectionFieldGuess.svelte';
25
21
  export { default as CollectionButton } from './form/CollectionButton.svelte';
22
+ export * from './db/types.js';
23
+ export * from './db/testDbSchema.js';
24
+ export * from './db/dbSchema.js';
25
+ export * from './db/dbSchema.spec.js';
26
+ export * from './db/dbFormValidate.spec.js';
27
+ export * from './db/dbFields.js';
28
+ export * from './db/dbFields.spec.js';
29
+ export * from './db/dbCollectionValues.spec.js';
30
+ export * from './db/dbCollectionFieldValues.spec.js';
31
+ export * from './db/dbCollectionFieldForge.spec.js';
32
+ export * from './db/dataModel.js';
33
+ export * from './db/FieldValue.spec.js';
34
+ export * from './db/CrudService.js';
package/dist/index.js CHANGED
@@ -6,17 +6,13 @@ export { default as List } from './fragments/List.svelte';
6
6
  export { default as InfoLine } from './fragments/InfoLine.svelte';
7
7
  export { default as Frame } from './fragments/Frame.svelte';
8
8
  export { default as Confirm } from './fragments/Confirm.svelte';
9
- export * from './db/types.js';
10
- export * from './db/dbSchema.js';
11
- export * from './db/dbFields.js';
12
- export * from './db/dataModel.js';
13
- export * from './db/CrudService.js';
14
9
  export * from './form/types.js';
15
10
  export { default as FieldValue } from './form/FieldValue.svelte';
16
11
  export { default as FieldInPlace } from './form/FieldInPlace.svelte';
17
12
  export { default as DataProvider } from './form/DataProvider.svelte';
18
13
  export { default as DataList } from './form/DataList.svelte';
19
14
  export { default as CrudZone } from './form/CrudZone.svelte';
15
+ export * from './form/CrudZone.spec.js';
20
16
  export { default as CreateUpdate } from './form/CreateUpdate.svelte';
21
17
  export { default as CollectionReverseFks } from './form/CollectionReverseFks.svelte';
22
18
  export { default as CollectionListMenu } from './form/CollectionListMenu.svelte';
@@ -24,3 +20,16 @@ export { default as CollectionList } from './form/CollectionList.svelte';
24
20
  export { default as CollectionFks } from './form/CollectionFks.svelte';
25
21
  export { default as CollectionFieldGuess } from './form/CollectionFieldGuess.svelte';
26
22
  export { default as CollectionButton } from './form/CollectionButton.svelte';
23
+ export * from './db/types.js';
24
+ export * from './db/testDbSchema.js';
25
+ export * from './db/dbSchema.js';
26
+ export * from './db/dbSchema.spec.js';
27
+ export * from './db/dbFormValidate.spec.js';
28
+ export * from './db/dbFields.js';
29
+ export * from './db/dbFields.spec.js';
30
+ export * from './db/dbCollectionValues.spec.js';
31
+ export * from './db/dbCollectionFieldValues.spec.js';
32
+ export * from './db/dbCollectionFieldForge.spec.js';
33
+ export * from './db/dataModel.js';
34
+ export * from './db/FieldValue.spec.js';
35
+ export * from './db/CrudService.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@medyll/idae-machine",
3
- "version": "0.105.0",
3
+ "version": "0.107.0",
4
4
  "scripts": {
5
5
  "dev": "vite dev",
6
6
  "build": "vite build && npm run prepack",