You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-11-26 17:03:12 +03:00
Iterate typing around sync, usage limits and errors (#2077)
This commit is contained in:
committed by
GitHub
parent
72643026a3
commit
3eaed30446
@@ -82,3 +82,12 @@ export enum HistoryVisibility {
|
|||||||
Shared = "shared",
|
Shared = "shared",
|
||||||
WorldReadable = "world_readable",
|
WorldReadable = "world_readable",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface IUsageLimit {
|
||||||
|
// "hs_disabled" is NOT a specced string, but is used in Synapse
|
||||||
|
// This is tracked over at https://github.com/matrix-org/synapse/issues/9237
|
||||||
|
// eslint-disable-next-line camelcase
|
||||||
|
limit_type: "monthly_active_user" | "hs_disabled" | string;
|
||||||
|
// eslint-disable-next-line camelcase
|
||||||
|
admin_contact?: string;
|
||||||
|
}
|
||||||
|
|||||||
@@ -97,7 +97,7 @@ import {
|
|||||||
IRecoveryKey,
|
IRecoveryKey,
|
||||||
ISecretStorageKeyInfo,
|
ISecretStorageKeyInfo,
|
||||||
} from "./crypto/api";
|
} from "./crypto/api";
|
||||||
import { SyncState } from "./sync.api";
|
import { SyncState } from "./sync";
|
||||||
import { EventTimelineSet } from "./models/event-timeline-set";
|
import { EventTimelineSet } from "./models/event-timeline-set";
|
||||||
import { VerificationRequest } from "./crypto/verification/request/VerificationRequest";
|
import { VerificationRequest } from "./crypto/verification/request/VerificationRequest";
|
||||||
import { VerificationBase as Verification } from "./crypto/verification/Base";
|
import { VerificationBase as Verification } from "./crypto/verification/Base";
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ import type { Request as _Request, CoreOptions } from "request";
|
|||||||
// waiting for the delay to elapse.
|
// waiting for the delay to elapse.
|
||||||
import * as callbacks from "./realtime-callbacks";
|
import * as callbacks from "./realtime-callbacks";
|
||||||
import { IUploadOpts } from "./@types/requests";
|
import { IUploadOpts } from "./@types/requests";
|
||||||
import { IAbortablePromise } from "./@types/partials";
|
import { IAbortablePromise, IUsageLimit } from "./@types/partials";
|
||||||
import { IDeferred } from "./utils";
|
import { IDeferred } from "./utils";
|
||||||
import { Callback } from "./client";
|
import { Callback } from "./client";
|
||||||
import * as utils from "./utils";
|
import * as utils from "./utils";
|
||||||
@@ -1015,7 +1015,7 @@ function getResponseContentType(response: XMLHttpRequest | IncomingMessage): Par
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
interface IErrorJson {
|
interface IErrorJson extends Partial<IUsageLimit> {
|
||||||
[key: string]: any; // extensible
|
[key: string]: any; // extensible
|
||||||
errcode?: string;
|
errcode?: string;
|
||||||
error?: string;
|
error?: string;
|
||||||
|
|||||||
@@ -1,26 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright 2021 The Matrix.org Foundation C.I.C.
|
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
// TODO: Merge this with sync.js once converted
|
|
||||||
|
|
||||||
export enum SyncState {
|
|
||||||
Error = "ERROR",
|
|
||||||
Prepared = "PREPARED",
|
|
||||||
Stopped = "STOPPED",
|
|
||||||
Syncing = "SYNCING",
|
|
||||||
Catchup = "CATCHUP",
|
|
||||||
Reconnecting = "RECONNECTING",
|
|
||||||
}
|
|
||||||
14
src/sync.ts
14
src/sync.ts
@@ -34,7 +34,6 @@ import { PushProcessor } from "./pushprocessor";
|
|||||||
import { logger } from './logger';
|
import { logger } from './logger';
|
||||||
import { InvalidStoreError } from './errors';
|
import { InvalidStoreError } from './errors';
|
||||||
import { IStoredClientOpts, MatrixClient, PendingEventOrdering } from "./client";
|
import { IStoredClientOpts, MatrixClient, PendingEventOrdering } from "./client";
|
||||||
import { SyncState } from "./sync.api";
|
|
||||||
import {
|
import {
|
||||||
Category,
|
Category,
|
||||||
IEphemeral,
|
IEphemeral,
|
||||||
@@ -68,6 +67,15 @@ const BUFFER_PERIOD_MS = 80 * 1000;
|
|||||||
// keepAlive is successful but the server /sync fails.
|
// keepAlive is successful but the server /sync fails.
|
||||||
const FAILED_SYNC_ERROR_THRESHOLD = 3;
|
const FAILED_SYNC_ERROR_THRESHOLD = 3;
|
||||||
|
|
||||||
|
export enum SyncState {
|
||||||
|
Error = "ERROR",
|
||||||
|
Prepared = "PREPARED",
|
||||||
|
Stopped = "STOPPED",
|
||||||
|
Syncing = "SYNCING",
|
||||||
|
Catchup = "CATCHUP",
|
||||||
|
Reconnecting = "RECONNECTING",
|
||||||
|
}
|
||||||
|
|
||||||
function getFilterName(userId: string, suffix?: string): string {
|
function getFilterName(userId: string, suffix?: string): string {
|
||||||
// scope this on the user ID because people may login on many accounts
|
// scope this on the user ID because people may login on many accounts
|
||||||
// and they all need to be stored!
|
// and they all need to be stored!
|
||||||
@@ -87,7 +95,7 @@ interface ISyncOptions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface ISyncStateData {
|
export interface ISyncStateData {
|
||||||
error?: Error;
|
error?: MatrixError;
|
||||||
oldSyncToken?: string;
|
oldSyncToken?: string;
|
||||||
nextSyncToken?: string;
|
nextSyncToken?: string;
|
||||||
catchingUp?: boolean;
|
catchingUp?: boolean;
|
||||||
@@ -477,7 +485,7 @@ export class SyncApi {
|
|||||||
return this.syncStateData;
|
return this.syncStateData;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async recoverFromSyncStartupError(savedSyncPromise: Promise<void>, err: Error): Promise<void> {
|
public async recoverFromSyncStartupError(savedSyncPromise: Promise<void>, err: MatrixError): Promise<void> {
|
||||||
// Wait for the saved sync to complete - we send the pushrules and filter requests
|
// Wait for the saved sync to complete - we send the pushrules and filter requests
|
||||||
// before the saved sync has finished so they can run in parallel, but only process
|
// before the saved sync has finished so they can run in parallel, but only process
|
||||||
// the results after the saved sync is done. Equivalently, we wait for it to finish
|
// the results after the saved sync is done. Equivalently, we wait for it to finish
|
||||||
|
|||||||
Reference in New Issue
Block a user