@medyll/idae-data-tpl 0.1.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/README.md +58 -0
- package/dist/dataTemplate/dataTemplate.d.ts +70 -0
- package/dist/dataTemplate/dataTemplate.js +443 -0
- package/dist/dataTemplate/types.d.ts +74 -0
- package/dist/dataTemplate/types.js +21 -0
- package/dist/dataTemplate/validator.d.ts +33 -0
- package/dist/dataTemplate/validator.js +172 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +4 -0
- package/package.json +56 -0
package/README.md
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# create-svelte
|
|
2
|
+
|
|
3
|
+
Everything you need to build a Svelte library, powered by [`create-svelte`](https://github.com/sveltejs/kit/tree/main/packages/create-svelte).
|
|
4
|
+
|
|
5
|
+
Read more about creating a library [in the docs](https://kit.svelte.dev/docs/packaging).
|
|
6
|
+
|
|
7
|
+
## Creating a project
|
|
8
|
+
|
|
9
|
+
If you're seeing this, you've probably already done this step. Congrats!
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
# create a new project in the current directory
|
|
13
|
+
npm create svelte@latest
|
|
14
|
+
|
|
15
|
+
# create a new project in my-app
|
|
16
|
+
npm create svelte@latest my-app
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Developing
|
|
20
|
+
|
|
21
|
+
Once you've created a project and installed dependencies with `npm install` (or `pnpm install` or `yarn`), start a development server:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
npm run dev
|
|
25
|
+
|
|
26
|
+
# or start the server and open the app in a new browser tab
|
|
27
|
+
npm run dev -- --open
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Everything inside `src/lib` is part of your library, everything inside `src/routes` can be used as a showcase or preview app.
|
|
31
|
+
|
|
32
|
+
## Building
|
|
33
|
+
|
|
34
|
+
To build your library:
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
npm run package
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
To create a production version of your showcase app:
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
npm run build
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
You can preview the production build with `npm run preview`.
|
|
47
|
+
|
|
48
|
+
> To deploy your app, you may need to install an [adapter](https://kit.svelte.dev/docs/adapters) for your target environment.
|
|
49
|
+
|
|
50
|
+
## Publishing
|
|
51
|
+
|
|
52
|
+
Go into the `package.json` and give your package the desired name through the `"name"` option. Also consider adding a `"license"` field and point it to a `LICENSE` file which you can create from a template (one popular option is the [MIT license](https://opensource.org/license/mit/)).
|
|
53
|
+
|
|
54
|
+
To publish your library to [npm](https://www.npmjs.com):
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
npm publish
|
|
58
|
+
```
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import type { TplCollectionName, IdaeTemplate, IDbForgeFields, IDbFieldRules, IDbForgeArgs, IDbFieldType, IdaeModelRoot, IdaeTemplateFields, ForgeFieldTypes, CoreModel } from './types.js';
|
|
2
|
+
export declare const exampleModel: IdaeModelRoot;
|
|
3
|
+
export declare class IdaeModelCore<T = Record<string, any>> {
|
|
4
|
+
#private;
|
|
5
|
+
model: IdaeModelRoot<T>;
|
|
6
|
+
constructor();
|
|
7
|
+
setModel<C = Record<string, any>>(model: IdaeModelRoot<C>): void;
|
|
8
|
+
addCollectionTemplate(collection: string, template: IdaeTemplate): void;
|
|
9
|
+
parseAllCollections(): Record<string, Record<string, any> | undefined>;
|
|
10
|
+
parseRawCollection(collection: TplCollectionName): Record<string, IDbForgeFields | undefined> | undefined;
|
|
11
|
+
parseCollectionFieldName(collection: TplCollectionName, fieldName: keyof IdaeTemplateFields<any>): IDbForgeFields<T> | undefined;
|
|
12
|
+
parsFieldRule(fieldRule: IDbFieldRules): Partial<IDbForgeFields<T>> | undefined;
|
|
13
|
+
private forge;
|
|
14
|
+
getCollection(collection: TplCollectionName): CoreModel;
|
|
15
|
+
getCollectionTemplate(collection: TplCollectionName): IdaeTemplate;
|
|
16
|
+
getCollectionTemplateFks(collection: TplCollectionName): IdaeTemplate["fks"];
|
|
17
|
+
getIndexName(collection: string): any;
|
|
18
|
+
getCollectionTemplateFields(collection: TplCollectionName): IdaeTemplateFields;
|
|
19
|
+
getTemplatePresentation(collection: TplCollectionName): string;
|
|
20
|
+
getFkFieldType(string: `${string}.${string}`): IDbFieldRules | undefined;
|
|
21
|
+
getFkTemplateFields(string: `${string}.${string}`): any;
|
|
22
|
+
private testIs;
|
|
23
|
+
is(what: ForgeFieldTypes, fieldRule: IDbFieldRules): Partial<IDbForgeFields>;
|
|
24
|
+
indexValue(collection: TplCollectionName, data: Record<string, any>): any;
|
|
25
|
+
extract(type: ForgeFieldTypes, fieldRule: IDbFieldRules): Partial<IDbForgeFields<T>>;
|
|
26
|
+
fks(collection: string): {
|
|
27
|
+
[collection: string]: IdaeTemplate;
|
|
28
|
+
};
|
|
29
|
+
reverseFks(targetCollection: TplCollectionName): Record<string, any>;
|
|
30
|
+
iterateArrayField(collection: TplCollectionName, fieldName: string, data: T[]): IDbForgeFields<T>[];
|
|
31
|
+
iterateObjectField(collection: TplCollectionName, fieldName: keyof T, data: Record<string, any>): IDbForgeFields<T>[];
|
|
32
|
+
}
|
|
33
|
+
export declare const IdaeModel: IdaeModelCore<Record<string, any>>;
|
|
34
|
+
export declare class IDbCollectionValues<T extends Record<string, any>> {
|
|
35
|
+
#private;
|
|
36
|
+
dbCollections: IdaeModelCore;
|
|
37
|
+
private collection;
|
|
38
|
+
constructor(collection: TplCollectionName, idaeModel: IdaeModelRoot);
|
|
39
|
+
presentation(data: T): string;
|
|
40
|
+
indexValue(data: Record<string, unknown>): unknown | null;
|
|
41
|
+
format(fieldName: keyof T, data: T): string;
|
|
42
|
+
getInputDataSet(fieldName: string, data: T): Record<`data-${'collection' | 'collectionId' | 'fieldName' | 'fieldType' | 'fieldArgs'}`, string>;
|
|
43
|
+
iterateArrayField(fieldName: keyof IdaeTemplateFields, data: any[]): IDbForgeFields[];
|
|
44
|
+
iterateObjectField(fieldName: keyof IdaeTemplateFields, data: Record<string, any>): IDbForgeFields[];
|
|
45
|
+
}
|
|
46
|
+
export declare class IDbCollectionFieldValues<T extends Record<string, any>> {
|
|
47
|
+
#private;
|
|
48
|
+
constructor(collection: TplCollectionName, data: T[]);
|
|
49
|
+
format(fieldName: keyof T): string | string[];
|
|
50
|
+
getInputDataSet(fieldName: keyof T): Record<"data-collection" | "data-fieldName" | "data-fieldType" | "data-fieldArgs" | "data-collectionId", string>;
|
|
51
|
+
getForge(fieldName: keyof T): IDbForgeFields | undefined;
|
|
52
|
+
iterateArray(fieldName: string, data: any[]): IDbForgeFields[];
|
|
53
|
+
iterateObject(fieldName: string, data: Record<string, any>): IDbForgeFields[];
|
|
54
|
+
}
|
|
55
|
+
export declare class IDbCollectionFieldForge<T extends Record<string, any>> {
|
|
56
|
+
#private;
|
|
57
|
+
constructor(collection: TplCollectionName, fieldName: any, data: T);
|
|
58
|
+
get format(): string;
|
|
59
|
+
get inputDataSet(): Record<"data-collection" | "data-fieldName" | "data-fieldType" | "data-fieldArgs" | "data-collectionId", string>;
|
|
60
|
+
get forge(): IDbForgeFields<T> | undefined;
|
|
61
|
+
get fieldArgs(): IDbForgeArgs | undefined;
|
|
62
|
+
get fieldType(): IDbFieldType | undefined;
|
|
63
|
+
/**
|
|
64
|
+
* will return text.inputBase for ['url', 'email', 'number', 'date', 'time', 'datetime', 'phone', 'password']
|
|
65
|
+
*/
|
|
66
|
+
get htmlInputType(): string | 'text' | 'area';
|
|
67
|
+
get rawData(): T;
|
|
68
|
+
iterateArray(fieldName: string, data: any[]): IDbForgeFields<T>[];
|
|
69
|
+
iterateObject(fieldName: string, data: Record<string, any>): IDbForgeFields<T>[];
|
|
70
|
+
}
|
|
@@ -0,0 +1,443 @@
|
|
|
1
|
+
import { AccessProperties } from './types.js';
|
|
2
|
+
export const exampleModel = {
|
|
3
|
+
agent: {
|
|
4
|
+
template: {
|
|
5
|
+
index: 'id',
|
|
6
|
+
presentation: 'name model',
|
|
7
|
+
fields: {
|
|
8
|
+
id: 'id (readonly)',
|
|
9
|
+
name: 'text (private)',
|
|
10
|
+
code: 'text',
|
|
11
|
+
model: 'text',
|
|
12
|
+
prompt: 'text-long',
|
|
13
|
+
created_at: 'date (private)',
|
|
14
|
+
ia_lock: 'boolean (private)',
|
|
15
|
+
agentPromptId: 'fk-agentPrompt.id (required)'
|
|
16
|
+
},
|
|
17
|
+
fks: {
|
|
18
|
+
agentPrompt: {
|
|
19
|
+
code: 'agentPrompt',
|
|
20
|
+
rules: 'readonly private',
|
|
21
|
+
multiple: true
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
// renammed from IDbFields to IDbCollections to IdaeModel
|
|
28
|
+
export class IdaeModelCore {
|
|
29
|
+
model;
|
|
30
|
+
constructor() { }
|
|
31
|
+
setModel(model) {
|
|
32
|
+
this.model = model;
|
|
33
|
+
}
|
|
34
|
+
addCollectionTemplate(collection, template) {
|
|
35
|
+
this.model[collection]['template'] = template;
|
|
36
|
+
}
|
|
37
|
+
parseAllCollections() {
|
|
38
|
+
let out = {};
|
|
39
|
+
Object.keys(this.model).forEach((collection) => {
|
|
40
|
+
out[collection] = this.parseRawCollection(collection);
|
|
41
|
+
});
|
|
42
|
+
return out;
|
|
43
|
+
}
|
|
44
|
+
parseRawCollection(collection) {
|
|
45
|
+
const fields = this.getCollectionTemplateFields(collection);
|
|
46
|
+
if (!fields)
|
|
47
|
+
return;
|
|
48
|
+
let out = {};
|
|
49
|
+
Object.keys(fields).forEach((fieldName) => {
|
|
50
|
+
let fieldType = fields[fieldName];
|
|
51
|
+
if (fieldType) {
|
|
52
|
+
out[fieldName] = this.parseCollectionFieldName(collection, fieldName);
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
return out;
|
|
56
|
+
}
|
|
57
|
+
parseCollectionFieldName(collection, fieldName) {
|
|
58
|
+
const field = this.#getTemplateFieldRule(collection, fieldName);
|
|
59
|
+
if (!field) {
|
|
60
|
+
IDbError.throwError(`Field ${fieldName} not found in collection ${collection}`, 'FIELD_NOT_FOUND');
|
|
61
|
+
return undefined;
|
|
62
|
+
}
|
|
63
|
+
const fieldType = this.testIs('primitive', field) ??
|
|
64
|
+
this.testIs('array', field) ??
|
|
65
|
+
this.testIs('object', field) ??
|
|
66
|
+
this.testIs('fk', field);
|
|
67
|
+
return this.forge({ collection, fieldName, ...fieldType });
|
|
68
|
+
}
|
|
69
|
+
parsFieldRule(fieldRule) {
|
|
70
|
+
if (!fieldRule)
|
|
71
|
+
return;
|
|
72
|
+
const fieldType = this.testIs('primitive', fieldRule) ??
|
|
73
|
+
this.testIs('array', fieldRule) ??
|
|
74
|
+
this.testIs('object', fieldRule) ??
|
|
75
|
+
this.testIs('fk', fieldRule);
|
|
76
|
+
return fieldType;
|
|
77
|
+
}
|
|
78
|
+
forge({ collection, fieldName, fieldType, fieldRule, fieldArgs, is }) {
|
|
79
|
+
return {
|
|
80
|
+
collection,
|
|
81
|
+
fieldName,
|
|
82
|
+
fieldType,
|
|
83
|
+
fieldRule,
|
|
84
|
+
fieldArgs,
|
|
85
|
+
is
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
#getModel() {
|
|
89
|
+
return this.model;
|
|
90
|
+
}
|
|
91
|
+
getCollection(collection) {
|
|
92
|
+
return this.#getModel()[String(collection)];
|
|
93
|
+
}
|
|
94
|
+
getCollectionTemplate(collection) {
|
|
95
|
+
return this.getCollection(collection)['template'];
|
|
96
|
+
}
|
|
97
|
+
getCollectionTemplateFks(collection) {
|
|
98
|
+
return this.getCollection(collection)['template']?.fks;
|
|
99
|
+
}
|
|
100
|
+
getIndexName(collection) {
|
|
101
|
+
return this.getCollection(collection)?.template?.index;
|
|
102
|
+
}
|
|
103
|
+
getCollectionTemplateFields(collection) {
|
|
104
|
+
return this.getCollectionTemplate(collection)?.fields;
|
|
105
|
+
}
|
|
106
|
+
getTemplatePresentation(collection) {
|
|
107
|
+
return this.getCollectionTemplate(collection)?.presentation;
|
|
108
|
+
}
|
|
109
|
+
#getTemplateFieldRule(collection, fieldName) {
|
|
110
|
+
return this.getCollectionTemplateFields(collection)?.[String(fieldName)];
|
|
111
|
+
}
|
|
112
|
+
getFkFieldType(string) {
|
|
113
|
+
const [collection, field] = string.split('.');
|
|
114
|
+
const template = this.#getTemplateFieldRule(collection, field);
|
|
115
|
+
return template;
|
|
116
|
+
}
|
|
117
|
+
getFkTemplateFields(string) {
|
|
118
|
+
const [collection, field] = string.split('.');
|
|
119
|
+
return this.getCollection(collection).template?.fields;
|
|
120
|
+
}
|
|
121
|
+
testIs(what, fieldRule) {
|
|
122
|
+
const typeMappings = {
|
|
123
|
+
fk: 'fk-',
|
|
124
|
+
array: 'array-of-',
|
|
125
|
+
object: 'object-',
|
|
126
|
+
primitive: ''
|
|
127
|
+
};
|
|
128
|
+
const prefix = typeMappings[what];
|
|
129
|
+
if (fieldRule.startsWith(prefix)) {
|
|
130
|
+
return this.is(what, fieldRule);
|
|
131
|
+
}
|
|
132
|
+
return undefined;
|
|
133
|
+
}
|
|
134
|
+
is(what, fieldRule) {
|
|
135
|
+
return this.extract(what, fieldRule);
|
|
136
|
+
}
|
|
137
|
+
indexValue(collection, data) {
|
|
138
|
+
const presentation = this.getIndexName(collection);
|
|
139
|
+
return data[presentation];
|
|
140
|
+
}
|
|
141
|
+
extract(type, fieldRule) {
|
|
142
|
+
// fieldType
|
|
143
|
+
function extractAfter(pattern, source) {
|
|
144
|
+
// remove all between () on source
|
|
145
|
+
const reg = source?.split('(')?.[0];
|
|
146
|
+
return reg.split(pattern)[1];
|
|
147
|
+
}
|
|
148
|
+
function extractArgs(source) {
|
|
149
|
+
const [piece, remaining] = source.split('(');
|
|
150
|
+
if (!remaining)
|
|
151
|
+
return { piece: piece.trim(), args: undefined };
|
|
152
|
+
const [central] = remaining?.split(')');
|
|
153
|
+
const args = central?.split(' ');
|
|
154
|
+
// console.log({ piece, args });
|
|
155
|
+
return { piece: piece.trim(), args };
|
|
156
|
+
}
|
|
157
|
+
const extractedArgs = extractArgs(fieldRule);
|
|
158
|
+
const fieldArgs = extractedArgs?.args;
|
|
159
|
+
let fieldType;
|
|
160
|
+
let is = extractedArgs?.piece;
|
|
161
|
+
switch (type) {
|
|
162
|
+
case 'array':
|
|
163
|
+
fieldType = extractAfter('array-of-', fieldRule);
|
|
164
|
+
is = is ?? fieldType;
|
|
165
|
+
break;
|
|
166
|
+
case 'object':
|
|
167
|
+
fieldType = extractAfter('object-', fieldRule);
|
|
168
|
+
is = is ?? fieldType;
|
|
169
|
+
break;
|
|
170
|
+
case 'fk':
|
|
171
|
+
fieldType = this.getFkFieldType(extractAfter('fk-', fieldRule));
|
|
172
|
+
is = extractedArgs?.piece;
|
|
173
|
+
break;
|
|
174
|
+
case 'primitive':
|
|
175
|
+
fieldType = extractedArgs?.piece;
|
|
176
|
+
is = is ?? fieldType;
|
|
177
|
+
break;
|
|
178
|
+
}
|
|
179
|
+
return { fieldType, fieldRule, fieldArgs, is: type };
|
|
180
|
+
}
|
|
181
|
+
fks(collection) {
|
|
182
|
+
const fks = this.getCollectionTemplateFks(collection);
|
|
183
|
+
const out = {};
|
|
184
|
+
// loop over fks
|
|
185
|
+
if (fks) {
|
|
186
|
+
Object.keys(fks).forEach((collection) => {
|
|
187
|
+
out[collection] = this.parseRawCollection(collection);
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
return out;
|
|
191
|
+
}
|
|
192
|
+
reverseFks(targetCollection) {
|
|
193
|
+
const result = {};
|
|
194
|
+
Object.entries(this.#getModel()).forEach(([collectionName, collectionModel]) => {
|
|
195
|
+
const template = collectionModel.template;
|
|
196
|
+
if (template && template.fks) {
|
|
197
|
+
Object.entries(template.fks).forEach(([fkName, fkConfig]) => {
|
|
198
|
+
if (fkConfig?.code === targetCollection) {
|
|
199
|
+
if (!result[collectionName]) {
|
|
200
|
+
result[collectionName] = {};
|
|
201
|
+
}
|
|
202
|
+
result[collectionName][fkName] = fkConfig;
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
return result;
|
|
208
|
+
}
|
|
209
|
+
// iterate base
|
|
210
|
+
iterateArrayField(collection, fieldName, data) {
|
|
211
|
+
const fieldInfo = this.parseCollectionFieldName(collection, fieldName);
|
|
212
|
+
if (fieldInfo?.is !== 'array' || !Array.isArray(data)) {
|
|
213
|
+
return [];
|
|
214
|
+
}
|
|
215
|
+
return data.map(() => this.parseCollectionFieldName(collection, fieldName)) ?? [];
|
|
216
|
+
}
|
|
217
|
+
iterateObjectField(collection, fieldName, data) {
|
|
218
|
+
const fieldInfo = this.parseCollectionFieldName(collection, fieldName);
|
|
219
|
+
if (fieldInfo?.is !== 'object' || typeof data !== 'object') {
|
|
220
|
+
return [];
|
|
221
|
+
}
|
|
222
|
+
return Object.keys(data).map((key) => this.parseCollectionFieldName(collection, key));
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
export const IdaeModel = new IdaeModelCore();
|
|
226
|
+
IdaeModel.setModel(exampleModel);
|
|
227
|
+
IdaeModel.getIndexName('users');
|
|
228
|
+
IdaeModel.is('array', 'array-of-text-long(private required)');
|
|
229
|
+
IdaeModel.reverseFks('users');
|
|
230
|
+
IdaeModel.getFkFieldType('collectio.ners');
|
|
231
|
+
// display field values, based on schema and provided data
|
|
232
|
+
// renamed from iDBFieldValues to iDbCollectionValues
|
|
233
|
+
// path D:\boulot\python\wollama\src\lib\db\dbFields.ts
|
|
234
|
+
export class IDbCollectionValues {
|
|
235
|
+
dbCollections;
|
|
236
|
+
collection;
|
|
237
|
+
constructor(collection, idaeModel) {
|
|
238
|
+
this.collection = collection;
|
|
239
|
+
this.dbCollections = new IdaeModelCore(idaeModel);
|
|
240
|
+
}
|
|
241
|
+
presentation(data) {
|
|
242
|
+
try {
|
|
243
|
+
this.#checkError(!this.#checkAccess(), 'Access denied', 'ACCESS_DENIED');
|
|
244
|
+
const presentation = this.dbCollections.getTemplatePresentation(this.collection);
|
|
245
|
+
this.#checkError(!presentation, 'Presentation template not found', 'TEMPLATE_NOT_FOUND');
|
|
246
|
+
const fields = presentation.split(' ');
|
|
247
|
+
return fields
|
|
248
|
+
.map((field) => {
|
|
249
|
+
const value = data[field];
|
|
250
|
+
return value !== null && value !== undefined ? String(value) : '';
|
|
251
|
+
})
|
|
252
|
+
.join(' ');
|
|
253
|
+
}
|
|
254
|
+
catch (error) {
|
|
255
|
+
IDbError.handleError(error);
|
|
256
|
+
return '';
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
indexValue(data) {
|
|
260
|
+
try {
|
|
261
|
+
this.#checkError(!this.#checkAccess(), 'Access denied', 'ACCESS_DENIED');
|
|
262
|
+
const indexName = this.dbCollections.getIndexName(this.collection);
|
|
263
|
+
this.#checkError(!indexName, 'Index not found for collection', 'INDEX_NOT_FOUND');
|
|
264
|
+
this.#checkError(!(indexName in data), `Index field ${indexName} not found in data`, 'FIELD_NOT_FOUND');
|
|
265
|
+
return data[indexName];
|
|
266
|
+
}
|
|
267
|
+
catch (error) {
|
|
268
|
+
IDbError.handleError(error);
|
|
269
|
+
return null;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
format(fieldName, data) {
|
|
273
|
+
try {
|
|
274
|
+
this.#checkError(!this.#checkAccess(), 'Access denied', 'ACCESS_DENIED');
|
|
275
|
+
this.#checkError(!(fieldName in data), `Field ${String(fieldName)} not found in data`, 'FIELD_NOT_FOUND');
|
|
276
|
+
const fieldInfo = this.dbCollections.parseCollectionFieldName(this.collection, fieldName);
|
|
277
|
+
this.#checkError(!fieldInfo, `Field ${String(fieldName)} not found in collection`, 'FIELD_NOT_FOUND');
|
|
278
|
+
switch (fieldInfo?.fieldType) {
|
|
279
|
+
case 'number':
|
|
280
|
+
return this.#formatNumberField(data[fieldName]);
|
|
281
|
+
case 'text':
|
|
282
|
+
case 'text-tiny':
|
|
283
|
+
case 'text-short':
|
|
284
|
+
case 'text-medium':
|
|
285
|
+
case 'text-long':
|
|
286
|
+
case 'text-giant':
|
|
287
|
+
return this.#formatTextField(data[fieldName], fieldInfo.fieldType);
|
|
288
|
+
default:
|
|
289
|
+
return String(data[fieldName]);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
catch (error) {
|
|
293
|
+
IDbError.handleError(error);
|
|
294
|
+
return '';
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
getInputDataSet(fieldName, data) {
|
|
298
|
+
const fieldInfo = this.dbCollections.parseCollectionFieldName(this.collection, fieldName);
|
|
299
|
+
const fieldType = fieldInfo?.fieldType ?? '';
|
|
300
|
+
const fieldArgs = fieldInfo?.fieldArgs?.join(' ') ?? '';
|
|
301
|
+
const indexName = this.dbCollections.getIndexName(this.collection);
|
|
302
|
+
return {
|
|
303
|
+
'data-collection': this.collection,
|
|
304
|
+
'data-collectionId': indexName && data?.[indexName] !== undefined ? String(data?.[indexName]) : '',
|
|
305
|
+
'data-fieldName': String(fieldName),
|
|
306
|
+
'data-fieldType': fieldType,
|
|
307
|
+
'data-fieldArgs': fieldArgs
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
iterateArrayField(fieldName, data) {
|
|
311
|
+
return this.dbCollections.iterateArrayField(this.collection, fieldName, data);
|
|
312
|
+
}
|
|
313
|
+
iterateObjectField(fieldName, data) {
|
|
314
|
+
return this.dbCollections.iterateObjectField(this.collection, fieldName, data);
|
|
315
|
+
}
|
|
316
|
+
#formatNumberField(value) {
|
|
317
|
+
// Implement number formatting logic here
|
|
318
|
+
return value.toString();
|
|
319
|
+
}
|
|
320
|
+
#formatTextField(value, type) {
|
|
321
|
+
const lengths = {
|
|
322
|
+
'text-tiny': 10,
|
|
323
|
+
'text-short': 20,
|
|
324
|
+
'text-medium': 30,
|
|
325
|
+
'text-long': 40,
|
|
326
|
+
'text-giant': 50
|
|
327
|
+
};
|
|
328
|
+
const maxLength = lengths[type] || value.length;
|
|
329
|
+
return value.substring(0, maxLength);
|
|
330
|
+
}
|
|
331
|
+
#checkAccess() {
|
|
332
|
+
// Implement access check logic here
|
|
333
|
+
return true;
|
|
334
|
+
}
|
|
335
|
+
#checkError(condition, message, code) {
|
|
336
|
+
if (condition) {
|
|
337
|
+
IDbError.throwError(message, code);
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
export class IDbCollectionFieldValues {
|
|
342
|
+
#collection;
|
|
343
|
+
#collectionValues;
|
|
344
|
+
#data;
|
|
345
|
+
constructor(collection, data) {
|
|
346
|
+
this.#collection = collection;
|
|
347
|
+
this.#collectionValues = new IDbCollectionValues(collection);
|
|
348
|
+
this.#data = data;
|
|
349
|
+
}
|
|
350
|
+
format(fieldName) {
|
|
351
|
+
const fieldInfo = this.#collectionValues.dbCollections.parseCollectionFieldName(this.#collection, fieldName);
|
|
352
|
+
if (fieldInfo?.is === 'array') {
|
|
353
|
+
return this.iterateArray(String(fieldName), this.#data);
|
|
354
|
+
}
|
|
355
|
+
if (fieldInfo?.is === 'object') {
|
|
356
|
+
return this.iterateObject(String(fieldName), this.#data);
|
|
357
|
+
}
|
|
358
|
+
return this.#collectionValues.format(fieldName, this.#data);
|
|
359
|
+
}
|
|
360
|
+
getInputDataSet(fieldName) {
|
|
361
|
+
return this.#collectionValues.getInputDataSet(String(fieldName), this.#data);
|
|
362
|
+
}
|
|
363
|
+
// renamed from parseCollectionFieldName
|
|
364
|
+
getForge(fieldName) {
|
|
365
|
+
return this.#collectionValues.dbCollections.parseCollectionFieldName(this.#collection, String(fieldName));
|
|
366
|
+
}
|
|
367
|
+
iterateArray(fieldName, data) {
|
|
368
|
+
return this.#collectionValues.iterateArrayField(fieldName, data);
|
|
369
|
+
}
|
|
370
|
+
iterateObject(fieldName, data) {
|
|
371
|
+
return this.#collectionValues.iterateObjectField(fieldName, data);
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
export class IDbCollectionFieldForge {
|
|
375
|
+
#collection;
|
|
376
|
+
#collectionValues;
|
|
377
|
+
#fieldName;
|
|
378
|
+
#data;
|
|
379
|
+
constructor(collection, fieldName, data) {
|
|
380
|
+
this.#collection = collection;
|
|
381
|
+
this.#collectionValues = new IDbCollectionValues(collection);
|
|
382
|
+
this.#fieldName = String(fieldName);
|
|
383
|
+
this.#data = data;
|
|
384
|
+
}
|
|
385
|
+
get format() {
|
|
386
|
+
return this.#collectionValues.format(String(this.#fieldName), this.#data);
|
|
387
|
+
}
|
|
388
|
+
get inputDataSet() {
|
|
389
|
+
return this.#collectionValues.getInputDataSet(String(this.#fieldName), this.#data);
|
|
390
|
+
}
|
|
391
|
+
// renamed from parseCollectionFieldName
|
|
392
|
+
get forge() {
|
|
393
|
+
return this.#collectionValues.dbCollections.parseCollectionFieldName(this.#collection, String(this.#fieldName));
|
|
394
|
+
}
|
|
395
|
+
get fieldArgs() {
|
|
396
|
+
return this.forge?.fieldArgs;
|
|
397
|
+
}
|
|
398
|
+
get fieldType() {
|
|
399
|
+
return this.forge?.fieldType;
|
|
400
|
+
}
|
|
401
|
+
/**
|
|
402
|
+
* will return text.inputBase for ['url', 'email', 'number', 'date', 'time', 'datetime', 'phone', 'password']
|
|
403
|
+
*/
|
|
404
|
+
get htmlInputType() {
|
|
405
|
+
const variant = this?.fieldType?.split('text-')?.[1] ?? this.fieldType;
|
|
406
|
+
if (variant === 'area')
|
|
407
|
+
return variant;
|
|
408
|
+
if (this.forge?.fieldType?.startsWith('text-'))
|
|
409
|
+
return 'text';
|
|
410
|
+
if (['url', 'email', 'number', 'date', 'time', 'datetime', 'phone', 'password'].includes(this.forge?.fieldType ?? '')) {
|
|
411
|
+
return this.forge?.fieldType?.trim?.() ?? 'text';
|
|
412
|
+
}
|
|
413
|
+
return 'text';
|
|
414
|
+
}
|
|
415
|
+
get rawData() {
|
|
416
|
+
return this.#data;
|
|
417
|
+
}
|
|
418
|
+
iterateArray(fieldName, data) {
|
|
419
|
+
return this.#collectionValues.iterateArrayField(fieldName, data);
|
|
420
|
+
}
|
|
421
|
+
iterateObject(fieldName, data) {
|
|
422
|
+
return this.#collectionValues.iterateObjectField(fieldName, data);
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
class IDbError extends Error {
|
|
426
|
+
code;
|
|
427
|
+
constructor(message, code) {
|
|
428
|
+
super(message);
|
|
429
|
+
this.code = code;
|
|
430
|
+
this.name = 'DbCollectionError';
|
|
431
|
+
}
|
|
432
|
+
static throwError(message, code) {
|
|
433
|
+
throw new IDbError(message, code);
|
|
434
|
+
}
|
|
435
|
+
static handleError(error) {
|
|
436
|
+
if (error instanceof IDbError) {
|
|
437
|
+
console.error(`${error.name}: ${error.message} (Code: ${error.code})`);
|
|
438
|
+
}
|
|
439
|
+
else {
|
|
440
|
+
console.error('Unexpected error:', error);
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
type CombineElements<T extends string = string, U extends string = T> = T extends any ? T | `${T} ${CombineElements<Exclude<U, T>>}` : never;
|
|
2
|
+
type CombinedArgs = CombineElements<AccessProperties>;
|
|
3
|
+
type IdbObjectify<T extends string = 'number'> = `array-of-${T}` | `object-${T}`;
|
|
4
|
+
export type TplCollectionName = string;
|
|
5
|
+
export type TemplateFieldPrimitive = keyof typeof enumFieldsPrimitives | `text-${'tiny' | 'short' | 'medium' | 'long' | 'area'}` | `${string}.${string}` | `fk-${string}.${string}`;
|
|
6
|
+
export type TplObjectFieldPrimitive = IdbObjectify<TemplateFieldPrimitive>;
|
|
7
|
+
export type TplFieldFk = `fk-${string}.${string}`;
|
|
8
|
+
export type TplFkObject = IdbObjectify<TplFieldFk>;
|
|
9
|
+
export type TplTypes = TemplateFieldPrimitive | TplObjectFieldPrimitive | TplFieldFk | TplFkObject;
|
|
10
|
+
export type TplFieldArgs = `${TplTypes} (${CombinedArgs})`;
|
|
11
|
+
export type TplFieldRules = TplFieldArgs | TplTypes;
|
|
12
|
+
export type IDbObjectPrimitive = IdbObjectify<TemplateFieldPrimitive>;
|
|
13
|
+
export type IDbFk = `fk-${string}.${string}`;
|
|
14
|
+
export type IDbFkObject = IdbObjectify<IDbFk>;
|
|
15
|
+
export type IDbTypes = TemplateFieldPrimitive | IDbObjectPrimitive | IDbFk | IDbFkObject;
|
|
16
|
+
export type IDBArgumentsTypes = `${IDbTypes}(${CombinedArgs})`;
|
|
17
|
+
export type IDbFieldRules = IDBArgumentsTypes | IDbTypes;
|
|
18
|
+
export type IDbFieldType = IDBArgumentsTypes | IDbTypes;
|
|
19
|
+
export type CoreModel<T> = {
|
|
20
|
+
template: IdaeTemplate<T[keyof T]>;
|
|
21
|
+
};
|
|
22
|
+
export type IdaeModelRoot<T = Record<string, any>> = Record<string, any> & {
|
|
23
|
+
[K in keyof T]: {
|
|
24
|
+
template?: IdaeTemplate<T[K]>;
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
export type IdaeTemplate<C = Record<string, any>, M = IdaeModelRoot> = {
|
|
28
|
+
index: string;
|
|
29
|
+
presentation: CombineElements<keyof C>;
|
|
30
|
+
fields: IdaeTemplateFields<C>;
|
|
31
|
+
fks: {
|
|
32
|
+
[K in M]?: {
|
|
33
|
+
code: K;
|
|
34
|
+
multiple: boolean;
|
|
35
|
+
rules: CombinedArgs;
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
export type IdaeTemplateFields<T> = {
|
|
40
|
+
[K in keyof T]: TplFieldRules;
|
|
41
|
+
};
|
|
42
|
+
export type IDbForgeArgs = keyof typeof AccessProperties;
|
|
43
|
+
export type IDbForgeFields<Collection> = {
|
|
44
|
+
collection?: TplCollectionName;
|
|
45
|
+
fieldName?: keyof Collection;
|
|
46
|
+
fieldType?: IDbFieldType;
|
|
47
|
+
fieldRule?: IDbFieldRules;
|
|
48
|
+
fieldArgs?: IDbForgeArgs | undefined;
|
|
49
|
+
is: string;
|
|
50
|
+
};
|
|
51
|
+
export type IDBTemplate<T> = {
|
|
52
|
+
[K in keyof T]: TplFieldRules;
|
|
53
|
+
};
|
|
54
|
+
export declare enum AccessProperties {
|
|
55
|
+
'private' = "private",
|
|
56
|
+
'readonly' = "readonly",
|
|
57
|
+
'required' = "required"
|
|
58
|
+
}
|
|
59
|
+
export declare enum enumFieldsPrimitives {
|
|
60
|
+
id = "id",
|
|
61
|
+
any = "any",
|
|
62
|
+
date = "date",
|
|
63
|
+
datetime = "datetime",
|
|
64
|
+
time = "time",
|
|
65
|
+
text = "text",
|
|
66
|
+
number = "number",
|
|
67
|
+
boolean = "boolean",
|
|
68
|
+
url = "url",
|
|
69
|
+
email = "email",
|
|
70
|
+
phone = "phone",
|
|
71
|
+
password = "password"
|
|
72
|
+
}
|
|
73
|
+
export type ForgeFieldTypes = 'primitive' | 'object' | 'array' | 'fk';
|
|
74
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export var AccessProperties;
|
|
2
|
+
(function (AccessProperties) {
|
|
3
|
+
AccessProperties["private"] = "private";
|
|
4
|
+
AccessProperties["readonly"] = "readonly";
|
|
5
|
+
AccessProperties["required"] = "required";
|
|
6
|
+
})(AccessProperties || (AccessProperties = {}));
|
|
7
|
+
export var enumFieldsPrimitives;
|
|
8
|
+
(function (enumFieldsPrimitives) {
|
|
9
|
+
enumFieldsPrimitives["id"] = "id";
|
|
10
|
+
enumFieldsPrimitives["any"] = "any";
|
|
11
|
+
enumFieldsPrimitives["date"] = "date";
|
|
12
|
+
enumFieldsPrimitives["datetime"] = "datetime";
|
|
13
|
+
enumFieldsPrimitives["time"] = "time";
|
|
14
|
+
enumFieldsPrimitives["text"] = "text";
|
|
15
|
+
enumFieldsPrimitives["number"] = "number";
|
|
16
|
+
enumFieldsPrimitives["boolean"] = "boolean";
|
|
17
|
+
enumFieldsPrimitives["url"] = "url";
|
|
18
|
+
enumFieldsPrimitives["email"] = "email";
|
|
19
|
+
enumFieldsPrimitives["phone"] = "phone";
|
|
20
|
+
enumFieldsPrimitives["password"] = "password";
|
|
21
|
+
})(enumFieldsPrimitives || (enumFieldsPrimitives = {}));
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { type IdaeTemplateFields } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* IDbFormValidate
|
|
4
|
+
*
|
|
5
|
+
*
|
|
6
|
+
*/
|
|
7
|
+
export declare class IDbFormValidate<T> {
|
|
8
|
+
#private;
|
|
9
|
+
private collection;
|
|
10
|
+
private dbFields;
|
|
11
|
+
constructor(collection: string);
|
|
12
|
+
validateField(fieldName: keyof IdaeTemplateFields<T>, value: string): {
|
|
13
|
+
isValid: boolean;
|
|
14
|
+
error?: string;
|
|
15
|
+
};
|
|
16
|
+
validateFieldValue(fieldName: keyof IdaeTemplateFields, value: any): boolean;
|
|
17
|
+
validateForm(formData: Record<string, unknown>, options?: {
|
|
18
|
+
ignoreFields?: string[] | undefined;
|
|
19
|
+
}): {
|
|
20
|
+
isValid: boolean;
|
|
21
|
+
errors: Record<string, string>;
|
|
22
|
+
invalidFields: string[];
|
|
23
|
+
};
|
|
24
|
+
private validateEmail;
|
|
25
|
+
private validateUrl;
|
|
26
|
+
private validatePhone;
|
|
27
|
+
private validateDateTime;
|
|
28
|
+
}
|
|
29
|
+
export declare class IDbValidationError extends Error {
|
|
30
|
+
field: string;
|
|
31
|
+
code: string;
|
|
32
|
+
constructor(field: string, code: string, message: string);
|
|
33
|
+
}
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { IdaeTemplateModel } from './dataTemplate.js';
|
|
2
|
+
import { enumFieldsPrimitives } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* IDbFormValidate
|
|
5
|
+
*
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
export class IDbFormValidate {
|
|
9
|
+
collection;
|
|
10
|
+
dbFields;
|
|
11
|
+
constructor(collection) {
|
|
12
|
+
this.collection = collection;
|
|
13
|
+
this.dbFields = new IdaeModel();
|
|
14
|
+
}
|
|
15
|
+
validateField(fieldName, value) {
|
|
16
|
+
try {
|
|
17
|
+
const fieldInfo = this.dbFields.parseCollectionFieldName(this.collection, fieldName);
|
|
18
|
+
if (!fieldInfo) {
|
|
19
|
+
return { isValid: false, error: `Field ${String(fieldName)} not found in collection` };
|
|
20
|
+
}
|
|
21
|
+
// Vérification du type
|
|
22
|
+
if (!this.#validateType(value, fieldInfo.fieldType)) {
|
|
23
|
+
return this.#returnError(fieldName, fieldInfo.fieldType);
|
|
24
|
+
}
|
|
25
|
+
// Vérification des arguments du champ (required, etc.)
|
|
26
|
+
if (fieldInfo.fieldArgs) {
|
|
27
|
+
for (const arg of fieldInfo.fieldArgs) {
|
|
28
|
+
if (arg === 'required' && (value === undefined || value === null || value === '')) {
|
|
29
|
+
return this.#returnError(fieldName, 'required');
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
// Validations spécifiques selon le type de champ
|
|
34
|
+
switch (fieldInfo.fieldType) {
|
|
35
|
+
case enumFieldsPrimitives.email:
|
|
36
|
+
if (!this.validateEmail(value)) {
|
|
37
|
+
return this.#returnError(fieldName, fieldInfo.fieldType);
|
|
38
|
+
}
|
|
39
|
+
break;
|
|
40
|
+
case enumFieldsPrimitives.url:
|
|
41
|
+
if (!this.validateUrl(value)) {
|
|
42
|
+
return this.#returnError(fieldName, fieldInfo.fieldType);
|
|
43
|
+
}
|
|
44
|
+
break;
|
|
45
|
+
case enumFieldsPrimitives.phone:
|
|
46
|
+
if (!this.validatePhone(value)) {
|
|
47
|
+
return this.#returnError(fieldName, fieldInfo.fieldType);
|
|
48
|
+
}
|
|
49
|
+
break;
|
|
50
|
+
case enumFieldsPrimitives.date:
|
|
51
|
+
case enumFieldsPrimitives.datetime:
|
|
52
|
+
case enumFieldsPrimitives.time:
|
|
53
|
+
if (!this.validateDateTime(value, fieldInfo.fieldType)) {
|
|
54
|
+
return this.#returnError(fieldName, fieldInfo.fieldType);
|
|
55
|
+
}
|
|
56
|
+
break;
|
|
57
|
+
// Ajoutez d'autres cas spécifiques ici
|
|
58
|
+
}
|
|
59
|
+
return { isValid: true };
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
if (error instanceof IDbValidationError) {
|
|
63
|
+
return { isValid: false, error: error.message };
|
|
64
|
+
}
|
|
65
|
+
throw error;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
validateFieldValue(fieldName, value) {
|
|
69
|
+
try {
|
|
70
|
+
this.validateField(fieldName, value);
|
|
71
|
+
return true;
|
|
72
|
+
}
|
|
73
|
+
catch {
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
validateForm(formData, options = {}) {
|
|
78
|
+
const errors = {};
|
|
79
|
+
const invalidFields = [];
|
|
80
|
+
let isValid = true;
|
|
81
|
+
const fields = this.dbFields.getCollectionTemplateFields(this.collection);
|
|
82
|
+
if (!fields) {
|
|
83
|
+
return {
|
|
84
|
+
isValid: false,
|
|
85
|
+
errors: { general: 'Collection template not found' },
|
|
86
|
+
invalidFields: ['general']
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
for (const [fieldName, fieldRule] of Object.entries(fields)) {
|
|
90
|
+
// Ignorer les champs spécifiés dans options.ignoreFields
|
|
91
|
+
if (options.ignoreFields && options.ignoreFields.includes(fieldName)) {
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
const result = this.validateField(fieldName, formData[fieldName]);
|
|
95
|
+
if (!result.isValid) {
|
|
96
|
+
errors[fieldName] = result.error || 'Invalid field';
|
|
97
|
+
invalidFields.push(fieldName);
|
|
98
|
+
isValid = false;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return { isValid, errors, invalidFields };
|
|
102
|
+
}
|
|
103
|
+
#validateType(value, type) {
|
|
104
|
+
switch (type) {
|
|
105
|
+
case enumFieldsPrimitives.number:
|
|
106
|
+
return typeof value === 'number' && !isNaN(value);
|
|
107
|
+
case enumFieldsPrimitives.boolean:
|
|
108
|
+
return typeof value === 'boolean';
|
|
109
|
+
case enumFieldsPrimitives.text:
|
|
110
|
+
case enumFieldsPrimitives.email:
|
|
111
|
+
case enumFieldsPrimitives.url:
|
|
112
|
+
case enumFieldsPrimitives.phone:
|
|
113
|
+
case enumFieldsPrimitives.password:
|
|
114
|
+
return typeof value === 'string';
|
|
115
|
+
case enumFieldsPrimitives.date:
|
|
116
|
+
case enumFieldsPrimitives.datetime:
|
|
117
|
+
case enumFieldsPrimitives.time:
|
|
118
|
+
return value instanceof Date || typeof value === 'string';
|
|
119
|
+
case enumFieldsPrimitives.any:
|
|
120
|
+
return true;
|
|
121
|
+
default:
|
|
122
|
+
return true; // Pour les types non gérés, on considère que c'est valide
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
#returnError(fieldName, enumCode) {
|
|
126
|
+
throw new IDbValidationError(String(fieldName), enumCode ?? 'unknown', `Invalid format for field ${String(fieldName)}. Cause "${enumCode}" `);
|
|
127
|
+
}
|
|
128
|
+
validateEmail(email) {
|
|
129
|
+
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
130
|
+
return emailRegex.test(email);
|
|
131
|
+
}
|
|
132
|
+
validateUrl(url) {
|
|
133
|
+
try {
|
|
134
|
+
new URL(url);
|
|
135
|
+
return true;
|
|
136
|
+
}
|
|
137
|
+
catch {
|
|
138
|
+
return false;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
validatePhone(phone) {
|
|
142
|
+
// Ceci est un exemple simple. Vous pouvez ajuster selon vos besoins spécifiques
|
|
143
|
+
const phoneRegex = /^\+?[\d\s-]{10,}$/;
|
|
144
|
+
return phoneRegex.test(phone);
|
|
145
|
+
}
|
|
146
|
+
validateDateTime(value, type) {
|
|
147
|
+
const date = value instanceof Date ? value : new Date(value);
|
|
148
|
+
if (isNaN(date.getTime()))
|
|
149
|
+
return false;
|
|
150
|
+
switch (type) {
|
|
151
|
+
case enumFieldsPrimitives.date:
|
|
152
|
+
return true; // La conversion en Date a déjà validé le format
|
|
153
|
+
case enumFieldsPrimitives.time:
|
|
154
|
+
// Vérifiez si la chaîne contient uniquement l'heure
|
|
155
|
+
return /^([01]\d|2[0-3]):([0-5]\d)(:([0-5]\d))?$/.test(value);
|
|
156
|
+
case enumFieldsPrimitives.datetime:
|
|
157
|
+
return true; // La conversion en Date a déjà validé le format
|
|
158
|
+
default:
|
|
159
|
+
return false;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
export class IDbValidationError extends Error {
|
|
164
|
+
field;
|
|
165
|
+
code;
|
|
166
|
+
constructor(field, code, message) {
|
|
167
|
+
super(message);
|
|
168
|
+
this.field = field;
|
|
169
|
+
this.code = code;
|
|
170
|
+
this.name = 'IDbValidationError';
|
|
171
|
+
}
|
|
172
|
+
}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@medyll/idae-data-tpl",
|
|
3
|
+
"scope": "@medyll",
|
|
4
|
+
"version": "0.1.0",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"dev": "vite dev",
|
|
7
|
+
"build": "vite build && npm run package",
|
|
8
|
+
"preview": "vite preview",
|
|
9
|
+
"package": "svelte-kit sync && svelte-package && publint",
|
|
10
|
+
"prepublishOnly": "npm run package",
|
|
11
|
+
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
|
|
12
|
+
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
|
|
13
|
+
"test": "vitest",
|
|
14
|
+
"lint": "prettier --check . && eslint .",
|
|
15
|
+
"format": "prettier --write ."
|
|
16
|
+
},
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
|
+
"svelte": "./dist/index.js"
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"files": [
|
|
24
|
+
"dist",
|
|
25
|
+
"!dist/**/*.test.*",
|
|
26
|
+
"!dist/**/*.spec.*"
|
|
27
|
+
],
|
|
28
|
+
"peerDependencies": {
|
|
29
|
+
"svelte": "^5.0.0-next.1"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@sveltejs/adapter-auto": "^3.0.0",
|
|
33
|
+
"@sveltejs/kit": "^2.0.0",
|
|
34
|
+
"@sveltejs/package": "^2.0.0",
|
|
35
|
+
"@sveltejs/vite-plugin-svelte": "^3.0.0",
|
|
36
|
+
"@types/eslint": "^8.56.7",
|
|
37
|
+
"eslint": "^9.0.0",
|
|
38
|
+
"eslint-config-prettier": "^9.1.0",
|
|
39
|
+
"eslint-plugin-svelte": "^2.36.0",
|
|
40
|
+
"glob": "^7.2.0",
|
|
41
|
+
"globals": "^15.0.0",
|
|
42
|
+
"prettier": "^3.1.1",
|
|
43
|
+
"prettier-plugin-svelte": "^3.1.2",
|
|
44
|
+
"publint": "^0.1.9",
|
|
45
|
+
"svelte": "^4.2.7",
|
|
46
|
+
"svelte-check": "^3.6.0",
|
|
47
|
+
"tslib": "^2.4.1",
|
|
48
|
+
"typescript": "^5.0.0",
|
|
49
|
+
"typescript-eslint": "^8.0.0-alpha.20",
|
|
50
|
+
"vite": "^5.0.11",
|
|
51
|
+
"vitest": "^1.2.0"
|
|
52
|
+
},
|
|
53
|
+
"svelte": "./dist/index.js",
|
|
54
|
+
"types": "./dist/index.d.ts",
|
|
55
|
+
"type": "module"
|
|
56
|
+
}
|