Merge pull request #29948 from overleaf/ar/docstore-conversion-to-esm
[docstore] conversion to esm GitOrigin-RevId: 9d255047bd7ae25f2b0b38f3a721741e8a0b7ad8
This commit is contained in:
@@ -1,14 +1,16 @@
|
||||
const MongoManager = require('./MongoManager')
|
||||
const Errors = require('./Errors')
|
||||
const logger = require('@overleaf/logger')
|
||||
const Settings = require('@overleaf/settings')
|
||||
const crypto = require('node:crypto')
|
||||
const { ReadableString } = require('@overleaf/stream-utils')
|
||||
const RangeManager = require('./RangeManager')
|
||||
const PersistorManager = require('./PersistorManager')
|
||||
const pMap = require('p-map')
|
||||
const { streamToBuffer } = require('./StreamToBuffer')
|
||||
const { BSON } = require('mongodb-legacy')
|
||||
import MongoManager from './MongoManager.js'
|
||||
import Errors from './Errors.js'
|
||||
import logger from '@overleaf/logger'
|
||||
import Settings from '@overleaf/settings'
|
||||
import crypto from 'node:crypto'
|
||||
import { ReadableString } from '@overleaf/stream-utils'
|
||||
import RangeManager from './RangeManager.js'
|
||||
import PersistorManager from './PersistorManager.js'
|
||||
import pMap from 'p-map'
|
||||
import { streamToBuffer } from './StreamToBuffer.js'
|
||||
import mongodb from 'mongodb-legacy'
|
||||
|
||||
const { BSON } = mongodb
|
||||
|
||||
const PARALLEL_JOBS = Settings.parallelArchiveJobs
|
||||
const UN_ARCHIVE_BATCH_SIZE = Settings.unArchiveBatchSize
|
||||
@@ -220,7 +222,7 @@ function _isArchivingEnabled() {
|
||||
return true
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
export default {
|
||||
archiveAllDocs,
|
||||
archiveDoc,
|
||||
unArchiveAllDocs,
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
const MongoManager = require('./MongoManager')
|
||||
const Errors = require('./Errors')
|
||||
const logger = require('@overleaf/logger')
|
||||
const _ = require('lodash')
|
||||
const DocArchive = require('./DocArchiveManager')
|
||||
const RangeManager = require('./RangeManager')
|
||||
const Settings = require('@overleaf/settings')
|
||||
const { setTimeout } = require('node:timers/promises')
|
||||
import MongoManager from './MongoManager.js'
|
||||
import Errors from './Errors.js'
|
||||
import logger from '@overleaf/logger'
|
||||
import _ from 'lodash'
|
||||
import DocArchive from './DocArchiveManager.js'
|
||||
import RangeManager from './RangeManager.js'
|
||||
import Settings from '@overleaf/settings'
|
||||
import { setTimeout } from 'node:timers/promises'
|
||||
|
||||
/**
|
||||
* @import { Document } from 'mongodb'
|
||||
@@ -319,4 +319,4 @@ const DocManager = {
|
||||
},
|
||||
}
|
||||
|
||||
module.exports = DocManager
|
||||
export default DocManager
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// import Errors from object-persistor to pass instanceof checks
|
||||
const OError = require('@overleaf/o-error')
|
||||
const { Errors } = require('@overleaf/object-persistor')
|
||||
import OError from '@overleaf/o-error'
|
||||
|
||||
import { Errors } from '@overleaf/object-persistor'
|
||||
|
||||
class Md5MismatchError extends OError {}
|
||||
|
||||
@@ -12,7 +13,7 @@ class DocVersionDecrementedError extends OError {}
|
||||
|
||||
class DocWithoutLinesError extends OError {}
|
||||
|
||||
module.exports = {
|
||||
export default {
|
||||
Md5MismatchError,
|
||||
DocModifiedError,
|
||||
DocRevValueError,
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
const { db, ObjectId } = require('./mongodb')
|
||||
const _ = require('lodash')
|
||||
const crypto = require('node:crypto')
|
||||
const settings = require('@overleaf/settings')
|
||||
import mongodb from './mongodb.js'
|
||||
import _ from 'lodash'
|
||||
import crypto from 'node:crypto'
|
||||
import settings from '@overleaf/settings'
|
||||
import logger from '@overleaf/logger'
|
||||
import { fetchNothing, fetchJson } from '@overleaf/fetch-utils'
|
||||
|
||||
const { db, ObjectId } = mongodb
|
||||
|
||||
const { port } = settings.internal.docstore
|
||||
const logger = require('@overleaf/logger')
|
||||
const { fetchNothing, fetchJson } = require('@overleaf/fetch-utils')
|
||||
|
||||
async function check() {
|
||||
const docId = new ObjectId()
|
||||
@@ -30,6 +33,7 @@ async function check() {
|
||||
throw new Error(`health check lines not equal ${body.lines} != ${lines}`)
|
||||
}
|
||||
}
|
||||
module.exports = {
|
||||
|
||||
export default {
|
||||
check,
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
const DocManager = require('./DocManager')
|
||||
const logger = require('@overleaf/logger')
|
||||
const DocArchive = require('./DocArchiveManager')
|
||||
const HealthChecker = require('./HealthChecker')
|
||||
const Errors = require('./Errors')
|
||||
const Settings = require('@overleaf/settings')
|
||||
const { expressify } = require('@overleaf/promise-utils')
|
||||
import DocManager from './DocManager.js'
|
||||
import logger from '@overleaf/logger'
|
||||
import DocArchive from './DocArchiveManager.js'
|
||||
import HealthChecker from './HealthChecker.js'
|
||||
import Errors from './Errors.js'
|
||||
import Settings from '@overleaf/settings'
|
||||
import { expressify } from '@overleaf/promise-utils'
|
||||
|
||||
async function getDoc(req, res) {
|
||||
const { doc_id: docId, project_id: projectId } = req.params
|
||||
@@ -236,7 +236,7 @@ async function healthCheck(req, res) {
|
||||
res.sendStatus(200)
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
export default {
|
||||
getDoc: expressify(getDoc),
|
||||
peekDoc: expressify(peekDoc),
|
||||
isDocDeleted: expressify(isDocDeleted),
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
const { db, ObjectId } = require('./mongodb')
|
||||
const Settings = require('@overleaf/settings')
|
||||
const Errors = require('./Errors')
|
||||
import mongodb from './mongodb.js'
|
||||
import Settings from '@overleaf/settings'
|
||||
import Errors from './Errors.js'
|
||||
|
||||
const { db, ObjectId } = mongodb
|
||||
|
||||
const ARCHIVING_LOCK_DURATION_MS = Settings.archivingLockDurationMs
|
||||
|
||||
@@ -239,7 +241,7 @@ async function destroyProject(projectId) {
|
||||
await db.docs.deleteMany({ project_id: new ObjectId(projectId) })
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
export default {
|
||||
findDoc,
|
||||
getProjectsDeletedDocs,
|
||||
getProjectsDocs,
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
const settings = require('@overleaf/settings')
|
||||
import settings from '@overleaf/settings'
|
||||
import ObjectPersistor from '@overleaf/object-persistor'
|
||||
import AbstractPersistor from '@overleaf/object-persistor/src/AbstractPersistor.js'
|
||||
import Metrics from '@overleaf/metrics'
|
||||
|
||||
const persistorSettings = settings.docstore
|
||||
persistorSettings.Metrics = require('@overleaf/metrics')
|
||||
persistorSettings.Metrics = Metrics
|
||||
|
||||
const ObjectPersistor = require('@overleaf/object-persistor')
|
||||
const AbstractPersistor = require('@overleaf/object-persistor/src/AbstractPersistor')
|
||||
const persistor = settings.docstore.backend
|
||||
? ObjectPersistor(persistorSettings)
|
||||
: new AbstractPersistor()
|
||||
|
||||
module.exports = persistor
|
||||
export default persistor
|
||||
|
||||
@@ -10,11 +10,14 @@
|
||||
* DS207: Consider shorter variations of null checks
|
||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
||||
*/
|
||||
let RangeManager
|
||||
const _ = require('lodash')
|
||||
const { ObjectId } = require('./mongodb')
|
||||
import _ from 'lodash'
|
||||
import mongodb from './mongodb.js'
|
||||
|
||||
module.exports = RangeManager = {
|
||||
const { ObjectId } = mongodb
|
||||
|
||||
let RangeManager
|
||||
|
||||
export default RangeManager = {
|
||||
shouldUpdateRanges(docRanges, incomingRanges) {
|
||||
if (incomingRanges == null) {
|
||||
throw new Error('expected incoming_ranges')
|
||||
|
||||
@@ -1,13 +1,9 @@
|
||||
const { LoggerStream, WritableBuffer } = require('@overleaf/stream-utils')
|
||||
const Settings = require('@overleaf/settings')
|
||||
const logger = require('@overleaf/logger/logging-manager')
|
||||
const { pipeline } = require('node:stream/promises')
|
||||
import { LoggerStream, WritableBuffer } from '@overleaf/stream-utils'
|
||||
import Settings from '@overleaf/settings'
|
||||
import logger from '@overleaf/logger/logging-manager.js'
|
||||
import { pipeline } from 'node:stream/promises'
|
||||
|
||||
module.exports = {
|
||||
streamToBuffer,
|
||||
}
|
||||
|
||||
async function streamToBuffer(projectId, docId, stream) {
|
||||
export async function streamToBuffer(projectId, docId, stream) {
|
||||
const loggerTransform = new LoggerStream(
|
||||
Settings.max_doc_length,
|
||||
(size, isFlush) => {
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
// @ts-check
|
||||
|
||||
const Metrics = require('@overleaf/metrics')
|
||||
const Settings = require('@overleaf/settings')
|
||||
const MongoUtils = require('@overleaf/mongo-utils')
|
||||
const { MongoClient, ObjectId } = require('mongodb-legacy')
|
||||
import Metrics from '@overleaf/metrics'
|
||||
|
||||
import Settings from '@overleaf/settings'
|
||||
import MongoUtils from '@overleaf/mongo-utils'
|
||||
import mongodb from 'mongodb-legacy'
|
||||
|
||||
const { MongoClient, ObjectId } = mongodb
|
||||
|
||||
const mongoClient = new MongoClient(Settings.mongo.url, Settings.mongo.options)
|
||||
const mongoDb = mongoClient.db()
|
||||
@@ -18,7 +21,7 @@ async function cleanupTestDatabase() {
|
||||
await MongoUtils.cleanupTestDatabase(mongoClient)
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
export default {
|
||||
db,
|
||||
mongoClient,
|
||||
ObjectId,
|
||||
|
||||
Reference in New Issue
Block a user