@medyll/idae-machine 0.128.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 +20 -28
- package/dist/index.js +20 -28
- 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 -71
- package/dist/main/machine/IDbCollection.js +0 -102
- 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 -57
- package/dist/main/machine/IDbCollectionFieldValues.js +0 -82
- 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
|
@@ -1,78 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
renamed from DbCollectionError to IDbErrors
|
|
3
|
-
*/
|
|
4
|
-
export class IDbError extends Error {
|
|
5
|
-
code;
|
|
6
|
-
constructor(message, code) {
|
|
7
|
-
super(message);
|
|
8
|
-
this.code = code;
|
|
9
|
-
this.name = 'DbCollectionError';
|
|
10
|
-
}
|
|
11
|
-
static throwError(message, code) {
|
|
12
|
-
throw new IDbError(message, code);
|
|
13
|
-
}
|
|
14
|
-
static handleError(error) {
|
|
15
|
-
if (error instanceof IDbError) {
|
|
16
|
-
console.error(`${error.name}: ${error.message} (Code: ${error.code})`);
|
|
17
|
-
/**
|
|
18
|
-
* IDbError
|
|
19
|
-
*
|
|
20
|
-
* Custom error class for collection-related errors.
|
|
21
|
-
*
|
|
22
|
-
* Usage:
|
|
23
|
-
* throw new IDbError('Message', 'ERROR_CODE');
|
|
24
|
-
* IDbError.handleError(error);
|
|
25
|
-
*/
|
|
26
|
-
export class IDbError extends Error {
|
|
27
|
-
code;
|
|
28
|
-
/**
|
|
29
|
-
* Create a new IDbError instance.
|
|
30
|
-
* @param message The error message.
|
|
31
|
-
* @param code The error code.
|
|
32
|
-
*/
|
|
33
|
-
constructor(message, code) {
|
|
34
|
-
super(message);
|
|
35
|
-
this.code = code;
|
|
36
|
-
this.name = 'DbCollectionError';
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Throw a new IDbError.
|
|
40
|
-
* @param message The error message.
|
|
41
|
-
* @param code The error code.
|
|
42
|
-
*/
|
|
43
|
-
static throwError(message, code) {
|
|
44
|
-
throw new IDbError(message, code);
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Handle an error, logging details if it's an IDbError.
|
|
48
|
-
* @param error The error to handle.
|
|
49
|
-
*/
|
|
50
|
-
static handleError(error) {
|
|
51
|
-
if (error instanceof IDbError) {
|
|
52
|
-
console.error(`${error.name}: ${error.message} (Code: ${error.code})`);
|
|
53
|
-
}
|
|
54
|
-
else {
|
|
55
|
-
console.error('Unexpected error:', error);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import type { TplCollectionName, TplFields } from '@medyll/idae-idbql';
|
|
2
|
-
import { MachineDb } from '../machineDb.js';
|
|
3
|
-
/**
|
|
4
|
-
* IDbFormValidate
|
|
5
|
-
*
|
|
6
|
-
* Provides validation utilities for form fields in a collection.
|
|
7
|
-
*
|
|
8
|
-
* Main responsibilities:
|
|
9
|
-
* - Holds a reference to the collection and schema.
|
|
10
|
-
* - Validates field values according to type and arguments.
|
|
11
|
-
* - Supports custom validation for email, URL, phone, and date/time fields.
|
|
12
|
-
*
|
|
13
|
-
* Usage:
|
|
14
|
-
* const validator = new IDbFormValidate('agents');
|
|
15
|
-
* const result = validator.validateField('email', value);
|
|
16
|
-
*/
|
|
17
|
-
export declare class IDbFormValidate {
|
|
18
|
-
#private;
|
|
19
|
-
private collection;
|
|
20
|
-
private idbCollections;
|
|
21
|
-
/**
|
|
22
|
-
* Create a new IDbFormValidate instance.
|
|
23
|
-
* @param collection The collection name.
|
|
24
|
-
* @param idbCollections Optional MachineDb instance.
|
|
25
|
-
*/
|
|
26
|
-
constructor(collection: TplCollectionName, idbCollections?: MachineDb);
|
|
27
|
-
/**
|
|
28
|
-
* Validate a field value for the collection.
|
|
29
|
-
* @param fieldName The field name.
|
|
30
|
-
* @param value The value to validate.
|
|
31
|
-
* @returns An object with isValid and optional error.
|
|
32
|
-
*/
|
|
33
|
-
validateField(fieldName: keyof TplFields, value: any): {
|
|
34
|
-
isValid: boolean;
|
|
35
|
-
error?: string;
|
|
36
|
-
};
|
|
37
|
-
/**
|
|
38
|
-
* Validate a single field value for a collection.
|
|
39
|
-
* @param fieldName The field name.
|
|
40
|
-
* @param value The value to validate.
|
|
41
|
-
* @returns True if valid, false otherwise.
|
|
42
|
-
*/
|
|
43
|
-
validateFieldValue(fieldName: keyof TplFields, value: any): boolean;
|
|
44
|
-
validateForm(formData: Record<string, any>, options?: {
|
|
45
|
-
ignoreFields?: string[] | undefined;
|
|
46
|
-
}): {
|
|
47
|
-
isValid: boolean;
|
|
48
|
-
errors: Record<string, string>;
|
|
49
|
-
invalidFields: string[];
|
|
50
|
-
};
|
|
51
|
-
private validateEmail;
|
|
52
|
-
private validateUrl;
|
|
53
|
-
private validatePhone;
|
|
54
|
-
private validateDateTime;
|
|
55
|
-
}
|
|
@@ -1,183 +0,0 @@
|
|
|
1
|
-
import { MachineDb, enumPrimitive } from '../machineDb.js';
|
|
2
|
-
import { IDbValidationError } from './IDbValidationError.js';
|
|
3
|
-
/**
|
|
4
|
-
* IDbFormValidate
|
|
5
|
-
*
|
|
6
|
-
* Provides validation utilities for form fields in a collection.
|
|
7
|
-
*
|
|
8
|
-
* Main responsibilities:
|
|
9
|
-
* - Holds a reference to the collection and schema.
|
|
10
|
-
* - Validates field values according to type and arguments.
|
|
11
|
-
* - Supports custom validation for email, URL, phone, and date/time fields.
|
|
12
|
-
*
|
|
13
|
-
* Usage:
|
|
14
|
-
* const validator = new IDbFormValidate('agents');
|
|
15
|
-
* const result = validator.validateField('email', value);
|
|
16
|
-
*/
|
|
17
|
-
export class IDbFormValidate {
|
|
18
|
-
collection;
|
|
19
|
-
idbCollections;
|
|
20
|
-
/**
|
|
21
|
-
* Create a new IDbFormValidate instance.
|
|
22
|
-
* @param collection The collection name.
|
|
23
|
-
* @param idbCollections Optional MachineDb instance.
|
|
24
|
-
*/
|
|
25
|
-
constructor(collection, idbCollections) {
|
|
26
|
-
this.collection = collection;
|
|
27
|
-
this.idbCollections = idbCollections ?? new MachineDb();
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Validate a field value for the collection.
|
|
31
|
-
* @param fieldName The field name.
|
|
32
|
-
* @param value The value to validate.
|
|
33
|
-
* @returns An object with isValid and optional error.
|
|
34
|
-
*/
|
|
35
|
-
validateField(fieldName, value) {
|
|
36
|
-
try {
|
|
37
|
-
const fieldInfo = this.idbCollections.parseCollectionFieldName(this.collection, fieldName);
|
|
38
|
-
if (!fieldInfo) {
|
|
39
|
-
return { isValid: false, error: `Field ${String(fieldName)} not found in collection` };
|
|
40
|
-
}
|
|
41
|
-
// Type checking
|
|
42
|
-
if (!this.#validateType(value, fieldInfo.fieldType)) {
|
|
43
|
-
return this.#returnError(fieldName, fieldInfo.fieldType);
|
|
44
|
-
}
|
|
45
|
-
// Check field arguments (required, etc.)
|
|
46
|
-
if (fieldInfo.fieldArgs) {
|
|
47
|
-
for (const arg of fieldInfo.fieldArgs) {
|
|
48
|
-
if (arg === 'required' && (value === undefined || value === null || value === '')) {
|
|
49
|
-
return this.#returnError(fieldName, 'required');
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
// Specific validations according to field type
|
|
54
|
-
switch (fieldInfo.fieldType) {
|
|
55
|
-
case enumPrimitive.email:
|
|
56
|
-
if (!this.validateEmail(value)) {
|
|
57
|
-
return this.#returnError(fieldName, fieldInfo.fieldType);
|
|
58
|
-
}
|
|
59
|
-
break;
|
|
60
|
-
case enumPrimitive.url:
|
|
61
|
-
if (!this.validateUrl(value)) {
|
|
62
|
-
return this.#returnError(fieldName, fieldInfo.fieldType);
|
|
63
|
-
}
|
|
64
|
-
break;
|
|
65
|
-
case enumPrimitive.phone:
|
|
66
|
-
if (!this.validatePhone(value)) {
|
|
67
|
-
return this.#returnError(fieldName, fieldInfo.fieldType);
|
|
68
|
-
}
|
|
69
|
-
break;
|
|
70
|
-
case enumPrimitive.date:
|
|
71
|
-
case enumPrimitive.datetime:
|
|
72
|
-
case enumPrimitive.time:
|
|
73
|
-
if (!this.validateDateTime(value, fieldInfo.fieldType)) {
|
|
74
|
-
return this.#returnError(fieldName, fieldInfo.fieldType);
|
|
75
|
-
}
|
|
76
|
-
break;
|
|
77
|
-
// Add other specific cases here
|
|
78
|
-
}
|
|
79
|
-
return { isValid: true };
|
|
80
|
-
}
|
|
81
|
-
catch (error) {
|
|
82
|
-
if (error instanceof IDbValidationError) {
|
|
83
|
-
return { isValid: false, error: error.message };
|
|
84
|
-
}
|
|
85
|
-
throw error;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* Validate a single field value for a collection.
|
|
90
|
-
* @param fieldName The field name.
|
|
91
|
-
* @param value The value to validate.
|
|
92
|
-
* @returns True if valid, false otherwise.
|
|
93
|
-
*/
|
|
94
|
-
validateFieldValue(fieldName, value) {
|
|
95
|
-
const result = this.validateField(fieldName, value);
|
|
96
|
-
return !!result.isValid;
|
|
97
|
-
}
|
|
98
|
-
validateForm(formData, options = {}) {
|
|
99
|
-
const errors = {};
|
|
100
|
-
const invalidFields = [];
|
|
101
|
-
let isValid = true;
|
|
102
|
-
const fields = this.idbCollections.collection(this.collection).getTemplate().fields;
|
|
103
|
-
if (!fields) {
|
|
104
|
-
return {
|
|
105
|
-
isValid: false,
|
|
106
|
-
errors: { general: 'Collection template not found' },
|
|
107
|
-
invalidFields: ['general']
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
for (const [fieldName, fieldRule] of Object.entries(fields)) {
|
|
111
|
-
// Ignorer les champs spécifiés dans options.ignoreFields
|
|
112
|
-
if (options.ignoreFields && options.ignoreFields.includes(fieldName)) {
|
|
113
|
-
continue;
|
|
114
|
-
}
|
|
115
|
-
const result = this.validateField(fieldName, formData[fieldName]);
|
|
116
|
-
if (!result.isValid) {
|
|
117
|
-
errors[fieldName] = result.error || 'Invalid field';
|
|
118
|
-
invalidFields.push(fieldName);
|
|
119
|
-
isValid = false;
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
return { isValid, errors, invalidFields };
|
|
123
|
-
}
|
|
124
|
-
#validateType(value, type) {
|
|
125
|
-
switch (type) {
|
|
126
|
-
case enumPrimitive.number:
|
|
127
|
-
return typeof value === 'number' && !isNaN(value);
|
|
128
|
-
case enumPrimitive.boolean:
|
|
129
|
-
return typeof value === 'boolean';
|
|
130
|
-
case enumPrimitive.text:
|
|
131
|
-
case enumPrimitive.email:
|
|
132
|
-
case enumPrimitive.url:
|
|
133
|
-
case enumPrimitive.phone:
|
|
134
|
-
case enumPrimitive.password:
|
|
135
|
-
return typeof value === 'string';
|
|
136
|
-
case enumPrimitive.date:
|
|
137
|
-
case enumPrimitive.datetime:
|
|
138
|
-
case enumPrimitive.time:
|
|
139
|
-
return value instanceof Date || typeof value === 'string';
|
|
140
|
-
case enumPrimitive.any:
|
|
141
|
-
return true;
|
|
142
|
-
default:
|
|
143
|
-
return true; // Pour les types non gérés, on considère que c'est valide
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
#returnError(fieldName, enumCode) {
|
|
147
|
-
throw new IDbValidationError(String(fieldName), enumCode ?? 'unknown', `Invalid format for field ${String(fieldName)}. Cause "${enumCode}" `);
|
|
148
|
-
}
|
|
149
|
-
validateEmail(email) {
|
|
150
|
-
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
151
|
-
return emailRegex.test(email);
|
|
152
|
-
}
|
|
153
|
-
validateUrl(url) {
|
|
154
|
-
try {
|
|
155
|
-
new URL(url);
|
|
156
|
-
return true;
|
|
157
|
-
}
|
|
158
|
-
catch {
|
|
159
|
-
return false;
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
validatePhone(phone) {
|
|
163
|
-
// Ceci est un exemple simple. Vous pouvez ajuster selon vos besoins spécifiques
|
|
164
|
-
const phoneRegex = /^\+?[\d\s-]{10,}$/;
|
|
165
|
-
return phoneRegex.test(phone);
|
|
166
|
-
}
|
|
167
|
-
validateDateTime(value, type) {
|
|
168
|
-
const date = value instanceof Date ? value : new Date(value);
|
|
169
|
-
if (isNaN(date.getTime()))
|
|
170
|
-
return false;
|
|
171
|
-
switch (type) {
|
|
172
|
-
case enumPrimitive.date:
|
|
173
|
-
return true; // La conversion en Date a déjà validé le format
|
|
174
|
-
case enumPrimitive.time:
|
|
175
|
-
// Vérifiez si la chaîne contient uniquement l'heure
|
|
176
|
-
return /^([01]\d|2[0-3]):([0-5]\d)(:([0-5]\d))?$/.test(value);
|
|
177
|
-
case enumPrimitive.datetime:
|
|
178
|
-
return true; // La conversion en Date a déjà validé le format
|
|
179
|
-
default:
|
|
180
|
-
return false;
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* IDbValidationError
|
|
3
|
-
*
|
|
4
|
-
* Custom error class for validation errors on form fields.
|
|
5
|
-
*
|
|
6
|
-
* Usage:
|
|
7
|
-
* throw new IDbValidationError('email', 'INVALID_EMAIL', 'Invalid email address');
|
|
8
|
-
*/
|
|
9
|
-
export declare class IDbValidationError extends Error {
|
|
10
|
-
field: string;
|
|
11
|
-
code: string;
|
|
12
|
-
/**
|
|
13
|
-
* Create a new IDbValidationError instance.
|
|
14
|
-
* @param field The field name.
|
|
15
|
-
* @param code The error code.
|
|
16
|
-
* @param message The error message.
|
|
17
|
-
*/
|
|
18
|
-
constructor(field: string, code: string, message: string);
|
|
19
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* IDbValidationError
|
|
3
|
-
*
|
|
4
|
-
* Custom error class for validation errors on form fields.
|
|
5
|
-
*
|
|
6
|
-
* Usage:
|
|
7
|
-
* throw new IDbValidationError('email', 'INVALID_EMAIL', 'Invalid email address');
|
|
8
|
-
*/
|
|
9
|
-
export class IDbValidationError extends Error {
|
|
10
|
-
field;
|
|
11
|
-
code;
|
|
12
|
-
/**
|
|
13
|
-
* Create a new IDbValidationError instance.
|
|
14
|
-
* @param field The field name.
|
|
15
|
-
* @param code The error code.
|
|
16
|
-
* @param message The error message.
|
|
17
|
-
*/
|
|
18
|
-
constructor(field, code, message) {
|
|
19
|
-
super(message);
|
|
20
|
-
this.field = field;
|
|
21
|
-
this.code = code;
|
|
22
|
-
this.name = 'IDbValidationError';
|
|
23
|
-
}
|
|
24
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
<!-- CollectionFieldGuess.svelte -->
|
|
2
|
-
<script lang="ts">
|
|
3
|
-
import { Guesser } from '../tools/Guesser ';
|
|
4
|
-
import type { TplCollectionName } from '@medyll/idae-idbql';
|
|
5
|
-
import { IconButton } from '@medyll/idae-slotui-svelte';
|
|
6
|
-
|
|
7
|
-
let { collection, collectionId, fieldName, data, onGuess } = $props<{
|
|
8
|
-
collection: TplCollectionName;
|
|
9
|
-
collectionId?: any;
|
|
10
|
-
fieldName: string;
|
|
11
|
-
data: Record<string, any>;
|
|
12
|
-
onGuess: (fieldName: string, value: string) => void;
|
|
13
|
-
}>();
|
|
14
|
-
|
|
15
|
-
const guesser = new Guesser();
|
|
16
|
-
|
|
17
|
-
async function guessValue() {
|
|
18
|
-
try {
|
|
19
|
-
const result = await guesser.guessValue({ collection, collectionId, fieldName, data });
|
|
20
|
-
console.log({ result });
|
|
21
|
-
onGuess?.(fieldName, result.guessedValue);
|
|
22
|
-
} catch (error) {
|
|
23
|
-
console.error('Erreur lors de la devinette :', error);
|
|
24
|
-
// Gérer l'erreur (par exemple, afficher un message à l'utilisateur)
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
</script>
|
|
28
|
-
|
|
29
|
-
<IconButton icon="mdi:brain" tall="tiny" class="guess-button" onclick={guessValue} />
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { TplCollectionName } from '@medyll/idae-idbql';
|
|
2
|
-
type $$ComponentProps = {
|
|
3
|
-
collection: TplCollectionName;
|
|
4
|
-
collectionId?: any;
|
|
5
|
-
fieldName: string;
|
|
6
|
-
data: Record<string, any>;
|
|
7
|
-
onGuess: (fieldName: string, value: string) => void;
|
|
8
|
-
};
|
|
9
|
-
declare const CollectionFieldGuess: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
10
|
-
type CollectionFieldGuess = ReturnType<typeof CollectionFieldGuess>;
|
|
11
|
-
export default CollectionFieldGuess;
|
|
File without changes
|
|
File without changes
|