Skip to content
This repository was archived by the owner on Jun 24, 2025. It is now read-only.

Commit ad93fe4

Browse files
committed
server-esm: Remove dynamic imports due to past circular issues
1 parent efdae79 commit ad93fe4

File tree

5 files changed

+9
-23
lines changed

5 files changed

+9
-23
lines changed

src/becca/becca-interface.ts

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,7 @@ export default class Becca {
155155
}
156156

157157
getRevision(revisionId: string): BRevision | null {
158-
const row = sql.getRow("SELECT * FROM revisions WHERE revisionId = ?", [revisionId]);
159-
160-
const BRevision = require('./entities/brevision'); // avoiding circular dependency problems
158+
const row = sql.getRow<RevisionRow | null>("SELECT * FROM revisions WHERE revisionId = ?", [revisionId]);
161159
return row ? new BRevision(row) : null;
162160
}
163161

@@ -179,9 +177,7 @@ export default class Becca {
179177
WHERE attachmentId = ? AND isDeleted = 0`
180178
: `SELECT * FROM attachments WHERE attachmentId = ? AND isDeleted = 0`;
181179

182-
const BAttachment = require('./entities/battachment'); // avoiding circular dependency problems
183-
184-
return sql.getRows(query, [attachmentId])
180+
return sql.getRows<AttachmentRow>(query, [attachmentId])
185181
.map(row => new BAttachment(row))[0];
186182
}
187183

@@ -194,7 +190,6 @@ export default class Becca {
194190
}
195191

196192
getAttachments(attachmentIds: string[]): BAttachment[] {
197-
const BAttachment = require('./entities/battachment'); // avoiding circular dependency problems
198193
return sql.getManyRows<AttachmentRow>("SELECT * FROM attachments WHERE attachmentId IN (???) AND isDeleted = 0", attachmentIds)
199194
.map(row => new BAttachment(row));
200195
}
@@ -204,9 +199,7 @@ export default class Becca {
204199
return null;
205200
}
206201

207-
const row = sql.getRow("SELECT *, LENGTH(content) AS contentLength FROM blobs WHERE blobId = ?", [entity.blobId]);
208-
209-
const BBlob = require('./entities/bblob'); // avoiding circular dependency problems
202+
const row = sql.getRow<BBlob | null>("SELECT *, LENGTH(content) AS contentLength FROM blobs WHERE blobId = ?", [entity.blobId]);
210203
return row ? new BBlob(row) : null;
211204
}
212205

@@ -248,16 +241,12 @@ export default class Becca {
248241
}
249242

250243
getRecentNotesFromQuery(query: string, params: string[] = []): BRecentNote[] {
251-
const rows = sql.getRows(query, params);
252-
253-
const BRecentNote = require('./entities/brecent_note'); // avoiding circular dependency problems
244+
const rows = sql.getRows<BRecentNote>(query, params);
254245
return rows.map(row => new BRecentNote(row));
255246
}
256247

257248
getRevisionsFromQuery(query: string, params: string[] = []): BRevision[] {
258249
const rows = sql.getRows<RevisionRow>(query, params);
259-
260-
const BRevision = require('./entities/brevision'); // avoiding circular dependency problems
261250
return rows.map(row => new BRevision(row));
262251
}
263252

src/becca/entities/rows.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export interface OptionRow {
4242
name: string;
4343
value: string;
4444
isSynced: boolean;
45-
utcDateModified: string;
45+
utcDateModified?: string;
4646
}
4747

4848
export interface EtapiTokenRow {

src/services/options.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import becca from "../becca/becca.js";
2+
import BOption from "../becca/entities/boption.js";
23
import { OptionRow } from '../becca/entities/rows';
34
import sql from "./sql.js";
45

@@ -68,10 +69,7 @@ function setOption(name: string, value: string | number | boolean) {
6869
}
6970
}
7071

71-
function createOption(name: string, value: string | number, isSynced: boolean) {
72-
// to avoid circular dependency, need to find a better solution
73-
const BOption = require('../becca/entities/boption');
74-
72+
function createOption(name: string, value: string, isSynced: boolean) {
7573
new BOption({
7674
name: name,
7775
value: value,

src/services/search/services/search.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import BAttribute from "../../../becca/entities/battribute.js";
1616
import { SearchParams, TokenStructure } from "./types";
1717
import Expression from "../expressions/expression.js";
1818
import sql from "../../sql.js";
19+
import scriptService from "../../script.js";
1920

2021
function searchFromNote(note: BNote) {
2122
let searchResultNoteIds;
@@ -78,7 +79,6 @@ function searchFromRelation(note: BNote, relationName: string) {
7879
return [];
7980
}
8081

81-
const scriptService = require('../../script'); // TODO: to avoid circular dependency
8282
const result = scriptService.executeNote(scriptNote, {originEntity: note});
8383

8484
if (!Array.isArray(result)) {

src/services/sync.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import entityConstructor from "../becca/entity_constructor.js";
1919
import becca from "../becca/becca.js";
2020
import { EntityChange, EntityChangeRecord, EntityRow } from './entity_changes_interface';
2121
import { CookieJar, ExecOpts } from './request_interface';
22+
import setupService from "./setup.js";
2223

2324
let proxyToggle = true;
2425

@@ -107,8 +108,6 @@ async function sync() {
107108
}
108109

109110
async function login() {
110-
const setupService = require('./setup'); // circular dependency issue
111-
112111
if (!await setupService.hasSyncServerSchemaAndSeed()) {
113112
await setupService.sendSeedToSyncServer();
114113
}

0 commit comments

Comments
 (0)