Skip to content

Commit a883c2b

Browse files
committed
api!(deltachat-jsonrpc): use kind as a tag for all union types
1 parent 954067e commit a883c2b

File tree

15 files changed

+36
-36
lines changed

15 files changed

+36
-36
lines changed

deltachat-jsonrpc/src/api/types/account.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use typescript_type_def::TypeDef;
77
use super::color_int_to_hex_string;
88

99
#[derive(Serialize, TypeDef, schemars::JsonSchema)]
10-
#[serde(tag = "type")]
10+
#[serde(tag = "kind")]
1111
pub enum Account {
1212
#[serde(rename_all = "camelCase")]
1313
Configured {

deltachat-jsonrpc/src/api/types/chat.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ impl BasicChat {
167167
}
168168

169169
#[derive(Clone, Serialize, Deserialize, TypeDef, schemars::JsonSchema)]
170+
#[serde(tag = "kind")]
170171
pub enum MuteDuration {
171172
NotMuted,
172173
Forever,

deltachat-jsonrpc/src/api/types/chat_list.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use super::message::MessageViewtype;
1818
pub struct ChatListEntry(pub u32, pub u32);
1919

2020
#[derive(Serialize, TypeDef, schemars::JsonSchema)]
21-
#[serde(tag = "type")]
21+
#[serde(tag = "kind")]
2222
pub enum ChatListItemFetchResult {
2323
#[serde(rename_all = "camelCase")]
2424
ChatListItem {

deltachat-jsonrpc/src/api/types/events.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ impl From<CoreEvent> for Event {
2222
}
2323

2424
#[derive(Serialize, TypeDef, schemars::JsonSchema)]
25-
#[serde(tag = "type")]
25+
#[serde(tag = "kind")]
2626
pub enum EventType {
2727
/// The library-user may write an informational string to the log.
2828
///

deltachat-jsonrpc/src/api/types/message.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use super::reactions::JSONRPCReactions;
1919
use super::webxdc::WebxdcMessageInfo;
2020

2121
#[derive(Serialize, TypeDef, schemars::JsonSchema)]
22-
#[serde(rename_all = "camelCase", tag = "variant")]
22+
#[serde(rename_all = "camelCase", tag = "kind")]
2323
pub enum MessageLoadResult {
2424
Message(MessageObject),
2525
LoadingError { error: String },

deltachat-jsonrpc/src/api/types/qr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use typescript_type_def::TypeDef;
44

55
#[derive(Serialize, TypeDef, schemars::JsonSchema)]
66
#[serde(rename = "Qr", rename_all = "camelCase")]
7-
#[serde(tag = "type")]
7+
#[serde(tag = "kind")]
88
pub enum QrObject {
99
AskVerifyContact {
1010
contact_id: u32,

deltachat-jsonrpc/typescript/example/example.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ async function run() {
3535
const accounts = await client.rpc.getAllAccounts();
3636
console.log("accounts loaded", accounts);
3737
for (const account of accounts) {
38-
if (account.type === "Configured") {
38+
if (account.kind === "Configured") {
3939
write(
4040
$head,
4141
`<a href="#" onclick="selectDeltaAccount(${account.id})">
@@ -57,7 +57,7 @@ async function run() {
5757
clear($main);
5858
const selectedAccount = SELECTED_ACCOUNT;
5959
const info = await client.rpc.getAccountInfo(selectedAccount);
60-
if (info.type !== "Configured") {
60+
if (info.kind !== "Configured") {
6161
return write($main, "Account is not configured");
6262
}
6363
write($main, `<h2>${info.addr!}</h2>`);
@@ -81,8 +81,7 @@ async function run() {
8181
messageIds
8282
);
8383
for (const [_messageId, message] of Object.entries(messages)) {
84-
if (message.variant === "message")
85-
write($main, `<p>${message.text}</p>`);
84+
if (message.kind === "message") write($main, `<p>${message.text}</p>`);
8685
else write($main, `<p>loading error: ${message.error}</p>`);
8786
}
8887
}
@@ -93,9 +92,9 @@ async function run() {
9392
$side,
9493
`
9594
<p class="message">
96-
[<strong>${event.type}</strong> on account ${accountId}]<br>
95+
[<strong>${event.kind}</strong> on account ${accountId}]<br>
9796
<em>f1:</em> ${JSON.stringify(
98-
Object.assign({}, event, { type: undefined })
97+
Object.assign({}, event, { kind: undefined })
9998
)}
10099
</p>`
101100
);

deltachat-jsonrpc/typescript/src/client.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,22 @@ import { WebsocketTransport, BaseTransport, Request } from "yerpc";
66
import { TinyEmitter } from "@deltachat/tiny-emitter";
77

88
type Events = { ALL: (accountId: number, event: EventType) => void } & {
9-
[Property in EventType["type"]]: (
9+
[Property in EventType["kind"]]: (
1010
accountId: number,
11-
event: Extract<EventType, { type: Property }>
11+
event: Extract<EventType, { kind: Property }>
1212
) => void;
1313
};
1414

1515
type ContextEvents = { ALL: (event: EventType) => void } & {
16-
[Property in EventType["type"]]: (
17-
event: Extract<EventType, { type: Property }>
16+
[Property in EventType["kind"]]: (
17+
event: Extract<EventType, { kind: Property }>
1818
) => void;
1919
};
2020

2121
export type DcEvent = EventType;
22-
export type DcEventType<T extends EventType["type"]> = Extract<
22+
export type DcEventType<T extends EventType["kind"]> = Extract<
2323
EventType,
24-
{ type: T }
24+
{ kind: T }
2525
>;
2626

2727
export class BaseDeltaChat<
@@ -46,12 +46,12 @@ export class BaseDeltaChat<
4646
while (true) {
4747
const event = await this.rpc.getNextEvent();
4848
//@ts-ignore
49-
this.emit(event.event.type, event.contextId, event.event);
49+
this.emit(event.event.kind, event.contextId, event.event);
5050
this.emit("ALL", event.contextId, event.event);
5151

5252
if (this.contextEmitters[event.contextId]) {
5353
this.contextEmitters[event.contextId].emit(
54-
event.event.type,
54+
event.event.kind,
5555
//@ts-ignore
5656
event.event as any
5757
);

deltachat-jsonrpc/typescript/test/online.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ describe("online tests", function () {
2929
serverHandle = await startServer();
3030
dc = new DeltaChat(serverHandle.stdin, serverHandle.stdout, true);
3131

32-
dc.on("ALL", (contextId, { type }) => {
33-
if (type !== "Info") console.log(contextId, type);
32+
dc.on("ALL", (contextId, { kind }) => {
33+
if (kind !== "Info") console.log(contextId, kind);
3434
});
3535

3636
account1 = await createTempUser(process.env.DCC_NEW_TMP_EMAIL);
@@ -177,12 +177,12 @@ describe("online tests", function () {
177177
});
178178
});
179179

180-
async function waitForEvent<T extends DcEvent["type"]>(
180+
async function waitForEvent<T extends DcEvent["kind"]>(
181181
dc: DeltaChat,
182182
eventType: T,
183183
accountId: number,
184184
timeout: number = EVENT_TIMEOUT
185-
): Promise<Extract<DcEvent, { type: T }>> {
185+
): Promise<Extract<DcEvent, { kind: T }>> {
186186
return new Promise((resolve, reject) => {
187187
const rejectTimeout = setTimeout(
188188
() => reject(new Error("Timeout reached before event came in")),

deltachat-rpc-client/examples/echobot_advanced.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414

1515
@hooks.on(events.RawEvent)
1616
async def log_event(event):
17-
if event.type == EventType.INFO:
17+
if event.kind == EventType.INFO:
1818
logging.info(event.msg)
19-
elif event.type == EventType.WARNING:
19+
elif event.kind == EventType.WARNING:
2020
logging.warning(event.msg)
2121

2222

0 commit comments

Comments
 (0)