Skip to content

Commit c3ccbf8

Browse files
committed
CHANGE use eslint rule require-await to reduce build size
1 parent 01dc9fc commit c3ccbf8

32 files changed

+109
-90
lines changed

.eslintrc.json

+19-5
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
],
1818
"parser": "@typescript-eslint/parser",
1919
"parserOptions": {
20-
"extraFileExtensions": [".json"],
20+
"extraFileExtensions": [
21+
".json"
22+
],
2123
"ecmaVersion": 2018,
2224
"sourceType": "module",
2325
"project": "./tsconfig.lint.json"
@@ -142,6 +144,10 @@
142144
]
143145
}
144146
],
147+
// transpiling async-await produces a really big build size,
148+
// so we try to not use async if we do not have an await.
149+
"@typescript-eslint/require-await": "error",
150+
"require-await": "error",
145151
// overrides
146152
// TODO: remove these rules one by one
147153
// to be better aligned with the recommended settings
@@ -156,14 +162,22 @@
156162
"@typescript-eslint/restrict-plus-operands": "off",
157163
"@typescript-eslint/await-thenable": "off",
158164
"@typescript-eslint/no-unnecessary-type-assertion": "off",
159-
"@typescript-eslint/require-await": "off",
160-
"require-await": "off",
161165
"@typescript-eslint/no-misused-promises": "off",
162166
"@typescript-eslint/restrict-template-expressions": "off",
163167
"no-prototype-builtins": "off",
164168
"@typescript-eslint/ban-types": "off",
165-
"@typescript-eslint/no-unused-vars": ["error", { "argsIgnorePattern": "^_" }],
166-
"no-unused-vars": ["error", { "argsIgnorePattern": "^_" }],
169+
"@typescript-eslint/no-unused-vars": [
170+
"error",
171+
{
172+
"argsIgnorePattern": "^_"
173+
}
174+
],
175+
"no-unused-vars": [
176+
"error",
177+
{
178+
"argsIgnorePattern": "^_"
179+
}
180+
],
167181
"@typescript-eslint/triple-slash-reference": "off",
168182
"@typescript-eslint/no-inferrable-types": "off",
169183
"@typescript-eslint/explicit-module-boundary-types": "off",

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# RxDB Changelog
33

44
<!-- CHANGELOG NEWEST -->
5-
5+
- CHANGE use eslint rule `require-await` to reduce build size.
66
<!-- ADD new changes here! -->
77

88
<!-- /CHANGELOG NEWEST -->

config/karma.conf.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
// while the karma tests run, we need some things which we start here
44
const GraphQLServer = require('../test_tmp/helper/graphql-server');
5-
async function thingsWeNeed() {
5+
function thingsWeNeed() {
66
// we need one graphql server so the browser can sync to it
77
GraphQLServer.spawn([], 18000);
88
}

src/plugins/attachments.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import {
55
import {
66
blobBufferUtil,
77
createRevision,
8-
flatClone
8+
flatClone,
9+
PROMISE_RESOLVE_VOID
910
} from './../util';
1011
import {
1112
newRxError
@@ -69,7 +70,7 @@ export class RxAttachment {
6970
_assignMethodsToAttachment(this);
7071
}
7172

72-
async remove(): Promise<void> {
73+
remove(): Promise<void> {
7374
this.doc._atomicQueue = this.doc._atomicQueue
7475
.then(async () => {
7576
const docWriteData: RxDocumentWriteData<{}> = flatCloneDocWithMeta(this.doc._data);
@@ -312,12 +313,12 @@ export async function preMigrateDocument<RxDocType>(
312313
}
313314
}
314315

315-
export async function postMigrateDocument(_action: any): Promise<void> {
316+
export function postMigrateDocument(_action: any): Promise<void> {
316317
/**
317318
* No longer needed because
318319
* we store the attachemnts data buffers directly in the document.
319320
*/
320-
return;
321+
return PROMISE_RESOLVE_VOID;
321322
}
322323

323324
export const RxDBAttachmentsPlugin: RxPlugin = {

src/plugins/backup/file-util.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export function prepareFolders(
5959
});
6060
}
6161

62-
export async function writeToFile(
62+
export function writeToFile(
6363
location: string,
6464
data: string | Buffer
6565
): Promise<void> {
@@ -79,7 +79,7 @@ export async function writeToFile(
7979
});
8080
}
8181

82-
export async function writeJsonToFile(
82+
export function writeJsonToFile(
8383
location: string,
8484
data: any
8585
): Promise<void> {
@@ -96,7 +96,7 @@ export function metaFileLocation(options: BackupOptions): string {
9696
);
9797
}
9898

99-
export async function getMeta(options: BackupOptions): Promise<BackupMetaFileContent> {
99+
export function getMeta(options: BackupOptions): Promise<BackupMetaFileContent> {
100100
const loc = metaFileLocation(options);
101101
return new Promise((res, rej) => {
102102
fs.readFile(loc, 'utf-8', (err, data) => {
@@ -110,7 +110,7 @@ export async function getMeta(options: BackupOptions): Promise<BackupMetaFileCon
110110
});
111111
}
112112

113-
export async function setMeta(
113+
export function setMeta(
114114
options: BackupOptions,
115115
meta: BackupMetaFileContent
116116
): Promise<void> {

src/plugins/backup/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ export class RxBackupState {
122122
* Do not call this while it is already running.
123123
* Returns true if there are more documents to process
124124
*/
125-
public async persistOnce() {
125+
public persistOnce() {
126126
return this.persistRunning = this.persistRunning.then(() => this._persistOnce());
127127
}
128128

src/plugins/dexie/rx-storage-instance-dexie.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -408,11 +408,12 @@ export class RxStorageInstanceDexie<RxDocType> implements RxStorageInstance<
408408
throw new Error('Attachments are not implemented in the dexie RxStorage. Make a pull request.');
409409
}
410410

411-
async close(): Promise<void> {
411+
close(): Promise<void> {
412412
ensureNotClosed(this);
413413
this.closed = true;
414414
this.changes$.complete();
415415
closeDexieDb(this.internals);
416+
return PROMISE_RESOLVE_VOID;
416417
}
417418

418419
conflictResultionTasks(): Observable<RxConflictResultionTask<RxDocType>> {
@@ -423,7 +424,7 @@ export class RxStorageInstanceDexie<RxDocType> implements RxStorageInstance<
423424
}
424425

425426

426-
export async function createDexieStorageInstance<RxDocType>(
427+
export function createDexieStorageInstance<RxDocType>(
427428
storage: RxStorageDexie,
428429
params: RxStorageInstanceCreationParams<RxDocType, DexieSettings>,
429430
settings: DexieSettings
@@ -450,7 +451,7 @@ export async function createDexieStorageInstance<RxDocType>(
450451
instance
451452
);
452453

453-
return instance;
454+
return Promise.resolve(instance);
454455
}
455456

456457

src/plugins/encryption.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ export const RxDBEncryptionPlugin: RxPlugin = {
221221
}
222222
},
223223
preWriteAttachment: {
224-
after: async (args) => {
224+
after: (args) => {
225225
const password = args.database.password;
226226
const schema = args.schema
227227
if (
@@ -236,7 +236,7 @@ export const RxDBEncryptionPlugin: RxPlugin = {
236236
}
237237
},
238238
postReadAttachment: {
239-
after: async (args) => {
239+
after: (args) => {
240240
const password = args.database.password;
241241
const schema = args.schema
242242
if (

src/plugins/lokijs/rx-storage-instance-loki.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export class RxStorageInstanceLoki<RxDocType> implements RxStorageInstance<
8686
this.internals.leaderElector.awaitLeadership().then(() => {
8787
// this instance is leader now, so it has to reply to queries from other instances
8888
ensureNotFalsy(this.internals.leaderElector).broadcastChannel
89-
.addEventListener('message', async (msg) => handleRemoteRequest(this, msg));
89+
.addEventListener('message', (msg) => handleRemoteRequest(this, msg));
9090
});
9191
}
9292
}

src/plugins/memory/rx-storage-instance-memory.ts

+18-15
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import {
2929
getFromMapOrThrow,
3030
lastOfArray,
3131
now,
32+
PROMISE_RESOLVE_TRUE,
3233
PROMISE_RESOLVE_VOID,
3334
RX_META_LWT_MINIMUM
3435
} from '../../util';
@@ -65,8 +66,8 @@ export class RxStorageInstanceMemory<RxDocType> implements RxStorageInstance<
6566
> {
6667

6768
public readonly primaryPath: StringKeys<RxDocumentData<RxDocType>>;
68-
private changes$: Subject<EventBulk<RxStorageChangeEvent<RxDocumentData<RxDocType>>, RxStorageDefaultCheckpoint>> = new Subject();
6969
public closed = false;
70+
private changes$: Subject<EventBulk<RxStorageChangeEvent<RxDocumentData<RxDocType>>, RxStorageDefaultCheckpoint>> = new Subject();
7071

7172
constructor(
7273
public readonly storage: RxStorageMemory,
@@ -167,7 +168,7 @@ export class RxStorageInstanceMemory<RxDocType> implements RxStorageInstance<
167168
return Promise.resolve(ret);
168169
}
169170

170-
async findDocumentsById(
171+
findDocumentsById(
171172
docIds: string[],
172173
withDeleted: boolean
173174
): Promise<RxDocumentDataById<RxDocType>> {
@@ -187,7 +188,7 @@ export class RxStorageInstanceMemory<RxDocType> implements RxStorageInstance<
187188
return Promise.resolve(ret);
188189
}
189190

190-
async query(preparedQuery: MemoryPreparedQuery<RxDocType>): Promise<RxStorageQueryResult<RxDocType>> {
191+
query(preparedQuery: MemoryPreparedQuery<RxDocType>): Promise<RxStorageQueryResult<RxDocType>> {
191192
const queryPlan = preparedQuery.queryPlan;
192193
const query = preparedQuery.query;
193194
const skip = query.skip ? query.skip : 0;
@@ -261,12 +262,12 @@ export class RxStorageInstanceMemory<RxDocType> implements RxStorageInstance<
261262
// apply skip and limit boundaries.
262263
rows = rows.slice(skip, skipPlusLimit);
263264

264-
return {
265+
return Promise.resolve({
265266
documents: rows
266-
};
267+
});
267268
}
268269

269-
async getChangedDocumentsSince(
270+
getChangedDocumentsSince(
270271
limit: number,
271272
checkpoint?: RxStorageDefaultCheckpoint
272273
): Promise<{
@@ -306,7 +307,7 @@ export class RxStorageInstanceMemory<RxDocType> implements RxStorageInstance<
306307
}
307308

308309
const lastDoc = lastOfArray(rows);
309-
return {
310+
return Promise.resolve({
310311
documents: rows,
311312
checkpoint: lastDoc ? {
312313
id: lastDoc[this.primaryPath] as any,
@@ -315,10 +316,10 @@ export class RxStorageInstanceMemory<RxDocType> implements RxStorageInstance<
315316
id: '',
316317
lwt: 0
317318
}
318-
};
319+
});
319320
}
320321

321-
async cleanup(minimumDeletedTime: number): Promise<boolean> {
322+
cleanup(minimumDeletedTime: number): Promise<boolean> {
322323
const maxDeletionTime = now() - minimumDeletedTime;
323324
const index = ['_deleted', '_meta.lwt', this.primaryPath as any];
324325
const indexName = getMemoryIndexName(index);
@@ -357,7 +358,7 @@ export class RxStorageInstanceMemory<RxDocType> implements RxStorageInstance<
357358
indexOfLower++;
358359
}
359360
}
360-
return true;
361+
return PROMISE_RESOLVE_TRUE;
361362
}
362363

363364
getAttachmentData(documentId: string, attachmentId: string): Promise<string> {
@@ -384,12 +385,12 @@ export class RxStorageInstanceMemory<RxDocType> implements RxStorageInstance<
384385
await this.close();
385386
}
386387

387-
async close(): Promise<void> {
388+
close(): Promise<void> {
388389
if (this.closed) {
389-
throw newRxError('SNH', {
390+
return Promise.reject(newRxError('SNH', {
390391
database: this.databaseName,
391392
collection: this.collectionName
392-
});
393+
}));
393394
}
394395
this.closed = true;
395396
this.changes$.complete();
@@ -400,6 +401,8 @@ export class RxStorageInstanceMemory<RxDocType> implements RxStorageInstance<
400401
getMemoryCollectionKey(this.databaseName, this.collectionName)
401402
);
402403
}
404+
405+
return PROMISE_RESOLVE_VOID;
403406
}
404407

405408
conflictResultionTasks(): Observable<RxConflictResultionTask<RxDocType>> {
@@ -410,7 +413,7 @@ export class RxStorageInstanceMemory<RxDocType> implements RxStorageInstance<
410413
}
411414
}
412415

413-
export async function createMemoryStorageInstance<RxDocType>(
416+
export function createMemoryStorageInstance<RxDocType>(
414417
storage: RxStorageMemory,
415418
params: RxStorageInstanceCreationParams<RxDocType, RxStorageMemoryInstanceCreationOptions>,
416419
settings: RxStorageMemorySettings
@@ -442,5 +445,5 @@ export async function createMemoryStorageInstance<RxDocType>(
442445
params.options,
443446
settings
444447
);
445-
return instance;
448+
return Promise.resolve(instance);
446449
}

src/plugins/pouchdb/custom-events-plugin.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ export function addCustomEventsPluginToPouch() {
115115
/**
116116
* Ensure we do not run bulkDocs() in parallel on the same PouchDB instance.
117117
*/
118-
const newBulkDocs = async function (
118+
const newBulkDocs = function (
119119
this: PouchDBInstance,
120120
body: any[] | { docs: any[], new_edits?: boolean },
121121
options: PouchBulkDocOptions,

src/plugins/pouchdb/rx-storage-instance-pouch.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ export class RxStorageInstancePouch<RxDocType> implements RxStorageInstance<
100100
*/
101101
const emittedEventBulkIds: ObliviousSet<string> = new ObliviousSet(60 * 1000);
102102

103-
const eventSub = emitter.subject.subscribe(async (eventBulk) => {
103+
const eventSub = emitter.subject.subscribe((eventBulk) => {
104104
if (
105105
eventBulk.events.length === 0 ||
106106
emittedEventBulkIds.has(eventBulk.id)

src/plugins/pouchdb/rx-storage-pouchdb.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export class RxStoragePouch implements RxStorage<PouchStorageInternals, PouchSet
4747
checkPouchAdapter(adapter);
4848
}
4949

50-
private async createPouch(
50+
private createPouch(
5151
location: string,
5252
options: PouchSettings
5353
): Promise<PouchDBInstance> {
@@ -75,7 +75,7 @@ export class RxStoragePouch implements RxStorage<PouchStorageInternals, PouchSet
7575
*/
7676
// await pouch.info();
7777

78-
return pouch;
78+
return Promise.resolve(pouch);
7979
}
8080

8181
public async createStorageInstance<RxDocType>(
@@ -161,7 +161,7 @@ export async function createIndexesOnPouch(
161161
);
162162

163163
await Promise.all(
164-
schema.indexes.map(async (indexMaybeArray) => {
164+
schema.indexes.map((indexMaybeArray) => {
165165
let indexArray: MaybeReadonly<string[]> = isMaybeReadonlyArray(indexMaybeArray) ? indexMaybeArray : [indexMaybeArray];
166166

167167
/**

src/plugins/replication/index.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,9 @@ export class RxReplicationStateBase<RxDocType> {
191191
/**
192192
* Ensures that this._run() does not run in parallel
193193
*/
194-
async run(retryOnFail = true): Promise<void> {
194+
run(retryOnFail = true): Promise<void> {
195195
if (this.isStopped()) {
196-
return;
196+
return PROMISE_RESOLVE_VOID;
197197
}
198198

199199
if (this.runQueueCount > 2) {
@@ -231,7 +231,7 @@ export class RxReplicationStateBase<RxDocType> {
231231
* depending on when it is called and if another run() cycle is already
232232
* running.
233233
*/
234-
async notifyAboutRemoteChange() {
234+
notifyAboutRemoteChange() {
235235
const callTime = now();
236236
return new Promise<void>(res => {
237237
this.runningPromise = this.runningPromise.then(() => {

0 commit comments

Comments
 (0)