@adonisjs/core 6.1.5-20 → 6.1.5-22
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/build/modules/http/main.d.ts +1 -0
- package/build/modules/http/main.js +1 -0
- package/build/modules/http/request_validator.d.ts +4 -14
- package/build/modules/http/request_validator.js +0 -8
- package/build/providers/edge_provider.d.ts +22 -1
- package/build/providers/edge_provider.js +50 -3
- package/build/providers/repl_provider.js +65 -2
- package/build/providers/vinejs_provider.d.ts +32 -4
- package/build/providers/vinejs_provider.js +75 -4
- package/build/src/test_utils/main.d.ts +1 -1
- package/build/types/http.d.ts +7 -0
- package/package.json +2 -2
- package/build/src/bindings/edge/main.d.ts +0 -7
- package/build/src/bindings/edge/main.js +0 -58
- package/build/src/bindings/edge/types.d.ts +0 -18
- package/build/src/bindings/edge/types.js +0 -9
- package/build/src/bindings/repl.d.ts +0 -6
- package/build/src/bindings/repl.js +0 -78
- package/build/src/bindings/vinejs/main.d.ts +0 -13
- package/build/src/bindings/vinejs/main.js +0 -76
- package/build/src/bindings/vinejs/types.d.ts +0 -12
- package/build/src/bindings/vinejs/types.js +0 -9
|
@@ -1,16 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type { Infer, SchemaTypes,
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
interface Request extends RequestValidator {
|
|
6
|
-
}
|
|
7
|
-
}
|
|
8
|
-
/**
|
|
9
|
-
* Request validation options with custom data as well
|
|
10
|
-
*/
|
|
11
|
-
type RequestValidationOptions<MetaData extends undefined | Record<string, any>> = ValidationOptions<MetaData> & {
|
|
12
|
-
data?: any;
|
|
13
|
-
};
|
|
1
|
+
import type { VineValidator } from '@vinejs/vine';
|
|
2
|
+
import type { Infer, SchemaTypes, ErrorReporterContract, MessagesProviderContact } from '@vinejs/vine/types';
|
|
3
|
+
import type { HttpContext } from './main.js';
|
|
4
|
+
import type { RequestValidationOptions } from '../../types/http.js';
|
|
14
5
|
/**
|
|
15
6
|
* Request validator is used validate HTTP request data using
|
|
16
7
|
* VineJS validators. You may validate the request body,
|
|
@@ -41,4 +32,3 @@ export declare class RequestValidator {
|
|
|
41
32
|
*/
|
|
42
33
|
validateUsing<Schema extends SchemaTypes, MetaData extends undefined | Record<string, any>>(validator: VineValidator<Schema, MetaData>, ...[options]: [undefined] extends MetaData ? [options?: RequestValidationOptions<MetaData> | undefined] : [options: RequestValidationOptions<MetaData>]): Promise<Infer<Schema>>;
|
|
43
34
|
}
|
|
44
|
-
export {};
|
|
@@ -6,7 +6,6 @@
|
|
|
6
6
|
* For the full copyright and license information, please view the LICENSE
|
|
7
7
|
* file that was distributed with this source code.
|
|
8
8
|
*/
|
|
9
|
-
import { Request } from '@adonisjs/http-server';
|
|
10
9
|
/**
|
|
11
10
|
* Request validator is used validate HTTP request data using
|
|
12
11
|
* VineJS validators. You may validate the request body,
|
|
@@ -65,10 +64,3 @@ export class RequestValidator {
|
|
|
65
64
|
return validator.validate(data, validatorOptions);
|
|
66
65
|
}
|
|
67
66
|
}
|
|
68
|
-
/**
|
|
69
|
-
* The validate method can be used to validate the request
|
|
70
|
-
* data for the current request using VineJS validators
|
|
71
|
-
*/
|
|
72
|
-
Request.macro('validateUsing', function (...args) {
|
|
73
|
-
return new RequestValidator(this.ctx).validateUsing(...args);
|
|
74
|
-
});
|
|
@@ -1,5 +1,26 @@
|
|
|
1
|
-
import '
|
|
1
|
+
import { type Edge } from 'edge.js';
|
|
2
2
|
import type { ApplicationService } from '../src/types.js';
|
|
3
|
+
import { type Route } from '../modules/http/main.js';
|
|
4
|
+
declare module '@adonisjs/core/http' {
|
|
5
|
+
interface HttpContext {
|
|
6
|
+
/**
|
|
7
|
+
* Reference to the edge renderer to render templates
|
|
8
|
+
* during an HTTP request
|
|
9
|
+
*/
|
|
10
|
+
view: ReturnType<Edge['createRenderer']>;
|
|
11
|
+
}
|
|
12
|
+
interface BriskRoute {
|
|
13
|
+
/**
|
|
14
|
+
* Render an edge template without defining an
|
|
15
|
+
* explicit route handler
|
|
16
|
+
*/
|
|
17
|
+
render(template: string, data?: Record<string, any>): Route;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* The Edge service provider configures Edge to work within
|
|
22
|
+
* an AdonisJS application environment
|
|
23
|
+
*/
|
|
3
24
|
export default class EdgeServiceProvider {
|
|
4
25
|
protected app: ApplicationService;
|
|
5
26
|
constructor(app: ApplicationService);
|
|
@@ -6,8 +6,12 @@
|
|
|
6
6
|
* For the full copyright and license information, please view the LICENSE
|
|
7
7
|
* file that was distributed with this source code.
|
|
8
8
|
*/
|
|
9
|
-
import '
|
|
10
|
-
import {
|
|
9
|
+
import edge from 'edge.js';
|
|
10
|
+
import { BriskRoute, HttpContext } from '../modules/http/main.js';
|
|
11
|
+
/**
|
|
12
|
+
* The Edge service provider configures Edge to work within
|
|
13
|
+
* an AdonisJS application environment
|
|
14
|
+
*/
|
|
11
15
|
export default class EdgeServiceProvider {
|
|
12
16
|
app;
|
|
13
17
|
constructor(app) {
|
|
@@ -17,6 +21,49 @@ export default class EdgeServiceProvider {
|
|
|
17
21
|
* Bridge AdonisJS and Edge
|
|
18
22
|
*/
|
|
19
23
|
async boot() {
|
|
20
|
-
|
|
24
|
+
const app = this.app;
|
|
25
|
+
const router = await this.app.container.make('router');
|
|
26
|
+
function edgeConfigResolver(key, defaultValue) {
|
|
27
|
+
return app.config.get(key, defaultValue);
|
|
28
|
+
}
|
|
29
|
+
edgeConfigResolver.has = function (key) {
|
|
30
|
+
return app.config.has(key);
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Mount the default disk
|
|
34
|
+
*/
|
|
35
|
+
edge.mount(app.viewsPath());
|
|
36
|
+
/**
|
|
37
|
+
* Cache templates in production
|
|
38
|
+
*/
|
|
39
|
+
edge.configure({ cache: app.inProduction });
|
|
40
|
+
/**
|
|
41
|
+
* Define Edge global helpers
|
|
42
|
+
*/
|
|
43
|
+
edge.global('route', function (...args) {
|
|
44
|
+
return router.makeUrl(...args);
|
|
45
|
+
});
|
|
46
|
+
edge.global('signedRoute', function (...args) {
|
|
47
|
+
return router.makeSignedUrl(...args);
|
|
48
|
+
});
|
|
49
|
+
edge.global('app', app);
|
|
50
|
+
edge.global('config', edgeConfigResolver);
|
|
51
|
+
/**
|
|
52
|
+
* Creating a isolated instance of edge renderer
|
|
53
|
+
*/
|
|
54
|
+
HttpContext.getter('view', function () {
|
|
55
|
+
return edge.createRenderer().share({
|
|
56
|
+
request: this.request,
|
|
57
|
+
});
|
|
58
|
+
}, true);
|
|
59
|
+
/**
|
|
60
|
+
* Adding brisk route to render templates without an
|
|
61
|
+
* explicit handler
|
|
62
|
+
*/
|
|
63
|
+
BriskRoute.macro('render', function (template, data) {
|
|
64
|
+
return this.setHandler(({ view }) => {
|
|
65
|
+
return view.render(template, data);
|
|
66
|
+
});
|
|
67
|
+
});
|
|
21
68
|
}
|
|
22
69
|
}
|
|
@@ -8,6 +8,14 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import { join } from 'node:path';
|
|
10
10
|
import { homedir } from 'node:os';
|
|
11
|
+
/**
|
|
12
|
+
* Resolves a container binding and sets it on the REPL
|
|
13
|
+
* context
|
|
14
|
+
*/
|
|
15
|
+
async function resolveBindingForRepl(app, repl, binding) {
|
|
16
|
+
repl.server.context[binding] = await app.container.make(binding);
|
|
17
|
+
repl.notify(`Loaded "${binding}" service. You can access it using the "${repl.colors.underline(binding)}" variable`);
|
|
18
|
+
}
|
|
11
19
|
export default class ReplServiceProvider {
|
|
12
20
|
app;
|
|
13
21
|
constructor(app) {
|
|
@@ -29,7 +37,62 @@ export default class ReplServiceProvider {
|
|
|
29
37
|
*/
|
|
30
38
|
async boot() {
|
|
31
39
|
const repl = await this.app.container.make('repl');
|
|
32
|
-
|
|
33
|
-
|
|
40
|
+
repl.addMethod('importDefault', (_, modulePath) => {
|
|
41
|
+
return this.app.importDefault(modulePath);
|
|
42
|
+
}, {
|
|
43
|
+
description: 'Returns the default export for a module',
|
|
44
|
+
});
|
|
45
|
+
repl.addMethod('make', (_, service, runtimeValues) => {
|
|
46
|
+
return this.app.container.make(service, runtimeValues);
|
|
47
|
+
}, {
|
|
48
|
+
description: 'Make class instance using "container.make" method',
|
|
49
|
+
});
|
|
50
|
+
repl.addMethod('loadApp', () => {
|
|
51
|
+
return resolveBindingForRepl(this.app, repl, 'app');
|
|
52
|
+
}, {
|
|
53
|
+
description: 'Load "app" service in the REPL context',
|
|
54
|
+
});
|
|
55
|
+
repl.addMethod('loadEncryption', () => {
|
|
56
|
+
return resolveBindingForRepl(this.app, repl, 'encryption');
|
|
57
|
+
}, {
|
|
58
|
+
description: 'Load "encryption" service in the REPL context',
|
|
59
|
+
});
|
|
60
|
+
repl.addMethod('loadHash', () => {
|
|
61
|
+
return resolveBindingForRepl(this.app, repl, 'hash');
|
|
62
|
+
}, {
|
|
63
|
+
description: 'Load "hash" service in the REPL context',
|
|
64
|
+
});
|
|
65
|
+
repl.addMethod('loadRouter', () => {
|
|
66
|
+
return resolveBindingForRepl(this.app, repl, 'router');
|
|
67
|
+
}, {
|
|
68
|
+
description: 'Load "router" service in the REPL context',
|
|
69
|
+
});
|
|
70
|
+
repl.addMethod('loadConfig', () => {
|
|
71
|
+
return resolveBindingForRepl(this.app, repl, 'config');
|
|
72
|
+
}, {
|
|
73
|
+
description: 'Load "config" service in the REPL context',
|
|
74
|
+
});
|
|
75
|
+
repl.addMethod('loadTestUtils', () => {
|
|
76
|
+
return resolveBindingForRepl(this.app, repl, 'testUtils');
|
|
77
|
+
}, {
|
|
78
|
+
description: 'Load "testUtils" service in the REPL context',
|
|
79
|
+
});
|
|
80
|
+
repl.addMethod('loadHelpers', async () => {
|
|
81
|
+
const { default: isModule } = await import('../src/helpers/is.js');
|
|
82
|
+
const { default: stringModule } = await import('../src/helpers/string.js');
|
|
83
|
+
const { base64, cuid, fsReadAll, slash, parseImports } = await import('../src/helpers/main.js');
|
|
84
|
+
repl.server.context.helpers = {
|
|
85
|
+
string: stringModule,
|
|
86
|
+
is: isModule,
|
|
87
|
+
base64,
|
|
88
|
+
cuid,
|
|
89
|
+
fsReadAll,
|
|
90
|
+
slash,
|
|
91
|
+
parseImports,
|
|
92
|
+
};
|
|
93
|
+
repl.notify(`Loaded "helpers" module. You can access it using the "${repl.colors.underline('helpers')}" variable`);
|
|
94
|
+
}, {
|
|
95
|
+
description: 'Load "helpers" module in the REPL context',
|
|
96
|
+
});
|
|
34
97
|
}
|
|
35
98
|
}
|
|
@@ -1,5 +1,33 @@
|
|
|
1
|
-
import '
|
|
2
|
-
import '
|
|
3
|
-
import '
|
|
4
|
-
|
|
1
|
+
import { BaseLiteralType } from '@vinejs/vine';
|
|
2
|
+
import type { Validation, FieldContext, FieldOptions } from '@vinejs/vine/types';
|
|
3
|
+
import type { MultipartFile, FileValidationOptions } from '@adonisjs/bodyparser/types';
|
|
4
|
+
import { RequestValidator } from '../modules/http/main.js';
|
|
5
|
+
/**
|
|
6
|
+
* Validation options accepted by the "file" rule
|
|
7
|
+
*/
|
|
8
|
+
export type FileRuleValidationOptions = Partial<FileValidationOptions> | ((field: FieldContext) => Partial<FileValidationOptions>);
|
|
9
|
+
/**
|
|
10
|
+
* Extend VineJS
|
|
11
|
+
*/
|
|
12
|
+
declare module '@vinejs/vine' {
|
|
13
|
+
interface Vine {
|
|
14
|
+
file(options?: FileRuleValidationOptions): VineMultipartFile;
|
|
15
|
+
}
|
|
5
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* Extend HTTP request class
|
|
19
|
+
*/
|
|
20
|
+
declare module '@adonisjs/core/http' {
|
|
21
|
+
interface Request extends RequestValidator {
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Represents a multipart file uploaded via multipart/form-data HTTP
|
|
26
|
+
* request.
|
|
27
|
+
*/
|
|
28
|
+
declare class VineMultipartFile extends BaseLiteralType<MultipartFile, MultipartFile> {
|
|
29
|
+
#private;
|
|
30
|
+
constructor(validationOptions?: FileRuleValidationOptions, options?: FieldOptions, validations?: Validation<any>[]);
|
|
31
|
+
clone(): this;
|
|
32
|
+
}
|
|
33
|
+
export {};
|
|
@@ -6,8 +6,79 @@
|
|
|
6
6
|
* For the full copyright and license information, please view the LICENSE
|
|
7
7
|
* file that was distributed with this source code.
|
|
8
8
|
*/
|
|
9
|
-
import '
|
|
10
|
-
import '../
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
import vine, { BaseLiteralType, Vine } from '@vinejs/vine';
|
|
10
|
+
import { Request, RequestValidator } from '../modules/http/main.js';
|
|
11
|
+
/**
|
|
12
|
+
* Checks if the value is an instance of multipart file
|
|
13
|
+
* from bodyparser.
|
|
14
|
+
*/
|
|
15
|
+
function isBodyParserFile(file) {
|
|
16
|
+
return !!(file && typeof file === 'object' && 'isMultipartFile' in file);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* VineJS validation rule that validates the file to be an
|
|
20
|
+
* instance of BodyParser MultipartFile class.
|
|
21
|
+
*/
|
|
22
|
+
const isMultipartFile = vine.createRule((file, options, field) => {
|
|
23
|
+
/**
|
|
24
|
+
* Report error when value is not a field multipart
|
|
25
|
+
* file object
|
|
26
|
+
*/
|
|
27
|
+
if (!isBodyParserFile(file)) {
|
|
28
|
+
field.report('The {{ field }} must be a file', 'file', field);
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
const validationOptions = typeof options === 'function' ? options(field) : options;
|
|
32
|
+
/**
|
|
33
|
+
* Set size when it's defined in the options and missing
|
|
34
|
+
* on the file instance
|
|
35
|
+
*/
|
|
36
|
+
if (file.sizeLimit === undefined && validationOptions.size) {
|
|
37
|
+
file.sizeLimit = validationOptions.size;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Set extensions when it's defined in the options and missing
|
|
41
|
+
* on the file instance
|
|
42
|
+
*/
|
|
43
|
+
if (file.allowedExtensions === undefined && validationOptions.extnames) {
|
|
44
|
+
file.allowedExtensions = validationOptions.extnames;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Validate file
|
|
48
|
+
*/
|
|
49
|
+
file.validate();
|
|
50
|
+
/**
|
|
51
|
+
* Report errors
|
|
52
|
+
*/
|
|
53
|
+
file.errors.forEach((error) => {
|
|
54
|
+
field.report(error.message, `file.${error.type}`, field, validationOptions);
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
/**
|
|
58
|
+
* Represents a multipart file uploaded via multipart/form-data HTTP
|
|
59
|
+
* request.
|
|
60
|
+
*/
|
|
61
|
+
class VineMultipartFile extends BaseLiteralType {
|
|
62
|
+
#validationOptions;
|
|
63
|
+
constructor(validationOptions, options, validations) {
|
|
64
|
+
super(options, validations || [isMultipartFile(validationOptions || {})]);
|
|
65
|
+
this.#validationOptions = validationOptions;
|
|
66
|
+
}
|
|
67
|
+
clone() {
|
|
68
|
+
return new VineMultipartFile(this.#validationOptions, this.cloneOptions(), this.cloneValidations());
|
|
69
|
+
}
|
|
13
70
|
}
|
|
71
|
+
/**
|
|
72
|
+
* The file method is used to validate a field to be a valid
|
|
73
|
+
* multipart file.
|
|
74
|
+
*/
|
|
75
|
+
Vine.macro('file', function (options) {
|
|
76
|
+
return new VineMultipartFile(options);
|
|
77
|
+
});
|
|
78
|
+
/**
|
|
79
|
+
* The validate method can be used to validate the request
|
|
80
|
+
* data for the current request using VineJS validators
|
|
81
|
+
*/
|
|
82
|
+
Request.macro('validateUsing', function (...args) {
|
|
83
|
+
return new RequestValidator(this.ctx).validateUsing(...args);
|
|
84
|
+
});
|
package/build/types/http.d.ts
CHANGED
|
@@ -1 +1,8 @@
|
|
|
1
1
|
export * from '@adonisjs/http-server/types';
|
|
2
|
+
import type { ValidationOptions } from '@vinejs/vine/types';
|
|
3
|
+
/**
|
|
4
|
+
* Validation options accepted by the "request.validateUsing" method
|
|
5
|
+
*/
|
|
6
|
+
export type RequestValidationOptions<MetaData extends undefined | Record<string, any>> = ValidationOptions<MetaData> & {
|
|
7
|
+
data?: any;
|
|
8
|
+
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adonisjs/core",
|
|
3
3
|
"description": "Core of AdonisJS",
|
|
4
|
-
"version": "6.1.5-
|
|
4
|
+
"version": "6.1.5-22",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=18.16.0"
|
|
7
7
|
},
|
|
@@ -112,7 +112,7 @@
|
|
|
112
112
|
},
|
|
113
113
|
"dependencies": {
|
|
114
114
|
"@adonisjs/ace": "^12.3.1-10",
|
|
115
|
-
"@adonisjs/application": "^7.1.2-
|
|
115
|
+
"@adonisjs/application": "^7.1.2-13",
|
|
116
116
|
"@adonisjs/bodyparser": "^9.3.2-7",
|
|
117
117
|
"@adonisjs/config": "^4.2.1-3",
|
|
118
118
|
"@adonisjs/encryption": "^5.1.2-2",
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import './types.js';
|
|
2
|
-
import type { ApplicationService } from '../../types.js';
|
|
3
|
-
import { type Router } from '../../../modules/http/main.js';
|
|
4
|
-
/**
|
|
5
|
-
* Bridges AdonisJS with Edge
|
|
6
|
-
*/
|
|
7
|
-
export declare function bridgeEdgeAdonisJS(app: ApplicationService, router: Router): void;
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* @adonisjs/core
|
|
3
|
-
*
|
|
4
|
-
* (c) AdonisJS
|
|
5
|
-
*
|
|
6
|
-
* For the full copyright and license information, please view the LICENSE
|
|
7
|
-
* file that was distributed with this source code.
|
|
8
|
-
*/
|
|
9
|
-
import edge from 'edge.js';
|
|
10
|
-
import './types.js';
|
|
11
|
-
import { HttpContext, BriskRoute } from '../../../modules/http/main.js';
|
|
12
|
-
/**
|
|
13
|
-
* Bridges AdonisJS with Edge
|
|
14
|
-
*/
|
|
15
|
-
export function bridgeEdgeAdonisJS(app, router) {
|
|
16
|
-
function edgeConfigResolver(key, defaultValue) {
|
|
17
|
-
return app.config.get(key, defaultValue);
|
|
18
|
-
}
|
|
19
|
-
edgeConfigResolver.has = function (key) {
|
|
20
|
-
return app.config.has(key);
|
|
21
|
-
};
|
|
22
|
-
/**
|
|
23
|
-
* Mount the default disk
|
|
24
|
-
*/
|
|
25
|
-
edge.mount(app.viewsPath());
|
|
26
|
-
/**
|
|
27
|
-
* Cache templates in production
|
|
28
|
-
*/
|
|
29
|
-
edge.configure({ cache: app.inProduction });
|
|
30
|
-
/**
|
|
31
|
-
* Define Edge global helpers
|
|
32
|
-
*/
|
|
33
|
-
edge.global('route', function (...args) {
|
|
34
|
-
return router.makeUrl(...args);
|
|
35
|
-
});
|
|
36
|
-
edge.global('signedRoute', function (...args) {
|
|
37
|
-
return router.makeSignedUrl(...args);
|
|
38
|
-
});
|
|
39
|
-
edge.global('app', app);
|
|
40
|
-
edge.global('config', edgeConfigResolver);
|
|
41
|
-
/**
|
|
42
|
-
* Creating a isolated instance of edge renderer
|
|
43
|
-
*/
|
|
44
|
-
HttpContext.getter('view', function () {
|
|
45
|
-
return edge.createRenderer().share({
|
|
46
|
-
request: this.request,
|
|
47
|
-
});
|
|
48
|
-
});
|
|
49
|
-
/**
|
|
50
|
-
* Adding brisk route to render templates without an
|
|
51
|
-
* explicit handler
|
|
52
|
-
*/
|
|
53
|
-
BriskRoute.macro('render', function (template, data) {
|
|
54
|
-
return this.setHandler(({ view }) => {
|
|
55
|
-
return view.render(template, data);
|
|
56
|
-
});
|
|
57
|
-
});
|
|
58
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { type Edge } from 'edge.js';
|
|
2
|
-
import type { Route } from '../../../modules/http/main.js';
|
|
3
|
-
declare module '@adonisjs/http-server' {
|
|
4
|
-
interface HttpContext {
|
|
5
|
-
/**
|
|
6
|
-
* Reference to the edge renderer to render templates
|
|
7
|
-
* during an HTTP request
|
|
8
|
-
*/
|
|
9
|
-
view: ReturnType<Edge['createRenderer']>;
|
|
10
|
-
}
|
|
11
|
-
interface BriskRoute {
|
|
12
|
-
/**
|
|
13
|
-
* Render an edge template without defining an
|
|
14
|
-
* explicit route handler
|
|
15
|
-
*/
|
|
16
|
-
render(template: string, data?: Record<string, any>): Route;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* @adonisjs/core
|
|
3
|
-
*
|
|
4
|
-
* (c) AdonisJS
|
|
5
|
-
*
|
|
6
|
-
* For the full copyright and license information, please view the LICENSE
|
|
7
|
-
* file that was distributed with this source code.
|
|
8
|
-
*/
|
|
9
|
-
/**
|
|
10
|
-
* Resolves a container binding and sets it on the REPL
|
|
11
|
-
* context
|
|
12
|
-
*/
|
|
13
|
-
async function resolveBindingForRepl(app, repl, binding) {
|
|
14
|
-
repl.server.context[binding] = await app.container.make(binding);
|
|
15
|
-
repl.notify(`Loaded "${binding}" service. You can access it using the "${repl.colors.underline(binding)}" variable`);
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Registers REPL methods
|
|
19
|
-
*/
|
|
20
|
-
export function defineReplBindings(app, repl) {
|
|
21
|
-
repl.addMethod('importDefault', (_, modulePath) => {
|
|
22
|
-
return app.importDefault(modulePath);
|
|
23
|
-
}, {
|
|
24
|
-
description: 'Returns the default export for a module',
|
|
25
|
-
});
|
|
26
|
-
repl.addMethod('make', (_, service, runtimeValues) => {
|
|
27
|
-
return app.container.make(service, runtimeValues);
|
|
28
|
-
}, {
|
|
29
|
-
description: 'Make class instance using "container.make" method',
|
|
30
|
-
});
|
|
31
|
-
repl.addMethod('loadApp', () => {
|
|
32
|
-
return resolveBindingForRepl(app, repl, 'app');
|
|
33
|
-
}, {
|
|
34
|
-
description: 'Load "app" service in the REPL context',
|
|
35
|
-
});
|
|
36
|
-
repl.addMethod('loadEncryption', () => {
|
|
37
|
-
return resolveBindingForRepl(app, repl, 'encryption');
|
|
38
|
-
}, {
|
|
39
|
-
description: 'Load "encryption" service in the REPL context',
|
|
40
|
-
});
|
|
41
|
-
repl.addMethod('loadHash', () => {
|
|
42
|
-
return resolveBindingForRepl(app, repl, 'hash');
|
|
43
|
-
}, {
|
|
44
|
-
description: 'Load "hash" service in the REPL context',
|
|
45
|
-
});
|
|
46
|
-
repl.addMethod('loadRouter', () => {
|
|
47
|
-
return resolveBindingForRepl(app, repl, 'router');
|
|
48
|
-
}, {
|
|
49
|
-
description: 'Load "router" service in the REPL context',
|
|
50
|
-
});
|
|
51
|
-
repl.addMethod('loadConfig', () => {
|
|
52
|
-
return resolveBindingForRepl(app, repl, 'config');
|
|
53
|
-
}, {
|
|
54
|
-
description: 'Load "config" service in the REPL context',
|
|
55
|
-
});
|
|
56
|
-
repl.addMethod('loadTestUtils', () => {
|
|
57
|
-
return resolveBindingForRepl(app, repl, 'testUtils');
|
|
58
|
-
}, {
|
|
59
|
-
description: 'Load "testUtils" service in the REPL context',
|
|
60
|
-
});
|
|
61
|
-
repl.addMethod('loadHelpers', async () => {
|
|
62
|
-
const { default: isModule } = await import('../helpers/is.js');
|
|
63
|
-
const { default: stringModule } = await import('../helpers/string.js');
|
|
64
|
-
const { base64, cuid, fsReadAll, slash, parseImports } = await import('../helpers/main.js');
|
|
65
|
-
repl.server.context.helpers = {
|
|
66
|
-
string: stringModule,
|
|
67
|
-
is: isModule,
|
|
68
|
-
base64,
|
|
69
|
-
cuid,
|
|
70
|
-
fsReadAll,
|
|
71
|
-
slash,
|
|
72
|
-
parseImports,
|
|
73
|
-
};
|
|
74
|
-
repl.notify(`Loaded "helpers" module. You can access it using the "${repl.colors.underline('helpers')}" variable`);
|
|
75
|
-
}, {
|
|
76
|
-
description: 'Load "helpers" module in the REPL context',
|
|
77
|
-
});
|
|
78
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { BaseLiteralType } from '@vinejs/vine';
|
|
2
|
-
import type { MultipartFile } from '@adonisjs/bodyparser/types';
|
|
3
|
-
import type { FieldOptions, Validation } from '@vinejs/vine/types';
|
|
4
|
-
import type { ValidationOptions } from './types.js';
|
|
5
|
-
/**
|
|
6
|
-
* Represents a multipart file uploaded via multipart/form-data HTTP
|
|
7
|
-
* request.
|
|
8
|
-
*/
|
|
9
|
-
export declare class VineMultipartFile extends BaseLiteralType<MultipartFile, MultipartFile> {
|
|
10
|
-
#private;
|
|
11
|
-
constructor(validationOptions?: ValidationOptions, options?: FieldOptions, validations?: Validation<any>[]);
|
|
12
|
-
clone(): this;
|
|
13
|
-
}
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* @adonisjs/core
|
|
3
|
-
*
|
|
4
|
-
* (c) AdonisJS
|
|
5
|
-
*
|
|
6
|
-
* For the full copyright and license information, please view the LICENSE
|
|
7
|
-
* file that was distributed with this source code.
|
|
8
|
-
*/
|
|
9
|
-
import vine, { BaseLiteralType, Vine } from '@vinejs/vine';
|
|
10
|
-
/**
|
|
11
|
-
* Checks if the value is an instance of multipart file
|
|
12
|
-
* from bodyparser.
|
|
13
|
-
*/
|
|
14
|
-
function isBodyParserFile(file) {
|
|
15
|
-
return !!(file && typeof file === 'object' && 'isMultipartFile' in file);
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* VineJS validation rule that validates the file to be an
|
|
19
|
-
* instance of BodyParser MultipartFile class.
|
|
20
|
-
*/
|
|
21
|
-
const isMultipartFile = vine.createRule((file, options, field) => {
|
|
22
|
-
/**
|
|
23
|
-
* Report error when value is not a field multipart
|
|
24
|
-
* file object
|
|
25
|
-
*/
|
|
26
|
-
if (!isBodyParserFile(file)) {
|
|
27
|
-
field.report('The {{ field }} must be a file', 'file', field);
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
const validationOptions = typeof options === 'function' ? options(field) : options;
|
|
31
|
-
/**
|
|
32
|
-
* Set size when it's defined in the options and missing
|
|
33
|
-
* on the file instance
|
|
34
|
-
*/
|
|
35
|
-
if (file.sizeLimit === undefined && validationOptions.size) {
|
|
36
|
-
file.sizeLimit = validationOptions.size;
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Set extensions when it's defined in the options and missing
|
|
40
|
-
* on the file instance
|
|
41
|
-
*/
|
|
42
|
-
if (file.allowedExtensions === undefined && validationOptions.extnames) {
|
|
43
|
-
file.allowedExtensions = validationOptions.extnames;
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Validate file
|
|
47
|
-
*/
|
|
48
|
-
file.validate();
|
|
49
|
-
/**
|
|
50
|
-
* Report errors
|
|
51
|
-
*/
|
|
52
|
-
file.errors.forEach((error) => {
|
|
53
|
-
field.report(error.message, `file.${error.type}`, field, validationOptions);
|
|
54
|
-
});
|
|
55
|
-
});
|
|
56
|
-
/**
|
|
57
|
-
* Represents a multipart file uploaded via multipart/form-data HTTP
|
|
58
|
-
* request.
|
|
59
|
-
*/
|
|
60
|
-
export class VineMultipartFile extends BaseLiteralType {
|
|
61
|
-
#validationOptions;
|
|
62
|
-
constructor(validationOptions, options, validations) {
|
|
63
|
-
super(options, validations || [isMultipartFile(validationOptions || {})]);
|
|
64
|
-
this.#validationOptions = validationOptions;
|
|
65
|
-
}
|
|
66
|
-
clone() {
|
|
67
|
-
return new VineMultipartFile(this.#validationOptions, this.cloneOptions(), this.cloneValidations());
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* The file method is used to validate a field to be a valid
|
|
72
|
-
* multipart file.
|
|
73
|
-
*/
|
|
74
|
-
Vine.macro('file', function (options) {
|
|
75
|
-
return new VineMultipartFile(options);
|
|
76
|
-
});
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { FieldContext } from '@vinejs/vine/types';
|
|
2
|
-
import type { FileValidationOptions } from '@adonisjs/bodyparser/types';
|
|
3
|
-
import type { VineMultipartFile } from './main.js';
|
|
4
|
-
export type ValidationOptions = Partial<FileValidationOptions> | ((field: FieldContext) => Partial<FileValidationOptions>);
|
|
5
|
-
/**
|
|
6
|
-
* Notifying TypeScript
|
|
7
|
-
*/
|
|
8
|
-
declare module '@vinejs/vine' {
|
|
9
|
-
interface Vine {
|
|
10
|
-
file(options?: ValidationOptions): VineMultipartFile;
|
|
11
|
-
}
|
|
12
|
-
}
|