@medyll/idae-machine 0.129.0 → 0.135.2
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 +21 -21
- package/README.md +360 -393
- package/cli.js +46 -0
- package/dist/demo/dbSchema.d.ts +446 -0
- package/dist/demo/dbSchema.js +449 -0
- package/dist/demo/testScheme.d.ts +56 -0
- package/dist/demo/testScheme.js +42 -0
- package/dist/form/CreateUpdate.svelte +219 -0
- package/dist/{demo/form → form}/CreateUpdate.svelte.d.ts +5 -7
- package/dist/form/DataProvider.svelte +23 -0
- package/dist/form/DataProvider.svelte.d.ts +7 -0
- package/dist/form/FieldInPlace.svelte +98 -0
- package/dist/form/FieldInPlace.svelte.d.ts +14 -0
- package/dist/form/FieldValue.svelte +148 -0
- package/dist/{demo/form → form}/FieldValue.svelte.d.ts +8 -9
- package/dist/fragments/Confirm.svelte +73 -58
- package/dist/fragments/Confirm.svelte.d.ts +4 -8
- package/dist/fragments/Frame.svelte +19 -19
- package/dist/fragments/InfoLine.svelte +21 -21
- package/dist/fragments/Selector.svelte +26 -26
- package/dist/fragments/Skeleton.svelte +21 -21
- package/dist/index.d.ts +22 -30
- package/dist/index.js +22 -30
- package/dist/main/machine/MachineError.d.ts +33 -0
- package/dist/main/machine/MachineError.js +49 -0
- package/dist/main/machine/MachineErrorValidation.d.ts +19 -0
- package/dist/main/machine/MachineErrorValidation.js +24 -0
- package/dist/main/machine/MachineFieldType.d.ts +121 -0
- package/dist/main/machine/MachineFieldType.js +250 -0
- package/dist/main/machine/MachineScheme.d.ts +84 -0
- package/dist/main/machine/MachineScheme.js +146 -0
- package/dist/main/machine/MachineSchemeField.d.ts +19 -0
- package/dist/main/machine/MachineSchemeField.js +51 -0
- package/dist/main/machine/MachineSchemeFieldForge.d.ts +84 -0
- package/dist/main/machine/MachineSchemeFieldForge.js +128 -0
- package/dist/main/machine/MachineSchemeFieldValues.d.ts +69 -0
- package/dist/main/machine/MachineSchemeFieldValues.js +94 -0
- package/dist/main/machine/MachineSchemeValidate.d.ts +51 -0
- package/dist/main/machine/MachineSchemeValidate.js +120 -0
- package/dist/main/machine/MachineSchemeValues.d.ts +109 -0
- package/dist/main/machine/{IDbCollectionValues.js → MachineSchemeValues.js} +116 -41
- package/dist/main/machine/SchemeFieldDefaultValues.d.ts +74 -0
- package/dist/main/machine/SchemeFieldDefaultValues.js +98 -0
- package/dist/main/machine.d.ts +71 -44
- package/dist/main/machine.js +74 -43
- package/dist/main/machineDb.d.ts +14 -56
- package/dist/main/machineDb.js +15 -98
- package/dist/main/{machineForge.d.ts → machineParserForge.d.ts} +15 -25
- package/dist/main/{machineForge.js → machineParserForge.js} +16 -10
- package/dist/ui/CollectionButton.svelte +29 -26
- package/dist/ui/CollectionButton.svelte.d.ts +3 -3
- package/dist/ui/CollectionFks.svelte +24 -24
- package/dist/ui/CollectionFks.svelte.d.ts +2 -2
- package/dist/ui/CollectionList.svelte +100 -95
- package/dist/ui/CollectionList.svelte.d.ts +1 -2
- package/dist/ui/CollectionListFieldValues.svelte +59 -0
- package/dist/ui/CollectionListFieldValues.svelte.d.ts +9 -0
- package/dist/ui/CollectionListMenu.svelte +39 -47
- package/dist/ui/CollectionListMenu.svelte.d.ts +1 -1
- package/dist/ui/CollectionReverseFks.svelte +37 -56
- package/dist/ui/CollectionReverseFks.svelte.d.ts +4 -8
- package/package.json +18 -5
- package/dist/db/dbSchema.d.ts +0 -201
- package/dist/db/dbSchema.js +0 -205
- package/dist/db/fieldTypes.d.ts +0 -13
- package/dist/db/fieldTypes.js +0 -67
- package/dist/db/types.d.ts +0 -124
- package/dist/demo/form/CreateUpdate.svelte +0 -198
- package/dist/demo/form/CrudZone.svelte +0 -22
- package/dist/demo/form/CrudZone.svelte.d.ts +0 -29
- package/dist/demo/form/DataProvider.svelte +0 -20
- package/dist/demo/form/DataProvider.svelte.d.ts +0 -9
- package/dist/demo/form/FieldInPlace.svelte +0 -49
- package/dist/demo/form/FieldInPlace.svelte.d.ts +0 -11
- package/dist/demo/form/FieldValue.svelte +0 -212
- package/dist/demo/form/types.js +0 -1
- package/dist/demo/testDbSchema.d.ts +0 -6
- package/dist/demo/testDbSchema.js +0 -58
- package/dist/demo/types.d.ts +0 -140
- package/dist/demo/types.js +0 -1
- package/dist/fragments/List.svelte +0 -21
- package/dist/fragments/List.svelte.d.ts +0 -38
- package/dist/main/machine/IDbCollection.d.ts +0 -69
- package/dist/main/machine/IDbCollection.js +0 -98
- package/dist/main/machine/IDbCollectionFieldForge.d.ts +0 -42
- package/dist/main/machine/IDbCollectionFieldForge.js +0 -74
- package/dist/main/machine/IDbCollectionFieldValues.d.ts +0 -46
- package/dist/main/machine/IDbCollectionFieldValues.js +0 -62
- package/dist/main/machine/IDbCollectionValues.d.ts +0 -78
- package/dist/main/machine/IDbError.d.ts +0 -6
- package/dist/main/machine/IDbError.js +0 -61
- package/dist/main/machine/IDbFormValidate.d.ts +0 -55
- package/dist/main/machine/IDbFormValidate.js +0 -183
- package/dist/main/machine/IDbValidationError.d.ts +0 -19
- package/dist/main/machine/IDbValidationError.js +0 -24
- package/dist/main/machine/types.d.ts +0 -1
- package/dist/main/machine/types.js +0 -1
- package/dist/ui/CollectionFieldGuess.svelte +0 -29
- package/dist/ui/CollectionFieldGuess.svelte.d.ts +0 -11
- /package/dist/{demo/form → form}/types.d.ts +0 -0
- /package/dist/{db → form}/types.js +0 -0
package/dist/main/machine.js
CHANGED
|
@@ -1,33 +1,8 @@
|
|
|
1
|
+
import { MachineDb } from "./machineDb.js";
|
|
2
|
+
import { createIdbqDb } from "@medyll/idae-idbql";
|
|
1
3
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
* import { Machine } from './machine.js';
|
|
5
|
-
*
|
|
6
|
-
* // Create a new Machine instance with default parameters
|
|
7
|
-
* const machine = new Machine( 'example-db', 1, { collections: {} });
|
|
8
|
-
*
|
|
9
|
-
* // Start the machine (initialize collections and IDBQL connection)
|
|
10
|
-
* machine.start();
|
|
11
|
-
*
|
|
12
|
-
* // Access collections (schema logic)
|
|
13
|
-
* const collections = machine.collections;
|
|
14
|
-
*
|
|
15
|
-
* // Access IDBQL (readonly)
|
|
16
|
-
* const idbql = machine.idbql;
|
|
17
|
-
*
|
|
18
|
-
* // Access IDBQL (stateful)
|
|
19
|
-
* const idbqlState = machine.idbqlState;
|
|
20
|
-
*
|
|
21
|
-
* // Access IndexedDB core
|
|
22
|
-
* const db = machine.indexedb;
|
|
23
|
-
*
|
|
24
|
-
* // Access the IDBQL data model
|
|
25
|
-
* const model = machine.idbqModel;
|
|
26
|
-
*/
|
|
27
|
-
import { MachineDb } from './machineDb.js';
|
|
28
|
-
import { createIdbqDb } from '@medyll/idae-idbql';
|
|
29
|
-
/**
|
|
30
|
-
* Machine: main entry point for managing the IDBQL connection and centralized data access.
|
|
4
|
+
* @class Machine
|
|
5
|
+
* @role Main entry point for managing the IDBQL connection and centralized data access.
|
|
31
6
|
*/
|
|
32
7
|
export class Machine {
|
|
33
8
|
/**
|
|
@@ -49,7 +24,7 @@ export class Machine {
|
|
|
49
24
|
/**
|
|
50
25
|
* Centralized access to schema and collection logic
|
|
51
26
|
*/
|
|
52
|
-
|
|
27
|
+
_machineDb;
|
|
53
28
|
/**
|
|
54
29
|
* Database name
|
|
55
30
|
*/
|
|
@@ -64,33 +39,60 @@ export class Machine {
|
|
|
64
39
|
_model;
|
|
65
40
|
/**
|
|
66
41
|
* Main constructor
|
|
42
|
+
* @role Constructor
|
|
43
|
+
* @param {string=} dbName The name of the database.
|
|
44
|
+
* @param {number=} version The schema version number.
|
|
45
|
+
* @param {IdbqModel=} model The IDBQL data model.
|
|
67
46
|
*/
|
|
68
47
|
constructor(dbName, version, model) {
|
|
69
|
-
this._dbName = dbName ??
|
|
48
|
+
this._dbName = dbName ?? "";
|
|
70
49
|
this._version = version ?? 1;
|
|
71
50
|
this._model = model ?? undefined;
|
|
72
51
|
}
|
|
52
|
+
/**
|
|
53
|
+
* Initialize the machine with configuration parameters.
|
|
54
|
+
* @role Initializer
|
|
55
|
+
* @param {{ dbName?: string; version?: number; model: IdbqModel }} [options] Optional parameters to set dbName, version, and model.
|
|
56
|
+
* @return {void}
|
|
57
|
+
*/
|
|
73
58
|
init(options) {
|
|
74
59
|
this._dbName = options?.dbName ?? this._dbName;
|
|
75
60
|
this._version = options?.version ?? this._version;
|
|
76
61
|
this._model = options?.model ?? this._model;
|
|
77
62
|
}
|
|
78
63
|
/**
|
|
79
|
-
* Start the machine:
|
|
64
|
+
* Start the machine: initializes collections and the IDBQL connection.
|
|
65
|
+
* Call this after constructing the Machine to set up the database and collections.
|
|
66
|
+
* @role Initializer
|
|
67
|
+
* @return {void}
|
|
80
68
|
*/
|
|
81
69
|
start() {
|
|
82
70
|
this.createCollections();
|
|
83
71
|
this.createStore();
|
|
84
72
|
}
|
|
73
|
+
/**
|
|
74
|
+
* Internal: Creates the collections logic using the provided data model.
|
|
75
|
+
* Throws an error if the model is not defined.
|
|
76
|
+
* @role Internal
|
|
77
|
+
* @private
|
|
78
|
+
* @return {void}
|
|
79
|
+
*/
|
|
85
80
|
createCollections() {
|
|
86
81
|
if (!this._model) {
|
|
87
|
-
throw new Error(
|
|
82
|
+
throw new Error("Data model is not defined");
|
|
88
83
|
}
|
|
89
|
-
this.
|
|
84
|
+
this._machineDb = new MachineDb(this._model);
|
|
90
85
|
}
|
|
86
|
+
/**
|
|
87
|
+
* Internal: Creates the IDBQL store and initializes database connections.
|
|
88
|
+
* Throws an error if model, dbName, or version is missing.
|
|
89
|
+
* @role Internal
|
|
90
|
+
* @private
|
|
91
|
+
* @return {void}
|
|
92
|
+
*/
|
|
91
93
|
createStore() {
|
|
92
94
|
if (!this._model || !this._dbName || !this._version) {
|
|
93
|
-
throw new Error(
|
|
95
|
+
throw new Error("Model, dbName, or version is not defined");
|
|
94
96
|
}
|
|
95
97
|
const idbqStore = createIdbqDb(this._model, this._version);
|
|
96
98
|
const { idbql, idbqlState, idbDatabase, idbqModel } = idbqStore.create(this._dbName);
|
|
@@ -98,40 +100,69 @@ export class Machine {
|
|
|
98
100
|
this._idbqlState = idbqlState;
|
|
99
101
|
this._idbDatabase = idbDatabase;
|
|
100
102
|
this._idbqModel = idbqModel;
|
|
103
|
+
console.log("Machine started with DB:", this._dbName, "Version:", this._version);
|
|
104
|
+
console.log("IDBQL State Instance:", this._idbqlState);
|
|
101
105
|
}
|
|
102
106
|
/**
|
|
103
|
-
* Get the
|
|
107
|
+
* Get the MachineDb (schema logic) instance.
|
|
108
|
+
* @role Accessor
|
|
109
|
+
* @deprecated Use logic instead.
|
|
110
|
+
* @return {MachineDb} The schema and collection logic instance.
|
|
104
111
|
*/
|
|
105
112
|
get collections() {
|
|
106
|
-
return this.
|
|
113
|
+
return this._machineDb;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Get the IDbBase (schema logic) instance.
|
|
117
|
+
* Recommended accessor for schema and collection logic.
|
|
118
|
+
* @role Accessor
|
|
119
|
+
* @return {MachineDb} The schema and collection logic instance.
|
|
120
|
+
*/
|
|
121
|
+
get logic() {
|
|
122
|
+
return this._machineDb;
|
|
107
123
|
}
|
|
108
124
|
/**
|
|
109
|
-
* IDBQL (readonly) instance
|
|
125
|
+
* Get the IDBQL (readonly) instance.
|
|
126
|
+
* Use for read-only access to collections.
|
|
127
|
+
* @role Accessor
|
|
128
|
+
* @return {ReturnType<ReturnType<typeof createIdbqDb>["create"]>["idbql"] | undefined} The readonly IDBQL instance.
|
|
110
129
|
*/
|
|
111
130
|
get idbql() {
|
|
112
131
|
return this._idbql;
|
|
113
132
|
}
|
|
114
133
|
/**
|
|
115
|
-
* IDBQL (stateful) instance
|
|
134
|
+
* Get the IDBQL (stateful) instance.
|
|
135
|
+
* Previously called idbqlState; use for stateful operations.
|
|
136
|
+
* @role Accessor
|
|
137
|
+
* @return {ReturnType<ReturnType<typeof createIdbqDb>["create"]>["idbqlState"]} The stateful IDBQL instance.
|
|
116
138
|
*/
|
|
117
139
|
get store() {
|
|
118
140
|
return this._idbqlState;
|
|
119
141
|
}
|
|
120
142
|
/**
|
|
121
|
-
* Direct getter for idbqlState (for test compatibility)
|
|
143
|
+
* Direct getter for idbqlState (for test compatibility).
|
|
144
|
+
* Returns the stateful IDBQL instance.
|
|
145
|
+
* @role Accessor
|
|
146
|
+
* @deprecated Use store instead.
|
|
147
|
+
* @return {ReturnType<ReturnType<typeof createIdbqDb>["create"]>["idbqlState"]} The stateful IDBQL instance.
|
|
122
148
|
*/
|
|
123
149
|
get idbqlState() {
|
|
124
150
|
return this._idbqlState;
|
|
125
151
|
}
|
|
126
152
|
/**
|
|
127
|
-
* IndexedDB (core) instance
|
|
128
|
-
* @
|
|
153
|
+
* Get the IndexedDB (core) instance.
|
|
154
|
+
* @role Accessor
|
|
155
|
+
* @deprecated Use IDBQL accessors instead.
|
|
156
|
+
* @return {ReturnType<ReturnType<typeof createIdbqDb>["create"]>["idbDatabase"] | undefined} The IndexedDB instance.
|
|
129
157
|
*/
|
|
130
158
|
get indexedb() {
|
|
131
159
|
return this._idbDatabase;
|
|
132
160
|
}
|
|
133
161
|
/**
|
|
134
|
-
* IDBQL data model instance
|
|
162
|
+
* Get the IDBQL data model instance.
|
|
163
|
+
* Returns the current IDBQL model used by the machine.
|
|
164
|
+
* @role Accessor
|
|
165
|
+
* @return {ReturnType<ReturnType<typeof createIdbqDb>["create"]>["idbqModel"] | undefined} The IDBQL model instance.
|
|
135
166
|
*/
|
|
136
167
|
get idbqModel() {
|
|
137
168
|
return this._idbqModel;
|
package/dist/main/machineDb.d.ts
CHANGED
|
@@ -1,42 +1,9 @@
|
|
|
1
|
-
import type { IdbqModel, TplCollectionName
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import { MachineForge } from "./machineForge.js";
|
|
5
|
-
export declare enum enumPrimitive {
|
|
6
|
-
id = "id",
|
|
7
|
-
any = "any",
|
|
8
|
-
date = "date",
|
|
9
|
-
datetime = "datetime",
|
|
10
|
-
time = "time",
|
|
11
|
-
text = "text",
|
|
12
|
-
number = "number",
|
|
13
|
-
boolean = "boolean",
|
|
14
|
-
url = "url",
|
|
15
|
-
email = "email",
|
|
16
|
-
phone = "phone",
|
|
17
|
-
password = "password"
|
|
18
|
-
}
|
|
19
|
-
export declare enum TplProperties {
|
|
20
|
-
"private" = "private",
|
|
21
|
-
"readonly" = "readonly",
|
|
22
|
-
"required" = "required"
|
|
23
|
-
}
|
|
24
|
-
type CombineElements<T extends string, U extends string = T> = T extends any ? T | `${T} ${CombineElements<Exclude<U, T>>}` : never;
|
|
25
|
-
type CombinedArgs = CombineElements<TplProperties>;
|
|
26
|
-
type IdbObjectify<T extends string = "number"> = `array-of-${T}` | `object-${T}`;
|
|
27
|
-
export type IdDbPrimitive<T = {}> = keyof typeof enumPrimitive | `text-${"tiny" | "short" | "medium" | "long" | "area"}` | `${string}.${string}` | `fk-${string}.${string}`;
|
|
28
|
-
export type IDbObjectPrimitive = IdbObjectify<IdDbPrimitive>;
|
|
29
|
-
export type IDbFk = `fk-${string}.${string}`;
|
|
30
|
-
export type IDbFkObject = IdbObjectify<IDbFk>;
|
|
31
|
-
export type IDbTypes = IdDbPrimitive | IDbObjectPrimitive | IDbFk | IDbFkObject;
|
|
32
|
-
export type IDBArgumentsTypes = `${IDbTypes}(${CombinedArgs})`;
|
|
33
|
-
export type IDbFieldRules = IDBArgumentsTypes | IDbTypes;
|
|
34
|
-
export type IDbFieldType = IDBArgumentsTypes | IDbTypes;
|
|
35
|
-
export type IDbForgeArgs = keyof typeof TplProperties;
|
|
1
|
+
import type { IdbqModel, TplCollectionName } from "@medyll/idae-idbql";
|
|
2
|
+
import { MachineScheme } from "./machine/MachineScheme.js";
|
|
3
|
+
import { MachineParserForge } from "./machineParserForge.js";
|
|
36
4
|
/**
|
|
37
|
-
*
|
|
38
|
-
* Provides methods to access collections, templates, fields, foreign keys, and type information.
|
|
39
|
-
* Used for dynamic UI generation, validation, and schema-driven logic.
|
|
5
|
+
* @class MachineDb
|
|
6
|
+
* @role Central class for parsing, introspecting, and extracting metadata from the database schema. Provides methods to access collections, templates, fields, foreign keys, and type information. Used for dynamic UI generation, validation, and schema-driven logic.
|
|
40
7
|
*/
|
|
41
8
|
export declare class MachineDb {
|
|
42
9
|
#private;
|
|
@@ -44,27 +11,18 @@ export declare class MachineDb {
|
|
|
44
11
|
* The database model (schema) used for introspection.
|
|
45
12
|
*/
|
|
46
13
|
model: IdbqModel;
|
|
47
|
-
machineForge:
|
|
14
|
+
machineForge: MachineParserForge;
|
|
48
15
|
/**
|
|
49
|
-
* Create a new
|
|
50
|
-
* @
|
|
16
|
+
* Create a new MachineDb instance.
|
|
17
|
+
* @role Constructor
|
|
18
|
+
* @param {IdbqModel} model Custom model to use.
|
|
51
19
|
*/
|
|
52
|
-
constructor(model
|
|
20
|
+
constructor(model: IdbqModel);
|
|
53
21
|
/**
|
|
54
22
|
* Get an IDbCollection instance for a collection name.
|
|
23
|
+
* @role Collection accessor
|
|
24
|
+
* @param {TplCollectionName} collection The collection name.
|
|
25
|
+
* @return {MachineScheme} The IDbCollection instance.
|
|
55
26
|
*/
|
|
56
|
-
collection(collection: TplCollectionName):
|
|
57
|
-
fks(collection: string): {
|
|
58
|
-
[collection: string]: Tpl;
|
|
59
|
-
};
|
|
60
|
-
reverseFks(targetCollection: TplCollectionName): Record<string, any>;
|
|
61
|
-
/**
|
|
62
|
-
* Parse all fields of a given collection.
|
|
63
|
-
*/
|
|
64
|
-
parseRawCollection(collection: TplCollectionName): Record<string, IDbForge | undefined> | undefined;
|
|
65
|
-
/**
|
|
66
|
-
* Parse a single field of a collection and return its IDbForge metadata.
|
|
67
|
-
*/
|
|
68
|
-
parseCollectionFieldName(collection: TplCollectionName, fieldName: keyof TplFields): IDbForge | undefined;
|
|
27
|
+
collection(collection: TplCollectionName): MachineScheme;
|
|
69
28
|
}
|
|
70
|
-
export {};
|
package/dist/main/machineDb.js
CHANGED
|
@@ -1,118 +1,35 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
*/
|
|
4
|
-
import { schemeModelDb } from "../db/dbSchema.js";
|
|
5
|
-
import { IDbCollection } from "./machine/IDbCollection.js";
|
|
6
|
-
import { IDbError } from "./machine/IDbError.js";
|
|
7
|
-
import { MachineForge } from "./machineForge.js";
|
|
8
|
-
export var enumPrimitive;
|
|
9
|
-
(function (enumPrimitive) {
|
|
10
|
-
enumPrimitive["id"] = "id";
|
|
11
|
-
enumPrimitive["any"] = "any";
|
|
12
|
-
enumPrimitive["date"] = "date";
|
|
13
|
-
enumPrimitive["datetime"] = "datetime";
|
|
14
|
-
enumPrimitive["time"] = "time";
|
|
15
|
-
enumPrimitive["text"] = "text";
|
|
16
|
-
enumPrimitive["number"] = "number";
|
|
17
|
-
enumPrimitive["boolean"] = "boolean";
|
|
18
|
-
enumPrimitive["url"] = "url";
|
|
19
|
-
enumPrimitive["email"] = "email";
|
|
20
|
-
enumPrimitive["phone"] = "phone";
|
|
21
|
-
enumPrimitive["password"] = "password";
|
|
22
|
-
})(enumPrimitive || (enumPrimitive = {}));
|
|
23
|
-
export var TplProperties;
|
|
24
|
-
(function (TplProperties) {
|
|
25
|
-
TplProperties["private"] = "private";
|
|
26
|
-
TplProperties["readonly"] = "readonly";
|
|
27
|
-
TplProperties["required"] = "required";
|
|
28
|
-
})(TplProperties || (TplProperties = {}));
|
|
29
|
-
const a = "any(private required readonly)";
|
|
1
|
+
import { MachineScheme } from "./machine/MachineScheme.js";
|
|
2
|
+
import { MachineParserForge } from "./machineParserForge.js";
|
|
30
3
|
/**
|
|
31
|
-
*
|
|
32
|
-
* Provides methods to access collections, templates, fields, foreign keys, and type information.
|
|
33
|
-
* Used for dynamic UI generation, validation, and schema-driven logic.
|
|
4
|
+
* @class MachineDb
|
|
5
|
+
* @role Central class for parsing, introspecting, and extracting metadata from the database schema. Provides methods to access collections, templates, fields, foreign keys, and type information. Used for dynamic UI generation, validation, and schema-driven logic.
|
|
34
6
|
*/
|
|
35
7
|
export class MachineDb {
|
|
36
8
|
/**
|
|
37
9
|
* The database model (schema) used for introspection.
|
|
38
10
|
*/
|
|
39
|
-
model
|
|
40
|
-
machineForge = new
|
|
11
|
+
model;
|
|
12
|
+
machineForge = new MachineParserForge();
|
|
41
13
|
#idbCollectionsList = {};
|
|
42
14
|
/**
|
|
43
|
-
* Create a new
|
|
44
|
-
* @
|
|
15
|
+
* Create a new MachineDb instance.
|
|
16
|
+
* @role Constructor
|
|
17
|
+
* @param {IdbqModel} model Custom model to use.
|
|
45
18
|
*/
|
|
46
19
|
constructor(model) {
|
|
47
|
-
this.model = model
|
|
48
|
-
this.machineForge = new
|
|
20
|
+
this.model = model;
|
|
21
|
+
this.machineForge = new MachineParserForge();
|
|
49
22
|
}
|
|
50
23
|
/**
|
|
51
24
|
* Get an IDbCollection instance for a collection name.
|
|
25
|
+
* @role Collection accessor
|
|
26
|
+
* @param {TplCollectionName} collection The collection name.
|
|
27
|
+
* @return {MachineScheme} The IDbCollection instance.
|
|
52
28
|
*/
|
|
53
29
|
collection(collection) {
|
|
54
30
|
if (!this.#idbCollectionsList[collection]) {
|
|
55
|
-
this.#idbCollectionsList[collection] = new
|
|
31
|
+
this.#idbCollectionsList[collection] = new MachineScheme(collection, this, this.model);
|
|
56
32
|
}
|
|
57
33
|
return this.#idbCollectionsList[collection];
|
|
58
34
|
}
|
|
59
|
-
fks(collection) {
|
|
60
|
-
const fks = this.collection(collection).getModelTemplateFks();
|
|
61
|
-
const out = {};
|
|
62
|
-
if (fks) {
|
|
63
|
-
Object.keys(fks).forEach((collection) => {
|
|
64
|
-
out[collection] = this.parseRawCollection(collection);
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
return out;
|
|
68
|
-
}
|
|
69
|
-
reverseFks(targetCollection) {
|
|
70
|
-
const result = {};
|
|
71
|
-
Object.entries(this.model).forEach(([collectionName, collectionModel]) => {
|
|
72
|
-
const template = collectionModel.template;
|
|
73
|
-
if (template && template.fks) {
|
|
74
|
-
Object.entries(template.fks).forEach(([fkName, fkConfig]) => {
|
|
75
|
-
if (fkConfig?.code === targetCollection) {
|
|
76
|
-
if (!result[collectionName]) {
|
|
77
|
-
result[collectionName] = {};
|
|
78
|
-
}
|
|
79
|
-
result[collectionName][fkName] = fkConfig;
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
return result;
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Parse all fields of a given collection.
|
|
88
|
-
*/
|
|
89
|
-
parseRawCollection(collection) {
|
|
90
|
-
const fields = new IDbCollection(collection, this, this.model).fields;
|
|
91
|
-
if (!fields)
|
|
92
|
-
return;
|
|
93
|
-
const out = {};
|
|
94
|
-
Object.keys(fields).forEach((fieldName) => {
|
|
95
|
-
const fieldType = fields[fieldName];
|
|
96
|
-
if (fieldType) {
|
|
97
|
-
out[fieldName] = this.parseCollectionFieldName(collection, fieldName);
|
|
98
|
-
}
|
|
99
|
-
});
|
|
100
|
-
return out;
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
|
-
* Parse a single field of a collection and return its IDbForge metadata.
|
|
104
|
-
*/
|
|
105
|
-
parseCollectionFieldName(collection, fieldName) {
|
|
106
|
-
const field = this.collection(collection).getFieldRule(fieldName);
|
|
107
|
-
if (!field) {
|
|
108
|
-
IDbError.throwError(`Field ${fieldName} not found in collection ${collection}`, "FIELD_NOT_FOUND");
|
|
109
|
-
return undefined;
|
|
110
|
-
}
|
|
111
|
-
const array = this.machineForge.testIs("array", field);
|
|
112
|
-
const object = this.machineForge.testIs("object", field);
|
|
113
|
-
const fk = this.machineForge.testIs("fk", field);
|
|
114
|
-
const primitive = this.machineForge.testIs("primitive", field);
|
|
115
|
-
const fieldType = array ?? object ?? fk ?? primitive;
|
|
116
|
-
return this.machineForge.forge({ collection, fieldName, ...fieldType });
|
|
117
|
-
}
|
|
118
35
|
}
|
|
@@ -1,30 +1,20 @@
|
|
|
1
|
-
import type { TplCollectionName,
|
|
2
|
-
import type { IDbFieldType, IDbFieldRules, IDbForgeArgs } from "./machineDb.js";
|
|
3
|
-
/**
|
|
4
|
-
* Represents the structure for database field forging.
|
|
5
|
-
* Used to describe and construct database field definitions dynamically.
|
|
6
|
-
*/
|
|
7
|
-
export type IDbForge = {
|
|
8
|
-
/** Name of the collection (table) */
|
|
9
|
-
collection?: TplCollectionName;
|
|
10
|
-
/** Name of the field within the collection */
|
|
11
|
-
fieldName?: keyof TplFields;
|
|
12
|
-
/** Type of the field (e.g., string, number, fk, array, etc.) */
|
|
13
|
-
fieldType?: IDbFieldType;
|
|
14
|
-
/** Field rule string describing the type and constraints */
|
|
15
|
-
fieldRule?: IDbFieldRules;
|
|
16
|
-
/** Additional arguments for the field (properties, options, etc.) */
|
|
17
|
-
fieldArgs?: IDbForgeArgs | undefined;
|
|
18
|
-
/** The resolved type (array, object, fk, primitive) */
|
|
19
|
-
is: unknown;
|
|
20
|
-
};
|
|
1
|
+
import type { TplCollectionName, TplFieldRules, TplFieldType, TplFieldArgs } from "@medyll/idae-idbql";
|
|
21
2
|
/**
|
|
22
3
|
* Utility class for parsing and constructing database field definitions (IDbForge).
|
|
23
4
|
* Provides methods to analyze field rules and extract type information for schema generation.
|
|
24
5
|
*/
|
|
25
|
-
export
|
|
6
|
+
export type IDbForge = {
|
|
7
|
+
collection: TplCollectionName;
|
|
8
|
+
fieldName: string;
|
|
9
|
+
fieldType: TplFieldType;
|
|
10
|
+
fieldRule: TplFieldRules;
|
|
11
|
+
fieldArgs: TplFieldArgs;
|
|
12
|
+
is: "array" | "object" | "fk" | "primitive";
|
|
13
|
+
};
|
|
14
|
+
export declare class MachineParserForge {
|
|
15
|
+
#private;
|
|
26
16
|
/**
|
|
27
|
-
* Create a new
|
|
17
|
+
* Create a new MachineParserForge instance.
|
|
28
18
|
*/
|
|
29
19
|
constructor();
|
|
30
20
|
/**
|
|
@@ -33,21 +23,21 @@ export declare class MachineForge {
|
|
|
33
23
|
* @param fieldRule - The field rule string to analyze.
|
|
34
24
|
* @returns Partial IDbForge object if the rule matches, otherwise undefined.
|
|
35
25
|
*/
|
|
36
|
-
testIs(what: "array" | "object" | "fk" | "primitive", fieldRule:
|
|
26
|
+
testIs(what: "array" | "object" | "fk" | "primitive", fieldRule: TplFieldRules): Partial<IDbForge> | undefined;
|
|
37
27
|
/**
|
|
38
28
|
* Returns a partial IDbForge object for the given type and field rule.
|
|
39
29
|
* @param what - The type to extract ("array", "object", "fk", "primitive").
|
|
40
30
|
* @param fieldRule - The field rule string to analyze.
|
|
41
31
|
* @returns Partial IDbForge object with extracted type info.
|
|
42
32
|
*/
|
|
43
|
-
is(what: "array" | "object" | "fk" | "primitive", fieldRule:
|
|
33
|
+
is(what: "array" | "object" | "fk" | "primitive", fieldRule: TplFieldRules): Partial<IDbForge>;
|
|
44
34
|
/**
|
|
45
35
|
* Extracts type, rule, and argument information from a field rule string.
|
|
46
36
|
* @param type - The type to extract ("array", "object", "fk", "primitive").
|
|
47
37
|
* @param fieldRule - The field rule string to analyze.
|
|
48
38
|
* @returns Partial IDbForge object with extracted details.
|
|
49
39
|
*/
|
|
50
|
-
extract(type: "array" | "object" | "fk" | "primitive", fieldRule:
|
|
40
|
+
extract(type: "array" | "object" | "fk" | "primitive", fieldRule: TplFieldRules): Partial<IDbForge>;
|
|
51
41
|
/**
|
|
52
42
|
* Constructs an IDbForge object from its components.
|
|
53
43
|
* @param params - The components of the IDbForge object.
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
*/
|
|
5
|
-
export class MachineForge {
|
|
1
|
+
import { MachineError } from "./machine/MachineError.js";
|
|
2
|
+
export class MachineParserForge {
|
|
3
|
+
#machineForge;
|
|
6
4
|
/**
|
|
7
|
-
* Create a new
|
|
5
|
+
* Create a new MachineParserForge instance.
|
|
8
6
|
*/
|
|
9
|
-
constructor() {
|
|
7
|
+
constructor() {
|
|
8
|
+
// Correction : ne pas initialiser #machineForge récursivement
|
|
9
|
+
this.#machineForge = undefined;
|
|
10
|
+
}
|
|
10
11
|
/**
|
|
11
12
|
* Test if a field rule matches a specific type (array, object, fk, primitive).
|
|
12
13
|
* @param what - The type to test for ("array", "object", "fk", "primitive").
|
|
@@ -70,9 +71,14 @@ export class MachineForge {
|
|
|
70
71
|
function extractArgs(source) {
|
|
71
72
|
const [piece, remaining] = source.split("(");
|
|
72
73
|
if (!remaining)
|
|
73
|
-
return { piece: piece.trim(), args:
|
|
74
|
-
|
|
75
|
-
|
|
74
|
+
return { piece: piece.trim(), args: [] };
|
|
75
|
+
let central;
|
|
76
|
+
if (remaining !== undefined) {
|
|
77
|
+
[central] = remaining.split(")");
|
|
78
|
+
}
|
|
79
|
+
const args = central
|
|
80
|
+
? central.split(" ")
|
|
81
|
+
: undefined;
|
|
76
82
|
return { piece: piece.trim(), args };
|
|
77
83
|
}
|
|
78
84
|
const extractedArgs = extractArgs(fieldRule);
|
|
@@ -1,26 +1,29 @@
|
|
|
1
|
-
<!--
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
let { collection = 'book', withData, ...rest }
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
<Button class="ellipsis" onclick={() => openCrud(collection)} width="auto" icon="mdi:add" value=
|
|
1
|
+
<!--
|
|
2
|
+
CollectionButton.svelte
|
|
3
|
+
Svelte 5 button to open CreateUpdate window for a collection
|
|
4
|
+
@role ui-button
|
|
5
|
+
@prop {string} collection - Collection name
|
|
6
|
+
@prop {object} [withData] - Data to prefill
|
|
7
|
+
@slot button - Custom button content
|
|
8
|
+
@event click - Emitted on button click
|
|
9
|
+
-->
|
|
10
|
+
|
|
11
|
+
<script lang="ts" generics="COL">
|
|
12
|
+
import { Button, openWindow } from '@medyll/idae-slotui-svelte';
|
|
13
|
+
import CreateUpdate from '../form/CreateUpdate.svelte';
|
|
14
|
+
import { type CreateUpdateProps } from '../form/types.js';
|
|
15
|
+
let { collection = 'book', withData, ...rest } = $props<{ collection?: string; withData?: Record<string, any> } & CreateUpdateProps>();
|
|
16
|
+
function openCrud(collection: string) {
|
|
17
|
+
openWindow(`create-${collection}`, {
|
|
18
|
+
component: CreateUpdate,
|
|
19
|
+
componentProps: { collection, withData, ...rest },
|
|
20
|
+
hideCloseButton: false
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
</script>
|
|
24
|
+
|
|
25
|
+
{#snippet button()}
|
|
26
|
+
<Button class="ellipsis" onclick={() => openCrud(collection)} width="auto" icon="mdi:add" value={`ui.${rest.mode}-${collection}`} />
|
|
27
|
+
{/snippet}
|
|
28
|
+
|
|
29
|
+
{@render button()}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { type CreateUpdateProps } from '../form/types.js';
|
|
2
|
-
type
|
|
3
|
-
collection
|
|
2
|
+
type $$ComponentProps = {
|
|
3
|
+
collection?: string;
|
|
4
4
|
withData?: Record<string, any>;
|
|
5
5
|
} & CreateUpdateProps;
|
|
6
6
|
declare function $$render<COL>(): {
|
|
7
|
-
props:
|
|
7
|
+
props: $$ComponentProps;
|
|
8
8
|
exports: {};
|
|
9
9
|
bindings: "";
|
|
10
10
|
slots: {};
|
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const fks = $derived(machine.
|
|
18
|
-
</script>
|
|
19
|
-
|
|
20
|
-
<Looper data={Object.entries(fks)}>
|
|
21
|
-
{#snippet children(
|
|
22
|
-
<div>{item[0]}</div>
|
|
23
|
-
{/snippet}
|
|
24
|
-
</Looper>
|
|
1
|
+
<!--
|
|
2
|
+
CollectionFks.svelte
|
|
3
|
+
Svelte 5 FK relation viewer for a collection
|
|
4
|
+
@role ui-fragment
|
|
5
|
+
@prop {string} collection - Collection name
|
|
6
|
+
@prop {any} [collectionId] - Optional collection id
|
|
7
|
+
@prop {object} [where] - Optional filter
|
|
8
|
+
@slot children (let:item) - Custom FK rendering
|
|
9
|
+
-->
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
<script lang="ts">
|
|
13
|
+
import type { TplCollectionName, Where } from '@medyll/idae-idbql';
|
|
14
|
+
import { Looper } from '@medyll/idae-slotui-svelte';
|
|
15
|
+
import { machine } from '../main/machine.js';
|
|
16
|
+
let { collection, collectionId, where } = $props<{ collection: TplCollectionName; collectionId?: any; where?: Where }>();
|
|
17
|
+
const fks = $derived(machine.logic.collection(collection).parseFks());
|
|
18
|
+
</script>
|
|
19
|
+
|
|
20
|
+
<Looper data={Object.entries(fks)}>
|
|
21
|
+
{#snippet children(item)}
|
|
22
|
+
<div>{item[0]}</div>
|
|
23
|
+
{/snippet}
|
|
24
|
+
</Looper>
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { TplCollectionName, Where } from '@medyll/idae-idbql';
|
|
2
|
-
type
|
|
2
|
+
type $$ComponentProps = {
|
|
3
3
|
collection: TplCollectionName;
|
|
4
4
|
collectionId?: any;
|
|
5
5
|
where?: Where;
|
|
6
6
|
};
|
|
7
|
-
declare const CollectionFks: import("svelte").Component
|
|
7
|
+
declare const CollectionFks: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
8
8
|
type CollectionFks = ReturnType<typeof CollectionFks>;
|
|
9
9
|
export default CollectionFks;
|