@medyll/idae-machine 0.113.0 → 0.115.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/dist/db/dbFields.d.ts +26 -148
- package/dist/db/dbFields.js +41 -221
- package/dist/form/CollectionFks.svelte +2 -2
- package/dist/form/CollectionListMenu.svelte +2 -2
- package/dist/form/CollectionReverseFks.svelte +2 -2
- package/dist/main/machine.d.ts +3 -3
- package/dist/main/machine.js +2 -2
- package/package.json +1 -1
package/dist/db/dbFields.d.ts
CHANGED
|
@@ -40,8 +40,8 @@ export type IDbForge = {
|
|
|
40
40
|
};
|
|
41
41
|
export declare class IDbCollection {
|
|
42
42
|
collection: TplCollectionName;
|
|
43
|
-
_dbCollections:
|
|
44
|
-
constructor(collection: TplCollectionName, dbCollections:
|
|
43
|
+
_dbCollections: IDbBase;
|
|
44
|
+
constructor(collection: TplCollectionName, dbCollections: IDbBase);
|
|
45
45
|
getCollectionModelTemplate(): Tpl;
|
|
46
46
|
getCollectionModelTemplateFks(): Tpl;
|
|
47
47
|
getIndexName(): any;
|
|
@@ -59,192 +59,70 @@ export declare class IDbCollection {
|
|
|
59
59
|
* Provides methods to access collections, templates, fields, foreign keys, and type information.
|
|
60
60
|
* Used for dynamic UI generation, validation, and schema-driven logic.
|
|
61
61
|
*/
|
|
62
|
-
export declare class
|
|
62
|
+
export declare class IDbBase {
|
|
63
63
|
#private;
|
|
64
64
|
/**
|
|
65
|
-
*
|
|
65
|
+
* The database model (schema) used for introspection.
|
|
66
66
|
*/
|
|
67
|
-
|
|
67
|
+
model: IdbqModel;
|
|
68
68
|
/**
|
|
69
|
-
*
|
|
69
|
+
* Create a new IDbBase instance.
|
|
70
|
+
* @param model Optional custom model to use (default: schemeModel)
|
|
70
71
|
*/
|
|
71
|
-
|
|
72
|
+
constructor(model?: IdbqModel);
|
|
72
73
|
/**
|
|
73
|
-
*
|
|
74
|
+
* Get an IDbCollection instance for a collection name.
|
|
74
75
|
*/
|
|
75
|
-
|
|
76
|
+
get(collection: TplCollectionName): IDbCollection;
|
|
76
77
|
/**
|
|
77
|
-
*
|
|
78
|
+
* Get an IDbCollectionValues instance for a collection name.
|
|
78
79
|
*/
|
|
79
|
-
|
|
80
|
+
collectionValues(collection: TplCollectionName): IDbCollectionValues<any>;
|
|
80
81
|
/**
|
|
81
|
-
*
|
|
82
|
+
* Get an IDbCollectionFieldValues instance for a collection and data.
|
|
82
83
|
*/
|
|
83
|
-
|
|
84
|
+
collectionFieldValues<T extends Record<string, any>>(collection: TplCollectionName, data: T): IDbCollectionFieldValues<T>;
|
|
84
85
|
/**
|
|
85
|
-
*
|
|
86
|
-
* @param model Optional custom model to use (default: schemeModel)
|
|
86
|
+
* Get an IDbCollectionFieldForge instance for a collection, field, and data.
|
|
87
87
|
*/
|
|
88
|
-
|
|
89
|
-
|
|
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;
|
|
90
93
|
/**
|
|
91
94
|
* Parse all collections in the model and return their fields as IDbForge objects.
|
|
92
|
-
* @returns An object mapping collection names to their parsed fields.
|
|
93
95
|
*/
|
|
94
96
|
parseAllCollections(): Record<string, Record<string, IDbForge | undefined> | undefined>;
|
|
95
97
|
/**
|
|
96
98
|
* Parse all fields of a given collection.
|
|
97
|
-
* @param collection The collection name.
|
|
98
|
-
* @returns An object mapping field names to their IDbForge representation.
|
|
99
99
|
*/
|
|
100
100
|
parseRawCollection(collection: TplCollectionName): Record<string, IDbForge | undefined> | undefined;
|
|
101
101
|
/**
|
|
102
102
|
* Parse a single field of a collection and return its IDbForge metadata.
|
|
103
|
-
* @param collection The collection name.
|
|
104
|
-
* @param fieldName The field name.
|
|
105
|
-
* @returns The IDbForge object for the field, or throws if not found.
|
|
106
103
|
*/
|
|
107
104
|
parseCollectionFieldName(collection: TplCollectionName, fieldName: keyof TplFields): IDbForge | undefined;
|
|
108
|
-
/**
|
|
109
|
-
* Parse a field rule string and extract its type and arguments.
|
|
110
|
-
* @param fieldRule The field rule string.
|
|
111
|
-
* @returns Partial IDbForge info for the rule.
|
|
112
|
-
*/
|
|
113
|
-
parsFieldRule(fieldRule: IDbFieldRules): Partial<IDbForge> | undefined;
|
|
114
105
|
/**
|
|
115
106
|
* Internal helper to construct an IDbForge object from its components.
|
|
116
|
-
* @param params The IDbForge properties (collection, fieldName, fieldType, fieldRule, fieldArgs, is).
|
|
117
|
-
* @returns The constructed IDbForge object.
|
|
118
107
|
*/
|
|
119
108
|
private forge;
|
|
120
|
-
|
|
121
|
-
* Get the collection object from the model.
|
|
122
|
-
* @param collection The collection name.
|
|
123
|
-
* @returns The collection object.
|
|
124
|
-
*/
|
|
125
|
-
getCollection(collection: TplCollectionName): CollectionModel; /**
|
|
126
|
-
* Get the collection object from the model.
|
|
127
|
-
* @param collection The collection name.
|
|
128
|
-
* @returns The collection object.
|
|
129
|
-
*/
|
|
109
|
+
getCollection(collection: TplCollectionName): CollectionModel;
|
|
130
110
|
getCollectionModel(collection: TplCollectionName): CollectionModel;
|
|
131
|
-
/**
|
|
132
|
-
* Get the template object for a collection.
|
|
133
|
-
* @param collection The collection name.
|
|
134
|
-
* @returns The template object.
|
|
135
|
-
*/
|
|
136
111
|
getCollectionModelTemplate(collection: TplCollectionName): Tpl;
|
|
137
|
-
/**
|
|
138
|
-
* Get the foreign keys (fks) object for a collection.
|
|
139
|
-
* @param collection The collection name.
|
|
140
|
-
* @returns The fks object.
|
|
141
|
-
*/
|
|
142
112
|
getCollectionModelTemplateFks(collection: TplCollectionName): Tpl["fks"];
|
|
143
|
-
/**
|
|
144
|
-
* Get the index field name for a collection.
|
|
145
|
-
* @param collection The collection name.
|
|
146
|
-
* @returns The index field name.
|
|
147
|
-
*/
|
|
148
113
|
getIndexName(collection: TplCollectionName): any;
|
|
149
|
-
/**
|
|
150
|
-
* Returns a shared instance of IDbCollectionValues for a given collection
|
|
151
|
-
*/
|
|
152
|
-
getCollectionValues(collection: TplCollectionName): IDbCollectionValues<any>;
|
|
153
|
-
/**
|
|
154
|
-
* Returns a shared instance of IDbCollectionFieldValues for a given collection and data
|
|
155
|
-
* The instance key is based on the collection and the main index of data (or JSON if missing)
|
|
156
|
-
*/
|
|
157
|
-
getCollectionFieldValues<T extends Record<string, any>>(collection: TplCollectionName, data: T): IDbCollectionFieldValues<T>;
|
|
158
|
-
/**
|
|
159
|
-
* Returns a shared instance of IDbCollectionFieldForge for a given collection, field, and data
|
|
160
|
-
* The instance key is based on collection, field, and the main index of data (or JSON if missing)
|
|
161
|
-
*/
|
|
162
|
-
getCollectionFieldForge<T extends Record<string, any>>(collection: TplCollectionName, fieldName: keyof T | string, data: T): IDbCollectionFieldForge<T>;
|
|
163
|
-
/**
|
|
164
|
-
* Returns a shared instance of IDbFormValidate for a given collection
|
|
165
|
-
*/
|
|
166
|
-
getFormValidate(collection: TplCollectionName): IDbFormValidate;
|
|
167
|
-
/**
|
|
168
|
-
* Get the fields object for a collection.
|
|
169
|
-
* @param collection The collection name.
|
|
170
|
-
* @returns The fields object.
|
|
171
|
-
*/
|
|
172
114
|
getCollectionTemplateFields(collection: TplCollectionName): TplFields;
|
|
173
|
-
/**
|
|
174
|
-
* Get the presentation string for a collection (used for display).
|
|
175
|
-
* @param collection The collection name.
|
|
176
|
-
* @returns The presentation string.
|
|
177
|
-
*/
|
|
178
115
|
getTemplatePresentation(collection: TplCollectionName): string;
|
|
179
|
-
/**
|
|
180
|
-
* Get the field rule for a foreign key field (e.g. 'collection.field').
|
|
181
|
-
* @param string The string in the form 'collection.field'.
|
|
182
|
-
* @returns The field rule string, or undefined.
|
|
183
|
-
*/
|
|
184
116
|
getFkFieldType(string: `${string}.${string}`): IDbFieldRules | undefined;
|
|
185
|
-
/**
|
|
186
|
-
* Get the fields object for a foreign key collection.
|
|
187
|
-
* @param string The string in the form 'collection.field'.
|
|
188
|
-
* @returns The fields object for the referenced collection.
|
|
189
|
-
*/
|
|
190
117
|
getFkTemplateFields(string: `${string}.${string}`): any;
|
|
191
|
-
/**
|
|
192
|
-
* Test if a field rule matches a given type (primitive, array, object, fk).
|
|
193
|
-
* @param what The type to test ('primitive', 'array', 'object', 'fk').
|
|
194
|
-
* @param fieldRule The field rule string.
|
|
195
|
-
* @returns Partial IDbForge info if match, else undefined.
|
|
196
|
-
*/
|
|
197
118
|
private testIs;
|
|
198
|
-
/**
|
|
199
|
-
* Extract type information for a field rule.
|
|
200
|
-
* @param what The type to extract ('primitive', 'array', 'object', 'fk').
|
|
201
|
-
* @param fieldRule The field rule string.
|
|
202
|
-
* @returns Partial IDbForge info.
|
|
203
|
-
*/
|
|
204
119
|
is(what: 'array' | 'object' | 'fk' | 'primitive', fieldRule: IDbFieldRules): Partial<IDbForge>;
|
|
205
|
-
/**
|
|
206
|
-
* Get the value of the index field for a given data object.
|
|
207
|
-
* @param collection The collection name.
|
|
208
|
-
* @param data The data object.
|
|
209
|
-
* @returns The value of the index field.
|
|
210
|
-
*/
|
|
211
|
-
indexValue(collection: TplCollectionName, data: Record<string, any>): any;
|
|
212
|
-
/**
|
|
213
|
-
* Extracts type, rule, and argument information from a field rule string.
|
|
214
|
-
* @param type The type to extract ('primitive', 'array', 'object', 'fk').
|
|
215
|
-
* @param fieldRule The field rule string.
|
|
216
|
-
* @returns Partial IDbForge info.
|
|
217
|
-
*/
|
|
218
120
|
extract(type: 'array' | 'object' | 'fk' | 'primitive', fieldRule: IDbFieldRules): Partial<IDbForge>;
|
|
219
|
-
/**
|
|
220
|
-
* Parse and return all foreign key collections referenced by a collection.
|
|
221
|
-
* @param collection The collection name.
|
|
222
|
-
* @returns An object mapping referenced collection names to their parsed fields.
|
|
223
|
-
*/
|
|
224
121
|
fks(collection: string): {
|
|
225
122
|
[collection: string]: Tpl;
|
|
226
123
|
};
|
|
227
|
-
/**
|
|
228
|
-
* Find all collections that reference the target collection via a foreign key.
|
|
229
|
-
* @param targetCollection The collection name to search for as a target.
|
|
230
|
-
* @returns An object mapping referencing collections to their fk configs.
|
|
231
|
-
*/
|
|
232
124
|
reverseFks(targetCollection: TplCollectionName): Record<string, any>;
|
|
233
|
-
/**
|
|
234
|
-
* Iterate over an array field and return an array of IDbForge objects for each element.
|
|
235
|
-
* @param collection The collection name.
|
|
236
|
-
* @param fieldName The field name.
|
|
237
|
-
* @param data The array data.
|
|
238
|
-
* @returns An array of IDbForge objects.
|
|
239
|
-
*/
|
|
240
125
|
iterateArrayField(collection: TplCollectionName, fieldName: keyof TplFields, data: any[]): IDbForge[];
|
|
241
|
-
/**
|
|
242
|
-
* Iterate over an object field and return an array of IDbForge objects for each property.
|
|
243
|
-
* @param collection The collection name.
|
|
244
|
-
* @param fieldName The field name.
|
|
245
|
-
* @param data The object data.
|
|
246
|
-
* @returns An array of IDbForge objects.
|
|
247
|
-
*/
|
|
248
126
|
iterateObjectField(collection: TplCollectionName, fieldName: keyof TplFields, data: Record<string, any>): IDbForge[];
|
|
249
127
|
}
|
|
250
128
|
/**
|
|
@@ -276,7 +154,7 @@ export declare class IDbCollectionValues<T extends Record<string, any>> {
|
|
|
276
154
|
/**
|
|
277
155
|
* The IDbCollections instance used for schema introspection.
|
|
278
156
|
*/
|
|
279
|
-
idbCollections:
|
|
157
|
+
idbCollections: IDbBase;
|
|
280
158
|
/**
|
|
281
159
|
* The collection name this instance operates on.
|
|
282
160
|
*/
|
|
@@ -285,7 +163,7 @@ export declare class IDbCollectionValues<T extends Record<string, any>> {
|
|
|
285
163
|
* Create a new IDbCollectionValues instance for a given collection.
|
|
286
164
|
* @param collectionName The collection name.
|
|
287
165
|
*/
|
|
288
|
-
constructor(collectionName: TplCollectionName, idbCollections?:
|
|
166
|
+
constructor(collectionName: TplCollectionName, idbCollections?: IDbBase);
|
|
289
167
|
presentation(data: Record<string, any>): string;
|
|
290
168
|
/**
|
|
291
169
|
* Get the value of the index field for a data object.
|
|
@@ -331,7 +209,7 @@ export declare class IDbCollectionFieldValues<T extends Record<string, any>> {
|
|
|
331
209
|
getForge(fieldName: keyof T): IDbForge | undefined;
|
|
332
210
|
constructor(collection: TplCollectionName, data: T, collectionValues?: IDbCollectionValues<T>);
|
|
333
211
|
format(fieldName: keyof T): string | string[];
|
|
334
|
-
getInputDataSet(fieldName: keyof T): Record<"data-collection" | "data-
|
|
212
|
+
getInputDataSet(fieldName: keyof T): Record<"data-collection" | "data-collectionId" | "data-fieldName" | "data-fieldType" | "data-fieldArgs", string>;
|
|
335
213
|
iterateArray(fieldName: string, data: any[]): IDbForge[];
|
|
336
214
|
iterateObject(fieldName: string, data: Record<string, any>): IDbForge[];
|
|
337
215
|
}
|
|
@@ -361,7 +239,7 @@ export declare class IDbCollectionFieldForge<T extends Record<string, any>> {
|
|
|
361
239
|
#private;
|
|
362
240
|
constructor(collection: TplCollectionName, fieldName: any, data: T, collectionValues?: IDbCollectionValues<T>);
|
|
363
241
|
get format(): string;
|
|
364
|
-
get inputDataSet(): Record<"data-collection" | "data-
|
|
242
|
+
get inputDataSet(): Record<"data-collection" | "data-collectionId" | "data-fieldName" | "data-fieldType" | "data-fieldArgs", string>;
|
|
365
243
|
get forge(): IDbForge | undefined;
|
|
366
244
|
get fieldArgs(): IDbForgeArgs | undefined;
|
|
367
245
|
get fieldType(): IDbFieldType | undefined;
|
|
@@ -377,7 +255,7 @@ export declare class IDbFormValidate {
|
|
|
377
255
|
#private;
|
|
378
256
|
private collection;
|
|
379
257
|
private idbCollections;
|
|
380
|
-
constructor(collection: TplCollectionName, idbCollections?:
|
|
258
|
+
constructor(collection: TplCollectionName, idbCollections?: IDbBase);
|
|
381
259
|
validateField(fieldName: keyof TplFields, value: any): {
|
|
382
260
|
isValid: boolean;
|
|
383
261
|
error?: string;
|
package/dist/db/dbFields.js
CHANGED
|
@@ -64,16 +64,16 @@ export class IDbCollection {
|
|
|
64
64
|
return this._dbCollections.getIndexName(this.collection);
|
|
65
65
|
}
|
|
66
66
|
collectionValues() {
|
|
67
|
-
return this._dbCollections.
|
|
67
|
+
return this._dbCollections.collectionValues(this.collection);
|
|
68
68
|
}
|
|
69
69
|
collectionFieldValues(data) {
|
|
70
|
-
return this._dbCollections.
|
|
70
|
+
return this._dbCollections.collectionFieldValues(this.collection, data);
|
|
71
71
|
}
|
|
72
72
|
fieldForge(fieldName, data) {
|
|
73
|
-
return this._dbCollections.
|
|
73
|
+
return this._dbCollections.collectionFieldForge(this.collection, fieldName, data);
|
|
74
74
|
}
|
|
75
75
|
getFormValidate() {
|
|
76
|
-
return this._dbCollections.
|
|
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
|
|
90
|
+
export class IDbBase {
|
|
91
91
|
/**
|
|
92
|
-
*
|
|
92
|
+
* The database model (schema) used for introspection.
|
|
93
93
|
*/
|
|
94
|
-
|
|
94
|
+
model = schemeModel;
|
|
95
95
|
/**
|
|
96
|
-
*
|
|
96
|
+
* Create a new IDbBase instance.
|
|
97
|
+
* @param model Optional custom model to use (default: schemeModel)
|
|
97
98
|
*/
|
|
98
|
-
|
|
99
|
+
constructor(model) {
|
|
100
|
+
this.model = model ?? schemeModel;
|
|
101
|
+
}
|
|
99
102
|
/**
|
|
100
|
-
*
|
|
103
|
+
* Get an IDbCollection instance for a collection name.
|
|
101
104
|
*/
|
|
102
|
-
|
|
105
|
+
get(collection) {
|
|
106
|
+
return new IDbCollection(collection, this);
|
|
107
|
+
}
|
|
103
108
|
/**
|
|
104
|
-
*
|
|
109
|
+
* Get an IDbCollectionValues instance for a collection name.
|
|
105
110
|
*/
|
|
106
|
-
|
|
111
|
+
collectionValues(collection) {
|
|
112
|
+
return new IDbCollectionValues(collection, this);
|
|
113
|
+
}
|
|
107
114
|
/**
|
|
108
|
-
*
|
|
115
|
+
* Get an IDbCollectionFieldValues instance for a collection and data.
|
|
109
116
|
*/
|
|
110
|
-
|
|
117
|
+
collectionFieldValues(collection, data) {
|
|
118
|
+
return new IDbCollectionFieldValues(collection, data, this.collectionValues(collection));
|
|
119
|
+
}
|
|
111
120
|
/**
|
|
112
|
-
*
|
|
113
|
-
* @param model Optional custom model to use (default: schemeModel)
|
|
121
|
+
* Get an IDbCollectionFieldForge instance for a collection, field, and data.
|
|
114
122
|
*/
|
|
115
|
-
|
|
116
|
-
|
|
123
|
+
collectionFieldForge(collection, fieldName, data) {
|
|
124
|
+
return new IDbCollectionFieldForge(collection, fieldName, data, this.collectionValues(collection));
|
|
117
125
|
}
|
|
118
|
-
|
|
119
|
-
|
|
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
|
-
|
|
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.
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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
|
|
632
|
+
this.idbCollections = idbCollections ?? new IDbBase();
|
|
813
633
|
}
|
|
814
634
|
validateField(fieldName, value) {
|
|
815
635
|
try {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
import {
|
|
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
|
|
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 {
|
|
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
|
|
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 {
|
|
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
|
|
33
|
+
const dbFields = new IDbBase(schemeModel);
|
|
34
34
|
const fks = $derived(dbFields.reverseFks(collection));
|
|
35
35
|
|
|
36
36
|
function getTitle() {
|
package/dist/main/machine.d.ts
CHANGED
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
* // Access the IDBQL data model
|
|
25
25
|
* const model = machine.idbqModel;
|
|
26
26
|
*/
|
|
27
|
-
import {
|
|
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:
|
|
53
|
+
_collections: IDbBase;
|
|
54
54
|
/**
|
|
55
55
|
* Database name
|
|
56
56
|
*/
|
|
@@ -81,7 +81,7 @@ export declare class Machine {
|
|
|
81
81
|
/**
|
|
82
82
|
* Get the IDbCollections (schema logic) instance
|
|
83
83
|
*/
|
|
84
|
-
get collections():
|
|
84
|
+
get collections(): IDbBase;
|
|
85
85
|
/**
|
|
86
86
|
* IDBQL (readonly) instance
|
|
87
87
|
*/
|
package/dist/main/machine.js
CHANGED
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
* // Access the IDBQL data model
|
|
25
25
|
* const model = machine.idbqModel;
|
|
26
26
|
*/
|
|
27
|
-
import {
|
|
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
|
|
87
|
+
this._collections = new IDbBase(this._model);
|
|
88
88
|
}
|
|
89
89
|
createStore() {
|
|
90
90
|
if (!this._model || !this._dbName || !this._version) {
|