@nhtio/lucid-resourceful 0.1.0-master-29dd5a13 → 0.1.0-master-641df8fc

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 (109) hide show
  1. package/adonis-env.d.ts +17 -0
  2. package/bundled_liqe.d.ts +6 -5
  3. package/bundled_xml_js.d.ts +5 -4
  4. package/definitions.d.ts +1 -1
  5. package/encoding.d.ts +6 -6
  6. package/errors.d.ts +23 -8
  7. package/{index-Bsyx9Sty.js → index-B-5JiNqG.js} +76 -221
  8. package/index-B-5JiNqG.js.map +1 -0
  9. package/{index-B6dIMDux.cjs → index-BrGbuAtt.cjs} +76 -221
  10. package/index-BrGbuAtt.cjs.map +1 -0
  11. package/index-C9zyi90j.js.map +1 -1
  12. package/{index-CpyTnwZV.cjs → index-CQApAM0M.cjs} +298 -353
  13. package/index-CQApAM0M.cjs.map +1 -0
  14. package/index-CxRBayw6.cjs.map +1 -1
  15. package/{index-C8mGEf4P.js → index-DLVvkVxI.js} +295 -350
  16. package/index-DLVvkVxI.js.map +1 -0
  17. package/index-DsojAcQ4.js.map +1 -1
  18. package/index-DuzIXu31.cjs.map +1 -1
  19. package/index.cjs +1 -1
  20. package/index.d.ts +7 -7
  21. package/index.mjs +1 -1
  22. package/integration/middlewares/odata_error.cjs +1 -1
  23. package/integration/middlewares/odata_error.d.ts +1 -1
  24. package/integration/middlewares/odata_error.mjs +1 -1
  25. package/integration/middlewares/resourceful_encoded_request.cjs +100 -12
  26. package/integration/middlewares/resourceful_encoded_request.cjs.map +1 -1
  27. package/integration/middlewares/resourceful_encoded_request.d.ts +1 -1
  28. package/integration/middlewares/resourceful_encoded_request.mjs +98 -10
  29. package/integration/middlewares/resourceful_encoded_request.mjs.map +1 -1
  30. package/integration/middlewares/resourceful_error.cjs +1 -1
  31. package/integration/middlewares/resourceful_error.d.ts +1 -1
  32. package/integration/middlewares/resourceful_error.mjs +1 -1
  33. package/integration/provider.cjs +1 -1
  34. package/integration/provider.mjs +1 -1
  35. package/joi.d.ts +1 -1
  36. package/{manager-OLS5T3G7-CJHhMwR7.cjs → manager-OLS5T3G7-BPVI59Zw.cjs} +2 -2
  37. package/{manager-OLS5T3G7-CJHhMwR7.cjs.map → manager-OLS5T3G7-BPVI59Zw.cjs.map} +1 -1
  38. package/{manager-OLS5T3G7-C-NS6lhx.js → manager-OLS5T3G7-DzVckqOB.js} +2 -2
  39. package/{manager-OLS5T3G7-C-NS6lhx.js.map → manager-OLS5T3G7-DzVckqOB.js.map} +1 -1
  40. package/odata/context.d.ts +1 -1
  41. package/odata/macro.d.ts +1 -1
  42. package/{odata_error_middleware-BWfOpQZV.cjs → odata_error_middleware-DhLzccN7.cjs} +4 -4
  43. package/{odata_error_middleware-BWfOpQZV.cjs.map → odata_error_middleware-DhLzccN7.cjs.map} +1 -1
  44. package/{odata_error_middleware-CWYqZMez.js → odata_error_middleware-Dspi8bct.js} +4 -4
  45. package/{odata_error_middleware-CWYqZMez.js.map → odata_error_middleware-Dspi8bct.js.map} +1 -1
  46. package/package.json +1 -1
  47. package/private/data_type_schemas.d.ts +12 -12
  48. package/private/data_types.d.ts +1 -1
  49. package/private/decorator_schemas.d.ts +1 -1
  50. package/private/decorator_utils.d.ts +1 -1
  51. package/private/decorators.d.ts +14 -11
  52. package/private/encoding.d.ts +3 -3
  53. package/private/joi/index.d.ts +3 -3
  54. package/private/lucene_to_lucid_translator.d.ts +1 -1
  55. package/private/mixin.d.ts +25 -8
  56. package/private/odata_macro/controllers/resourceful_model_controller.d.ts +4 -4
  57. package/private/odata_macro/index.d.ts +1 -1
  58. package/private/odata_macro/middlewares/odata_error_middleware.d.ts +22 -10
  59. package/private/odata_macro/services/odata_context_service.d.ts +1 -1
  60. package/private/odata_macro/services/odata_metadata_service.d.ts +3 -3
  61. package/private/odata_macro/utils/odata.d.ts +2 -2
  62. package/private/odata_to_lucid_translator.d.ts +1 -1
  63. package/private/open_api_schema_service.d.ts +3 -3
  64. package/private/router_macro/controllers/resourceful_model_controller.d.ts +5 -5
  65. package/private/router_macro/index.d.ts +3 -3
  66. package/private/router_macro/middlewares/resourceful_error_middleware.d.ts +22 -10
  67. package/private/router_macro/services/resourceful_router_choices_service.d.ts +3 -3
  68. package/private/router_macro/services/resourceful_router_context_service.d.ts +1 -1
  69. package/private/router_macro/services/resourceful_router_model_options_service.d.ts +1 -1
  70. package/private/router_macro/services/resourceful_router_model_resolver_service.d.ts +3 -3
  71. package/private/router_macro/services/resourceful_router_openapi_document_service.d.ts +4 -4
  72. package/private/router_macro/services/resourceful_router_options_service.d.ts +3 -3
  73. package/private/router_macro/types.d.ts +15 -8
  74. package/private/router_macro/utils/errors.d.ts +1 -1
  75. package/private/router_macro/utils/http.d.ts +1 -1
  76. package/private/router_macro/utils/openapi_validation_schemas.d.ts +2 -2
  77. package/private/router_macro/utils/relationships.d.ts +1 -1
  78. package/private/router_macro/utils/type_guards.d.ts +1 -1
  79. package/private/schema_types.d.ts +1 -1
  80. package/private/type_guards.d.ts +5 -5
  81. package/private/types.d.ts +5 -5
  82. package/private/utils/casters.d.ts +1 -1
  83. package/private/utils/consumers.d.ts +1 -1
  84. package/private/utils/preparers.d.ts +1 -1
  85. package/private/utils.d.ts +1 -1
  86. package/{resourceful_error_middleware-CMSZGdoG.js → resourceful_error_middleware-Cb_eTzST.js} +4 -4
  87. package/{resourceful_error_middleware-CMSZGdoG.js.map → resourceful_error_middleware-Cb_eTzST.js.map} +1 -1
  88. package/{resourceful_error_middleware-lXgefPIC.cjs → resourceful_error_middleware-CnjbNoev.cjs} +4 -4
  89. package/{resourceful_error_middleware-lXgefPIC.cjs.map → resourceful_error_middleware-CnjbNoev.cjs.map} +1 -1
  90. package/router/context.d.ts +1 -1
  91. package/router/utils.cjs +1 -1
  92. package/router/utils.d.ts +1 -1
  93. package/router/utils.mjs +1 -1
  94. package/router.cjs +1 -1
  95. package/router.d.ts +2 -2
  96. package/router.mjs +1 -1
  97. package/types.d.ts +13 -13
  98. package/utils.d.ts +4 -4
  99. package/vite-env.d.ts +3 -0
  100. package/index-B6dIMDux.cjs.map +0 -1
  101. package/index-Bsyx9Sty.js.map +0 -1
  102. package/index-C8mGEf4P.js.map +0 -1
  103. package/index-CpIq4gOr.js +0 -93
  104. package/index-CpIq4gOr.js.map +0 -1
  105. package/index-CpyTnwZV.cjs.map +0 -1
  106. package/index-DqbJXpcT.cjs +0 -92
  107. package/index-DqbJXpcT.cjs.map +0 -1
  108. package/private/controller_factory.d.ts +0 -1
  109. package/private/utils/function_serializer.d.ts +0 -32
@@ -1 +1 @@
1
- {"version":3,"file":"odata_error_middleware-CWYqZMez.js","sources":["../src/private/odata_macro/utils/http.ts","../src/private/odata_macro/middlewares/odata_error_middleware.ts"],"sourcesContent":["import type { HttpContext } from '@adonisjs/core/http'\n\nexport const ODataResponseFormat = ['xml' as 'xml', 'json' as 'json']\nexport type ODataResponseFormat = (typeof ODataResponseFormat)[number]\n\nexport const negotiateContent = (\n ctx: HttpContext,\n fallback: ODataResponseFormat = 'json'\n): ODataResponseFormat => {\n for (const acceptable of ODataResponseFormat) {\n const query = ctx.request.qs()\n if ('string' === typeof query['$format'] && query['$format'].includes(acceptable)) {\n return acceptable\n }\n if (ctx.request.header('accept')?.includes(acceptable)) {\n return acceptable\n }\n }\n return fallback\n}\n\nexport const ODataMetadataLevel = ['full' as 'full', 'minimal' as 'minimal', 'none' as 'none']\nexport type ODataMetadataLevel = (typeof ODataMetadataLevel)[number]\n\nexport const negotiateMetadata = (\n ctx: HttpContext,\n fallback: ODataMetadataLevel = 'minimal'\n): ODataMetadataLevel => {\n for (const acceptable of ODataMetadataLevel) {\n const query = ctx.request.qs()\n if (\n 'string' === typeof query['$format'] &&\n query['$format'].includes(`metadata=${acceptable}`)\n ) {\n return acceptable\n }\n if (ctx.request.header('accept')?.includes(`metadata=${acceptable}`)) {\n return acceptable\n }\n }\n return fallback\n}\n\nexport const ODataPreference = ['representation' as 'representation', 'minimal' as 'minimal']\nexport type ODataPreference = (typeof ODataPreference)[number]\n\nexport const negotiatePreference = (\n ctx: HttpContext,\n fallback: ODataPreference = 'representation'\n): ODataPreference => {\n const prefer = ctx.request.header('prefer')\n if (prefer) {\n for (const acceptable of ODataPreference) {\n if (prefer.includes(acceptable)) {\n return acceptable\n }\n }\n }\n return fallback\n}\n","/*\n|--------------------------------------------------------------------------\n| Resourceful Error Middleware\n|--------------------------------------------------------------------------\n|\n| Intercepts errors thrown during http requests and formats the responses\n| in a consistent manner meant to be easily consumed by clients.\n|\n| While designed specifically to work with Lucid Resourceful, there is no\n| reason it cannot be applied to non-resourceful routes as well.\n*/\nimport { js2xml } from 'xml-js'\nimport { errors } from '@vinejs/vine'\nimport { Exception } from '@poppinss/utils'\nimport { negotiateContent } from '../utils/http'\nimport { default as string } from '@poppinss/string'\nimport { TypedEventEmitter } from '@nhtio/tiny-typed-emitter'\nimport { isObject, stripUndefinedValuesFromObject } from '../../utils'\nimport { ValidationError as JoiValidationError } from '@nhtio/lucid-resourceful/joi'\nimport {\n isError,\n isException,\n isJoiValidationError,\n isVineValidationError,\n isNotImplementedError,\n} from '../../router_macro/utils/errors'\nimport type { JsonObject } from 'type-fest'\nimport type { ElementCompact } from 'xml-js'\nimport type { HttpContext } from '@adonisjs/core/http'\nimport type { NextFn } from '@adonisjs/core/types/http'\nimport type { EventMap } from '@nhtio/tiny-typed-emitter'\n/**\n * Type alias for Vine validation errors thrown by the VineJS validation library.\n *\n * @example\n * ```typescript\n * try {\n * await vine.validate(schema, data)\n * } catch (error) {\n * if (isVineValidationError(error)) {\n * // Handle Vine validation error\n * }\n * }\n * ```\n */\nexport type VineValidationError = InstanceType<typeof errors.E_VALIDATION_ERROR>\n\n/**\n * Event map defining the types of errors that can be emitted by the ODataErrorMiddleware.\n * Each event type maps to the specific error instance that will be passed to event handlers.\n *\n * @example\n * ```typescript\n * const middleware = new ODataErrorMiddleware({\n * onVineValidationError: (error) => logger.warn('Validation failed', error),\n * onException: (error) => monitoring.captureException(error),\n * onAny: (error) => analytics.trackError(error)\n * })\n * ```\n */\nexport type ODataErrorMiddlewareEvents = EventMap<{\n vineValidationError: [VineValidationError]\n joiValidationError: [JoiValidationError]\n exception: [Exception]\n error: [Error]\n unknown: [unknown]\n any: [unknown]\n}>\n\nclass ODataErrorMiddlewareEmitter extends TypedEventEmitter<ODataErrorMiddlewareEvents> {}\n\n/**\n * Configuration object for custom HTTP headers to be included in error responses.\n * Allows for CORS headers, security headers, API versioning, or any custom headers\n * that should be consistently applied to all error responses.\n *\n * @example\n * ```typescript\n * const headers: ODataErrorMiddlewareHeaders = {\n * 'X-API-Version': '1.0',\n * 'Access-Control-Allow-Origin': '*',\n * 'X-RateLimit-Remaining': '100'\n * }\n * ```\n */\nexport interface ODataErrorMiddlewareHeaders {\n [key: string]: string\n}\n\n/**\n * Configuration options for the ODataErrorMiddleware class.\n * Defines event handlers for different error types and response formatting options.\n *\n * @example\n * ```typescript\n * const options: ODataErrorMiddlewareOptions = {\n * onVineValidationError: (error) => logger.warn('Validation failed', error),\n * onException: (error) => monitoring.captureException(error),\n * onAny: (error) => analytics.trackError(error),\n * asYaml: true,\n * headers: {\n * 'X-API-Version': '1.0',\n * 'Access-Control-Allow-Origin': '*'\n * }\n * }\n * ```\n */\nexport interface ODataErrorMiddlewareOptions {\n /** Event handler called when a Vine validation error is encountered */\n onVineValidationError?: (error: VineValidationError) => void\n /** Event handler called when a Joi validation error is encountered */\n onJoiValidationError?: (error: JoiValidationError) => void\n /** Event handler called when a framework Exception is encountered */\n onException?: (error: Exception) => void\n /** Event handler called when a generic Error is encountered */\n onError?: (error: Error) => void\n /** Event handler called when an unknown error type is encountered */\n onUnknown?: (error: unknown) => void\n /** Event handler called for any error that occurs, regardless of type */\n onAny?: (error: unknown) => void\n /** Whether to support YAML response format. Defaults to true */\n asYaml?: boolean\n /** Custom headers to include in all error responses */\n headers?: ODataErrorMiddlewareHeaders\n}\n\n/**\n * Individual error detail within a formatted error response.\n * Provides field-level information for validation errors or error chain details.\n *\n * @example\n * ```typescript\n * const detail: ResourcefulFormattedErrorDetails = {\n * code: 'E_REQUIRED',\n * message: 'The email field is required',\n * target: 'email',\n * context: { field: 'email', value: null }\n * }\n * ```\n */\nexport interface ResourcefulFormattedErrorDetails {\n /** Machine-readable error code (e.g., 'E_REQUIRED', 'E_INVALID_FORMAT') */\n code: string\n /** Human-readable error message */\n message: string\n /** The field or property that caused the error (for validation errors) */\n target?: string\n /** Additional context information about the error */\n context?: JsonObject\n}\n\n/**\n * Standardized error response format used by the ODataErrorMiddleware.\n * Provides consistent structure for all API error responses with support for\n * field-level validation details and error chaining.\n *\n * @example\n * ```typescript\n * const formattedError: ResourcefulFormattedError = {\n * status: 422,\n * code: 'E_VALIDATION_ERROR',\n * message: 'Validation failed',\n * help: 'Check the provided field values',\n * details: [\n * {\n * code: 'E_REQUIRED',\n * message: 'The email field is required',\n * target: 'email'\n * }\n * ]\n * }\n * ```\n */\nexport interface ResourcefulFormattedError {\n /** HTTP status code for the error response */\n status: number\n /** Machine-readable error code */\n code: string\n /** Human-readable error message */\n message: string\n /** Optional help text providing guidance on how to resolve the error */\n help?: string\n /** Array of detailed error information, typically for validation errors */\n details?: ResourcefulFormattedErrorDetails[]\n}\n\n/**\n * AdonisJS middleware that intercepts errors thrown during HTTP requests and formats\n * the responses in a consistent, client-friendly manner. Supports multiple error types\n * including Vine validation errors, Joi validation errors, framework exceptions, and\n * generic errors.\n *\n * The middleware provides:\n * - Consistent error response formatting across all error types\n * - Event-driven error handling for monitoring and logging\n * - Content negotiation supporting JSON and YAML responses\n * - Recursive error cause handling to preserve error chains\n * - Configurable headers for CORS, security, and custom requirements\n *\n * @example\n * ```typescript\n * // Basic usage with default configuration\n * const middleware = new ODataErrorMiddleware({})\n * router.use(middleware.handle)\n *\n * // Advanced usage with event handlers and custom headers\n * const middleware = new ODataErrorMiddleware({\n * onVineValidationError: (error) => logger.warn('Validation failed', error),\n * onException: (error) => monitoring.captureException(error),\n * onAny: (error) => analytics.trackError(error),\n * headers: {\n * 'X-API-Version': '1.0',\n * 'Access-Control-Allow-Origin': '*'\n * }\n * })\n * router.use(middleware.handle)\n * ```\n *\n * @example\n * ```typescript\n * // Standalone usage outside of resourceful routes\n * import ODataErrorMiddleware from '@nhtio/lucid-resourceful/middlewares/resourceful_error'\n *\n * const errorHandler = new ODataErrorMiddleware({\n * onException: (error) => logger.error(error),\n * headers: { 'X-Error-Handler': 'resourceful' }\n * })\n *\n * router.use(errorHandler.handle)\n * ```\n */\nexport class ODataErrorMiddleware {\n /**\n * Creates a usable middleware function that can be applied directly to AdonisJS routes.\n * @param opts - Configuration options for the middleware\n * @returns A middleware function that can be used in AdonisJS routes\n */\n public static usable(opts: ODataErrorMiddlewareOptions = {}) {\n const instance = new ODataErrorMiddleware(opts)\n return (ctx: HttpContext, next: NextFn) => instance.handle(ctx, next)\n }\n\n /**\n * Handles errors thrown during request processing. This method is meant to be integrated with the AdonisJS HttpExceptionHandler\n * @param error - The error that was thrown\n * @param ctx - The HTTP context object\n * @param opts - Configuration options for the middleware\n * @returns A Promise that resolves to the error response\n */\n public static handle(error: unknown, ctx: HttpContext, opts: ODataErrorMiddlewareOptions = {}) {\n const instance = new ODataErrorMiddleware(opts)\n return instance.onError(ctx, error)\n }\n\n /**\n * Determines if the middleware should handle the request based on the desired response format.\n * If the desired format is HTML, it returns false to allow other handlers to process the request.\n * Otherwise, it returns true to indicate that this middleware should handle the error response.\n *\n * @param ctx - The HTTP context object containing request and response information\n * @returns A boolean indicating whether this middleware should handle the request\n */\n public static shouldHandle(_ctx: HttpContext): boolean {\n return true\n }\n\n readonly #emitter: ODataErrorMiddlewareEmitter\n readonly #asYaml: boolean\n readonly #headers: ODataErrorMiddlewareHeaders\n\n /**\n * Creates a new instance of ODataErrorMiddleware with the specified configuration.\n *\n * @param opts - Configuration options for the middleware\n *\n * @example\n * ```typescript\n * const middleware = new ODataErrorMiddleware({\n * onVineValidationError: (error) => console.error('Validation:', error),\n * onException: (error) => monitoring.captureException(error),\n * asYaml: true,\n * headers: { 'X-API-Version': '1.0' }\n * })\n * ```\n */\n constructor(opts: ODataErrorMiddlewareOptions) {\n this.#emitter = new ODataErrorMiddlewareEmitter()\n // asYaml defaults to `true`\n this.#asYaml = false !== opts.asYaml\n // headers defaults to an empty object\n this.#headers = isObject(opts.headers) ? opts.headers : {}\n if ('function' === typeof opts.onVineValidationError) {\n this.#emitter.once('vineValidationError', opts.onVineValidationError)\n }\n if ('function' === typeof opts.onJoiValidationError) {\n this.#emitter.once('joiValidationError', opts.onJoiValidationError)\n }\n if ('function' === typeof opts.onException) {\n this.#emitter.once('exception', opts.onException)\n }\n if ('function' === typeof opts.onError) {\n this.#emitter.once('error', opts.onError)\n }\n if ('function' === typeof opts.onUnknown) {\n this.#emitter.once('unknown', opts.onUnknown)\n }\n if ('function' === typeof opts.onAny) {\n this.#emitter.once('any', opts.onAny)\n }\n }\n\n /**\n * AdonisJS middleware handler that intercepts and processes errors during request execution.\n * This method should be used as middleware in your route definitions.\n *\n * @param ctx - The HTTP context object containing request and response information\n * @param next - The next function to call in the middleware chain\n *\n * @example\n * ```typescript\n * const middleware = new ODataErrorMiddleware({})\n * router.use(middleware.handle)\n *\n * // Or bind it to specific routes\n * router.get('/api/users', UserController.index).use([middleware.handle])\n * ```\n */\n async handle(ctx: HttpContext, next: NextFn) {\n try {\n await next()\n } catch (error) {\n return this.onError(ctx, error)\n }\n }\n\n /**\n * Processes a caught error, emits appropriate events, and sends a formatted response.\n * This method handles error classification, event emission, content negotiation,\n * and response formatting.\n *\n * @param ctx - The HTTP context object\n * @param error - The error that was caught during request processing\n *\n * @example\n * ```typescript\n * // Typically called automatically by the handle method, but can be used directly\n * try {\n * // Some operation that might throw\n * } catch (error) {\n * middleware.onError(ctx, error)\n * }\n * ```\n */\n onError(ctx: HttpContext, error: unknown) {\n this.#emitter.emit('any', error)\n switch (true) {\n case isVineValidationError(error):\n this.#emitter.emit('vineValidationError', error)\n break\n\n case isJoiValidationError(error):\n this.#emitter.emit('joiValidationError', error)\n break\n\n case isException(error):\n this.#emitter.emit('exception', error)\n break\n\n case isError(error):\n this.#emitter.emit('error', error)\n break\n\n default:\n this.#emitter.emit('unknown', error)\n break\n }\n const format = negotiateContent(ctx)\n // if the desired format is HTML, break early since that needs to be handled elsewhere\n const formattedError = this.#getFormattedError(error)\n ctx.response.status(formattedError.status)\n Object.entries(this.#headers).forEach(([key, value]) => {\n ctx.response.header(key, value)\n })\n switch (true) {\n case 'xml' === format && this.#asYaml:\n return this.#sendAsXml(ctx, formattedError)\n\n default:\n return this.#sendAsJson(ctx, formattedError)\n }\n }\n\n #sendAsJson(ctx: HttpContext, formattedError: ResourcefulFormattedError) {\n ctx.response.header('Content-Type', 'application/json')\n ctx.response.send(\n JSON.stringify({\n error: stripUndefinedValuesFromObject({\n ...formattedError,\n status: undefined,\n }),\n })\n )\n }\n\n #sendAsXml(ctx: HttpContext, formattedError: ResourcefulFormattedError) {\n const payload: ElementCompact = {\n '_declaration': { _attributes: { version: '1.0', encoding: 'UTF-8' } },\n 'm:error': {\n '_attributes': {\n 'xmlns:m': 'http://docs.oasis-open.org/odata/ns/metadata',\n },\n 'm:code': { _text: formattedError.code },\n 'm:message': { _text: formattedError.message },\n ...(formattedError.details &&\n formattedError.details.length > 0 && {\n 'm:details': formattedError.details.map((detail) => ({\n 'm:detail': {\n 'm:code': { _text: detail.code },\n 'm:message': { _text: detail.message },\n ...(detail.target && { 'm:target': { _text: detail.target } }),\n },\n })),\n }),\n },\n }\n\n ctx.response.header('Content-Type', 'application/xml')\n ctx.response.header('OData-Version', '4.0')\n ctx.response.send(js2xml(payload, { compact: true, spaces: 2 }))\n }\n\n #getFormattedError(error: unknown): ResourcefulFormattedError {\n switch (true) {\n case isVineValidationError(error):\n return this.#formatVineValidationError(error)\n\n case isJoiValidationError(error):\n return this.#formatJoiValidationError(error)\n\n case isException(error):\n return this.#formatException(error)\n\n case isError(error):\n return this.#formatError(error)\n\n default:\n return this.#formatUnknown(error)\n }\n }\n\n #formatVineValidationError(error: VineValidationError): ResourcefulFormattedError {\n const status: number = error.status || 422\n const code: string = error.code || 'E_VALIDATION_ERROR'\n const message: string = error.messages || 'Validation failed'\n const help: string | undefined =\n 'help' in error && 'string' === typeof error.help ? error.help : undefined\n let details: ResourcefulFormattedErrorDetails[] | undefined = Array.isArray(error.messages)\n ? error.messages.map((m) => {\n return stripUndefinedValuesFromObject({\n code: m.rule ? string.snakeCase(m.rule).toUpperCase() : 'E_VALIDATION_ERROR',\n message: m.message || 'Validation error',\n target: m.field,\n })\n })\n : undefined\n if (error.cause) {\n if (!details) {\n details = []\n }\n const formattedCause = this.#getFormattedError(error.cause)\n details.push({\n code: formattedCause.code,\n message: formattedCause.message,\n })\n }\n return stripUndefinedValuesFromObject({\n status,\n code,\n message,\n help,\n details,\n })\n }\n\n #formatJoiValidationError(error: JoiValidationError): ResourcefulFormattedError {\n const status: number = 422\n const code: string = 'E_VALIDATION_ERROR'\n const message: string = error.message || 'Validation failed'\n const help: string | undefined =\n 'help' in error && 'string' === typeof error.help ? error.help : undefined\n let details: ResourcefulFormattedErrorDetails[] | undefined = Array.isArray(error.details)\n ? error.details.map((d) => {\n return stripUndefinedValuesFromObject({\n code: string.snakeCase(d.type).toUpperCase(),\n message: d.message || 'Validation error',\n target: d.path.length > 0 ? d.path.join('.') : undefined,\n context: d.context || undefined,\n })\n })\n : undefined\n if (error.cause) {\n if (!details) {\n details = []\n }\n const formattedCause = this.#getFormattedError(error.cause)\n details.push({\n code: formattedCause.code,\n message: formattedCause.message,\n })\n }\n return stripUndefinedValuesFromObject({\n status,\n code,\n message,\n help,\n details,\n })\n }\n\n #formatException(error: Exception): ResourcefulFormattedError {\n const status: number = error.status || 500\n const code: string = error.code || 'E_EXCEPTION'\n const message: string = error.message || 'An exception occurred'\n const help: string | undefined =\n 'help' in error && 'string' === typeof error.help ? error.help : undefined\n const formattedCause = error.cause ? this.#getFormattedError(error.cause) : undefined\n const details: ResourcefulFormattedErrorDetails[] | undefined = formattedCause\n ? [\n stripUndefinedValuesFromObject({\n code: formattedCause.code,\n message: formattedCause.message,\n }),\n ]\n : undefined\n return stripUndefinedValuesFromObject({\n status,\n code,\n message,\n help,\n details,\n })\n }\n\n #formatError(error: Error): ResourcefulFormattedError {\n const status: number = isNotImplementedError(error) ? 501 : 500\n const code: string = 'E_ERROR'\n const message: string = error.message || 'An error occurred'\n const help: string | undefined =\n 'help' in error && 'string' === typeof error.help ? error.help : undefined\n const formattedCause = error.cause ? this.#getFormattedError(error.cause) : undefined\n const details: ResourcefulFormattedErrorDetails[] | undefined = formattedCause\n ? [\n stripUndefinedValuesFromObject({\n code: formattedCause.code,\n message: formattedCause.message,\n }),\n ]\n : undefined\n return stripUndefinedValuesFromObject({\n status,\n code,\n message,\n help,\n details,\n })\n }\n\n #formatUnknown(error: unknown): ResourcefulFormattedError {\n const status: number = 500\n const code: string = 'E_UNKNOWN_ERROR'\n const message: string = 'An unknown error occurred'\n const help: string | undefined =\n isObject(error) && 'help' in error && 'string' === typeof error.help ? error.help : undefined\n const formattedCause =\n isObject(error) && error.cause ? this.#getFormattedError(error.cause) : undefined\n const details: ResourcefulFormattedErrorDetails[] | undefined = formattedCause\n ? [\n stripUndefinedValuesFromObject({\n code: formattedCause.code,\n message: formattedCause.message,\n }),\n ]\n : undefined\n return stripUndefinedValuesFromObject({\n status,\n code,\n message,\n help,\n details,\n })\n }\n}\n"],"names":["TypedEventEmitter","js2xml","string"],"mappings":";;;AAEO,MAAM,sBAAsB,CAAC,OAAgB,MAAgB;AAG7D,MAAM,mBAAmB,CAC9B,KACA,WAAgC,WACR;AACxB,aAAW,cAAc,qBAAqB;AAC5C,UAAM,QAAQ,IAAI,QAAQ,GAAA;AAC1B,QAAI,aAAa,OAAO,MAAM,SAAS,KAAK,MAAM,SAAS,EAAE,SAAS,UAAU,GAAG;AACjF,aAAO;AAAA,IACT;AACA,QAAI,IAAI,QAAQ,OAAO,QAAQ,GAAG,SAAS,UAAU,GAAG;AACtD,aAAO;AAAA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UAAU,SAAS,aAAa,OAAO,MAAM,OAAO,MAAM,OAAO;AACtF,UAAM,iBACJ,SAAS,KAAK,KAAK,MAAM,QAAQ,KAAK,mBAAmB,MAAM,KAAK,IAAI;AAC1E,UAAM,UAA0D,iBAC5D;AAAA,MACE,+BAA+B;AAAA,QAC7B,MAAM,eAAe;AAAA,QACrB,SAAS,eAAe;AAAA,MAAA,CACzB;AAAA,IAAA,IAEH;AACJ,WAAO,+BAA+B;AAAA,MACpC;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IAAA,CACD;AAAA,EACH;AACF;"}
1
+ {"version":3,"file":"odata_error_middleware-Dspi8bct.js","sources":["../src/private/odata_macro/utils/http.ts","../src/private/odata_macro/middlewares/odata_error_middleware.ts"],"sourcesContent":["import type { HttpContext } from '@adonisjs/core/http'\n\nexport const ODataResponseFormat = ['xml' as 'xml', 'json' as 'json']\nexport type ODataResponseFormat = (typeof ODataResponseFormat)[number]\n\nexport const negotiateContent = (\n ctx: HttpContext,\n fallback: ODataResponseFormat = 'json'\n): ODataResponseFormat => {\n for (const acceptable of ODataResponseFormat) {\n const query = ctx.request.qs()\n if ('string' === typeof query['$format'] && query['$format'].includes(acceptable)) {\n return acceptable\n }\n if (ctx.request.header('accept')?.includes(acceptable)) {\n return acceptable\n }\n }\n return fallback\n}\n\nexport const ODataMetadataLevel = ['full' as 'full', 'minimal' as 'minimal', 'none' as 'none']\nexport type ODataMetadataLevel = (typeof ODataMetadataLevel)[number]\n\nexport const negotiateMetadata = (\n ctx: HttpContext,\n fallback: ODataMetadataLevel = 'minimal'\n): ODataMetadataLevel => {\n for (const acceptable of ODataMetadataLevel) {\n const query = ctx.request.qs()\n if (\n 'string' === typeof query['$format'] &&\n query['$format'].includes(`metadata=${acceptable}`)\n ) {\n return acceptable\n }\n if (ctx.request.header('accept')?.includes(`metadata=${acceptable}`)) {\n return acceptable\n }\n }\n return fallback\n}\n\nexport const ODataPreference = ['representation' as 'representation', 'minimal' as 'minimal']\nexport type ODataPreference = (typeof ODataPreference)[number]\n\nexport const negotiatePreference = (\n ctx: HttpContext,\n fallback: ODataPreference = 'representation'\n): ODataPreference => {\n const prefer = ctx.request.header('prefer')\n if (prefer) {\n for (const acceptable of ODataPreference) {\n if (prefer.includes(acceptable)) {\n return acceptable\n }\n }\n }\n return fallback\n}\n","/*\n|--------------------------------------------------------------------------\n| Resourceful Error Middleware\n|--------------------------------------------------------------------------\n|\n| Intercepts errors thrown during http requests and formats the responses\n| in a consistent manner meant to be easily consumed by clients.\n|\n| While designed specifically to work with Lucid Resourceful, there is no\n| reason it cannot be applied to non-resourceful routes as well.\n*/\nimport { js2xml } from 'xml-js'\nimport { errors } from '@vinejs/vine'\nimport { Exception } from '@poppinss/utils'\nimport { negotiateContent } from '../utils/http'\nimport { default as string } from '@poppinss/string'\nimport { TypedEventEmitter } from '@nhtio/tiny-typed-emitter'\nimport { isObject, stripUndefinedValuesFromObject } from '../../utils'\nimport { ValidationError as JoiValidationError } from '@nhtio/lucid-resourceful/joi'\nimport {\n isError,\n isException,\n isJoiValidationError,\n isVineValidationError,\n isNotImplementedError,\n} from '../../router_macro/utils/errors'\nimport type { JsonObject } from 'type-fest'\nimport type { ElementCompact } from 'xml-js'\nimport type { HttpContext } from '@adonisjs/core/http'\nimport type { NextFn } from '@adonisjs/core/types/http'\nimport type { EventMap } from '@nhtio/tiny-typed-emitter'\n/**\n * Type alias for Vine validation errors thrown by the VineJS validation library.\n *\n * @example\n * ```typescript\n * try {\n * await vine.validate(schema, data)\n * } catch (error) {\n * if (isVineValidationError(error)) {\n * // Handle Vine validation error\n * }\n * }\n * ```\n */\nexport type VineValidationError = InstanceType<typeof errors.E_VALIDATION_ERROR>\n\n/**\n * Event map defining the types of errors that can be emitted by the ODataErrorMiddleware.\n * Each event type maps to the specific error instance that will be passed to event handlers.\n *\n * @example\n * ```typescript\n * const middleware = new ODataErrorMiddleware({\n * onVineValidationError: (error) => logger.warn('Validation failed', error),\n * onException: (error) => monitoring.captureException(error),\n * onAny: (error) => analytics.trackError(error)\n * })\n * ```\n */\nexport type ODataErrorMiddlewareEvents = EventMap<{\n vineValidationError: [VineValidationError]\n joiValidationError: [JoiValidationError]\n exception: [Exception]\n error: [Error]\n unknown: [unknown]\n any: [unknown]\n}>\n\nclass ODataErrorMiddlewareEmitter extends TypedEventEmitter<ODataErrorMiddlewareEvents> {}\n\n/**\n * Configuration object for custom HTTP headers to be included in error responses.\n * Allows for CORS headers, security headers, API versioning, or any custom headers\n * that should be consistently applied to all error responses.\n *\n * @example\n * ```typescript\n * const headers: ODataErrorMiddlewareHeaders = {\n * 'X-API-Version': '1.0',\n * 'Access-Control-Allow-Origin': '*',\n * 'X-RateLimit-Remaining': '100'\n * }\n * ```\n */\nexport interface ODataErrorMiddlewareHeaders {\n [key: string]: string\n}\n\n/**\n * Configuration options for the ODataErrorMiddleware class.\n * Defines event handlers for different error types and response formatting options.\n *\n * @example\n * ```typescript\n * const options: ODataErrorMiddlewareOptions = {\n * onVineValidationError: (error) => logger.warn('Validation failed', error),\n * onException: (error) => monitoring.captureException(error),\n * onAny: (error) => analytics.trackError(error),\n * asYaml: true,\n * headers: {\n * 'X-API-Version': '1.0',\n * 'Access-Control-Allow-Origin': '*'\n * }\n * }\n * ```\n */\nexport interface ODataErrorMiddlewareOptions {\n /** Event handler called when a Vine validation error is encountered */\n onVineValidationError?: (error: VineValidationError) => void\n /** Event handler called when a Joi validation error is encountered */\n onJoiValidationError?: (error: JoiValidationError) => void\n /** Event handler called when a framework Exception is encountered */\n onException?: (error: Exception) => void\n /** Event handler called when a generic Error is encountered */\n onError?: (error: Error) => void\n /** Event handler called when an unknown error type is encountered */\n onUnknown?: (error: unknown) => void\n /** Event handler called for any error that occurs, regardless of type */\n onAny?: (error: unknown) => void\n /** Whether to support YAML response format. Defaults to true */\n asYaml?: boolean\n /** Custom headers to include in all error responses */\n headers?: ODataErrorMiddlewareHeaders\n}\n\n/**\n * Individual error detail within a formatted error response.\n * Provides field-level information for validation errors or error chain details.\n *\n * @example\n * ```typescript\n * const detail: ResourcefulFormattedErrorDetails = {\n * code: 'E_REQUIRED',\n * message: 'The email field is required',\n * target: 'email',\n * context: { field: 'email', value: null }\n * }\n * ```\n */\nexport interface ResourcefulFormattedErrorDetails {\n /** Machine-readable error code (e.g., 'E_REQUIRED', 'E_INVALID_FORMAT') */\n code: string\n /** Human-readable error message */\n message: string\n /** The field or property that caused the error (for validation errors) */\n target?: string\n /** Additional context information about the error */\n context?: JsonObject\n}\n\n/**\n * Standardized error response format used by the ODataErrorMiddleware.\n * Provides consistent structure for all API error responses with support for\n * field-level validation details and error chaining.\n *\n * @example\n * ```typescript\n * const formattedError: ResourcefulFormattedError = {\n * status: 422,\n * code: 'E_VALIDATION_ERROR',\n * message: 'Validation failed',\n * help: 'Check the provided field values',\n * details: [\n * {\n * code: 'E_REQUIRED',\n * message: 'The email field is required',\n * target: 'email'\n * }\n * ]\n * }\n * ```\n */\nexport interface ResourcefulFormattedError {\n /** HTTP status code for the error response */\n status: number\n /** Machine-readable error code */\n code: string\n /** Human-readable error message */\n message: string\n /** Optional help text providing guidance on how to resolve the error */\n help?: string\n /** Array of detailed error information, typically for validation errors */\n details?: ResourcefulFormattedErrorDetails[]\n}\n\n/**\n * AdonisJS middleware that intercepts errors thrown during HTTP requests and formats\n * the responses in a consistent, client-friendly manner. Supports multiple error types\n * including Vine validation errors, Joi validation errors, framework exceptions, and\n * generic errors.\n *\n * The middleware provides:\n * - Consistent error response formatting across all error types\n * - Event-driven error handling for monitoring and logging\n * - Content negotiation supporting JSON and YAML responses\n * - Recursive error cause handling to preserve error chains\n * - Configurable headers for CORS, security, and custom requirements\n *\n * @example\n * ```typescript\n * // Basic usage with default configuration\n * const middleware = new ODataErrorMiddleware({})\n * router.use(middleware.handle)\n *\n * // Advanced usage with event handlers and custom headers\n * const middleware = new ODataErrorMiddleware({\n * onVineValidationError: (error) => logger.warn('Validation failed', error),\n * onException: (error) => monitoring.captureException(error),\n * onAny: (error) => analytics.trackError(error),\n * headers: {\n * 'X-API-Version': '1.0',\n * 'Access-Control-Allow-Origin': '*'\n * }\n * })\n * router.use(middleware.handle)\n * ```\n *\n * @example\n * ```typescript\n * // Standalone usage outside of resourceful routes\n * import ODataErrorMiddleware from '@nhtio/lucid-resourceful/middlewares/resourceful_error'\n *\n * const errorHandler = new ODataErrorMiddleware({\n * onException: (error) => logger.error(error),\n * headers: { 'X-Error-Handler': 'resourceful' }\n * })\n *\n * router.use(errorHandler.handle)\n * ```\n */\nexport class ODataErrorMiddleware {\n /**\n * Creates a usable middleware function that can be applied directly to AdonisJS routes.\n * @param opts - Configuration options for the middleware\n * @returns A middleware function that can be used in AdonisJS routes\n */\n public static usable(opts: ODataErrorMiddlewareOptions = {}) {\n const instance = new ODataErrorMiddleware(opts)\n return (ctx: HttpContext, next: NextFn) => instance.handle(ctx, next)\n }\n\n /**\n * Handles errors thrown during request processing. This method is meant to be integrated with the AdonisJS HttpExceptionHandler\n * @param error - The error that was thrown\n * @param ctx - The HTTP context object\n * @param opts - Configuration options for the middleware\n * @returns A Promise that resolves to the error response\n */\n public static handle(error: unknown, ctx: HttpContext, opts: ODataErrorMiddlewareOptions = {}) {\n const instance = new ODataErrorMiddleware(opts)\n return instance.onError(ctx, error)\n }\n\n /**\n * Determines if the middleware should handle the request based on the desired response format.\n * If the desired format is HTML, it returns false to allow other handlers to process the request.\n * Otherwise, it returns true to indicate that this middleware should handle the error response.\n *\n * @param ctx - The HTTP context object containing request and response information\n * @returns A boolean indicating whether this middleware should handle the request\n */\n public static shouldHandle(_ctx: HttpContext): boolean {\n return true\n }\n\n readonly #emitter: ODataErrorMiddlewareEmitter\n readonly #asYaml: boolean\n readonly #headers: ODataErrorMiddlewareHeaders\n\n /**\n * Creates a new instance of ODataErrorMiddleware with the specified configuration.\n *\n * @param opts - Configuration options for the middleware\n *\n * @example\n * ```typescript\n * const middleware = new ODataErrorMiddleware({\n * onVineValidationError: (error) => console.error('Validation:', error),\n * onException: (error) => monitoring.captureException(error),\n * asYaml: true,\n * headers: { 'X-API-Version': '1.0' }\n * })\n * ```\n */\n constructor(opts: ODataErrorMiddlewareOptions) {\n this.#emitter = new ODataErrorMiddlewareEmitter()\n // asYaml defaults to `true`\n this.#asYaml = false !== opts.asYaml\n // headers defaults to an empty object\n this.#headers = isObject(opts.headers) ? opts.headers : {}\n if ('function' === typeof opts.onVineValidationError) {\n this.#emitter.once('vineValidationError', opts.onVineValidationError)\n }\n if ('function' === typeof opts.onJoiValidationError) {\n this.#emitter.once('joiValidationError', opts.onJoiValidationError)\n }\n if ('function' === typeof opts.onException) {\n this.#emitter.once('exception', opts.onException)\n }\n if ('function' === typeof opts.onError) {\n this.#emitter.once('error', opts.onError)\n }\n if ('function' === typeof opts.onUnknown) {\n this.#emitter.once('unknown', opts.onUnknown)\n }\n if ('function' === typeof opts.onAny) {\n this.#emitter.once('any', opts.onAny)\n }\n }\n\n /**\n * AdonisJS middleware handler that intercepts and processes errors during request execution.\n * This method should be used as middleware in your route definitions.\n *\n * @param ctx - The HTTP context object containing request and response information\n * @param next - The next function to call in the middleware chain\n *\n * @example\n * ```typescript\n * const middleware = new ODataErrorMiddleware({})\n * router.use(middleware.handle)\n *\n * // Or bind it to specific routes\n * router.get('/api/users', UserController.index).use([middleware.handle])\n * ```\n */\n async handle(ctx: HttpContext, next: NextFn) {\n try {\n await next()\n } catch (error) {\n return this.onError(ctx, error)\n }\n }\n\n /**\n * Processes a caught error, emits appropriate events, and sends a formatted response.\n * This method handles error classification, event emission, content negotiation,\n * and response formatting.\n *\n * @param ctx - The HTTP context object\n * @param error - The error that was caught during request processing\n *\n * @example\n * ```typescript\n * // Typically called automatically by the handle method, but can be used directly\n * try {\n * // Some operation that might throw\n * } catch (error) {\n * middleware.onError(ctx, error)\n * }\n * ```\n */\n onError(ctx: HttpContext, error: unknown) {\n this.#emitter.emit('any', error)\n switch (true) {\n case isVineValidationError(error):\n this.#emitter.emit('vineValidationError', error)\n break\n\n case isJoiValidationError(error):\n this.#emitter.emit('joiValidationError', error)\n break\n\n case isException(error):\n this.#emitter.emit('exception', error)\n break\n\n case isError(error):\n this.#emitter.emit('error', error)\n break\n\n default:\n this.#emitter.emit('unknown', error)\n break\n }\n const format = negotiateContent(ctx)\n // if the desired format is HTML, break early since that needs to be handled elsewhere\n const formattedError = this.#getFormattedError(error)\n ctx.response.status(formattedError.status)\n Object.entries(this.#headers).forEach(([key, value]) => {\n ctx.response.header(key, value)\n })\n switch (true) {\n case 'xml' === format && this.#asYaml:\n return this.#sendAsXml(ctx, formattedError)\n\n default:\n return this.#sendAsJson(ctx, formattedError)\n }\n }\n\n #sendAsJson(ctx: HttpContext, formattedError: ResourcefulFormattedError) {\n ctx.response.header('Content-Type', 'application/json')\n ctx.response.send(\n JSON.stringify({\n error: stripUndefinedValuesFromObject({\n ...formattedError,\n status: undefined,\n }),\n })\n )\n }\n\n #sendAsXml(ctx: HttpContext, formattedError: ResourcefulFormattedError) {\n const payload: ElementCompact = {\n '_declaration': { _attributes: { version: '1.0', encoding: 'UTF-8' } },\n 'm:error': {\n '_attributes': {\n 'xmlns:m': 'http://docs.oasis-open.org/odata/ns/metadata',\n },\n 'm:code': { _text: formattedError.code },\n 'm:message': { _text: formattedError.message },\n ...(formattedError.details &&\n formattedError.details.length > 0 && {\n 'm:details': formattedError.details.map((detail) => ({\n 'm:detail': {\n 'm:code': { _text: detail.code },\n 'm:message': { _text: detail.message },\n ...(detail.target && { 'm:target': { _text: detail.target } }),\n },\n })),\n }),\n },\n }\n\n ctx.response.header('Content-Type', 'application/xml')\n ctx.response.header('OData-Version', '4.0')\n ctx.response.send(js2xml(payload, { compact: true, spaces: 2 }))\n }\n\n #getFormattedError(error: unknown): ResourcefulFormattedError {\n switch (true) {\n case isVineValidationError(error):\n return this.#formatVineValidationError(error)\n\n case isJoiValidationError(error):\n return this.#formatJoiValidationError(error)\n\n case isException(error):\n return this.#formatException(error)\n\n case isError(error):\n return this.#formatError(error)\n\n default:\n return this.#formatUnknown(error)\n }\n }\n\n #formatVineValidationError(error: VineValidationError): ResourcefulFormattedError {\n const status: number = error.status || 422\n const code: string = error.code || 'E_VALIDATION_ERROR'\n const message: string = error.messages || 'Validation failed'\n const help: string | undefined =\n 'help' in error && 'string' === typeof error.help ? error.help : undefined\n let details: ResourcefulFormattedErrorDetails[] | undefined = Array.isArray(error.messages)\n ? error.messages.map((m) => {\n return stripUndefinedValuesFromObject({\n code: m.rule ? string.snakeCase(m.rule).toUpperCase() : 'E_VALIDATION_ERROR',\n message: m.message || 'Validation error',\n target: m.field,\n })\n })\n : undefined\n if (error.cause) {\n if (!details) {\n details = []\n }\n const formattedCause = this.#getFormattedError(error.cause)\n details.push({\n code: formattedCause.code,\n message: formattedCause.message,\n })\n }\n return stripUndefinedValuesFromObject({\n status,\n code,\n message,\n help,\n details,\n })\n }\n\n #formatJoiValidationError(error: JoiValidationError): ResourcefulFormattedError {\n const status: number = 422\n const code: string = 'E_VALIDATION_ERROR'\n const message: string = error.message || 'Validation failed'\n const help: string | undefined =\n 'help' in error && 'string' === typeof error.help ? error.help : undefined\n let details: ResourcefulFormattedErrorDetails[] | undefined = Array.isArray(error.details)\n ? error.details.map((d) => {\n return stripUndefinedValuesFromObject({\n code: string.snakeCase(d.type).toUpperCase(),\n message: d.message || 'Validation error',\n target: d.path.length > 0 ? d.path.join('.') : undefined,\n context: d.context || undefined,\n })\n })\n : undefined\n if (error.cause) {\n if (!details) {\n details = []\n }\n const formattedCause = this.#getFormattedError(error.cause)\n details.push({\n code: formattedCause.code,\n message: formattedCause.message,\n })\n }\n return stripUndefinedValuesFromObject({\n status,\n code,\n message,\n help,\n details,\n })\n }\n\n #formatException(error: Exception): ResourcefulFormattedError {\n const status: number = error.status || 500\n const code: string = error.code || 'E_EXCEPTION'\n const message: string = error.message || 'An exception occurred'\n const help: string | undefined =\n 'help' in error && 'string' === typeof error.help ? error.help : undefined\n const formattedCause = error.cause ? this.#getFormattedError(error.cause) : undefined\n const details: ResourcefulFormattedErrorDetails[] | undefined = formattedCause\n ? [\n stripUndefinedValuesFromObject({\n code: formattedCause.code,\n message: formattedCause.message,\n }),\n ]\n : undefined\n return stripUndefinedValuesFromObject({\n status,\n code,\n message,\n help,\n details,\n })\n }\n\n #formatError(error: Error): ResourcefulFormattedError {\n const status: number = isNotImplementedError(error) ? 501 : 500\n const code: string = 'E_ERROR'\n const message: string = error.message || 'An error occurred'\n const help: string | undefined =\n 'help' in error && 'string' === typeof error.help ? error.help : undefined\n const formattedCause = error.cause ? this.#getFormattedError(error.cause) : undefined\n const details: ResourcefulFormattedErrorDetails[] | undefined = formattedCause\n ? [\n stripUndefinedValuesFromObject({\n code: formattedCause.code,\n message: formattedCause.message,\n }),\n ]\n : undefined\n return stripUndefinedValuesFromObject({\n status,\n code,\n message,\n help,\n details,\n })\n }\n\n #formatUnknown(error: unknown): ResourcefulFormattedError {\n const status: number = 500\n const code: string = 'E_UNKNOWN_ERROR'\n const message: string = 'An unknown error occurred'\n const help: string | undefined =\n isObject(error) && 'help' in error && 'string' === typeof error.help ? error.help : undefined\n const formattedCause =\n isObject(error) && error.cause ? this.#getFormattedError(error.cause) : undefined\n const details: ResourcefulFormattedErrorDetails[] | undefined = formattedCause\n ? [\n stripUndefinedValuesFromObject({\n code: formattedCause.code,\n message: formattedCause.message,\n }),\n ]\n : undefined\n return stripUndefinedValuesFromObject({\n status,\n code,\n message,\n help,\n details,\n })\n }\n}\n"],"names":["TypedEventEmitter","js2xml","string"],"mappings":";;;AAEO,MAAM,sBAAsB,CAAC,OAAgB,MAAgB;AAG7D,MAAM,mBAAmB,CAC9B,KACA,WAAgC,WACR;AACxB,aAAW,cAAc,qBAAqB;AAC5C,UAAM,QAAQ,IAAI,QAAQ,GAAA;AAC1B,QAAI,aAAa,OAAO,MAAM,SAAS,KAAK,MAAM,SAAS,EAAE,SAAS,UAAU,GAAG;AACjF,aAAO;AAAA,IACT;AACA,QAAI,IAAI,QAAQ,OAAO,QAAQ,GAAG,SAAS,UAAU,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ACJ,SAAS,KAAK,KAAK,UAAU,SAAS,aAAa,OAAO,MAAM,OAAO,MAAM,OAAO;AACtF,UAAM,iBACJ,SAAS,KAAK,KAAK,MAAM,QAAQ,KAAK,mBAAmB,MAAM,KAAK,IAAI;AAC1E,UAAM,UAA0D,iBAC5D;AAAA,MACE,+BAA+B;AAAA,QAC7B,MAAM,eAAe;AAAA,QACrB,SAAS,eAAe;AAAA,MAAA,CACzB;AAAA,IAAA,IAEH;AACJ,WAAO,+BAA+B;AAAA,MACpC;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IAAA,CACD;AAAA,EACH;AACF;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nhtio/lucid-resourceful",
3
- "version": "0.1.0-master-29dd5a13",
3
+ "version": "0.1.0-master-641df8fc",
4
4
  "description": "A decorator-driven AdonisJS library that lets you annotate Lucid ORM models with metadata to automatically generate CRUD controllers, validation rules, OpenAPI schemas, and a unified query interface.",
5
5
  "keywords": [],
6
6
  "author": "Jak Giveon <jak@nht.io>",
@@ -1,12 +1,12 @@
1
- import type { ResourcefulStringTypeOptions, ResourcefulDateTypeOptions, ResourcefulDateTimeTypeOptions, ResourcefulBinaryTypeOptions, ResourcefulNumberTypeOptions, ResourcefulIntegerTypeOptions, ResourcefulBigintTypeOptions, ResourcefulUnsignedIntegerTypeOptions, ResourcefulBooleanTypeOptions, ResourcefulObjectTypeOptions, ResourcefulArrayTypeOptions } from './data_types';
2
- export declare const ResourcefulStringTypeSchema: () => import("@nhtio/validation").ObjectSchema<ResourcefulStringTypeOptions>;
3
- export declare const ResourcefulDateTypeSchema: () => import("@nhtio/validation").ObjectSchema<ResourcefulDateTypeOptions>;
4
- export declare const ResourcefulDateTimeTypeSchema: () => import("@nhtio/validation").ObjectSchema<ResourcefulDateTimeTypeOptions>;
5
- export declare const ResourcefulBinaryTypeSchema: () => import("@nhtio/validation").ObjectSchema<ResourcefulBinaryTypeOptions>;
6
- export declare const ResourcefulNumberTypeSchema: () => import("@nhtio/validation").ObjectSchema<ResourcefulNumberTypeOptions>;
7
- export declare const ResourcefulIntegerTypeSchema: () => import("@nhtio/validation").ObjectSchema<ResourcefulIntegerTypeOptions>;
8
- export declare const ResourcefulBigintTypeSchema: () => import("@nhtio/validation").ObjectSchema<ResourcefulBigintTypeOptions>;
9
- export declare const ResourcefulUnsignedIntegerTypeSchema: () => import("@nhtio/validation").ObjectSchema<ResourcefulUnsignedIntegerTypeOptions>;
10
- export declare const ResourcefulBooleanTypeSchema: () => import("@nhtio/validation").ObjectSchema<ResourcefulBooleanTypeOptions>;
11
- export declare const ResourcefulObjectTypeSchema: () => import("@nhtio/validation").ObjectSchema<ResourcefulObjectTypeOptions>;
12
- export declare const ResourcefulArrayTypeSchema: () => import("@nhtio/validation").ObjectSchema<ResourcefulArrayTypeOptions>;
1
+ import type { ResourcefulStringTypeOptions, ResourcefulDateTypeOptions, ResourcefulDateTimeTypeOptions, ResourcefulBinaryTypeOptions, ResourcefulNumberTypeOptions, ResourcefulIntegerTypeOptions, ResourcefulBigintTypeOptions, ResourcefulUnsignedIntegerTypeOptions, ResourcefulBooleanTypeOptions, ResourcefulObjectTypeOptions, ResourcefulArrayTypeOptions } from "./data_types";
2
+ export declare const ResourcefulStringTypeSchema: () => import("../bundled_nhtio_validation").ObjectSchema<ResourcefulStringTypeOptions>;
3
+ export declare const ResourcefulDateTypeSchema: () => import("../bundled_nhtio_validation").ObjectSchema<ResourcefulDateTypeOptions>;
4
+ export declare const ResourcefulDateTimeTypeSchema: () => import("../bundled_nhtio_validation").ObjectSchema<ResourcefulDateTimeTypeOptions>;
5
+ export declare const ResourcefulBinaryTypeSchema: () => import("../bundled_nhtio_validation").ObjectSchema<ResourcefulBinaryTypeOptions>;
6
+ export declare const ResourcefulNumberTypeSchema: () => import("../bundled_nhtio_validation").ObjectSchema<ResourcefulNumberTypeOptions>;
7
+ export declare const ResourcefulIntegerTypeSchema: () => import("../bundled_nhtio_validation").ObjectSchema<ResourcefulIntegerTypeOptions>;
8
+ export declare const ResourcefulBigintTypeSchema: () => import("../bundled_nhtio_validation").ObjectSchema<ResourcefulBigintTypeOptions>;
9
+ export declare const ResourcefulUnsignedIntegerTypeSchema: () => import("../bundled_nhtio_validation").ObjectSchema<ResourcefulUnsignedIntegerTypeOptions>;
10
+ export declare const ResourcefulBooleanTypeSchema: () => import("../bundled_nhtio_validation").ObjectSchema<ResourcefulBooleanTypeOptions>;
11
+ export declare const ResourcefulObjectTypeSchema: () => import("../bundled_nhtio_validation").ObjectSchema<ResourcefulObjectTypeOptions>;
12
+ export declare const ResourcefulArrayTypeSchema: () => import("../bundled_nhtio_validation").ObjectSchema<ResourcefulArrayTypeOptions>;
@@ -1,4 +1,4 @@
1
- import type { ObjectSchema } from '../bundled_nhtio_validation';
1
+ import type { ObjectSchema } from "../bundled_nhtio_validation";
2
2
  /**
3
3
  * Base interface for all Resourceful data type options.
4
4
  * Includes common modifier properties that apply to all data types.
@@ -1,4 +1,4 @@
1
- import type { ObjectSchema } from '../bundled_nhtio_validation';
1
+ import type { ObjectSchema } from "../bundled_nhtio_validation";
2
2
  export declare const validateNormalizeAndCastDecoratorOptions: <InputType, OutputType>(fieldName: string, decoratorName: string, schema: ObjectSchema, input: InputType) => OutputType;
3
3
  export declare const resourcefulColumnDefinitionSchema: ObjectSchema<any>;
4
4
  export declare const resourcefulColumnOptionsSchema: ObjectSchema<any>;
@@ -1,5 +1,5 @@
1
1
  import { DateTime } from 'luxon';
2
- import type { LucidBinaryValue, LucidPlainObject } from '../types'
2
+ import type { LucidBinaryValue, LucidPlainObject } from "../types";
3
3
  /**
4
4
  * Casts an unknown value to a string
5
5
  * @param value - The value to cast
@@ -1,6 +1,6 @@
1
1
  import { LucidModel, ColumnOptions, ComputedOptions } from '@adonisjs/lucid/types/model';
2
2
  import type { HasOne, ManyToMany, HasManyThrough, ManyToManyRelationOptions, RelationOptions, ThroughRelationOptions } from '@adonisjs/lucid/types/relations';
3
- import type { ResourcefulColumnDefinition, ResourcefulComputedAccessorDefinition, ResourcefulRelationshipDefinition, AnySchema, StringSchema, DateSchema, BinarySchema, NumberSchema, BooleanSchema, ObjectSchema, ArraySchema, ResourcefulPropertySchema } from '../types'
3
+ import type { ResourcefulColumnDefinition, ResourcefulComputedAccessorDefinition, ResourcefulRelationshipDefinition, AnySchema, StringSchema, DateSchema, BinarySchema, NumberSchema, BooleanSchema, ObjectSchema, ArraySchema, ResourcefulPropertySchema } from "../types";
4
4
  /**
5
5
  * Options for date columns including autoCreate and autoUpdate flags.
6
6
  *
@@ -22,7 +22,7 @@ export type DateColumnOptions = DataTypeColumnOptions & {
22
22
  *
23
23
  * @example
24
24
  * ```ts
25
- * import { resourcefulBelongsTo } from '@/'
25
+ * import { resourcefulBelongsTo } from '@nhtio/lucid-resourceful'
26
26
  *
27
27
  * class Post {
28
28
  * @resourcefulBelongsTo(() => User, { foreignKey: 'user_id' })
@@ -36,7 +36,7 @@ export type RelatedModelRelationOptions<RelatedModel extends LucidModel> = Relat
36
36
  *
37
37
  * @example
38
38
  * ```ts
39
- * import { resourcefulHasManyThrough } from '@/'
39
+ * import { resourcefulHasManyThrough } from '@nhtio/lucid-resourceful'
40
40
  *
41
41
  * class User {
42
42
  * @resourcefulHasManyThrough([
@@ -56,7 +56,7 @@ export type DataTypeComputedOptions = Omit<ComputedOptions, 'prepare' | 'consume
56
56
  *
57
57
  * @example
58
58
  * ```ts
59
- * import { resourcefulColumn, ResourcefulStringType } from '@/'
59
+ * import { resourcefulColumn, ResourcefulStringType } from '@nhtio/lucid-resourceful'
60
60
  *
61
61
  * class User {
62
62
  * @resourcefulColumn({ type: ResourcefulStringType({ minLength: 1, maxLength: 100 }), nullable: false })
@@ -87,7 +87,7 @@ export declare namespace resourcefulColumn {
87
87
  *
88
88
  * @example
89
89
  * ```ts
90
- * import { resourcefulComputed, ResourcefulStringType } from '@/'
90
+ * import { resourcefulComputed, ResourcefulStringType } from '@nhtio/lucid-resourceful'
91
91
  *
92
92
  * class User {
93
93
  * @resourcefulComputed({ type: ResourcefulStringType({ minLength: 1, maxLength: 100 }) })
@@ -119,7 +119,7 @@ export declare namespace resourcefulComputed {
119
119
  *
120
120
  * @example
121
121
  * ```ts
122
- * import { resourcefulBelongsTo } from '@/'
122
+ * import { resourcefulBelongsTo } from '@nhtio/lucid-resourceful'
123
123
  *
124
124
  * class Post {
125
125
  * @resourcefulBelongsTo(() => User, { foreignKey: 'user_id' })
@@ -137,7 +137,7 @@ export declare function resourcefulBelongsTo<RelatedModel extends LucidModel>(mo
137
137
  *
138
138
  * @example
139
139
  * ```ts
140
- * import { resourcefulHasOne } from '@/'
140
+ * import { resourcefulHasOne } from '@nhtio/lucid-resourceful'
141
141
  *
142
142
  * class UserProfile {
143
143
  * @resourcefulHasOne(() => User, { foreignKey: 'user_id' })
@@ -155,7 +155,7 @@ export declare function resourcefulHasOne<RelatedModel extends LucidModel>(model
155
155
  *
156
156
  * @example
157
157
  * ```ts
158
- * import { resourcefulHasMany } from '@/'
158
+ * import { resourcefulHasMany } from '@nhtio/lucid-resourceful'
159
159
  *
160
160
  * class User {
161
161
  * @resourcefulHasMany(() => Post, { foreignKey: 'user_id' })
@@ -173,7 +173,7 @@ export declare function resourcefulHasMany<RelatedModel extends LucidModel>(mode
173
173
  *
174
174
  * @example
175
175
  * ```ts
176
- * import { resourcefulManyToMany } from '@/'
176
+ * import { resourcefulManyToMany } from '@nhtio/lucid-resourceful'
177
177
  *
178
178
  * class User {
179
179
  * @resourcefulManyToMany(() => Role, { pivotTable: 'role_user' })
@@ -191,7 +191,7 @@ export declare function resourcefulManyToMany<RelatedModel extends LucidModel>(m
191
191
  *
192
192
  * @example
193
193
  * ```ts
194
- * import { resourcefulHasManyThrough } from '@/'
194
+ * import { resourcefulHasManyThrough } from '@nhtio/lucid-resourceful'
195
195
  *
196
196
  * class User {
197
197
  * @resourcefulHasManyThrough([
@@ -206,4 +206,7 @@ export declare function resourcefulManyToMany<RelatedModel extends LucidModel>(m
206
206
  * @param options - HasManyThrough relationship options and resourceful relationship definition.
207
207
  * @returns Property decorator function.
208
208
  */
209
- export declare function resourcefulHasManyThrough<RelatedModel extends LucidModel>(model: [() => RelatedModel, () => LucidModel], options?: Partial<HasManyThroughRelationOptions<RelatedModel>> & Partial<ResourcefulRelationshipDefinition>): (target: any, propertyKey: string) => void;
209
+ export declare function resourcefulHasManyThrough<RelatedModel extends LucidModel>(model: [
210
+ () => RelatedModel,
211
+ () => LucidModel
212
+ ], options?: Partial<HasManyThroughRelationOptions<RelatedModel>> & Partial<ResourcefulRelationshipDefinition>): (target: any, propertyKey: string) => void;
@@ -1,3 +1,3 @@
1
- export * from '../bundled_nhtio_encoder';
2
- export * from '../bundled_nhtio_encoder_exceptions';
3
- export * from '../bundled_nhtio_encoder_function_serializer';
1
+ export * from "../bundled_nhtio_encoder";
2
+ export * from "../bundled_nhtio_encoder_exceptions";
3
+ export * from "../bundled_nhtio_encoder_function_serializer";
@@ -1,4 +1,4 @@
1
- export * from '../../bundled_nhtio_validation';
2
- import { validator } from '../../bundled_nhtio_validation';
1
+ export * from "../../bundled_nhtio_validation";
2
+ import { validator } from "../../bundled_nhtio_validation";
3
3
  export { validator as joi };
4
- export type * from '../../bundled_nhtio_validation';
4
+ export type * from "../../bundled_nhtio_validation";
@@ -1,7 +1,7 @@
1
1
  import type { QueryClientContract } from '@adonisjs/lucid/types/database';
2
2
  import type { LucidModel, ModelKeysContract } from '@adonisjs/lucid/types/model';
3
3
  import type { DatabaseQueryBuilderContract } from '@adonisjs/lucid/types/querybuilder';
4
- import type { ComparisonOperatorToken, EmptyExpression, FieldToken, ImplicitFieldToken, LiteralExpressionToken, LogicalExpressionToken, RangeExpressionToken, RegexExpressionToken, TagToken, UnaryOperatorToken, ParenthesizedExpressionToken, ExpressionToken, ParserAst } from '../bundled_liqe';
4
+ import type { ComparisonOperatorToken, EmptyExpression, FieldToken, ImplicitFieldToken, LiteralExpressionToken, LogicalExpressionToken, RangeExpressionToken, RegexExpressionToken, TagToken, UnaryOperatorToken, ParenthesizedExpressionToken, ExpressionToken, ParserAst } from "../bundled_liqe";
5
5
  /**
6
6
  * Database query builder contract extended for Lucene filtering capabilities.
7
7
  *
@@ -1,13 +1,13 @@
1
1
  import { HttpContext } from '@adonisjs/core/http';
2
2
  import { type BaseModel } from '@adonisjs/lucid/orm';
3
- import { GenerateModelSchemaOptions } from './open_api_schema_service';
3
+ import { GenerateModelSchemaOptions } from "./open_api_schema_service";
4
4
  import type { ApplicationService } from '@adonisjs/core/types';
5
- import type { EventMap, Key, Listener } from '../bundled_nhtio_tiny_typed_emitter';
5
+ import type { EventMap, Key, Listener } from "../bundled_nhtio_tiny_typed_emitter";
6
6
  import type { NormalizeConstructor } from '@adonisjs/core/types/helpers';
7
- import type { AnySchema, ObjectSchema } from '../bundled_nhtio_validation';
7
+ import type { AnySchema, ObjectSchema } from "../bundled_nhtio_validation";
8
8
  import type { DatabaseQueryBuilderContract } from '@adonisjs/lucid/types/querybuilder';
9
9
  import type { LucidModel } from '@adonisjs/lucid/types/model';
10
- import type { ExternalDocumentationObject, PromiseAble, ResourcefulColumnDefinition, ResourcefulComputedAccessorDefinition, ResourcefulDataType, ResourcefulGeneralAccessControlFilter, ResourcefulModelMetaSchema, ResourcefulModelOpenApiSchema, ResourcefulPropertySchema, ResourcefulRelationshipDefinition, ResourcefulResourceAccessControlFilter } from '../types'
10
+ import type { ExternalDocumentationObject, PromiseAble, ResourcefulColumnDefinition, ResourcefulComputedAccessorDefinition, ResourcefulDataType, ResourcefulGeneralAccessControlFilter, ResourcefulModelMetaSchema, ResourcefulModelOpenApiSchema, ResourcefulPropertySchema, ResourcefulRelationshipDefinition, ResourcefulResourceAccessControlFilter } from "../types";
11
11
  /**
12
12
  * Result object returned by the resourceful index/list operation.
13
13
  *
@@ -106,8 +106,19 @@ export interface ResourcefulHooks {
106
106
  payloadValidationSchemas: ResourcefulValidationHooks;
107
107
  }
108
108
  export type ResourcefulMixinEventMap<Model extends LucidModel = LucidModel, ModelInstance = InstanceType<Model>> = EventMap<{
109
- 'acl:error': [unknown, HttpContext, ApplicationService, ModelInstance | undefined];
110
- 'validation:scope:error': [unknown, HttpContext, ApplicationService, string, ResourcefulDataType];
109
+ 'acl:error': [
110
+ unknown,
111
+ HttpContext,
112
+ ApplicationService,
113
+ ModelInstance | undefined
114
+ ];
115
+ 'validation:scope:error': [
116
+ unknown,
117
+ HttpContext,
118
+ ApplicationService,
119
+ string,
120
+ ResourcefulDataType
121
+ ];
111
122
  }>;
112
123
  /**
113
124
  * Enhanced Lucid model interface providing resourceful CRUD functionality.
@@ -310,7 +321,10 @@ export interface ResourcefulModel extends LucidModel {
310
321
  * );
311
322
  * ```
312
323
  */
313
- $onResourcefulIndex(filter: string | null | undefined, page: number, perPage: number, fields: string | string[] | null | undefined, sort: Array<[string, 'asc' | 'desc']> | null | undefined, ctx: HttpContext, app: ApplicationService, hooks?: ResourcefulScopeHooks, aggregations?: ResourcefulIndexAggregateOptions): Promise<ResourcefulIndexResult<{
324
+ $onResourcefulIndex(filter: string | null | undefined, page: number, perPage: number, fields: string | string[] | null | undefined, sort: Array<[
325
+ string,
326
+ 'asc' | 'desc'
327
+ ]> | null | undefined, ctx: HttpContext, app: ApplicationService, hooks?: ResourcefulScopeHooks, aggregations?: ResourcefulIndexAggregateOptions): Promise<ResourcefulIndexResult<{
314
328
  [key: string]: any;
315
329
  }>>;
316
330
  /**
@@ -399,7 +413,10 @@ export interface ResourcefulModel extends LucidModel {
399
413
  * );
400
414
  * ```
401
415
  */
402
- $onResourcefulReadRelationship(uid: any, relationshipKey: string, filter: string | null | undefined, page: number, perPage: number, fields: string | string[] | null | undefined, sort: Array<[string, 'asc' | 'desc']> | null | undefined, ctx: HttpContext, app: ApplicationService, hooks?: ResourcefulScopeHooks, aggregations?: ResourcefulIndexAggregateOptions): Promise<ResourcefulIndexResult<{
416
+ $onResourcefulReadRelationship(uid: any, relationshipKey: string, filter: string | null | undefined, page: number, perPage: number, fields: string | string[] | null | undefined, sort: Array<[
417
+ string,
418
+ 'asc' | 'desc'
419
+ ]> | null | undefined, ctx: HttpContext, app: ApplicationService, hooks?: ResourcefulScopeHooks, aggregations?: ResourcefulIndexAggregateOptions): Promise<ResourcefulIndexResult<{
403
420
  [key: string]: any;
404
421
  }>>;
405
422
  /**
@@ -1,9 +1,9 @@
1
- import { E_UNRESOLVABLE_MODEL } from '../../../errors'
1
+ import { E_UNRESOLVABLE_MODEL } from "../../../errors";
2
2
  import type { HttpContext } from '@adonisjs/core/http';
3
- import type { AnySchema } from '../../../joi'
3
+ import type { AnySchema } from "../../../joi";
4
4
  import type { ApplicationService } from '@adonisjs/core/types';
5
- import type { ResourcefulRouterModelServiceOptionsService } from '../../router_macro/services/resourceful_router_model_options_service';
6
- import type { ResourcefulModel, ResourcefulIndexResponse, ResourceResourcefulRecordResponse, ResourcefulQueryScopeCallback, ResourcefulPayloadSchemaGetter, ResourcefulPolicy, ResourcefulRouterMutatorOptions } from '../../../types'
5
+ import type { ResourcefulRouterModelServiceOptionsService } from "../../router_macro/services/resourceful_router_model_options_service";
6
+ import type { ResourcefulModel, ResourcefulIndexResponse, ResourceResourcefulRecordResponse, ResourcefulQueryScopeCallback, ResourcefulPayloadSchemaGetter, ResourcefulPolicy, ResourcefulRouterMutatorOptions } from "../../../types";
7
7
  type ODataMetadata = {
8
8
  context: string;
9
9
  } & Partial<{
@@ -1,5 +1,5 @@
1
1
  import type { Router, RouteGroup } from '@adonisjs/core/http';
2
- import type { MacroModelsMap, ResourcefulRouterOptions } from '../router_macro/types';
2
+ import type { MacroModelsMap, ResourcefulRouterOptions } from "../router_macro/types";
3
3
  declare class ODataRouterService {
4
4
  #private;
5
5
  /** @private */
@@ -1,10 +1,10 @@
1
1
  import { errors } from '@vinejs/vine';
2
2
  import { Exception } from '@poppinss/utils';
3
- import { ValidationError as JoiValidationError } from '../../../joi'
4
- import type { JsonObject } from '../../../bundled_type_fest';
3
+ import { ValidationError as JoiValidationError } from "../../../joi";
4
+ import type { JsonObject } from "../../../bundled_type_fest";
5
5
  import type { HttpContext } from '@adonisjs/core/http';
6
6
  import type { NextFn } from '@adonisjs/core/types/http';
7
- import type { EventMap } from '../../../bundled_nhtio_tiny_typed_emitter';
7
+ import type { EventMap } from "../../../bundled_nhtio_tiny_typed_emitter";
8
8
  /**
9
9
  * Type alias for Vine validation errors thrown by the VineJS validation library.
10
10
  *
@@ -34,12 +34,24 @@ export type VineValidationError = InstanceType<typeof errors.E_VALIDATION_ERROR>
34
34
  * ```
35
35
  */
36
36
  export type ODataErrorMiddlewareEvents = EventMap<{
37
- vineValidationError: [VineValidationError];
38
- joiValidationError: [JoiValidationError];
39
- exception: [Exception];
40
- error: [Error];
41
- unknown: [unknown];
42
- any: [unknown];
37
+ vineValidationError: [
38
+ VineValidationError
39
+ ];
40
+ joiValidationError: [
41
+ JoiValidationError
42
+ ];
43
+ exception: [
44
+ Exception
45
+ ];
46
+ error: [
47
+ Error
48
+ ];
49
+ unknown: [
50
+ unknown
51
+ ];
52
+ any: [
53
+ unknown
54
+ ];
43
55
  }>;
44
56
  /**
45
57
  * Configuration object for custom HTTP headers to be included in error responses.
@@ -187,7 +199,7 @@ export interface ResourcefulFormattedError {
187
199
  * @example
188
200
  * ```typescript
189
201
  * // Standalone usage outside of resourceful routes
190
- * import ODataErrorMiddleware from '@//middlewares/resourceful_error'
202
+ * import ODataErrorMiddleware from '@nhtio/lucid-resourceful/middlewares/resourceful_error'
191
203
  *
192
204
  * const errorHandler = new ODataErrorMiddleware({
193
205
  * onException: (error) => logger.error(error),
@@ -1,5 +1,5 @@
1
1
  import { AsyncLocalStorage } from 'node:async_hooks';
2
- import type { ODataResponseFormat, ODataMetadataLevel } from '../utils/http';
2
+ import type { ODataResponseFormat, ODataMetadataLevel } from "../utils/http";
3
3
  export interface ResolvedODataContext {
4
4
  serviceBaseUrl: string;
5
5
  serveAs: ODataResponseFormat;
@@ -1,7 +1,7 @@
1
- import type { ElementCompact } from '../../../bundled_xml_js';
1
+ import type { ElementCompact } from "../../../bundled_xml_js";
2
2
  import type { HttpContext } from '@adonisjs/core/http';
3
- import type { ResourcefulModelController } from '../controllers/resourceful_model_controller';
4
- import type { ResourcefulRouterOptionsService } from '../../router_macro/services/resourceful_router_options_service';
3
+ import type { ResourcefulModelController } from "../controllers/resourceful_model_controller";
4
+ import type { ResourcefulRouterOptionsService } from "../../router_macro/services/resourceful_router_options_service";
5
5
  export declare const makeOpName: (...parts: string[]) => string;
6
6
  export declare class ODataMetadataService {
7
7
  #private;
@@ -1,7 +1,7 @@
1
- import type { ODataPreference } from './http';
1
+ import type { ODataPreference } from "./http";
2
2
  import type { HttpContext } from '@adonisjs/core/http';
3
3
  import type { ApplicationService } from '@adonisjs/core/types';
4
- import type { ResourcefulModel } from '../../../types'
4
+ import type { ResourcefulModel } from "../../../types";
5
5
  export declare const isSimpleIdentifier: (name: unknown) => boolean;
6
6
  export declare const sanitizeSelect: (query: Record<string, any>, model: ResourcefulModel, ctx: HttpContext, app: ApplicationService) => Promise<{
7
7
  valid: string[] | undefined;
@@ -1,4 +1,4 @@
1
- import type { ResourcefulQueryScopeCallback } from './mixin';
1
+ import type { ResourcefulQueryScopeCallback } from "./mixin";
2
2
  import type { DatabaseQueryBuilderContract } from '@adonisjs/lucid/types/querybuilder';
3
3
  export type Dialect = 'postgres' | 'mysql' | 'sqlite';
4
4
  export declare class ODataToLucidTranslator {
@@ -1,6 +1,6 @@
1
- import type { ResourcefulModel } from './mixin';
2
- import type { ApplicationService, HttpContext } from '../types'
3
- import type { ResourcefulModelColumnMetaSchema, ResourcefulModelComputedAccessorMetaSchema, ResourcefulModelRelationshipMetaSchema, ResourcefulModelMetaSchema, ResourcefulModelOpenApiSchema, ResourcefulModelOpenApiRelatedSchema } from './types';
1
+ import type { ResourcefulModel } from "./mixin";
2
+ import type { ApplicationService, HttpContext } from "../types";
3
+ import type { ResourcefulModelColumnMetaSchema, ResourcefulModelComputedAccessorMetaSchema, ResourcefulModelRelationshipMetaSchema, ResourcefulModelMetaSchema, ResourcefulModelOpenApiSchema, ResourcefulModelOpenApiRelatedSchema } from "./types";
4
4
  export interface GenerateModelSchemaOptions {
5
5
  includeRelations?: boolean;
6
6
  relationsDeepLevel?: number | null;
@@ -1,10 +1,10 @@
1
- import { E_UNRESOLVABLE_MODEL } from '../../../errors'
2
- import type { ElementCompact } from '../../../bundled_xml_js';
1
+ import { E_UNRESOLVABLE_MODEL } from "../../../errors";
2
+ import type { ElementCompact } from "../../../bundled_xml_js";
3
3
  import type { HttpContext } from '@adonisjs/core/http';
4
- import type { AnySchema } from '../../../joi'
4
+ import type { AnySchema } from "../../../joi";
5
5
  import type { ApplicationService } from '@adonisjs/core/types';
6
- import type { ResourcefulRouterModelServiceOptionsService } from '../services/resourceful_router_model_options_service';
7
- import type { ResourcefulModel, ResourcefulIndexResult, ServableResourcefulIndexResult, ResourcefulIndexResponse, ResourceResourcefulRecordResponse, ResourcefulQueryScopeCallback, ResourcefulPayloadSchemaGetter, ResourcefulPolicy, ResourcefulRouterMutatorOptions } from '../../../types'
6
+ import type { ResourcefulRouterModelServiceOptionsService } from "../services/resourceful_router_model_options_service";
7
+ import type { ResourcefulModel, ResourcefulIndexResult, ServableResourcefulIndexResult, ResourcefulIndexResponse, ResourceResourcefulRecordResponse, ResourcefulQueryScopeCallback, ResourcefulPayloadSchemaGetter, ResourcefulPolicy, ResourcefulRouterMutatorOptions } from "../../../types";
8
8
  export type ResourcefulModelControllerHooks = {
9
9
  index: [
10
10
  [
@@ -1,6 +1,6 @@
1
- import { ResourcefulModelController } from './controllers/resourceful_model_controller';
1
+ import { ResourcefulModelController } from "./controllers/resourceful_model_controller";
2
2
  import type { Router, RouteGroup } from '@adonisjs/core/http';
3
- import type { MacroModelsMap, ResourcefulRouterOptions, ResourcefulRouterMacro } from './types';
3
+ import type { MacroModelsMap, ResourcefulRouterOptions, ResourcefulRouterMacro } from "./types";
4
4
  declare class ResourcefulRouterService {
5
5
  #private;
6
6
  /** @private */
@@ -11,4 +11,4 @@ declare class ResourcefulRouterService {
11
11
  export declare const resourcefulRouterMacro: ResourcefulRouterMacro;
12
12
  export type { ResourcefulRouterService };
13
13
  export type GetResourcefulModelCreatePayloadValidationSchemaArgs = Parameters<(typeof ResourcefulModelController)['getResourcefulModelCreatePayloadValidationSchema']>;
14
- export declare const getResourcefulModelCreatePayloadValidationSchema: (...args: GetResourcefulModelCreatePayloadValidationSchemaArgs) => Promise<import("@nhtio/validation").AnySchema<any>>;
14
+ export declare const getResourcefulModelCreatePayloadValidationSchema: (...args: GetResourcefulModelCreatePayloadValidationSchemaArgs) => Promise<import("../../bundled_nhtio_validation").AnySchema<any>>;