Skip to content

Commit ec94bcd

Browse files
authored
#310 - introduced protocolPath to update all affected tests
1 parent 07bcddb commit ec94bcd

File tree

10 files changed

+179
-129
lines changed

10 files changed

+179
-129
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-93.86%25-brightgreen.svg?style=flat) ![Branches](https://img.shields.io/badge/branches-93.36%25-brightgreen.svg?style=flat) ![Functions](https://img.shields.io/badge/functions-91.54%25-brightgreen.svg?style=flat) ![Lines](https://img.shields.io/badge/lines-93.86%25-brightgreen.svg?style=flat)
6+
![Statements](https://img.shields.io/badge/statements-93.86%25-brightgreen.svg?style=flat) ![Branches](https://img.shields.io/badge/branches-93.39%25-brightgreen.svg?style=flat) ![Functions](https://img.shields.io/badge/functions-91.54%25-brightgreen.svg?style=flat) ![Lines](https://img.shields.io/badge/lines-93.86%25-brightgreen.svg?style=flat)
77

88
## Introduction
99

json-schemas/records/records-write.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@
104104
"protocol": {
105105
"type": "string"
106106
},
107+
"protocolPath": {
108+
"type": "string"
109+
},
107110
"schema": {
108111
"type": "string"
109112
},

src/interfaces/records/messages/records-write.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import { DwnInterfaceName, DwnMethodName } from '../../../core/message.js';
3333
export type RecordsWriteOptions = {
3434
recipient?: string;
3535
protocol?: string;
36+
protocolPath?: string;
3637
contextId?: string;
3738
schema?: string;
3839
recordId?: string;
@@ -137,7 +138,10 @@ export class RecordsWrite extends Message<RecordsWriteMessage> {
137138
* @param options.dateModified If `undefined`, it will be auto-filled with current time.
138139
*/
139140
public static async create(options: RecordsWriteOptions): Promise<RecordsWrite> {
140-
const currentTime = getCurrentTimeInHighPrecision();
141+
if ((options.protocol === undefined && options.protocolPath !== undefined) ||
142+
(options.protocol !== undefined && options.protocolPath === undefined)) {
143+
throw new Error('`protocol` and `protocolPath` must both be defined or undefined at the same time');
144+
}
141145

142146
if ((options.data === undefined && options.dataCid === undefined) ||
143147
(options.data !== undefined && options.dataCid !== undefined)) {
@@ -152,10 +156,13 @@ export class RecordsWrite extends Message<RecordsWriteMessage> {
152156
const dataCid = options.dataCid ?? await Cid.computeDagPbCidFromBytes(options.data!);
153157
const dataSize = options.dataSize ?? options.data!.length;
154158

159+
const currentTime = getCurrentTimeInHighPrecision();
160+
155161
const descriptor: RecordsWriteDescriptor = {
156162
interface : DwnInterfaceName.Records,
157163
method : DwnMethodName.Write,
158164
protocol : options.protocol,
165+
protocolPath : options.protocolPath,
159166
recipient : options.recipient!,
160167
schema : options.schema,
161168
parentId : options.parentId,
@@ -270,6 +277,7 @@ export class RecordsWrite extends Message<RecordsWriteMessage> {
270277
dateCreated : unsignedMessage.descriptor.dateCreated,
271278
contextId : unsignedMessage.contextId,
272279
protocol : unsignedMessage.descriptor.protocol,
280+
protocolPath : unsignedMessage.descriptor.protocolPath,
273281
parentId : unsignedMessage.descriptor.parentId,
274282
schema : unsignedMessage.descriptor.schema,
275283
dataFormat : unsignedMessage.descriptor.dataFormat,

src/interfaces/records/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export type RecordsWriteDescriptor = {
1212
interface: DwnInterfaceName.Records;
1313
method: DwnMethodName.Write;
1414
protocol?: string;
15+
protocolPath?: string;
1516
recipient: string;
1617
schema?: string;
1718
parentId?: string;
@@ -76,6 +77,7 @@ export type RecordsQueryFilter = {
7677
attester?: string;
7778
recipient?: string;
7879
protocol?: string;
80+
protocolPath?: string;
7981
contextId?: string;
8082
schema?: string;
8183
recordId?: string;

tests/interfaces/records/handlers/records-query.spec.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -632,13 +632,14 @@ describe('RecordsQueryHandler.handle()', () => {
632632
}]
633633
};
634634

635-
const schema = 'email';
635+
const schema = emailProtocolDefinition.labels.email.schema;
636636
const { message, dataStream } = await TestDataGenerator.generateRecordsWrite(
637637
{
638-
requester : bob,
638+
requester : bob,
639639
protocol,
640+
protocolPath : 'email', // this comes from `labels` in protocol definition
640641
schema,
641-
data : bobMessageEncryptedBytes,
642+
data : bobMessageEncryptedBytes,
642643
encryptionInput
643644
}
644645
);

tests/interfaces/records/handlers/records-read.spec.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ describe('RecordsReadHandler.handle()', () => {
178178
const imageRecordsWrite = await TestDataGenerator.generateRecordsWrite({
179179
requester : alice,
180180
protocol,
181+
protocolPath : 'image', // this comes from `labels` in protocol definition
181182
schema : protocolDefinition.labels.image.schema,
182183
data : encodedImage,
183184
recipientDid : alice.did
@@ -219,6 +220,7 @@ describe('RecordsReadHandler.handle()', () => {
219220
const emailRecordsWrite = await TestDataGenerator.generateRecordsWrite({
220221
requester : alice,
221222
protocol,
223+
protocolPath : 'email', // this comes from `labels` in protocol definition
222224
schema : protocolDefinition.labels.email.schema,
223225
data : encodedEmail,
224226
recipientDid : bob.did
@@ -268,6 +270,7 @@ describe('RecordsReadHandler.handle()', () => {
268270
const emailRecordsWrite = await TestDataGenerator.generateRecordsWrite({
269271
requester : bob,
270272
protocol,
273+
protocolPath : 'email', // this comes from `labels` in protocol definition
271274
schema : protocolDefinition.labels.email.schema,
272275
data : encodedEmail,
273276
recipientDid : alice.did
@@ -407,10 +410,11 @@ describe('RecordsReadHandler.handle()', () => {
407410

408411
const { message, dataStream } = await TestDataGenerator.generateRecordsWrite(
409412
{
410-
requester : bob,
413+
requester : bob,
411414
protocol,
412-
schema : 'email',
413-
data : bobMessageEncryptedBytes,
415+
protocolPath : 'email', // this comes from `labels` in protocol definition
416+
schema : emailProtocolDefinition.labels.email.schema,
417+
data : bobMessageEncryptedBytes,
414418
encryptionInput
415419
}
416420
);

0 commit comments

Comments
 (0)