@medyll/idae-machine 0.112.0 → 0.114.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 medyll
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -40,17 +40,11 @@ export type IDbForge = {
40
40
  };
41
41
  export declare class IDbCollection {
42
42
  collection: TplCollectionName;
43
- _dbCollections: IDbCollections;
44
- constructor(collection: TplCollectionName, dbCollections: IDbCollections);
43
+ _dbCollections: IDbBase;
44
+ constructor(collection: TplCollectionName, dbCollections: IDbBase);
45
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;
46
+ getCollectionModelTemplateFks(): Tpl;
47
+ getIndexName(): any;
54
48
  collectionValues(): IDbCollectionValues<any>;
55
49
  collectionFieldValues<T extends Record<string, any>>(data: T): IDbCollectionFieldValues<T>;
56
50
  fieldForge<T extends Record<string, any>>(fieldName: keyof T, data: T): IDbCollectionFieldForge<T>;
@@ -65,194 +59,70 @@ export declare class IDbCollection {
65
59
  * Provides methods to access collections, templates, fields, foreign keys, and type information.
66
60
  * Used for dynamic UI generation, validation, and schema-driven logic.
67
61
  */
68
- export declare class IDbCollections {
62
+ export declare class IDbBase {
69
63
  #private;
70
64
  /**
71
- * Stores shared instances of IDbCollectionValues per collection
65
+ * The database model (schema) used for introspection.
72
66
  */
73
- private _collectionValuesMap;
67
+ model: IdbqModel;
74
68
  /**
75
- * Stores shared instances of IDbCollectionFieldValues per collection+data
69
+ * Create a new IDbBase instance.
70
+ * @param model Optional custom model to use (default: schemeModel)
76
71
  */
77
- private _collectionFieldValuesMap;
72
+ constructor(model?: IdbqModel);
78
73
  /**
79
- * Stores shared instances of IDbCollectionFieldForge per collection, field, and data
74
+ * Get an IDbCollection instance for a collection name.
80
75
  */
81
- private _collectionFieldForgeMap;
76
+ get(collection: TplCollectionName): IDbCollection;
82
77
  /**
83
- * Stores shared instances of IDbFormValidate per collection
78
+ * Get an IDbCollectionValues instance for a collection name.
84
79
  */
85
- private _formValidateMap;
80
+ collectionValues(collection: TplCollectionName): IDbCollectionValues<any>;
86
81
  /**
87
- * The database model (schema) used for introspection.
82
+ * Get an IDbCollectionFieldValues instance for a collection and data.
88
83
  */
89
- model: IdbqModel;
84
+ collectionFieldValues<T extends Record<string, any>>(collection: TplCollectionName, data: T): IDbCollectionFieldValues<T>;
90
85
  /**
91
- * Create a new IDbCollections instance.
92
- * @param model Optional custom model to use (default: schemeModel)
86
+ * Get an IDbCollectionFieldForge instance for a collection, field, and data.
93
87
  */
94
- constructor(model?: IdbqModel);
95
- get(collection: TplCollectionName): IDbCollection;
88
+ collectionFieldForge<T extends Record<string, any>>(collection: TplCollectionName, fieldName: keyof T | string, data: T): IDbCollectionFieldForge<T>;
89
+ /**
90
+ * Get an IDbFormValidate instance for a collection name.
91
+ */
92
+ formValidate(collection: TplCollectionName): IDbFormValidate;
96
93
  /**
97
94
  * Parse all collections in the model and return their fields as IDbForge objects.
98
- * @returns An object mapping collection names to their parsed fields.
99
95
  */
100
96
  parseAllCollections(): Record<string, Record<string, IDbForge | undefined> | undefined>;
101
97
  /**
102
98
  * Parse all fields of a given collection.
103
- * @param collection The collection name.
104
- * @returns An object mapping field names to their IDbForge representation.
105
99
  */
106
100
  parseRawCollection(collection: TplCollectionName): Record<string, IDbForge | undefined> | undefined;
107
101
  /**
108
102
  * Parse a single field of a collection and return its IDbForge metadata.
109
- * @param collection The collection name.
110
- * @param fieldName The field name.
111
- * @returns The IDbForge object for the field, or throws if not found.
112
103
  */
113
104
  parseCollectionFieldName(collection: TplCollectionName, fieldName: keyof TplFields): IDbForge | undefined;
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
- */
119
- parsFieldRule(fieldRule: IDbFieldRules): Partial<IDbForge> | undefined;
120
105
  /**
121
106
  * Internal helper to construct an IDbForge object from its components.
122
- * @param params The IDbForge properties (collection, fieldName, fieldType, fieldRule, fieldArgs, is).
123
- * @returns The constructed IDbForge object.
124
107
  */
125
108
  private forge;
126
- /**
127
- * Get the collection object from the model.
128
- * @param collection The collection name.
129
- * @returns The collection object.
130
- */
131
- getCollection(collection: TplCollectionName): CollectionModel; /**
132
- * Get the collection object from the model.
133
- * @param collection The collection name.
134
- * @returns The collection object.
135
- */
109
+ getCollection(collection: TplCollectionName): CollectionModel;
136
110
  getCollectionModel(collection: TplCollectionName): CollectionModel;
137
- /**
138
- * Get the template object for a collection.
139
- * @param collection The collection name.
140
- * @returns The template object.
141
- */
142
111
  getCollectionModelTemplate(collection: TplCollectionName): Tpl;
143
- /**
144
- * Get the foreign keys (fks) object for a collection.
145
- * @param collection The collection name.
146
- * @returns The fks object.
147
- */
148
112
  getCollectionModelTemplateFks(collection: TplCollectionName): Tpl["fks"];
149
- /**
150
- * Get the index field name for a collection.
151
- * @param collection The collection name.
152
- * @returns The index field name.
153
- */
154
- getIndexName(collection: TplCollectionName): string;
155
- /**
156
- * Returns a shared instance of IDbCollectionValues for a given collection
157
- */
158
- getCollectionValues(collection: TplCollectionName): IDbCollectionValues<any>;
159
- /**
160
- * Returns a shared instance of IDbCollectionFieldValues for a given collection and data
161
- * The instance key is based on the collection and the main index of data (or JSON if missing)
162
- */
163
- getCollectionFieldValues<T extends Record<string, any>>(collection: TplCollectionName, data: T): IDbCollectionFieldValues<T>;
164
- /**
165
- * Returns a shared instance of IDbCollectionFieldForge for a given collection, field, and data
166
- * The instance key is based on collection, field, and the main index of data (or JSON if missing)
167
- */
168
- getCollectionFieldForge<T extends Record<string, any>>(collection: TplCollectionName, fieldName: keyof T | string, data: T): IDbCollectionFieldForge<T>;
169
- /**
170
- * Returns a shared instance of IDbFormValidate for a given collection
171
- */
172
- getFormValidate(collection: TplCollectionName): IDbFormValidate;
173
- /**
174
- * Get the fields object for a collection.
175
- * @param collection The collection name.
176
- * @returns The fields object.
177
- */
113
+ getIndexName(collection: TplCollectionName): any;
178
114
  getCollectionTemplateFields(collection: TplCollectionName): TplFields;
179
- /**
180
- * Get the presentation string for a collection (used for display).
181
- * @param collection The collection name.
182
- * @returns The presentation string.
183
- */
184
115
  getTemplatePresentation(collection: TplCollectionName): string;
185
- /**
186
- * Get the field rule for a foreign key field (e.g. 'collection.field').
187
- * @param string The string in the form 'collection.field'.
188
- * @returns The field rule string, or undefined.
189
- */
190
116
  getFkFieldType(string: `${string}.${string}`): IDbFieldRules | undefined;
191
- /**
192
- * Get the fields object for a foreign key collection.
193
- * @param string The string in the form 'collection.field'.
194
- * @returns The fields object for the referenced collection.
195
- */
196
- getFkTemplateFields(string: `${string}.${string}`): {
197
- [x: string]: import("@medyll/idae-idbql").TplFieldRules;
198
- };
199
- /**
200
- * Test if a field rule matches a given type (primitive, array, object, fk).
201
- * @param what The type to test ('primitive', 'array', 'object', 'fk').
202
- * @param fieldRule The field rule string.
203
- * @returns Partial IDbForge info if match, else undefined.
204
- */
117
+ getFkTemplateFields(string: `${string}.${string}`): any;
205
118
  private testIs;
206
- /**
207
- * Extract type information for a field rule.
208
- * @param what The type to extract ('primitive', 'array', 'object', 'fk').
209
- * @param fieldRule The field rule string.
210
- * @returns Partial IDbForge info.
211
- */
212
119
  is(what: 'array' | 'object' | 'fk' | 'primitive', fieldRule: IDbFieldRules): Partial<IDbForge>;
213
- /**
214
- * Get the value of the index field for a given data object.
215
- * @param collection The collection name.
216
- * @param data The data object.
217
- * @returns The value of the index field.
218
- */
219
- indexValue(collection: TplCollectionName, data: Record<string, any>): any;
220
- /**
221
- * Extracts type, rule, and argument information from a field rule string.
222
- * @param type The type to extract ('primitive', 'array', 'object', 'fk').
223
- * @param fieldRule The field rule string.
224
- * @returns Partial IDbForge info.
225
- */
226
120
  extract(type: 'array' | 'object' | 'fk' | 'primitive', fieldRule: IDbFieldRules): Partial<IDbForge>;
227
- /**
228
- * Parse and return all foreign key collections referenced by a collection.
229
- * @param collection The collection name.
230
- * @returns An object mapping referenced collection names to their parsed fields.
231
- */
232
121
  fks(collection: string): {
233
122
  [collection: string]: Tpl;
234
123
  };
235
- /**
236
- * Find all collections that reference the target collection via a foreign key.
237
- * @param targetCollection The collection name to search for as a target.
238
- * @returns An object mapping referencing collections to their fk configs.
239
- */
240
124
  reverseFks(targetCollection: TplCollectionName): Record<string, any>;
241
- /**
242
- * Iterate over an array field and return an array of IDbForge objects for each element.
243
- * @param collection The collection name.
244
- * @param fieldName The field name.
245
- * @param data The array data.
246
- * @returns An array of IDbForge objects.
247
- */
248
125
  iterateArrayField(collection: TplCollectionName, 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 collection The collection name.
252
- * @param fieldName The field name.
253
- * @param data The object data.
254
- * @returns An array of IDbForge objects.
255
- */
256
126
  iterateObjectField(collection: TplCollectionName, fieldName: keyof TplFields, data: Record<string, any>): IDbForge[];
257
127
  }
258
128
  /**
@@ -284,7 +154,7 @@ export declare class IDbCollectionValues<T extends Record<string, any>> {
284
154
  /**
285
155
  * The IDbCollections instance used for schema introspection.
286
156
  */
287
- idbCollections: IDbCollections;
157
+ idbCollections: IDbBase;
288
158
  /**
289
159
  * The collection name this instance operates on.
290
160
  */
@@ -293,7 +163,7 @@ export declare class IDbCollectionValues<T extends Record<string, any>> {
293
163
  * Create a new IDbCollectionValues instance for a given collection.
294
164
  * @param collectionName The collection name.
295
165
  */
296
- constructor(collectionName: TplCollectionName, idbCollections?: IDbCollections);
166
+ constructor(collectionName: TplCollectionName, idbCollections?: IDbBase);
297
167
  presentation(data: Record<string, any>): string;
298
168
  /**
299
169
  * Get the value of the index field for a data object.
@@ -339,7 +209,7 @@ export declare class IDbCollectionFieldValues<T extends Record<string, any>> {
339
209
  getForge(fieldName: keyof T): IDbForge | undefined;
340
210
  constructor(collection: TplCollectionName, data: T, collectionValues?: IDbCollectionValues<T>);
341
211
  format(fieldName: keyof T): string | string[];
342
- getInputDataSet(fieldName: keyof T): Record<"data-collection" | "data-fieldName" | "data-fieldType" | "data-fieldArgs" | "data-collectionId", string>;
212
+ getInputDataSet(fieldName: keyof T): Record<"data-collection" | "data-collectionId" | "data-fieldName" | "data-fieldType" | "data-fieldArgs", string>;
343
213
  iterateArray(fieldName: string, data: any[]): IDbForge[];
344
214
  iterateObject(fieldName: string, data: Record<string, any>): IDbForge[];
345
215
  }
@@ -369,7 +239,7 @@ export declare class IDbCollectionFieldForge<T extends Record<string, any>> {
369
239
  #private;
370
240
  constructor(collection: TplCollectionName, fieldName: any, data: T, collectionValues?: IDbCollectionValues<T>);
371
241
  get format(): string;
372
- get inputDataSet(): Record<"data-collection" | "data-fieldName" | "data-fieldType" | "data-fieldArgs" | "data-collectionId", string>;
242
+ get inputDataSet(): Record<"data-collection" | "data-collectionId" | "data-fieldName" | "data-fieldType" | "data-fieldArgs", string>;
373
243
  get forge(): IDbForge | undefined;
374
244
  get fieldArgs(): IDbForgeArgs | undefined;
375
245
  get fieldType(): IDbFieldType | undefined;
@@ -385,7 +255,7 @@ export declare class IDbFormValidate {
385
255
  #private;
386
256
  private collection;
387
257
  private idbCollections;
388
- constructor(collection: TplCollectionName, idbCollections?: IDbCollections);
258
+ constructor(collection: TplCollectionName, idbCollections?: IDbBase);
389
259
  validateField(fieldName: keyof TplFields, value: any): {
390
260
  isValid: boolean;
391
261
  error?: string;
@@ -64,16 +64,16 @@ export class IDbCollection {
64
64
  return this._dbCollections.getIndexName(this.collection);
65
65
  }
66
66
  collectionValues() {
67
- return this._dbCollections.getCollectionValues(this.collection);
67
+ return this._dbCollections.collectionValues(this.collection);
68
68
  }
69
69
  collectionFieldValues(data) {
70
- return this._dbCollections.getCollectionFieldValues(this.collection, data);
70
+ return this._dbCollections.collectionFieldValues(this.collection, data);
71
71
  }
72
72
  fieldForge(fieldName, data) {
73
- return this._dbCollections.getCollectionFieldForge(this.collection, fieldName, data);
73
+ return this._dbCollections.collectionFieldForge(this.collection, fieldName, data);
74
74
  }
75
75
  getFormValidate() {
76
- return this._dbCollections.getFormValidate(this.collection);
76
+ return this._dbCollections.formValidate(this.collection);
77
77
  }
78
78
  fks() {
79
79
  return this._dbCollections.fks(this.collection);
@@ -87,40 +87,50 @@ export class IDbCollection {
87
87
  * Provides methods to access collections, templates, fields, foreign keys, and type information.
88
88
  * Used for dynamic UI generation, validation, and schema-driven logic.
89
89
  */
90
- export class IDbCollections {
90
+ export class IDbBase {
91
91
  /**
92
- * Stores shared instances of IDbCollectionValues per collection
92
+ * The database model (schema) used for introspection.
93
93
  */
94
- _collectionValuesMap = {};
94
+ model = schemeModel;
95
95
  /**
96
- * Stores shared instances of IDbCollectionFieldValues per collection+data
96
+ * Create a new IDbBase instance.
97
+ * @param model Optional custom model to use (default: schemeModel)
97
98
  */
98
- _collectionFieldValuesMap = new Map();
99
+ constructor(model) {
100
+ this.model = model ?? schemeModel;
101
+ }
99
102
  /**
100
- * Stores shared instances of IDbCollectionFieldForge per collection, field, and data
103
+ * Get an IDbCollection instance for a collection name.
101
104
  */
102
- _collectionFieldForgeMap = new Map();
105
+ get(collection) {
106
+ return new IDbCollection(collection, this);
107
+ }
103
108
  /**
104
- * Stores shared instances of IDbFormValidate per collection
109
+ * Get an IDbCollectionValues instance for a collection name.
105
110
  */
106
- _formValidateMap = new Map();
111
+ collectionValues(collection) {
112
+ return new IDbCollectionValues(collection, this);
113
+ }
107
114
  /**
108
- * The database model (schema) used for introspection.
115
+ * Get an IDbCollectionFieldValues instance for a collection and data.
109
116
  */
110
- model = schemeModel;
117
+ collectionFieldValues(collection, data) {
118
+ return new IDbCollectionFieldValues(collection, data, this.collectionValues(collection));
119
+ }
111
120
  /**
112
- * Create a new IDbCollections instance.
113
- * @param model Optional custom model to use (default: schemeModel)
121
+ * Get an IDbCollectionFieldForge instance for a collection, field, and data.
114
122
  */
115
- constructor(model) {
116
- this.model = model ?? schemeModel;
123
+ collectionFieldForge(collection, fieldName, data) {
124
+ return new IDbCollectionFieldForge(collection, fieldName, data, this.collectionValues(collection));
117
125
  }
118
- get(collection) {
119
- return new IDbCollection(collection, this);
126
+ /**
127
+ * Get an IDbFormValidate instance for a collection name.
128
+ */
129
+ formValidate(collection) {
130
+ return new IDbFormValidate(collection, this);
120
131
  }
121
132
  /**
122
133
  * Parse all collections in the model and return their fields as IDbForge objects.
123
- * @returns An object mapping collection names to their parsed fields.
124
134
  */
125
135
  parseAllCollections() {
126
136
  let out = {};
@@ -131,8 +141,6 @@ export class IDbCollections {
131
141
  }
132
142
  /**
133
143
  * Parse all fields of a given collection.
134
- * @param collection The collection name.
135
- * @returns An object mapping field names to their IDbForge representation.
136
144
  */
137
145
  parseRawCollection(collection) {
138
146
  const fields = this.getCollectionTemplateFields(collection);
@@ -149,9 +157,6 @@ export class IDbCollections {
149
157
  }
150
158
  /**
151
159
  * Parse a single field of a collection and return its IDbForge metadata.
152
- * @param collection The collection name.
153
- * @param fieldName The field name.
154
- * @returns The IDbForge object for the field, or throws if not found.
155
160
  */
156
161
  parseCollectionFieldName(collection, fieldName) {
157
162
  const field = this.#getTemplateFieldRule(collection, fieldName);
@@ -166,178 +171,53 @@ export class IDbCollections {
166
171
  const fieldType = array ?? object ?? fk ?? primitive;
167
172
  return this.forge({ collection, fieldName, ...fieldType });
168
173
  }
169
- /**
170
- * Parse a field rule string and extract its type and arguments.
171
- * @param fieldRule The field rule string.
172
- * @returns Partial IDbForge info for the rule.
173
- */
174
- parsFieldRule(fieldRule) {
175
- if (!fieldRule)
176
- return;
177
- const fieldType = this.testIs('primitive', fieldRule) ??
178
- this.testIs('array', fieldRule) ??
179
- this.testIs('object', fieldRule) ??
180
- this.testIs('fk', fieldRule);
181
- return fieldType;
182
- }
183
174
  /**
184
175
  * Internal helper to construct an IDbForge object from its components.
185
- * @param params The IDbForge properties (collection, fieldName, fieldType, fieldRule, fieldArgs, is).
186
- * @returns The constructed IDbForge object.
187
176
  */
188
177
  forge({ collection, fieldName, fieldType, fieldRule, fieldArgs, is }) {
189
- return {
190
- collection,
191
- fieldName,
192
- fieldType,
193
- fieldRule,
194
- fieldArgs,
195
- is
196
- };
178
+ return { collection, fieldName, fieldType, fieldRule, fieldArgs, is };
197
179
  }
198
180
  #getModel() {
199
181
  return this.model;
200
182
  }
201
- /**
202
- * Get the collection object from the model.
203
- * @param collection The collection name.
204
- * @returns The collection object.
205
- */
206
183
  getCollection(collection) {
207
184
  return this.#getModel()[String(collection)];
208
- } /**
209
- * Get the collection object from the model.
210
- * @param collection The collection name.
211
- * @returns The collection object.
212
- */
185
+ }
213
186
  getCollectionModel(collection) {
214
187
  return this.#getModel()[String(collection)];
215
188
  }
216
- /**
217
- * Get the template object for a collection.
218
- * @param collection The collection name.
219
- * @returns The template object.
220
- */
221
189
  getCollectionModelTemplate(collection) {
222
190
  return this.getCollectionModel(collection)['template'];
223
191
  }
224
- /**
225
- * Get the foreign keys (fks) object for a collection.
226
- * @param collection The collection name.
227
- * @returns The fks object.
228
- */
229
192
  getCollectionModelTemplateFks(collection) {
230
193
  return this.getCollectionModel(collection)['template']?.fks;
231
194
  }
232
- /**
233
- * Get the index field name for a collection.
234
- * @param collection The collection name.
235
- * @returns The index field name.
236
- */
237
195
  getIndexName(collection) {
238
196
  return this.getCollectionModel(collection)?.template?.index;
239
197
  }
240
- /**
241
- * Returns a shared instance of IDbCollectionValues for a given collection
242
- */
243
- getCollectionValues(collection) {
244
- if (!this._collectionValuesMap[collection]) {
245
- this._collectionValuesMap[collection] = new IDbCollectionValues(collection, this);
246
- }
247
- return this._collectionValuesMap[collection];
248
- }
249
- /**
250
- * Returns a shared instance of IDbCollectionFieldValues for a given collection and data
251
- * The instance key is based on the collection and the main index of data (or JSON if missing)
252
- */
253
- getCollectionFieldValues(collection, data) {
254
- const indexName = this.getIndexName(collection);
255
- const indexValue = data?.[indexName];
256
- const key = `${collection}:${indexValue ?? JSON.stringify(data)}`;
257
- if (!this._collectionFieldValuesMap.has(key)) {
258
- this._collectionFieldValuesMap.set(key, new IDbCollectionFieldValues(collection, data, this.getCollectionValues(collection)));
259
- }
260
- return this._collectionFieldValuesMap.get(key);
261
- }
262
- /**
263
- * Returns a shared instance of IDbCollectionFieldForge for a given collection, field, and data
264
- * The instance key is based on collection, field, and the main index of data (or JSON if missing)
265
- */
266
- getCollectionFieldForge(collection, fieldName, data) {
267
- const indexName = this.getIndexName(collection);
268
- const indexValue = data?.[indexName];
269
- const key = `${collection}:${String(fieldName)}:${indexValue ?? JSON.stringify(data)}`;
270
- if (!this._collectionFieldForgeMap.has(key)) {
271
- this._collectionFieldForgeMap.set(key, new IDbCollectionFieldForge(collection, fieldName, data, this.getCollectionValues(collection)));
272
- }
273
- return this._collectionFieldForgeMap.get(key);
274
- }
275
- /**
276
- * Returns a shared instance of IDbFormValidate for a given collection
277
- */
278
- getFormValidate(collection) {
279
- if (!this._formValidateMap.has(collection)) {
280
- this._formValidateMap.set(collection, new IDbFormValidate(collection, this));
281
- }
282
- return this._formValidateMap.get(collection);
283
- }
284
- /**
285
- * Get the fields object for a collection.
286
- * @param collection The collection name.
287
- * @returns The fields object.
288
- */
289
198
  getCollectionTemplateFields(collection) {
290
199
  return this.getCollectionModelTemplate(collection)?.fields;
291
200
  }
292
- /**
293
- * Get the presentation string for a collection (used for display).
294
- * @param collection The collection name.
295
- * @returns The presentation string.
296
- */
297
201
  getTemplatePresentation(collection) {
298
202
  return this.getCollectionModelTemplate(collection)?.presentation;
299
203
  }
300
204
  #getTemplateFieldRule(collection, fieldName) {
301
205
  return this.getCollectionTemplateFields(collection)?.[String(fieldName)];
302
206
  }
303
- /**
304
- * Get the field rule for a foreign key field (e.g. 'collection.field').
305
- * @param string The string in the form 'collection.field'.
306
- * @returns The field rule string, or undefined.
307
- */
308
207
  getFkFieldType(string) {
309
208
  const [collection, field] = string.split('.');
310
209
  let template = this.#getTemplateFieldRule(collection, field);
311
210
  return template;
312
211
  }
313
- /**
314
- * Get the fields object for a foreign key collection.
315
- * @param string The string in the form 'collection.field'.
316
- * @returns The fields object for the referenced collection.
317
- */
318
212
  getFkTemplateFields(string) {
319
213
  const [collection, field] = string.split('.');
320
214
  return this.getCollectionModel(collection).template?.fields;
321
215
  }
322
- /**
323
- * Test if a field rule matches a given type (primitive, array, object, fk).
324
- * @param what The type to test ('primitive', 'array', 'object', 'fk').
325
- * @param fieldRule The field rule string.
326
- * @returns Partial IDbForge info if match, else undefined.
327
- */
328
216
  testIs(what, fieldRule) {
329
- const typeMappings = {
330
- fk: 'fk-',
331
- array: 'array-of-',
332
- object: 'object-',
333
- primitive: ''
334
- };
217
+ const typeMappings = { fk: 'fk-', array: 'array-of-', object: 'object-', primitive: '' };
335
218
  const prefix = typeMappings[what];
336
219
  if (what === 'primitive') {
337
- // Un type primitif ne doit pas commencer par un préfixe array/object/fk
338
- if (!fieldRule.startsWith('array-of-') &&
339
- !fieldRule.startsWith('object-') &&
340
- !fieldRule.startsWith('fk-')) {
220
+ if (!fieldRule.startsWith('array-of-') && !fieldRule.startsWith('object-') && !fieldRule.startsWith('fk-')) {
341
221
  return this.is(what, fieldRule);
342
222
  }
343
223
  return undefined;
@@ -347,35 +227,11 @@ export class IDbCollections {
347
227
  }
348
228
  return undefined;
349
229
  }
350
- /**
351
- * Extract type information for a field rule.
352
- * @param what The type to extract ('primitive', 'array', 'object', 'fk').
353
- * @param fieldRule The field rule string.
354
- * @returns Partial IDbForge info.
355
- */
356
230
  is(what, fieldRule) {
357
231
  return this.extract(what, fieldRule);
358
232
  }
359
- /**
360
- * Get the value of the index field for a given data object.
361
- * @param collection The collection name.
362
- * @param data The data object.
363
- * @returns The value of the index field.
364
- */
365
- indexValue(collection, data) {
366
- let presentation = this.getIndexName(collection);
367
- return data[presentation];
368
- }
369
- /**
370
- * Extracts type, rule, and argument information from a field rule string.
371
- * @param type The type to extract ('primitive', 'array', 'object', 'fk').
372
- * @param fieldRule The field rule string.
373
- * @returns Partial IDbForge info.
374
- */
375
233
  extract(type, fieldRule) {
376
- // fieldType
377
234
  function extractAfter(pattern, source) {
378
- // remove all between () on source
379
235
  const reg = source?.split('(')?.[0];
380
236
  return reg.split(pattern)[1];
381
237
  }
@@ -385,7 +241,6 @@ export class IDbCollections {
385
241
  return { piece: piece.trim(), args: undefined };
386
242
  const [central] = remaining?.split(')');
387
243
  const args = central?.split(' ');
388
- // console.log({ piece, args });
389
244
  return { piece: piece.trim(), args };
390
245
  }
391
246
  let extractedArgs = extractArgs(fieldRule);
@@ -402,7 +257,6 @@ export class IDbCollections {
402
257
  is = is ?? fieldType;
403
258
  break;
404
259
  case 'fk':
405
- // Pour les fk, fieldType doit rester la string d'origine (ex: 'fk-agentPrompt.id')
406
260
  fieldType = 'fk-' + extractAfter('fk-', fieldRule);
407
261
  is = extractedArgs?.piece;
408
262
  break;
@@ -413,15 +267,9 @@ export class IDbCollections {
413
267
  }
414
268
  return { fieldType, fieldRule, fieldArgs, is: type };
415
269
  }
416
- /**
417
- * Parse and return all foreign key collections referenced by a collection.
418
- * @param collection The collection name.
419
- * @returns An object mapping referenced collection names to their parsed fields.
420
- */
421
270
  fks(collection) {
422
- let fks = this.getCollectionTemplateFks(collection);
271
+ let fks = this.getCollectionModelTemplateFks(collection);
423
272
  let out = {};
424
- // loop over fks
425
273
  if (fks) {
426
274
  Object.keys(fks).forEach((collection) => {
427
275
  out[collection] = this.parseRawCollection(collection);
@@ -429,11 +277,6 @@ export class IDbCollections {
429
277
  }
430
278
  return out;
431
279
  }
432
- /**
433
- * Find all collections that reference the target collection via a foreign key.
434
- * @param targetCollection The collection name to search for as a target.
435
- * @returns An object mapping referencing collections to their fk configs.
436
- */
437
280
  reverseFks(targetCollection) {
438
281
  const result = {};
439
282
  Object.entries(this.#getModel()).forEach(([collectionName, collectionModel]) => {
@@ -451,42 +294,19 @@ export class IDbCollections {
451
294
  });
452
295
  return result;
453
296
  }
454
- // iterate base
455
- /**
456
- * Iterate over an array field and return an array of IDbForge objects for each element.
457
- * @param collection The collection name.
458
- * @param fieldName The field name.
459
- * @param data The array data.
460
- * @returns An array of IDbForge objects.
461
- */
462
297
  iterateArrayField(collection, fieldName, data) {
463
298
  const fieldInfo = this.parseCollectionFieldName(collection, fieldName);
464
299
  if (fieldInfo?.is !== 'array' || !Array.isArray(data)) {
465
300
  return [];
466
301
  }
467
- // Retourne un tableau d'objets IDbForge génériques pour chaque élément
468
- return data.map((_, idx) => ({
469
- ...fieldInfo,
470
- fieldName: `${String(fieldName)}[${idx}]`,
471
- }));
302
+ return data.map((_, idx) => ({ ...fieldInfo, fieldName: `${String(fieldName)}[${idx}]` }));
472
303
  }
473
- /**
474
- * Iterate over an object field and return an array of IDbForge objects for each property.
475
- * @param collection The collection name.
476
- * @param fieldName The field name.
477
- * @param data The object data.
478
- * @returns An array of IDbForge objects.
479
- */
480
304
  iterateObjectField(collection, fieldName, data) {
481
305
  const fieldInfo = this.parseCollectionFieldName(collection, fieldName);
482
306
  if (fieldInfo?.is !== 'object' || typeof data !== 'object' || data === null) {
483
307
  return [];
484
308
  }
485
- // Retourne un tableau d'objets IDbForge génériques pour chaque clé
486
- return Object.keys(data).map((key) => ({
487
- ...fieldInfo,
488
- fieldName: `${String(fieldName)}.${key}`,
489
- }));
309
+ return Object.keys(data).map((key) => ({ ...fieldInfo, fieldName: `${String(fieldName)}.${key}` }));
490
310
  }
491
311
  }
492
312
  /**
@@ -528,7 +348,7 @@ export class IDbCollectionValues {
528
348
  */
529
349
  constructor(collectionName, idbCollections) {
530
350
  this.collectionName = collectionName;
531
- this.idbCollections = idbCollections ?? new IDbCollections();
351
+ this.idbCollections = idbCollections ?? new IDbBase();
532
352
  }
533
353
  presentation(data) {
534
354
  try {
@@ -809,7 +629,7 @@ export class IDbFormValidate {
809
629
  idbCollections;
810
630
  constructor(collection, idbCollections) {
811
631
  this.collection = collection;
812
- this.idbCollections = idbCollections ?? new IDbCollections();
632
+ this.idbCollections = idbCollections ?? new IDbBase();
813
633
  }
814
634
  validateField(fieldName, value) {
815
635
  try {
@@ -453,4 +453,4 @@ export declare const schemeModelDb: {
453
453
  };
454
454
  export declare const schemeModel: IdbqModel;
455
455
  export type DataModelFinal = DbDataModelTs<typeof schemeModelDb>;
456
- 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>>>;
456
+ export declare const idbql: any, idbqlState: any, idbDatabase: any, idbqModel: any;
@@ -53,4 +53,4 @@ export declare const schemeModelTestDb: {
53
53
  };
54
54
  export declare const schemeModelTest: IdbqModel;
55
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>>>;
56
+ export declare const idbql: any, idbqlState: any, idbDatabase: any, idbqModel: any;
@@ -1,5 +1,5 @@
1
1
  <script lang="ts">
2
- import { IDbCollections } from '../db/dbFields.js';
2
+ import { IDbBase } from '../db/dbFields.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';
@@ -15,7 +15,7 @@
15
15
  // idbqlState[fkCollection].get(fkId);
16
16
 
17
17
  const dbFields = machine.collections;
18
- const collections = new IDbCollections(schemeModel);
18
+ const collections = new IDbBase(schemeModel);
19
19
  const fks = $derived(collections.fks(collection));
20
20
  </script>
21
21
 
@@ -2,7 +2,7 @@
2
2
  import { type MenuListProps, Button, MenuList, MenuListItem, openWindow, type Props } from '@medyll/idae-slotui-svelte';
3
3
  import CreateUpdate from './CreateUpdate.svelte';
4
4
  import { idbqlState } from '../db/dbSchema';
5
- import { IDbCollections, IDbCollectionValues } from '../db/dbFields';
5
+ import { IDbBase, IDbCollectionValues } from '../db/dbFields';
6
6
  import { hydrate } from 'svelte';
7
7
  import type { Where } from '@medyll/idae-idbql';
8
8
 
@@ -18,7 +18,7 @@
18
18
 
19
19
  let { collection, target, data, menuListProps, onclick, style, where }: DataListMenuProps = $props();
20
20
 
21
- let test = new IDbCollections();
21
+ let test = new IDbBase();
22
22
  let fieldValues = new IDbCollectionValues(collection);
23
23
  let index = test.getIndexName(collection);
24
24
 
@@ -14,7 +14,7 @@
14
14
  }
15
15
  -->
16
16
  <script lang="ts">
17
- import { IDbCollections } from '../db/dbFields.js';
17
+ import { IDbBase } 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';
@@ -30,7 +30,7 @@
30
30
  componentProps?: Record<string, any>;
31
31
  };
32
32
  let { collection, children: child, showTitle = false, component, componentProps = {} }: CollectionFksProps = $props();
33
- const dbFields = new IDbCollections(schemeModel);
33
+ const dbFields = new IDbBase(schemeModel);
34
34
  const fks = $derived(dbFields.reverseFks(collection));
35
35
 
36
36
  function getTitle() {
@@ -29,7 +29,7 @@
29
29
  showAiGuess = false
30
30
  }: FieldValueProps = $props();
31
31
 
32
- let _data = getContext('data');
32
+ let _data = getContext('data');
33
33
 
34
34
  data = data ?? ({} as COL);
35
35
 
@@ -24,7 +24,7 @@
24
24
  * // Access the IDBQL data model
25
25
  * const model = machine.idbqModel;
26
26
  */
27
- import { IDbCollections } from '../db/dbFields.js';
27
+ import { IDbBase } from '../db/dbFields.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.
@@ -50,7 +50,7 @@ export declare class Machine {
50
50
  /**
51
51
  * Centralized access to schema and collection logic
52
52
  */
53
- _collections: IDbCollections;
53
+ _collections: IDbBase;
54
54
  /**
55
55
  * Database name
56
56
  */
@@ -81,23 +81,23 @@ export declare class Machine {
81
81
  /**
82
82
  * Get the IDbCollections (schema logic) instance
83
83
  */
84
- get collections(): IDbCollections;
84
+ get collections(): IDbBase;
85
85
  /**
86
86
  * IDBQL (readonly) instance
87
87
  */
88
- get idbql(): import("@medyll/idae-idbql").ReadonlyCollections<IdbqModel<Record<string, Record<string, any>>>> | undefined;
88
+ get idbql(): any;
89
89
  /**
90
90
  * IDBQL (stateful) instance
91
91
  */
92
- get store(): import("@medyll/idae-idbql").StateCollections<IdbqModel<Record<string, Record<string, any>>>>;
92
+ get store(): any;
93
93
  /**
94
94
  * IndexedDB (core) instance
95
95
  * @deprecated
96
96
  */
97
- get indexedb(): import("@medyll/idae-idbql").IdbqlIndexedCore<IdbqModel<Record<string, Record<string, any>>>> | undefined;
97
+ get indexedb(): any;
98
98
  /**
99
99
  * IDBQL data model instance
100
100
  */
101
- get idbqModel(): IdbqModel<Record<string, Record<string, any>>> | undefined;
101
+ get idbqModel(): any;
102
102
  }
103
103
  export declare const machine: Machine;
@@ -24,7 +24,7 @@
24
24
  * // Access the IDBQL data model
25
25
  * const model = machine.idbqModel;
26
26
  */
27
- import { IDbCollections } from '../db/dbFields.js';
27
+ import { IDbBase } from '../db/dbFields.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.
@@ -84,7 +84,7 @@ export class Machine {
84
84
  if (!this._model) {
85
85
  throw new Error('Data model is not defined');
86
86
  }
87
- this._collections = new IDbCollections(this._model);
87
+ this._collections = new IDbBase(this._model);
88
88
  }
89
89
  createStore() {
90
90
  if (!this._model || !this._dbName || !this._version) {
package/package.json CHANGED
@@ -1,66 +1,65 @@
1
1
  {
2
- "name": "@medyll/idae-machine",
3
- "version": "0.112.0",
4
- "scripts": {
5
- "dev": "vite dev",
6
- "build": "vite build && npm run prepack",
7
- "preview": "vite preview",
8
- "prepare": "svelte-kit sync || echo ''",
9
- "prepack": "svelte-kit sync && svelte-package && publint",
10
- "check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
11
- "check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
12
- "format": "prettier --write .",
13
- "lint": "prettier --check . && eslint .",
14
- "test:unit": "vitest",
15
- "test": "npm run test:unit -- --run",
16
- "package:pre": "node scripts/package-pre.js"
17
- },
18
- "files": [
19
- "dist",
20
- "!dist/**/*.test.*",
21
- "!dist/**/*.spec.*"
22
- ],
23
- "sideEffects": [
24
- "**/*.css"
25
- ],
26
- "svelte": "./dist/index.js",
27
- "types": "./dist/index.d.ts",
28
- "type": "module",
29
- "exports": {
30
- ".": {
31
- "types": "./dist/index.d.ts",
32
- "svelte": "./dist/index.js"
33
- }
34
- },
35
- "peerDependencies": {
36
- "svelte": "^5.0.0"
37
- },
38
- "devDependencies": {
39
- "@eslint/compat": "^1.2.7",
40
- "@eslint/js": "^9.23.0",
41
- "@sveltejs/adapter-auto": "^5.0.0",
42
- "@sveltejs/kit": "^2.20.2",
43
- "@sveltejs/package": "^2.3.10",
44
- "@sveltejs/vite-plugin-svelte": "^5.0.3",
45
- "@testing-library/jest-dom": "^6.6.3",
46
- "@testing-library/svelte": "^5.2.7",
47
- "eslint": "^9.23.0",
48
- "eslint-config-prettier": "^10.1.1",
49
- "eslint-plugin-svelte": "^3.3.3",
50
- "globals": "^16.0.0",
51
- "jsdom": "^26.0.0",
52
- "prettier": "^3.5.3",
53
- "prettier-plugin-svelte": "^3.3.3",
54
- "publint": "^0.3.9",
55
- "svelte": "^5.25.3",
56
- "svelte-check": "^4.1.5",
57
- "typescript": "^5.8.2",
58
- "typescript-eslint": "^8.28.0",
59
- "vite": "^6.2.3",
60
- "vitest": "^3.0.9"
61
- },
62
- "scope": "@medyll",
63
- "dependencies": {
64
- "@huggingface/prettier-plugin-vertical-align": "^0.2.3"
65
- }
66
- }
2
+ "name": "@medyll/idae-machine",
3
+ "version": "0.114.0",
4
+ "files": [
5
+ "dist",
6
+ "!dist/**/*.test.*",
7
+ "!dist/**/*.spec.*"
8
+ ],
9
+ "sideEffects": [
10
+ "**/*.css"
11
+ ],
12
+ "svelte": "./dist/index.js",
13
+ "types": "./dist/index.d.ts",
14
+ "type": "module",
15
+ "exports": {
16
+ ".": {
17
+ "types": "./dist/index.d.ts",
18
+ "svelte": "./dist/index.js"
19
+ }
20
+ },
21
+ "peerDependencies": {
22
+ "svelte": "^5.0.0"
23
+ },
24
+ "devDependencies": {
25
+ "@eslint/compat": "^1.2.7",
26
+ "@eslint/js": "^9.23.0",
27
+ "@sveltejs/adapter-auto": "^5.0.0",
28
+ "@sveltejs/kit": "^2.20.2",
29
+ "@sveltejs/package": "^2.3.10",
30
+ "@sveltejs/vite-plugin-svelte": "^5.0.3",
31
+ "@testing-library/jest-dom": "^6.6.3",
32
+ "@testing-library/svelte": "^5.2.7",
33
+ "eslint": "^9.23.0",
34
+ "eslint-config-prettier": "^10.1.1",
35
+ "eslint-plugin-svelte": "^3.3.3",
36
+ "globals": "^16.0.0",
37
+ "jsdom": "^26.0.0",
38
+ "prettier": "^3.5.3",
39
+ "prettier-plugin-svelte": "^3.3.3",
40
+ "publint": "^0.3.9",
41
+ "svelte": "^5.25.3",
42
+ "svelte-check": "^4.1.5",
43
+ "typescript": "^5.8.2",
44
+ "typescript-eslint": "^8.28.0",
45
+ "vite": "^6.2.3",
46
+ "vitest": "^3.0.9",
47
+ "@medyll/idae-prettier-config": "1.2.1"
48
+ },
49
+ "scope": "@medyll",
50
+ "dependencies": {
51
+ "@huggingface/prettier-plugin-vertical-align": "^0.2.3"
52
+ },
53
+ "scripts": {
54
+ "dev": "vite dev",
55
+ "build": "vite build && npm run prepack",
56
+ "preview": "vite preview",
57
+ "check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
58
+ "check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
59
+ "format": "prettier --write .",
60
+ "lint": "prettier --check . && eslint .",
61
+ "test:unit": "vitest",
62
+ "test": "npm run test:unit -- --run",
63
+ "package:pre": "node scripts/package-pre.js"
64
+ }
65
+ }