|
| 1 | +import type { BaseMessage } from './core/types.js'; |
1 | 2 | import type { DidMethodResolver } from './did/did-resolver.js'; |
2 | 3 | import type { MessageStore } from './store/message-store.js'; |
3 | | -import type { BaseMessage, RequestSchema } from './core/types.js'; |
4 | 4 | import type { Interface, MethodHandler } from './interfaces/types.js'; |
5 | 5 |
|
6 | 6 | import { DidResolver } from './did/did-resolver.js'; |
7 | 7 | import { Encoder } from './utils/encoder.js'; |
8 | 8 | import { Message } from './core/message.js'; |
9 | 9 | import { MessageReply } from './core/message-reply.js'; |
10 | 10 | import { MessageStoreLevel } from './store/message-store-level.js'; |
11 | | -import { Request } from './core/request.js'; |
12 | | -import { Response } from './core/response.js'; |
13 | 11 |
|
14 | 12 | import { PermissionsInterface } from './interfaces/permissions/permissions-interface.js'; |
15 | 13 | import { ProtocolsInterface } from './interfaces/protocols/protocols-interface.js'; |
@@ -60,42 +58,22 @@ export class Dwn { |
60 | 58 | } |
61 | 59 |
|
62 | 60 | /** |
63 | | - * Processes the given DWN request and returns with a DWN response. |
64 | | - * @param tenant The tenant DID to route the given request to. |
| 61 | + * Processes the given DWN message given as raw bytes and returns with a message reply. |
| 62 | + * @param tenant The tenant DID to route the given message to. |
65 | 63 | */ |
66 | | - async processRequest(tenant: string, rawRequest: Uint8Array): Promise<Response> { |
67 | | - let request: RequestSchema; |
| 64 | + async processRequest(tenant: string, rawRequest: Uint8Array): Promise<MessageReply> { |
| 65 | + let message: BaseMessage; |
68 | 66 | try { |
69 | 67 | const requestString = Encoder.bytesToString(rawRequest); |
70 | | - request = JSON.parse(requestString); |
71 | | - } catch { |
72 | | - throw new Error('expected request to be valid JSON'); |
73 | | - } |
74 | | - |
75 | | - try { |
76 | | - request = Request.parse(request); |
77 | | - } catch (e) { |
78 | | - return new Response({ |
79 | | - status: { code: 400, message: e.message } |
| 68 | + message = JSON.parse(requestString); |
| 69 | + } catch (error) { |
| 70 | + return new MessageReply({ |
| 71 | + status: { code: 400, detail: error.message } |
80 | 72 | }); |
81 | 73 | } |
82 | 74 |
|
83 | | - const response = new Response(); |
84 | | - |
85 | | - for (const message of request.messages) { |
86 | | - let result; |
87 | | - try { |
88 | | - result = await this.processMessage(tenant, message); |
89 | | - } catch (error) { |
90 | | - result = new MessageReply({ |
91 | | - status: { code: 500, detail: error.message } |
92 | | - }); |
93 | | - } |
94 | | - |
95 | | - response.addMessageResult(result); |
96 | | - } |
97 | | - |
98 | | - return response; |
| 75 | + const messageReply = await this.processMessage(tenant, message); |
| 76 | + return messageReply; |
99 | 77 | } |
100 | 78 |
|
101 | 79 | /** |
|
0 commit comments