@forinda/kickjs 3.1.3 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -212
- package/dist/adapter-BNw2pGbg.d.mts +261 -0
- package/dist/adapter-BNw2pGbg.d.mts.map +1 -0
- package/dist/{app-module-Cotu9TIC.d.mts → app-module-CO0ksPCm.d.mts} +12 -2
- package/dist/app-module-CO0ksPCm.d.mts.map +1 -0
- package/dist/{application-BVl6L8xo.mjs → application-Ce4DQN6m.mjs} +114 -25
- package/dist/application-Ce4DQN6m.mjs.map +1 -0
- package/dist/application-Czwm7Gty.d.mts +302 -0
- package/dist/application-Czwm7Gty.d.mts.map +1 -0
- package/dist/{bootstrap-D6leYXz2.mjs → bootstrap-CB7bJeJG.mjs} +6 -6
- package/dist/{bootstrap-D6leYXz2.mjs.map → bootstrap-CB7bJeJG.mjs.map} +1 -1
- package/dist/bootstrap-NxFRaNTh.d.mts +28 -0
- package/dist/bootstrap-NxFRaNTh.d.mts.map +1 -0
- package/dist/{cache-CcTzzNdr.d.mts → cache-BStrqXSZ.d.mts} +2 -2
- package/dist/{cache-CcTzzNdr.d.mts.map → cache-BStrqXSZ.d.mts.map} +1 -1
- package/dist/config/index.d.mts +1 -1
- package/dist/config/index.mjs +3 -3
- package/dist/{config-gkVEnxVm.mjs → config-wZ_TgBfs.mjs} +4 -4
- package/dist/{config-gkVEnxVm.mjs.map → config-wZ_TgBfs.mjs.map} +1 -1
- package/dist/{container-BJb34faa.d.mts → container-CnWDsxi-.d.mts} +9 -7
- package/dist/container-CnWDsxi-.d.mts.map +1 -0
- package/dist/{container-BBZLlK6y.mjs → container-DYYSu58w.mjs} +313 -9
- package/dist/container-DYYSu58w.mjs.map +1 -0
- package/dist/context-BAGzqT7-.mjs +319 -0
- package/dist/context-BAGzqT7-.mjs.map +1 -0
- package/dist/context-Ymvv-85x.d.mts +260 -0
- package/dist/context-Ymvv-85x.d.mts.map +1 -0
- package/dist/context-decorator-B5v3VQCN.d.mts +111 -0
- package/dist/context-decorator-B5v3VQCN.d.mts.map +1 -0
- package/dist/core/adapter.d.mts +1 -1
- package/dist/core/adapter.mjs +1 -1
- package/dist/core/app-module.d.mts +1 -1
- package/dist/core/app-module.mjs +1 -1
- package/dist/core/cache.d.mts +1 -1
- package/dist/core/cache.mjs +2 -2
- package/dist/core/cache.mjs.map +1 -1
- package/dist/core/container.d.mts +1 -1
- package/dist/core/container.mjs +2 -2
- package/dist/core/cron.d.mts +1 -1
- package/dist/core/cron.mjs +2 -2
- package/dist/core/decorators.d.mts +2 -2
- package/dist/core/decorators.mjs +48 -16
- package/dist/core/decorators.mjs.map +1 -1
- package/dist/core/errors.d.mts +1 -1
- package/dist/core/errors.mjs +1 -1
- package/dist/core/interfaces.d.mts +1 -1
- package/dist/core/interfaces.mjs +35 -16
- package/dist/core/interfaces.mjs.map +1 -1
- package/dist/core/logger.d.mts +2 -2
- package/dist/core/logger.mjs +2 -4
- package/dist/core/logger.mjs.map +1 -1
- package/dist/core/path.d.mts +1 -1
- package/dist/core/path.mjs +1 -1
- package/dist/core/plugin.d.mts +1 -1
- package/dist/core/plugin.mjs +1 -1
- package/dist/core/reactivity.d.mts +1 -1
- package/dist/core/reactivity.mjs +1 -1
- package/dist/core-DBcoqPHM.mjs +709 -0
- package/dist/core-DBcoqPHM.mjs.map +1 -0
- package/dist/cors-BfgqfLPd.d.mts +48 -0
- package/dist/cors-BfgqfLPd.d.mts.map +1 -0
- package/dist/{cron-H-IyLcOr.d.mts → cron-7zqvsmMI.d.mts} +1 -1
- package/dist/{cron-H-IyLcOr.d.mts.map → cron-7zqvsmMI.d.mts.map} +1 -1
- package/dist/csrf-DiK9zept.d.mts +52 -0
- package/dist/csrf-DiK9zept.d.mts.map +1 -0
- package/dist/{decorators-C9_SN7ge.d.mts → decorators-BMvaLliz.d.mts} +147 -12
- package/dist/decorators-BMvaLliz.d.mts.map +1 -0
- package/dist/{env-Cu5hWsuE.mjs → env-CdH5-dM_.mjs} +3 -4
- package/dist/{env-Cu5hWsuE.mjs.map → env-CdH5-dM_.mjs.map} +1 -1
- package/dist/error-handler-Xud_3Lah.d.mts +20 -0
- package/dist/error-handler-Xud_3Lah.d.mts.map +1 -0
- package/dist/{errors-BOUCRl-p.d.mts → errors-uaHCeXRz.d.mts} +1 -1
- package/dist/{errors-BOUCRl-p.d.mts.map → errors-uaHCeXRz.d.mts.map} +1 -1
- package/dist/execution-context-DKnt61pY.d.mts +57 -0
- package/dist/execution-context-DKnt61pY.d.mts.map +1 -0
- package/dist/helmet-CaMbjzBG.d.mts +41 -0
- package/dist/helmet-CaMbjzBG.d.mts.map +1 -0
- package/dist/http/application.d.mts +2 -239
- package/dist/http/application.mjs +2 -2
- package/dist/http/bootstrap.d.mts +2 -27
- package/dist/http/bootstrap.mjs +2 -2
- package/dist/http/context.d.mts +3 -262
- package/dist/http/context.mjs +2 -271
- package/dist/http/middleware/cors.d.mts +2 -47
- package/dist/http/middleware/cors.mjs +1 -1
- package/dist/http/middleware/csrf.d.mts +2 -51
- package/dist/http/middleware/csrf.mjs +2 -2
- package/dist/http/middleware/csrf.mjs.map +1 -1
- package/dist/http/middleware/error-handler.d.mts +2 -19
- package/dist/http/middleware/error-handler.mjs +2 -2
- package/dist/http/middleware/helmet.d.mts +2 -40
- package/dist/http/middleware/helmet.mjs +1 -1
- package/dist/http/middleware/rate-limit.d.mts +2 -55
- package/dist/http/middleware/rate-limit.mjs +2 -2
- package/dist/http/middleware/rate-limit.mjs.map +1 -1
- package/dist/http/middleware/request-id.d.mts +2 -9
- package/dist/http/middleware/request-id.mjs +12 -3
- package/dist/http/middleware/request-id.mjs.map +1 -1
- package/dist/http/middleware/request-logger.d.mts +2 -31
- package/dist/http/middleware/request-logger.mjs +2 -2
- package/dist/http/middleware/session.d.mts +2 -69
- package/dist/http/middleware/session.mjs +1 -1
- package/dist/http/middleware/spa.d.mts +2 -100
- package/dist/http/middleware/spa.mjs +5 -5
- package/dist/http/middleware/spa.mjs.map +1 -1
- package/dist/http/middleware/upload.d.mts +2 -78
- package/dist/http/middleware/upload.mjs +1 -1
- package/dist/http/middleware/validate.d.mts +2 -22
- package/dist/http/middleware/validate.mjs +2 -2
- package/dist/http/middleware/views.d.mts +2 -61
- package/dist/http/middleware/views.mjs +16 -15
- package/dist/http/middleware/views.mjs.map +1 -1
- package/dist/http/query/index.d.mts +1 -1
- package/dist/http/query/index.mjs +2 -2
- package/dist/http/router-builder.d.mts +2 -20
- package/dist/http/router-builder.mjs +58 -10
- package/dist/http/router-builder.mjs.map +1 -1
- package/dist/{index-Co7a3Zat.d.mts → index-B9cyOQAe.d.mts} +1 -1
- package/dist/{index-Co7a3Zat.d.mts.map → index-B9cyOQAe.d.mts.map} +1 -1
- package/dist/{index-DNVfGjF9.d.mts → index-D-qhXg9M.d.mts} +3 -3
- package/dist/{index-DNVfGjF9.d.mts.map → index-D-qhXg9M.d.mts.map} +1 -1
- package/dist/index-DQyWtyp0.d.mts +511 -0
- package/dist/index-DQyWtyp0.d.mts.map +1 -0
- package/dist/index.d.mts +34 -133
- package/dist/index.mjs +14 -14
- package/dist/interfaces-B50n7dwl.d.mts +71 -0
- package/dist/{interfaces-DXjE8Re1.d.mts.map → interfaces-B50n7dwl.d.mts.map} +1 -1
- package/dist/{logger-CW6FHtvU.d.mts → logger-CLVRZf2N.d.mts} +2 -4
- package/dist/{logger-CW6FHtvU.d.mts.map → logger-CLVRZf2N.d.mts.map} +1 -1
- package/dist/{metadata-BwRJ69bC.mjs → metadata-VQM9wChy.mjs} +2 -2
- package/dist/{metadata-BwRJ69bC.mjs.map → metadata-VQM9wChy.mjs.map} +1 -1
- package/dist/{path-B4JcbwKX.d.mts → path-Diviu6hv.d.mts} +1 -1
- package/dist/path-Diviu6hv.d.mts.map +1 -0
- package/dist/plugin-WdrDgNzk.d.mts +165 -0
- package/dist/plugin-WdrDgNzk.d.mts.map +1 -0
- package/dist/{query-BQ2UT3oi.mjs → query-DJMxdx5r.mjs} +2 -2
- package/dist/{query-BQ2UT3oi.mjs.map → query-DJMxdx5r.mjs.map} +1 -1
- package/dist/rate-limit-DUwoICtI.d.mts +56 -0
- package/dist/rate-limit-DUwoICtI.d.mts.map +1 -0
- package/dist/{reactivity-I8nDlg4c.d.mts → reactivity-CfJceo4H.d.mts} +1 -1
- package/dist/{reactivity-I8nDlg4c.d.mts.map → reactivity-CfJceo4H.d.mts.map} +1 -1
- package/dist/request-id-BgglvZHN.d.mts +19 -0
- package/dist/request-id-BgglvZHN.d.mts.map +1 -0
- package/dist/request-logger-CWHbAzTE.d.mts +32 -0
- package/dist/request-logger-CWHbAzTE.d.mts.map +1 -0
- package/dist/router-builder-C799BAf0.d.mts +31 -0
- package/dist/router-builder-C799BAf0.d.mts.map +1 -0
- package/dist/session-N0hActOO.d.mts +70 -0
- package/dist/session-N0hActOO.d.mts.map +1 -0
- package/dist/spa-CrFR2_cz.d.mts +101 -0
- package/dist/spa-CrFR2_cz.d.mts.map +1 -0
- package/dist/upload-BueOnnLw.d.mts +79 -0
- package/dist/upload-BueOnnLw.d.mts.map +1 -0
- package/dist/validate-HwAyWTwH.d.mts +23 -0
- package/dist/validate-HwAyWTwH.d.mts.map +1 -0
- package/dist/views-DhQSXV2P.d.mts +176 -0
- package/dist/views-DhQSXV2P.d.mts.map +1 -0
- package/package.json +6 -9
- package/dist/adapter-DjL8ql5d.d.mts +0 -140
- package/dist/adapter-DjL8ql5d.d.mts.map +0 -1
- package/dist/app-module-Cotu9TIC.d.mts.map +0 -1
- package/dist/application-BVl6L8xo.mjs.map +0 -1
- package/dist/chunk-CVPG7JJl.mjs +0 -15
- package/dist/container-BBZLlK6y.mjs.map +0 -1
- package/dist/container-BJb34faa.d.mts.map +0 -1
- package/dist/core-qyPNtpKp.mjs +0 -121
- package/dist/core-qyPNtpKp.mjs.map +0 -1
- package/dist/decorators-C9_SN7ge.d.mts.map +0 -1
- package/dist/http/application.d.mts.map +0 -1
- package/dist/http/bootstrap.d.mts.map +0 -1
- package/dist/http/context.d.mts.map +0 -1
- package/dist/http/context.mjs.map +0 -1
- package/dist/http/middleware/cors.d.mts.map +0 -1
- package/dist/http/middleware/csrf.d.mts.map +0 -1
- package/dist/http/middleware/error-handler.d.mts.map +0 -1
- package/dist/http/middleware/helmet.d.mts.map +0 -1
- package/dist/http/middleware/rate-limit.d.mts.map +0 -1
- package/dist/http/middleware/request-id.d.mts.map +0 -1
- package/dist/http/middleware/request-logger.d.mts.map +0 -1
- package/dist/http/middleware/session.d.mts.map +0 -1
- package/dist/http/middleware/spa.d.mts.map +0 -1
- package/dist/http/middleware/upload.d.mts.map +0 -1
- package/dist/http/middleware/validate.d.mts.map +0 -1
- package/dist/http/middleware/views.d.mts.map +0 -1
- package/dist/http/router-builder.d.mts.map +0 -1
- package/dist/index-CwqjAF6I.d.mts +0 -112
- package/dist/index-CwqjAF6I.d.mts.map +0 -1
- package/dist/index.d.mts.map +0 -1
- package/dist/interfaces-DXjE8Re1.d.mts +0 -52
- package/dist/path-B4JcbwKX.d.mts.map +0 -1
- package/dist/plugin-Cvacmm7N.d.mts +0 -95
- package/dist/plugin-Cvacmm7N.d.mts.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"query-BQ2UT3oi.mjs","names":[],"sources":["../src/http/query/types.ts","../src/http/query/parse-query.ts"],"sourcesContent":["/** Supported filter operators for query string parsing */\nexport type FilterOperator =\n | 'eq'\n | 'neq'\n | 'gt'\n | 'gte'\n | 'lt'\n | 'lte'\n | 'between'\n | 'in'\n | 'contains'\n | 'starts'\n | 'ends'\n\nexport const FILTER_OPERATORS = new Set<string>([\n 'eq',\n 'neq',\n 'gt',\n 'gte',\n 'lt',\n 'lte',\n 'between',\n 'in',\n 'contains',\n 'starts',\n 'ends',\n])\n\nexport interface FilterItem {\n field: string\n operator: FilterOperator\n value: string\n}\n\nexport interface SortItem {\n field: string\n direction: 'asc' | 'desc'\n}\n\nexport interface PaginationParams {\n page: number\n limit: number\n offset: number\n}\n\n/**\n * The result of parsing a query string. ORM-agnostic — pass this to\n * a query builder adapter (Drizzle, Prisma, Sequelize, etc.) to produce\n * database-specific query objects.\n */\nexport interface ParsedQuery {\n filters: FilterItem[]\n sort: SortItem[]\n pagination: PaginationParams\n search: string\n}\n\n/**\n * Helper that extracts the literal field union from a `QueryFieldConfig`\n * key. When the user passes `{ filterable: ['status', 'category'] } as const`,\n * `FieldsOf<typeof config, 'filterable'>` resolves to `'status' | 'category'`.\n *\n * Without `as const`, the arrays widen to `string[]` and the union falls\n * back to `string`. This is the documented escape hatch.\n */\nexport type FieldsOf<\n TConfig extends QueryFieldConfig | undefined,\n K extends 'filterable' | 'sortable' | 'searchable',\n> = TConfig extends { readonly [P in K]: readonly (infer F)[] }\n ? F extends string\n ? F\n : string\n : TConfig extends { columns: infer C }\n ? K extends 'filterable'\n ? keyof C & string\n : string\n : string\n\n/**\n * Narrowed `ParsedQuery` whose `filters[].field` and `sort[].field`\n * unions are constrained to the literal whitelist passed to\n * `ctx.qs()` / `parseQuery()`. Extends `ParsedQuery`, so any function\n * accepting `ParsedQuery` accepts a `TypedParsedQuery<X>` automatically\n * (subtype assignment, no codegen, backward compatible).\n *\n * @example\n * ```ts\n * const parsed = ctx.qs({\n * filterable: ['status', 'priority'],\n * sortable: ['createdAt'],\n * } as const)\n * parsed.filters[0]?.field // 'status' | 'priority'\n * parsed.sort[0]?.field // 'createdAt'\n * ```\n */\nexport interface TypedParsedQuery<\n TConfig extends QueryFieldConfig | undefined,\n> extends ParsedQuery {\n filters: Array<FilterItem & { field: FieldsOf<TConfig, 'filterable'> }>\n sort: Array<SortItem & { field: FieldsOf<TConfig, 'sortable'> }>\n}\n\n/**\n * Restrict which fields can be filtered, sorted, or searched.\n * Fields not in the allow-list are silently ignored.\n *\n * Accepts two forms:\n * 1. **String arrays** (standard): `{ filterable: ['name', 'status'], sortable: ['createdAt'] }`\n * 2. **Column-object maps** (Drizzle-style): `{ columns: { name: col, status: col }, sortable: { createdAt: col } }`\n *\n * When column-object maps are provided, `Object.keys()` is used to derive the field names.\n */\nexport type QueryFieldConfig = StringQueryFieldConfig | ColumnQueryFieldConfig\n\nexport interface StringQueryFieldConfig {\n filterable?: string[]\n sortable?: string[]\n searchable?: string[]\n}\n\n/**\n * Column-object-based field config (e.g., from DrizzleQueryParamsConfig).\n * Keys are the field names used in query strings; values are ORM column references.\n */\nexport interface ColumnQueryFieldConfig {\n columns: Record<string, any>\n sortable?: Record<string, any>\n searchColumns?: any[]\n [key: string]: any\n}\n\n/** Standardized paginated response shape */\nexport interface PaginatedResponse<T = any> {\n data: T[]\n meta: {\n page: number\n limit: number\n total: number\n totalPages: number\n hasNext: boolean\n hasPrev: boolean\n }\n}\n\n/**\n * Interface for ORM-specific query builder adapters.\n * Implement this to translate a `ParsedQuery` into your ORM's query format.\n *\n * @example\n * ```ts\n * // Drizzle adapter\n * class DrizzleQueryAdapter implements QueryBuilderAdapter<DrizzleQueryResult> {\n * build(parsed: ParsedQuery, config: DrizzleConfig): DrizzleQueryResult {\n * // Convert filters → Drizzle SQL conditions\n * // Convert sort → Drizzle orderBy\n * return { where, orderBy, limit, offset }\n * }\n * }\n *\n * // Prisma adapter\n * class PrismaQueryAdapter implements QueryBuilderAdapter<PrismaQueryResult> {\n * build(parsed: ParsedQuery, config: PrismaConfig): PrismaQueryResult {\n * return { where, orderBy, skip, take }\n * }\n * }\n * ```\n */\nexport interface QueryBuilderAdapter<TResult = any, TConfig = any> {\n /** Human-readable name for debugging */\n readonly name: string\n\n /**\n * Convert a ParsedQuery into an ORM-specific query object.\n * @param parsed - The ORM-agnostic parsed query\n * @param config - ORM-specific configuration (column maps, search columns, etc.)\n */\n build(parsed: ParsedQuery, config: TConfig): TResult\n}\n","import {\n FILTER_OPERATORS,\n type FilterItem,\n type FilterOperator,\n type SortItem,\n type PaginationParams,\n type ParsedQuery,\n type QueryFieldConfig,\n type StringQueryFieldConfig,\n type TypedParsedQuery,\n} from './types'\n\nconst MAX_SEARCH_LENGTH = 200\nconst DEFAULT_PAGE = 1\nconst DEFAULT_LIMIT = 20\nconst MAX_LIMIT = 100\n\n// ── Individual parsers ──────────────────────────────────────────────────\n\n/** Parse filter strings like \"status:eq:active\" into structured objects */\nexport function parseFilters(\n filterParam: string | string[] | undefined,\n allowedFields?: string[],\n): FilterItem[] {\n if (!filterParam) return []\n\n const items = Array.isArray(filterParam) ? filterParam : [filterParam]\n const results: FilterItem[] = []\n const allowed = allowedFields ? new Set(allowedFields) : null\n\n for (const item of items) {\n // Split on first two colons only — value may contain colons (e.g. timestamps)\n const firstColon = item.indexOf(':')\n if (firstColon === -1) continue\n\n const secondColon = item.indexOf(':', firstColon + 1)\n if (secondColon === -1) continue\n\n const field = item.slice(0, firstColon)\n const operator = item.slice(firstColon + 1, secondColon)\n const value = item.slice(secondColon + 1)\n\n if (!field || !value) continue\n if (!FILTER_OPERATORS.has(operator)) continue\n if (allowed && !allowed.has(field)) continue\n\n results.push({ field, operator: operator as FilterOperator, value })\n }\n\n return results\n}\n\n/** Parse sort strings like \"firstName:asc\" into structured objects */\nexport function parseSort(\n sortParam: string | string[] | undefined,\n allowedFields?: string[],\n): SortItem[] {\n if (!sortParam) return []\n\n const items = Array.isArray(sortParam) ? sortParam : [sortParam]\n const results: SortItem[] = []\n const allowed = allowedFields ? new Set(allowedFields) : null\n\n for (const item of items) {\n // Split on last colon so field names with colons work\n const lastColon = item.lastIndexOf(':')\n if (lastColon === -1) continue\n\n const field = item.slice(0, lastColon)\n const dir = item.slice(lastColon + 1).toLowerCase()\n\n if (!field) continue\n if (dir !== 'asc' && dir !== 'desc') continue\n if (allowed && !allowed.has(field)) continue\n\n results.push({ field, direction: dir })\n }\n\n return results\n}\n\n/** Parse page/limit into pagination with computed offset */\nexport function parsePagination(params: {\n page?: string | number\n limit?: string | number\n}): PaginationParams {\n let page =\n typeof params.page === 'string'\n ? Number.parseInt(params.page, 10)\n : (params.page ?? DEFAULT_PAGE)\n let limit =\n typeof params.limit === 'string'\n ? Number.parseInt(params.limit, 10)\n : (params.limit ?? DEFAULT_LIMIT)\n\n if (Number.isNaN(page) || page < 1) page = DEFAULT_PAGE\n if (Number.isNaN(limit) || limit < 1) limit = DEFAULT_LIMIT\n if (limit > MAX_LIMIT) limit = MAX_LIMIT\n\n return { page, limit, offset: (page - 1) * limit }\n}\n\n/** Sanitize and truncate search query */\nexport function parseSearchQuery(q: string | undefined): string {\n if (!q) return ''\n return q.trim().slice(0, MAX_SEARCH_LENGTH)\n}\n\n// ── Config normalizer ───────────────────────────────────────────────────\n\n/**\n * Normalize a QueryFieldConfig into the string-based form.\n * Detects column-object-based configs (DrizzleQueryParamsConfig) by checking\n * for a `columns` property and extracts `Object.keys()`.\n */\nfunction normalizeFieldConfig(config?: QueryFieldConfig): StringQueryFieldConfig | undefined {\n if (!config) return undefined\n\n // Column-object-based config (e.g., DrizzleQueryParamsConfig)\n if ('columns' in config && config.columns && typeof config.columns === 'object') {\n return {\n filterable: Object.keys(config.columns),\n sortable: config.sortable ? Object.keys(config.sortable) : undefined,\n searchable: undefined, // searchColumns are Column objects, not used for string filtering\n }\n }\n\n // Already string-based\n return config as StringQueryFieldConfig\n}\n\n// ── Combined parser ─────────────────────────────────────────────────────\n\n/**\n * Parse a raw Express query object into a structured, ORM-agnostic ParsedQuery.\n *\n * @param query - Raw query string object from `req.query` or Zod-validated object\n * @param fieldConfig - Optional field restrictions (whitelist filterable/sortable/searchable).\n * Accepts both string-based configs (`{ filterable, sortable, searchable }`) and\n * column-object configs (`{ columns, sortable, searchColumns }`).\n *\n * @example\n * ```ts\n * // String-based config\n * const parsed = parseQuery(ctx.query, {\n * filterable: ['status', 'priority'],\n * sortable: ['createdAt', 'title'],\n * })\n *\n * // Column-object config (DrizzleQueryParamsConfig)\n * const parsed = parseQuery(ctx.query, TASK_QUERY_CONFIG)\n * ```\n *\n * Query string format:\n * - Filters: `?filter=field:operator:value` (repeatable)\n * - Sort: `?sort=field:asc|desc` (repeatable)\n * - Pagination: `?page=1&limit=20`\n * - Search: `?q=search+term`\n *\n * Filter operators: eq, neq, gt, gte, lt, lte, between, in, contains, starts, ends\n */\nexport function parseQuery<TConfig extends QueryFieldConfig | undefined = undefined>(\n query: Record<string, any>,\n fieldConfig?: TConfig,\n): TypedParsedQuery<TConfig> {\n const normalized = normalizeFieldConfig(fieldConfig)\n return {\n filters: parseFilters(query.filter, normalized?.filterable),\n sort: parseSort(query.sort, normalized?.sortable),\n pagination: parsePagination({ page: query.page, limit: query.limit }),\n search: parseSearchQuery(query.q),\n } as TypedParsedQuery<TConfig>\n}\n\n// ── Query URL builder (for client-side or testing) ──────────────────────\n\n/** Convert ParsedQuery back into query string parameters */\nexport function buildQueryParams(\n parsed: Partial<ParsedQuery>,\n): Record<string, string | string[] | number> {\n const params: Record<string, string | string[] | number> = {}\n\n if (parsed.filters?.length) {\n params.filter = parsed.filters.map((f) => `${f.field}:${f.operator}:${f.value}`)\n }\n\n if (parsed.sort?.length) {\n params.sort = parsed.sort.map((s) => `${s.field}:${s.direction}`)\n }\n\n if (parsed.pagination) {\n params.page = parsed.pagination.page\n params.limit = parsed.pagination.limit\n }\n\n if (parsed.search) {\n params.q = parsed.search\n }\n\n return params\n}\n"],"mappings":";;;;;;;;;;;AAcA,MAAa,mBAAmB,IAAI,IAAY;CAC9C;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD,CAAC;;;ACdF,MAAM,oBAAoB;AAC1B,MAAM,eAAe;AACrB,MAAM,gBAAgB;AACtB,MAAM,YAAY;;AAKlB,SAAgB,aACd,aACA,eACc;AACd,KAAI,CAAC,YAAa,QAAO,EAAE;CAE3B,MAAM,QAAQ,MAAM,QAAQ,YAAY,GAAG,cAAc,CAAC,YAAY;CACtE,MAAM,UAAwB,EAAE;CAChC,MAAM,UAAU,gBAAgB,IAAI,IAAI,cAAc,GAAG;AAEzD,MAAK,MAAM,QAAQ,OAAO;EAExB,MAAM,aAAa,KAAK,QAAQ,IAAI;AACpC,MAAI,eAAe,GAA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;AAGnC,KAAI,OAAO,OACT,QAAO,IAAI,OAAO;AAGpB,QAAO"}
|
|
1
|
+
{"version":3,"file":"query-DJMxdx5r.mjs","names":[],"sources":["../src/http/query/types.ts","../src/http/query/parse-query.ts"],"sourcesContent":["/** Supported filter operators for query string parsing */\nexport type FilterOperator =\n | 'eq'\n | 'neq'\n | 'gt'\n | 'gte'\n | 'lt'\n | 'lte'\n | 'between'\n | 'in'\n | 'contains'\n | 'starts'\n | 'ends'\n\nexport const FILTER_OPERATORS = new Set<string>([\n 'eq',\n 'neq',\n 'gt',\n 'gte',\n 'lt',\n 'lte',\n 'between',\n 'in',\n 'contains',\n 'starts',\n 'ends',\n])\n\nexport interface FilterItem {\n field: string\n operator: FilterOperator\n value: string\n}\n\nexport interface SortItem {\n field: string\n direction: 'asc' | 'desc'\n}\n\nexport interface PaginationParams {\n page: number\n limit: number\n offset: number\n}\n\n/**\n * The result of parsing a query string. ORM-agnostic — pass this to\n * a query builder adapter (Drizzle, Prisma, Sequelize, etc.) to produce\n * database-specific query objects.\n */\nexport interface ParsedQuery {\n filters: FilterItem[]\n sort: SortItem[]\n pagination: PaginationParams\n search: string\n}\n\n/**\n * Helper that extracts the literal field union from a `QueryFieldConfig`\n * key. When the user passes `{ filterable: ['status', 'category'] } as const`,\n * `FieldsOf<typeof config, 'filterable'>` resolves to `'status' | 'category'`.\n *\n * Without `as const`, the arrays widen to `string[]` and the union falls\n * back to `string`. This is the documented escape hatch.\n */\nexport type FieldsOf<\n TConfig extends QueryFieldConfig | undefined,\n K extends 'filterable' | 'sortable' | 'searchable',\n> = TConfig extends { readonly [P in K]: readonly (infer F)[] }\n ? F extends string\n ? F\n : string\n : TConfig extends { columns: infer C }\n ? K extends 'filterable'\n ? keyof C & string\n : string\n : string\n\n/**\n * Narrowed `ParsedQuery` whose `filters[].field` and `sort[].field`\n * unions are constrained to the literal whitelist passed to\n * `ctx.qs()` / `parseQuery()`. Extends `ParsedQuery`, so any function\n * accepting `ParsedQuery` accepts a `TypedParsedQuery<X>` automatically\n * (subtype assignment, no codegen, backward compatible).\n *\n * @example\n * ```ts\n * const parsed = ctx.qs({\n * filterable: ['status', 'priority'],\n * sortable: ['createdAt'],\n * } as const)\n * parsed.filters[0]?.field // 'status' | 'priority'\n * parsed.sort[0]?.field // 'createdAt'\n * ```\n */\nexport interface TypedParsedQuery<\n TConfig extends QueryFieldConfig | undefined,\n> extends ParsedQuery {\n filters: Array<FilterItem & { field: FieldsOf<TConfig, 'filterable'> }>\n sort: Array<SortItem & { field: FieldsOf<TConfig, 'sortable'> }>\n}\n\n/**\n * Restrict which fields can be filtered, sorted, or searched.\n * Fields not in the allow-list are silently ignored.\n *\n * Accepts two forms:\n * 1. **String arrays** (standard): `{ filterable: ['name', 'status'], sortable: ['createdAt'] }`\n * 2. **Column-object maps** (Drizzle-style): `{ columns: { name: col, status: col }, sortable: { createdAt: col } }`\n *\n * When column-object maps are provided, `Object.keys()` is used to derive the field names.\n */\nexport type QueryFieldConfig = StringQueryFieldConfig | ColumnQueryFieldConfig\n\nexport interface StringQueryFieldConfig {\n filterable?: string[]\n sortable?: string[]\n searchable?: string[]\n}\n\n/**\n * Column-object-based field config (e.g., from DrizzleQueryParamsConfig).\n * Keys are the field names used in query strings; values are ORM column references.\n */\nexport interface ColumnQueryFieldConfig {\n columns: Record<string, any>\n sortable?: Record<string, any>\n searchColumns?: any[]\n [key: string]: any\n}\n\n/** Standardized paginated response shape */\nexport interface PaginatedResponse<T = any> {\n data: T[]\n meta: {\n page: number\n limit: number\n total: number\n totalPages: number\n hasNext: boolean\n hasPrev: boolean\n }\n}\n\n/**\n * Interface for ORM-specific query builder adapters.\n * Implement this to translate a `ParsedQuery` into your ORM's query format.\n *\n * @example\n * ```ts\n * // Drizzle adapter\n * class DrizzleQueryAdapter implements QueryBuilderAdapter<DrizzleQueryResult> {\n * build(parsed: ParsedQuery, config: DrizzleConfig): DrizzleQueryResult {\n * // Convert filters → Drizzle SQL conditions\n * // Convert sort → Drizzle orderBy\n * return { where, orderBy, limit, offset }\n * }\n * }\n *\n * // Prisma adapter\n * class PrismaQueryAdapter implements QueryBuilderAdapter<PrismaQueryResult> {\n * build(parsed: ParsedQuery, config: PrismaConfig): PrismaQueryResult {\n * return { where, orderBy, skip, take }\n * }\n * }\n * ```\n */\nexport interface QueryBuilderAdapter<TResult = any, TConfig = any> {\n /** Human-readable name for debugging */\n readonly name: string\n\n /**\n * Convert a ParsedQuery into an ORM-specific query object.\n * @param parsed - The ORM-agnostic parsed query\n * @param config - ORM-specific configuration (column maps, search columns, etc.)\n */\n build(parsed: ParsedQuery, config: TConfig): TResult\n}\n","import {\n FILTER_OPERATORS,\n type FilterItem,\n type FilterOperator,\n type SortItem,\n type PaginationParams,\n type ParsedQuery,\n type QueryFieldConfig,\n type StringQueryFieldConfig,\n type TypedParsedQuery,\n} from './types'\n\nconst MAX_SEARCH_LENGTH = 200\nconst DEFAULT_PAGE = 1\nconst DEFAULT_LIMIT = 20\nconst MAX_LIMIT = 100\n\n// ── Individual parsers ──────────────────────────────────────────────────\n\n/** Parse filter strings like \"status:eq:active\" into structured objects */\nexport function parseFilters(\n filterParam: string | string[] | undefined,\n allowedFields?: string[],\n): FilterItem[] {\n if (!filterParam) return []\n\n const items = Array.isArray(filterParam) ? filterParam : [filterParam]\n const results: FilterItem[] = []\n const allowed = allowedFields ? new Set(allowedFields) : null\n\n for (const item of items) {\n // Split on first two colons only — value may contain colons (e.g. timestamps)\n const firstColon = item.indexOf(':')\n if (firstColon === -1) continue\n\n const secondColon = item.indexOf(':', firstColon + 1)\n if (secondColon === -1) continue\n\n const field = item.slice(0, firstColon)\n const operator = item.slice(firstColon + 1, secondColon)\n const value = item.slice(secondColon + 1)\n\n if (!field || !value) continue\n if (!FILTER_OPERATORS.has(operator)) continue\n if (allowed && !allowed.has(field)) continue\n\n results.push({ field, operator: operator as FilterOperator, value })\n }\n\n return results\n}\n\n/** Parse sort strings like \"firstName:asc\" into structured objects */\nexport function parseSort(\n sortParam: string | string[] | undefined,\n allowedFields?: string[],\n): SortItem[] {\n if (!sortParam) return []\n\n const items = Array.isArray(sortParam) ? sortParam : [sortParam]\n const results: SortItem[] = []\n const allowed = allowedFields ? new Set(allowedFields) : null\n\n for (const item of items) {\n // Split on last colon so field names with colons work\n const lastColon = item.lastIndexOf(':')\n if (lastColon === -1) continue\n\n const field = item.slice(0, lastColon)\n const dir = item.slice(lastColon + 1).toLowerCase()\n\n if (!field) continue\n if (dir !== 'asc' && dir !== 'desc') continue\n if (allowed && !allowed.has(field)) continue\n\n results.push({ field, direction: dir })\n }\n\n return results\n}\n\n/** Parse page/limit into pagination with computed offset */\nexport function parsePagination(params: {\n page?: string | number\n limit?: string | number\n}): PaginationParams {\n let page =\n typeof params.page === 'string'\n ? Number.parseInt(params.page, 10)\n : (params.page ?? DEFAULT_PAGE)\n let limit =\n typeof params.limit === 'string'\n ? Number.parseInt(params.limit, 10)\n : (params.limit ?? DEFAULT_LIMIT)\n\n if (Number.isNaN(page) || page < 1) page = DEFAULT_PAGE\n if (Number.isNaN(limit) || limit < 1) limit = DEFAULT_LIMIT\n if (limit > MAX_LIMIT) limit = MAX_LIMIT\n\n return { page, limit, offset: (page - 1) * limit }\n}\n\n/** Sanitize and truncate search query */\nexport function parseSearchQuery(q: string | undefined): string {\n if (!q) return ''\n return q.trim().slice(0, MAX_SEARCH_LENGTH)\n}\n\n// ── Config normalizer ───────────────────────────────────────────────────\n\n/**\n * Normalize a QueryFieldConfig into the string-based form.\n * Detects column-object-based configs (DrizzleQueryParamsConfig) by checking\n * for a `columns` property and extracts `Object.keys()`.\n */\nfunction normalizeFieldConfig(config?: QueryFieldConfig): StringQueryFieldConfig | undefined {\n if (!config) return undefined\n\n // Column-object-based config (e.g., DrizzleQueryParamsConfig)\n if ('columns' in config && config.columns && typeof config.columns === 'object') {\n return {\n filterable: Object.keys(config.columns),\n sortable: config.sortable ? Object.keys(config.sortable) : undefined,\n searchable: undefined, // searchColumns are Column objects, not used for string filtering\n }\n }\n\n // Already string-based\n return config as StringQueryFieldConfig\n}\n\n// ── Combined parser ─────────────────────────────────────────────────────\n\n/**\n * Parse a raw Express query object into a structured, ORM-agnostic ParsedQuery.\n *\n * @param query - Raw query string object from `req.query` or Zod-validated object\n * @param fieldConfig - Optional field restrictions (whitelist filterable/sortable/searchable).\n * Accepts both string-based configs (`{ filterable, sortable, searchable }`) and\n * column-object configs (`{ columns, sortable, searchColumns }`).\n *\n * @example\n * ```ts\n * // String-based config\n * const parsed = parseQuery(ctx.query, {\n * filterable: ['status', 'priority'],\n * sortable: ['createdAt', 'title'],\n * })\n *\n * // Column-object config (DrizzleQueryParamsConfig)\n * const parsed = parseQuery(ctx.query, TASK_QUERY_CONFIG)\n * ```\n *\n * Query string format:\n * - Filters: `?filter=field:operator:value` (repeatable)\n * - Sort: `?sort=field:asc|desc` (repeatable)\n * - Pagination: `?page=1&limit=20`\n * - Search: `?q=search+term`\n *\n * Filter operators: eq, neq, gt, gte, lt, lte, between, in, contains, starts, ends\n */\nexport function parseQuery<TConfig extends QueryFieldConfig | undefined = undefined>(\n query: Record<string, any>,\n fieldConfig?: TConfig,\n): TypedParsedQuery<TConfig> {\n const normalized = normalizeFieldConfig(fieldConfig)\n return {\n filters: parseFilters(query.filter, normalized?.filterable),\n sort: parseSort(query.sort, normalized?.sortable),\n pagination: parsePagination({ page: query.page, limit: query.limit }),\n search: parseSearchQuery(query.q),\n } as TypedParsedQuery<TConfig>\n}\n\n// ── Query URL builder (for client-side or testing) ──────────────────────\n\n/** Convert ParsedQuery back into query string parameters */\nexport function buildQueryParams(\n parsed: Partial<ParsedQuery>,\n): Record<string, string | string[] | number> {\n const params: Record<string, string | string[] | number> = {}\n\n if (parsed.filters?.length) {\n params.filter = parsed.filters.map((f) => `${f.field}:${f.operator}:${f.value}`)\n }\n\n if (parsed.sort?.length) {\n params.sort = parsed.sort.map((s) => `${s.field}:${s.direction}`)\n }\n\n if (parsed.pagination) {\n params.page = parsed.pagination.page\n params.limit = parsed.pag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aAAa,MAAM,QAAQ,YAAY,WAAW;EAC3D,MAAM,UAAU,MAAM,MAAM,YAAY,SAAS;EACjD,YAAY,gBAAgB;GAAE,MAAM,MAAM;GAAM,OAAO,MAAM;GAAO,CAAC;EACrE,QAAQ,iBAAiB,MAAM,EAAE;EAClC;;;AAMH,SAAgB,iBACd,QAC4C;CAC5C,MAAM,SAAqD,EAAE;AAE7D,KAAI,OAAO,SAAS,OAClB,QAAO,SAAS,OAAO,QAAQ,KAAK,MAAM,GAAG,EAAE,MAAM,GAAG,EAAE,SAAS,GAAG,EAAE,QAAQ;AAGlF,KAAI,OAAO,MAAM,OACf,QAAO,OAAO,OAAO,KAAK,KAAK,MAAM,GAAG,EAAE,MAAM,GAAG,EAAE,YAAY;AAGnE,KAAI,OAAO,YAAY;AACrB,SAAO,OAAO,OAAO,WAAW;AAChC,SAAO,QAAQ,OAAO,WAAW;;AAGnC,KAAI,OAAO,OACT,QAAO,IAAI,OAAO;AAGpB,QAAO"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
|
|
2
|
+
import { NextFunction, Request, Response } from "express";
|
|
3
|
+
|
|
4
|
+
//#region src/http/middleware/rate-limit.d.ts
|
|
5
|
+
interface RateLimitStore {
|
|
6
|
+
increment(key: string): Promise<{
|
|
7
|
+
totalHits: number;
|
|
8
|
+
resetTime: Date;
|
|
9
|
+
}>;
|
|
10
|
+
decrement(key: string): Promise<void>;
|
|
11
|
+
reset(key: string): Promise<void>;
|
|
12
|
+
}
|
|
13
|
+
interface RateLimitOptions {
|
|
14
|
+
/** Maximum number of requests per window (default: 100) */
|
|
15
|
+
max?: number;
|
|
16
|
+
/** Time window in milliseconds (default: 60_000) */
|
|
17
|
+
windowMs?: number;
|
|
18
|
+
/** Response message when rate limit is exceeded (default: 'Too Many Requests') */
|
|
19
|
+
message?: string;
|
|
20
|
+
/** HTTP status code when rate limit is exceeded (default: 429) */
|
|
21
|
+
statusCode?: number;
|
|
22
|
+
/** Function to generate the key for rate limiting (default: req.ip) */
|
|
23
|
+
keyGenerator?: (req: Request) => string;
|
|
24
|
+
/** Whether to send rate limit headers (default: true) */
|
|
25
|
+
headers?: boolean;
|
|
26
|
+
/** Custom store implementation (default: in-memory Map) */
|
|
27
|
+
store?: RateLimitStore;
|
|
28
|
+
/** Function to skip rate limiting for certain requests */
|
|
29
|
+
skip?: (req: Request) => boolean;
|
|
30
|
+
/** Paths to exclude from rate limiting */
|
|
31
|
+
skipPaths?: string[];
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Rate limiting middleware.
|
|
35
|
+
*
|
|
36
|
+
* Limits the number of requests a client can make within a time window.
|
|
37
|
+
* Uses an in-memory store by default, but accepts a custom store for
|
|
38
|
+
* distributed deployments (e.g. Redis).
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```ts
|
|
42
|
+
* import { rateLimit } from '@forinda/kickjs'
|
|
43
|
+
*
|
|
44
|
+
* bootstrap({
|
|
45
|
+
* modules,
|
|
46
|
+
* middleware: [
|
|
47
|
+
* rateLimit({ max: 100, windowMs: 60_000 }),
|
|
48
|
+
* // ... other middleware
|
|
49
|
+
* ],
|
|
50
|
+
* })
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
declare function rateLimit(options?: RateLimitOptions): (req: Request, res: Response, next: NextFunction) => Promise<void | Response<any, Record<string, any>>>;
|
|
54
|
+
//#endregion
|
|
55
|
+
export { RateLimitStore as n, rateLimit as r, RateLimitOptions as t };
|
|
56
|
+
//# sourceMappingURL=rate-limit-DUwoICtI.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rate-limit-DUwoICtI.d.mts","names":[],"sources":["../src/http/middleware/rate-limit.ts"],"mappings":";;;;UAEiB,cAAA;EACf,SAAA,CAAU,GAAA,WAAc,OAAA;IAAU,SAAA;IAAmB,SAAA,EAAW,IAAA;EAAA;EAChE,SAAA,CAAU,GAAA,WAAc,OAAA;EACxB,KAAA,CAAM,GAAA,WAAc,OAAA;AAAA;AAAA,UAGL,gBAAA;EAHY;EAK3B,GAAA;EAPA;EASA,QAAA;EATwB;EAWxB,OAAA;EAXqD;EAarD,UAAA;EAZA;EAcA,YAAA,IAAgB,GAAA,EAAK,OAAA;EAdG;EAgBxB,OAAA;EAfM;EAiBN,KAAA,GAAQ,cAAA;EAjBmB;EAmB3B,IAAA,IAAQ,GAAA,EAAK,OAAA;EAhBE;EAkBf,SAAA;AAAA;;;;;;;;;;;;;;;;;;;;;iBA4Ec,SAAA,CAAU,OAAA,GAAS,gBAAA,IAWnB,GAAA,EAAK,OAAA,EAAS,GAAA,EAAK,QAAA,EAAU,IAAA,EAAM,YAAA,KAAY,OAAA,QAAA,QAAA,MAAA,MAAA"}
|
|
@@ -81,4 +81,4 @@ declare function unref<T>(value: Ref<T> | T): T;
|
|
|
81
81
|
declare function toRefs<T extends Record<string, any>>(obj: T): { [K in keyof T]: Ref<T[K]> };
|
|
82
82
|
//#endregion
|
|
83
83
|
export { isRef as a, toRefs as c, computed as i, unref as l, Ref as n, reactive as o, WatchOptions as r, ref as s, ComputedRef as t, watch as u };
|
|
84
|
-
//# sourceMappingURL=reactivity-
|
|
84
|
+
//# sourceMappingURL=reactivity-CfJceo4H.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reactivity-
|
|
1
|
+
{"version":3,"file":"reactivity-CfJceo4H.d.mts","names":[],"sources":["../src/core/reactivity.ts"],"mappings":";;;AAuCA;;;;UAAiB,GAAA;EACf,KAAA,EAAO,CAAA;EAEgC;EAAvC,SAAA,CAAU,EAAA,GAAK,QAAA,EAAU,CAAA,EAAG,QAAA,EAAU,CAAA;AAAA;;;;;;;;;;;iBAaxB,GAAA,GAAA,CAAO,YAAA,EAAc,CAAA,GAAI,GAAA,CAAI,CAAA;AAAA,UA2B5B,WAAA;EAAA,SACN,KAAA,EAAO,CAAA;AAAA;;;;;;;;;;;;AADlB;iBAgBgB,QAAA,GAAA,CAAY,MAAA,QAAc,CAAA,GAAI,WAAA,CAAY,CAAA;AAAA,UA+BzC,YAAA;EA9CE;EAgDjB,SAAA;AAAA;AAAA,KAGG,WAAA,MAAiB,GAAA,CAAI,CAAA,IAAK,WAAA,CAAY,CAAA,WAAY,CAAA;;;AApCvD;;;;;;;;;;;;iBAoDgB,KAAA,GAAA,CACd,MAAA,EAAQ,WAAA,CAAY,CAAA,GACpB,QAAA,GAAW,QAAA,EAAU,CAAA,EAAG,QAAA,EAAU,CAAA,WAClC,OAAA,GAAU,YAAA;;;AAxBZ;;;;;AAGC;;;;;;;;iBAwEe,QAAA,WAAmB,MAAA,cAAA,CAAqB,MAAA,EAAQ,CAAA,GAAI,CAAA;;iBA0BpD,KAAA,CAAM,KAAA,QAAa,KAAA,IAAS,GAAA;;iBAK5B,KAAA,GAAA,CAAS,KAAA,EAAO,GAAA,CAAI,CAAA,IAAK,CAAA,GAAI,CAAA;;iBAK7B,MAAA,WAAiB,MAAA,cAAA,CAAqB,GAAA,EAAK,CAAA,iBAAkB,CAAA,GAAI,GAAA,CAAI,CAAA,CAAE,CAAA"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
|
|
2
|
+
import { NextFunction, Request, Response } from "express";
|
|
3
|
+
|
|
4
|
+
//#region src/http/middleware/request-id.d.ts
|
|
5
|
+
declare const REQUEST_ID_HEADER = "x-request-id";
|
|
6
|
+
/**
|
|
7
|
+
* Middleware that generates or propagates a unique request ID.
|
|
8
|
+
*
|
|
9
|
+
* Idempotent: if `req.requestId` is already set (e.g. by
|
|
10
|
+
* `requestScopeMiddleware` earlier in the pipeline), this middleware reuses
|
|
11
|
+
* it instead of generating a divergent second value. Keeps the
|
|
12
|
+
* X-Request-Id response header, the ALS store's `requestId`, and
|
|
13
|
+
* `RequestContext.requestId` in agreement for every request, regardless of
|
|
14
|
+
* mounting order.
|
|
15
|
+
*/
|
|
16
|
+
declare function requestId(): (req: Request, res: Response, next: NextFunction) => void;
|
|
17
|
+
//#endregion
|
|
18
|
+
export { requestId as n, REQUEST_ID_HEADER as t };
|
|
19
|
+
//# sourceMappingURL=request-id-BgglvZHN.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request-id-BgglvZHN.d.mts","names":[],"sources":["../src/http/middleware/request-id.ts"],"mappings":";;;;cAGa,iBAAA;;AAAb;;;;;AAYA;;;;iBAAgB,SAAA,CAAA,IACN,GAAA,EAAK,OAAA,EAAS,GAAA,EAAK,QAAA,EAAU,IAAA,EAAM,YAAA"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
|
|
2
|
+
import { NextFunction, Request, Response } from "express";
|
|
3
|
+
|
|
4
|
+
//#region src/http/middleware/request-logger.d.ts
|
|
5
|
+
interface RequestLoggerOptions {
|
|
6
|
+
/** Logger name (default: 'HTTP') */
|
|
7
|
+
name?: string;
|
|
8
|
+
/** Log level for successful requests (default: 'info') */
|
|
9
|
+
level?: 'info' | 'debug' | 'trace';
|
|
10
|
+
/** Skip logging for paths matching these prefixes (e.g. ['/health', '/_debug']) */
|
|
11
|
+
skip?: string[];
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Middleware that logs every request with method, URL, status, duration, and request ID.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* bootstrap({
|
|
19
|
+
* middleware: [requestId(), requestLogger(), express.json()],
|
|
20
|
+
* })
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* Output:
|
|
24
|
+
* ```
|
|
25
|
+
* [HTTP] GET /api/v1/users 200 12ms req-abc123
|
|
26
|
+
* [HTTP] POST /api/v1/users 201 45ms req-def456
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
declare function requestLogger(options?: RequestLoggerOptions): (req: Request, res: Response, next: NextFunction) => void;
|
|
30
|
+
//#endregion
|
|
31
|
+
export { requestLogger as n, RequestLoggerOptions as t };
|
|
32
|
+
//# sourceMappingURL=request-logger-CWHbAzTE.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request-logger-CWHbAzTE.d.mts","names":[],"sources":["../src/http/middleware/request-logger.ts"],"mappings":";;;;UAGiB,oBAAA;;EAEf,IAAA;EAFmC;EAInC,KAAA;EAJmC;EAMnC,IAAA;AAAA;;;;AAmBF;;;;;;;;;;;;;iBAAgB,aAAA,CAAc,OAAA,GAAS,oBAAA,IAK7B,GAAA,EAAK,OAAA,EAAS,GAAA,EAAK,QAAA,EAAU,IAAA,EAAM,YAAA"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
|
|
2
|
+
import { x as SourcedRegistration } from "./index-DQyWtyp0.mjs";
|
|
3
|
+
import { Router } from "express";
|
|
4
|
+
|
|
5
|
+
//#region src/http/router-builder.d.ts
|
|
6
|
+
/** @internal — set by Application.setup() before each `mod.routes()` call. */
|
|
7
|
+
declare function _setExternalContributorSources(sources: readonly SourcedRegistration[]): void;
|
|
8
|
+
interface BuildRoutesOptions {
|
|
9
|
+
/**
|
|
10
|
+
* Extra contributors to merge into the per-route pipeline at their declared
|
|
11
|
+
* precedence levels. Pass explicitly when calling buildRoutes outside the
|
|
12
|
+
* Application route-mount loop (typically in tests). When omitted, falls
|
|
13
|
+
* back to the slot set by Application.setup().
|
|
14
|
+
*/
|
|
15
|
+
externalSources?: readonly SourcedRegistration[];
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Build an Express Router from a controller class decorated with @Get, @Post, etc.
|
|
19
|
+
* Resolves the controller from the DI container, wraps handlers in RequestContext,
|
|
20
|
+
* and applies class-level and method-level middleware.
|
|
21
|
+
*
|
|
22
|
+
* Routes are registered using only the method-level decorator paths (e.g. @Get('/me') → '/me').
|
|
23
|
+
* The @Controller path is NOT baked into the router — it serves as metadata only
|
|
24
|
+
* (used by Swagger and other adapters for introspection).
|
|
25
|
+
* The module's routes().path is the single source of truth for the mount prefix,
|
|
26
|
+
* which avoids path doubling when both the module and controller specify the same path.
|
|
27
|
+
*/
|
|
28
|
+
declare function buildRoutes(controllerClass: any, options?: BuildRoutesOptions): Router;
|
|
29
|
+
//#endregion
|
|
30
|
+
export { _setExternalContributorSources as n, buildRoutes as r, BuildRoutesOptions as t };
|
|
31
|
+
//# sourceMappingURL=router-builder-C799BAf0.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"router-builder-C799BAf0.d.mts","names":[],"sources":["../src/http/router-builder.ts"],"mappings":";;;;;;iBAoCgB,8BAAA,CAA+B,OAAA,WAAkB,mBAAA;AAAA,UAIhD,kBAAA;EAJ6B;;;;AAI9C;;EAOE,eAAA,YAA2B,mBAAA;AAAA;;AAc7B;;;;;;;;;;iBAAgB,WAAA,CAAY,eAAA,OAAsB,OAAA,GAAS,kBAAA,GAA0B,MAAA"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
|
|
2
|
+
import { NextFunction, Request, Response } from "express";
|
|
3
|
+
|
|
4
|
+
//#region src/http/middleware/session.d.ts
|
|
5
|
+
interface SessionData {
|
|
6
|
+
[key: string]: unknown;
|
|
7
|
+
}
|
|
8
|
+
interface SessionStore {
|
|
9
|
+
get(sid: string): Promise<SessionData | null>;
|
|
10
|
+
set(sid: string, data: SessionData, maxAge: number): Promise<void>;
|
|
11
|
+
destroy(sid: string): Promise<void>;
|
|
12
|
+
touch?(sid: string, maxAge: number): Promise<void>;
|
|
13
|
+
}
|
|
14
|
+
interface Session {
|
|
15
|
+
id: string;
|
|
16
|
+
data: SessionData;
|
|
17
|
+
regenerate(): Promise<void>;
|
|
18
|
+
destroy(): Promise<void>;
|
|
19
|
+
save(): Promise<void>;
|
|
20
|
+
}
|
|
21
|
+
interface SessionOptions {
|
|
22
|
+
/** Secret used to sign the session cookie (required) */
|
|
23
|
+
secret: string;
|
|
24
|
+
/** Cookie name (default: 'kick.sid') */
|
|
25
|
+
cookieName?: string;
|
|
26
|
+
/** Session max age in milliseconds (default: 86400000 = 24h) */
|
|
27
|
+
maxAge?: number;
|
|
28
|
+
/** Reset maxAge on every response (default: false) */
|
|
29
|
+
rolling?: boolean;
|
|
30
|
+
/** Save new sessions that have not been modified (default: true) */
|
|
31
|
+
saveUninitialized?: boolean;
|
|
32
|
+
/** Cookie options */
|
|
33
|
+
cookie?: {
|
|
34
|
+
httpOnly?: boolean;
|
|
35
|
+
secure?: boolean;
|
|
36
|
+
sameSite?: 'strict' | 'lax' | 'none';
|
|
37
|
+
path?: string;
|
|
38
|
+
domain?: string;
|
|
39
|
+
};
|
|
40
|
+
/** Custom session store (default: in-memory store with TTL cleanup) */
|
|
41
|
+
store?: SessionStore;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Session management middleware.
|
|
45
|
+
*
|
|
46
|
+
* Attaches a `req.session` object with `id`, `data`, `regenerate()`,
|
|
47
|
+
* `destroy()`, and `save()` methods. Session IDs are signed with
|
|
48
|
+
* HMAC-SHA256 to prevent cookie tampering.
|
|
49
|
+
*
|
|
50
|
+
* Reads the session cookie from `req.cookies` when an upstream cookie
|
|
51
|
+
* parser is present; otherwise parses `req.headers.cookie` directly, so
|
|
52
|
+
* no cookie parser is required upstream.
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```ts
|
|
56
|
+
* import { session } from '@forinda/kickjs'
|
|
57
|
+
*
|
|
58
|
+
* bootstrap({
|
|
59
|
+
* modules,
|
|
60
|
+
* middleware: [
|
|
61
|
+
* session({ secret: process.env.SESSION_SECRET! }),
|
|
62
|
+
* // ... other middleware
|
|
63
|
+
* ],
|
|
64
|
+
* })
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
declare function session(options: SessionOptions): (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
68
|
+
//#endregion
|
|
69
|
+
export { session as a, SessionStore as i, SessionData as n, SessionOptions as r, Session as t };
|
|
70
|
+
//# sourceMappingURL=session-N0hActOO.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-N0hActOO.d.mts","names":[],"sources":["../src/http/middleware/session.ts"],"mappings":";;;;UAGiB,WAAA;EAAA,CACd,GAAA;AAAA;AAAA,UAGc,YAAA;EACf,GAAA,CAAI,GAAA,WAAc,OAAA,CAAQ,WAAA;EAC1B,GAAA,CAAI,GAAA,UAAa,IAAA,EAAM,WAAA,EAAa,MAAA,WAAiB,OAAA;EACrD,OAAA,CAAQ,GAAA,WAAc,OAAA;EACtB,KAAA,EAAO,GAAA,UAAa,MAAA,WAAiB,OAAA;AAAA;AAAA,UAGtB,OAAA;EACf,EAAA;EACA,IAAA,EAAM,WAAA;EACN,UAAA,IAAc,OAAA;EACd,OAAA,IAAW,OAAA;EACX,IAAA,IAAQ,OAAA;AAAA;AAAA,UAGO,cAAA;EAX6B;EAa5C,MAAA;EAhBI;EAkBJ,UAAA;EAlB0B;EAoB1B,MAAA;EAnBI;EAqBJ,OAAA;EArBiB;EAuBjB,iBAAA;EAvBqD;EAyBrD,MAAA;IACE,QAAA;IACA,MAAA;IACA,QAAA;IACA,IAAA;IACA,MAAA;EAAA;EA5B0C;EA+B5C,KAAA,GAAQ,YAAA;AAAA;;;;;;;;;;;;;;;;;;;;AApBV;;;;;iBAiJgB,OAAA,CAAQ,OAAA,EAAS,cAAA,IAoBjB,GAAA,EAAK,OAAA,EAAS,GAAA,EAAK,QAAA,EAAU,IAAA,EAAM,YAAA,KAAY,OAAA"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
|
|
2
|
+
import { r as AppAdapter, t as AdapterContext } from "./adapter-BNw2pGbg.mjs";
|
|
3
|
+
//#region src/http/middleware/spa.d.ts
|
|
4
|
+
interface SpaAdapterOptions {
|
|
5
|
+
/**
|
|
6
|
+
* Directory containing the built SPA files (index.html, assets, etc.)
|
|
7
|
+
* Default: 'dist/client'
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* // Vue: 'dist'
|
|
12
|
+
* // React (Vite): 'dist'
|
|
13
|
+
* // React (CRA): 'build'
|
|
14
|
+
* // Svelte: 'build'
|
|
15
|
+
* // Angular: 'dist/my-app/browser'
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
clientDir?: string;
|
|
19
|
+
/**
|
|
20
|
+
* URL prefix for API routes. SPA fallback only applies to
|
|
21
|
+
* non-API routes (routes NOT starting with this prefix).
|
|
22
|
+
* Default: '/api'
|
|
23
|
+
*
|
|
24
|
+
* Set to an array for multiple prefixes:
|
|
25
|
+
* ```ts
|
|
26
|
+
* apiPrefix: ['/api', '/graphql', '/_debug']
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
apiPrefix?: string | string[];
|
|
30
|
+
/**
|
|
31
|
+
* Additional paths to exclude from SPA fallback.
|
|
32
|
+
* These paths will NOT serve index.html.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```ts
|
|
36
|
+
* exclude: ['/health', '/metrics', '/ws']
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
exclude?: string[];
|
|
40
|
+
/**
|
|
41
|
+
* Cache-Control header for static assets (default: 'public, max-age=31536000, immutable')
|
|
42
|
+
* Set to false to disable caching headers.
|
|
43
|
+
*/
|
|
44
|
+
cacheControl?: string | false;
|
|
45
|
+
/**
|
|
46
|
+
* Cache-Control for index.html (default: 'no-cache')
|
|
47
|
+
* index.html should not be cached to ensure clients get fresh builds.
|
|
48
|
+
*/
|
|
49
|
+
indexCacheControl?: string;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* SPA adapter — serve a Vue, React, Svelte, or Angular build alongside
|
|
53
|
+
* your KickJS API. API routes are handled by controllers; everything else
|
|
54
|
+
* falls back to index.html for client-side routing.
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```ts
|
|
58
|
+
* import { SpaAdapter } from '@forinda/kickjs/spa'
|
|
59
|
+
*
|
|
60
|
+
* bootstrap({
|
|
61
|
+
* modules,
|
|
62
|
+
* adapters: [
|
|
63
|
+
* new SpaAdapter({
|
|
64
|
+
* clientDir: 'dist/client', // or 'build', 'dist', etc.
|
|
65
|
+
* apiPrefix: '/api',
|
|
66
|
+
* }),
|
|
67
|
+
* ],
|
|
68
|
+
* })
|
|
69
|
+
* ```
|
|
70
|
+
*
|
|
71
|
+
* File structure:
|
|
72
|
+
* ```
|
|
73
|
+
* dist/
|
|
74
|
+
* client/ ← SPA build output
|
|
75
|
+
* index.html
|
|
76
|
+
* assets/
|
|
77
|
+
* app.js
|
|
78
|
+
* style.css
|
|
79
|
+
* server/ ← KickJS server
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
declare class SpaAdapter implements AppAdapter {
|
|
83
|
+
private options;
|
|
84
|
+
name: string;
|
|
85
|
+
private clientDir;
|
|
86
|
+
private apiPrefixes;
|
|
87
|
+
private excludePaths;
|
|
88
|
+
private cacheControl;
|
|
89
|
+
private indexCacheControl;
|
|
90
|
+
private indexHtml;
|
|
91
|
+
constructor(options?: SpaAdapterOptions);
|
|
92
|
+
beforeMount({
|
|
93
|
+
app
|
|
94
|
+
}: AdapterContext): void;
|
|
95
|
+
beforeStart({
|
|
96
|
+
app
|
|
97
|
+
}: AdapterContext): void;
|
|
98
|
+
}
|
|
99
|
+
//#endregion
|
|
100
|
+
export { SpaAdapterOptions as n, SpaAdapter as t };
|
|
101
|
+
//# sourceMappingURL=spa-CrFR2_cz.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spa-CrFR2_cz.d.mts","names":[],"sources":["../src/http/middleware/spa.ts"],"mappings":";;;UAMiB,iBAAA;;;AAAjB;;;;;;;;;;;EAcE,SAAA;EAqEsB;;;;;;;;;;EAzDtB,SAAA;EAkEoB;;;;;;;;;EAvDpB,OAAA;EAuDoB;;;;EAjDpB,YAAA;EAoGA;;;;EA9FA,iBAAA;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAkCW,UAAA,YAAsB,UAAA;EAAA,QASb,OAAA;EARpB,IAAA;EAAA,QACQ,SAAA;EAAA,QACA,WAAA;EAAA,QACA,YAAA;EAAA,QACA,YAAA;EAAA,QACA,iBAAA;EAAA,QACA,SAAA;cAEY,OAAA,GAAS,iBAAA;EAU7B,WAAA,CAAA;IAAc;EAAA,GAAO,cAAA;EAyCrB,WAAA,CAAA;IAAc;EAAA,GAAO,cAAA;AAAA"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
|
|
2
|
+
import { g as FileUploadConfig, o as BaseUploadOptions } from "./decorators-BMvaLliz.mjs";
|
|
3
|
+
import { NextFunction, Request, RequestHandler, Response } from "express";
|
|
4
|
+
import { Options } from "multer";
|
|
5
|
+
|
|
6
|
+
//#region src/http/middleware/upload.d.ts
|
|
7
|
+
/**
|
|
8
|
+
* Resolves a list of file type identifiers to MIME type strings.
|
|
9
|
+
* Accepts short extensions (`'jpg'`, `'pdf'`) or full MIME types (`'image/jpeg'`).
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* resolveMimeTypes(['jpg', 'png', 'application/pdf'])
|
|
14
|
+
* // → ['image/jpeg', 'image/png', 'application/pdf']
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
declare function resolveMimeTypes(types: string[]): string[];
|
|
18
|
+
/**
|
|
19
|
+
* Upload options for the middleware.
|
|
20
|
+
* Extends BaseUploadOptions from core (shared with @FileUpload decorator)
|
|
21
|
+
* and adds Multer-specific storage options.
|
|
22
|
+
*/
|
|
23
|
+
interface UploadOptions extends BaseUploadOptions {
|
|
24
|
+
/** Multer storage config (default: memory storage) */
|
|
25
|
+
storage?: Options['storage'];
|
|
26
|
+
/** Multer dest for disk storage shorthand */
|
|
27
|
+
dest?: string;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Single file upload middleware. Attaches the file to `req.file`.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```ts
|
|
34
|
+
* @Post('/avatar')
|
|
35
|
+
* @Middleware(upload.single('avatar', { maxSize: 2 * 1024 * 1024, allowedTypes: ['jpg', 'png'] }))
|
|
36
|
+
* async uploadAvatar(ctx: RequestContext) {
|
|
37
|
+
* ctx.json({ filename: ctx.file.originalname })
|
|
38
|
+
* }
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
declare function single(fieldName: string, options?: UploadOptions): RequestHandler;
|
|
42
|
+
/**
|
|
43
|
+
* Multiple file upload middleware. Attaches files to `req.files`.
|
|
44
|
+
*/
|
|
45
|
+
declare function array(fieldName: string, maxCount?: number, options?: UploadOptions): RequestHandler;
|
|
46
|
+
/**
|
|
47
|
+
* No file upload — just parse multipart form data without file fields.
|
|
48
|
+
*/
|
|
49
|
+
declare function none(options?: UploadOptions): RequestHandler;
|
|
50
|
+
/**
|
|
51
|
+
* Removes temporary files from disk after the response is sent.
|
|
52
|
+
* Attach this as Express middleware after the upload middleware.
|
|
53
|
+
* Works with both `req.file` (single) and `req.files` (array).
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```ts
|
|
57
|
+
* @Post('/process')
|
|
58
|
+
* @Middleware(upload.single('document', { dest: '/tmp/uploads' }), cleanupFiles())
|
|
59
|
+
* async processDocument(ctx: RequestContext) {
|
|
60
|
+
* ctx.json({ ok: true })
|
|
61
|
+
* }
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
declare function cleanupFiles(): (req: Request, res: Response, next: NextFunction) => void;
|
|
65
|
+
/**
|
|
66
|
+
* Build upload middleware from a @FileUpload decorator config.
|
|
67
|
+
* Used internally by the router builder when it detects FILE_UPLOAD metadata.
|
|
68
|
+
* Accepts the same FileUploadConfig interface used by the @FileUpload decorator.
|
|
69
|
+
*/
|
|
70
|
+
declare function buildUploadMiddleware(config: FileUploadConfig): RequestHandler;
|
|
71
|
+
/** Upload middleware factory with `.single()`, `.array()`, `.none()` methods */
|
|
72
|
+
declare const upload: {
|
|
73
|
+
single: typeof single;
|
|
74
|
+
array: typeof array;
|
|
75
|
+
none: typeof none;
|
|
76
|
+
};
|
|
77
|
+
//#endregion
|
|
78
|
+
export { upload as a, resolveMimeTypes as i, buildUploadMiddleware as n, cleanupFiles as r, UploadOptions as t };
|
|
79
|
+
//# sourceMappingURL=upload-BueOnnLw.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"upload-BueOnnLw.d.mts","names":[],"sources":["../src/http/middleware/upload.ts"],"mappings":";;;;;;;;;AAsEA;;;;;AAYA;;iBAZgB,gBAAA,CAAiB,KAAA;;;;;;UAYhB,aAAA,SAAsB,iBAAA;EAIjC;EAFJ,OAAA,GAAU,OAAA;EAmEG;EAjEb,IAAA;AAAA;;;;;;;AAiE6E;;;;;;iBAAtE,MAAA,CAAO,SAAA,UAAmB,OAAA,GAAS,aAAA,GAAqB,cAAA;;;;iBAQxD,KAAA,CAAM,SAAA,UAAmB,QAAA,WAAe,OAAA,GAAS,aAAA,GAAqB,cAAA;AAAc;;;AAAA,iBAQpF,IAAA,CAAK,OAAA,GAAS,aAAA,GAAqB,cAAA;;;;;;AAmB5C;;;;;;;;;iBAAgB,YAAA,CAAA,IACN,GAAA,EAAK,OAAA,EAAS,GAAA,EAAK,QAAA,EAAU,IAAA,EAAM,YAAA;;;;;;iBA+B7B,qBAAA,CAAsB,MAAA,EAAQ,gBAAA,GAAmB,cAAA;AAAjE;AAAA,cAmBa,MAAA"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
|
|
2
|
+
import { NextFunction, Request, Response } from "express";
|
|
3
|
+
|
|
4
|
+
//#region src/http/middleware/validate.d.ts
|
|
5
|
+
interface ValidationSchema {
|
|
6
|
+
body?: any;
|
|
7
|
+
query?: any;
|
|
8
|
+
params?: any;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Express middleware that validates request body/query/params against schemas.
|
|
12
|
+
* Works with any validation library that exposes `.safeParse(data)` returning
|
|
13
|
+
* `{ success: true, data }` or `{ success: false, error: { issues } }`.
|
|
14
|
+
*
|
|
15
|
+
* Validation failures are forwarded via `next(err)` as an `HttpException`, so
|
|
16
|
+
* they flow through the application's global error handler (`onError`) and
|
|
17
|
+
* produce a uniform response envelope. Apps that keep the built-in handler
|
|
18
|
+
* continue to see the same `{ message, errors: [{ field, message }] }` body.
|
|
19
|
+
*/
|
|
20
|
+
declare function validate(schema: ValidationSchema): (req: Request, _res: Response, next: NextFunction) => void;
|
|
21
|
+
//#endregion
|
|
22
|
+
export { validate as n, ValidationSchema as t };
|
|
23
|
+
//# sourceMappingURL=validate-HwAyWTwH.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate-HwAyWTwH.d.mts","names":[],"sources":["../src/http/middleware/validate.ts"],"mappings":";;;;UAGiB,gBAAA;EACf,IAAA;EACA,KAAA;EACA,MAAA;AAAA;;;;;;;AA8CF;;;;iBAAgB,QAAA,CAAS,MAAA,EAAQ,gBAAA,IACvB,GAAA,EAAK,OAAA,EAAS,IAAA,EAAM,QAAA,EAAU,IAAA,EAAM,YAAA"}
|