@medyll/idae-machine 0.120.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.
@@ -1,5 +1,5 @@
1
1
  <script lang="ts">
2
- import { IDbBase } from '../db/dbFields.js';
2
+ import { IDbBase } from '../main/machineDb.js';
3
3
  import { schemeModel, idbqlState } from '../db/dbSchema.js';
4
4
  import type { TplCollectionName, Where } from '@medyll/idae-idbql';
5
5
  import { Looper } from '@medyll/idae-slotui-svelte';
@@ -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.get(collection).collectionValues() ;
45
- let index = collections.get(collection).getIndexName();
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
 
@@ -14,7 +14,7 @@
14
14
  }
15
15
  -->
16
16
  <script lang="ts">
17
- import { IDbBase } from '../db/dbFields.js';
17
+ import { IDbBase } from '../main/machineDb.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';
@@ -4,7 +4,7 @@
4
4
  -->
5
5
 
6
6
  <script lang="ts" generics="COL = Record<string,any>">
7
- import { IDbFormValidate } from '../db/dbFields.js';
7
+ import { IDbFormValidate } from '../main/machineDb.js';
8
8
  import type { CreateUpdateProps } from './types';
9
9
  import CollectionReverseFks from './CollectionReverseFks.svelte';
10
10
  import FieldInput from './FieldValue.svelte';
@@ -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.get(collection).fieldForge(String(fieldName), data)
38
- let collectionFieldValues = machine.collections.get(collection).collectionValues()
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/index.d.ts CHANGED
@@ -1,4 +1,6 @@
1
1
  export * from './types/appschemeTypes.js';
2
+ export * from './main/machineDb.js';
3
+ export * from './main/machineDb.spec.js';
2
4
  export * from './main/machine.js';
3
5
  export * from './main/machine.spec.js';
4
6
  export { default as Skeleton } from './fragments/Skeleton.svelte';
@@ -25,8 +27,6 @@ export * from './db/testDbSchema.js';
25
27
  export * from './db/dbSchema.js';
26
28
  export * from './db/dbSchema.spec.js';
27
29
  export * from './db/dbFormValidate.spec.js';
28
- export * from './db/dbFields.js';
29
- export * from './db/dbFields.spec.js';
30
30
  export * from './db/dbCollectionValues.spec.js';
31
31
  export * from './db/dbCollectionFieldValues.spec.js';
32
32
  export * from './db/dbCollectionFieldForge.spec.js';
package/dist/index.js CHANGED
@@ -1,5 +1,7 @@
1
1
  // auto exports of entry components
2
2
  export * from './types/appschemeTypes.js';
3
+ export * from './main/machineDb.js';
4
+ export * from './main/machineDb.spec.js';
3
5
  export * from './main/machine.js';
4
6
  export * from './main/machine.spec.js';
5
7
  export { default as Skeleton } from './fragments/Skeleton.svelte';
@@ -26,8 +28,6 @@ export * from './db/testDbSchema.js';
26
28
  export * from './db/dbSchema.js';
27
29
  export * from './db/dbSchema.spec.js';
28
30
  export * from './db/dbFormValidate.spec.js';
29
- export * from './db/dbFields.js';
30
- export * from './db/dbFields.spec.js';
31
31
  export * from './db/dbCollectionValues.spec.js';
32
32
  export * from './db/dbCollectionFieldValues.spec.js';
33
33
  export * from './db/dbCollectionFieldForge.spec.js';
@@ -24,14 +24,13 @@
24
24
  * // Access the IDBQL data model
25
25
  * const model = machine.idbqModel;
26
26
  */
27
- import { IDbBase } from '../db/dbFields.js';
27
+ import { IDbBase } from './machineDb.js';
28
28
  import { createIdbqDb, type IdbqModel } from '@medyll/idae-idbql';
29
29
  /**
30
30
  * Machine: main entry point for managing the IDBQL connection and centralized data access.
31
31
  */
32
32
  export declare class Machine {
33
33
  /**
34
-
35
34
  * IDBQL (readonly collections instance)
36
35
  */
37
36
  _idbql: ReturnType<ReturnType<typeof createIdbqDb>["create"]>["idbql"] | undefined;
@@ -50,7 +49,7 @@ export declare class Machine {
50
49
  /**
51
50
  * Centralized access to schema and collection logic
52
51
  */
53
- _collections: IDbBase;
52
+ _idbbase: IDbBase;
54
53
  /**
55
54
  * Database name
56
55
  */
@@ -66,7 +65,7 @@ export declare class Machine {
66
65
  /**
67
66
  * Main constructor
68
67
  */
69
- constructor();
68
+ constructor(dbName?: string, version?: number, model?: IdbqModel);
70
69
  init(options?: {
71
70
  dbName?: string;
72
71
  version?: number;
@@ -79,7 +78,7 @@ export declare class Machine {
79
78
  private createCollections;
80
79
  private createStore;
81
80
  /**
82
- * Get the IDbCollections (schema logic) instance
81
+ * Get the IDbBase (schema logic) instance
83
82
  */
84
83
  get collections(): IDbBase;
85
84
  /**
@@ -87,9 +86,13 @@ export declare class Machine {
87
86
  */
88
87
  get idbql(): import("@medyll/idae-idbql").ReadonlyCollections<IdbqModel<Record<string, Record<string, any>>>> | undefined;
89
88
  /**
90
- * IDBQL (stateful) instance
89
+ * IDBQL (stateful) instance , old name was idbqlState => store
91
90
  */
92
91
  get store(): import("@medyll/idae-idbql").StateCollections<IdbqModel<Record<string, Record<string, any>>>>;
92
+ /**
93
+ * Direct getter for idbqlState (for test compatibility)
94
+ */
95
+ get idbqlState(): import("@medyll/idae-idbql").StateCollections<IdbqModel<Record<string, Record<string, any>>>>;
93
96
  /**
94
97
  * IndexedDB (core) instance
95
98
  * @deprecated
@@ -24,14 +24,13 @@
24
24
  * // Access the IDBQL data model
25
25
  * const model = machine.idbqModel;
26
26
  */
27
- import { IDbBase } from '../db/dbFields.js';
27
+ import { IDbBase } from './machineDb.js';
28
28
  import { createIdbqDb } from '@medyll/idae-idbql';
29
29
  /**
30
30
  * Machine: main entry point for managing the IDBQL connection and centralized data access.
31
31
  */
32
32
  export class Machine {
33
33
  /**
34
-
35
34
  * IDBQL (readonly collections instance)
36
35
  */
37
36
  _idbql;
@@ -50,7 +49,7 @@ export class Machine {
50
49
  /**
51
50
  * Centralized access to schema and collection logic
52
51
  */
53
- _collections;
52
+ _idbbase;
54
53
  /**
55
54
  * Database name
56
55
  */
@@ -66,7 +65,10 @@ export class Machine {
66
65
  /**
67
66
  * Main constructor
68
67
  */
69
- constructor() {
68
+ constructor(dbName, version, model) {
69
+ this._dbName = dbName ?? '';
70
+ this._version = version ?? 1;
71
+ this._model = model ?? undefined;
70
72
  }
71
73
  init(options) {
72
74
  this._dbName = options?.dbName ?? this._dbName;
@@ -84,7 +86,7 @@ export class Machine {
84
86
  if (!this._model) {
85
87
  throw new Error('Data model is not defined');
86
88
  }
87
- this._collections = new IDbBase(this._model);
89
+ this._idbbase = new IDbBase(this._model);
88
90
  }
89
91
  createStore() {
90
92
  if (!this._model || !this._dbName || !this._version) {
@@ -98,10 +100,10 @@ export class Machine {
98
100
  this._idbqModel = idbqModel;
99
101
  }
100
102
  /**
101
- * Get the IDbCollections (schema logic) instance
103
+ * Get the IDbBase (schema logic) instance
102
104
  */
103
105
  get collections() {
104
- return this._collections;
106
+ return this._idbbase;
105
107
  }
106
108
  /**
107
109
  * IDBQL (readonly) instance
@@ -110,11 +112,17 @@ export class Machine {
110
112
  return this._idbql;
111
113
  }
112
114
  /**
113
- * IDBQL (stateful) instance
115
+ * IDBQL (stateful) instance , old name was idbqlState => store
114
116
  */
115
117
  get store() {
116
118
  return this._idbqlState;
117
119
  }
120
+ /**
121
+ * Direct getter for idbqlState (for test compatibility)
122
+ */
123
+ get idbqlState() {
124
+ return this._idbqlState;
125
+ }
118
126
  /**
119
127
  * IndexedDB (core) instance
120
128
  * @deprecated
@@ -38,28 +38,6 @@ export type IDbForge = {
38
38
  fieldArgs?: IDbForgeArgs | undefined;
39
39
  is: any;
40
40
  };
41
- export declare class IDbCollection {
42
- collection: TplCollectionName;
43
- _dbCollections: IDbBase;
44
- constructor(collection: TplCollectionName, dbCollections: IDbBase);
45
- getCollectionModelTemplate(): Tpl;
46
- getCollectionModelTemplateFks(): {
47
- [x: string]: {
48
- code: string;
49
- multiple: boolean;
50
- rules: import("@medyll/idae-idbql").CombinedArgs;
51
- } | undefined;
52
- };
53
- getIndexName(): string;
54
- collectionValues(): IDbCollectionValues<any>;
55
- collectionFieldValues<T extends Record<string, any>>(data: T): IDbCollectionFieldValues<T>;
56
- fieldForge<T extends Record<string, any>>(fieldName: keyof T, data: T): IDbCollectionFieldForge<T>;
57
- getFormValidate(): IDbFormValidate;
58
- fks(): {
59
- [collection: string]: Tpl;
60
- };
61
- reverseFks(): Record<string, any>;
62
- }
63
41
  /**
64
42
  * Central class for parsing, introspecting, and extracting metadata from the database schema.
65
43
  * Provides methods to access collections, templates, fields, foreign keys, and type information.
@@ -79,7 +57,11 @@ export declare class IDbBase {
79
57
  /**
80
58
  * Get an IDbCollection instance for a collection name.
81
59
  */
82
- get(collection: TplCollectionName): IDbCollection;
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;
83
65
  /**
84
66
  * Get an IDbCollectionValues instance for a collection name.
85
67
  */
@@ -96,10 +78,6 @@ export declare class IDbBase {
96
78
  * Get an IDbFormValidate instance for a collection name.
97
79
  */
98
80
  formValidate(collection: TplCollectionName): IDbFormValidate;
99
- /**
100
- * Parse all collections in the model and return their fields as IDbForge objects.
101
- */
102
- parseAllCollections(): Record<string, Record<string, IDbForge | undefined> | undefined>;
103
81
  /**
104
82
  * Parse all fields of a given collection.
105
83
  */
@@ -108,17 +86,6 @@ export declare class IDbBase {
108
86
  * Parse a single field of a collection and return its IDbForge metadata.
109
87
  */
110
88
  parseCollectionFieldName(collection: TplCollectionName, fieldName: keyof TplFields): IDbForge | undefined;
111
- /**
112
- * Internal helper to construct an IDbForge object from its components.
113
- */
114
- private forge;
115
- getCollection(collection: TplCollectionName): CollectionModel;
116
- getCollectionModel(collection: TplCollectionName): CollectionModel;
117
- getCollectionModelTemplate(collection: TplCollectionName): Tpl;
118
- getCollectionModelTemplateFks(collection: TplCollectionName): Tpl["fks"];
119
- getIndexName(collection: TplCollectionName): string;
120
- getCollectionTemplateFields(collection: TplCollectionName): TplFields;
121
- getTemplatePresentation(collection: TplCollectionName): string;
122
89
  getFkFieldType(string: `${string}.${string}`): IDbFieldRules | undefined;
123
90
  getFkTemplateFields(string: `${string}.${string}`): {
124
91
  [x: string]: import("@medyll/idae-idbql").TplFieldRules;
@@ -132,6 +99,31 @@ export declare class IDbBase {
132
99
  reverseFks(targetCollection: TplCollectionName): Record<string, any>;
133
100
  iterateArrayField(collection: TplCollectionName, fieldName: keyof TplFields, data: any[]): IDbForge[];
134
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;
106
+ }
107
+ export declare class IDbCollection {
108
+ collection: TplCollectionName;
109
+ _dbCollections: IDbBase;
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"];
118
+ getIndexName(): string;
119
+ collectionValues(): IDbCollectionValues<any>;
120
+ collectionFieldValues<T extends Record<string, any>>(data: T): IDbCollectionFieldValues<T>;
121
+ fieldForge<T extends Record<string, any>>(fieldName: keyof T, data: T): IDbCollectionFieldForge<T>;
122
+ getFormValidate(): IDbFormValidate;
123
+ fks(): {
124
+ [collection: string]: Tpl;
125
+ };
126
+ reverseFks(): Record<string, any>;
135
127
  }
136
128
  /**
137
129
  * IDbCollectionValues
@@ -140,7 +132,7 @@ export declare class IDbBase {
140
132
  * It is designed for dynamic UI rendering, presentation logic, and metadata extraction for form generation in schema-driven applications.
141
133
  *
142
134
  * Main responsibilities:
143
- * - Holds a reference to the collection name and the schema (IDbCollections).
135
+ * - Holds a reference to the collection name and the schema (IDbBase).
144
136
  * - Provides methods to format field values according to their type (number, text, array, object, etc.).
145
137
  * - Supplies presentation logic for displaying records (e.g., presentation string, index value).
146
138
  * - Offers input attribute generation for forms (inputDataSet).
@@ -154,15 +146,15 @@ export declare class IDbBase {
154
146
  * const formatted = values.format('name', agentData); // formatted field value
155
147
  * const attrs = values.getInputDataSet('name', agentData); // input attributes for forms
156
148
  *
157
- * This class is typically used via IDbCollections.getCollectionValues for shared instance management.
149
+ * This class is typically used via IDbBase.getCollectionValues for shared instance management.
158
150
  * @template T - The type of the data object for the collection.
159
151
  */
160
152
  export declare class IDbCollectionValues<T extends Record<string, any>> {
161
153
  #private;
162
154
  /**
163
- * The IDbCollections instance used for schema introspection.
155
+ * The IDbBase instance used for schema introspection.
164
156
  */
165
- idbCollections: IDbBase;
157
+ idbBase: IDbBase;
166
158
  /**
167
159
  * The collection name this instance operates on.
168
160
  */
@@ -171,7 +163,7 @@ export declare class IDbCollectionValues<T extends Record<string, any>> {
171
163
  * Create a new IDbCollectionValues instance for a given collection.
172
164
  * @param collectionName The collection name.
173
165
  */
174
- constructor(collectionName: TplCollectionName, idbCollections?: IDbBase);
166
+ constructor(collectionName: TplCollectionName, idbBase?: IDbBase);
175
167
  presentation(data: Record<string, any>): string;
176
168
  /**
177
169
  * Get the value of the index field for a data object.
@@ -241,7 +233,7 @@ export declare class IDbCollectionFieldValues<T extends Record<string, any>> {
241
233
  * const inputType = forge.htmlInputType; // e.g. 'text', 'area', 'email', etc.
242
234
  * const meta = forge.forge; // IDbForge metadata for the field
243
235
  *
244
- * This class is typically used via IDbCollections.getCollectionFieldForge for shared instance management.
236
+ * This class is typically used via IDbBase.getCollectionFieldForge for shared instance management.
245
237
  */
246
238
  export declare class IDbCollectionFieldForge<T extends Record<string, any>> {
247
239
  #private;
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  path: D:\boulot\python\wollama\src\lib\db\dbFields.ts
3
3
  */
4
- import { schemeModel } from './dbSchema.js';
4
+ import { schemeModel } from '../db/dbSchema.js';
5
5
  export var enumPrimitive;
6
6
  (function (enumPrimitive) {
7
7
  enumPrimitive["id"] = "id";
@@ -46,42 +46,6 @@ class IDbError extends Error {
46
46
  }
47
47
  }
48
48
  }
49
- /* Single collection relies on IDbCollections */
50
- export class IDbCollection {
51
- collection;
52
- _dbCollections;
53
- constructor(collection, dbCollections) {
54
- this.collection = collection;
55
- this._dbCollections = dbCollections;
56
- }
57
- getCollectionModelTemplate() {
58
- return this._dbCollections.getCollectionModelTemplate(this.collection);
59
- }
60
- getCollectionModelTemplateFks() {
61
- return this._dbCollections.getCollectionModelTemplateFks(this.collection);
62
- }
63
- getIndexName() {
64
- return this._dbCollections.getIndexName(this.collection);
65
- }
66
- collectionValues() {
67
- return this._dbCollections.collectionValues(this.collection);
68
- }
69
- collectionFieldValues(data) {
70
- return this._dbCollections.collectionFieldValues(this.collection, data);
71
- }
72
- fieldForge(fieldName, data) {
73
- return this._dbCollections.collectionFieldForge(this.collection, fieldName, data);
74
- }
75
- getFormValidate() {
76
- return this._dbCollections.formValidate(this.collection);
77
- }
78
- fks() {
79
- return this._dbCollections.fks(this.collection);
80
- }
81
- reverseFks() {
82
- return this._dbCollections.reverseFks(this.collection);
83
- }
84
- }
85
49
  /**
86
50
  * Central class for parsing, introspecting, and extracting metadata from the database schema.
87
51
  * Provides methods to access collections, templates, fields, foreign keys, and type information.
@@ -102,8 +66,15 @@ export class IDbBase {
102
66
  /**
103
67
  * Get an IDbCollection instance for a collection name.
104
68
  */
105
- get(collection) {
106
- 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];
107
78
  }
108
79
  /**
109
80
  * Get an IDbCollectionValues instance for a collection name.
@@ -129,21 +100,11 @@ export class IDbBase {
129
100
  formValidate(collection) {
130
101
  return new IDbFormValidate(collection, this);
131
102
  }
132
- /**
133
- * Parse all collections in the model and return their fields as IDbForge objects.
134
- */
135
- parseAllCollections() {
136
- let out = {};
137
- Object.keys(this.model).forEach((collection) => {
138
- out[collection] = this.parseRawCollection(collection);
139
- });
140
- return out;
141
- }
142
103
  /**
143
104
  * Parse all fields of a given collection.
144
105
  */
145
106
  parseRawCollection(collection) {
146
- const fields = this.getCollectionTemplateFields(collection);
107
+ const fields = new IDbCollection(collection, this, this.model).getFields();
147
108
  if (!fields)
148
109
  return;
149
110
  const out = {};
@@ -171,38 +132,10 @@ export class IDbBase {
171
132
  const fieldType = array ?? object ?? fk ?? primitive;
172
133
  return this.forge({ collection, fieldName, ...fieldType });
173
134
  }
174
- /**
175
- * Internal helper to construct an IDbForge object from its components.
176
- */
177
- forge({ collection, fieldName, fieldType, fieldRule, fieldArgs, is }) {
178
- return { collection, fieldName, fieldType, fieldRule, fieldArgs, is };
179
- }
180
- #getModel() {
181
- return this.model;
182
- }
183
- getCollection(collection) {
184
- return this.#getModel()[String(collection)];
185
- }
186
- getCollectionModel(collection) {
187
- return this.#getModel()[String(collection)];
188
- }
189
- getCollectionModelTemplate(collection) {
190
- return this.getCollectionModel(collection)['template'];
191
- }
192
- getCollectionModelTemplateFks(collection) {
193
- return this.getCollectionModel(collection)['template']?.fks;
194
- }
195
- getIndexName(collection) {
196
- return this.getCollectionModel(collection)?.template?.index;
197
- }
198
- getCollectionTemplateFields(collection) {
199
- return this.getCollectionModelTemplate(collection)?.fields;
200
- }
201
- getTemplatePresentation(collection) {
202
- return this.getCollectionModelTemplate(collection)?.presentation;
203
- }
135
+ // Toutes ces méthodes sont maintenant dans IDbCollection
204
136
  #getTemplateFieldRule(collection, fieldName) {
205
- return this.getCollectionTemplateFields(collection)?.[String(fieldName)];
137
+ // Utilise la nouvelle API orientée collection
138
+ return new IDbCollection(collection, this, this.model).getFieldRule(fieldName);
206
139
  }
207
140
  getFkFieldType(string) {
208
141
  const [collection, field] = string.split('.');
@@ -211,7 +144,7 @@ export class IDbBase {
211
144
  }
212
145
  getFkTemplateFields(string) {
213
146
  const [collection, field] = string.split('.');
214
- return this.getCollectionModel(collection).template?.fields;
147
+ return this.collection(collection).getModelTemplate()?.fields;
215
148
  }
216
149
  testIs(what, fieldRule) {
217
150
  const typeMappings = { fk: 'fk-', array: 'array-of-', object: 'object-', primitive: '' };
@@ -268,7 +201,7 @@ export class IDbBase {
268
201
  return { fieldType, fieldRule, fieldArgs, is: type };
269
202
  }
270
203
  fks(collection) {
271
- let fks = this.getCollectionModelTemplateFks(collection);
204
+ let fks = this.collection(collection).getModelTemplateFks();
272
205
  let out = {};
273
206
  if (fks) {
274
207
  Object.keys(fks).forEach((collection) => {
@@ -279,7 +212,7 @@ export class IDbBase {
279
212
  }
280
213
  reverseFks(targetCollection) {
281
214
  const result = {};
282
- Object.entries(this.#getModel()).forEach(([collectionName, collectionModel]) => {
215
+ Object.entries(this.model).forEach(([collectionName, collectionModel]) => {
283
216
  const template = collectionModel.template;
284
217
  if (template && template.fks) {
285
218
  Object.entries(template.fks).forEach(([fkName, fkConfig]) => {
@@ -308,6 +241,63 @@ export class IDbBase {
308
241
  }
309
242
  return Object.keys(data).map((key) => ({ ...fieldInfo, fieldName: `${String(fieldName)}.${key}` }));
310
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
+ }
250
+ }
251
+ /* Single collection relies on IDbBase */
252
+ export class IDbCollection {
253
+ // --- NOUVELLES MÉTHODES MIGRÉES DE IDbBase ---
254
+ collection;
255
+ _dbCollections;
256
+ model;
257
+ constructor(collection, dbCollections, model) {
258
+ this.collection = collection;
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)];
273
+ }
274
+ getModelTemplate() {
275
+ return this.model['template'];
276
+ }
277
+ getModelTemplateFks() {
278
+ return this.model['template']?.fks;
279
+ }
280
+ getIndexName() {
281
+ return this.getModelTemplate()?.index;
282
+ }
283
+ collectionValues() {
284
+ return this._dbCollections.collectionValues(this.collection);
285
+ }
286
+ collectionFieldValues(data) {
287
+ return this._dbCollections.collectionFieldValues(this.collection, data);
288
+ }
289
+ fieldForge(fieldName, data) {
290
+ return this._dbCollections.collectionFieldForge(this.collection, fieldName, data);
291
+ }
292
+ getFormValidate() {
293
+ return this._dbCollections.formValidate(this.collection);
294
+ }
295
+ fks() {
296
+ return this._dbCollections.fks(this.collection);
297
+ }
298
+ reverseFks() {
299
+ return this._dbCollections.reverseFks(this.collection);
300
+ }
311
301
  }
312
302
  /**
313
303
  * IDbCollectionValues
@@ -316,7 +306,7 @@ export class IDbBase {
316
306
  * It is designed for dynamic UI rendering, presentation logic, and metadata extraction for form generation in schema-driven applications.
317
307
  *
318
308
  * Main responsibilities:
319
- * - Holds a reference to the collection name and the schema (IDbCollections).
309
+ * - Holds a reference to the collection name and the schema (IDbBase).
320
310
  * - Provides methods to format field values according to their type (number, text, array, object, etc.).
321
311
  * - Supplies presentation logic for displaying records (e.g., presentation string, index value).
322
312
  * - Offers input attribute generation for forms (inputDataSet).
@@ -330,14 +320,14 @@ export class IDbBase {
330
320
  * const formatted = values.format('name', agentData); // formatted field value
331
321
  * const attrs = values.getInputDataSet('name', agentData); // input attributes for forms
332
322
  *
333
- * This class is typically used via IDbCollections.getCollectionValues for shared instance management.
323
+ * This class is typically used via IDbBase.getCollectionValues for shared instance management.
334
324
  * @template T - The type of the data object for the collection.
335
325
  */
336
326
  export class IDbCollectionValues {
337
327
  /**
338
- * The IDbCollections instance used for schema introspection.
328
+ * The IDbBase instance used for schema introspection.
339
329
  */
340
- idbCollections;
330
+ idbBase;
341
331
  /**
342
332
  * The collection name this instance operates on.
343
333
  */
@@ -346,14 +336,14 @@ export class IDbCollectionValues {
346
336
  * Create a new IDbCollectionValues instance for a given collection.
347
337
  * @param collectionName The collection name.
348
338
  */
349
- constructor(collectionName, idbCollections) {
339
+ constructor(collectionName, idbBase) {
350
340
  this.collectionName = collectionName;
351
- this.idbCollections = idbCollections ?? new IDbBase();
341
+ this.idbBase = idbBase ?? new IDbBase();
352
342
  }
353
343
  presentation(data) {
354
344
  try {
355
345
  this.#checkError(!this.#checkAccess(), 'Access denied', 'ACCESS_DENIED');
356
- const presentation = this.idbCollections.getTemplatePresentation(this.collectionName);
346
+ const presentation = this.idbBase.collection(this.collectionName).getPresentation();
357
347
  this.#checkError(!presentation, 'Presentation template not found', 'TEMPLATE_NOT_FOUND');
358
348
  const fields = presentation.split(' ');
359
349
  return fields
@@ -376,7 +366,7 @@ export class IDbCollectionValues {
376
366
  indexValue(data) {
377
367
  try {
378
368
  this.#checkError(!this.#checkAccess(), 'Access denied', 'ACCESS_DENIED');
379
- const indexName = this.idbCollections.getIndexName(this.collectionName);
369
+ const indexName = this.idbBase.collection(this.collectionName).getIndexName();
380
370
  this.#checkError(!indexName, 'Index not found for collection', 'INDEX_NOT_FOUND');
381
371
  this.#checkError(!(indexName in data), `Index field ${indexName} not found in data`, 'FIELD_NOT_FOUND');
382
372
  return data[indexName];
@@ -396,7 +386,7 @@ export class IDbCollectionValues {
396
386
  try {
397
387
  this.#checkError(!this.#checkAccess(), 'Access denied', 'ACCESS_DENIED');
398
388
  this.#checkError(!(fieldName in data), `Field ${String(fieldName)} not found in data`, 'FIELD_NOT_FOUND');
399
- const fieldInfo = this.idbCollections.parseCollectionFieldName(this.collectionName, fieldName);
389
+ const fieldInfo = this.idbBase.parseCollectionFieldName(this.collectionName, fieldName);
400
390
  this.#checkError(!fieldInfo, `Field ${String(fieldName)} not found in collection`, 'FIELD_NOT_FOUND');
401
391
  switch (fieldInfo?.fieldType) {
402
392
  case 'number':
@@ -424,10 +414,10 @@ export class IDbCollectionValues {
424
414
  * @returns An object with data-* attributes for the field.
425
415
  */
426
416
  getInputDataSet(fieldName, data) {
427
- const fieldInfo = this.idbCollections.parseCollectionFieldName(this.collectionName, fieldName);
417
+ const fieldInfo = this.idbBase.parseCollectionFieldName(this.collectionName, fieldName);
428
418
  const fieldType = fieldInfo?.fieldType ?? '';
429
419
  const fieldArgs = fieldInfo?.fieldArgs?.join(' ') ?? '';
430
- const indexName = this.idbCollections.getIndexName(this.collectionName);
420
+ const indexName = this.idbBase.collection(this.collectionName).getIndexName();
431
421
  return {
432
422
  'data-collection': this.collectionName,
433
423
  'data-collectionId': indexName && data?.[indexName] !== undefined ? String(data?.[indexName]) : '',
@@ -443,7 +433,7 @@ export class IDbCollectionValues {
443
433
  * @returns An array of IDbForge objects.
444
434
  */
445
435
  iterateArrayField(fieldName, data) {
446
- return this.idbCollections.iterateArrayField(this.collectionName, fieldName, data);
436
+ return this.idbBase.iterateArrayField(this.collectionName, fieldName, data);
447
437
  }
448
438
  /**
449
439
  * Iterate over an object field and return an array of IDbForge objects for each property.
@@ -452,7 +442,7 @@ export class IDbCollectionValues {
452
442
  * @returns An array of IDbForge objects.
453
443
  */
454
444
  iterateObjectField(fieldName, data) {
455
- return this.idbCollections.iterateObjectField(this.collectionName, fieldName, data);
445
+ return this.idbBase.iterateObjectField(this.collectionName, fieldName, data);
456
446
  }
457
447
  /**
458
448
  * Internal: Format a number field for display.
@@ -477,8 +467,9 @@ export class IDbCollectionValues {
477
467
  'text-long': 40,
478
468
  'text-giant': 50
479
469
  };
480
- const maxLength = lengths[type] || value.length;
481
- return value.substring(0, maxLength);
470
+ const str = typeof value === 'string' ? value : String(value ?? '');
471
+ const maxLength = lengths[type] || str.length;
472
+ return str.substring(0, maxLength);
482
473
  }
483
474
  /**
484
475
  * Internal: Check if access is allowed (override for custom logic).
@@ -509,7 +500,7 @@ export class IDbCollectionFieldValues {
509
500
  * @param fieldName The field name to introspect.
510
501
  */
511
502
  getForge(fieldName) {
512
- return this.#collectionValues.idbCollections.parseCollectionFieldName(this.#collection, String(fieldName));
503
+ return this.#collectionValues.idbBase.parseCollectionFieldName(this.#collection, String(fieldName));
513
504
  }
514
505
  constructor(collection, data, collectionValues) {
515
506
  this.#collection = collection;
@@ -517,7 +508,7 @@ export class IDbCollectionFieldValues {
517
508
  this.#data = data;
518
509
  }
519
510
  format(fieldName) {
520
- const fieldInfo = this.#collectionValues.idbCollections.parseCollectionFieldName(this.#collection, fieldName);
511
+ const fieldInfo = this.#collectionValues.idbBase.parseCollectionFieldName(this.#collection, fieldName);
521
512
  if (fieldInfo?.is === 'array') {
522
513
  return this.iterateArray(String(fieldName), this.#data);
523
514
  }
@@ -560,14 +551,13 @@ export class IDbCollectionFieldValues {
560
551
  * const inputType = forge.htmlInputType; // e.g. 'text', 'area', 'email', etc.
561
552
  * const meta = forge.forge; // IDbForge metadata for the field
562
553
  *
563
- * This class is typically used via IDbCollections.getCollectionFieldForge for shared instance management.
554
+ * This class is typically used via IDbBase.getCollectionFieldForge for shared instance management.
564
555
  */
565
556
  export class IDbCollectionFieldForge {
566
557
  #collection;
567
558
  #collectionValues;
568
559
  #fieldName;
569
560
  #data;
570
- #forge;
571
561
  constructor(collection, fieldName, data, collectionValues) {
572
562
  this.#collection = collection;
573
563
  this.#collectionValues = collectionValues ?? new IDbCollectionValues(collection);
@@ -582,7 +572,7 @@ export class IDbCollectionFieldForge {
582
572
  }
583
573
  // renamed from parseCollectionFieldName
584
574
  get forge() {
585
- return this.#collectionValues.idbCollections.parseCollectionFieldName(this.#collection, String(this.#fieldName));
575
+ return this.#collectionValues.idbBase.parseCollectionFieldName(this.#collection, String(this.#fieldName));
586
576
  }
587
577
  get fieldArgs() {
588
578
  return this.forge?.fieldArgs;
@@ -698,7 +688,7 @@ export class IDbFormValidate {
698
688
  const errors = {};
699
689
  const invalidFields = [];
700
690
  let isValid = true;
701
- const fields = this.idbCollections.getCollectionTemplateFields(this.collection);
691
+ const fields = this.idbCollections.collection(this.collection).getModelTemplate().fields;
702
692
  if (!fields) {
703
693
  return {
704
694
  isValid: false,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@medyll/idae-machine",
3
- "version": "0.120.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.173.0",
53
- "@medyll/idae-idbql": "0.170.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",