Skip to content

Commit 97a9f99

Browse files
committed
chore: fixed importEtherpad
1 parent e5920da commit 97a9f99

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

src/node/db/Pad.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export const cleanText = (txt:string): string => txt.replace(/\r\n/g, '\n')
3939
.replace(/\xa0/g, ' ');
4040

4141
class Pad {
42-
db: DBFunctionsPromisified;
42+
db: DBFunctionsPromisified|Database;
4343
atext: AText;
4444
pool: AttributePool;
4545
head: number;
@@ -55,7 +55,7 @@ class Pad {
5555
* can be used to shard pad storage across multiple database backends, to put each pad in its
5656
* own database table, or to validate imported pad data before it is written to the database.
5757
*/
58-
constructor(id:string, database = db) {
58+
constructor(id:string, database: DBFunctionsPromisified|Database = db) {
5959
this.db = database;
6060
this.atext = makeAText('\n');
6161
this.pool = new AttributePool();
@@ -382,7 +382,7 @@ class Pad {
382382
});
383383
}
384384

385-
async init(text:string, authorId = '') {
385+
async init(text:string | null, authorId = '') {
386386
// try to load the pad
387387
const value = await this.db.get(`pad:${this.id}`);
388388

src/node/utils/ImportEtherpad.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
'use strict';
2-
3-
import {APool} from "../types/PadType";
4-
51
/**
62
* 2014 John McLear (Etherpad Foundation / McLear Ltd)
73
*
@@ -19,18 +15,18 @@ import {APool} from "../types/PadType";
1915
*/
2016

2117
import AttributePool from '../../static/js/AttributePool';
22-
const {Pad} = require('../db/Pad');
18+
import Pad from '../db/Pad';
2319
import Stream from './Stream';
24-
const authorManager = require('../db/AuthorManager');
25-
const db = require('../db/DB');
20+
import authorManager from '../db/AuthorManager';
21+
import db from '../db/DB';
2622
const hooks = require('../../static/js/pluginfw/hooks');
2723
import log4js from 'log4js';
2824
const supportedElems = require('../../static/js/contentcollector').supportedElems;
2925
import {Database} from 'ueberdb2';
3026

3127
const logger = log4js.getLogger('ImportEtherpad');
3228

33-
exports.setPadRaw = async (padId: string, r: string, authorId = '') => {
29+
export const setPadRaw = async (padId: string, r: string, authorId = '') => {
3430
const records = JSON.parse(r);
3531

3632
// get supported block Elements from plugins, we will use this later.
@@ -55,7 +51,7 @@ exports.setPadRaw = async (padId: string, r: string, authorId = '') => {
5551
// there is a problem with the data.
5652

5753
const data = new Map();
58-
const existingAuthors = new Set();
54+
const existingAuthors: Set<string> = new Set();
5955
const padDb = new Database('memory', {data});
6056
await padDb.init();
6157
try {
@@ -126,3 +122,7 @@ exports.setPadRaw = async (padId: string, r: string, authorId = '') => {
126122
})();
127123
for (const op of new Stream(writeOps).batch(100).buffer(99)) await op;
128124
};
125+
126+
export default {
127+
setPadRaw
128+
}

src/tests/backend/specs/ImportEtherpad.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import {MapArrayType} from "../../../node/types/MapType";
44

5-
const assert = require('assert').strict;
5+
import {strict as assert} from 'node:assert';
66
import authorManager from '../../../node/db/AuthorManager';
77
import db from '../../../node/db/DB';
88
const importEtherpad = require('../../../node/utils/ImportEtherpad');
@@ -70,7 +70,7 @@ describe(__filename, function () {
7070
const data:MapArrayType<any> = makeExport(authorId);
7171
data['pad:differentPadId:revs:0'] = data['pad:testing:revs:0'];
7272
delete data['pad:testing:revs:0'];
73-
assert.rejects(importEtherpad.setPadRaw(padId, JSON.stringify(data)), /unexpected pad ID/);
73+
await assert.rejects(importEtherpad.setPadRaw(padId, JSON.stringify(data)), /unexpected pad ID/);
7474
assert(!await authorManager.doesAuthorExist(authorId));
7575
assert(!await padManager.doesPadExist(padId));
7676
});

0 commit comments

Comments
 (0)