@medyll/idae-machine 0.122.0 → 0.124.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/CollectionListMenu.svelte +3 -3
- package/dist/form/CollectionReverseFks.svelte +2 -2
- package/dist/main/machine.d.ts +3 -3
- package/dist/main/machine.js +2 -2
- package/dist/main/machineDb.d.ts +11 -16
- package/dist/main/machineDb.js +37 -38
- 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
|
|
|
@@ -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() {
|
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,14 +36,14 @@ 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
48
|
/**
|
|
49
49
|
* The database model (schema) used for introspection.
|
|
@@ -70,10 +70,6 @@ export declare class IDbBase {
|
|
|
70
70
|
* Get an IDbCollectionFieldValues instance for a collection and data.
|
|
71
71
|
*/
|
|
72
72
|
collectionFieldValues<T extends Record<string, any>>(collection: TplCollectionName, data: T): IDbCollectionFieldValues<T>;
|
|
73
|
-
/**
|
|
74
|
-
* Get an IDbCollectionFieldForge instance for a collection, field, and data.
|
|
75
|
-
*/
|
|
76
|
-
collectionFieldForge<T extends Record<string, any>>(collection: TplCollectionName, fieldName: keyof T | string, data: T): IDbCollectionFieldForge<T>;
|
|
77
73
|
/**
|
|
78
74
|
* Get an IDbFormValidate instance for a collection name.
|
|
79
75
|
*/
|
|
@@ -105,18 +101,17 @@ export declare class IDbBase {
|
|
|
105
101
|
private forge;
|
|
106
102
|
}
|
|
107
103
|
export declare class IDbCollection {
|
|
104
|
+
#private;
|
|
108
105
|
collection: TplCollectionName;
|
|
109
|
-
|
|
110
|
-
model:
|
|
111
|
-
|
|
112
|
-
getModel(): CollectionModel<Record<string, any>>;
|
|
113
|
-
getFields(): TplFields;
|
|
106
|
+
constructor(collectionName: TplCollectionName, idbBase: MachineDb, model: IdbqModel);
|
|
107
|
+
get model(): CollectionModel<Record<string, any>>;
|
|
108
|
+
get fields(): TplFields;
|
|
114
109
|
getPresentation(): string;
|
|
115
110
|
getFieldRule(fieldName: keyof TplFields): IDbFieldRules | undefined;
|
|
116
|
-
|
|
111
|
+
getTemplate(): Tpl;
|
|
117
112
|
getModelTemplateFks(): Tpl["fks"];
|
|
118
113
|
getIndexName(): string;
|
|
119
|
-
collectionValues(): IDbCollectionValues<any
|
|
114
|
+
collectionValues(): IDbCollectionValues<Record<string, any>>;
|
|
120
115
|
collectionFieldValues<T extends Record<string, any>>(data: T): IDbCollectionFieldValues<T>;
|
|
121
116
|
fieldForge<T extends Record<string, any>>(fieldName: keyof T, data: T): IDbCollectionFieldForge<T>;
|
|
122
117
|
getFormValidate(): IDbFormValidate;
|
|
@@ -154,7 +149,7 @@ export declare class IDbCollectionValues<T extends Record<string, any>> {
|
|
|
154
149
|
/**
|
|
155
150
|
* The IDbBase instance used for schema introspection.
|
|
156
151
|
*/
|
|
157
|
-
idbBase:
|
|
152
|
+
idbBase: MachineDb;
|
|
158
153
|
/**
|
|
159
154
|
* The collection name this instance operates on.
|
|
160
155
|
*/
|
|
@@ -163,7 +158,7 @@ export declare class IDbCollectionValues<T extends Record<string, any>> {
|
|
|
163
158
|
* Create a new IDbCollectionValues instance for a given collection.
|
|
164
159
|
* @param collectionName The collection name.
|
|
165
160
|
*/
|
|
166
|
-
constructor(collectionName: TplCollectionName, idbBase?:
|
|
161
|
+
constructor(collectionName: TplCollectionName, idbBase?: MachineDb);
|
|
167
162
|
presentation(data: Record<string, any>): string;
|
|
168
163
|
/**
|
|
169
164
|
* Get the value of the index field for a data object.
|
|
@@ -255,7 +250,7 @@ export declare class IDbFormValidate {
|
|
|
255
250
|
#private;
|
|
256
251
|
private collection;
|
|
257
252
|
private idbCollections;
|
|
258
|
-
constructor(collection: TplCollectionName, idbCollections?:
|
|
253
|
+
constructor(collection: TplCollectionName, idbCollections?: MachineDb);
|
|
259
254
|
validateField(fieldName: keyof TplFields, value: any): {
|
|
260
255
|
isValid: boolean;
|
|
261
256
|
error?: string;
|
package/dist/main/machineDb.js
CHANGED
|
@@ -51,11 +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
|
|
54
|
+
export class MachineDb {
|
|
55
55
|
/**
|
|
56
56
|
* The database model (schema) used for introspection.
|
|
57
57
|
*/
|
|
58
58
|
model = schemeModel;
|
|
59
|
+
#idbCollectionsList = {};
|
|
59
60
|
/**
|
|
60
61
|
* Create a new IDbBase instance.
|
|
61
62
|
* @param model Optional custom model to use (default: schemeModel)
|
|
@@ -67,13 +68,16 @@ export class IDbBase {
|
|
|
67
68
|
* Get an IDbCollection instance for a collection name.
|
|
68
69
|
*/
|
|
69
70
|
collection(collection) {
|
|
70
|
-
|
|
71
|
+
if (!this.#idbCollectionsList[collection]) {
|
|
72
|
+
this.#idbCollectionsList[collection] = new IDbCollection(collection, this, this.model);
|
|
73
|
+
}
|
|
74
|
+
return this.#idbCollectionsList[collection];
|
|
71
75
|
}
|
|
72
76
|
/**
|
|
73
77
|
* Public: Get the value of the index field for a given data object.
|
|
74
78
|
*/
|
|
75
79
|
indexValue(collection, data) {
|
|
76
|
-
const indexName =
|
|
80
|
+
const indexName = this.collection(collection).getIndexName();
|
|
77
81
|
return data && typeof data === 'object' && indexName && data[indexName];
|
|
78
82
|
}
|
|
79
83
|
/**
|
|
@@ -88,12 +92,6 @@ export class IDbBase {
|
|
|
88
92
|
collectionFieldValues(collection, data) {
|
|
89
93
|
return new IDbCollectionFieldValues(collection, data, this.collectionValues(collection));
|
|
90
94
|
}
|
|
91
|
-
/**
|
|
92
|
-
* Get an IDbCollectionFieldForge instance for a collection, field, and data.
|
|
93
|
-
*/
|
|
94
|
-
collectionFieldForge(collection, fieldName, data) {
|
|
95
|
-
return new IDbCollectionFieldForge(collection, fieldName, data, this.collectionValues(collection));
|
|
96
|
-
}
|
|
97
95
|
/**
|
|
98
96
|
* Get an IDbFormValidate instance for a collection name.
|
|
99
97
|
*/
|
|
@@ -104,7 +102,7 @@ export class IDbBase {
|
|
|
104
102
|
* Parse all fields of a given collection.
|
|
105
103
|
*/
|
|
106
104
|
parseRawCollection(collection) {
|
|
107
|
-
const fields = new IDbCollection(collection, this, this.model).
|
|
105
|
+
const fields = new IDbCollection(collection, this, this.model).fields;
|
|
108
106
|
if (!fields)
|
|
109
107
|
return;
|
|
110
108
|
const out = {};
|
|
@@ -144,7 +142,7 @@ export class IDbBase {
|
|
|
144
142
|
}
|
|
145
143
|
getFkTemplateFields(string) {
|
|
146
144
|
const [collection, field] = string.split('.');
|
|
147
|
-
return this.collection(collection).
|
|
145
|
+
return this.collection(collection).getTemplate()?.fields;
|
|
148
146
|
}
|
|
149
147
|
testIs(what, fieldRule) {
|
|
150
148
|
const typeMappings = { fk: 'fk-', array: 'array-of-', object: 'object-', primitive: '' };
|
|
@@ -248,55 +246,56 @@ export class IDbBase {
|
|
|
248
246
|
return { collection, fieldName, fieldType, fieldRule, fieldArgs, is };
|
|
249
247
|
}
|
|
250
248
|
}
|
|
251
|
-
/* Single collection relies on IDbBase */
|
|
249
|
+
/* Single collection template relies on IDbBase */
|
|
252
250
|
export class IDbCollection {
|
|
253
|
-
// --- NOUVELLES MÉTHODES MIGRÉES DE IDbBase ---
|
|
254
251
|
collection;
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
this.
|
|
260
|
-
this
|
|
252
|
+
#template;
|
|
253
|
+
#machineDb;
|
|
254
|
+
#model;
|
|
255
|
+
constructor(collectionName, idbBase, model) {
|
|
256
|
+
this.collection = collectionName;
|
|
257
|
+
this.#machineDb = idbBase;
|
|
258
|
+
this.#model = model[String(collectionName)];
|
|
259
|
+
this.#template = this.#model['template'];
|
|
261
260
|
}
|
|
262
|
-
|
|
263
|
-
return this
|
|
261
|
+
get model() {
|
|
262
|
+
return this.#model;
|
|
264
263
|
}
|
|
265
|
-
|
|
266
|
-
return this
|
|
264
|
+
get fields() {
|
|
265
|
+
return this.#template?.fields;
|
|
267
266
|
}
|
|
268
267
|
getPresentation() {
|
|
269
|
-
return this
|
|
268
|
+
return this.#template?.presentation;
|
|
270
269
|
}
|
|
271
270
|
getFieldRule(fieldName) {
|
|
272
|
-
return this.
|
|
271
|
+
return this.fields[String(fieldName)];
|
|
273
272
|
}
|
|
274
|
-
|
|
275
|
-
return this
|
|
273
|
+
getTemplate() {
|
|
274
|
+
return this.#template;
|
|
276
275
|
}
|
|
277
276
|
getModelTemplateFks() {
|
|
278
|
-
return this
|
|
277
|
+
return this.#template?.fks;
|
|
279
278
|
}
|
|
280
279
|
getIndexName() {
|
|
281
|
-
return this
|
|
280
|
+
return this.#template?.index;
|
|
282
281
|
}
|
|
283
282
|
collectionValues() {
|
|
284
|
-
return
|
|
283
|
+
return new IDbCollectionValues(this.collection, this.#machineDb);
|
|
285
284
|
}
|
|
286
285
|
collectionFieldValues(data) {
|
|
287
|
-
return
|
|
286
|
+
return new IDbCollectionFieldValues(this.collection, data, this.collectionValues());
|
|
288
287
|
}
|
|
289
288
|
fieldForge(fieldName, data) {
|
|
290
|
-
return
|
|
289
|
+
return new IDbCollectionFieldForge(this.collection, fieldName, data, this.collectionValues());
|
|
291
290
|
}
|
|
292
291
|
getFormValidate() {
|
|
293
|
-
return
|
|
292
|
+
return new IDbFormValidate(this.collection, this.#machineDb);
|
|
294
293
|
}
|
|
295
294
|
fks() {
|
|
296
|
-
return this.
|
|
295
|
+
return this.#machineDb.fks(this.collection);
|
|
297
296
|
}
|
|
298
297
|
reverseFks() {
|
|
299
|
-
return this.
|
|
298
|
+
return this.#machineDb.reverseFks(this.collection);
|
|
300
299
|
}
|
|
301
300
|
}
|
|
302
301
|
/**
|
|
@@ -338,7 +337,7 @@ export class IDbCollectionValues {
|
|
|
338
337
|
*/
|
|
339
338
|
constructor(collectionName, idbBase) {
|
|
340
339
|
this.collectionName = collectionName;
|
|
341
|
-
this.idbBase = idbBase ?? new
|
|
340
|
+
this.idbBase = idbBase ?? new MachineDb();
|
|
342
341
|
}
|
|
343
342
|
presentation(data) {
|
|
344
343
|
try {
|
|
@@ -619,7 +618,7 @@ export class IDbFormValidate {
|
|
|
619
618
|
idbCollections;
|
|
620
619
|
constructor(collection, idbCollections) {
|
|
621
620
|
this.collection = collection;
|
|
622
|
-
this.idbCollections = idbCollections ?? new
|
|
621
|
+
this.idbCollections = idbCollections ?? new MachineDb();
|
|
623
622
|
}
|
|
624
623
|
validateField(fieldName, value) {
|
|
625
624
|
try {
|
|
@@ -688,7 +687,7 @@ export class IDbFormValidate {
|
|
|
688
687
|
const errors = {};
|
|
689
688
|
const invalidFields = [];
|
|
690
689
|
let isValid = true;
|
|
691
|
-
const fields = this.idbCollections.collection(this.collection).
|
|
690
|
+
const fields = this.idbCollections.collection(this.collection).getTemplate().fields;
|
|
692
691
|
if (!fields) {
|
|
693
692
|
return {
|
|
694
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.124.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.177.0",
|
|
53
|
+
"@medyll/idae-idbql": "0.174.0"
|
|
54
54
|
},
|
|
55
55
|
"scripts": {
|
|
56
56
|
"dev": "vite dev",
|