5htp-core 0.6.2-7 → 0.6.2-9
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/components/Input.tsx +0 -2
- package/package.json +1 -1
- package/server/app/service/index.ts +32 -5
- package/server/services/disks/index.ts +4 -4
- package/server/services/prisma/Facet.ts +34 -14
- package/server/services/prisma/index.ts +5 -7
- package/server/services/router/index.ts +18 -13
- package/server/services/router/request/validation/zod.ts +44 -9
- package/server/services/router/response/index.ts +7 -4
- package/server/services/schema/request.ts +20 -35
- 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
|
@@ -13,8 +13,6 @@ import {
|
|
|
13
13
|
|
|
14
14
|
// Core libs
|
|
15
15
|
import { InputBaseProps, useMantineInput } from './utils';
|
|
16
|
-
import { default as Validator } from '../../server/services/router/request/validation/validator';
|
|
17
|
-
import type { SchemaValidators } from '@server/services/router/request/validation/validators';
|
|
18
16
|
|
|
19
17
|
/*----------------------------------
|
|
20
18
|
- TYPES
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "5htp-core",
|
|
3
3
|
"description": "Convenient TypeScript framework designed for Performance and Productivity.",
|
|
4
|
-
"version": "0.6.2-
|
|
4
|
+
"version": "0.6.2-9",
|
|
5
5
|
"author": "Gaetan Le Gac (https://github.com/gaetanlegac)",
|
|
6
6
|
"repository": "git://github.com/gaetanlegac/5htp-core.git",
|
|
7
7
|
"license": "MIT",
|
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
- DEPENDANCES
|
|
3
3
|
----------------------------------*/
|
|
4
4
|
|
|
5
|
+
// Npm
|
|
6
|
+
import zod from 'zod';
|
|
7
|
+
|
|
5
8
|
// Specific
|
|
6
9
|
import type { Application } from "..";
|
|
7
10
|
import type { Command } from "../commands";
|
|
@@ -10,6 +13,7 @@ import type { TControllerDefinition, TRoute } from '../../services/router';
|
|
|
10
13
|
import { Anomaly } from "@common/errors";
|
|
11
14
|
|
|
12
15
|
export { schema } from '../../services/router/request/validation/zod';
|
|
16
|
+
export type { z } from '../../services/router/request/validation/zod';
|
|
13
17
|
|
|
14
18
|
/*----------------------------------
|
|
15
19
|
- TYPES: OPTIONS
|
|
@@ -52,7 +56,30 @@ export type TServiceArgs<TService extends AnyService> = [
|
|
|
52
56
|
|
|
53
57
|
const LogPrefix = '[service]';
|
|
54
58
|
|
|
55
|
-
|
|
59
|
+
type TDecoratorArgs = (
|
|
60
|
+
[path: string] |
|
|
61
|
+
[path: string, schema: zod.ZodSchema] |
|
|
62
|
+
[path: string, schema: zod.ZodSchema, options?: Omit<TControllerDefinition, 'controller'|'schema'|'path'>] |
|
|
63
|
+
[options: Omit<TControllerDefinition, 'controller'>]
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
export function Route( ...args: TDecoratorArgs ) {
|
|
67
|
+
|
|
68
|
+
let path: string | undefined;
|
|
69
|
+
let schema: zod.ZodSchema | undefined;
|
|
70
|
+
let options: Omit<TControllerDefinition, 'controller'|'schema'|'path'> = {};
|
|
71
|
+
|
|
72
|
+
if (typeof args[0] === 'object') {
|
|
73
|
+
const { path: path_, schema: schema_, ...options_ } = args[0];
|
|
74
|
+
path = path_;
|
|
75
|
+
schema = schema_;
|
|
76
|
+
options = options_;
|
|
77
|
+
} else {
|
|
78
|
+
path = args[0];
|
|
79
|
+
schema = args[1];
|
|
80
|
+
options = args[2] || {};
|
|
81
|
+
}
|
|
82
|
+
|
|
56
83
|
return function (
|
|
57
84
|
target: any,
|
|
58
85
|
propertyKey: string,
|
|
@@ -61,8 +88,8 @@ export function Route(options: Omit<TControllerDefinition, 'controller'> = {}) {
|
|
|
61
88
|
// Store the original method
|
|
62
89
|
const originalMethod = descriptor.value;
|
|
63
90
|
|
|
64
|
-
if (
|
|
65
|
-
|
|
91
|
+
if (path === undefined)
|
|
92
|
+
path = target.constructor.name + '/' + propertyKey;
|
|
66
93
|
|
|
67
94
|
// Ensure the class has a static property to collect routes
|
|
68
95
|
if (!target.__routes) {
|
|
@@ -72,9 +99,9 @@ export function Route(options: Omit<TControllerDefinition, 'controller'> = {}) {
|
|
|
72
99
|
// Create route object
|
|
73
100
|
const route: TRoute = {
|
|
74
101
|
method: 'POST',
|
|
75
|
-
path: '/api/' +
|
|
102
|
+
path: '/api/' + path,
|
|
76
103
|
controller: originalMethod,
|
|
77
|
-
schema:
|
|
104
|
+
schema: schema,
|
|
78
105
|
options: {
|
|
79
106
|
priority: options.priority || 0
|
|
80
107
|
}
|
|
@@ -34,9 +34,9 @@ export type Services = {
|
|
|
34
34
|
- SERVICE
|
|
35
35
|
----------------------------------*/
|
|
36
36
|
export default class DisksManager<
|
|
37
|
-
MountpointList extends Services
|
|
38
|
-
TConfig extends Config
|
|
39
|
-
TApplication extends Application
|
|
37
|
+
MountpointList extends Services,
|
|
38
|
+
TConfig extends Config,
|
|
39
|
+
TApplication extends Application
|
|
40
40
|
> extends Service<TConfig, Hooks, TApplication> {
|
|
41
41
|
|
|
42
42
|
public default!: Driver;
|
|
@@ -45,7 +45,7 @@ export default class DisksManager<
|
|
|
45
45
|
- LIFECYCLE
|
|
46
46
|
----------------------------------*/
|
|
47
47
|
|
|
48
|
-
public constructor( ...args: TServiceArgs<DisksManager
|
|
48
|
+
public constructor( ...args: TServiceArgs<DisksManager<MountpointList, TConfig, TApplication>>) {
|
|
49
49
|
|
|
50
50
|
super(...args);
|
|
51
51
|
|
|
@@ -1,6 +1,34 @@
|
|
|
1
1
|
import type { Prisma, PrismaClient } from '@models/types';
|
|
2
2
|
import * as runtime from '@/var/prisma/runtime/library.js';
|
|
3
3
|
|
|
4
|
+
/*export type TDelegate<R> = {
|
|
5
|
+
findMany(args?: any): Promise<R[]>
|
|
6
|
+
findFirst(args?: any): Promise<R | null>
|
|
7
|
+
}*/
|
|
8
|
+
|
|
9
|
+
/*
|
|
10
|
+
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
export type TDelegate<R> = PrismaClient[string];
|
|
15
|
+
|
|
16
|
+
/*export type TExtractPayload<D extends TDelegate<never>> =
|
|
17
|
+
D extends { [K in symbol]: { types: { payload: infer P } } } ? P : never;
|
|
18
|
+
|
|
19
|
+
export type TExtractPayload2<D> =
|
|
20
|
+
D extends { [K: symbol]: { types: Prisma.TypeMap<infer E>['model'][infer M] } }
|
|
21
|
+
? Prisma.TypeMap<E>['model'][M & keyof Prisma.TypeMap<E>['model']]['payload']
|
|
22
|
+
: never;*/
|
|
23
|
+
|
|
24
|
+
export type Transform<S extends TSubset, R, RT> = (
|
|
25
|
+
row: runtime.Types.Result.GetResult<
|
|
26
|
+
Prisma.$ProspectContactLeadPayload,
|
|
27
|
+
ReturnType<S>,
|
|
28
|
+
'findMany'
|
|
29
|
+
>[number]
|
|
30
|
+
) => RT
|
|
31
|
+
|
|
4
32
|
export type TWithStats = {
|
|
5
33
|
$table: string,
|
|
6
34
|
$key: string
|
|
@@ -13,12 +41,10 @@ export type TSubset = (...a: any[]) => Prisma.ProspectContactLeadFindFirstArgs &
|
|
|
13
41
|
}
|
|
14
42
|
|
|
15
43
|
export default class Facet<
|
|
16
|
-
D extends
|
|
17
|
-
findMany(args?: any): Promise<any>
|
|
18
|
-
findFirst(args?: any): Promise<any>
|
|
19
|
-
},
|
|
44
|
+
D extends TDelegate<R>,
|
|
20
45
|
S extends TSubset,
|
|
21
|
-
R
|
|
46
|
+
R, // Result type
|
|
47
|
+
RT // Transformed result type
|
|
22
48
|
> {
|
|
23
49
|
constructor(
|
|
24
50
|
|
|
@@ -28,18 +54,12 @@ export default class Facet<
|
|
|
28
54
|
private readonly subset: S,
|
|
29
55
|
|
|
30
56
|
/* the **ONLY** line that changed ↓↓↓ */
|
|
31
|
-
private readonly transform?:
|
|
32
|
-
row: runtime.Types.Result.GetResult<
|
|
33
|
-
Prisma.$ProspectContactLeadPayload,
|
|
34
|
-
ReturnType<S>,
|
|
35
|
-
'findMany'
|
|
36
|
-
>[number]
|
|
37
|
-
) => R,
|
|
57
|
+
private readonly transform?: Transform<S, R, RT>,
|
|
38
58
|
) { }
|
|
39
59
|
|
|
40
60
|
public async findMany(
|
|
41
61
|
...args: Parameters<S>
|
|
42
|
-
): Promise<
|
|
62
|
+
): Promise<RT[]> {
|
|
43
63
|
|
|
44
64
|
const { withStats, ...subset } = this.subset(...args);
|
|
45
65
|
|
|
@@ -57,7 +77,7 @@ export default class Facet<
|
|
|
57
77
|
|
|
58
78
|
public async findFirst(
|
|
59
79
|
...args: Parameters<S>
|
|
60
|
-
): Promise<
|
|
80
|
+
): Promise<RT | null> {
|
|
61
81
|
|
|
62
82
|
const { withStats, ...subset } = this.subset(...args);
|
|
63
83
|
|
|
@@ -10,7 +10,7 @@ import type { Application } from '@server/app';
|
|
|
10
10
|
import Service from '@server/app/service';
|
|
11
11
|
|
|
12
12
|
// Specific
|
|
13
|
-
import Facet, { TSubset } from './Facet';
|
|
13
|
+
import Facet, { TDelegate, TSubset, Transform } from './Facet';
|
|
14
14
|
|
|
15
15
|
/*----------------------------------
|
|
16
16
|
- TYPES
|
|
@@ -52,13 +52,11 @@ export default class ModelsManager extends Service<Config, Hooks, Application> {
|
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
public Facet<
|
|
55
|
-
D extends
|
|
56
|
-
findMany(args?: any): Promise<any>
|
|
57
|
-
findFirst(args?: any): Promise<any>
|
|
58
|
-
},
|
|
55
|
+
D extends TDelegate<R>,
|
|
59
56
|
S extends TSubset,
|
|
60
|
-
R
|
|
61
|
-
|
|
57
|
+
R,
|
|
58
|
+
RT
|
|
59
|
+
>(...args: [D, S, Transform<S, R, RT>]) {
|
|
62
60
|
|
|
63
61
|
return new Facet(
|
|
64
62
|
this.client,
|
|
@@ -55,7 +55,7 @@ export type { default as Request, UploadedFile } from "./request";
|
|
|
55
55
|
export type { default as Response, TRouterContext } from "./response";
|
|
56
56
|
export type { TRoute, TAnyRoute } from '@common/router';
|
|
57
57
|
|
|
58
|
-
export type TApiRegisterArgs<TRouter extends ServerRouter
|
|
58
|
+
export type TApiRegisterArgs<TRouter extends ServerRouter<Application>> = ([
|
|
59
59
|
path: string,
|
|
60
60
|
controller: TServerController<TRouter>
|
|
61
61
|
] | [
|
|
@@ -64,7 +64,7 @@ export type TApiRegisterArgs<TRouter extends ServerRouter> = ([
|
|
|
64
64
|
controller: TServerController<TRouter>
|
|
65
65
|
])
|
|
66
66
|
|
|
67
|
-
export type TServerController<TRouter extends ServerRouter
|
|
67
|
+
export type TServerController<TRouter extends ServerRouter<Application>> = (context: TRouterContext<TRouter>) => any;
|
|
68
68
|
|
|
69
69
|
export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'OPTIONS'
|
|
70
70
|
export type TRouteHttpMethod = HttpMethod | '*';
|
|
@@ -83,8 +83,8 @@ export type HttpHeaders = { [cle: string]: string }
|
|
|
83
83
|
const LogPrefix = '[router]';
|
|
84
84
|
|
|
85
85
|
export type Config<
|
|
86
|
-
TServiceList extends TRouterServicesList
|
|
87
|
-
TAdditionnalSsrData extends {}
|
|
86
|
+
TServiceList extends TRouterServicesList,
|
|
87
|
+
TAdditionnalSsrData extends {}
|
|
88
88
|
> = {
|
|
89
89
|
|
|
90
90
|
debug: boolean,
|
|
@@ -96,18 +96,16 @@ export type Config<
|
|
|
96
96
|
http: HttpServiceConfig,
|
|
97
97
|
|
|
98
98
|
context: (
|
|
99
|
-
request: ServerRequest<
|
|
99
|
+
request: ServerRequest<TServerRouter>,
|
|
100
100
|
app: Application
|
|
101
101
|
) => TAdditionnalSsrData,
|
|
102
102
|
|
|
103
|
-
plugins:
|
|
104
|
-
[routerServiceId: string]: RouterService
|
|
105
|
-
}
|
|
103
|
+
plugins: TServiceList
|
|
106
104
|
}
|
|
107
105
|
|
|
108
106
|
// Set it as a function, so when we instanciate the services, we can callthis.router to pass the router instance in roiuter services
|
|
109
107
|
type TRouterServicesList = {
|
|
110
|
-
[serviceName: string]: RouterService<
|
|
108
|
+
[serviceName: string]: RouterService<TServerRouter>
|
|
111
109
|
}
|
|
112
110
|
|
|
113
111
|
export type Hooks = {
|
|
@@ -117,14 +115,21 @@ export type Hooks = {
|
|
|
117
115
|
export type TControllerDefinition = {
|
|
118
116
|
path?: string,
|
|
119
117
|
schema?: zod.ZodSchema,
|
|
120
|
-
controller: TServerController<
|
|
118
|
+
controller: TServerController<TServerRouter>,
|
|
121
119
|
}
|
|
122
120
|
|
|
121
|
+
export type TServerRouter = ServerRouter<Application, Config<TRouterServicesList, {}>, TRouterServicesList, {}>;
|
|
122
|
+
|
|
123
123
|
/*----------------------------------
|
|
124
124
|
- CLASSE
|
|
125
125
|
----------------------------------*/
|
|
126
|
-
export default class ServerRouter
|
|
127
|
-
extends
|
|
126
|
+
export default class ServerRouter<
|
|
127
|
+
TApplication extends Application,
|
|
128
|
+
TConfig extends Config<TServiceList, TAdditionnalSsrData>,
|
|
129
|
+
TServiceList extends TRouterServicesList,
|
|
130
|
+
TAdditionnalSsrData extends {}
|
|
131
|
+
>
|
|
132
|
+
extends Service<TConfig, Hooks, TApplication> implements BaseRouter {
|
|
128
133
|
|
|
129
134
|
public disks = this.use<DisksManager>('Core/Disks', { optional: true });
|
|
130
135
|
|
|
@@ -151,7 +156,7 @@ export default class ServerRouter
|
|
|
151
156
|
- SERVICE
|
|
152
157
|
----------------------------------*/
|
|
153
158
|
|
|
154
|
-
public constructor( ...args: TServiceArgs<ServerRouter>) {
|
|
159
|
+
public constructor( ...args: TServiceArgs< ServerRouter<TApplication, TConfig, TServiceList, TAdditionnalSsrData> >) {
|
|
155
160
|
|
|
156
161
|
super(...args);
|
|
157
162
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { InputError } from '@common/errors';
|
|
2
|
-
import zod from 'zod';
|
|
2
|
+
import zod, { _ZodType } from 'zod';
|
|
3
3
|
|
|
4
4
|
export type TRichTextValidatorOptions = {
|
|
5
5
|
attachements?: boolean
|
|
@@ -46,18 +46,51 @@ function validateLexicalNode(node: any, opts: TRichTextValidatorOptions ) {
|
|
|
46
46
|
export const schema = {
|
|
47
47
|
...zod,
|
|
48
48
|
|
|
49
|
-
file: (
|
|
49
|
+
file: () => {
|
|
50
50
|
|
|
51
51
|
// Chaine = url ancien fichier = exclusion de la valeur pour conserver l'ancien fichier
|
|
52
52
|
// NOTE: Si la valeur est présente mais undefined, alors on supprimera le fichier
|
|
53
|
-
if (typeof val === 'string')
|
|
54
|
-
return true
|
|
53
|
+
/*if (typeof val === 'string')
|
|
54
|
+
return true;*/
|
|
55
55
|
|
|
56
|
-
|
|
57
|
-
|
|
56
|
+
return zod.file();
|
|
57
|
+
},
|
|
58
58
|
|
|
59
|
-
|
|
60
|
-
|
|
59
|
+
int: () => zod.preprocess( val => {
|
|
60
|
+
|
|
61
|
+
if (typeof val === "string")
|
|
62
|
+
return Number.parseInt(val);
|
|
63
|
+
|
|
64
|
+
return val;
|
|
65
|
+
|
|
66
|
+
}, zod.int()),
|
|
67
|
+
|
|
68
|
+
choice: ( choices: string[] | { value: any, label: string }[] | _ZodType, options: { multiple?: boolean } = {} ) => {
|
|
69
|
+
|
|
70
|
+
const normalizeValue = (value: any) => typeof value === 'object' ? value.value : value;
|
|
71
|
+
|
|
72
|
+
const valueType: _ZodType = Array.isArray(choices)
|
|
73
|
+
? zod.enum( choices.map(normalizeValue) )
|
|
74
|
+
: zod.string();
|
|
75
|
+
|
|
76
|
+
const itemType = zod.union([
|
|
77
|
+
|
|
78
|
+
zod.object({ value: valueType, label: zod.string() }),
|
|
79
|
+
|
|
80
|
+
valueType
|
|
81
|
+
|
|
82
|
+
]);
|
|
83
|
+
|
|
84
|
+
const type = options.multiple ? zod.array( itemType ) : itemType;
|
|
85
|
+
|
|
86
|
+
return type.transform(v => {
|
|
87
|
+
if (options.multiple) {
|
|
88
|
+
return v.map(normalizeValue);
|
|
89
|
+
} else {
|
|
90
|
+
return normalizeValue(v);
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
},
|
|
61
94
|
|
|
62
95
|
richText: (opts: TRichTextValidatorOptions = {}) => schema.custom(val => {
|
|
63
96
|
|
|
@@ -94,4 +127,6 @@ export const schema = {
|
|
|
94
127
|
|
|
95
128
|
return true;
|
|
96
129
|
})
|
|
97
|
-
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export type { default as z } from 'zod';
|
|
@@ -41,7 +41,7 @@ export type TBasicSSrData = {
|
|
|
41
41
|
export type TRouterContext<TRouter extends ServerRouter = ServerRouter> = (
|
|
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"],
|
|
@@ -52,14 +52,17 @@ export type TRouterContext<TRouter extends ServerRouter = ServerRouter> = (
|
|
|
52
52
|
|
|
53
53
|
Router: TRouter,
|
|
54
54
|
}
|
|
55
|
-
|
|
55
|
+
& TRouterContextServices<TRouter>
|
|
56
56
|
)
|
|
57
57
|
|
|
58
|
-
export type TRouterContextServices<
|
|
58
|
+
export type TRouterContextServices<
|
|
59
|
+
TRouter extends ServerRouter<Application>,
|
|
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]
|
|
63
66
|
}
|
|
64
67
|
)
|
|
65
68
|
|
|
@@ -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 { schema } from '@server/services/router/request/validation/zod';
|
|
14
16
|
|
|
15
17
|
/*----------------------------------
|
|
16
18
|
- SERVICE CONFIG
|
|
@@ -25,38 +27,21 @@ 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> {
|
|
44
|
-
|
|
45
|
-
this.config.debug && console.log(LogPrefix, "Validate request data:", this.request.data);
|
|
30
|
+
export default(
|
|
31
|
+
request: ServerRequest< TServerRouter >,
|
|
32
|
+
config: TConfig,
|
|
33
|
+
router = request.router,
|
|
34
|
+
app = router.app
|
|
35
|
+
) => ({
|
|
46
36
|
|
|
47
|
-
|
|
37
|
+
...schema,
|
|
48
38
|
|
|
49
|
-
|
|
50
|
-
const values = schema.validate( this.request.data, {
|
|
51
|
-
debug: this.config.debug,
|
|
52
|
-
validateDeps: false,
|
|
53
|
-
validators: this
|
|
54
|
-
}, []);
|
|
39
|
+
validate( fields: zod.ZodSchema | { [key: string]: zod.ZodSchema } ) {
|
|
55
40
|
|
|
56
|
-
|
|
57
|
-
this.request.validatedData = values;
|
|
41
|
+
config.debug && console.log(LogPrefix, "Validate request data:", request.data);
|
|
58
42
|
|
|
59
|
-
|
|
60
|
-
}
|
|
43
|
+
const schema = typeof fields === 'object' ? zod.object(fields) : fields;
|
|
61
44
|
|
|
62
|
-
|
|
45
|
+
return schema.parse(request.data);
|
|
46
|
+
},
|
|
47
|
+
})
|
|
@@ -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/icons.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export type TIcones = "solid/spinner-third"|"
|
|
1
|
+
export type TIcones = "times"|"solid/spinner-third"|"long-arrow-right"|"check-circle"|"rocket"|"crosshairs"|"plane-departure"|"plus-circle"|"comments-alt"|"arrow-right"|"chart-bar"|"user-circle"|"user-shield"|"shield-alt"|"chart-line"|"money-bill-wave"|"star"|"link"|"file-alt"|"long-arrow-left"|"calendar-alt"|"paper-plane"|"at"|"search"|"lightbulb"|"magnet"|"phone"|"brands/linkedin"|"user-plus"|"sack-dollar"|"info-circle"|"mouse-pointer"|"thumbs-up"|"dollar-sign"|"brands/whatsapp"|"user"|"plus"|"minus"|"trash"|"play"|"stop"|"solid/crown"|"eye"|"pen"|"file"|"envelope"|"angle-up"|"angle-down"|"check"|"clock"|"cog"|"ellipsis-h"|"coins"|"regular/shield-check"|"download"|"exclamation-circle"|"times-circle"|"meh-rolling-eyes"|"arrow-left"|"bars"|"chevron-left"|"bolt"|"key"|"power-off"|"comment-alt"|"question-circle"|"minus-circle"|"wind"|"external-link"|"broom"|"solid/check-circle"|"solid/exclamation-triangle"|"solid/times-circle"|"hourglass"|"building"|"briefcase"|"map-marker-alt"|"graduation-cap"|"brands/google"|"coin"|"angle-left"|"angle-right"|"users"|"bug"|"binoculars"|"arrow-to-bottom"|"plug"|"copy"|"solid/magic"|"map-marker"|"fire"|"globe"|"industry"|"calendar"|"magic"|"code"|"bold"|"italic"|"underline"|"font"|"strikethrough"|"subscript"|"superscript"|"empty-set"|"horizontal-rule"|"page-break"|"image"|"table"|"poll"|"columns"|"sticky-note"|"caret-right"|"unlink"|"align-left"|"align-center"|"align-right"|"align-justify"|"indent"|"outdent"|"list-ul"|"check-square"|"h1"|"h2"|"h3"|"h4"|"list-ol"|"paragraph"|"quote-left"
|
|
@@ -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
|
-
};
|