5htp-core 0.6.2 → 0.6.3
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/client/app/index.ts +2 -1
- package/client/assets/css/components/table.less +1 -0
- package/client/components/Input.tsx +0 -2
- package/client/components/Rte/Editor.tsx +2 -0
- package/client/components/Rte/index.tsx +0 -1
- package/client/services/router/request/api.ts +0 -9
- package/common/router/request/api.ts +0 -8
- package/package.json +1 -1
- package/server/app/container/console/index.ts +65 -48
- package/server/app/index.ts +19 -8
- package/server/app/service/index.ts +55 -15
- package/server/services/auth/router/index.ts +3 -1
- package/server/services/disks/driver.ts +5 -1
- package/server/services/disks/drivers/s3/index.ts +2 -2
- package/server/services/disks/index.ts +10 -5
- package/server/services/email/index.ts +1 -1
- package/server/services/prisma/Facet.ts +39 -15
- package/server/services/prisma/index.ts +5 -7
- package/server/services/router/http/multipart.ts +5 -0
- package/server/services/router/index.ts +50 -35
- package/server/services/router/request/api.ts +0 -12
- package/server/services/router/request/validation/zod.ts +180 -0
- package/server/services/router/response/index.ts +14 -9
- package/server/services/router/response/page/document.tsx +5 -3
- package/server/services/router/service.ts +7 -4
- package/server/services/schema/request.ts +21 -34
- package/server/services/schema/router/index.ts +3 -3
- package/types/icons.d.ts +1 -1
- package/common/data/input/validate.ts +0 -54
- package/server/services/router/request/validation/index.ts +0 -23
- package/server/services/router/request/validation/schema.ts +0 -211
- package/server/services/router/request/validation/validator.ts +0 -117
- package/server/services/router/request/validation/validators.ts +0 -485
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
// https://github.com/adonisjs/validator
|
|
2
|
-
|
|
3
|
-
/*----------------------------------
|
|
4
|
-
- DEPENDANCES
|
|
5
|
-
----------------------------------*/
|
|
6
|
-
/*----------------------------------
|
|
7
|
-
- CONSTANTES
|
|
8
|
-
----------------------------------*/
|
|
9
|
-
|
|
10
|
-
const debug = false;
|
|
11
|
-
|
|
12
|
-
/*----------------------------------
|
|
13
|
-
- TYPES: DECLARATION SCHEMA
|
|
14
|
-
----------------------------------*/
|
|
15
|
-
|
|
16
|
-
//import type { Choix } from '@client/components/Champs/Base/Choix';
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
/*----------------------------------
|
|
20
|
-
- FONCTIONS
|
|
21
|
-
----------------------------------*/
|
|
22
|
-
export const isSchema = <TElem extends TSchema | TSchemaChampComplet>(elem: TElem): elem is TSchema => !('type' in elem)
|
|
23
|
-
|
|
24
|
-
export const initDonnees = <TSchemaA extends TSchema>(
|
|
25
|
-
schema: TSchemaA,
|
|
26
|
-
donnees: TObjetDonnees,
|
|
27
|
-
toutConserver: boolean = false
|
|
28
|
-
): Partial<TValidatedData<TSchemaA>> => {
|
|
29
|
-
|
|
30
|
-
// toutConserver = true: on conserve toutes les données, y compris celles n'étant pas été définies dans le schéma
|
|
31
|
-
let retour: Partial<TValidatedData<TSchemaA>> = toutConserver ? { ...donnees } : {}
|
|
32
|
-
|
|
33
|
-
for (const nomChamp in schema) {
|
|
34
|
-
const elem = schema[nomChamp];
|
|
35
|
-
|
|
36
|
-
// Sous-schema
|
|
37
|
-
if (isSchema(elem)) {
|
|
38
|
-
|
|
39
|
-
retour[nomChamp] = initDonnees(elem, donnees[nomChamp] || {}, toutConserver);
|
|
40
|
-
|
|
41
|
-
// Champ
|
|
42
|
-
} else if (elem.defaut !== undefined && donnees[nomChamp] === undefined) {
|
|
43
|
-
|
|
44
|
-
retour[nomChamp] = elem.defaut;
|
|
45
|
-
|
|
46
|
-
} else
|
|
47
|
-
retour[nomChamp] = donnees[nomChamp];
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
return retour;
|
|
51
|
-
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export const validate =
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/*----------------------------------
|
|
2
|
-
- DEPENDANCES
|
|
3
|
-
----------------------------------*/
|
|
4
|
-
|
|
5
|
-
import type { TValidatorDefinition } from './validator';
|
|
6
|
-
import type { SchemaValidators } from './validators';
|
|
7
|
-
|
|
8
|
-
/*----------------------------------
|
|
9
|
-
- EXPORT
|
|
10
|
-
----------------------------------*/
|
|
11
|
-
|
|
12
|
-
export { default as Schema } from './schema';
|
|
13
|
-
export type { TSchemaFields, TValidatedData } from './schema';
|
|
14
|
-
|
|
15
|
-
export const field = new Proxy<SchemaValidators>({} as SchemaValidators, {
|
|
16
|
-
get: (target, propKey) => {
|
|
17
|
-
return (...args: any[]) => ([ propKey, args ]);
|
|
18
|
-
}
|
|
19
|
-
}) as unknown as {
|
|
20
|
-
[K in keyof SchemaValidators]: SchemaValidators[K] extends (...args: any[]) => any
|
|
21
|
-
? (...args: Parameters<SchemaValidators[K]>) => TValidatorDefinition<K>
|
|
22
|
-
: SchemaValidators[K];
|
|
23
|
-
};
|
|
@@ -1,211 +0,0 @@
|
|
|
1
|
-
/*----------------------------------
|
|
2
|
-
- DEPENDANCES
|
|
3
|
-
----------------------------------*/
|
|
4
|
-
|
|
5
|
-
// Core
|
|
6
|
-
import { CoreError, TListeErreursSaisie, InputErrorSchema } from '@common/errors';
|
|
7
|
-
|
|
8
|
-
// Specific
|
|
9
|
-
import { default as Validator, EXCLUDE_VALUE, TValidatorDefinition } from './validator';
|
|
10
|
-
import defaultValidators, { SchemaValidators, getFieldValidator } from './validators';
|
|
11
|
-
|
|
12
|
-
/*----------------------------------
|
|
13
|
-
- TYPES
|
|
14
|
-
----------------------------------*/
|
|
15
|
-
|
|
16
|
-
export type TSchemaFields = {
|
|
17
|
-
[fieldName: string]: TSchemaFields | Schema<{}> | Validator<any> | TValidatorDefinition
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
type TSchemaOptions = {
|
|
21
|
-
opt?: boolean
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export type TValidateOptions<TFields extends TSchemaFields = {}> = {
|
|
25
|
-
debug?: boolean,
|
|
26
|
-
throwError?: boolean,
|
|
27
|
-
ignoreMissing?: boolean,
|
|
28
|
-
only?: (keyof TFields)[],
|
|
29
|
-
validateDeps?: boolean,
|
|
30
|
-
autoCorrect?: boolean,
|
|
31
|
-
validators?: SchemaValidators
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export type TValidationResult<TFields extends TSchemaFields> = {
|
|
35
|
-
values: TValidatedData<TFields>,
|
|
36
|
-
errorsCount: number,
|
|
37
|
-
erreurs: TListeErreursSaisie
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export type TSchemaData<TSchema extends Schema<{}>> =
|
|
41
|
-
TValidationResult<TSchema["fields"]>
|
|
42
|
-
|
|
43
|
-
export type TValidatedData<TFields extends TSchemaFields> = {
|
|
44
|
-
// For each field, the values returned by validator.validate()
|
|
45
|
-
[name in keyof TFields]: TFieldReturnType<TFields[name]>
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
type TFieldReturnType<TField> = TField extends TValidatorDefinition
|
|
49
|
-
? TField[2]
|
|
50
|
-
: TField extends Schema<infer T>
|
|
51
|
-
? TValidatedData<T>
|
|
52
|
-
: never
|
|
53
|
-
|
|
54
|
-
/*----------------------------------
|
|
55
|
-
- CONST
|
|
56
|
-
----------------------------------*/
|
|
57
|
-
|
|
58
|
-
const LogPrefix = '[schema][validator]';
|
|
59
|
-
|
|
60
|
-
/*----------------------------------
|
|
61
|
-
- CLASS
|
|
62
|
-
----------------------------------*/
|
|
63
|
-
export default class Schema<TFields extends TSchemaFields> {
|
|
64
|
-
|
|
65
|
-
public constructor(
|
|
66
|
-
public fields: TFields,
|
|
67
|
-
public options: TSchemaOptions = {}
|
|
68
|
-
) {
|
|
69
|
-
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
public getFieldValidator(
|
|
73
|
-
fieldName: string,
|
|
74
|
-
validators: SchemaValidators = defaultValidators
|
|
75
|
-
): null | Validator<any> | Schema<{}> {
|
|
76
|
-
|
|
77
|
-
let field = this.fields[fieldName];
|
|
78
|
-
if (field === undefined) {
|
|
79
|
-
|
|
80
|
-
return null;
|
|
81
|
-
|
|
82
|
-
// TValidatorDefinition
|
|
83
|
-
} else
|
|
84
|
-
return getFieldValidator(field);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
public validate<TDonnees extends TObjetDonnees>(
|
|
88
|
-
dataToValidate: Partial<TDonnees>,
|
|
89
|
-
opts: TValidateOptions<TFields> = {},
|
|
90
|
-
chemin: string[] = []
|
|
91
|
-
): TValidatedData<TFields> {
|
|
92
|
-
|
|
93
|
-
const validators = opts.validators || defaultValidators;
|
|
94
|
-
|
|
95
|
-
// Check data type
|
|
96
|
-
if (typeof dataToValidate !== 'object')
|
|
97
|
-
throw new InputErrorSchema({ [chemin.join('.')]: ['Must be an object'] });
|
|
98
|
-
|
|
99
|
-
// Default options
|
|
100
|
-
opts = {
|
|
101
|
-
debug: false,
|
|
102
|
-
throwError: true,
|
|
103
|
-
validateDeps: true,
|
|
104
|
-
autoCorrect: false,
|
|
105
|
-
...opts,
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
const keysToValidate = (opts.only || Object.keys(this.fields)) as string[];
|
|
109
|
-
|
|
110
|
-
// Validation de chacune d'entre elles
|
|
111
|
-
const output: Partial<TDonnees> = {};
|
|
112
|
-
let erreurs: TListeErreursSaisie = {};
|
|
113
|
-
let errorsCount = 0;
|
|
114
|
-
for (const fieldName of keysToValidate) {
|
|
115
|
-
|
|
116
|
-
const validator = this.getFieldValidator(fieldName, validators);
|
|
117
|
-
if (validator === null) {
|
|
118
|
-
opts.debug && console.warn(LogPrefix, '[' + fieldName + ']', 'Exclusion (pas présent dans le schéma)');
|
|
119
|
-
continue;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
// Create field path
|
|
123
|
-
const cheminA = [...chemin, fieldName]
|
|
124
|
-
const cheminAstr = cheminA.join('.')
|
|
125
|
-
const valOrigine = dataToValidate[fieldName];
|
|
126
|
-
|
|
127
|
-
// Validation
|
|
128
|
-
try {
|
|
129
|
-
|
|
130
|
-
const val = validator.validate(valOrigine, opts, cheminA);
|
|
131
|
-
|
|
132
|
-
// Exclusion seulement si explicitement demandé
|
|
133
|
-
// IMPORTANT: Conserver les values undefined
|
|
134
|
-
// La présence d'un valeur undefined peut être utile, par exemple, pour indiquer qu'on souhaite supprimer une donnée
|
|
135
|
-
// Exemple: undefinec = suppression fichier | Absende donnée = conservation fihcier actuel
|
|
136
|
-
if (val === EXCLUDE_VALUE)
|
|
137
|
-
opts.debug && console.log(LogPrefix, '[' + cheminA + '] Exclusion demandée');
|
|
138
|
-
// Key not in the input data, we don't create an entry in the output
|
|
139
|
-
else if (fieldName in dataToValidate)
|
|
140
|
-
output[fieldName] = val;
|
|
141
|
-
|
|
142
|
-
opts.debug && console.log(LogPrefix, '[' + cheminA + ']', valOrigine, '=>', val);
|
|
143
|
-
|
|
144
|
-
} catch (error) {
|
|
145
|
-
|
|
146
|
-
opts.debug && console.warn(LogPrefix, '[' + cheminA + ']', valOrigine, '|| CoreError:', error);
|
|
147
|
-
|
|
148
|
-
if (error instanceof InputErrorSchema) {
|
|
149
|
-
|
|
150
|
-
erreurs = { ...erreurs, ...error.errors };
|
|
151
|
-
errorsCount += Object.keys(error.errors).length;
|
|
152
|
-
|
|
153
|
-
} else if (error instanceof CoreError) {
|
|
154
|
-
|
|
155
|
-
erreurs[cheminAstr] = [error.message]
|
|
156
|
-
errorsCount++;
|
|
157
|
-
|
|
158
|
-
} else if (SERVER) {
|
|
159
|
-
|
|
160
|
-
// Server: transmiss error & report bug
|
|
161
|
-
throw error;
|
|
162
|
-
|
|
163
|
-
} else {
|
|
164
|
-
|
|
165
|
-
console.error(LogPrefix, '[' + cheminA + ']', error);
|
|
166
|
-
erreurs[cheminAstr] = ["Technical error while validating data"];
|
|
167
|
-
errorsCount++;
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
if (errorsCount !== 0)
|
|
173
|
-
throw new InputErrorSchema(erreurs);
|
|
174
|
-
|
|
175
|
-
opts.debug && console.log(LogPrefix, '', dataToValidate, '=>', output);
|
|
176
|
-
|
|
177
|
-
return output as TValidatedData<TFields>;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
public validateWithDetails<TDonnees extends TObjetDonnees>(
|
|
181
|
-
|
|
182
|
-
dataToValidate: Partial<TDonnees>,
|
|
183
|
-
allData: TDonnees,
|
|
184
|
-
output: TObjetDonnees = {},
|
|
185
|
-
|
|
186
|
-
opts: TValidateOptions<TFields> = {},
|
|
187
|
-
chemin: string[] = []
|
|
188
|
-
|
|
189
|
-
): TValidationResult<TFields> {
|
|
190
|
-
|
|
191
|
-
let erreurs: TListeErreursSaisie = {};
|
|
192
|
-
let errorsCount = 0;
|
|
193
|
-
|
|
194
|
-
try {
|
|
195
|
-
this.validate(dataToValidate, opts, chemin);
|
|
196
|
-
} catch (error) {
|
|
197
|
-
if (error instanceof InputErrorSchema) {
|
|
198
|
-
erreurs = error.errors;
|
|
199
|
-
errorsCount = Object.keys(erreurs).length;
|
|
200
|
-
} else {
|
|
201
|
-
throw error;
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
return {
|
|
206
|
-
values: output as TValidatedData<TFields>,
|
|
207
|
-
erreurs,
|
|
208
|
-
errorsCount,
|
|
209
|
-
};
|
|
210
|
-
}
|
|
211
|
-
}
|
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
/*----------------------------------
|
|
2
|
-
- DEPENDANCES
|
|
3
|
-
----------------------------------*/
|
|
4
|
-
|
|
5
|
-
// Npm
|
|
6
|
-
import type { ComponentChild } from 'preact'
|
|
7
|
-
|
|
8
|
-
// Core
|
|
9
|
-
import { InputError } from '@common/errors';
|
|
10
|
-
|
|
11
|
-
// Specific
|
|
12
|
-
import type { TValidateOptions } from './schema';
|
|
13
|
-
import type { SchemaValidators } from './validators';
|
|
14
|
-
import type { InputBaseProps } from '@client/components/utils';
|
|
15
|
-
|
|
16
|
-
/*----------------------------------
|
|
17
|
-
- TYPES
|
|
18
|
-
----------------------------------*/
|
|
19
|
-
|
|
20
|
-
export type TValidatorDefinition<K extends keyof SchemaValidators = keyof SchemaValidators> = [
|
|
21
|
-
type: string,
|
|
22
|
-
args: any[],
|
|
23
|
-
returnType: string
|
|
24
|
-
]
|
|
25
|
-
|
|
26
|
-
// TODO: remove
|
|
27
|
-
export type TValidatorOptions<TValue> = {
|
|
28
|
-
|
|
29
|
-
rendu?: TFieldRenderer,
|
|
30
|
-
|
|
31
|
-
// I don't remind what is options.activer about
|
|
32
|
-
activer?: (donnees: TObjetDonnees) => boolean,
|
|
33
|
-
onglet?: string, // Sert juste d'identifiant secondaire. Ex: nom onglet correspondant
|
|
34
|
-
|
|
35
|
-
// Executé après le validateur propre au type
|
|
36
|
-
dependances?: string[],
|
|
37
|
-
opt?: true,
|
|
38
|
-
defaut?: TValue,
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export type TFieldRenderer = (props: any) => ComponentChild;
|
|
43
|
-
|
|
44
|
-
type TNonEmptyValue = Exclude<any, undefined | '' | null>
|
|
45
|
-
|
|
46
|
-
type TValidationArgs<TValue, TAllValues extends {}> = [
|
|
47
|
-
// For the value given as input in the validation function,
|
|
48
|
-
// Only the empty values were escluded
|
|
49
|
-
val: TNonEmptyValue,
|
|
50
|
-
validateOptions: TValidateOptions,
|
|
51
|
-
path: string[]
|
|
52
|
-
]
|
|
53
|
-
|
|
54
|
-
type TValidationFunction<TValue, TAllValues extends {} = {}> = (
|
|
55
|
-
...args: TValidationArgs<TValue, TAllValues>
|
|
56
|
-
) => TValue | typeof EXCLUDE_VALUE;
|
|
57
|
-
|
|
58
|
-
type TValidateReturnType<
|
|
59
|
-
TOptions extends TValidatorOptions<TValue>,
|
|
60
|
-
TValue extends any
|
|
61
|
-
> = TOptions extends { opt: true }
|
|
62
|
-
? (undefined | TValue)
|
|
63
|
-
: TValue
|
|
64
|
-
|
|
65
|
-
/*----------------------------------
|
|
66
|
-
- CONST
|
|
67
|
-
----------------------------------*/
|
|
68
|
-
|
|
69
|
-
export const EXCLUDE_VALUE = "action:exclure" as const;
|
|
70
|
-
|
|
71
|
-
/*----------------------------------
|
|
72
|
-
- CLASS
|
|
73
|
-
----------------------------------*/
|
|
74
|
-
export default class Validator<
|
|
75
|
-
TValue,
|
|
76
|
-
TOptions extends TValidatorOptions<TValue> = TValidatorOptions<TValue>,
|
|
77
|
-
//TComponent = React.FunctionComponent< InputBaseProps< TValue > >
|
|
78
|
-
> {
|
|
79
|
-
|
|
80
|
-
public constructor(
|
|
81
|
-
public type: string,
|
|
82
|
-
public validateType: TValidationFunction<TValue>,
|
|
83
|
-
public options: TOptions,
|
|
84
|
-
public componentAttributes: Partial<InputBaseProps<TValue>> = {}
|
|
85
|
-
) {
|
|
86
|
-
|
|
87
|
-
// Basic component attriutes
|
|
88
|
-
this.componentAttributes.required = options?.opt !== true;
|
|
89
|
-
//this.componentAttributes.validator = this;
|
|
90
|
-
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
public isEmpty = (val: any) => val === undefined || val === '' || val === null
|
|
94
|
-
|
|
95
|
-
public validate(...[
|
|
96
|
-
val, validateOptions, path
|
|
97
|
-
]: TValidationArgs<TValue, {}>): TValidateReturnType<TOptions, TValue> {
|
|
98
|
-
|
|
99
|
-
// Required value
|
|
100
|
-
if (this.isEmpty(val)) {
|
|
101
|
-
// Optionnel, on skip
|
|
102
|
-
if (this.options.opt === true || (
|
|
103
|
-
validateOptions?.ignoreMissing === true
|
|
104
|
-
&&
|
|
105
|
-
val === undefined
|
|
106
|
-
))
|
|
107
|
-
return undefined as TValidateReturnType<TOptions, TValue>;
|
|
108
|
-
// Requis
|
|
109
|
-
else
|
|
110
|
-
throw new InputError("Please enter a value");
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
// Validate type
|
|
114
|
-
return this.validateType(val, validateOptions, path) as TValidateReturnType<TOptions, TValue>;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
}
|