@medyll/idae-machine 0.124.0 → 0.125.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/CreateUpdate.svelte +2 -1
- package/dist/index.d.ts +18 -11
- package/dist/index.js +18 -11
- package/dist/main/machine/IDbCollection.d.ts +71 -0
- package/dist/main/machine/IDbCollection.js +102 -0
- package/dist/main/machine/IDbCollectionFieldForge.d.ts +42 -0
- package/dist/main/machine/IDbCollectionFieldForge.js +74 -0
- package/dist/main/machine/IDbCollectionFieldValues.d.ts +57 -0
- package/dist/main/machine/IDbCollectionFieldValues.js +82 -0
- package/dist/main/machine/IDbCollectionValues.d.ts +78 -0
- package/dist/main/machine/IDbCollectionValues.js +203 -0
- package/dist/main/machine/IDbError.d.ts +6 -0
- package/dist/main/machine/IDbError.js +61 -0
- package/dist/main/machine/IDbFormValidate.d.ts +55 -0
- package/dist/main/machine/IDbFormValidate.js +183 -0
- package/dist/main/machine/IDbValidationError.d.ts +19 -0
- package/dist/main/machine/IDbValidationError.js +24 -0
- package/dist/main/machineDb.d.ts +18 -222
- package/dist/main/machineDb.js +60 -653
- package/dist/main/machineForge.d.ts +57 -0
- package/dist/main/machineForge.js +105 -0
- package/dist/{form → ui}/CollectionButton.svelte +2 -2
- package/dist/{form → ui}/CollectionButton.svelte.d.ts +1 -1
- package/dist/{form → ui}/CollectionFks.svelte +3 -5
- package/dist/{form → ui}/CollectionList.svelte +1 -1
- package/dist/{form → ui}/CollectionListMenu.svelte +3 -2
- package/package.json +3 -3
- package/dist/form/DataList.svelte +0 -60
- package/dist/form/DataList.svelte.d.ts +0 -10
- /package/dist/{form → ui}/CollectionFieldGuess.svelte +0 -0
- /package/dist/{form → ui}/CollectionFieldGuess.svelte.d.ts +0 -0
- /package/dist/{form → ui}/CollectionFks.svelte.d.ts +0 -0
- /package/dist/{form → ui}/CollectionList.svelte.d.ts +0 -0
- /package/dist/{form → ui}/CollectionListMenu.svelte.d.ts +0 -0
- /package/dist/{form → ui}/CollectionReverseFks.svelte +0 -0
- /package/dist/{form → ui}/CollectionReverseFks.svelte.d.ts +0 -0
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
-->
|
|
5
5
|
|
|
6
6
|
<script lang="ts" generics="COL = Record<string,any>">
|
|
7
|
-
|
|
7
|
+
|
|
8
|
+
import { IDbFormValidate } from '../main/IDbFormValidate';
|
|
8
9
|
import type { CreateUpdateProps } from './types';
|
|
9
10
|
import CollectionReverseFks from './CollectionReverseFks.svelte';
|
|
10
11
|
import FieldInput from './FieldValue.svelte';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
|
+
export { default as CollectionReverseFks } from './ui/CollectionReverseFks.svelte';
|
|
2
|
+
export { default as CollectionListMenu } from './ui/CollectionListMenu.svelte';
|
|
3
|
+
export { default as CollectionList } from './ui/CollectionList.svelte';
|
|
4
|
+
export { default as CollectionFks } from './ui/CollectionFks.svelte';
|
|
5
|
+
export { default as CollectionFieldGuess } from './ui/CollectionFieldGuess.svelte';
|
|
6
|
+
export { default as CollectionButton } from './ui/CollectionButton.svelte';
|
|
1
7
|
export * from './types/appschemeTypes.js';
|
|
2
|
-
export * from './main/machineDb.js';
|
|
3
|
-
export * from './main/machineDb.spec.js';
|
|
4
|
-
export * from './main/machine.js';
|
|
5
|
-
export * from './main/machine.spec.js';
|
|
6
8
|
export { default as Skeleton } from './fragments/Skeleton.svelte';
|
|
7
9
|
export { default as Selector } from './fragments/Selector.svelte';
|
|
8
10
|
export { default as List } from './fragments/List.svelte';
|
|
9
11
|
export { default as InfoLine } from './fragments/InfoLine.svelte';
|
|
10
12
|
export { default as Frame } from './fragments/Frame.svelte';
|
|
11
13
|
export { default as Confirm } from './fragments/Confirm.svelte';
|
|
14
|
+
export * from './main/machineForge.js';
|
|
15
|
+
export * from './main/machineDb.js';
|
|
16
|
+
export * from './main/machineDb.spec.js';
|
|
17
|
+
export * from './main/machine.js';
|
|
18
|
+
export * from './main/machine.spec.js';
|
|
12
19
|
export * from './form/types.js';
|
|
13
20
|
export { default as FieldValue } from './form/FieldValue.svelte';
|
|
14
21
|
export { default as FieldInPlace } from './form/FieldInPlace.svelte';
|
|
15
22
|
export { default as DataProvider } from './form/DataProvider.svelte';
|
|
16
|
-
export { default as DataList } from './form/DataList.svelte';
|
|
17
23
|
export { default as CrudZone } from './form/CrudZone.svelte';
|
|
18
24
|
export { default as CreateUpdate } from './form/CreateUpdate.svelte';
|
|
19
|
-
export { default as CollectionReverseFks } from './form/CollectionReverseFks.svelte';
|
|
20
|
-
export { default as CollectionListMenu } from './form/CollectionListMenu.svelte';
|
|
21
|
-
export { default as CollectionList } from './form/CollectionList.svelte';
|
|
22
|
-
export { default as CollectionFks } from './form/CollectionFks.svelte';
|
|
23
|
-
export { default as CollectionFieldGuess } from './form/CollectionFieldGuess.svelte';
|
|
24
|
-
export { default as CollectionButton } from './form/CollectionButton.svelte';
|
|
25
25
|
export * from './db/types.js';
|
|
26
26
|
export * from './db/testDbSchema.js';
|
|
27
27
|
export * from './db/dbSchema.js';
|
|
@@ -32,3 +32,10 @@ export * from './db/dbCollectionFieldValues.spec.js';
|
|
|
32
32
|
export * from './db/dbCollectionFieldForge.spec.js';
|
|
33
33
|
export * from './db/dataModel.js';
|
|
34
34
|
export * from './db/CrudService.js';
|
|
35
|
+
export * from './main/machine/IDbValidationError.js';
|
|
36
|
+
export * from './main/machine/IDbFormValidate.js';
|
|
37
|
+
export * from './main/machine/IDbError.js';
|
|
38
|
+
export * from './main/machine/IDbCollectionValues.js';
|
|
39
|
+
export * from './main/machine/IDbCollectionFieldValues.js';
|
|
40
|
+
export * from './main/machine/IDbCollectionFieldForge.js';
|
|
41
|
+
export * from './main/machine/IDbCollection.js';
|
package/dist/index.js
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
1
|
// auto exports of entry components
|
|
2
|
+
export { default as CollectionReverseFks } from './ui/CollectionReverseFks.svelte';
|
|
3
|
+
export { default as CollectionListMenu } from './ui/CollectionListMenu.svelte';
|
|
4
|
+
export { default as CollectionList } from './ui/CollectionList.svelte';
|
|
5
|
+
export { default as CollectionFks } from './ui/CollectionFks.svelte';
|
|
6
|
+
export { default as CollectionFieldGuess } from './ui/CollectionFieldGuess.svelte';
|
|
7
|
+
export { default as CollectionButton } from './ui/CollectionButton.svelte';
|
|
2
8
|
export * from './types/appschemeTypes.js';
|
|
3
|
-
export * from './main/machineDb.js';
|
|
4
|
-
export * from './main/machineDb.spec.js';
|
|
5
|
-
export * from './main/machine.js';
|
|
6
|
-
export * from './main/machine.spec.js';
|
|
7
9
|
export { default as Skeleton } from './fragments/Skeleton.svelte';
|
|
8
10
|
export { default as Selector } from './fragments/Selector.svelte';
|
|
9
11
|
export { default as List } from './fragments/List.svelte';
|
|
10
12
|
export { default as InfoLine } from './fragments/InfoLine.svelte';
|
|
11
13
|
export { default as Frame } from './fragments/Frame.svelte';
|
|
12
14
|
export { default as Confirm } from './fragments/Confirm.svelte';
|
|
15
|
+
export * from './main/machineForge.js';
|
|
16
|
+
export * from './main/machineDb.js';
|
|
17
|
+
export * from './main/machineDb.spec.js';
|
|
18
|
+
export * from './main/machine.js';
|
|
19
|
+
export * from './main/machine.spec.js';
|
|
13
20
|
export * from './form/types.js';
|
|
14
21
|
export { default as FieldValue } from './form/FieldValue.svelte';
|
|
15
22
|
export { default as FieldInPlace } from './form/FieldInPlace.svelte';
|
|
16
23
|
export { default as DataProvider } from './form/DataProvider.svelte';
|
|
17
|
-
export { default as DataList } from './form/DataList.svelte';
|
|
18
24
|
export { default as CrudZone } from './form/CrudZone.svelte';
|
|
19
25
|
export { default as CreateUpdate } from './form/CreateUpdate.svelte';
|
|
20
|
-
export { default as CollectionReverseFks } from './form/CollectionReverseFks.svelte';
|
|
21
|
-
export { default as CollectionListMenu } from './form/CollectionListMenu.svelte';
|
|
22
|
-
export { default as CollectionList } from './form/CollectionList.svelte';
|
|
23
|
-
export { default as CollectionFks } from './form/CollectionFks.svelte';
|
|
24
|
-
export { default as CollectionFieldGuess } from './form/CollectionFieldGuess.svelte';
|
|
25
|
-
export { default as CollectionButton } from './form/CollectionButton.svelte';
|
|
26
26
|
export * from './db/types.js';
|
|
27
27
|
export * from './db/testDbSchema.js';
|
|
28
28
|
export * from './db/dbSchema.js';
|
|
@@ -33,3 +33,10 @@ export * from './db/dbCollectionFieldValues.spec.js';
|
|
|
33
33
|
export * from './db/dbCollectionFieldForge.spec.js';
|
|
34
34
|
export * from './db/dataModel.js';
|
|
35
35
|
export * from './db/CrudService.js';
|
|
36
|
+
export * from './main/machine/IDbValidationError.js';
|
|
37
|
+
export * from './main/machine/IDbFormValidate.js';
|
|
38
|
+
export * from './main/machine/IDbError.js';
|
|
39
|
+
export * from './main/machine/IDbCollectionValues.js';
|
|
40
|
+
export * from './main/machine/IDbCollectionFieldValues.js';
|
|
41
|
+
export * from './main/machine/IDbCollectionFieldForge.js';
|
|
42
|
+
export * from './main/machine/IDbCollection.js';
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import type { TplCollectionName, Tpl, IdbqModel, TplFields } from "@medyll/idae-idbql";
|
|
2
|
+
import { MachineDb, type IDbFieldRules } from "../machineDb.js";
|
|
3
|
+
import { IDbFormValidate } from "./IDbFormValidate.js";
|
|
4
|
+
import { IDbCollectionFieldForge } from "./IDbCollectionFieldForge.js";
|
|
5
|
+
import { IDbCollectionFieldValues } from "./IDbCollectionFieldValues.js";
|
|
6
|
+
import { IDbCollectionValues } from "./IDbCollectionValues.js";
|
|
7
|
+
/**
|
|
8
|
+
* IDbCollection
|
|
9
|
+
*
|
|
10
|
+
* Represents a single collection template, providing access to its schema, fields, and metadata.
|
|
11
|
+
*
|
|
12
|
+
* Main responsibilities:
|
|
13
|
+
* - Holds references to the collection name, template, and model.
|
|
14
|
+
* - Provides access to field rules, presentation, and foreign keys.
|
|
15
|
+
* - Supplies utilities for retrieving collection values and templates.
|
|
16
|
+
*
|
|
17
|
+
* Usage:
|
|
18
|
+
* const collection = new IDbCollection('agents', idbBase, model);
|
|
19
|
+
* const fields = collection.fields;
|
|
20
|
+
* const presentation = collection.getPresentation();
|
|
21
|
+
*
|
|
22
|
+
* This class is typically used for schema-driven applications and dynamic UI generation.
|
|
23
|
+
*/
|
|
24
|
+
export declare class IDbCollection {
|
|
25
|
+
#private;
|
|
26
|
+
/** The collection name. */
|
|
27
|
+
collection: TplCollectionName;
|
|
28
|
+
/**
|
|
29
|
+
* Create a new IDbCollection instance.
|
|
30
|
+
* @param collectionName The collection name.
|
|
31
|
+
* @param idbBase The MachineDb instance.
|
|
32
|
+
* @param model The IdbqModel instance.
|
|
33
|
+
*/
|
|
34
|
+
constructor(collectionName: TplCollectionName, idbBase: MachineDb, model: IdbqModel);
|
|
35
|
+
/**
|
|
36
|
+
* Get the collection model.
|
|
37
|
+
*/
|
|
38
|
+
get model(): import("@medyll/idae-idbql").CollectionModel<Record<string, any>>;
|
|
39
|
+
/**
|
|
40
|
+
* Get the collection fields.
|
|
41
|
+
*/
|
|
42
|
+
get fields(): TplFields;
|
|
43
|
+
/**
|
|
44
|
+
* Get the presentation string for the collection.
|
|
45
|
+
*/
|
|
46
|
+
getPresentation(): string;
|
|
47
|
+
/**
|
|
48
|
+
* Get the field rule for a given field name.
|
|
49
|
+
* @param fieldName The field name.
|
|
50
|
+
*/
|
|
51
|
+
getFieldRule(fieldName: keyof TplFields): IDbFieldRules | undefined;
|
|
52
|
+
/**
|
|
53
|
+
* Get the collection template.
|
|
54
|
+
*/
|
|
55
|
+
getTemplate(): Tpl;
|
|
56
|
+
/**
|
|
57
|
+
* Get the foreign keys from the model template.
|
|
58
|
+
*/
|
|
59
|
+
getModelTemplateFks(): Tpl["fks"];
|
|
60
|
+
/**
|
|
61
|
+
* Get the index name for the collection.
|
|
62
|
+
*/
|
|
63
|
+
getIndexName(): string;
|
|
64
|
+
/**
|
|
65
|
+
* Get a new IDbCollectionValues instance for this collection.
|
|
66
|
+
*/
|
|
67
|
+
collectionValues(): IDbCollectionValues<Record<string, any>>;
|
|
68
|
+
collectionFieldValues<T extends Record<string, any>>(data: T): IDbCollectionFieldValues<T>;
|
|
69
|
+
fieldForge<T extends Record<string, any>>(fieldName: keyof T, data: T): IDbCollectionFieldForge<T>;
|
|
70
|
+
getFormValidate(): IDbFormValidate;
|
|
71
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { MachineDb } from "../machineDb.js";
|
|
2
|
+
import { IDbFormValidate } from "./IDbFormValidate.js";
|
|
3
|
+
import { IDbCollectionFieldForge } from "./IDbCollectionFieldForge.js";
|
|
4
|
+
import { IDbCollectionFieldValues } from "./IDbCollectionFieldValues.js";
|
|
5
|
+
import { IDbCollectionValues } from "./IDbCollectionValues.js";
|
|
6
|
+
/**
|
|
7
|
+
* IDbCollection
|
|
8
|
+
*
|
|
9
|
+
* Represents a single collection template, providing access to its schema, fields, and metadata.
|
|
10
|
+
*
|
|
11
|
+
* Main responsibilities:
|
|
12
|
+
* - Holds references to the collection name, template, and model.
|
|
13
|
+
* - Provides access to field rules, presentation, and foreign keys.
|
|
14
|
+
* - Supplies utilities for retrieving collection values and templates.
|
|
15
|
+
*
|
|
16
|
+
* Usage:
|
|
17
|
+
* const collection = new IDbCollection('agents', idbBase, model);
|
|
18
|
+
* const fields = collection.fields;
|
|
19
|
+
* const presentation = collection.getPresentation();
|
|
20
|
+
*
|
|
21
|
+
* This class is typically used for schema-driven applications and dynamic UI generation.
|
|
22
|
+
*/
|
|
23
|
+
export class IDbCollection {
|
|
24
|
+
/** The collection name. */
|
|
25
|
+
collection;
|
|
26
|
+
/** The collection template. */
|
|
27
|
+
#template;
|
|
28
|
+
/** The MachineDb instance. */
|
|
29
|
+
#machineDb;
|
|
30
|
+
/** The collection model. */
|
|
31
|
+
#model;
|
|
32
|
+
/**
|
|
33
|
+
* Create a new IDbCollection instance.
|
|
34
|
+
* @param collectionName The collection name.
|
|
35
|
+
* @param idbBase The MachineDb instance.
|
|
36
|
+
* @param model The IdbqModel instance.
|
|
37
|
+
*/
|
|
38
|
+
constructor(collectionName, idbBase, model) {
|
|
39
|
+
this.collection = collectionName;
|
|
40
|
+
this.#machineDb = idbBase;
|
|
41
|
+
this.#model = model[String(collectionName)];
|
|
42
|
+
this.#template = this.#model["template"];
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Get the collection model.
|
|
46
|
+
*/
|
|
47
|
+
get model() {
|
|
48
|
+
return this.#model;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Get the collection fields.
|
|
52
|
+
*/
|
|
53
|
+
get fields() {
|
|
54
|
+
return this.#template?.fields;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Get the presentation string for the collection.
|
|
58
|
+
*/
|
|
59
|
+
getPresentation() {
|
|
60
|
+
return this.#template?.presentation;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Get the field rule for a given field name.
|
|
64
|
+
* @param fieldName The field name.
|
|
65
|
+
*/
|
|
66
|
+
getFieldRule(fieldName) {
|
|
67
|
+
return this.fields[String(fieldName)];
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Get the collection template.
|
|
71
|
+
*/
|
|
72
|
+
getTemplate() {
|
|
73
|
+
return this.#template;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Get the foreign keys from the model template.
|
|
77
|
+
*/
|
|
78
|
+
getModelTemplateFks() {
|
|
79
|
+
return this.#template?.fks;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Get the index name for the collection.
|
|
83
|
+
*/
|
|
84
|
+
getIndexName() {
|
|
85
|
+
return this.#template?.index;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Get a new IDbCollectionValues instance for this collection.
|
|
89
|
+
*/
|
|
90
|
+
collectionValues() {
|
|
91
|
+
return new IDbCollectionValues(this.collection, this.#machineDb);
|
|
92
|
+
}
|
|
93
|
+
collectionFieldValues(data) {
|
|
94
|
+
return new IDbCollectionFieldValues(this.collection, data, this.collectionValues());
|
|
95
|
+
}
|
|
96
|
+
fieldForge(fieldName, data) {
|
|
97
|
+
return new IDbCollectionFieldForge(this.collection, fieldName, data, this.collectionValues());
|
|
98
|
+
}
|
|
99
|
+
getFormValidate() {
|
|
100
|
+
return new IDbFormValidate(this.collection, this.#machineDb);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { TplCollectionName } from '@medyll/idae-idbql';
|
|
2
|
+
import { IDbCollectionValues } from './IDbCollectionValues.js';
|
|
3
|
+
import type { IDbForgeArgs, IDbFieldType } from '../machineDb.js';
|
|
4
|
+
import type { IDbForge } from '../machineForge.js';
|
|
5
|
+
/**
|
|
6
|
+
* IDbCollectionFieldForge
|
|
7
|
+
*
|
|
8
|
+
* This class provides advanced metadata and formatting for a single field of a collection, given a data object.
|
|
9
|
+
* It is designed for dynamic UI generation, form rendering, and introspection in schema-driven applications.
|
|
10
|
+
*
|
|
11
|
+
* Main responsibilities:
|
|
12
|
+
* - Holds references to the collection name, field name, and the data object for context.
|
|
13
|
+
* - Provides access to the parsed field metadata (IDbForge) for the field, including type, rules, and arguments.
|
|
14
|
+
* - Offers formatting utilities for the field value, adapting to type (number, text, array, object, etc.).
|
|
15
|
+
* - Supplies input attributes and type hints for form generation (e.g., htmlInputType, inputDataSet).
|
|
16
|
+
* - Supports iteration over array/object fields for complex form layouts.
|
|
17
|
+
* - Enables extraction of raw data and field arguments for validation and UI logic.
|
|
18
|
+
*
|
|
19
|
+
* Usage:
|
|
20
|
+
* const forge = new IDbCollectionFieldForge('agents', 'name', agentData);
|
|
21
|
+
* const formatted = forge.format; // formatted value for display
|
|
22
|
+
* const inputType = forge.htmlInputType; // e.g. 'text', 'area', 'email', etc.
|
|
23
|
+
* const meta = forge.forge; // IDbForge metadata for the field
|
|
24
|
+
*
|
|
25
|
+
* This class is typically used via IDbBase.getCollectionFieldForge for shared instance management.
|
|
26
|
+
*/
|
|
27
|
+
export declare class IDbCollectionFieldForge<T extends Record<string, any>> {
|
|
28
|
+
#private;
|
|
29
|
+
constructor(collection: TplCollectionName, fieldName: any, data: T, collectionValues?: IDbCollectionValues<T>);
|
|
30
|
+
get format(): string;
|
|
31
|
+
get inputDataSet(): Record<"data-fieldArgs" | "data-fieldType" | "data-fieldName" | "data-collection" | "data-collectionId", string>;
|
|
32
|
+
get forge(): IDbForge | undefined;
|
|
33
|
+
get fieldArgs(): IDbForgeArgs | undefined;
|
|
34
|
+
get fieldType(): IDbFieldType | undefined;
|
|
35
|
+
/**
|
|
36
|
+
* will return text.inputBase for ['url', 'email', 'number', 'date', 'time', 'datetime', 'phone', 'password']
|
|
37
|
+
*/
|
|
38
|
+
get htmlInputType(): string | 'text' | 'area';
|
|
39
|
+
get rawData(): T;
|
|
40
|
+
iterateArray(fieldName: string, data: any[]): IDbForge[];
|
|
41
|
+
iterateObject(fieldName: string, data: Record<string, any>): IDbForge[];
|
|
42
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { IDbCollectionValues } from './IDbCollectionValues.js';
|
|
2
|
+
/**
|
|
3
|
+
* IDbCollectionFieldForge
|
|
4
|
+
*
|
|
5
|
+
* This class provides advanced metadata and formatting for a single field of a collection, given a data object.
|
|
6
|
+
* It is designed for dynamic UI generation, form rendering, and introspection in schema-driven applications.
|
|
7
|
+
*
|
|
8
|
+
* Main responsibilities:
|
|
9
|
+
* - Holds references to the collection name, field name, and the data object for context.
|
|
10
|
+
* - Provides access to the parsed field metadata (IDbForge) for the field, including type, rules, and arguments.
|
|
11
|
+
* - Offers formatting utilities for the field value, adapting to type (number, text, array, object, etc.).
|
|
12
|
+
* - Supplies input attributes and type hints for form generation (e.g., htmlInputType, inputDataSet).
|
|
13
|
+
* - Supports iteration over array/object fields for complex form layouts.
|
|
14
|
+
* - Enables extraction of raw data and field arguments for validation and UI logic.
|
|
15
|
+
*
|
|
16
|
+
* Usage:
|
|
17
|
+
* const forge = new IDbCollectionFieldForge('agents', 'name', agentData);
|
|
18
|
+
* const formatted = forge.format; // formatted value for display
|
|
19
|
+
* const inputType = forge.htmlInputType; // e.g. 'text', 'area', 'email', etc.
|
|
20
|
+
* const meta = forge.forge; // IDbForge metadata for the field
|
|
21
|
+
*
|
|
22
|
+
* This class is typically used via IDbBase.getCollectionFieldForge for shared instance management.
|
|
23
|
+
*/
|
|
24
|
+
export class IDbCollectionFieldForge {
|
|
25
|
+
#collection;
|
|
26
|
+
#collectionValues;
|
|
27
|
+
#fieldName;
|
|
28
|
+
#data;
|
|
29
|
+
constructor(collection, fieldName, data, collectionValues) {
|
|
30
|
+
this.#collection = collection;
|
|
31
|
+
this.#collectionValues = collectionValues ?? new IDbCollectionValues(collection);
|
|
32
|
+
this.#fieldName = String(fieldName);
|
|
33
|
+
this.#data = data;
|
|
34
|
+
}
|
|
35
|
+
get format() {
|
|
36
|
+
return this.#collectionValues.format(String(this.#fieldName), this.#data);
|
|
37
|
+
}
|
|
38
|
+
get inputDataSet() {
|
|
39
|
+
return this.#collectionValues.getInputDataSet(String(this.#fieldName), this.#data);
|
|
40
|
+
}
|
|
41
|
+
// renamed from parseCollectionFieldName
|
|
42
|
+
get forge() {
|
|
43
|
+
return this.#collectionValues.idbBase.parseCollectionFieldName(this.#collection, String(this.#fieldName));
|
|
44
|
+
}
|
|
45
|
+
get fieldArgs() {
|
|
46
|
+
return this.forge?.fieldArgs;
|
|
47
|
+
}
|
|
48
|
+
get fieldType() {
|
|
49
|
+
return this.forge?.fieldType;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* will return text.inputBase for ['url', 'email', 'number', 'date', 'time', 'datetime', 'phone', 'password']
|
|
53
|
+
*/
|
|
54
|
+
get htmlInputType() {
|
|
55
|
+
let variant = this?.fieldType?.split('text-')?.[1] ?? this.fieldType;
|
|
56
|
+
if (variant === 'area')
|
|
57
|
+
return variant;
|
|
58
|
+
if (this.forge?.fieldType?.startsWith('text-'))
|
|
59
|
+
return 'text';
|
|
60
|
+
if (['url', 'email', 'number', 'date', 'time', 'datetime', 'phone', 'password'].includes(this.forge?.fieldType ?? '')) {
|
|
61
|
+
return this.forge?.fieldType?.trim?.() ?? 'text';
|
|
62
|
+
}
|
|
63
|
+
return 'text';
|
|
64
|
+
}
|
|
65
|
+
get rawData() {
|
|
66
|
+
return this.#data;
|
|
67
|
+
}
|
|
68
|
+
iterateArray(fieldName, data) {
|
|
69
|
+
return this.#collectionValues.iterateArrayField(fieldName, data);
|
|
70
|
+
}
|
|
71
|
+
iterateObject(fieldName, data) {
|
|
72
|
+
return this.#collectionValues.iterateObjectField(fieldName, data);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { TplCollectionName } from '@medyll/idae-idbql';
|
|
2
|
+
import { IDbCollectionValues } from './IDbCollectionValues.js';
|
|
3
|
+
import type { IDbForge } from '../machineForge.js';
|
|
4
|
+
/**
|
|
5
|
+
* IDbCollectionFieldValues
|
|
6
|
+
*
|
|
7
|
+
* Provides utilities to introspect and format field values for a given collection and data object.
|
|
8
|
+
*
|
|
9
|
+
* Main responsibilities:
|
|
10
|
+
* - Holds references to the collection, data, and collection values instance.
|
|
11
|
+
* - Provides methods to get field metadata, format values, and generate input attributes.
|
|
12
|
+
* - Supports iteration over array and object fields for advanced UI layouts.
|
|
13
|
+
*
|
|
14
|
+
* Usage:
|
|
15
|
+
* const fieldValues = new IDbCollectionFieldValues('agents', agentData);
|
|
16
|
+
* const forge = fieldValues.getForge('name');
|
|
17
|
+
* const formatted = fieldValues.format('name');
|
|
18
|
+
*
|
|
19
|
+
* @template T - The type of the data object for the collection.
|
|
20
|
+
*/
|
|
21
|
+
export declare class IDbCollectionFieldValues<T extends Record<string, any>> {
|
|
22
|
+
#private;
|
|
23
|
+
/**
|
|
24
|
+
* Returns the IDbForge metadata for a given field name.
|
|
25
|
+
* @param fieldName The field name to introspect.
|
|
26
|
+
*/
|
|
27
|
+
getForge(fieldName: keyof T): IDbForge | undefined;
|
|
28
|
+
/**
|
|
29
|
+
* Create a new IDbCollectionFieldValues instance.
|
|
30
|
+
* @param collection The collection name.
|
|
31
|
+
* @param data The data object.
|
|
32
|
+
* @param collectionValues Optional IDbCollectionValues instance.
|
|
33
|
+
*/
|
|
34
|
+
constructor(collection: TplCollectionName, data: T, collectionValues?: IDbCollectionValues<T>);
|
|
35
|
+
/**
|
|
36
|
+
* Format the value of a field, handling arrays and objects.
|
|
37
|
+
* @param fieldName The field name.
|
|
38
|
+
*/
|
|
39
|
+
format(fieldName: keyof T): string | string[];
|
|
40
|
+
/**
|
|
41
|
+
* Get input attributes for a field.
|
|
42
|
+
* @param fieldName The field name.
|
|
43
|
+
*/
|
|
44
|
+
getInputDataSet(fieldName: keyof T): Record<"data-fieldArgs" | "data-fieldType" | "data-fieldName" | "data-collection" | "data-collectionId", string>;
|
|
45
|
+
/**
|
|
46
|
+
* Iterate over an array field and return field metadata for each item.
|
|
47
|
+
* @param fieldName The field name.
|
|
48
|
+
* @param data The array data.
|
|
49
|
+
*/
|
|
50
|
+
iterateArray(fieldName: string, data: any[]): IDbForge[];
|
|
51
|
+
/**
|
|
52
|
+
* Iterate over an object field and return field metadata for each property.
|
|
53
|
+
* @param fieldName The field name.
|
|
54
|
+
* @param data The object data.
|
|
55
|
+
*/
|
|
56
|
+
iterateObject(fieldName: string, data: Record<string, any>): IDbForge[];
|
|
57
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { IDbCollectionValues } from './IDbCollectionValues.js';
|
|
2
|
+
/**
|
|
3
|
+
* IDbCollectionFieldValues
|
|
4
|
+
*
|
|
5
|
+
* Provides utilities to introspect and format field values for a given collection and data object.
|
|
6
|
+
*
|
|
7
|
+
* Main responsibilities:
|
|
8
|
+
* - Holds references to the collection, data, and collection values instance.
|
|
9
|
+
* - Provides methods to get field metadata, format values, and generate input attributes.
|
|
10
|
+
* - Supports iteration over array and object fields for advanced UI layouts.
|
|
11
|
+
*
|
|
12
|
+
* Usage:
|
|
13
|
+
* const fieldValues = new IDbCollectionFieldValues('agents', agentData);
|
|
14
|
+
* const forge = fieldValues.getForge('name');
|
|
15
|
+
* const formatted = fieldValues.format('name');
|
|
16
|
+
*
|
|
17
|
+
* @template T - The type of the data object for the collection.
|
|
18
|
+
*/
|
|
19
|
+
export class IDbCollectionFieldValues {
|
|
20
|
+
#collection;
|
|
21
|
+
#collectionValues;
|
|
22
|
+
#data;
|
|
23
|
+
/**
|
|
24
|
+
* Returns the IDbForge metadata for a given field name.
|
|
25
|
+
* @param fieldName The field name to introspect.
|
|
26
|
+
*/
|
|
27
|
+
getForge(fieldName) {
|
|
28
|
+
return this.#collectionValues.idbBase.parseCollectionFieldName(this.#collection, String(fieldName));
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Create a new IDbCollectionFieldValues instance.
|
|
32
|
+
* @param collection The collection name.
|
|
33
|
+
* @param data The data object.
|
|
34
|
+
* @param collectionValues Optional IDbCollectionValues instance.
|
|
35
|
+
*/
|
|
36
|
+
constructor(collection, data, collectionValues) {
|
|
37
|
+
this.#collection = collection;
|
|
38
|
+
this.#collectionValues = collectionValues ?? new IDbCollectionValues(collection);
|
|
39
|
+
this.#data = data;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Format the value of a field, handling arrays and objects.
|
|
43
|
+
* @param fieldName The field name.
|
|
44
|
+
*/
|
|
45
|
+
format(fieldName) {
|
|
46
|
+
const fieldInfo = this.#collectionValues.idbBase.parseCollectionFieldName(this.#collection, fieldName);
|
|
47
|
+
if (fieldInfo?.is === 'array') {
|
|
48
|
+
return this.iterateArray(String(fieldName), this.#data);
|
|
49
|
+
}
|
|
50
|
+
if (fieldInfo?.is === 'object') {
|
|
51
|
+
return this.iterateObject(String(fieldName), this.#data);
|
|
52
|
+
}
|
|
53
|
+
return this.#collectionValues.format(fieldName, this.#data);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Get input attributes for a field.
|
|
57
|
+
* @param fieldName The field name.
|
|
58
|
+
*/
|
|
59
|
+
getInputDataSet(fieldName) {
|
|
60
|
+
return this.#collectionValues.getInputDataSet(String(fieldName), this.#data);
|
|
61
|
+
}
|
|
62
|
+
// renamed from parseCollectionFieldName
|
|
63
|
+
// get forge(): IDbForge | undefined {
|
|
64
|
+
// return undefined; // Pas de #fieldName dans cette classe, getter non pertinent
|
|
65
|
+
// }
|
|
66
|
+
/**
|
|
67
|
+
* Iterate over an array field and return field metadata for each item.
|
|
68
|
+
* @param fieldName The field name.
|
|
69
|
+
* @param data The array data.
|
|
70
|
+
*/
|
|
71
|
+
iterateArray(fieldName, data) {
|
|
72
|
+
return this.#collectionValues.iterateArrayField(fieldName, data);
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Iterate over an object field and return field metadata for each property.
|
|
76
|
+
* @param fieldName The field name.
|
|
77
|
+
* @param data The object data.
|
|
78
|
+
*/
|
|
79
|
+
iterateObject(fieldName, data) {
|
|
80
|
+
return this.#collectionValues.iterateObjectField(fieldName, data);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import type { TplCollectionName, TplFields } from '@medyll/idae-idbql';
|
|
2
|
+
import { MachineDb } from '../machineDb.js';
|
|
3
|
+
import { type IDbForge } from '../machineForge.js';
|
|
4
|
+
/**
|
|
5
|
+
* IDbCollectionValues
|
|
6
|
+
*
|
|
7
|
+
* This class provides utilities to display, format, and introspect field values for a given collection, using the schema and provided data.
|
|
8
|
+
* It is designed for dynamic UI rendering, presentation logic, and metadata extraction for form generation in schema-driven applications.
|
|
9
|
+
*
|
|
10
|
+
* Main responsibilities:
|
|
11
|
+
* - Holds a reference to the collection name and the schema (IDbBase).
|
|
12
|
+
* - Provides methods to format field values according to their type (number, text, array, object, etc.).
|
|
13
|
+
* - Supplies presentation logic for displaying records (e.g., presentation string, index value).
|
|
14
|
+
* - Offers input attribute generation for forms (inputDataSet).
|
|
15
|
+
* - Supports iteration over array/object fields for advanced UI layouts.
|
|
16
|
+
* - Enables access to field metadata for validation and rendering.
|
|
17
|
+
*
|
|
18
|
+
* Usage:
|
|
19
|
+
* const values = new IDbCollectionValues('agents');
|
|
20
|
+
* const display = values.presentation(agentData); // formatted display string
|
|
21
|
+
* const index = values.indexValue(agentData); // index field value
|
|
22
|
+
* const formatted = values.format('name', agentData); // formatted field value
|
|
23
|
+
* const attrs = values.getInputDataSet('name', agentData); // input attributes for forms
|
|
24
|
+
*
|
|
25
|
+
* This class is typically used via IDbBase.getCollectionValues for shared instance management.
|
|
26
|
+
* @template T - The type of the data object for the collection.
|
|
27
|
+
*/
|
|
28
|
+
export declare class IDbCollectionValues<T extends Record<string, any>> {
|
|
29
|
+
#private;
|
|
30
|
+
/**
|
|
31
|
+
* The IDbBase instance used for schema introspection.
|
|
32
|
+
*/
|
|
33
|
+
idbBase: MachineDb;
|
|
34
|
+
/**
|
|
35
|
+
* The collection name this instance operates on.
|
|
36
|
+
*/
|
|
37
|
+
private collectionName;
|
|
38
|
+
/**
|
|
39
|
+
* Create a new IDbCollectionValues instance for a given collection.
|
|
40
|
+
* @param collectionName The collection name.
|
|
41
|
+
*/
|
|
42
|
+
constructor(collectionName: TplCollectionName, idbBase?: MachineDb);
|
|
43
|
+
presentation(data: Record<string, any>): string;
|
|
44
|
+
/**
|
|
45
|
+
* Get the value of the index field for a data object.
|
|
46
|
+
* @param data The data object.
|
|
47
|
+
* @returns The value of the index field, or null if not found.
|
|
48
|
+
*/
|
|
49
|
+
indexValue(data: Record<string, any>): any | null;
|
|
50
|
+
/**
|
|
51
|
+
* Format a field value for display, using the field type and schema.
|
|
52
|
+
* @param fieldName The field name.
|
|
53
|
+
* @param data The data object.
|
|
54
|
+
* @returns The formatted value as a string.
|
|
55
|
+
*/
|
|
56
|
+
format(fieldName: keyof T, data: T): string;
|
|
57
|
+
/**
|
|
58
|
+
* Get a set of data-* attributes for a field, for use in form generation or UI.
|
|
59
|
+
* @param fieldName The field name.
|
|
60
|
+
* @param data The data object.
|
|
61
|
+
* @returns An object with data-* attributes for the field.
|
|
62
|
+
*/
|
|
63
|
+
getInputDataSet(fieldName: string, data: T): Record<`data-${'collection' | 'collectionId' | 'fieldName' | 'fieldType' | 'fieldArgs'}`, string>;
|
|
64
|
+
/**
|
|
65
|
+
* Iterate over an array field and return an array of IDbForge objects for each element.
|
|
66
|
+
* @param fieldName The field name.
|
|
67
|
+
* @param data The array data.
|
|
68
|
+
* @returns An array of IDbForge objects.
|
|
69
|
+
*/
|
|
70
|
+
iterateArrayField(fieldName: keyof TplFields, data: any[]): IDbForge[];
|
|
71
|
+
/**
|
|
72
|
+
* Iterate over an object field and return an array of IDbForge objects for each property.
|
|
73
|
+
* @param fieldName The field name.
|
|
74
|
+
* @param data The object data.
|
|
75
|
+
* @returns An array of IDbForge objects.
|
|
76
|
+
*/
|
|
77
|
+
iterateObjectField(fieldName: keyof TplFields, data: Record<string, unknown>): IDbForge[];
|
|
78
|
+
}
|