@nwire/errors 0.8.17 → 0.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/errors.d.ts CHANGED
@@ -1,31 +1,36 @@
1
1
  /**
2
2
  * `@nwire/errors` — typed domain errors.
3
3
  *
4
- * NotFoundError / ValidationError / ConflictError / ForbiddenError /
5
- * UnauthorizedError. Every Nwire transport recognizes these and maps them to
6
- * the right status code / error envelope. Use `instanceof` checks in
7
- * middleware instead of string comparisons.
4
+ * The canonical error definitions now live in `@nwire/handler` as
5
+ * `defineError(...)` singletons (`Unauthorized`, `Forbidden`, `NotFound`,
6
+ * `Conflict`, `Gone`, `BadRequest`). Transports detect them via
7
+ * `instanceof NwireError`.
8
8
  *
9
- * See: architecture-sketch.html §05 (Foundation tier).
9
+ * The class-shaped errors below extend `NwireError` so transports
10
+ * recognize them as the same kind. They are retained for compatibility
11
+ * with code written against `new NotFoundError(...)` style; new code
12
+ * should import the singletons from `@nwire/handler`.
10
13
  */
11
- export declare class NotFoundError extends Error {
12
- readonly code = "NOT_FOUND";
14
+ import { NwireError } from "@nwire/handler";
15
+ export { defineError, NwireError, isNwireError, Unauthorized, Forbidden, NotFound, Conflict, Gone, BadRequest, } from "@nwire/handler";
16
+ /** @deprecated Use `NotFound({ resource, id })` from `@nwire/handler`. */
17
+ export declare class NotFoundError extends NwireError {
13
18
  constructor(entity: string, id?: string);
14
19
  }
15
- export declare class ValidationError extends Error {
16
- readonly code = "VALIDATION_ERROR";
20
+ /** @deprecated Use `defineError({ code: "VALIDATION_ERROR", status: 422, summary })` from `@nwire/handler`. */
21
+ export declare class ValidationError extends NwireError {
17
22
  constructor(message: string);
18
23
  }
19
- export declare class ConflictError extends Error {
20
- readonly code = "CONFLICT";
24
+ /** @deprecated Use `Conflict({ ... })` from `@nwire/handler`. */
25
+ export declare class ConflictError extends NwireError {
21
26
  constructor(message: string);
22
27
  }
23
- export declare class ForbiddenError extends Error {
24
- readonly code = "FORBIDDEN";
28
+ /** @deprecated Use `Forbidden({ ... })` from `@nwire/handler`. */
29
+ export declare class ForbiddenError extends NwireError {
25
30
  constructor(message: string);
26
31
  }
27
- export declare class UnauthorizedError extends Error {
28
- readonly code = "UNAUTHORIZED";
32
+ /** @deprecated Use `Unauthorized({ ... })` from `@nwire/handler`. */
33
+ export declare class UnauthorizedError extends NwireError {
29
34
  constructor(message: string);
30
35
  }
31
36
  //# sourceMappingURL=errors.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,qBAAa,aAAc,SAAQ,KAAK;IACtC,QAAQ,CAAC,IAAI,eAAe;gBAChB,MAAM,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,MAAM;CAIxC;AAED,qBAAa,eAAgB,SAAQ,KAAK;IACxC,QAAQ,CAAC,IAAI,sBAAsB;gBACvB,OAAO,EAAE,MAAM;CAI5B;AAED,qBAAa,aAAc,SAAQ,KAAK;IACtC,QAAQ,CAAC,IAAI,cAAc;gBACf,OAAO,EAAE,MAAM;CAI5B;AAED,qBAAa,cAAe,SAAQ,KAAK;IACvC,QAAQ,CAAC,IAAI,eAAe;gBAChB,OAAO,EAAE,MAAM;CAI5B;AAED,qBAAa,iBAAkB,SAAQ,KAAK;IAC1C,QAAQ,CAAC,IAAI,kBAAkB;gBACnB,OAAO,EAAE,MAAM;CAI5B"}
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAE5C,OAAO,EACL,WAAW,EACX,UAAU,EACV,YAAY,EACZ,YAAY,EACZ,SAAS,EACT,QAAQ,EACR,QAAQ,EACR,IAAI,EACJ,UAAU,GACX,MAAM,gBAAgB,CAAC;AAExB,0EAA0E;AAC1E,qBAAa,aAAc,SAAQ,UAAU;gBAC/B,MAAM,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,MAAM;CAWxC;AAED,+GAA+G;AAC/G,qBAAa,eAAgB,SAAQ,UAAU;gBACjC,OAAO,EAAE,MAAM;CAI5B;AAED,iEAAiE;AACjE,qBAAa,aAAc,SAAQ,UAAU;gBAC/B,OAAO,EAAE,MAAM;CAI5B;AAED,kEAAkE;AAClE,qBAAa,cAAe,SAAQ,UAAU;gBAChC,OAAO,EAAE,MAAM;CAI5B;AAED,qEAAqE;AACrE,qBAAa,iBAAkB,SAAQ,UAAU;gBACnC,OAAO,EAAE,MAAM;CAI5B"}
package/dist/errors.js CHANGED
@@ -1,45 +1,54 @@
1
1
  /**
2
2
  * `@nwire/errors` — typed domain errors.
3
3
  *
4
- * NotFoundError / ValidationError / ConflictError / ForbiddenError /
5
- * UnauthorizedError. Every Nwire transport recognizes these and maps them to
6
- * the right status code / error envelope. Use `instanceof` checks in
7
- * middleware instead of string comparisons.
4
+ * The canonical error definitions now live in `@nwire/handler` as
5
+ * `defineError(...)` singletons (`Unauthorized`, `Forbidden`, `NotFound`,
6
+ * `Conflict`, `Gone`, `BadRequest`). Transports detect them via
7
+ * `instanceof NwireError`.
8
8
  *
9
- * See: architecture-sketch.html §05 (Foundation tier).
9
+ * The class-shaped errors below extend `NwireError` so transports
10
+ * recognize them as the same kind. They are retained for compatibility
11
+ * with code written against `new NotFoundError(...)` style; new code
12
+ * should import the singletons from `@nwire/handler`.
10
13
  */
11
- export class NotFoundError extends Error {
12
- code = "NOT_FOUND";
14
+ import { NwireError } from "@nwire/handler";
15
+ export { defineError, NwireError, isNwireError, Unauthorized, Forbidden, NotFound, Conflict, Gone, BadRequest, } from "@nwire/handler";
16
+ /** @deprecated Use `NotFound({ resource, id })` from `@nwire/handler`. */
17
+ export class NotFoundError extends NwireError {
13
18
  constructor(entity, id) {
14
- super(id ? `${entity} not found: ${id}` : `${entity} not found`);
19
+ super({
20
+ code: "NOT_FOUND",
21
+ status: 404,
22
+ summary: id ? `${entity} not found: ${id}` : `${entity} not found`,
23
+ }, id ? { entity, id } : { entity });
15
24
  this.name = "NotFoundError";
16
25
  }
17
26
  }
18
- export class ValidationError extends Error {
19
- code = "VALIDATION_ERROR";
27
+ /** @deprecated Use `defineError({ code: "VALIDATION_ERROR", status: 422, summary })` from `@nwire/handler`. */
28
+ export class ValidationError extends NwireError {
20
29
  constructor(message) {
21
- super(message);
30
+ super({ code: "VALIDATION_ERROR", status: 422, summary: message });
22
31
  this.name = "ValidationError";
23
32
  }
24
33
  }
25
- export class ConflictError extends Error {
26
- code = "CONFLICT";
34
+ /** @deprecated Use `Conflict({ ... })` from `@nwire/handler`. */
35
+ export class ConflictError extends NwireError {
27
36
  constructor(message) {
28
- super(message);
37
+ super({ code: "CONFLICT", status: 409, summary: message });
29
38
  this.name = "ConflictError";
30
39
  }
31
40
  }
32
- export class ForbiddenError extends Error {
33
- code = "FORBIDDEN";
41
+ /** @deprecated Use `Forbidden({ ... })` from `@nwire/handler`. */
42
+ export class ForbiddenError extends NwireError {
34
43
  constructor(message) {
35
- super(message);
44
+ super({ code: "FORBIDDEN", status: 403, summary: message });
36
45
  this.name = "ForbiddenError";
37
46
  }
38
47
  }
39
- export class UnauthorizedError extends Error {
40
- code = "UNAUTHORIZED";
48
+ /** @deprecated Use `Unauthorized({ ... })` from `@nwire/handler`. */
49
+ export class UnauthorizedError extends NwireError {
41
50
  constructor(message) {
42
- super(message);
51
+ super({ code: "UNAUTHORIZED", status: 401, summary: message });
43
52
  this.name = "UnauthorizedError";
44
53
  }
45
54
  }
@@ -1 +1 @@
1
- {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,MAAM,OAAO,aAAc,SAAQ,KAAK;IAC7B,IAAI,GAAG,WAAW,CAAC;IAC5B,YAAY,MAAc,EAAE,EAAW;QACrC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,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O,EAAE,CAAC,CAAC;QAC/D,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAC;IAClC,CAAC;CACF"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@nwire/errors",
3
- "version": "0.8.17",
4
- "description": "Typed domain errors (NotFoundError, ValidationError, ConflictError, ForbiddenError, UnauthorizedError) for uniform error handling. Use `instanceof` checks in route handlers instead of string comparisons.",
3
+ "version": "0.9.1",
4
+ "description": "Compatibility shim around @nwire/handler error definitions. New code should import the canonical singletons (Unauthorized, Forbidden, NotFound, Conflict, Gone, BadRequest) directly from @nwire/handler.",
5
5
  "license": "MIT",
6
6
  "files": [
7
7
  "dist",
@@ -20,6 +20,9 @@
20
20
  "publishConfig": {
21
21
  "access": "public"
22
22
  },
23
+ "dependencies": {
24
+ "@nwire/handler": "0.9.1"
25
+ },
23
26
  "devDependencies": {
24
27
  "@types/node": "^22.19.9",
25
28
  "typescript": "^5.9.3"