-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathui.ts
More file actions
52 lines (44 loc) · 1.91 KB
/
Copy pathui.ts
File metadata and controls
52 lines (44 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
/**
* `/ui` domain — extracted dispatcher body (ADR-0076 D11 step ③, PR-3).
* Serves rendered view metadata from the `protocol` service.
*
* Routes (path is the sub-path after `/ui`):
* GET /view/:object[/:type] → getUiView (type also accepted as ?type=)
*/
import type { HttpProtocolContext, HttpDispatcherResult } from '../http-dispatcher.js';
import type { DomainHandlerDeps, DomainRoute } from '../domain-handler-registry.js';
export function createUiDomain(deps: DomainHandlerDeps): DomainRoute {
return {
prefix: '/ui',
handler: (req, context) =>
handleUiRequest(deps, req.path.substring(3), req.query, context),
};
}
/** Body kept signature-compatible with the legacy `HttpDispatcher.handleUi`. */
export async function handleUiRequest(
deps: DomainHandlerDeps,
path: string,
query: any,
_context: HttpProtocolContext,
): Promise<HttpDispatcherResult> {
const parts = path.replace(/^\/+/, '').split('/').filter(Boolean);
// GET /ui/view/:object (with optional type param)
if (parts[0] === 'view' && parts[1]) {
const objectName = parts[1];
// Support both path param /view/obj/list AND query param /view/obj?type=list
const type = parts[2] || query?.type || 'list';
const protocol = await deps.resolveService('protocol');
if (protocol && typeof protocol.getUiView === 'function') {
try {
const result = await protocol.getUiView({ object: objectName, type });
return { handled: true, response: deps.success(result) };
} catch (e: any) {
return { handled: true, response: deps.error(e.message, 500) };
}
} else {
return { handled: true, response: deps.error('Protocol service not available', 503) };
}
}
return { handled: false };
}