@syncular/server-hono 0.30.16 → 0.31.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/dist/admin.d.ts CHANGED
@@ -10,7 +10,7 @@
10
10
  * commit metadata, scope activity, and reactions) and authorization is
11
11
  * entirely the host's and mandatory.
12
12
  */
13
- import { type SyncularAdmin, type SyncularErrorHandler } from '@syncular/server';
13
+ import { type SyncularAdmin, type SyncularErrorHandler, type SyncularErrorMapper } from '@syncular/server';
14
14
  import { Hono } from 'hono';
15
15
  export interface AdminAuthContext {
16
16
  /** The partition the request targets (from the query string / route). */
@@ -35,6 +35,11 @@ export interface SyncularAdminRoutesOptions {
35
35
  * `SyncError`, which answers 500 `sync.internal_error` (§10.2).
36
36
  */
37
37
  readonly onError?: SyncularErrorHandler;
38
+ /**
39
+ * Optional synchronous mapper (§10.2) for those exceptions; return a catalog
40
+ * `SyncError` to answer with it, or `undefined` for `sync.internal_error`.
41
+ */
42
+ readonly mapError?: SyncularErrorMapper;
38
43
  }
39
44
  /**
40
45
  * Build the mountable admin sub-app. Mount it under any prefix, e.g.
package/dist/admin.js CHANGED
@@ -30,7 +30,7 @@ export function createSyncularAdminRoutes(admin, options) {
30
30
  }
31
31
  const app = new Hono();
32
32
  const jsonError = (error) => {
33
- const sync = adapterSyncError(error, options.onError, 'admin');
33
+ const sync = adapterSyncError(error, (error, context) => options.onError?.(error, context), 'admin', (error, context) => options.mapError?.(error, context));
34
34
  return Response.json(errorBody(sync), { status: sync.httpStatus });
35
35
  };
36
36
  // Throws outside a route's own try, such as from `authorize`.
package/dist/index.js CHANGED
@@ -12,7 +12,7 @@ export function createSyncularHono(options) {
12
12
  // A `SyncError` answers with its catalog status. Any other exception goes
13
13
  // to `config.onError` and answers 500 `sync.internal_error` (§10.2).
14
14
  const errorResponse = (c, error, route = 'sync') => {
15
- const sync = adapterSyncError(error, options.config.onError, route);
15
+ const sync = adapterSyncError(error, (error, context) => options.config.onError?.(error, context), route, (error, context) => options.config.mapError?.(error, context));
16
16
  const response = Response.json(errorBody(sync), {
17
17
  status: sync.httpStatus,
18
18
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@syncular/server-hono",
3
- "version": "0.30.16",
3
+ "version": "0.31.0",
4
4
  "description": "Hono adapter for the Syncular sync server",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Benjamin Kniffler",
@@ -45,10 +45,10 @@
45
45
  "!dist/**/*.test.d.ts"
46
46
  ],
47
47
  "dependencies": {
48
- "@syncular/server": "0.30.16",
48
+ "@syncular/server": "0.31.0",
49
49
  "hono": "^4.13.7"
50
50
  },
51
51
  "devDependencies": {
52
- "@syncular/core": "0.30.16"
52
+ "@syncular/core": "0.31.0"
53
53
  }
54
54
  }
package/src/admin.ts CHANGED
@@ -19,6 +19,7 @@ import {
19
19
  SyncError,
20
20
  type SyncularAdmin,
21
21
  type SyncularErrorHandler,
22
+ type SyncularErrorMapper,
22
23
  type SyncularServerEvent,
23
24
  } from '@syncular/server';
24
25
  import { Hono } from 'hono';
@@ -48,6 +49,11 @@ export interface SyncularAdminRoutesOptions {
48
49
  * `SyncError`, which answers 500 `sync.internal_error` (§10.2).
49
50
  */
50
51
  readonly onError?: SyncularErrorHandler;
52
+ /**
53
+ * Optional synchronous mapper (§10.2) for those exceptions; return a catalog
54
+ * `SyncError` to answer with it, or `undefined` for `sync.internal_error`.
55
+ */
56
+ readonly mapError?: SyncularErrorMapper;
51
57
  }
52
58
 
53
59
  function intParam(value: string | undefined, fallback: number): number {
@@ -72,7 +78,12 @@ export function createSyncularAdminRoutes(
72
78
  }
73
79
  const app = new Hono();
74
80
  const jsonError = (error: unknown): Response => {
75
- const sync = adapterSyncError(error, options.onError, 'admin');
81
+ const sync = adapterSyncError(
82
+ error,
83
+ (error, context) => options.onError?.(error, context),
84
+ 'admin',
85
+ (error, context) => options.mapError?.(error, context),
86
+ );
76
87
  return Response.json(errorBody(sync), { status: sync.httpStatus });
77
88
  };
78
89
  // Throws outside a route's own try, such as from `authorize`.
package/src/index.ts CHANGED
@@ -44,7 +44,12 @@ export function createSyncularHono(options: SyncularHonoOptions): Hono {
44
44
  error: unknown,
45
45
  route: SyncularErrorRoute = 'sync',
46
46
  ): Response => {
47
- const sync = adapterSyncError(error, options.config.onError, route);
47
+ const sync = adapterSyncError(
48
+ error,
49
+ (error, context) => options.config.onError?.(error, context),
50
+ route,
51
+ (error, context) => options.config.mapError?.(error, context),
52
+ );
48
53
  const response = Response.json(errorBody(sync), {
49
54
  status: sync.httpStatus,
50
55
  });