@adonisjs/core 6.1.5-7 → 6.1.5-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.
@@ -7,7 +7,7 @@
7
7
  * file that was distributed with this source code.
8
8
  */
9
9
  import { Ignitor } from '../../src/ignitor/main.js';
10
- import { defineConfig as defineHttpConfig } from '../../modules/http.js';
10
+ import { defineConfig as defineHttpConfig } from '../../modules/http/main.js';
11
11
  import { defineConfig as defineLoggerConfig } from '../../modules/logger.js';
12
12
  import { defineConfig as defineHashConfig } from '../../modules/hash/main.js';
13
13
  import { defineConfig as defineBodyParserConfig } from '../../modules/bodyparser/main.js';
@@ -0,0 +1,2 @@
1
+ export * from '@adonisjs/http-server';
2
+ export { RequestValidator } from './request_validator.js';
@@ -0,0 +1,10 @@
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
+ export * from '@adonisjs/http-server';
10
+ export { RequestValidator } from './request_validator.js';
@@ -0,0 +1,44 @@
1
+ import { type VineValidator } from '@vinejs/vine';
2
+ import type { Infer, SchemaTypes, ValidationOptions, ErrorReporterContract, MessagesProviderContact } from '@vinejs/vine/types';
3
+ import { type HttpContext } from '@adonisjs/http-server';
4
+ /**
5
+ * Request validation options with custom data as well
6
+ */
7
+ type RequestValidationOptions<MetaData extends undefined | Record<string, any>> = ValidationOptions<MetaData> & {
8
+ data?: any;
9
+ };
10
+ /**
11
+ * Request validator is used validate HTTP request data using
12
+ * VineJS validators. You may validate the request body,
13
+ * files, cookies, and headers.
14
+ */
15
+ export declare class RequestValidator {
16
+ #private;
17
+ constructor(ctx: HttpContext);
18
+ /**
19
+ * The error reporter method returns the error reporter
20
+ * to use for reporting errors.
21
+ *
22
+ * You can use this function to pick a different error reporter
23
+ * for each HTTP request
24
+ */
25
+ static errorReporter?: (_: HttpContext) => ErrorReporterContract;
26
+ /**
27
+ * The messages provider method returns the messages provider to use
28
+ * finding custom error messages
29
+ *
30
+ * You can use this function to pick a different messages provider for
31
+ * each HTTP request
32
+ */
33
+ static messagesProvider?: (_: HttpContext) => MessagesProviderContact;
34
+ /**
35
+ * The validate method can be used to validate the request
36
+ * data for the current request using VineJS validators
37
+ */
38
+ 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>>;
39
+ }
40
+ declare module '@adonisjs/http-server' {
41
+ interface Request extends RequestValidator {
42
+ }
43
+ }
44
+ export {};
@@ -0,0 +1,74 @@
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 { Request } from '@adonisjs/http-server';
10
+ /**
11
+ * Request validator is used validate HTTP request data using
12
+ * VineJS validators. You may validate the request body,
13
+ * files, cookies, and headers.
14
+ */
15
+ export class RequestValidator {
16
+ #ctx;
17
+ constructor(ctx) {
18
+ this.#ctx = ctx;
19
+ }
20
+ /**
21
+ * The error reporter method returns the error reporter
22
+ * to use for reporting errors.
23
+ *
24
+ * You can use this function to pick a different error reporter
25
+ * for each HTTP request
26
+ */
27
+ static errorReporter;
28
+ /**
29
+ * The messages provider method returns the messages provider to use
30
+ * finding custom error messages
31
+ *
32
+ * You can use this function to pick a different messages provider for
33
+ * each HTTP request
34
+ */
35
+ static messagesProvider;
36
+ /**
37
+ * The validate method can be used to validate the request
38
+ * data for the current request using VineJS validators
39
+ */
40
+ validateUsing(validator, ...[options]) {
41
+ const validatorOptions = options || {};
42
+ /**
43
+ * Assign request specific error reporter
44
+ */
45
+ if (RequestValidator.errorReporter) {
46
+ const errorReporter = RequestValidator.errorReporter(this.#ctx);
47
+ validatorOptions.errorReporter = () => errorReporter;
48
+ }
49
+ /**
50
+ * Assign request specific messages provider
51
+ */
52
+ if (RequestValidator.messagesProvider) {
53
+ validatorOptions.messagesProvider = RequestValidator.messagesProvider(this.#ctx);
54
+ }
55
+ /**
56
+ * Data to validate
57
+ */
58
+ const data = validatorOptions.data || {
59
+ ...this.#ctx.request.all(),
60
+ ...this.#ctx.request.allFiles(),
61
+ params: this.#ctx.request.params(),
62
+ headers: this.#ctx.request.headers(),
63
+ cookies: this.#ctx.request.cookiesList(),
64
+ };
65
+ return validator.validate(data, validatorOptions);
66
+ }
67
+ }
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
+ });
@@ -6,7 +6,7 @@
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 { Router, Server } from '../modules/http.js';
9
+ import { Router, Server } from '../modules/http/main.js';
10
10
  import BodyParserMiddleware from '../modules/bodyparser/bodyparser_middleware.js';
11
11
  /**
12
12
  * Http Service provider binds the router and the HTTP server to
@@ -6,6 +6,8 @@
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 { join } from 'node:path';
10
+ import { homedir } from 'node:os';
9
11
  export default class ReplServiceProvider {
10
12
  app;
11
13
  constructor(app) {
@@ -17,7 +19,9 @@ export default class ReplServiceProvider {
17
19
  register() {
18
20
  this.app.container.singleton('repl', async () => {
19
21
  const { Repl } = await import('../modules/repl.js');
20
- return new Repl();
22
+ return new Repl({
23
+ historyFilePath: join(homedir(), '.adonisjs_v6_repl_history'),
24
+ });
21
25
  });
22
26
  }
23
27
  /**
@@ -1,5 +1,5 @@
1
- import { type Router } from '../../modules/http.js';
2
1
  import type { UIPrimitives } from '../../types/ace.js';
2
+ import { type Router } from '../../modules/http/main.js';
3
3
  /**
4
4
  * Shape of the serialized route specific to the formatter
5
5
  */
@@ -2,7 +2,7 @@
2
2
  import Macroable from '@poppinss/macroable';
3
3
  import { IncomingMessage, ServerResponse } from 'node:http';
4
4
  import { HttpServerUtils } from './http.js';
5
- import { CookieClient } from '../../modules/http.js';
5
+ import { CookieClient } from '../../modules/http/main.js';
6
6
  import type { ApplicationService } from '../types.js';
7
7
  /**
8
8
  * Test utils has a collection of helper methods to make testing
@@ -33,5 +33,5 @@ export declare class TestUtils extends Macroable {
33
33
  createHttpContext(options?: {
34
34
  req?: IncomingMessage;
35
35
  res?: ServerResponse;
36
- }): Promise<import("../../modules/http.js").HttpContext>;
36
+ }): Promise<import("../../modules/http/main.js").HttpContext>;
37
37
  }
@@ -10,7 +10,7 @@ import { Socket } from 'node:net';
10
10
  import Macroable from '@poppinss/macroable';
11
11
  import { IncomingMessage, ServerResponse } from 'node:http';
12
12
  import { HttpServerUtils } from './http.js';
13
- import { CookieClient } from '../../modules/http.js';
13
+ import { CookieClient } from '../../modules/http/main.js';
14
14
  /**
15
15
  * Test utils has a collection of helper methods to make testing
16
16
  * experience great for AdonisJS applications
@@ -4,9 +4,9 @@ import type { Emitter } from '../modules/events.js';
4
4
  import type { Kernel } from '../modules/ace/main.js';
5
5
  import type { Application } from '../modules/app.js';
6
6
  import type { TestUtils } from './test_utils/main.js';
7
- import type { Router, Server } from '../modules/http.js';
8
7
  import type { LoggerManager } from '../modules/logger.js';
9
8
  import type { Encryption } from '../modules/encryption.js';
9
+ import type { Router, Server } from '../modules/http/main.js';
10
10
  import type { HttpRequestFinishedPayload } from '../types/http.js';
11
11
  import type { ContainerResolveEventData } from '../types/container.js';
12
12
  import type { LoggerConfig, LoggerManagerConfig } from '../types/logger.js';
@@ -0,0 +1 @@
1
+ import './validates_files.js';
@@ -6,4 +6,4 @@
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
- export * from '@adonisjs/http-server';
9
+ import './validates_files.js';
@@ -0,0 +1,22 @@
1
+ import { BaseLiteralType } from '@vinejs/vine';
2
+ import type { FieldContext, FieldOptions, Validation } from '@vinejs/vine/types';
3
+ import type { MultipartFile, FileValidationOptions } from '@adonisjs/bodyparser/types';
4
+ type ValidationOptions = Partial<FileValidationOptions> | ((field: FieldContext) => Partial<FileValidationOptions>);
5
+ /**
6
+ * Represents a multipart file uploaded via multipart/form-data HTTP
7
+ * request.
8
+ */
9
+ declare class VineMultipartFile extends BaseLiteralType<MultipartFile, MultipartFile> {
10
+ #private;
11
+ constructor(validationOptions?: ValidationOptions, options?: FieldOptions, validations?: Validation<any>[]);
12
+ clone(): this;
13
+ }
14
+ /**
15
+ * Notifying TypeScript
16
+ */
17
+ declare module '@vinejs/vine' {
18
+ interface Vine {
19
+ file(options?: ValidationOptions): VineMultipartFile;
20
+ }
21
+ }
22
+ export {};
@@ -0,0 +1,76 @@
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
+ 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
+ });
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-7",
4
+ "version": "6.1.5-9",
5
5
  "engines": {
6
6
  "node": ">=18.16.0"
7
7
  },
@@ -26,6 +26,7 @@
26
26
  },
27
27
  "exports": {
28
28
  ".": "./build/index.js",
29
+ "./commands": "./build/commands/main.js",
29
30
  "./commands/*": "./build/commands/*.js",
30
31
  "./factories": "./build/factories/core/main.js",
31
32
  "./factories/*": "./build/factories/*.js",
@@ -35,6 +36,7 @@
35
36
  "./providers/*": "./build/providers/*.js",
36
37
  "./helpers": "./build/src/helpers/main.js",
37
38
  "./helpers/*": "./build/src/helpers/*.js",
39
+ "./vinejs/extensions": "./build/src/vinejs/extensions/main.js",
38
40
  "./ace": "./build/modules/ace/main.js",
39
41
  "./ace/shell": "./build/modules/ace/shell.js",
40
42
  "./bodyparser": "./build/modules/bodyparser/main.js",
@@ -72,32 +74,33 @@
72
74
  "index:commands": "node --loader=ts-node/esm toolkit/main.js index build/commands"
73
75
  },
74
76
  "devDependencies": {
75
- "@adonisjs/assembler": "^6.1.3-12",
76
- "@adonisjs/eslint-config": "^1.1.7",
77
- "@adonisjs/prettier-config": "^1.1.7",
78
- "@adonisjs/tsconfig": "^1.1.7",
79
- "@commitlint/cli": "^17.6.6",
80
- "@commitlint/config-conventional": "^17.6.6",
77
+ "@adonisjs/assembler": "^6.1.3-13",
78
+ "@adonisjs/eslint-config": "^1.1.8",
79
+ "@adonisjs/prettier-config": "^1.1.8",
80
+ "@adonisjs/tsconfig": "^1.1.8",
81
+ "@commitlint/cli": "^17.6.7",
82
+ "@commitlint/config-conventional": "^17.6.7",
81
83
  "@japa/assert": "2.0.0-1",
82
84
  "@japa/expect-type": "2.0.0-0",
83
85
  "@japa/file-system": "2.0.0-1",
84
86
  "@japa/runner": "^3.0.0-5",
85
- "@swc/core": "^1.3.68",
86
- "@types/node": "^20.4.1",
87
+ "@swc/core": "^1.3.70",
88
+ "@types/node": "^20.4.2",
87
89
  "@types/pretty-hrtime": "^1.0.1",
88
90
  "@types/sinon": "^10.0.15",
89
91
  "@types/supertest": "^2.0.12",
90
92
  "@types/test-console": "^2.0.0",
93
+ "@vinejs/vine": "^1.5.2",
91
94
  "c8": "^8.0.0",
92
95
  "copyfiles": "^2.4.1",
93
96
  "cross-env": "^7.0.3",
94
97
  "del-cli": "^5.0.0",
95
- "eslint": "^8.44.0",
98
+ "eslint": "^8.45.0",
96
99
  "get-port": "^7.0.0",
97
100
  "github-label-sync": "^2.3.1",
98
101
  "husky": "^8.0.3",
99
102
  "np": "^8.0.4",
100
- "prettier": "^2.8.8",
103
+ "prettier": "^3.0.0",
101
104
  "sinon": "^15.2.0",
102
105
  "supertest": "^6.3.3",
103
106
  "test-console": "^2.0.0",
@@ -114,14 +117,14 @@
114
117
  "@adonisjs/events": "^8.4.9-3",
115
118
  "@adonisjs/fold": "^9.9.3-6",
116
119
  "@adonisjs/hash": "^8.3.1-3",
117
- "@adonisjs/http-server": "^6.8.2-8",
120
+ "@adonisjs/http-server": "^6.8.2-9",
118
121
  "@adonisjs/logger": "^5.4.2-3",
119
122
  "@adonisjs/repl": "^4.0.0-5",
120
123
  "@antfu/install-pkg": "^0.1.1",
121
124
  "@paralleldrive/cuid2": "^2.2.0",
122
125
  "@poppinss/macroable": "^1.0.0-7",
123
126
  "@poppinss/utils": "^6.5.0-3",
124
- "@sindresorhus/is": "^5.4.1",
127
+ "@sindresorhus/is": "^5.5.2",
125
128
  "@types/he": "^1.2.0",
126
129
  "execa": "^7.1.1",
127
130
  "he": "^1.2.0",
@@ -133,6 +136,7 @@
133
136
  },
134
137
  "peerDependencies": {
135
138
  "@adonisjs/assembler": "^6.1.3-12",
139
+ "@vinejs/vine": "^1.5.2",
136
140
  "argon2": "^0.30.3",
137
141
  "bcrypt": "^5.0.1"
138
142
  },
@@ -145,6 +149,9 @@
145
149
  },
146
150
  "@adonisjs/assembler": {
147
151
  "optional": true
152
+ },
153
+ "@vinejs/vine": {
154
+ "optional": true
148
155
  }
149
156
  },
150
157
  "author": "virk,adonisjs",
@@ -1 +0,0 @@
1
- export * from '@adonisjs/http-server';