5htp-core 0.6.2 → 0.6.3-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/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/index.tsx +1 -1
- package/client/services/router/request/api.ts +26 -52
- package/common/data/dates.ts +3 -0
- package/common/router/request/api.ts +0 -8
- package/package.json +1 -1
- package/server/app/container/config.ts +43 -4
- package/server/app/container/console/index.ts +66 -49
- package/server/app/index.ts +19 -8
- package/server/app/service/index.ts +55 -15
- package/server/services/auth/router/index.ts +8 -4
- package/server/services/database/connection.ts +33 -19
- 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 +19 -10
- 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/global/utils.d.ts +22 -4
- 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
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { InputError } from '@common/errors';
|
|
2
|
+
import zod, { _ZodType } from 'zod';
|
|
3
|
+
|
|
4
|
+
export type TRichTextValidatorOptions = {
|
|
5
|
+
attachements?: boolean
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export const preprocessSchema = (schema: zod.ZodObject): zod.ZodObject => {
|
|
9
|
+
|
|
10
|
+
// Not working, data is {}
|
|
11
|
+
return schema;
|
|
12
|
+
|
|
13
|
+
if (!(schema instanceof zod.ZodObject))
|
|
14
|
+
return schema;
|
|
15
|
+
|
|
16
|
+
if (schema.withPreprocessing)
|
|
17
|
+
return schema;
|
|
18
|
+
|
|
19
|
+
const shape = schema.def.shape;
|
|
20
|
+
const newShape: Record<string, zod.ZodTypeAny> = {};
|
|
21
|
+
|
|
22
|
+
for (const key in shape) {
|
|
23
|
+
|
|
24
|
+
if (!['newEntity', 'email'].includes(key))
|
|
25
|
+
continue;
|
|
26
|
+
|
|
27
|
+
let current: zod.ZodTypeAny = shape[key];
|
|
28
|
+
while (current) {
|
|
29
|
+
|
|
30
|
+
const origType = current.type;
|
|
31
|
+
const preprocessor = toPreprocess[origType];
|
|
32
|
+
|
|
33
|
+
if (origType === 'object') {
|
|
34
|
+
newShape[key] = preprocessSchema(current as zod.ZodObject);
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (preprocessor) {
|
|
39
|
+
newShape[key] = preprocessor(current);
|
|
40
|
+
console.log('====newShape', key, newShape[key]);
|
|
41
|
+
break;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
current = current.def;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const newSchema = zod.object(newShape);
|
|
49
|
+
newSchema.withPreprocessing = true;
|
|
50
|
+
return newSchema;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const toPreprocess = {
|
|
54
|
+
|
|
55
|
+
string: (zString: zod.ZodString) => zod.preprocess( val => {
|
|
56
|
+
return val === '' ? undefined : val;
|
|
57
|
+
}, zString),
|
|
58
|
+
|
|
59
|
+
int: (zInt: zod.ZodInt) => zod.preprocess( val => {
|
|
60
|
+
return typeof val === 'string' ? Number.parseInt(val) : val;
|
|
61
|
+
}, zInt),
|
|
62
|
+
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export const schema = {
|
|
66
|
+
...zod,
|
|
67
|
+
|
|
68
|
+
file: () => {
|
|
69
|
+
|
|
70
|
+
// Chaine = url ancien fichier = exclusion de la valeur pour conserver l'ancien fichier
|
|
71
|
+
// NOTE: Si la valeur est présente mais undefined, alors on supprimera le fichier
|
|
72
|
+
/*if (typeof val === 'string')
|
|
73
|
+
return true;*/
|
|
74
|
+
|
|
75
|
+
return zod.file();
|
|
76
|
+
},
|
|
77
|
+
|
|
78
|
+
choice: ( choices: string[] | { value: any, label: string }[] | _ZodType, options: { multiple?: boolean } = {} ) => {
|
|
79
|
+
|
|
80
|
+
const normalizeValue = (value: any) => typeof value === 'object' ? value.value : value;
|
|
81
|
+
|
|
82
|
+
const valueType: _ZodType = Array.isArray(choices)
|
|
83
|
+
? zod.enum( choices.map(normalizeValue) )
|
|
84
|
+
: zod.string();
|
|
85
|
+
|
|
86
|
+
const itemType = zod.union([
|
|
87
|
+
|
|
88
|
+
zod.object({ value: valueType, label: zod.string() }),
|
|
89
|
+
|
|
90
|
+
valueType
|
|
91
|
+
|
|
92
|
+
]);
|
|
93
|
+
|
|
94
|
+
const type = options.multiple ? zod.array( itemType ) : itemType;
|
|
95
|
+
|
|
96
|
+
return type.transform(v => {
|
|
97
|
+
if (options.multiple) {
|
|
98
|
+
return v.map(normalizeValue);
|
|
99
|
+
} else {
|
|
100
|
+
return normalizeValue(v);
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
},
|
|
104
|
+
|
|
105
|
+
richText: (opts: TRichTextValidatorOptions = {}) => schema.custom(val => {
|
|
106
|
+
|
|
107
|
+
if (typeof val !== 'string') {
|
|
108
|
+
console.error("Invalid rich text format.", val);
|
|
109
|
+
return false;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// We get a stringified json as input since the editor workds with JSON string
|
|
113
|
+
try {
|
|
114
|
+
val = JSON.parse(val);
|
|
115
|
+
} catch (error) {
|
|
116
|
+
console.error("Failed to parse rich text json:", error, val);
|
|
117
|
+
return false;//throw new InputError("Invalid rich text format.");
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// Check that the root exists and has a valid type
|
|
121
|
+
if (!val || typeof val !== 'object' || typeof val.root !== 'object' || val.root.type !== 'root') {
|
|
122
|
+
console.error("Invalid rich text value (1).", val);
|
|
123
|
+
return false;//throw new InputError("Invalid rich text value (1).");
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// Check if root has children array
|
|
127
|
+
if (!Array.isArray(val.root.children)) {
|
|
128
|
+
console.error("Invalid rich text value (2).", val);
|
|
129
|
+
return false;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// Validate each child node in root
|
|
133
|
+
for (const child of val.root.children) {
|
|
134
|
+
if (!validateLexicalNode(child, opts))
|
|
135
|
+
return false;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
return true;
|
|
139
|
+
})
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// Recursive function to validate each node
|
|
143
|
+
function validateLexicalNode(node: any, opts: TRichTextValidatorOptions ) {
|
|
144
|
+
|
|
145
|
+
// Each node should be an object with a `type` property
|
|
146
|
+
if (typeof node !== 'object' || !node.type || typeof node.type !== 'string')
|
|
147
|
+
throw new InputError("Invalid rich text value (3).");
|
|
148
|
+
|
|
149
|
+
// Validate text nodes
|
|
150
|
+
if (node.type === 'text') {
|
|
151
|
+
|
|
152
|
+
if (typeof node.text !== 'string')
|
|
153
|
+
throw new InputError("Invalid rich text value (4).");
|
|
154
|
+
|
|
155
|
+
// Validate paragraph, heading, or other structural nodes that may contain children
|
|
156
|
+
} else if (['paragraph', 'heading', 'list', 'listitem'].includes(node.type)) {
|
|
157
|
+
|
|
158
|
+
if (!Array.isArray(node.children) || !node.children.every(children => validateLexicalNode(children, opts))) {
|
|
159
|
+
throw new InputError("Invalid rich text value (5).");
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// Files upload
|
|
163
|
+
} else if (node.type === 'image') {
|
|
164
|
+
|
|
165
|
+
// Check if allowed
|
|
166
|
+
/*if (opts.attachements === undefined)
|
|
167
|
+
throw new InputError("Image attachments not allowed in this rich text field.");*/
|
|
168
|
+
|
|
169
|
+
// TODO: check mime
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
// Upload file
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
return true;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
export type { default as z } from 'zod';
|
|
@@ -12,7 +12,7 @@ import express from 'express';
|
|
|
12
12
|
|
|
13
13
|
// Core
|
|
14
14
|
import { Application } from '@server/app';
|
|
15
|
-
import type ServerRouter from '@server/services/router';
|
|
15
|
+
import type { RouterService, default as ServerRouter, TServerRouter } from '@server/services/router';
|
|
16
16
|
import ServerRequest from '@server/services/router/request';
|
|
17
17
|
import { TRoute, TAnyRoute, TDomainsList } from '@common/router';
|
|
18
18
|
import { NotFound, Forbidden, Anomaly } from '@common/errors';
|
|
@@ -38,31 +38,40 @@ export type TBasicSSrData = {
|
|
|
38
38
|
domains: TDomainsList
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
export type TRouterContext<TRouter extends
|
|
41
|
+
export type TRouterContext<TRouter extends TServerRouter> = (
|
|
42
42
|
// Request context
|
|
43
43
|
{
|
|
44
|
-
app:
|
|
44
|
+
app: TRouter["app"],
|
|
45
45
|
context: TRouterContext<TRouter>, // = this
|
|
46
46
|
request: ServerRequest<TRouter>,
|
|
47
47
|
api: ServerRequest<TRouter>["api"],
|
|
48
48
|
response: ServerResponse<TRouter>,
|
|
49
49
|
route: TRoute,
|
|
50
50
|
page?: Page,
|
|
51
|
-
user: TBasicUser,
|
|
52
51
|
|
|
53
52
|
Router: TRouter,
|
|
54
53
|
}
|
|
55
|
-
|
|
54
|
+
& TRouterContextServices<TRouter>
|
|
55
|
+
//& TRouterRequestContext<TRouter>
|
|
56
56
|
)
|
|
57
57
|
|
|
58
|
-
export type TRouterContextServices<
|
|
58
|
+
export type TRouterContextServices<
|
|
59
|
+
TRouter extends TServerRouter,
|
|
60
|
+
TPlugins = TRouter["config"]["plugins"]
|
|
61
|
+
> = (
|
|
59
62
|
// Custom context via servuces
|
|
60
63
|
// For each roiuter service, return the request service (returned by roiuterService.requestService() )
|
|
61
64
|
{
|
|
62
|
-
[serviceName in keyof
|
|
65
|
+
[serviceName in keyof TPlugins]: TPlugins[serviceName] extends RouterService
|
|
66
|
+
? ReturnType<TPlugins[serviceName]["requestService"]>
|
|
67
|
+
: TPlugins[serviceName]
|
|
63
68
|
}
|
|
64
69
|
)
|
|
65
70
|
|
|
71
|
+
export type TRouterRequestContext<
|
|
72
|
+
TRouter extends TServerRouter
|
|
73
|
+
> = ReturnType<TRouter["config"]["context"]>
|
|
74
|
+
|
|
66
75
|
|
|
67
76
|
/*----------------------------------
|
|
68
77
|
- CLASSE
|
|
@@ -212,7 +221,7 @@ export default class ServerResponse<
|
|
|
212
221
|
return this;
|
|
213
222
|
}
|
|
214
223
|
|
|
215
|
-
public async render( page: Page, context: TRouterContext
|
|
224
|
+
public async render( page: Page, context: TRouterContext<TRouter>, additionnalData: {} ) {
|
|
216
225
|
|
|
217
226
|
// Set page in context for the client side
|
|
218
227
|
context.page = page;
|
|
@@ -308,11 +317,11 @@ export default class ServerResponse<
|
|
|
308
317
|
return this.end();
|
|
309
318
|
}
|
|
310
319
|
|
|
311
|
-
public redirect(url: string, code: number = 302) {
|
|
320
|
+
public redirect(url: string, code: number = 302, absolute: boolean = false) {
|
|
312
321
|
|
|
313
322
|
debug && console.log("[routeur][response] Redirect", url);
|
|
314
323
|
this.statusCode = code;
|
|
315
|
-
this.headers['Location'] = this.router.url( url );
|
|
324
|
+
this.headers['Location'] = this.router.url( url, {}, absolute );
|
|
316
325
|
return this.end();
|
|
317
326
|
}
|
|
318
327
|
|
|
@@ -39,8 +39,9 @@ export default class DocumentRenderer<TRouter extends Router> {
|
|
|
39
39
|
<meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1" />
|
|
40
40
|
|
|
41
41
|
{/* CSS */}
|
|
42
|
-
<link rel="stylesheet" type="text/css" href="/public/icons.css" />
|
|
43
42
|
<link rel="preload" href="/public/client.css" as="style" />
|
|
43
|
+
<link rel="preload" as="font" href={"/public/icons.woff2?v=" + BUILD_ID} type="font/woff2" />
|
|
44
|
+
<link rel="stylesheet" type="text/css" href="/public/icons.css" />
|
|
44
45
|
<link rel="stylesheet" type="text/css" href="/public/client.css" />
|
|
45
46
|
<ColorSchemeScript />
|
|
46
47
|
|
|
@@ -120,6 +121,7 @@ export default class DocumentRenderer<TRouter extends Router> {
|
|
|
120
121
|
|
|
121
122
|
private styles( page: Page ) {
|
|
122
123
|
return <>
|
|
124
|
+
<link rel="preload" as="font" href={"/public/icons.woff2?v=" + BUILD_ID} type="font/woff2" />
|
|
123
125
|
<link rel="stylesheet" type="text/css" href={"/public/icons.css?" + BUILD_ID} />
|
|
124
126
|
<link rel="preload" href="/public/client.css" as="style" />
|
|
125
127
|
<link rel="stylesheet" type="text/css" href="/public/client.css" />
|
|
@@ -135,8 +137,8 @@ export default class DocumentRenderer<TRouter extends Router> {
|
|
|
135
137
|
|
|
136
138
|
private async scripts( response: ServerResponse<TRouter>, page: Page ) {
|
|
137
139
|
|
|
138
|
-
const
|
|
139
|
-
|
|
140
|
+
const ssrData = response.forSsr(page);
|
|
141
|
+
const context = safeStringify( ssrData );
|
|
140
142
|
const routesForClient = JSON.stringify( this.router.ssrRoutes );
|
|
141
143
|
|
|
142
144
|
return <>
|
|
@@ -11,7 +11,10 @@ import type { default as Router } from '.';
|
|
|
11
11
|
import type ServerRequest from './request';
|
|
12
12
|
import type RequestService from './request/service';
|
|
13
13
|
|
|
14
|
-
export type TRouterServiceArgs =
|
|
14
|
+
export type TRouterServiceArgs = [
|
|
15
|
+
getConfig: TServiceArgs<RouterService>[1],
|
|
16
|
+
app: Application,
|
|
17
|
+
];
|
|
15
18
|
|
|
16
19
|
/*----------------------------------
|
|
17
20
|
- SERVICE
|
|
@@ -20,10 +23,10 @@ export default abstract class RouterService<
|
|
|
20
23
|
TConfig extends {} = {}
|
|
21
24
|
> extends Service<TConfig, {}, Application> {
|
|
22
25
|
|
|
23
|
-
public constructor( ...
|
|
24
|
-
super(
|
|
26
|
+
public constructor( ...[config, app]: TRouterServiceArgs) {
|
|
27
|
+
super(app, config, app);
|
|
25
28
|
}
|
|
26
29
|
|
|
27
|
-
public abstract requestService( request: ServerRequest<
|
|
30
|
+
public abstract requestService( request: ServerRequest<RouterService> ): RequestService | {} | null;
|
|
28
31
|
|
|
29
32
|
}
|
|
@@ -2,15 +2,17 @@
|
|
|
2
2
|
- DEPENDANCES
|
|
3
3
|
----------------------------------*/
|
|
4
4
|
|
|
5
|
+
// Npm
|
|
6
|
+
import zod from 'zod';
|
|
7
|
+
import { SomeType } from 'zod/v4/core';
|
|
8
|
+
|
|
5
9
|
// Core
|
|
6
10
|
import {
|
|
7
|
-
default as Router,
|
|
11
|
+
default as Router, TServerRouter, Request as ServerRequest
|
|
8
12
|
} from '@server/services/router';
|
|
9
13
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
// Specific
|
|
13
|
-
import ServerSchemaValidator from '.';
|
|
14
|
+
// Ap
|
|
15
|
+
import { preprocessSchema, schema } from '@server/services/router/request/validation/zod';
|
|
14
16
|
|
|
15
17
|
/*----------------------------------
|
|
16
18
|
- SERVICE CONFIG
|
|
@@ -25,38 +27,23 @@ export type TConfig = {
|
|
|
25
27
|
/*----------------------------------
|
|
26
28
|
- SERVICE
|
|
27
29
|
----------------------------------*/
|
|
28
|
-
export default
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
public app = router.app
|
|
35
|
-
) {
|
|
36
|
-
|
|
37
|
-
super(app);
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
public validate<TSchemaFieldsA extends TSchemaFields>(
|
|
42
|
-
fields: TSchemaFieldsA | Schema<TSchemaFieldsA>
|
|
43
|
-
): TValidatedData<TSchemaFieldsA> {
|
|
30
|
+
export default(
|
|
31
|
+
request: ServerRequest< TServerRouter >,
|
|
32
|
+
config: TConfig,
|
|
33
|
+
router = request.router,
|
|
34
|
+
app = router.app
|
|
35
|
+
) => ({
|
|
44
36
|
|
|
45
|
-
|
|
37
|
+
...schema,
|
|
46
38
|
|
|
47
|
-
|
|
39
|
+
validate( fields: zod.ZodSchema | { [key: string]: zod.ZodSchema } ) {
|
|
48
40
|
|
|
49
|
-
|
|
50
|
-
const values = schema.validate( this.request.data, {
|
|
51
|
-
debug: this.config.debug,
|
|
52
|
-
validateDeps: false,
|
|
53
|
-
validators: this
|
|
54
|
-
}, []);
|
|
41
|
+
config.debug && console.log(LogPrefix, "Validate request data:", request.data);
|
|
55
42
|
|
|
56
|
-
|
|
57
|
-
this.request.validatedData = values;
|
|
43
|
+
const schema = typeof fields === 'object' ? zod.object(fields) : fields;
|
|
58
44
|
|
|
59
|
-
|
|
60
|
-
}
|
|
45
|
+
const preprocessedSchema = preprocessSchema(schema);
|
|
61
46
|
|
|
62
|
-
|
|
47
|
+
return preprocessedSchema.parse(request.data);
|
|
48
|
+
},
|
|
49
|
+
})
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
RouterService
|
|
9
9
|
} from '@server/services/router';
|
|
10
10
|
|
|
11
|
-
import
|
|
11
|
+
import makeRequestValidators from '../request';
|
|
12
12
|
|
|
13
13
|
/*----------------------------------
|
|
14
14
|
- TYPES
|
|
@@ -22,7 +22,7 @@ export default class SchemaRouterService<
|
|
|
22
22
|
TUser extends {} = {}
|
|
23
23
|
> extends RouterService {
|
|
24
24
|
|
|
25
|
-
public requestService( request: ServerRequest )
|
|
26
|
-
return
|
|
25
|
+
public requestService( request: ServerRequest ) {
|
|
26
|
+
return makeRequestValidators( request, this.config );
|
|
27
27
|
}
|
|
28
28
|
}
|
package/types/global/utils.d.ts
CHANGED
|
@@ -63,11 +63,29 @@ declare type PrimitiveValue = string | number | boolean;
|
|
|
63
63
|
- COPY FROM CLI/APP/INDEX.TS
|
|
64
64
|
----------------------------------*/
|
|
65
65
|
|
|
66
|
-
type TEnvConfig = {
|
|
66
|
+
/*type TEnvConfig = {
|
|
67
67
|
name: 'local' | 'server',
|
|
68
|
-
profile: 'dev' | 'prod',
|
|
69
|
-
|
|
70
|
-
|
|
68
|
+
profile: 'dev' | 'testing' | 'prod',
|
|
69
|
+
|
|
70
|
+
router: {
|
|
71
|
+
port: number,
|
|
72
|
+
domains: TDomainsList
|
|
73
|
+
},
|
|
74
|
+
database: {
|
|
75
|
+
name: string,
|
|
76
|
+
databases: string[],
|
|
77
|
+
host: string,
|
|
78
|
+
port: number,
|
|
79
|
+
login: string,
|
|
80
|
+
password: string,
|
|
81
|
+
},
|
|
82
|
+
console: {
|
|
83
|
+
enable: boolean,
|
|
84
|
+
debug: boolean,
|
|
85
|
+
bufferLimit: number,
|
|
86
|
+
level: TLogProfile,
|
|
87
|
+
},
|
|
88
|
+
}*/
|
|
71
89
|
|
|
72
90
|
type TServiceSetup = {
|
|
73
91
|
id: string,
|
package/types/icons.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export type TIcones = "solid/spinner-third"|"
|
|
1
|
+
export type TIcones = "solid/spinner-third"|"times"|"at"|"star"|"plus"|"minus"|"trash"|"user-circle"|"search"|"long-arrow-right"|"lightbulb"|"long-arrow-left"|"magnet"|"phone"|"brands/linkedin"|"arrow-right"|"plane-departure"|"plus-circle"|"comments-alt"|"rocket"|"user-shield"|"shield-alt"|"chart-line"|"money-bill-wave"|"link"|"file-alt"|"paper-plane"|"solid/crown"|"eye"|"pen"|"file"|"angle-up"|"angle-down"|"envelope"|"play"|"stop"|"clock"|"cog"|"ellipsis-h"|"check"|"user-plus"|"sack-dollar"|"info-circle"|"mouse-pointer"|"thumbs-up"|"dollar-sign"|"regular/shield-check"|"download"|"brands/google"|"brands/whatsapp"|"crown"|"check-circle"|"exclamation-circle"|"times-circle"|"arrow-left"|"key"|"broom"|"arrow-to-bottom"|"minus-circle"|"map-marker-alt"|"solid/check-circle"|"solid/exclamation-triangle"|"solid/times-circle"|"hourglass"|"external-link"|"user"|"building"|"briefcase"|"graduation-cap"|"angle-left"|"angle-right"|"plug"|"magic"|"coins"|"coin"|"question-circle"|"meh-rolling-eyes"|"bold"|"italic"|"underline"|"strikethrough"|"subscript"|"superscript"|"code"|"unlink"|"font"|"empty-set"|"horizontal-rule"|"page-break"|"image"|"table"|"poll"|"columns"|"sticky-note"|"caret-right"|"list-ul"|"check-square"|"h1"|"h2"|"h3"|"h4"|"list-ol"|"paragraph"|"quote-left"|"align-left"|"align-center"|"align-right"|"align-justify"|"indent"|"outdent"
|
|
@@ -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
|
-
};
|