Skip to content

Commit 985c4b1

Browse files
authored
#198 - removed multi-message request model
1 parent ba253a4 commit 985c4b1

File tree

9 files changed

+15
-157
lines changed

9 files changed

+15
-157
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Decentralized Web Node (DWN) SDK
44

55
Code Coverage
6-
![Statements](https://img.shields.io/badge/statements-92.65%25-brightgreen.svg?style=flat) ![Branches](https://img.shields.io/badge/branches-91.98%25-brightgreen.svg?style=flat) ![Functions](https://img.shields.io/badge/functions-89.3%25-yellow.svg?style=flat) ![Lines](https://img.shields.io/badge/lines-92.65%25-brightgreen.svg?style=flat)
6+
![Statements](https://img.shields.io/badge/statements-93.6%25-brightgreen.svg?style=flat) ![Branches](https://img.shields.io/badge/branches-91.96%25-brightgreen.svg?style=flat) ![Functions](https://img.shields.io/badge/functions-90.38%25-brightgreen.svg?style=flat) ![Lines](https://img.shields.io/badge/lines-93.6%25-brightgreen.svg?style=flat)
77

88
## Introduction
99

build/compile-validators.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ import ProtocolsQuery from '../json-schemas/protocols/protocols-query.json' asse
3232
import PublicJwk from '../json-schemas/jwk/public-jwk.json' assert { type: 'json' };
3333
import RecordsQuery from '../json-schemas/records/records-query.json' assert { type: 'json' };
3434
import RecordsWrite from '../json-schemas/records/records-write.json' assert { type: 'json' };
35-
import Request from '../json-schemas/request.json' assert { type: 'json' };
3635

3736
const schemas = {
3837
RecordsQuery,
@@ -49,8 +48,7 @@ const schemas = {
4948
ProtocolRuleSet,
5049
ProtocolsConfigure,
5150
ProtocolsQuery,
52-
PublicJwk,
53-
Request
51+
PublicJwk
5452
};
5553

5654
const ajv = new Ajv({ code: { source: true, esm: true } });

json-schemas/request.json

Lines changed: 0 additions & 18 deletions
This file was deleted.

src/core/request.ts

Lines changed: 0 additions & 14 deletions
This file was deleted.

src/core/response.ts

Lines changed: 0 additions & 44 deletions
This file was deleted.

src/core/types.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,3 @@ export type DataReferencingMessage = {
3636
export type AuthCreateOptions = {
3737
signatureInput: SignatureInput
3838
};
39-
40-
export type RequestSchema = {
41-
messages: BaseMessage[]
42-
};

src/dwn.ts

Lines changed: 11 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
1+
import type { BaseMessage } from './core/types.js';
12
import type { DidMethodResolver } from './did/did-resolver.js';
23
import type { MessageStore } from './store/message-store.js';
3-
import type { BaseMessage, RequestSchema } from './core/types.js';
44
import type { Interface, MethodHandler } from './interfaces/types.js';
55

66
import { DidResolver } from './did/did-resolver.js';
77
import { Encoder } from './utils/encoder.js';
88
import { Message } from './core/message.js';
99
import { MessageReply } from './core/message-reply.js';
1010
import { MessageStoreLevel } from './store/message-store-level.js';
11-
import { Request } from './core/request.js';
12-
import { Response } from './core/response.js';
1311

1412
import { PermissionsInterface } from './interfaces/permissions/permissions-interface.js';
1513
import { ProtocolsInterface } from './interfaces/protocols/protocols-interface.js';
@@ -60,42 +58,22 @@ export class Dwn {
6058
}
6159

6260
/**
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.
6563
*/
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;
6866
try {
6967
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 }
8072
});
8173
}
8274

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;
9977
}
10078

10179
/**

src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ export { DidResolver, DidMethodResolver } from './did/did-resolver.js';
2323
export { Dwn } from './dwn.js';
2424
export { Encoder } from './utils/encoder.js';
2525
export { HooksWrite, HooksWriteOptions } from './interfaces/hooks/messages/hooks-write.js';
26+
export { MessageReply } from './core/message-reply.js';
2627
export { MessageStore } from './store/message-store.js';
2728
export { MessageStoreLevel } from './store/message-store-level.js';
2829
export { PrivateJwk, PublicJwk } from './jose/types.js';
2930
export { ProtocolsConfigure, ProtocolsConfigureOptions } from './interfaces/protocols/messages/protocols-configure.js';
30-
export { ProtocolsQuery, ProtocolsQueryOptions } from './interfaces/protocols/messages/protocols-query.js';
31-
export { Response } from './core/response.js';
31+
export { ProtocolsQuery, ProtocolsQueryOptions } from './interfaces/protocols/messages/protocols-query.js';

tests/core/request.spec.ts

Lines changed: 0 additions & 38 deletions
This file was deleted.

0 commit comments

Comments
 (0)