5htp-core 0.2.5-2 → 0.2.6
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/package.json +1 -1
- package/src/client/components/Dialog/Manager.tsx +4 -5
- package/src/client/components/Form.ts +88 -36
- package/src/client/components/Form_old/index.tsx +17 -17
- package/src/client/components/Form_old/index.tsx.old +17 -17
- package/src/client/components/Select/ChoiceSelector.tsx +172 -0
- package/src/client/components/Select/index.tsx +27 -138
- package/src/client/components/containers/Popover/getPosition.ts +14 -11
- package/src/client/components/containers/Popover/index.tsx +52 -35
- package/src/client/components/containers/Popover/popover.less +7 -1
- package/src/client/components/dropdown/index.tsx +1 -1
- package/src/client/components/index.ts +1 -1
- package/src/client/components/input/Number/index.tsx +2 -2
- package/src/client/components/inputv3/{string/index.tsx → index.tsx} +6 -2
- package/src/client/pages/_messages/403.tsx +1 -1
- package/src/client/pages/_messages/500.tsx +1 -1
- package/src/client/pages/bug.tsx +3 -3
- package/src/client/utils/dom.ts +12 -1
- package/src/common/validation/schema.ts +26 -27
- package/src/common/validation/validator.ts +14 -5
- package/src/server/app/index.ts +6 -2
- package/src/server/services/schema/request.ts +0 -1
|
@@ -18,18 +18,18 @@ type TSchemaOptions = {
|
|
|
18
18
|
opt?: boolean
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
type
|
|
21
|
+
export type TValidateOptions<TFields extends TSchemaFields = {}> = {
|
|
22
22
|
debug?: boolean,
|
|
23
23
|
throwError?: boolean,
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
ignoreMissing?: boolean,
|
|
25
|
+
only?: (keyof TFields)[],
|
|
26
26
|
validateDeps?: boolean,
|
|
27
27
|
autoCorrect?: boolean,
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
export type TValidationResult<TFields extends TSchemaFields> = {
|
|
31
31
|
values: TValidatedData<TFields>,
|
|
32
|
-
|
|
32
|
+
errorsCount: number,
|
|
33
33
|
erreurs: TListeErreursSaisie
|
|
34
34
|
}
|
|
35
35
|
|
|
@@ -62,7 +62,7 @@ export default class Schema<TFields extends TSchemaFields> {
|
|
|
62
62
|
allData: TDonnees,
|
|
63
63
|
output: TObjetDonnees = {},
|
|
64
64
|
|
|
65
|
-
opts:
|
|
65
|
+
opts: TValidateOptions<TFields> = {},
|
|
66
66
|
chemin: string[] = []
|
|
67
67
|
|
|
68
68
|
): TValidationResult<TFields> {
|
|
@@ -70,45 +70,44 @@ export default class Schema<TFields extends TSchemaFields> {
|
|
|
70
70
|
opts = {
|
|
71
71
|
debug: false,
|
|
72
72
|
throwError: false,
|
|
73
|
-
validateAll: false,
|
|
74
73
|
validateDeps: true,
|
|
75
74
|
autoCorrect: false,
|
|
76
75
|
...opts,
|
|
77
76
|
}
|
|
78
77
|
|
|
79
|
-
const clesAvalider = Object.keys(opts.validateAll === true ? this.fields : dataToValidate);
|
|
80
|
-
|
|
81
78
|
let outputSchema = output;
|
|
82
79
|
for (const branche of chemin)
|
|
83
80
|
outputSchema = outputSchema[branche];
|
|
81
|
+
|
|
82
|
+
const keysToValidate = opts.only || Object.keys(this.fields);
|
|
84
83
|
|
|
85
84
|
// Validation de chacune d'entre elles
|
|
86
85
|
let erreurs: TListeErreursSaisie = {};
|
|
87
|
-
let
|
|
88
|
-
for (const
|
|
86
|
+
let errorsCount = 0;
|
|
87
|
+
for (const fieldName of keysToValidate) {
|
|
89
88
|
|
|
90
89
|
// La donnée est répertoriée dans le schema
|
|
91
|
-
const field = this.fields[
|
|
90
|
+
const field = this.fields[fieldName];
|
|
92
91
|
if (field === undefined) {
|
|
93
|
-
opts.debug && console.warn(LogPrefix, '[' +
|
|
92
|
+
opts.debug && console.warn(LogPrefix, '[' + fieldName + ']', 'Exclusion (pas présent dans le schéma)');
|
|
94
93
|
continue;
|
|
95
94
|
}
|
|
96
95
|
|
|
97
|
-
const cheminA = [...chemin,
|
|
96
|
+
const cheminA = [...chemin, fieldName]
|
|
98
97
|
const cheminAstr = cheminA.join('.')
|
|
99
98
|
|
|
100
99
|
// Sous-schema
|
|
101
100
|
if (field instanceof Schema) {
|
|
102
101
|
|
|
103
102
|
// Initialise la structure pour permettre l'assignement d'outputSchema
|
|
104
|
-
if (outputSchema[
|
|
105
|
-
outputSchema[
|
|
103
|
+
if (outputSchema[fieldName] === undefined)
|
|
104
|
+
outputSchema[fieldName] = {}
|
|
106
105
|
|
|
107
106
|
// The corresponding data should be an object
|
|
108
|
-
const schemadata = dataToValidate[
|
|
107
|
+
const schemadata = dataToValidate[fieldName];
|
|
109
108
|
if (typeof schemadata !== 'object') {
|
|
110
109
|
erreurs[ cheminAstr ] = [`Should be an object`];
|
|
111
|
-
|
|
110
|
+
errorsCount++;
|
|
112
111
|
continue;
|
|
113
112
|
}
|
|
114
113
|
|
|
@@ -123,30 +122,30 @@ export default class Schema<TFields extends TSchemaFields> {
|
|
|
123
122
|
cheminA
|
|
124
123
|
);
|
|
125
124
|
erreurs = { ...erreurs, ...validationSchema.erreurs };
|
|
126
|
-
|
|
125
|
+
errorsCount += validationSchema.errorsCount;
|
|
127
126
|
|
|
128
127
|
// Pas besoin d'assigner, car output est passé en référence
|
|
129
|
-
//output[
|
|
128
|
+
//output[fieldName] = validationSchema.values;
|
|
130
129
|
|
|
131
130
|
|
|
132
131
|
// I don't remind what is options.activer about
|
|
133
132
|
/*} else if (field.activer !== undefined && field.activer(allData) === false) {
|
|
134
133
|
|
|
135
|
-
delete outputSchema[
|
|
134
|
+
delete outputSchema[fieldName];*/
|
|
136
135
|
|
|
137
136
|
// Validator
|
|
138
137
|
} else {
|
|
139
138
|
|
|
140
139
|
// Champ composé de plusieurs values
|
|
141
140
|
const valOrigine = field.options.as === undefined
|
|
142
|
-
? dataToValidate[
|
|
143
|
-
// Le
|
|
141
|
+
? dataToValidate[fieldName]
|
|
142
|
+
// Le fieldName regroupe plusieurs values (ex: Periode)
|
|
144
143
|
: field.options.as.map((nomVal: string) => dataToValidate[nomVal])
|
|
145
144
|
|
|
146
145
|
// Validation
|
|
147
146
|
try {
|
|
148
147
|
|
|
149
|
-
const val = field.validate(valOrigine, allData, output, opts
|
|
148
|
+
const val = field.validate(valOrigine, allData, output, opts);
|
|
150
149
|
|
|
151
150
|
// Exclusion seulement si explicitement demandé
|
|
152
151
|
// IMPORTANT: Conserver les values undefined
|
|
@@ -155,7 +154,7 @@ export default class Schema<TFields extends TSchemaFields> {
|
|
|
155
154
|
if (val === EXCLUDE_VALUE)
|
|
156
155
|
opts.debug && console.log(LogPrefix, '[' + cheminA + '] Exclusion demandée');
|
|
157
156
|
else
|
|
158
|
-
outputSchema[
|
|
157
|
+
outputSchema[fieldName] = val;
|
|
159
158
|
|
|
160
159
|
opts.debug && console.log(LogPrefix, '[' + cheminA + ']', valOrigine, '=>', val);
|
|
161
160
|
|
|
@@ -167,7 +166,7 @@ export default class Schema<TFields extends TSchemaFields> {
|
|
|
167
166
|
|
|
168
167
|
// Référencement erreur
|
|
169
168
|
erreurs[cheminAstr] = [error.message]
|
|
170
|
-
|
|
169
|
+
errorsCount++;
|
|
171
170
|
|
|
172
171
|
} else
|
|
173
172
|
throw error;
|
|
@@ -175,7 +174,7 @@ export default class Schema<TFields extends TSchemaFields> {
|
|
|
175
174
|
}
|
|
176
175
|
}
|
|
177
176
|
|
|
178
|
-
if (
|
|
177
|
+
if (errorsCount !== 0 && opts.throwError === true) {
|
|
179
178
|
throw new InputErrorSchema(erreurs);
|
|
180
179
|
}
|
|
181
180
|
|
|
@@ -184,7 +183,7 @@ export default class Schema<TFields extends TSchemaFields> {
|
|
|
184
183
|
return {
|
|
185
184
|
values: output as TValidatedData<TFields>,
|
|
186
185
|
erreurs,
|
|
187
|
-
|
|
186
|
+
errorsCount,
|
|
188
187
|
};
|
|
189
188
|
|
|
190
189
|
}
|
|
@@ -8,6 +8,9 @@ import type { ComponentChild } from 'preact'
|
|
|
8
8
|
// Core
|
|
9
9
|
import { InputError } from '@common/errors';
|
|
10
10
|
|
|
11
|
+
// Specific
|
|
12
|
+
import type { TValidateOptions } from './schema';
|
|
13
|
+
|
|
11
14
|
/*----------------------------------
|
|
12
15
|
- TYPES
|
|
13
16
|
----------------------------------*/
|
|
@@ -41,12 +44,12 @@ type TValidationArgs<TValue, TAllValues extends {}> = [
|
|
|
41
44
|
val: TNonEmptyValue,
|
|
42
45
|
input: TAllValues,
|
|
43
46
|
output: Partial<TAllValues>,
|
|
44
|
-
|
|
47
|
+
validateOptions?: TValidateOptions
|
|
45
48
|
]
|
|
46
49
|
|
|
47
50
|
type TValidationFunction<TValue, TAllValues extends {} = {}> = (
|
|
48
51
|
...args: TValidationArgs<TValue, TAllValues>
|
|
49
|
-
|
|
52
|
+
) => TValue | typeof EXCLUDE_VALUE;
|
|
50
53
|
|
|
51
54
|
type TValidateReturnType<
|
|
52
55
|
TOptions extends TValidator<TValue>,
|
|
@@ -76,12 +79,18 @@ export default class Validator<TValue, TOptions extends TValidator<TValue> = TVa
|
|
|
76
79
|
|
|
77
80
|
public isEmpty = (val: any) => val === undefined || val === '' || val === null
|
|
78
81
|
|
|
79
|
-
public validate(...[
|
|
82
|
+
public validate(...[
|
|
83
|
+
val, input, output, validateOptions
|
|
84
|
+
]: TValidationArgs<TValue, {}>): TValidateReturnType<TOptions, TValue> {
|
|
80
85
|
|
|
81
86
|
// Required value
|
|
82
87
|
if (this.isEmpty(val)) {
|
|
83
88
|
// Optionnel, on skip
|
|
84
|
-
if (this.options.opt === true
|
|
89
|
+
if (this.options.opt === true || (
|
|
90
|
+
validateOptions?.ignoreMissing === true
|
|
91
|
+
&&
|
|
92
|
+
val === undefined
|
|
93
|
+
))
|
|
85
94
|
return undefined as TValidateReturnType<TOptions, TValue>;
|
|
86
95
|
// Requis
|
|
87
96
|
else
|
|
@@ -89,7 +98,7 @@ export default class Validator<TValue, TOptions extends TValidator<TValue> = TVa
|
|
|
89
98
|
}
|
|
90
99
|
|
|
91
100
|
// Validate type
|
|
92
|
-
return this.validateType(val, input, output,
|
|
101
|
+
return this.validateType(val, input, output, validateOptions) as TValidateReturnType<TOptions, TValue>;
|
|
93
102
|
}
|
|
94
103
|
|
|
95
104
|
}
|
package/src/server/app/index.ts
CHANGED
|
@@ -192,9 +192,13 @@ export default abstract class Application extends Service<Config, Hooks, /* TODO
|
|
|
192
192
|
// Start service
|
|
193
193
|
if (service.start) {
|
|
194
194
|
service.started = service.start();
|
|
195
|
-
await service.started
|
|
195
|
+
await service.started.catch(e => {
|
|
196
|
+
console.error("Catched error while starting service " + serviceClassName + '. Exiting process if mode production.');
|
|
197
|
+
if (this.env.profile === 'prod')
|
|
198
|
+
process.exit();
|
|
199
|
+
})
|
|
196
200
|
}
|
|
197
|
-
|
|
201
|
+
|
|
198
202
|
service.status = 'running';
|
|
199
203
|
}
|
|
200
204
|
|