@turystack/exceptions 1.0.2 → 1.0.3

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.
@@ -1 +1 @@
1
- {"version":3,"file":"error-handling.js","sourceRoot":"","sources":["../../src/error-handling/error-handling.ts"],"names":[],"mappings":"AACA,MAAM,OAAO,QAAS,SAAQ,KAAK;IAClB,UAAU,CAAQ;IAClB,IAAI,CAAQ;IACZ,QAAQ,CAA0B;IAElD,YACC,OAAe,EACf,UAAkB,EAClB,IAAY,EACZ,QAAkC;QAElC,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,UAAU,GAAG,UAAU,CAAA;QAC5B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;QACxB,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,IAAI,MAAM,CAAC,SAAS,CAAC,CAAA;IAClD,CAAC;CACD;AAED,MAAM,OAAO,eAAgB,SAAQ,QAAQ;IAC5C,YAAY,OAAe,EAAE,QAAkC;QAC9D,KAAK,CAAC,OAAO,EAAE,GAAG,EAAE,aAAa,EAAE,QAAQ,CAAC,CAAA;IAC7C,CAAC;CACD;AAED,MAAM,OAAO,eAAgB,SAAQ,QAAQ;IAC5C,YAAY,OAAe,EAAE,QAAkC;QAC9D,KAAK,CAAC,OAAO,EAAE,GAAG,EAAE,kBAAkB,EAAE,QAAQ,CAAC,CAAA;IAClD,CAAC;CACD;AAED,MAAM,OAAO,iBAAkB,SAAQ,QAAQ;IAC9C,YAAY,OAAe,EAAE,QAAkC;QAC9D,KAAK,CAAC,OAAO,EAAE,GAAG,EAAE,cAAc,EAAE,QAAQ,CAAC,CAAA;IAC9C,CAAC;CACD;AAED,MAAM,OAAO,cAAe,SAAQ,QAAQ;IAC3C,YAAY,OAAe,EAAE,QAAkC;QAC9D,KAAK,CAAC,OAAO,EAAE,GAAG,EAAE,WAAW,EAAE,QAA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C,OAAO,KAAK,YAAY,QAAQ,CAAA;AACjC,CAAC","sourcesContent":["/** Base class for HTTP-mappable application errors. */\nexport class AppError extends Error {\n\tpublic readonly statusCode: number\n\tpublic readonly code: string\n\tpublic readonly metadata?: Record<string, unknown>\n\n\tconstructor(\n\t\tmessage: string,\n\t\tstatusCode: number,\n\t\tcode: string,\n\t\tmetadata?: Record<string, unknown>,\n\t) {\n\t\tsuper(message)\n\t\tthis.statusCode = statusCode\n\t\tthis.code = code\n\t\tthis.metadata = metadata\n\t\tObject.setPrototypeOf(this, new.target.prototype)\n\t}\n}\n\nexport class BadRequestError extends AppError {\n\tconstructor(message: string, metadata?: Record<string, unknown>) {\n\t\tsuper(message, 400, 'BAD_REQUEST', metadata)\n\t}\n}\n\nexport class ValidationError extends AppError {\n\tconstructor(message: string, metadata?: Record<string, unknown>) {\n\t\tsuper(message, 400, 'VALIDATION_ERROR', metadata)\n\t}\n}\n\nexport class UnauthorizedError extends AppError {\n\tconstructor(message: string, metadata?: Record<string, unknown>) {\n\t\tsuper(message, 401, 'UNAUTHORIZED', metadata)\n\t}\n}\n\nexport class ForbiddenError extends AppError {\n\tconstructor(message: string, metadata?: Record<string, unknown>) {\n\t\tsuper(message, 403, 'FORBIDDEN', metadata)\n\t}\n}\n\nexport class NotFoundError extends AppError {\n\tconstructor(message: string, metadata?: Record<string, unknown>) {\n\t\tsuper(message, 404, 'NOT_FOUND', metadata)\n\t}\n}\n\nexport class MethodNotAllowedError extends AppError {\n\tconstructor(message: string, metadata?: Record<string, unknown>) {\n\t\tsuper(message, 405, 'METHOD_NOT_ALLOWED', metadata)\n\t}\n}\n\nexport class ConflictError extends AppError {\n\tconstructor(message: string, metadata?: Record<string, unknown>) {\n\t\tsuper(message, 409, 'CONFLICT', metadata)\n\t}\n}\n\nexport class ConcurrentUpdateError extends AppError {\n\tconstructor(message: string, metadata?: Record<string, unknown>) {\n\t\tsuper(message, 409, 'CONCURRENT_UPDATE', metadata)\n\t}\n}\n\nexport class GoneError extends AppError {\n\tconstructor(message: string, metadata?: Record<string, unknown>) {\n\t\tsuper(message, 410, 'GONE', metadata)\n\t}\n}\n\nexport class UnprocessableEntityError extends AppError {\n\tconstructor(message: string, metadata?: Record<string, unknown>) {\n\t\tsuper(message, 422, 'UNPROCESSABLE_ENTITY', metadata)\n\t}\n}\n\nexport class TooManyRequestsError extends AppError {\n\tconstructor(message: string, metadata?: Record<string, unknown>) {\n\t\tsuper(message, 429, 'TOO_MANY_REQUESTS', metadata)\n\t}\n}\n\nexport class InternalServerError extends AppError {\n\tconstructor(\n\t\tmessage = 'Internal server error',\n\t\tmetadata?: Record<string, unknown>,\n\t) {\n\t\tsuper(message, 500, 'INTERNAL_SERVER_ERROR', metadata)\n\t}\n}\n\nexport class BadGatewayError extends AppError {\n\tconstructor(message: string, metadata?: Record<string, unknown>) {\n\t\tsuper(message, 502, 'BAD_GATEWAY', metadata)\n\t}\n}\n\nexport class ServiceUnavailableError extends AppError {\n\tconstructor(message: string, metadata?: Record<string, unknown>) {\n\t\tsuper(message, 503, 'SERVICE_UNAVAILABLE', metadata)\n\t}\n}\n\nexport class GatewayTimeoutError extends AppError {\n\tconstructor(message: string, metadata?: Record<string, unknown>) {\n\t\tsuper(message, 504, 'GATEWAY_TIMEOUT', metadata)\n\t}\n}\n\nexport function isAppError(error: unknown): error is AppError {\n\treturn error instanceof AppError\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/error-handling/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/error-handling/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAA","sourcesContent":["export * from './error-handling.js'\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"exceptions.js","sourceRoot":"","sources":["../../src/exceptions/exceptions.ts"],"names":[],"mappings":"AAOA,OAAO,EAEN,eAAe,EACf,eAAe,EACf,aAAa,EACb,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B,CAAC,GAAG,MAAM,YAAY,EAAE,aAAa,CAAC;aAClE,CAAA;YAED,KAAK,MAAM,CAAC,SAAS,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAGnD,EAAE,CAAC;gBACL,KAAK,MAAM,IAAI,IAAI,KAAK,IAAI,EAAE,EAAE,CAAC;oBAChC,gBAAgB,CAAC,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,eAAe,CAAC,SAAS,CAAC,CAAC,CAAA;gBACvE,CAAC;YACF,CAAC;YAED,OAAO,UAA0C,CAAA;QAClD,CAAC;KACD,CAAA;IAED,OAAO,OAAO,CAAC,OAAO,CAAC,CAAA;AACxB,CAAC","sourcesContent":["import type {\n\tExceptionBuilder,\n\tExceptionClass,\n\tExceptionGroup,\n\tExceptionGroupedModule,\n} from './exceptions.types.js'\n\nimport {\n\ttype AppError,\n\tBadGatewayError,\n\tBadRequestError,\n\tConflictError,\n\tForbiddenError,\n\tGatewayTimeoutError,\n\tGoneError,\n\tInternalServerError,\n\tMethodNotAllowedError,\n\tNotFoundError,\n\tServiceUnavailableError,\n\tTooManyRequestsError,\n\tUnauthorizedError,\n\tUnprocessableEntityError,\n} from '@/error-handling/index.js'\n\ntype ExceptionBase = new (\n\tmessage: string,\n\tmetadata?: Record<string, unknown>,\n) => AppError\n\nfunction makeExceptionClass<C extends string>(\n\tcode: C,\n\tBase: ExceptionBase,\n): ExceptionClass<C> {\n\tconst Exception = class extends Base {\n\t\tstatic readonly code = code\n\n\t\tconstructor(metadata?: Record<string, unknown>) {\n\t\t\tsuper(code, metadata)\n\t\t}\n\t}\n\n\tObject.defineProperty(Exception, Symbol.toPrimitive, {\n\t\tvalue: () => code,\n\t})\n\tObject.defineProperty(Exception, 'toString', {\n\t\tvalue: () => code,\n\t})\n\n\treturn Exception as unknown as ExceptionClass<C>\n}\n\nfunction snakeToCamel(input: string): string {\n\treturn input.replace(/_([a-z0-9])/g, (_, character: string) =>\n\t\tcharacter.toUpperCase(),\n\t)\n}\n\nconst groupBaseByName = {\n\tbadGateway: BadGatewayError,\n\tbadRequest: BadRequestError,\n\tconflict: ConflictError,\n\tforbidden: ForbiddenError,\n\tgatewayTimeout: GatewayTimeoutError,\n\tgone: GoneError,\n\tinternalServerError: InternalServerError,\n\tmethodNotAllowed: MethodNotAllowedError,\n\tnotFound: NotFoundError,\n\tserviceUnavailable: ServiceUnavailableError,\n\ttooManyRequests: TooManyRequestsError,\n\tunauthorized: UnauthorizedError,\n\tunprocessableEntity: UnprocessableEntityError,\n} satisfies Record<keyof ExceptionGroup, ExceptionBase>\n\nfunction addExceptionCode(\n\texceptions: Record<string, ExceptionClass>,\n\tprefix: string,\n\tcode: string,\n\tBase: ExceptionBase,\n): void {\n\texceptions[snakeToCamel(code)] = makeExceptionClass(`${prefix}.${code}`, Base)\n}\n\n/**\n * Builds a module's typed exception classes from a declarative group definition.\n *\n * The factory receives a builder whose `module(prefix, groups)` maps each\n * snake_case code (grouped by HTTP category) to an {@link AppError} subclass\n * keyed by its camelCase name. A `notFound` exception is always included.\n * Each generated class exposes a static `code` (`\"<prefix>.<code>\"`) and\n * coerces to that code via `toString`/`Symbol.toPrimitive`.\n *\n * @example\n * ```ts\n * const OrderExceptions = createExceptions((e) => ({\n * order: e.module('order', {\n * conflict: ['already_paid'],\n * unprocessableEntity: ['empty_cart'],\n * }),\n * }))\n *\n * throw new OrderExceptions.order.alreadyPaid({ id })\n * ```\n */\nexport function createExceptions<T>(factory: (e: ExceptionBuilder) => T): T {\n\tconst builder: ExceptionBuilder = {\n\t\tmodule<P extends string, const C extends ExceptionGroup>(\n\t\t\tprefix: P,\n\t\t\tgroups: C,\n\t\t): ExceptionGroupedModule<P, C> {\n\t\t\tconst exceptions: Record<string, ExceptionClass> = {\n\t\t\t\tnotFound: makeExceptionClass(`${prefix}.not_found`, NotFoundError),\n\t\t\t}\n\n\t\t\tfor (const [groupName, codes] of Object.entries(groups) as [\n\t\t\t\tkeyof ExceptionGroup,\n\t\t\t\treadonly string[] | undefined,\n\t\t\t][]) {\n\t\t\t\tfor (const code of codes ?? []) {\n\t\t\t\t\taddExceptionCode(exceptions, prefix, code, groupBaseByName[groupName])\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn exceptions as ExceptionGroupedModule<P, C>\n\t\t},\n\t}\n\n\treturn factory(builder)\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"exceptions.types.js","sourceRoot":"","sources":["../../src/exceptions/exceptions.types.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"exceptions.types.js","sourceRoot":"","sources":["../../src/exceptions/exceptions.types.ts"],"names":[],"mappings":"","sourcesContent":["import type { AppError } from '@/error-handling/index.js'\n\n/** Declarative map of HTTP error categories to their snake_case codes. */\nexport type ExceptionGroup = {\n\tbadRequest?: readonly string[]\n\tnotFound?: readonly string[]\n\tunauthorized?: readonly string[]\n\tforbidden?: readonly string[]\n\tmethodNotAllowed?: readonly string[]\n\tconflict?: readonly string[]\n\tgone?: readonly string[]\n\tunprocessableEntity?: readonly string[]\n\ttooManyRequests?: readonly string[]\n\tinternalServerError?: readonly string[]\n\tbadGateway?: readonly string[]\n\tserviceUnavailable?: readonly string[]\n\tgatewayTimeout?: readonly string[]\n}\n\ntype GroupCodeUnion<T extends ExceptionGroup> = {\n\t[K in keyof T]: T[K] extends readonly (infer Code)[] ? Code : never\n}[keyof T] &\n\tstring\n\n/** Constructor for a generated exception, carrying a static literal code. */\nexport type ExceptionClass<C extends string = string> = (new (\n\tmetadata?: Record<string, unknown>,\n) => AppError) & {\n\treadonly code: C\n}\n\ntype CamelCaseKey<S extends string> = S extends `${infer Head}_${infer Tail}`\n\t? `${Head}${Capitalize<CamelCaseKey<Tail>>}`\n\t: S\n\nexport type NotFoundMetadata = Record<string, unknown>\n\n/** The always-present `<prefix>.not_found` exception. */\nexport type NotFoundExceptionClass<P extends string> = (new (\n\tmetadata: NotFoundMetadata,\n) => AppError) & {\n\treadonly code: `${P}.not_found`\n}\n\n/** A camelCase-keyed record of generated exception classes. */\nexport type ExceptionGroupedModule<\n\tP extends string,\n\tT extends ExceptionGroup,\n> = {\n\tnotFound: NotFoundExceptionClass<P>\n} & {\n\t[K in GroupCodeUnion<T> as CamelCaseKey<K>]: ExceptionClass<`${P}.${K}`>\n}\n\nexport type ExceptionBuilder = {\n\tmodule<P extends string, const T extends ExceptionGroup>(\n\t\tprefix: P,\n\t\tgroups: T,\n\t): ExceptionGroupedModule<P, T>\n}\n\n/** Extracts the union of all generated literal exception codes. */\nexport type InferCreateExceptions<T> = {\n\t[K in keyof T]: T[K] extends ExceptionClass<infer C>\n\t\t? C\n\t\t: T[K] extends NotFoundExceptionClass<infer P>\n\t\t\t? `${P}.not_found`\n\t\t\t: never\n}[keyof T]\n\n/**\n * Extracts the union of every literal exception code across a whole catalog\n * (a record of modules built with {@link createExceptions}). Use it to declare\n * the API's `Exceptions` type and to augment typed consumers:\n *\n * @example\n * ```ts\n * export type Exceptions = InferExceptionCodes<typeof exceptions>\n * // 'order.not_found' | 'order.already_paid' | 'user.not_found' | ...\n * ```\n */\nexport type InferExceptionCodes<T> = {\n\t[M in keyof T]: InferCreateExceptions<T[M]>\n}[keyof T]\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/exceptions/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/exceptions/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAA","sourcesContent":["export * from './exceptions.js'\nexport type * from './exceptions.types.js'\n"]}
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAA;AACzC,cAAc,uBAAuB,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAA;AACzC,cAAc,uBAAuB,CAAA","sourcesContent":["export * from '@/error-handling/index.js'\nexport * from '@/exceptions/index.js'\n"]}
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@turystack/exceptions",
3
3
  "description": "Type-safe HTTP-semantic application exception classes with stable domain codes and metadata.",
4
4
  "private": false,
5
- "version": "1.0.2",
5
+ "version": "1.0.3",
6
6
  "type": "module",
7
7
  "sideEffects": false,
8
8
  "main": "./dist/index.js",