@adonisjs/core 6.19.0 → 7.0.0-next.1

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.
Files changed (177) hide show
  1. package/build/commands/add.d.ts +36 -5
  2. package/build/commands/add.js +24 -60
  3. package/build/commands/build.d.ts +23 -3
  4. package/build/commands/build.js +22 -36
  5. package/build/commands/commands.json +1 -1
  6. package/build/commands/configure.d.ts +35 -12
  7. package/build/commands/configure.js +39 -12
  8. package/build/commands/eject.d.ts +28 -3
  9. package/build/commands/eject.js +24 -5
  10. package/build/commands/env/add.d.ts +41 -4
  11. package/build/commands/env/add.js +32 -5
  12. package/build/commands/generate_key.d.ts +20 -1
  13. package/build/commands/generate_key.js +14 -1
  14. package/build/commands/inspect_rcfile.d.ts +20 -2
  15. package/build/commands/inspect_rcfile.js +20 -2
  16. package/build/commands/list/routes.d.ts +33 -11
  17. package/build/commands/list/routes.js +28 -5
  18. package/build/commands/make/command.d.ts +26 -3
  19. package/build/commands/make/command.js +25 -5
  20. package/build/commands/make/controller.d.ts +35 -2
  21. package/build/commands/make/controller.js +20 -2
  22. package/build/commands/make/event.d.ts +30 -4
  23. package/build/commands/make/event.js +27 -4
  24. package/build/commands/make/exception.d.ts +30 -4
  25. package/build/commands/make/exception.js +27 -4
  26. package/build/commands/make/listener.d.ts +38 -5
  27. package/build/commands/make/listener.js +32 -5
  28. package/build/commands/make/middleware.d.ts +25 -2
  29. package/build/commands/make/middleware.js +21 -4
  30. package/build/commands/make/preload.d.ts +31 -4
  31. package/build/commands/make/preload.js +28 -8
  32. package/build/commands/make/provider.d.ts +32 -3
  33. package/build/commands/make/provider.js +29 -7
  34. package/build/commands/make/service.d.ts +21 -2
  35. package/build/commands/make/service.js +18 -2
  36. package/build/commands/make/test.d.ts +27 -4
  37. package/build/commands/make/test.js +36 -8
  38. package/build/commands/make/transformer.d.ts +43 -0
  39. package/build/commands/make/transformer.js +65 -0
  40. package/build/commands/make/validator.d.ts +36 -5
  41. package/build/commands/make/validator.js +30 -5
  42. package/build/commands/make/view.d.ts +26 -3
  43. package/build/commands/make/view.js +24 -4
  44. package/build/commands/repl.d.ts +24 -4
  45. package/build/commands/repl.js +23 -3
  46. package/build/commands/serve.d.ts +38 -4
  47. package/build/commands/serve.js +34 -43
  48. package/build/commands/test.d.ts +68 -7
  49. package/build/commands/test.js +39 -37
  50. package/build/factories/core/ace.d.ts +31 -4
  51. package/build/factories/core/ace.js +20 -4
  52. package/build/factories/core/ignitor.d.ts +80 -9
  53. package/build/factories/core/ignitor.js +84 -13
  54. package/build/factories/core/main.d.ts +3 -3
  55. package/build/factories/core/main.js +3 -3
  56. package/build/factories/core/test_utils.d.ts +32 -4
  57. package/build/factories/core/test_utils.js +21 -4
  58. package/build/factories/stubs.d.ts +54 -5
  59. package/build/factories/stubs.js +55 -6
  60. package/build/index.d.ts +5 -4
  61. package/build/index.js +13 -9
  62. package/build/modules/ace/codemods.d.ts +71 -11
  63. package/build/modules/ace/codemods.js +90 -22
  64. package/build/modules/ace/commands.d.ts +48 -13
  65. package/build/modules/ace/commands.js +45 -10
  66. package/build/modules/ace/create_kernel.d.ts +19 -8
  67. package/build/modules/ace/create_kernel.js +19 -8
  68. package/build/modules/ace/kernel.d.ts +18 -4
  69. package/build/modules/ace/kernel.js +17 -3
  70. package/build/modules/ace/main.d.ts +3 -3
  71. package/build/modules/ace/main.js +3 -3
  72. package/build/modules/dumper/define_config.d.ts +25 -4
  73. package/build/modules/dumper/define_config.js +23 -2
  74. package/build/modules/dumper/dumper.d.ts +82 -12
  75. package/build/modules/dumper/dumper.js +82 -12
  76. package/build/modules/dumper/errors.d.ts +31 -10
  77. package/build/modules/dumper/errors.js +28 -7
  78. package/build/modules/dumper/main.d.ts +3 -3
  79. package/build/modules/dumper/main.js +3 -3
  80. package/build/modules/dumper/plugins/edge.d.ts +1 -1
  81. package/build/modules/hash/define_config.d.ts +53 -8
  82. package/build/modules/hash/define_config.js +51 -6
  83. package/build/modules/hash/main.d.ts +1 -1
  84. package/build/modules/hash/main.js +1 -1
  85. package/build/modules/http/main.d.ts +1 -1
  86. package/build/modules/http/main.js +1 -1
  87. package/build/modules/http/request_validator.d.ts +36 -9
  88. package/build/modules/http/request_validator.js +32 -5
  89. package/build/modules/transformers/main.d.ts +1 -0
  90. package/build/modules/transformers/main.js +9 -0
  91. package/build/providers/app_provider.d.ts +173 -1
  92. package/build/providers/app_provider.js +204 -8
  93. package/build/providers/edge_provider.d.ts +31 -2
  94. package/build/providers/edge_provider.js +31 -2
  95. package/build/providers/hash_provider.d.ts +38 -1
  96. package/build/providers/hash_provider.js +40 -3
  97. package/build/providers/repl_provider.d.ts +40 -1
  98. package/build/providers/repl_provider.js +52 -2
  99. package/build/providers/vinejs_provider.d.ts +32 -5
  100. package/build/providers/vinejs_provider.js +31 -4
  101. package/build/services/ace.d.ts +1 -1
  102. package/build/services/ace.js +1 -1
  103. package/build/services/app.d.ts +1 -1
  104. package/build/services/config.d.ts +1 -1
  105. package/build/services/config.js +1 -1
  106. package/build/services/dumper.js +1 -1
  107. package/build/services/emitter.d.ts +1 -1
  108. package/build/services/emitter.js +1 -1
  109. package/build/services/encryption.d.ts +1 -1
  110. package/build/services/encryption.js +1 -1
  111. package/build/services/hash.d.ts +1 -1
  112. package/build/services/hash.js +1 -1
  113. package/build/services/logger.d.ts +1 -1
  114. package/build/services/logger.js +1 -1
  115. package/build/services/repl.d.ts +1 -1
  116. package/build/services/repl.js +1 -1
  117. package/build/services/router.d.ts +1 -1
  118. package/build/services/router.js +1 -1
  119. package/build/services/server.d.ts +1 -1
  120. package/build/services/server.js +1 -1
  121. package/build/services/test_utils.d.ts +1 -1
  122. package/build/services/test_utils.js +1 -1
  123. package/build/services/url_builder.d.ts +4 -0
  124. package/build/services/url_builder.js +21 -0
  125. package/build/src/assembler_hooks/index_entities.d.ts +37 -0
  126. package/build/src/assembler_hooks/index_entities.js +106 -0
  127. package/build/src/cli_formatters/routes_list.d.ts +24 -12
  128. package/build/src/cli_formatters/routes_list.js +43 -46
  129. package/build/src/config_provider.d.ts +48 -3
  130. package/build/src/config_provider.js +47 -2
  131. package/build/src/debug.d.ts +15 -0
  132. package/build/src/debug.js +15 -0
  133. package/build/src/exceptions.d.ts +41 -1
  134. package/build/src/exceptions.js +41 -1
  135. package/build/src/helpers/assert.d.ts +47 -1
  136. package/build/src/helpers/assert.js +47 -1
  137. package/build/src/helpers/is.d.ts +21 -0
  138. package/build/src/helpers/is.js +21 -0
  139. package/build/src/helpers/main.d.ts +48 -5
  140. package/build/src/helpers/main.js +48 -5
  141. package/build/src/helpers/string.d.ts +89 -9
  142. package/build/src/helpers/string.js +21 -2
  143. package/build/src/helpers/types.d.ts +97 -2
  144. package/build/src/helpers/types.js +96 -2
  145. package/build/src/helpers/verification_token.d.ts +22 -1
  146. package/build/src/helpers/verification_token.js +24 -2
  147. package/build/src/ignitor/ace.d.ts +23 -3
  148. package/build/src/ignitor/ace.js +21 -1
  149. package/build/src/ignitor/http.d.ts +16 -3
  150. package/build/src/ignitor/http.js +16 -3
  151. package/build/src/ignitor/main.d.ts +29 -6
  152. package/build/src/ignitor/main.js +30 -7
  153. package/build/src/ignitor/test.d.ts +26 -3
  154. package/build/src/ignitor/test.js +24 -1
  155. package/build/src/test_utils/http.d.ts +19 -3
  156. package/build/src/test_utils/http.js +24 -3
  157. package/build/src/test_utils/main.d.ts +22 -4
  158. package/build/src/test_utils/main.js +21 -3
  159. package/build/src/types.d.ts +283 -26
  160. package/build/src/utils.d.ts +60 -0
  161. package/build/src/utils.js +104 -0
  162. package/build/src/vine.d.ts +24 -1
  163. package/build/src/vine.js +27 -1
  164. package/build/stubs/main.js +1 -2
  165. package/build/stubs/make/transformer/main.stub +18 -0
  166. package/build/toolkit/main.js +1 -1
  167. package/build/types/common.d.ts +1 -0
  168. package/build/types/common.js +9 -0
  169. package/build/types/helpers.d.ts +2 -1
  170. package/build/types/http.d.ts +1 -0
  171. package/build/types/transformers.d.ts +1 -0
  172. package/build/types/transformers.js +9 -0
  173. package/package.json +55 -52
  174. package/build/src/helpers/parse_binding_reference.d.ts +0 -45
  175. package/build/src/helpers/parse_binding_reference.js +0 -83
  176. package/build/src/internal_helpers.d.ts +0 -15
  177. package/build/src/internal_helpers.js +0 -63
@@ -0,0 +1,37 @@
1
+ import { type IndexEntitiesConfig } from '../types.ts';
2
+ /**
3
+ * Configures the IndexGenerator to create barrel files for "controllers", "events",
4
+ * and "listeners". This function is used as an assembler hook to automatically generate
5
+ * index files that export all modules from specified directories.
6
+ *
7
+ * @param {IndexEntitiesConfig} entities - Configuration object for entities indexing
8
+ *
9
+ * @example
10
+ * // Basic usage with default configuration
11
+ * indexEntities({})
12
+ *
13
+ * @example
14
+ * // Custom configuration for specific entities
15
+ * indexEntities({
16
+ * events: {
17
+ * enabled: true,
18
+ * source: 'app/custom-events',
19
+ * importAlias: '#custom-events'
20
+ * },
21
+ * controllers: {
22
+ * enabled: false
23
+ * }
24
+ * })
25
+ *
26
+ * @example
27
+ * // Using custom glob patterns
28
+ * indexEntities({
29
+ * listeners: {
30
+ * source: 'app/handlers',
31
+ * glob: '**\/*_handler.ts'
32
+ * }
33
+ * })
34
+ */
35
+ export declare function indexEntities(entities?: IndexEntitiesConfig): {
36
+ run(_: import("@adonisjs/assembler").DevServer | import("@adonisjs/assembler").TestRunner | import("@adonisjs/assembler").Bundler, indexGenerator: import("@adonisjs/assembler/index_generator").IndexGenerator): void;
37
+ };
@@ -0,0 +1,106 @@
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 stringHelpers from "../helpers/string.js";
10
+ import { outputTransformerDataObjects } from "../utils.js";
11
+ /**
12
+ * Configures the IndexGenerator to create barrel files for "controllers", "events",
13
+ * and "listeners". This function is used as an assembler hook to automatically generate
14
+ * index files that export all modules from specified directories.
15
+ *
16
+ * @param {IndexEntitiesConfig} entities - Configuration object for entities indexing
17
+ *
18
+ * @example
19
+ * // Basic usage with default configuration
20
+ * indexEntities({})
21
+ *
22
+ * @example
23
+ * // Custom configuration for specific entities
24
+ * indexEntities({
25
+ * events: {
26
+ * enabled: true,
27
+ * source: 'app/custom-events',
28
+ * importAlias: '#custom-events'
29
+ * },
30
+ * controllers: {
31
+ * enabled: false
32
+ * }
33
+ * })
34
+ *
35
+ * @example
36
+ * // Using custom glob patterns
37
+ * indexEntities({
38
+ * listeners: {
39
+ * source: 'app/handlers',
40
+ * glob: '**\/*_handler.ts'
41
+ * }
42
+ * })
43
+ */
44
+ export function indexEntities(entities = {}) {
45
+ const events = Object.assign({ enabled: true, source: 'app/events', importAlias: '#events' }, entities.events);
46
+ const listeners = Object.assign({ enabled: true, source: 'app/listeners', importAlias: '#listeners' }, entities.listeners);
47
+ const controllers = Object.assign({ enabled: true, source: 'app/controllers', importAlias: '#controllers' }, entities.controllers);
48
+ const transformers = Object.assign({ enabled: false, source: 'app/transformers', importAlias: '#transformers' }, entities.transformers);
49
+ return {
50
+ run(_, indexGenerator) {
51
+ if (events.enabled) {
52
+ indexGenerator.add('events', {
53
+ source: events.source,
54
+ glob: events.glob,
55
+ as: 'barrelFile',
56
+ exportName: 'events',
57
+ importAlias: events.importAlias,
58
+ output: '.adonisjs/server/events.ts',
59
+ });
60
+ }
61
+ if (listeners.enabled) {
62
+ indexGenerator.add('listeners', {
63
+ source: listeners.source,
64
+ glob: listeners.glob,
65
+ as: 'barrelFile',
66
+ exportName: 'listeners',
67
+ importAlias: listeners.importAlias,
68
+ output: '.adonisjs/server/listeners.ts',
69
+ });
70
+ }
71
+ if (controllers.enabled) {
72
+ indexGenerator.add('controllers', {
73
+ source: controllers.source,
74
+ glob: controllers.glob,
75
+ as: 'barrelFile',
76
+ exportName: 'controllers',
77
+ importAlias: controllers.importAlias,
78
+ removeSuffix: 'controller',
79
+ output: '.adonisjs/server/controllers.ts',
80
+ });
81
+ }
82
+ if (transformers.enabled) {
83
+ indexGenerator.add('transformers', {
84
+ source: transformers.source,
85
+ glob: transformers.glob,
86
+ as(vfs, buffer, __, helpers) {
87
+ const transformersList = vfs.asTree({
88
+ transformKey(key) {
89
+ const segments = key.split('/');
90
+ const baseName = segments.pop();
91
+ return [
92
+ ...segments.map((segment) => stringHelpers.pascalCase(segment)),
93
+ stringHelpers.create(baseName).removeSuffix('transformer').pascalCase(),
94
+ ].join('/');
95
+ },
96
+ transformValue: helpers.toImportPath,
97
+ });
98
+ outputTransformerDataObjects(transformersList, buffer);
99
+ },
100
+ importAlias: transformers.importAlias,
101
+ output: '.adonisjs/client/data.d.ts',
102
+ });
103
+ }
104
+ },
105
+ };
106
+ }
@@ -1,5 +1,6 @@
1
- import type { UIPrimitives } from '../../types/ace.js';
2
- import { type Router } from '../../modules/http/main.js';
1
+ import type { UIPrimitives } from '../../types/ace.ts';
2
+ import { type Router } from '../../modules/http/main.ts';
3
+ import type { MiddlewareHandlerInfo, RouteHandlerInfo } from '../../types/http.ts';
3
4
  /**
4
5
  * Shape of the serialized route specific to the formatter
5
6
  */
@@ -7,25 +8,36 @@ type SerializedRoute = {
7
8
  name: string;
8
9
  pattern: string;
9
10
  methods: string[];
10
- middleware: string[];
11
- handler: {
12
- type: 'closure';
13
- name: string;
14
- args?: string;
15
- } | {
16
- type: 'controller';
17
- moduleNameOrPath: string;
18
- method: string;
19
- };
11
+ middleware: MiddlewareHandlerInfo[];
12
+ handler: RouteHandlerInfo;
20
13
  };
21
14
  /**
22
15
  * Routes list formatter is used to format the routes to JSON or an ANSI string
23
16
  * with pretty output.
24
17
  *
25
18
  * The decisions of colors, padding, alignment are all handled by the lists formatter
19
+ *
20
+ * @example
21
+ * const formatter = new RoutesListFormatter(router, ui, {
22
+ * displayHeadRoutes: false,
23
+ * maxPrettyPrintWidth: 120
24
+ * }, {
25
+ * match: 'api',
26
+ * middleware: ['auth']
27
+ * })
28
+ *
29
+ * const ansiOutput = await formatter.formatAsAnsiList()
26
30
  */
27
31
  export declare class RoutesListFormatter {
28
32
  #private;
33
+ /**
34
+ * Creates a new instance of the routes list formatter
35
+ *
36
+ * @param router - Router instance containing routes to format
37
+ * @param ui - UI primitives for colors and table formatting
38
+ * @param options - Display options for route formatting
39
+ * @param filters - Filters to apply when displaying routes
40
+ */
29
41
  constructor(router: Router, ui: UIPrimitives, options: {
30
42
  displayHeadRoutes?: boolean;
31
43
  maxPrettyPrintWidth?: number;
@@ -7,17 +7,37 @@
7
7
  * file that was distributed with this source code.
8
8
  */
9
9
  import stringWidth from 'string-width';
10
- import { cliHelpers } from '../../modules/ace/main.js';
11
- import { parseBindingReference } from '../../src/helpers/main.js';
10
+ import { cliHelpers } from "../../modules/ace/main.js";
11
+ import { middlewareInfo, routeInfo } from '@adonisjs/http-server/helpers';
12
12
  /**
13
13
  * Routes list formatter is used to format the routes to JSON or an ANSI string
14
14
  * with pretty output.
15
15
  *
16
16
  * The decisions of colors, padding, alignment are all handled by the lists formatter
17
+ *
18
+ * @example
19
+ * const formatter = new RoutesListFormatter(router, ui, {
20
+ * displayHeadRoutes: false,
21
+ * maxPrettyPrintWidth: 120
22
+ * }, {
23
+ * match: 'api',
24
+ * middleware: ['auth']
25
+ * })
26
+ *
27
+ * const ansiOutput = await formatter.formatAsAnsiList()
17
28
  */
18
29
  export class RoutesListFormatter {
30
+ /**
31
+ * Router instance containing all registered routes
32
+ */
19
33
  #router;
34
+ /**
35
+ * Colors utility for ANSI formatting
36
+ */
20
37
  #colors;
38
+ /**
39
+ * Table utility for creating formatted tables
40
+ */
21
41
  #table;
22
42
  /**
23
43
  * Options for printing routes
@@ -27,6 +47,14 @@ export class RoutesListFormatter {
27
47
  * Filters to apply when finding routes
28
48
  */
29
49
  #filters;
50
+ /**
51
+ * Creates a new instance of the routes list formatter
52
+ *
53
+ * @param router - Router instance containing routes to format
54
+ * @param ui - UI primitives for colors and table formatting
55
+ * @param options - Display options for route formatting
56
+ * @param filters - Filters to apply when displaying routes
57
+ */
30
58
  constructor(router, ui, options, filters) {
31
59
  this.#router = router;
32
60
  this.#colors = ui.colors;
@@ -49,7 +77,7 @@ export class RoutesListFormatter {
49
77
  if (name === '*') {
50
78
  return route.middleware.length > 0;
51
79
  }
52
- return route.middleware.includes(name);
80
+ return route.middleware.find((middleware) => middleware.name === name);
53
81
  });
54
82
  }
55
83
  /**
@@ -61,7 +89,7 @@ export class RoutesListFormatter {
61
89
  if (name === '*') {
62
90
  return route.middleware.length === 0;
63
91
  }
64
- return !route.middleware.includes(name);
92
+ return !route.middleware.find((middleware) => middleware.name === name);
65
93
  });
66
94
  }
67
95
  /**
@@ -95,43 +123,6 @@ export class RoutesListFormatter {
95
123
  */
96
124
  return false;
97
125
  }
98
- /**
99
- * Serialize route middleware to an array of names
100
- */
101
- #serializeMiddleware(middleware) {
102
- return [...middleware.all()].reduce((result, one) => {
103
- if (typeof one === 'function') {
104
- result.push(one.name || 'closure');
105
- return result;
106
- }
107
- if ('name' in one && one.name) {
108
- result.push(one.name);
109
- }
110
- return result;
111
- }, []);
112
- }
113
- /**
114
- * Serialize route handler reference to display object
115
- */
116
- async #serializeHandler(handler) {
117
- /**
118
- * Value is a controller reference
119
- */
120
- if ('reference' in handler) {
121
- return {
122
- type: 'controller',
123
- ...(await parseBindingReference(handler.reference)),
124
- };
125
- }
126
- /**
127
- * Value is an inline closure
128
- */
129
- return {
130
- type: 'closure',
131
- name: handler.name || 'closure',
132
- args: 'listArgs' in handler ? String(handler.listArgs) : undefined,
133
- };
134
- }
135
126
  /**
136
127
  * Serializes routes JSON to an object that can be used for pretty printing
137
128
  */
@@ -140,12 +131,15 @@ export class RoutesListFormatter {
140
131
  if (!this.#options.displayHeadRoutes) {
141
132
  methods = methods.filter((method) => method !== 'HEAD');
142
133
  }
134
+ const middlewareList = await Promise.all([...route.middleware.all()].map((middleware) => {
135
+ return middlewareInfo(middleware);
136
+ }));
143
137
  return {
144
138
  name: route.name || '',
145
139
  pattern: route.pattern,
146
140
  methods: methods,
147
- handler: await this.#serializeHandler(route.handler),
148
- middleware: this.#serializeMiddleware(route.middleware),
141
+ handler: await routeInfo(route),
142
+ middleware: middlewareList.filter((info) => info.type !== 'global'),
149
143
  };
150
144
  }
151
145
  /**
@@ -201,12 +195,15 @@ export class RoutesListFormatter {
201
195
  */
202
196
  #formatMiddleware(route, mode = 'normal') {
203
197
  if (mode === 'compact' && route.middleware.length > 3) {
204
- const firstMiddleware = route.middleware[0];
205
- const secondMiddleware = route.middleware[1];
198
+ const firstMiddleware = route.middleware[0].name;
199
+ const secondMiddleware = route.middleware[1].name;
206
200
  const diff = route.middleware.length - 2;
207
201
  return this.#colors.dim(`${firstMiddleware}, ${secondMiddleware}, and ${diff} more`);
208
202
  }
209
- return this.#colors.dim(`${route.middleware.filter((one) => one).join(', ')}`);
203
+ return this.#colors.dim(`${route.middleware
204
+ .map((one) => one.name)
205
+ .filter((one) => one)
206
+ .join(', ')}`);
210
207
  }
211
208
  /**
212
209
  * Formatting the domain headling to be in green color with
@@ -1,9 +1,54 @@
1
- import { ApplicationService, ConfigProvider } from './types.js';
1
+ import { type ApplicationService, type ConfigProvider } from './types.ts';
2
2
  /**
3
- * Helper to create config provider and resolve config from
4
- * them
3
+ * Helper utilities to create and resolve config providers. Config providers
4
+ * are used to defer configuration resolution until the application is booted,
5
+ * allowing access to environment variables and other application services.
6
+ *
7
+ * @example
8
+ * // Creating a database config provider
9
+ * const databaseConfig = configProvider.create(async (app) => ({
10
+ * connection: app.env.get('DB_CONNECTION', 'sqlite'),
11
+ * host: app.env.get('DB_HOST', 'localhost'),
12
+ * port: app.env.get('DB_PORT', 5432)
13
+ * }))
14
+ *
15
+ * @example
16
+ * // Resolving a config provider
17
+ * const config = await configProvider.resolve(app, databaseConfig)
18
+ * if (config) {
19
+ * console.log(`Database connection: ${config.connection}`)
20
+ * }
5
21
  */
6
22
  export declare const configProvider: {
23
+ /**
24
+ * Creates a new config provider that will resolve configuration
25
+ * when the application is booted.
26
+ *
27
+ * @param resolver - Function that receives the application service and returns the configuration
28
+ *
29
+ * @example
30
+ * const mailConfig = configProvider.create(async (app) => ({
31
+ * driver: app.env.get('MAIL_DRIVER', 'smtp'),
32
+ * host: app.env.get('SMTP_HOST'),
33
+ * port: app.env.get('SMTP_PORT', 587)
34
+ * }))
35
+ */
7
36
  create<T>(resolver: ConfigProvider<T>["resolver"]): ConfigProvider<T>;
37
+ /**
38
+ * Resolves a config provider if the provided value is a valid config provider,
39
+ * otherwise returns null.
40
+ *
41
+ * @param app - The application service instance
42
+ * @param provider - The potential config provider to resolve
43
+ *
44
+ * @example
45
+ * const resolved = await configProvider.resolve(app, someProvider)
46
+ * if (resolved) {
47
+ * // Use the resolved configuration
48
+ * console.log('Config resolved:', resolved)
49
+ * } else {
50
+ * console.log('Not a valid config provider')
51
+ * }
52
+ */
8
53
  resolve<T>(app: ApplicationService, provider: unknown): Promise<T | null>;
9
54
  };
@@ -7,16 +7,61 @@
7
7
  * file that was distributed with this source code.
8
8
  */
9
9
  /**
10
- * Helper to create config provider and resolve config from
11
- * them
10
+ * Helper utilities to create and resolve config providers. Config providers
11
+ * are used to defer configuration resolution until the application is booted,
12
+ * allowing access to environment variables and other application services.
13
+ *
14
+ * @example
15
+ * // Creating a database config provider
16
+ * const databaseConfig = configProvider.create(async (app) => ({
17
+ * connection: app.env.get('DB_CONNECTION', 'sqlite'),
18
+ * host: app.env.get('DB_HOST', 'localhost'),
19
+ * port: app.env.get('DB_PORT', 5432)
20
+ * }))
21
+ *
22
+ * @example
23
+ * // Resolving a config provider
24
+ * const config = await configProvider.resolve(app, databaseConfig)
25
+ * if (config) {
26
+ * console.log(`Database connection: ${config.connection}`)
27
+ * }
12
28
  */
13
29
  export const configProvider = {
30
+ /**
31
+ * Creates a new config provider that will resolve configuration
32
+ * when the application is booted.
33
+ *
34
+ * @param resolver - Function that receives the application service and returns the configuration
35
+ *
36
+ * @example
37
+ * const mailConfig = configProvider.create(async (app) => ({
38
+ * driver: app.env.get('MAIL_DRIVER', 'smtp'),
39
+ * host: app.env.get('SMTP_HOST'),
40
+ * port: app.env.get('SMTP_PORT', 587)
41
+ * }))
42
+ */
14
43
  create(resolver) {
15
44
  return {
16
45
  type: 'provider',
17
46
  resolver,
18
47
  };
19
48
  },
49
+ /**
50
+ * Resolves a config provider if the provided value is a valid config provider,
51
+ * otherwise returns null.
52
+ *
53
+ * @param app - The application service instance
54
+ * @param provider - The potential config provider to resolve
55
+ *
56
+ * @example
57
+ * const resolved = await configProvider.resolve(app, someProvider)
58
+ * if (resolved) {
59
+ * // Use the resolved configuration
60
+ * console.log('Config resolved:', resolved)
61
+ * } else {
62
+ * console.log('Not a valid config provider')
63
+ * }
64
+ */
20
65
  async resolve(app, provider) {
21
66
  if (provider && typeof provider === 'object' && 'type' in provider) {
22
67
  return provider.resolver(app);
@@ -1,2 +1,17 @@
1
+ /**
2
+ * Debug utility for AdonisJS core. This uses Node.js built-in debuglog
3
+ * utility to provide debugging information when the NODE_DEBUG environment
4
+ * variable includes 'adonisjs:core'.
5
+ *
6
+ * @example
7
+ * // Enable debugging by setting environment variable
8
+ * // NODE_DEBUG=adonisjs:core node app.js
9
+ *
10
+ * @example
11
+ * // Usage in code
12
+ * import debug from '@adonisjs/core/debug'
13
+ * debug('Application started')
14
+ * debug('Processing request: %s', req.url)
15
+ */
1
16
  declare const _default: import("util").DebugLogger;
2
17
  export default _default;
@@ -7,4 +7,19 @@
7
7
  * file that was distributed with this source code.
8
8
  */
9
9
  import { debuglog } from 'node:util';
10
+ /**
11
+ * Debug utility for AdonisJS core. This uses Node.js built-in debuglog
12
+ * utility to provide debugging information when the NODE_DEBUG environment
13
+ * variable includes 'adonisjs:core'.
14
+ *
15
+ * @example
16
+ * // Enable debugging by setting environment variable
17
+ * // NODE_DEBUG=adonisjs:core node app.js
18
+ *
19
+ * @example
20
+ * // Usage in code
21
+ * import debug from '@adonisjs/core/debug'
22
+ * debug('Application started')
23
+ * debug('Processing request: %s', req.url)
24
+ */
10
25
  export default debuglog('adonisjs:core');
@@ -1 +1,41 @@
1
- export { Exception, createError, RuntimeException, InvalidArgumentsException, } from '@poppinss/utils';
1
+ /**
2
+ * Core exception classes and utilities for AdonisJS. This module re-exports
3
+ * commonly used exception classes from @poppinss/utils for creating and
4
+ * handling errors in AdonisJS applications.
5
+ *
6
+ * @example
7
+ * // Creating a custom exception
8
+ * import { Exception } from '@adonisjs/core/exceptions'
9
+ *
10
+ * class ValidationException extends Exception {
11
+ * static status = 422
12
+ * static code = 'E_VALIDATION_FAILURE'
13
+ * }
14
+ *
15
+ * @example
16
+ * // Using createError to create custom error classes
17
+ * import { createError } from '@adonisjs/core/exceptions'
18
+ *
19
+ * const UserNotFound = createError('User not found', 'E_USER_NOT_FOUND', 404)
20
+ * throw new UserNotFound()
21
+ */
22
+ export {
23
+ /**
24
+ * Base exception class for creating custom exceptions with status codes,
25
+ * error codes, and additional context.
26
+ */
27
+ Exception,
28
+ /**
29
+ * Utility function to create custom error classes with predefined
30
+ * message, code, and status.
31
+ */
32
+ createError,
33
+ /**
34
+ * Runtime exception class for errors that occur during application runtime.
35
+ */
36
+ RuntimeException,
37
+ /**
38
+ * Exception class for invalid argument errors, typically used in function
39
+ * parameter validation.
40
+ */
41
+ InvalidArgumentsException, } from '@poppinss/utils/exception';
@@ -6,4 +6,44 @@
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 { Exception, createError, RuntimeException, InvalidArgumentsException, } from '@poppinss/utils';
9
+ /**
10
+ * Core exception classes and utilities for AdonisJS. This module re-exports
11
+ * commonly used exception classes from @poppinss/utils for creating and
12
+ * handling errors in AdonisJS applications.
13
+ *
14
+ * @example
15
+ * // Creating a custom exception
16
+ * import { Exception } from '@adonisjs/core/exceptions'
17
+ *
18
+ * class ValidationException extends Exception {
19
+ * static status = 422
20
+ * static code = 'E_VALIDATION_FAILURE'
21
+ * }
22
+ *
23
+ * @example
24
+ * // Using createError to create custom error classes
25
+ * import { createError } from '@adonisjs/core/exceptions'
26
+ *
27
+ * const UserNotFound = createError('User not found', 'E_USER_NOT_FOUND', 404)
28
+ * throw new UserNotFound()
29
+ */
30
+ export {
31
+ /**
32
+ * Base exception class for creating custom exceptions with status codes,
33
+ * error codes, and additional context.
34
+ */
35
+ Exception,
36
+ /**
37
+ * Utility function to create custom error classes with predefined
38
+ * message, code, and status.
39
+ */
40
+ createError,
41
+ /**
42
+ * Runtime exception class for errors that occur during application runtime.
43
+ */
44
+ RuntimeException,
45
+ /**
46
+ * Exception class for invalid argument errors, typically used in function
47
+ * parameter validation.
48
+ */
49
+ InvalidArgumentsException, } from '@poppinss/utils/exception';
@@ -1 +1,47 @@
1
- export { assertExists, assertNotNull, assertIsDefined, assertUnreachable, } from '@poppinss/utils/assert';
1
+ /**
2
+ * Assertion utilities for type-safe programming in AdonisJS. These functions
3
+ * provide runtime type assertions that help with TypeScript type narrowing
4
+ * and catching potential null/undefined issues early.
5
+ *
6
+ * @example
7
+ * // Type-safe null checking
8
+ * import { assertExists } from '@adonisjs/core/helpers'
9
+ *
10
+ * function processUser(user: User | null) {
11
+ * assertExists(user) // TypeScript now knows user is not null
12
+ * console.log(user.name) // Safe to access properties
13
+ * }
14
+ *
15
+ * @example
16
+ * // Exhaustiveness checking in switch statements
17
+ * import { assertUnreachable } from '@adonisjs/core/helpers'
18
+ *
19
+ * function handleStatus(status: 'pending' | 'completed') {
20
+ * switch (status) {
21
+ * case 'pending': return 'Processing...'
22
+ * case 'completed': return 'Done!'
23
+ * default: return assertUnreachable(status)
24
+ * }
25
+ * }
26
+ */
27
+ export {
28
+ /**
29
+ * Assert that a value exists (is not null or undefined).
30
+ * Throws an error if the value is null or undefined.
31
+ */
32
+ assertExists,
33
+ /**
34
+ * Assert that a value is not null.
35
+ * Throws an error if the value is null.
36
+ */
37
+ assertNotNull,
38
+ /**
39
+ * Assert that a value is defined (is not undefined).
40
+ * Throws an error if the value is undefined.
41
+ */
42
+ assertIsDefined,
43
+ /**
44
+ * Assert that code should never reach this point.
45
+ * Useful for exhaustiveness checking in switch statements.
46
+ */
47
+ assertUnreachable, } from '@poppinss/utils/assert';