@medyll/idae-machine 0.121.0 → 0.123.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/form/CollectionFks.svelte +2 -2
- package/dist/form/CollectionList.svelte +2 -2
- package/dist/form/CollectionListMenu.svelte +3 -3
- package/dist/form/CollectionReverseFks.svelte +2 -2
- package/dist/form/FieldValue.svelte +2 -2
- package/dist/main/machine.d.ts +3 -3
- package/dist/main/machine.js +2 -2
- package/dist/main/machineDb.d.ts +23 -50
- package/dist/main/machineDb.js +64 -89
- package/package.json +3 -3
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
import {
|
|
2
|
+
import { MachineDb } 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';
|
|
@@ -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 MachineDb(schemeModel);
|
|
19
19
|
const fks = $derived(collections.fks(collection));
|
|
20
20
|
</script>
|
|
21
21
|
|
|
@@ -41,8 +41,8 @@ import {machine } from '../main/machine.js';
|
|
|
41
41
|
|
|
42
42
|
let collections = machine.collections;
|
|
43
43
|
let store = machine.store;
|
|
44
|
-
let fieldValues = machine.collections.
|
|
45
|
-
let index = collections.
|
|
44
|
+
let fieldValues = machine.collections.collection(collection).collectionValues() ;
|
|
45
|
+
let index = collections.collection(collection).getIndexName();
|
|
46
46
|
|
|
47
47
|
let qy = $derived(where ? store[collection].where(where) : store[collection].getAll());
|
|
48
48
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
<script lang="ts" generics="COL = Record<string,any>">
|
|
2
2
|
import { type MenuListProps, Button, MenuList, MenuListItem, openWindow, type Props } from '@medyll/idae-slotui-svelte';
|
|
3
3
|
import CreateUpdate from './CreateUpdate.svelte';
|
|
4
|
-
import { idbqlState } from '../db/dbSchema';
|
|
5
|
-
import {
|
|
4
|
+
import { idbqlState } from '../db/dbSchema.js';
|
|
5
|
+
import { MachineDb, IDbCollectionValues } from '../main/machineDb.js';
|
|
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 MachineDb();
|
|
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 { MachineDb } 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';
|
|
@@ -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 MachineDb(schemeModel);
|
|
34
34
|
const fks = $derived(dbFields.reverseFks(collection));
|
|
35
35
|
|
|
36
36
|
function getTitle() {
|
|
@@ -34,8 +34,8 @@
|
|
|
34
34
|
data = data ?? ({} as COL);
|
|
35
35
|
|
|
36
36
|
// Initialisation des valeurs de champ de collection
|
|
37
|
-
const forge = machine.collections.
|
|
38
|
-
let collectionFieldValues = machine.collections.
|
|
37
|
+
const forge = machine.collections.collection(collection).fieldForge(String(fieldName), data)
|
|
38
|
+
let collectionFieldValues = machine.collections.collection(collection).collectionValues()
|
|
39
39
|
let inputDataset = collectionFieldValues.getInputDataSet(fieldName, data);
|
|
40
40
|
|
|
41
41
|
// Création d'une instance de forge de champ de collection
|
package/dist/main/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 { MachineDb } 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.
|
|
@@ -49,7 +49,7 @@ export declare class Machine {
|
|
|
49
49
|
/**
|
|
50
50
|
* Centralized access to schema and collection logic
|
|
51
51
|
*/
|
|
52
|
-
_idbbase:
|
|
52
|
+
_idbbase: MachineDb;
|
|
53
53
|
/**
|
|
54
54
|
* Database name
|
|
55
55
|
*/
|
|
@@ -80,7 +80,7 @@ export declare class Machine {
|
|
|
80
80
|
/**
|
|
81
81
|
* Get the IDbBase (schema logic) instance
|
|
82
82
|
*/
|
|
83
|
-
get collections():
|
|
83
|
+
get collections(): MachineDb;
|
|
84
84
|
/**
|
|
85
85
|
* IDBQL (readonly) instance
|
|
86
86
|
*/
|
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 { MachineDb } 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.
|
|
@@ -86,7 +86,7 @@ export class Machine {
|
|
|
86
86
|
if (!this._model) {
|
|
87
87
|
throw new Error('Data model is not defined');
|
|
88
88
|
}
|
|
89
|
-
this._idbbase = new
|
|
89
|
+
this._idbbase = new MachineDb(this._model);
|
|
90
90
|
}
|
|
91
91
|
createStore() {
|
|
92
92
|
if (!this._model || !this._dbName || !this._version) {
|
package/dist/main/machineDb.d.ts
CHANGED
|
@@ -36,29 +36,15 @@ export type IDbForge = {
|
|
|
36
36
|
fieldType?: IDbFieldType;
|
|
37
37
|
fieldRule?: IDbFieldRules;
|
|
38
38
|
fieldArgs?: IDbForgeArgs | undefined;
|
|
39
|
-
is:
|
|
39
|
+
is: unknown;
|
|
40
40
|
};
|
|
41
41
|
/**
|
|
42
42
|
* Central class for parsing, introspecting, and extracting metadata from the database schema.
|
|
43
43
|
* Provides methods to access collections, templates, fields, foreign keys, and type information.
|
|
44
44
|
* Used for dynamic UI generation, validation, and schema-driven logic.
|
|
45
45
|
*/
|
|
46
|
-
export declare class
|
|
46
|
+
export declare class MachineDb {
|
|
47
47
|
#private;
|
|
48
|
-
/**
|
|
49
|
-
* Public: Get the foreign keys (fks) object for a collection.
|
|
50
|
-
*/
|
|
51
|
-
getCollectionTemplateFks(collection: TplCollectionName): {
|
|
52
|
-
[x: string]: {
|
|
53
|
-
code: string;
|
|
54
|
-
multiple: boolean;
|
|
55
|
-
rules: import("@medyll/idae-idbql").CombinedArgs;
|
|
56
|
-
} | undefined;
|
|
57
|
-
};
|
|
58
|
-
/**
|
|
59
|
-
* Public: Get the value of the index field for a given data object.
|
|
60
|
-
*/
|
|
61
|
-
indexValue(collection: TplCollectionName, data: object): unknown;
|
|
62
48
|
/**
|
|
63
49
|
* The database model (schema) used for introspection.
|
|
64
50
|
*/
|
|
@@ -71,7 +57,11 @@ export declare class IDbBase {
|
|
|
71
57
|
/**
|
|
72
58
|
* Get an IDbCollection instance for a collection name.
|
|
73
59
|
*/
|
|
74
|
-
|
|
60
|
+
collection(collection: TplCollectionName): IDbCollection;
|
|
61
|
+
/**
|
|
62
|
+
* Public: Get the value of the index field for a given data object.
|
|
63
|
+
*/
|
|
64
|
+
indexValue(collection: TplCollectionName, data: object): unknown;
|
|
75
65
|
/**
|
|
76
66
|
* Get an IDbCollectionValues instance for a collection name.
|
|
77
67
|
*/
|
|
@@ -80,18 +70,10 @@ export declare class IDbBase {
|
|
|
80
70
|
* Get an IDbCollectionFieldValues instance for a collection and data.
|
|
81
71
|
*/
|
|
82
72
|
collectionFieldValues<T extends Record<string, any>>(collection: TplCollectionName, data: T): IDbCollectionFieldValues<T>;
|
|
83
|
-
/**
|
|
84
|
-
* Get an IDbCollectionFieldForge instance for a collection, field, and data.
|
|
85
|
-
*/
|
|
86
|
-
collectionFieldForge<T extends Record<string, any>>(collection: TplCollectionName, fieldName: keyof T | string, data: T): IDbCollectionFieldForge<T>;
|
|
87
73
|
/**
|
|
88
74
|
* Get an IDbFormValidate instance for a collection name.
|
|
89
75
|
*/
|
|
90
76
|
formValidate(collection: TplCollectionName): IDbFormValidate;
|
|
91
|
-
/**
|
|
92
|
-
* Parse all collections in the model and return their fields as IDbForge objects.
|
|
93
|
-
*/
|
|
94
|
-
parseAllCollections(): Record<string, Record<string, IDbForge | undefined> | undefined>;
|
|
95
77
|
/**
|
|
96
78
|
* Parse all fields of a given collection.
|
|
97
79
|
*/
|
|
@@ -100,17 +82,6 @@ export declare class IDbBase {
|
|
|
100
82
|
* Parse a single field of a collection and return its IDbForge metadata.
|
|
101
83
|
*/
|
|
102
84
|
parseCollectionFieldName(collection: TplCollectionName, fieldName: keyof TplFields): IDbForge | undefined;
|
|
103
|
-
/**
|
|
104
|
-
* Internal helper to construct an IDbForge object from its components.
|
|
105
|
-
*/
|
|
106
|
-
private forge;
|
|
107
|
-
getCollection(collection: TplCollectionName): CollectionModel;
|
|
108
|
-
getCollectionModel(collection: TplCollectionName): CollectionModel;
|
|
109
|
-
getCollectionModelTemplate(collection: TplCollectionName): Tpl;
|
|
110
|
-
getCollectionModelTemplateFks(collection: TplCollectionName): Tpl["fks"];
|
|
111
|
-
getIndexName(collection: TplCollectionName): string;
|
|
112
|
-
getCollectionTemplateFields(collection: TplCollectionName): TplFields;
|
|
113
|
-
getTemplatePresentation(collection: TplCollectionName): string;
|
|
114
85
|
getFkFieldType(string: `${string}.${string}`): IDbFieldRules | undefined;
|
|
115
86
|
getFkTemplateFields(string: `${string}.${string}`): {
|
|
116
87
|
[x: string]: import("@medyll/idae-idbql").TplFieldRules;
|
|
@@ -124,21 +95,23 @@ export declare class IDbBase {
|
|
|
124
95
|
reverseFks(targetCollection: TplCollectionName): Record<string, any>;
|
|
125
96
|
iterateArrayField(collection: TplCollectionName, fieldName: keyof TplFields, data: any[]): IDbForge[];
|
|
126
97
|
iterateObjectField(collection: TplCollectionName, fieldName: keyof TplFields, data: Record<string, any>): IDbForge[];
|
|
98
|
+
/**
|
|
99
|
+
* Internal helper to construct an IDbForge object from its components.
|
|
100
|
+
*/
|
|
101
|
+
private forge;
|
|
127
102
|
}
|
|
128
103
|
export declare class IDbCollection {
|
|
104
|
+
#private;
|
|
129
105
|
collection: TplCollectionName;
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
rules: import("@medyll/idae-idbql").CombinedArgs;
|
|
138
|
-
} | undefined;
|
|
139
|
-
};
|
|
106
|
+
constructor(collection: TplCollectionName, idbBase: MachineDb, model: IdbqModel);
|
|
107
|
+
get model(): CollectionModel<Record<string, any>>;
|
|
108
|
+
get fields(): TplFields;
|
|
109
|
+
getPresentation(): string;
|
|
110
|
+
getFieldRule(fieldName: keyof TplFields): IDbFieldRules | undefined;
|
|
111
|
+
getTemplate(): Tpl;
|
|
112
|
+
getModelTemplateFks(): Tpl["fks"];
|
|
140
113
|
getIndexName(): string;
|
|
141
|
-
collectionValues(): IDbCollectionValues<any
|
|
114
|
+
collectionValues(): IDbCollectionValues<Record<string, any>>;
|
|
142
115
|
collectionFieldValues<T extends Record<string, any>>(data: T): IDbCollectionFieldValues<T>;
|
|
143
116
|
fieldForge<T extends Record<string, any>>(fieldName: keyof T, data: T): IDbCollectionFieldForge<T>;
|
|
144
117
|
getFormValidate(): IDbFormValidate;
|
|
@@ -176,7 +149,7 @@ export declare class IDbCollectionValues<T extends Record<string, any>> {
|
|
|
176
149
|
/**
|
|
177
150
|
* The IDbBase instance used for schema introspection.
|
|
178
151
|
*/
|
|
179
|
-
idbBase:
|
|
152
|
+
idbBase: MachineDb;
|
|
180
153
|
/**
|
|
181
154
|
* The collection name this instance operates on.
|
|
182
155
|
*/
|
|
@@ -185,7 +158,7 @@ export declare class IDbCollectionValues<T extends Record<string, any>> {
|
|
|
185
158
|
* Create a new IDbCollectionValues instance for a given collection.
|
|
186
159
|
* @param collectionName The collection name.
|
|
187
160
|
*/
|
|
188
|
-
constructor(collectionName: TplCollectionName, idbBase?:
|
|
161
|
+
constructor(collectionName: TplCollectionName, idbBase?: MachineDb);
|
|
189
162
|
presentation(data: Record<string, any>): string;
|
|
190
163
|
/**
|
|
191
164
|
* Get the value of the index field for a data object.
|
|
@@ -277,7 +250,7 @@ export declare class IDbFormValidate {
|
|
|
277
250
|
#private;
|
|
278
251
|
private collection;
|
|
279
252
|
private idbCollections;
|
|
280
|
-
constructor(collection: TplCollectionName, idbCollections?:
|
|
253
|
+
constructor(collection: TplCollectionName, idbCollections?: MachineDb);
|
|
281
254
|
validateField(fieldName: keyof TplFields, value: any): {
|
|
282
255
|
isValid: boolean;
|
|
283
256
|
error?: string;
|
package/dist/main/machineDb.js
CHANGED
|
@@ -51,25 +51,12 @@ class IDbError extends Error {
|
|
|
51
51
|
* Provides methods to access collections, templates, fields, foreign keys, and type information.
|
|
52
52
|
* Used for dynamic UI generation, validation, and schema-driven logic.
|
|
53
53
|
*/
|
|
54
|
-
export class
|
|
55
|
-
/**
|
|
56
|
-
* Public: Get the foreign keys (fks) object for a collection.
|
|
57
|
-
*/
|
|
58
|
-
getCollectionTemplateFks(collection) {
|
|
59
|
-
return this.getCollectionModelTemplateFks(collection);
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Public: Get the value of the index field for a given data object.
|
|
63
|
-
*/
|
|
64
|
-
indexValue(collection, data) {
|
|
65
|
-
const indexName = this.getIndexName(collection);
|
|
66
|
-
// @ts-ignore
|
|
67
|
-
return data && typeof data === 'object' && indexName && data[indexName];
|
|
68
|
-
}
|
|
54
|
+
export class MachineDb {
|
|
69
55
|
/**
|
|
70
56
|
* The database model (schema) used for introspection.
|
|
71
57
|
*/
|
|
72
58
|
model = schemeModel;
|
|
59
|
+
#idbCollectionsList = {};
|
|
73
60
|
/**
|
|
74
61
|
* Create a new IDbBase instance.
|
|
75
62
|
* @param model Optional custom model to use (default: schemeModel)
|
|
@@ -80,8 +67,18 @@ export class IDbBase {
|
|
|
80
67
|
/**
|
|
81
68
|
* Get an IDbCollection instance for a collection name.
|
|
82
69
|
*/
|
|
83
|
-
|
|
84
|
-
|
|
70
|
+
collection(collection) {
|
|
71
|
+
if (!this.#idbCollectionsList[collection]) {
|
|
72
|
+
this.#idbCollectionsList[collection] = new IDbCollection(collection, this, this.model);
|
|
73
|
+
}
|
|
74
|
+
return this.#idbCollectionsList[collection];
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Public: Get the value of the index field for a given data object.
|
|
78
|
+
*/
|
|
79
|
+
indexValue(collection, data) {
|
|
80
|
+
const indexName = this.collection(collection).getIndexName();
|
|
81
|
+
return data && typeof data === 'object' && indexName && data[indexName];
|
|
85
82
|
}
|
|
86
83
|
/**
|
|
87
84
|
* Get an IDbCollectionValues instance for a collection name.
|
|
@@ -95,33 +92,17 @@ export class IDbBase {
|
|
|
95
92
|
collectionFieldValues(collection, data) {
|
|
96
93
|
return new IDbCollectionFieldValues(collection, data, this.collectionValues(collection));
|
|
97
94
|
}
|
|
98
|
-
/**
|
|
99
|
-
* Get an IDbCollectionFieldForge instance for a collection, field, and data.
|
|
100
|
-
*/
|
|
101
|
-
collectionFieldForge(collection, fieldName, data) {
|
|
102
|
-
return new IDbCollectionFieldForge(collection, fieldName, data, this.collectionValues(collection));
|
|
103
|
-
}
|
|
104
95
|
/**
|
|
105
96
|
* Get an IDbFormValidate instance for a collection name.
|
|
106
97
|
*/
|
|
107
98
|
formValidate(collection) {
|
|
108
99
|
return new IDbFormValidate(collection, this);
|
|
109
100
|
}
|
|
110
|
-
/**
|
|
111
|
-
* Parse all collections in the model and return their fields as IDbForge objects.
|
|
112
|
-
*/
|
|
113
|
-
parseAllCollections() {
|
|
114
|
-
let out = {};
|
|
115
|
-
Object.keys(this.model).forEach((collection) => {
|
|
116
|
-
out[collection] = this.parseRawCollection(collection);
|
|
117
|
-
});
|
|
118
|
-
return out;
|
|
119
|
-
}
|
|
120
101
|
/**
|
|
121
102
|
* Parse all fields of a given collection.
|
|
122
103
|
*/
|
|
123
104
|
parseRawCollection(collection) {
|
|
124
|
-
const fields = this.
|
|
105
|
+
const fields = new IDbCollection(collection, this, this.model).fields;
|
|
125
106
|
if (!fields)
|
|
126
107
|
return;
|
|
127
108
|
const out = {};
|
|
@@ -149,38 +130,10 @@ export class IDbBase {
|
|
|
149
130
|
const fieldType = array ?? object ?? fk ?? primitive;
|
|
150
131
|
return this.forge({ collection, fieldName, ...fieldType });
|
|
151
132
|
}
|
|
152
|
-
|
|
153
|
-
* Internal helper to construct an IDbForge object from its components.
|
|
154
|
-
*/
|
|
155
|
-
forge({ collection, fieldName, fieldType, fieldRule, fieldArgs, is }) {
|
|
156
|
-
return { collection, fieldName, fieldType, fieldRule, fieldArgs, is };
|
|
157
|
-
}
|
|
158
|
-
#getModel() {
|
|
159
|
-
return this.model;
|
|
160
|
-
}
|
|
161
|
-
getCollection(collection) {
|
|
162
|
-
return this.#getModel()[String(collection)];
|
|
163
|
-
}
|
|
164
|
-
getCollectionModel(collection) {
|
|
165
|
-
return this.#getModel()[String(collection)];
|
|
166
|
-
}
|
|
167
|
-
getCollectionModelTemplate(collection) {
|
|
168
|
-
return this.getCollectionModel(collection)['template'];
|
|
169
|
-
}
|
|
170
|
-
getCollectionModelTemplateFks(collection) {
|
|
171
|
-
return this.getCollectionModel(collection)['template']?.fks;
|
|
172
|
-
}
|
|
173
|
-
getIndexName(collection) {
|
|
174
|
-
return this.getCollectionModel(collection)?.template?.index;
|
|
175
|
-
}
|
|
176
|
-
getCollectionTemplateFields(collection) {
|
|
177
|
-
return this.getCollectionModelTemplate(collection)?.fields;
|
|
178
|
-
}
|
|
179
|
-
getTemplatePresentation(collection) {
|
|
180
|
-
return this.getCollectionModelTemplate(collection)?.presentation;
|
|
181
|
-
}
|
|
133
|
+
// Toutes ces méthodes sont maintenant dans IDbCollection
|
|
182
134
|
#getTemplateFieldRule(collection, fieldName) {
|
|
183
|
-
|
|
135
|
+
// Utilise la nouvelle API orientée collection
|
|
136
|
+
return new IDbCollection(collection, this, this.model).getFieldRule(fieldName);
|
|
184
137
|
}
|
|
185
138
|
getFkFieldType(string) {
|
|
186
139
|
const [collection, field] = string.split('.');
|
|
@@ -189,7 +142,7 @@ export class IDbBase {
|
|
|
189
142
|
}
|
|
190
143
|
getFkTemplateFields(string) {
|
|
191
144
|
const [collection, field] = string.split('.');
|
|
192
|
-
return this.
|
|
145
|
+
return this.collection(collection).getTemplate()?.fields;
|
|
193
146
|
}
|
|
194
147
|
testIs(what, fieldRule) {
|
|
195
148
|
const typeMappings = { fk: 'fk-', array: 'array-of-', object: 'object-', primitive: '' };
|
|
@@ -246,7 +199,7 @@ export class IDbBase {
|
|
|
246
199
|
return { fieldType, fieldRule, fieldArgs, is: type };
|
|
247
200
|
}
|
|
248
201
|
fks(collection) {
|
|
249
|
-
let fks = this.
|
|
202
|
+
let fks = this.collection(collection).getModelTemplateFks();
|
|
250
203
|
let out = {};
|
|
251
204
|
if (fks) {
|
|
252
205
|
Object.keys(fks).forEach((collection) => {
|
|
@@ -257,7 +210,7 @@ export class IDbBase {
|
|
|
257
210
|
}
|
|
258
211
|
reverseFks(targetCollection) {
|
|
259
212
|
const result = {};
|
|
260
|
-
Object.entries(this
|
|
213
|
+
Object.entries(this.model).forEach(([collectionName, collectionModel]) => {
|
|
261
214
|
const template = collectionModel.template;
|
|
262
215
|
if (template && template.fks) {
|
|
263
216
|
Object.entries(template.fks).forEach(([fkName, fkConfig]) => {
|
|
@@ -286,41 +239,63 @@ export class IDbBase {
|
|
|
286
239
|
}
|
|
287
240
|
return Object.keys(data).map((key) => ({ ...fieldInfo, fieldName: `${String(fieldName)}.${key}` }));
|
|
288
241
|
}
|
|
242
|
+
/**
|
|
243
|
+
* Internal helper to construct an IDbForge object from its components.
|
|
244
|
+
*/
|
|
245
|
+
forge({ collection, fieldName, fieldType, fieldRule, fieldArgs, is }) {
|
|
246
|
+
return { collection, fieldName, fieldType, fieldRule, fieldArgs, is };
|
|
247
|
+
}
|
|
289
248
|
}
|
|
290
|
-
/* Single collection relies on IDbBase */
|
|
249
|
+
/* Single collection template relies on IDbBase */
|
|
291
250
|
export class IDbCollection {
|
|
292
251
|
collection;
|
|
293
|
-
|
|
294
|
-
|
|
252
|
+
#template;
|
|
253
|
+
#machineDb;
|
|
254
|
+
#model;
|
|
255
|
+
constructor(collection, idbBase, model) {
|
|
295
256
|
this.collection = collection;
|
|
296
|
-
this
|
|
257
|
+
this.#machineDb = idbBase;
|
|
258
|
+
this.#model = model[String(collection)];
|
|
259
|
+
this.#template = this.#model['template'];
|
|
260
|
+
}
|
|
261
|
+
get model() {
|
|
262
|
+
return this.#model;
|
|
263
|
+
}
|
|
264
|
+
get fields() {
|
|
265
|
+
return this.#template?.fields;
|
|
266
|
+
}
|
|
267
|
+
getPresentation() {
|
|
268
|
+
return this.#template?.presentation;
|
|
269
|
+
}
|
|
270
|
+
getFieldRule(fieldName) {
|
|
271
|
+
return this.fields[String(fieldName)];
|
|
297
272
|
}
|
|
298
|
-
|
|
299
|
-
return this
|
|
273
|
+
getTemplate() {
|
|
274
|
+
return this.#template;
|
|
300
275
|
}
|
|
301
|
-
|
|
302
|
-
return this
|
|
276
|
+
getModelTemplateFks() {
|
|
277
|
+
return this.#template?.fks;
|
|
303
278
|
}
|
|
304
279
|
getIndexName() {
|
|
305
|
-
return this
|
|
280
|
+
return this.#template?.index;
|
|
306
281
|
}
|
|
307
282
|
collectionValues() {
|
|
308
|
-
return
|
|
283
|
+
return new IDbCollectionValues(this.collection, this.#machineDb);
|
|
309
284
|
}
|
|
310
285
|
collectionFieldValues(data) {
|
|
311
|
-
return
|
|
286
|
+
return new IDbCollectionFieldValues(this.collection, data, this.collectionValues());
|
|
312
287
|
}
|
|
313
288
|
fieldForge(fieldName, data) {
|
|
314
|
-
return
|
|
289
|
+
return new IDbCollectionFieldForge(this.collection, fieldName, data, this.collectionValues());
|
|
315
290
|
}
|
|
316
291
|
getFormValidate() {
|
|
317
|
-
return
|
|
292
|
+
return new IDbFormValidate(this.collection, this.#machineDb);
|
|
318
293
|
}
|
|
319
294
|
fks() {
|
|
320
|
-
return this.
|
|
295
|
+
return this.#machineDb.fks(this.collection);
|
|
321
296
|
}
|
|
322
297
|
reverseFks() {
|
|
323
|
-
return this.
|
|
298
|
+
return this.#machineDb.reverseFks(this.collection);
|
|
324
299
|
}
|
|
325
300
|
}
|
|
326
301
|
/**
|
|
@@ -362,12 +337,12 @@ export class IDbCollectionValues {
|
|
|
362
337
|
*/
|
|
363
338
|
constructor(collectionName, idbBase) {
|
|
364
339
|
this.collectionName = collectionName;
|
|
365
|
-
this.idbBase = idbBase ?? new
|
|
340
|
+
this.idbBase = idbBase ?? new MachineDb();
|
|
366
341
|
}
|
|
367
342
|
presentation(data) {
|
|
368
343
|
try {
|
|
369
344
|
this.#checkError(!this.#checkAccess(), 'Access denied', 'ACCESS_DENIED');
|
|
370
|
-
const presentation = this.idbBase.
|
|
345
|
+
const presentation = this.idbBase.collection(this.collectionName).getPresentation();
|
|
371
346
|
this.#checkError(!presentation, 'Presentation template not found', 'TEMPLATE_NOT_FOUND');
|
|
372
347
|
const fields = presentation.split(' ');
|
|
373
348
|
return fields
|
|
@@ -390,7 +365,7 @@ export class IDbCollectionValues {
|
|
|
390
365
|
indexValue(data) {
|
|
391
366
|
try {
|
|
392
367
|
this.#checkError(!this.#checkAccess(), 'Access denied', 'ACCESS_DENIED');
|
|
393
|
-
const indexName = this.idbBase.
|
|
368
|
+
const indexName = this.idbBase.collection(this.collectionName).getIndexName();
|
|
394
369
|
this.#checkError(!indexName, 'Index not found for collection', 'INDEX_NOT_FOUND');
|
|
395
370
|
this.#checkError(!(indexName in data), `Index field ${indexName} not found in data`, 'FIELD_NOT_FOUND');
|
|
396
371
|
return data[indexName];
|
|
@@ -441,7 +416,7 @@ export class IDbCollectionValues {
|
|
|
441
416
|
const fieldInfo = this.idbBase.parseCollectionFieldName(this.collectionName, fieldName);
|
|
442
417
|
const fieldType = fieldInfo?.fieldType ?? '';
|
|
443
418
|
const fieldArgs = fieldInfo?.fieldArgs?.join(' ') ?? '';
|
|
444
|
-
const indexName = this.idbBase.
|
|
419
|
+
const indexName = this.idbBase.collection(this.collectionName).getIndexName();
|
|
445
420
|
return {
|
|
446
421
|
'data-collection': this.collectionName,
|
|
447
422
|
'data-collectionId': indexName && data?.[indexName] !== undefined ? String(data?.[indexName]) : '',
|
|
@@ -643,7 +618,7 @@ export class IDbFormValidate {
|
|
|
643
618
|
idbCollections;
|
|
644
619
|
constructor(collection, idbCollections) {
|
|
645
620
|
this.collection = collection;
|
|
646
|
-
this.idbCollections = idbCollections ?? new
|
|
621
|
+
this.idbCollections = idbCollections ?? new MachineDb();
|
|
647
622
|
}
|
|
648
623
|
validateField(fieldName, value) {
|
|
649
624
|
try {
|
|
@@ -712,7 +687,7 @@ export class IDbFormValidate {
|
|
|
712
687
|
const errors = {};
|
|
713
688
|
const invalidFields = [];
|
|
714
689
|
let isValid = true;
|
|
715
|
-
const fields = this.idbCollections.
|
|
690
|
+
const fields = this.idbCollections.collection(this.collection).getTemplate().fields;
|
|
716
691
|
if (!fields) {
|
|
717
692
|
return {
|
|
718
693
|
isValid: false,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@medyll/idae-machine",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.123.0",
|
|
4
4
|
"files": [
|
|
5
5
|
"dist",
|
|
6
6
|
"!dist/**/*.test.*",
|
|
@@ -49,8 +49,8 @@
|
|
|
49
49
|
"scope": "@medyll",
|
|
50
50
|
"dependencies": {
|
|
51
51
|
"@huggingface/prettier-plugin-vertical-align": "^0.2.3",
|
|
52
|
-
"@medyll/idae-slotui-svelte": "0.
|
|
53
|
-
"@medyll/idae-idbql": "0.
|
|
52
|
+
"@medyll/idae-slotui-svelte": "0.176.0",
|
|
53
|
+
"@medyll/idae-idbql": "0.173.0"
|
|
54
54
|
},
|
|
55
55
|
"scripts": {
|
|
56
56
|
"dev": "vite dev",
|