mirror of
https://github.com/chatmail/core.git
synced 2026-05-20 07:16:31 +03:00
Naming consistency: Use DeltaChat not Deltachat
This commit is contained in:
committed by
Simon Laux
parent
7fc162543a
commit
7eae3a1072
6
deltachat-jsonrpc/typescript/.npmignore
Normal file
6
deltachat-jsonrpc/typescript/.npmignore
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
node_modules
|
||||||
|
accounts
|
||||||
|
docs
|
||||||
|
coverage
|
||||||
|
yarn*
|
||||||
|
package-lock.json
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<title>Deltachat JSON-RPC example</title>
|
<title>DeltaChat JSON-RPC example</title>
|
||||||
<style>
|
<style>
|
||||||
body {
|
body {
|
||||||
font-family: monospace;
|
font-family: monospace;
|
||||||
@@ -42,7 +42,7 @@
|
|||||||
<script type="module" src="dist/example.bundle.js"></script>
|
<script type="module" src="dist/example.bundle.js"></script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>Deltachat JSON-RPC example</h1>
|
<h1>DeltaChat JSON-RPC example</h1>
|
||||||
<div class="grid">
|
<div class="grid">
|
||||||
<div id="header"></div>
|
<div id="header"></div>
|
||||||
<div id="main"></div>
|
<div id="main"></div>
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { Deltachat, DeltachatEvent } from "../deltachat.js";
|
import { DeltaChat, DeltaChatEvent } from "../deltachat.js";
|
||||||
|
|
||||||
var SELECTED_ACCOUNT = 0;
|
var SELECTED_ACCOUNT = 0;
|
||||||
|
|
||||||
@@ -16,7 +16,7 @@ async function run() {
|
|||||||
const $side = document.getElementById("side")!;
|
const $side = document.getElementById("side")!;
|
||||||
const $head = document.getElementById("header")!;
|
const $head = document.getElementById("header")!;
|
||||||
|
|
||||||
const client = new Deltachat('ws://localhost:20808/ws')
|
const client = new DeltaChat('ws://localhost:20808/ws')
|
||||||
|
|
||||||
;(window as any).client = client.rpc;
|
;(window as any).client = client.rpc;
|
||||||
|
|
||||||
@@ -88,7 +88,7 @@ async function run() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function onIncomingEvent(event: DeltachatEvent) {
|
function onIncomingEvent(event: DeltaChatEvent) {
|
||||||
write(
|
write(
|
||||||
$side,
|
$side,
|
||||||
`
|
`
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import { Deltachat } from "../dist/deltachat.js";
|
import { DeltaChat } from "../dist/deltachat.js";
|
||||||
|
|
||||||
run().catch(console.error);
|
run().catch(console.error);
|
||||||
|
|
||||||
async function run() {
|
async function run() {
|
||||||
const delta = new Deltachat('ws://localhost:20808/ws');
|
const delta = new DeltaChat('ws://localhost:20808/ws');
|
||||||
delta.on("event", (event) => {
|
delta.on("event", (event) => {
|
||||||
console.log("event", event.data);
|
console.log("event", event.data);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import { Deltachat } from "../dist/deltachat.js";
|
import { DeltaChat } from "../dist/deltachat.js";
|
||||||
|
|
||||||
run().catch(console.error);
|
run().catch(console.error);
|
||||||
|
|
||||||
async function run() {
|
async function run() {
|
||||||
const delta = new Deltachat();
|
const delta = new DeltaChat();
|
||||||
delta.on("event", (event) => {
|
delta.on("event", (event) => {
|
||||||
console.log("event", event.data);
|
console.log("event", event.data);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"name": "@deltachat/jsonrpc-client",
|
"name": "deltachat-jsonrpc-client",
|
||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"main": "dist/deltachat.js",
|
"main": "dist/deltachat.js",
|
||||||
"types": "dist/deltachat.d.ts",
|
"types": "dist/deltachat.d.ts",
|
||||||
@@ -12,7 +12,7 @@
|
|||||||
"generate-bindings": "cargo test",
|
"generate-bindings": "cargo test",
|
||||||
"build": "run-s generate-bindings build:tsc build:bundle",
|
"build": "run-s generate-bindings build:tsc build:bundle",
|
||||||
"build:tsc": "tsc",
|
"build:tsc": "tsc",
|
||||||
"build:bundle": "esbuild --bundle dist/deltachat.js --outfile=dist/deltachat.bundle.js",
|
"build:bundle": "esbuild --format=esm --bundle dist/deltachat.js --outfile=dist/deltachat.bundle.js",
|
||||||
"example": "run-s build example:build example:start",
|
"example": "run-s build example:build example:start",
|
||||||
"example:build": "esbuild --bundle dist/example/example.js --outfile=dist/example.bundle.js",
|
"example:build": "esbuild --bundle dist/example/example.js --outfile=dist/example.bundle.js",
|
||||||
"example:start": "http-server .",
|
"example:start": "http-server .",
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import { EventTypeName } from "../generated/events.js";
|
|||||||
import { WebsocketTransport, BaseTransport, Request } from "yerpc";
|
import { WebsocketTransport, BaseTransport, Request } from "yerpc";
|
||||||
import { TinyEmitter } from "tiny-emitter";
|
import { TinyEmitter } from "tiny-emitter";
|
||||||
|
|
||||||
export type DeltachatEvent = {
|
export type DeltaChatEvent = {
|
||||||
id: EventTypeName;
|
id: EventTypeName;
|
||||||
contextId: number;
|
contextId: number;
|
||||||
field1: any;
|
field1: any;
|
||||||
@@ -13,10 +13,10 @@ export type DeltachatEvent = {
|
|||||||
};
|
};
|
||||||
export type Events = Record<
|
export type Events = Record<
|
||||||
EventTypeName | "ALL",
|
EventTypeName | "ALL",
|
||||||
(event: DeltachatEvent) => void
|
(event: DeltaChatEvent) => void
|
||||||
>;
|
>;
|
||||||
|
|
||||||
export class BaseDeltachat<
|
export class BaseDeltaChat<
|
||||||
Transport extends BaseTransport<any>
|
Transport extends BaseTransport<any>
|
||||||
> extends TinyEmitter<Events> {
|
> extends TinyEmitter<Events> {
|
||||||
rpc: RawClient;
|
rpc: RawClient;
|
||||||
@@ -28,7 +28,7 @@ export class BaseDeltachat<
|
|||||||
this.transport.on("request", (request: Request) => {
|
this.transport.on("request", (request: Request) => {
|
||||||
const method = request.method;
|
const method = request.method;
|
||||||
if (method === "event") {
|
if (method === "event") {
|
||||||
const event = request.params! as DeltachatEvent;
|
const event = request.params! as DeltaChatEvent;
|
||||||
this.emit(event.id, event);
|
this.emit(event.id, event);
|
||||||
this.emit("ALL", event);
|
this.emit("ALL", event);
|
||||||
|
|
||||||
@@ -61,7 +61,7 @@ export type Opts = {
|
|||||||
export const DEFAULT_OPTS: Opts = {
|
export const DEFAULT_OPTS: Opts = {
|
||||||
url: "ws://localhost:20808/ws",
|
url: "ws://localhost:20808/ws",
|
||||||
};
|
};
|
||||||
export class Deltachat extends BaseDeltachat<WebsocketTransport> {
|
export class DeltaChat extends BaseDeltaChat<WebsocketTransport> {
|
||||||
opts: Opts;
|
opts: Opts;
|
||||||
close() {
|
close() {
|
||||||
this.transport.close();
|
this.transport.close();
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { strictEqual } from "assert";
|
|||||||
import chai, { assert, expect } from "chai";
|
import chai, { assert, expect } from "chai";
|
||||||
import chaiAsPromised from "chai-as-promised";
|
import chaiAsPromised from "chai-as-promised";
|
||||||
chai.use(chaiAsPromised);
|
chai.use(chaiAsPromised);
|
||||||
import { Deltachat } from "../deltachat.js";
|
import { DeltaChat } from "../deltachat.js";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
RpcServerHandle,
|
RpcServerHandle,
|
||||||
@@ -11,13 +11,13 @@ import {
|
|||||||
|
|
||||||
describe("basic tests", () => {
|
describe("basic tests", () => {
|
||||||
let serverHandle: RpcServerHandle;
|
let serverHandle: RpcServerHandle;
|
||||||
let dc: Deltachat;
|
let dc: DeltaChat;
|
||||||
|
|
||||||
before(async () => {
|
before(async () => {
|
||||||
serverHandle = await startServer();
|
serverHandle = await startServer();
|
||||||
// make sure server is up by the time we continue
|
// make sure server is up by the time we continue
|
||||||
await new Promise((res) => setTimeout(res, 100));
|
await new Promise((res) => setTimeout(res, 100));
|
||||||
dc = new Deltachat(serverHandle.url)
|
dc = new DeltaChat(serverHandle.url)
|
||||||
// dc.on("ALL", (event) => {
|
// dc.on("ALL", (event) => {
|
||||||
//console.log("event", event);
|
//console.log("event", event);
|
||||||
// });
|
// });
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { assert, expect } from "chai";
|
import { assert, expect } from "chai";
|
||||||
import { Deltachat, DeltachatEvent, EventTypeName } from "../deltachat.js";
|
import { DeltaChat, DeltaChatEvent, EventTypeName } from "../deltachat.js";
|
||||||
import {
|
import {
|
||||||
RpcServerHandle,
|
RpcServerHandle,
|
||||||
createTempUser,
|
createTempUser,
|
||||||
@@ -10,7 +10,7 @@ const EVENT_TIMEOUT = 10000
|
|||||||
|
|
||||||
describe("online tests", function () {
|
describe("online tests", function () {
|
||||||
let serverHandle: RpcServerHandle;
|
let serverHandle: RpcServerHandle;
|
||||||
let dc: Deltachat;
|
let dc: DeltaChat;
|
||||||
let account1: { email: string; password: string };
|
let account1: { email: string; password: string };
|
||||||
let account2: { email: string; password: string };
|
let account2: { email: string; password: string };
|
||||||
let accountId1: number, accountId2: number;
|
let accountId1: number, accountId2: number;
|
||||||
@@ -31,7 +31,7 @@ describe("online tests", function () {
|
|||||||
this.skip();
|
this.skip();
|
||||||
}
|
}
|
||||||
serverHandle = await startServer();
|
serverHandle = await startServer();
|
||||||
dc = new Deltachat(serverHandle.url)
|
dc = new DeltaChat(serverHandle.url)
|
||||||
|
|
||||||
dc.on("ALL", ({ id, contextId }) => {
|
dc.on("ALL", ({ id, contextId }) => {
|
||||||
if (id !== "Info") console.log(contextId, id);
|
if (id !== "Info") console.log(contextId, id);
|
||||||
@@ -182,17 +182,17 @@ describe("online tests", function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
async function waitForEvent(
|
async function waitForEvent(
|
||||||
dc: Deltachat,
|
dc: DeltaChat,
|
||||||
eventType: EventTypeName,
|
eventType: EventTypeName,
|
||||||
accountId: number,
|
accountId: number,
|
||||||
timeout: number = EVENT_TIMEOUT
|
timeout: number = EVENT_TIMEOUT
|
||||||
): Promise<DeltachatEvent> {
|
): Promise<DeltaChatEvent> {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const rejectTimeout = setTimeout(
|
const rejectTimeout = setTimeout(
|
||||||
() => reject(new Error('Timeout reached before event came in')),
|
() => reject(new Error('Timeout reached before event came in')),
|
||||||
timeout
|
timeout
|
||||||
)
|
)
|
||||||
const callback = (event: DeltachatEvent) => {
|
const callback = (event: DeltaChatEvent) => {
|
||||||
if (event.contextId == accountId) {
|
if (event.contextId == accountId) {
|
||||||
dc.off(eventType, callback);
|
dc.off(eventType, callback);
|
||||||
clearTimeout(rejectTimeout)
|
clearTimeout(rejectTimeout)
|
||||||
|
|||||||
Reference in New Issue
Block a user