Skip to content

Commit

Permalink
update bsync protos
Browse files Browse the repository at this point in the history
  • Loading branch information
devinivy committed Jan 16, 2024
1 parent 07a9c89 commit 6913ec2
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 16 deletions.
7 changes: 4 additions & 3 deletions packages/bsync/proto/bsync.proto
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ option go_package = "./;bsync";

message MuteOperation {
enum Type {
ADD = 0;
REMOVE = 1;
CLEAR = 2;
TYPE_UNSPECIFIED = 0;
TYPE_ADD = 1;
TYPE_REMOVE = 2;
TYPE_CLEAR = 3;
}
string id = 1;
Type type = 2;
Expand Down
28 changes: 17 additions & 11 deletions packages/bsync/src/gen/bsync_pb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class MuteOperation extends Message<MuteOperation> {
/**
* @generated from field: bsync.MuteOperation.Type type = 2;
*/
type = MuteOperation_Type.ADD
type = MuteOperation_Type.UNSPECIFIED

/**
* @generated from field: string actor_did = 3;
Expand Down Expand Up @@ -90,25 +90,31 @@ export class MuteOperation extends Message<MuteOperation> {
*/
export enum MuteOperation_Type {
/**
* @generated from enum value: ADD = 0;
* @generated from enum value: TYPE_UNSPECIFIED = 0;
*/
ADD = 0,
UNSPECIFIED = 0,

/**
* @generated from enum value: REMOVE = 1;
* @generated from enum value: TYPE_ADD = 1;
*/
REMOVE = 1,
ADD = 1,

/**
* @generated from enum value: CLEAR = 2;
* @generated from enum value: TYPE_REMOVE = 2;
*/
CLEAR = 2,
REMOVE = 2,

/**
* @generated from enum value: TYPE_CLEAR = 3;
*/
CLEAR = 3,
}
// Retrieve enum metadata with: proto3.getEnumType(MuteOperation_Type)
proto3.util.setEnumType(MuteOperation_Type, 'bsync.MuteOperation.Type', [
{ no: 0, name: 'ADD' },
{ no: 1, name: 'REMOVE' },
{ no: 2, name: 'CLEAR' },
{ no: 0, name: 'TYPE_UNSPECIFIED' },
{ no: 1, name: 'TYPE_ADD' },
{ no: 2, name: 'TYPE_REMOVE' },
{ no: 3, name: 'TYPE_CLEAR' },
])

/**
Expand All @@ -118,7 +124,7 @@ export class AddMuteOperationRequest extends Message<AddMuteOperationRequest> {
/**
* @generated from field: bsync.MuteOperation.Type type = 1;
*/
type = MuteOperation_Type.ADD
type = MuteOperation_Type.UNSPECIFIED

/**
* @generated from field: string actor_did = 2;
Expand Down
19 changes: 17 additions & 2 deletions packages/bsync/src/routes/add-mute-operation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,16 @@ const clearMuteItems = async (db: Database, op: MuteOpInfo) => {
.execute()
}

const validMuteOp = (op: MuteOpInfo): MuteOpInfo => {
const validMuteOp = (op: MuteOpInfo): MuteOpInfoValid => {
if (!Object.values(MuteOperation_Type).includes(op.type)) {
throw new ConnectError('bad mute operation type', Code.InvalidArgument)
}
if (op.type === MuteOperation_Type.UNSPECIFIED) {
throw new ConnectError(
'unspecified mute operation type',
Code.InvalidArgument,
)
}
if (!isValidDid(op.actorDid)) {
throw new ConnectError(
'actor_did must be a valid did',
Expand Down Expand Up @@ -127,7 +133,7 @@ const validMuteOp = (op: MuteOpInfo): MuteOpInfo => {
)
}
}
return op
return op as MuteOpInfoValid // op.type has been checked
}

const isValidDid = (did: string) => {
Expand Down Expand Up @@ -156,3 +162,12 @@ type MuteOpInfo = {
actorDid: string
subject: string
}

type MuteOpInfoValid = {
type:
| MuteOperation_Type.ADD
| MuteOperation_Type.REMOVE
| MuteOperation_Type.CLEAR
actorDid: string
subject: string
}

0 comments on commit 6913ec2

Please sign in to comment.