mirror of
https://github.com/codex-team/codex.docs.git
synced 2025-07-18 20:59:42 +02:00
🤩MongoDB support 🤩 (#272)
* implement configuration through YAML * remove rcparser * use password from appConfig * update docker configs * fix dockerignore * implement mongodb driver * update eslint packages * fix bugs * refactor code for grouping by parent * fix yet another bug * use unique symbol to the EntityId type * fix more bugs * implement db converter * fix bug with parent selector * fix eslint * db-converter refactoring * create cli program for db-converter * add readme and gitignore * update development docs * update development docs and default config * add docs about converter * add src/test to docker ignore * move database code from utils * improve docs * eslint fix * add more docs * fix docs * remove env_file from docker-compose * implement duplicate detection in db-converter * use published version of the config-loader * fix bug * Update DEVELOPMENT.md Co-authored-by: Ilya Maroz <37909603+ilyamore88@users.noreply.github.com> * fix bugs * fix next/prev buttons * fix more bugs * fix sorting Co-authored-by: Ilya Maroz <37909603+ilyamore88@users.noreply.github.com>
This commit is contained in:
parent
13762096c4
commit
55b4b3ee61
72 changed files with 12614 additions and 665 deletions
14
bin/db-converter/.eslintrc
Normal file
14
bin/db-converter/.eslintrc
Normal file
|
@ -0,0 +1,14 @@
|
|||
{
|
||||
"extends": [
|
||||
"codex"
|
||||
],
|
||||
"env": {
|
||||
"es2022": true
|
||||
},
|
||||
"parser": "@babel/eslint-parser",
|
||||
"parserOptions": {
|
||||
"requireConfigFile": false,
|
||||
"sourceType": "module",
|
||||
"allowImportExportEverywhere": true
|
||||
}
|
||||
}
|
2
bin/db-converter/.gitignore
vendored
Normal file
2
bin/db-converter/.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
.yarn/unplugged
|
||||
.yarn/build-state.yml
|
10025
bin/db-converter/.pnp.cjs
generated
Executable file
10025
bin/db-converter/.pnp.cjs
generated
Executable file
File diff suppressed because one or more lines are too long
285
bin/db-converter/.pnp.loader.mjs
generated
Normal file
285
bin/db-converter/.pnp.loader.mjs
generated
Normal file
|
@ -0,0 +1,285 @@
|
|||
import { URL, fileURLToPath, pathToFileURL } from 'url';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import moduleExports, { Module } from 'module';
|
||||
|
||||
var PathType;
|
||||
(function(PathType2) {
|
||||
PathType2[PathType2["File"] = 0] = "File";
|
||||
PathType2[PathType2["Portable"] = 1] = "Portable";
|
||||
PathType2[PathType2["Native"] = 2] = "Native";
|
||||
})(PathType || (PathType = {}));
|
||||
const npath = Object.create(path);
|
||||
const ppath = Object.create(path.posix);
|
||||
npath.cwd = () => process.cwd();
|
||||
ppath.cwd = () => toPortablePath(process.cwd());
|
||||
ppath.resolve = (...segments) => {
|
||||
if (segments.length > 0 && ppath.isAbsolute(segments[0])) {
|
||||
return path.posix.resolve(...segments);
|
||||
} else {
|
||||
return path.posix.resolve(ppath.cwd(), ...segments);
|
||||
}
|
||||
};
|
||||
const contains = function(pathUtils, from, to) {
|
||||
from = pathUtils.normalize(from);
|
||||
to = pathUtils.normalize(to);
|
||||
if (from === to)
|
||||
return `.`;
|
||||
if (!from.endsWith(pathUtils.sep))
|
||||
from = from + pathUtils.sep;
|
||||
if (to.startsWith(from)) {
|
||||
return to.slice(from.length);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
npath.fromPortablePath = fromPortablePath;
|
||||
npath.toPortablePath = toPortablePath;
|
||||
npath.contains = (from, to) => contains(npath, from, to);
|
||||
ppath.contains = (from, to) => contains(ppath, from, to);
|
||||
const WINDOWS_PATH_REGEXP = /^([a-zA-Z]:.*)$/;
|
||||
const UNC_WINDOWS_PATH_REGEXP = /^\/\/(\.\/)?(.*)$/;
|
||||
const PORTABLE_PATH_REGEXP = /^\/([a-zA-Z]:.*)$/;
|
||||
const UNC_PORTABLE_PATH_REGEXP = /^\/unc\/(\.dot\/)?(.*)$/;
|
||||
function fromPortablePath(p) {
|
||||
if (process.platform !== `win32`)
|
||||
return p;
|
||||
let portablePathMatch, uncPortablePathMatch;
|
||||
if (portablePathMatch = p.match(PORTABLE_PATH_REGEXP))
|
||||
p = portablePathMatch[1];
|
||||
else if (uncPortablePathMatch = p.match(UNC_PORTABLE_PATH_REGEXP))
|
||||
p = `\\\\${uncPortablePathMatch[1] ? `.\\` : ``}${uncPortablePathMatch[2]}`;
|
||||
else
|
||||
return p;
|
||||
return p.replace(/\//g, `\\`);
|
||||
}
|
||||
function toPortablePath(p) {
|
||||
if (process.platform !== `win32`)
|
||||
return p;
|
||||
p = p.replace(/\\/g, `/`);
|
||||
let windowsPathMatch, uncWindowsPathMatch;
|
||||
if (windowsPathMatch = p.match(WINDOWS_PATH_REGEXP))
|
||||
p = `/${windowsPathMatch[1]}`;
|
||||
else if (uncWindowsPathMatch = p.match(UNC_WINDOWS_PATH_REGEXP))
|
||||
p = `/unc/${uncWindowsPathMatch[1] ? `.dot/` : ``}${uncWindowsPathMatch[2]}`;
|
||||
return p;
|
||||
}
|
||||
|
||||
const builtinModules = new Set(Module.builtinModules || Object.keys(process.binding(`natives`)));
|
||||
const isBuiltinModule = (request) => request.startsWith(`node:`) || builtinModules.has(request);
|
||||
function readPackageScope(checkPath) {
|
||||
const rootSeparatorIndex = checkPath.indexOf(npath.sep);
|
||||
let separatorIndex;
|
||||
do {
|
||||
separatorIndex = checkPath.lastIndexOf(npath.sep);
|
||||
checkPath = checkPath.slice(0, separatorIndex);
|
||||
if (checkPath.endsWith(`${npath.sep}node_modules`))
|
||||
return false;
|
||||
const pjson = readPackage(checkPath + npath.sep);
|
||||
if (pjson) {
|
||||
return {
|
||||
data: pjson,
|
||||
path: checkPath
|
||||
};
|
||||
}
|
||||
} while (separatorIndex > rootSeparatorIndex);
|
||||
return false;
|
||||
}
|
||||
function readPackage(requestPath) {
|
||||
const jsonPath = npath.resolve(requestPath, `package.json`);
|
||||
if (!fs.existsSync(jsonPath))
|
||||
return null;
|
||||
return JSON.parse(fs.readFileSync(jsonPath, `utf8`));
|
||||
}
|
||||
|
||||
const [major, minor] = process.versions.node.split(`.`).map((value) => parseInt(value, 10));
|
||||
const HAS_CONSOLIDATED_HOOKS = major > 16 || major === 16 && minor >= 12;
|
||||
const HAS_UNFLAGGED_JSON_MODULES = major > 17 || major === 17 && minor >= 5 || major === 16 && minor >= 15;
|
||||
const HAS_JSON_IMPORT_ASSERTION_REQUIREMENT = major > 17 || major === 17 && minor >= 1 || major === 16 && minor > 14;
|
||||
|
||||
async function tryReadFile(path2) {
|
||||
try {
|
||||
return await fs.promises.readFile(path2, `utf8`);
|
||||
} catch (error) {
|
||||
if (error.code === `ENOENT`)
|
||||
return null;
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
function tryParseURL(str, base) {
|
||||
try {
|
||||
return new URL(str, base);
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
let entrypointPath = null;
|
||||
function setEntrypointPath(file) {
|
||||
entrypointPath = file;
|
||||
}
|
||||
function getFileFormat(filepath) {
|
||||
var _a, _b;
|
||||
const ext = path.extname(filepath);
|
||||
switch (ext) {
|
||||
case `.mjs`: {
|
||||
return `module`;
|
||||
}
|
||||
case `.cjs`: {
|
||||
return `commonjs`;
|
||||
}
|
||||
case `.wasm`: {
|
||||
throw new Error(`Unknown file extension ".wasm" for ${filepath}`);
|
||||
}
|
||||
case `.json`: {
|
||||
if (HAS_UNFLAGGED_JSON_MODULES)
|
||||
return `json`;
|
||||
throw new Error(`Unknown file extension ".json" for ${filepath}`);
|
||||
}
|
||||
case `.js`: {
|
||||
const pkg = readPackageScope(filepath);
|
||||
if (!pkg)
|
||||
return `commonjs`;
|
||||
return (_a = pkg.data.type) != null ? _a : `commonjs`;
|
||||
}
|
||||
default: {
|
||||
if (entrypointPath !== filepath)
|
||||
return null;
|
||||
const pkg = readPackageScope(filepath);
|
||||
if (!pkg)
|
||||
return `commonjs`;
|
||||
if (pkg.data.type === `module`)
|
||||
return null;
|
||||
return (_b = pkg.data.type) != null ? _b : `commonjs`;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function getFormat$1(resolved, context, defaultGetFormat) {
|
||||
const url = tryParseURL(resolved);
|
||||
if ((url == null ? void 0 : url.protocol) !== `file:`)
|
||||
return defaultGetFormat(resolved, context, defaultGetFormat);
|
||||
const format = getFileFormat(fileURLToPath(url));
|
||||
if (format) {
|
||||
return {
|
||||
format
|
||||
};
|
||||
}
|
||||
return defaultGetFormat(resolved, context, defaultGetFormat);
|
||||
}
|
||||
|
||||
async function getSource$1(urlString, context, defaultGetSource) {
|
||||
const url = tryParseURL(urlString);
|
||||
if ((url == null ? void 0 : url.protocol) !== `file:`)
|
||||
return defaultGetSource(urlString, context, defaultGetSource);
|
||||
return {
|
||||
source: await fs.promises.readFile(fileURLToPath(url), `utf8`)
|
||||
};
|
||||
}
|
||||
|
||||
async function load$1(urlString, context, nextLoad) {
|
||||
var _a;
|
||||
const url = tryParseURL(urlString);
|
||||
if ((url == null ? void 0 : url.protocol) !== `file:`)
|
||||
return nextLoad(urlString, context, nextLoad);
|
||||
const filePath = fileURLToPath(url);
|
||||
const format = getFileFormat(filePath);
|
||||
if (!format)
|
||||
return nextLoad(urlString, context, nextLoad);
|
||||
if (HAS_JSON_IMPORT_ASSERTION_REQUIREMENT && format === `json` && ((_a = context.importAssertions) == null ? void 0 : _a.type) !== `json`) {
|
||||
const err = new TypeError(`[ERR_IMPORT_ASSERTION_TYPE_MISSING]: Module "${urlString}" needs an import assertion of type "json"`);
|
||||
err.code = `ERR_IMPORT_ASSERTION_TYPE_MISSING`;
|
||||
throw err;
|
||||
}
|
||||
return {
|
||||
format,
|
||||
source: await fs.promises.readFile(filePath, `utf8`),
|
||||
shortCircuit: true
|
||||
};
|
||||
}
|
||||
|
||||
const pathRegExp = /^(?![a-zA-Z]:[\\/]|\\\\|\.{0,2}(?:\/|$))((?:node:)?(?:@[^/]+\/)?[^/]+)\/*(.*|)$/;
|
||||
const isRelativeRegexp = /^\.{0,2}\//;
|
||||
async function resolve$1(originalSpecifier, context, nextResolve) {
|
||||
var _a;
|
||||
const {findPnpApi} = moduleExports;
|
||||
if (!findPnpApi || isBuiltinModule(originalSpecifier))
|
||||
return nextResolve(originalSpecifier, context, nextResolve);
|
||||
let specifier = originalSpecifier;
|
||||
const url = tryParseURL(specifier, isRelativeRegexp.test(specifier) ? context.parentURL : void 0);
|
||||
if (url) {
|
||||
if (url.protocol !== `file:`)
|
||||
return nextResolve(originalSpecifier, context, nextResolve);
|
||||
specifier = fileURLToPath(url);
|
||||
}
|
||||
const {parentURL, conditions = []} = context;
|
||||
const issuer = parentURL ? fileURLToPath(parentURL) : process.cwd();
|
||||
const pnpapi = (_a = findPnpApi(issuer)) != null ? _a : url ? findPnpApi(specifier) : null;
|
||||
if (!pnpapi)
|
||||
return nextResolve(originalSpecifier, context, nextResolve);
|
||||
const dependencyNameMatch = specifier.match(pathRegExp);
|
||||
let allowLegacyResolve = false;
|
||||
if (dependencyNameMatch) {
|
||||
const [, dependencyName, subPath] = dependencyNameMatch;
|
||||
if (subPath === ``) {
|
||||
const resolved = pnpapi.resolveToUnqualified(`${dependencyName}/package.json`, issuer);
|
||||
if (resolved) {
|
||||
const content = await tryReadFile(resolved);
|
||||
if (content) {
|
||||
const pkg = JSON.parse(content);
|
||||
allowLegacyResolve = pkg.exports == null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
const result = pnpapi.resolveRequest(specifier, issuer, {
|
||||
conditions: new Set(conditions),
|
||||
extensions: allowLegacyResolve ? void 0 : []
|
||||
});
|
||||
if (!result)
|
||||
throw new Error(`Resolving '${specifier}' from '${issuer}' failed`);
|
||||
const resultURL = pathToFileURL(result);
|
||||
if (url) {
|
||||
resultURL.search = url.search;
|
||||
resultURL.hash = url.hash;
|
||||
}
|
||||
if (!parentURL)
|
||||
setEntrypointPath(fileURLToPath(resultURL));
|
||||
return {
|
||||
url: resultURL.href,
|
||||
shortCircuit: true
|
||||
};
|
||||
}
|
||||
|
||||
const binding = process.binding(`fs`);
|
||||
const originalfstat = binding.fstat;
|
||||
const ZIP_MASK = 4278190080;
|
||||
const ZIP_MAGIC = 704643072;
|
||||
binding.fstat = function(...args) {
|
||||
const [fd, useBigint, req] = args;
|
||||
if ((fd & ZIP_MASK) === ZIP_MAGIC && useBigint === false && req === void 0) {
|
||||
try {
|
||||
const stats = fs.fstatSync(fd);
|
||||
return new Float64Array([
|
||||
stats.dev,
|
||||
stats.mode,
|
||||
stats.nlink,
|
||||
stats.uid,
|
||||
stats.gid,
|
||||
stats.rdev,
|
||||
stats.blksize,
|
||||
stats.ino,
|
||||
stats.size,
|
||||
stats.blocks
|
||||
]);
|
||||
} catch {
|
||||
}
|
||||
}
|
||||
return originalfstat.apply(this, args);
|
||||
};
|
||||
|
||||
const resolve = resolve$1;
|
||||
const getFormat = HAS_CONSOLIDATED_HOOKS ? void 0 : getFormat$1;
|
||||
const getSource = HAS_CONSOLIDATED_HOOKS ? void 0 : getSource$1;
|
||||
const load = HAS_CONSOLIDATED_HOOKS ? load$1 : void 0;
|
||||
|
||||
export { getFormat, getSource, load, resolve };
|
BIN
bin/db-converter/.yarn/cache/@types-node-npm-18.7.23-070e968159-2c8df0830d.zip
vendored
Normal file
BIN
bin/db-converter/.yarn/cache/@types-node-npm-18.7.23-070e968159-2c8df0830d.zip
vendored
Normal file
Binary file not shown.
BIN
bin/db-converter/.yarn/cache/@types-webidl-conversions-npm-7.0.0-0903313151-60142c7ddd.zip
vendored
Normal file
BIN
bin/db-converter/.yarn/cache/@types-webidl-conversions-npm-7.0.0-0903313151-60142c7ddd.zip
vendored
Normal file
Binary file not shown.
BIN
bin/db-converter/.yarn/cache/@types-whatwg-url-npm-8.2.2-54c5c24e6c-5dc5afe078.zip
vendored
Normal file
BIN
bin/db-converter/.yarn/cache/@types-whatwg-url-npm-8.2.2-54c5c24e6c-5dc5afe078.zip
vendored
Normal file
Binary file not shown.
BIN
bin/db-converter/.yarn/cache/base64-js-npm-1.5.1-b2f7275641-669632eb37.zip
vendored
Normal file
BIN
bin/db-converter/.yarn/cache/base64-js-npm-1.5.1-b2f7275641-669632eb37.zip
vendored
Normal file
Binary file not shown.
BIN
bin/db-converter/.yarn/cache/bson-npm-4.7.0-b334c59903-83e7b64afd.zip
vendored
Normal file
BIN
bin/db-converter/.yarn/cache/bson-npm-4.7.0-b334c59903-83e7b64afd.zip
vendored
Normal file
Binary file not shown.
BIN
bin/db-converter/.yarn/cache/buffer-npm-5.7.1-513ef8259e-e2cf8429e1.zip
vendored
Normal file
BIN
bin/db-converter/.yarn/cache/buffer-npm-5.7.1-513ef8259e-e2cf8429e1.zip
vendored
Normal file
Binary file not shown.
BIN
bin/db-converter/.yarn/cache/commander-npm-9.4.1-9deffb2749-bfb18e325a.zip
vendored
Normal file
BIN
bin/db-converter/.yarn/cache/commander-npm-9.4.1-9deffb2749-bfb18e325a.zip
vendored
Normal file
Binary file not shown.
BIN
bin/db-converter/.yarn/cache/denque-npm-2.1.0-578d0b6297-1d4ae1d05e.zip
vendored
Normal file
BIN
bin/db-converter/.yarn/cache/denque-npm-2.1.0-578d0b6297-1d4ae1d05e.zip
vendored
Normal file
Binary file not shown.
BIN
bin/db-converter/.yarn/cache/ieee754-npm-1.2.1-fb63b3caeb-5144c0c981.zip
vendored
Normal file
BIN
bin/db-converter/.yarn/cache/ieee754-npm-1.2.1-fb63b3caeb-5144c0c981.zip
vendored
Normal file
Binary file not shown.
BIN
bin/db-converter/.yarn/cache/ip-npm-2.0.0-204facb3cc-cfcfac6b87.zip
vendored
Normal file
BIN
bin/db-converter/.yarn/cache/ip-npm-2.0.0-204facb3cc-cfcfac6b87.zip
vendored
Normal file
Binary file not shown.
BIN
bin/db-converter/.yarn/cache/memory-pager-npm-1.5.0-46e20e6c81-d1a2e68458.zip
vendored
Normal file
BIN
bin/db-converter/.yarn/cache/memory-pager-npm-1.5.0-46e20e6c81-d1a2e68458.zip
vendored
Normal file
Binary file not shown.
BIN
bin/db-converter/.yarn/cache/mongodb-connection-string-url-npm-2.5.4-c420109e4e-9f431826b2.zip
vendored
Normal file
BIN
bin/db-converter/.yarn/cache/mongodb-connection-string-url-npm-2.5.4-c420109e4e-9f431826b2.zip
vendored
Normal file
Binary file not shown.
BIN
bin/db-converter/.yarn/cache/mongodb-npm-4.10.0-99903c2c4a-4847fe69b6.zip
vendored
Normal file
BIN
bin/db-converter/.yarn/cache/mongodb-npm-4.10.0-99903c2c4a-4847fe69b6.zip
vendored
Normal file
Binary file not shown.
BIN
bin/db-converter/.yarn/cache/punycode-npm-2.1.1-26eb3e15cf-823bf443c6.zip
vendored
Normal file
BIN
bin/db-converter/.yarn/cache/punycode-npm-2.1.1-26eb3e15cf-823bf443c6.zip
vendored
Normal file
Binary file not shown.
BIN
bin/db-converter/.yarn/cache/saslprep-npm-1.0.3-8db649c346-4fdc0b70fb.zip
vendored
Normal file
BIN
bin/db-converter/.yarn/cache/saslprep-npm-1.0.3-8db649c346-4fdc0b70fb.zip
vendored
Normal file
Binary file not shown.
BIN
bin/db-converter/.yarn/cache/smart-buffer-npm-4.2.0-5ac3f668bb-b5167a7142.zip
vendored
Normal file
BIN
bin/db-converter/.yarn/cache/smart-buffer-npm-4.2.0-5ac3f668bb-b5167a7142.zip
vendored
Normal file
Binary file not shown.
BIN
bin/db-converter/.yarn/cache/socks-npm-2.7.1-17f2b53052-259d9e3e8e.zip
vendored
Normal file
BIN
bin/db-converter/.yarn/cache/socks-npm-2.7.1-17f2b53052-259d9e3e8e.zip
vendored
Normal file
Binary file not shown.
BIN
bin/db-converter/.yarn/cache/sparse-bitfield-npm-3.0.3-cb80d0c89f-174da88dbb.zip
vendored
Normal file
BIN
bin/db-converter/.yarn/cache/sparse-bitfield-npm-3.0.3-cb80d0c89f-174da88dbb.zip
vendored
Normal file
Binary file not shown.
BIN
bin/db-converter/.yarn/cache/tr46-npm-3.0.0-e1ae1ea7c9-44c3cc6767.zip
vendored
Normal file
BIN
bin/db-converter/.yarn/cache/tr46-npm-3.0.0-e1ae1ea7c9-44c3cc6767.zip
vendored
Normal file
Binary file not shown.
BIN
bin/db-converter/.yarn/cache/webidl-conversions-npm-7.0.0-e8c8e30c68-f05588567a.zip
vendored
Normal file
BIN
bin/db-converter/.yarn/cache/webidl-conversions-npm-7.0.0-e8c8e30c68-f05588567a.zip
vendored
Normal file
Binary file not shown.
BIN
bin/db-converter/.yarn/cache/whatwg-url-npm-11.0.0-073529d93a-ed4826aaa5.zip
vendored
Normal file
BIN
bin/db-converter/.yarn/cache/whatwg-url-npm-11.0.0-073529d93a-ed4826aaa5.zip
vendored
Normal file
Binary file not shown.
BIN
bin/db-converter/.yarn/install-state.gz
Normal file
BIN
bin/db-converter/.yarn/install-state.gz
Normal file
Binary file not shown.
783
bin/db-converter/.yarn/releases/yarn-3.2.3.cjs
vendored
Executable file
783
bin/db-converter/.yarn/releases/yarn-3.2.3.cjs
vendored
Executable file
File diff suppressed because one or more lines are too long
1
bin/db-converter/.yarnrc.yml
Normal file
1
bin/db-converter/.yarnrc.yml
Normal file
|
@ -0,0 +1 @@
|
|||
yarnPath: .yarn/releases/yarn-3.2.3.cjs
|
10
bin/db-converter/README.md
Normal file
10
bin/db-converter/README.md
Normal file
|
@ -0,0 +1,10 @@
|
|||
# db-converter
|
||||
|
||||
Converts a database from local to MongoDB.
|
||||
It can be useful for migrating from a local database to MongoDB.
|
||||
|
||||
## Usage
|
||||
|
||||
```bash
|
||||
node index.js --db-path .db --mongodb-url mongodb://localhost:27017
|
||||
```
|
70
bin/db-converter/index.js
Normal file
70
bin/db-converter/index.js
Normal file
|
@ -0,0 +1,70 @@
|
|||
import './program.js';
|
||||
import {ObjectId} from 'mongodb';
|
||||
import {closeConnection, getFromLocalDB, saveData} from './lib.js';
|
||||
|
||||
console.log('Start converting...');
|
||||
const [pages, aliases, files, pagesOrder] = ['pages', 'aliases', 'files', 'pagesOrder'].map(getFromLocalDB);
|
||||
|
||||
const pagesIdsMap = pages.reduce((acc, curr) => {
|
||||
const newId = new ObjectId();
|
||||
|
||||
if (acc.has(curr._id)) {
|
||||
console.log(`Duplicate id detected ${curr._id}. Skipping it`);
|
||||
}
|
||||
|
||||
acc.set(curr._id, newId);
|
||||
|
||||
return acc;
|
||||
}, new Map());
|
||||
|
||||
// Explicitly set the root page id
|
||||
pagesIdsMap.set('0', '0');
|
||||
|
||||
const newPages = [];
|
||||
|
||||
pagesIdsMap.forEach((newId, oldId) => {
|
||||
if (newId === '0') {
|
||||
return
|
||||
}
|
||||
const page = pages.find((p) => p._id === oldId);
|
||||
newPages.push({
|
||||
...page,
|
||||
_id: newId,
|
||||
parent: page.parent ? pagesIdsMap.get(page.parent) : null,
|
||||
});
|
||||
});
|
||||
|
||||
await saveData('pages', newPages);
|
||||
|
||||
const newAliases = aliases.map(alias => {
|
||||
return {
|
||||
...alias,
|
||||
_id: new ObjectId(),
|
||||
id: pagesIdsMap.get(alias.id),
|
||||
};
|
||||
});
|
||||
|
||||
await saveData('aliases', newAliases);
|
||||
|
||||
const newFiles = files.map(file => {
|
||||
return {
|
||||
...file,
|
||||
_id: new ObjectId(),
|
||||
};
|
||||
});
|
||||
|
||||
await saveData('files', newFiles);
|
||||
|
||||
const newPagesOrder = pagesOrder.map(pageOrder => {
|
||||
return {
|
||||
...pageOrder,
|
||||
_id: new ObjectId(),
|
||||
page: pagesIdsMap.get(pageOrder.page),
|
||||
order: pageOrder.order.map(page => pagesIdsMap.get(page)),
|
||||
};
|
||||
});
|
||||
|
||||
await saveData('pagesOrder', newPagesOrder);
|
||||
|
||||
await closeConnection();
|
||||
console.log('Done!');
|
48
bin/db-converter/lib.js
Normal file
48
bin/db-converter/lib.js
Normal file
|
@ -0,0 +1,48 @@
|
|||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import { MongoClient } from 'mongodb';
|
||||
import { options } from './program.js';
|
||||
const mongoClient = await MongoClient.connect(options.mongodbUri);
|
||||
const db = mongoClient.db();
|
||||
|
||||
/**
|
||||
* Returns data from local database as JSON object
|
||||
*
|
||||
* @param {string} filename - name of the file to read
|
||||
* @returns {object} - JSON data
|
||||
*/
|
||||
export function getFromLocalDB(filename) {
|
||||
const filePath = path.resolve(process.cwd(), `${options.dbPath}/${filename}.db`);
|
||||
const rawData = fs.readFileSync(filePath);
|
||||
|
||||
const convertedData = String(rawData)
|
||||
.replace(/\n/gi, ',')
|
||||
.slice(0, -1);
|
||||
|
||||
return JSON.parse(`[${convertedData}]`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves data to MongoDB
|
||||
*
|
||||
* @param {string} collectionName - collection to which data will be saved
|
||||
* @param {object[]} data - data to save
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
export async function saveData(collectionName, data) {
|
||||
console.log(`Saving ${data.length} items to ${collectionName}...`);
|
||||
const collection = db.collection(collectionName);
|
||||
|
||||
await collection.deleteMany({});
|
||||
await collection.insertMany(data);
|
||||
console.log(`Saved ${data.length} items to ${collectionName}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes connection to MongoDB
|
||||
*
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
export async function closeConnection() {
|
||||
await mongoClient.close();
|
||||
}
|
12
bin/db-converter/package.json
Normal file
12
bin/db-converter/package.json
Normal file
|
@ -0,0 +1,12 @@
|
|||
{
|
||||
"name": "db-converter",
|
||||
"version": "1.0.0",
|
||||
"main": "index.js",
|
||||
"license": "MIT",
|
||||
"type": "module",
|
||||
"dependencies": {
|
||||
"commander": "^9.4.1",
|
||||
"mongodb": "^4.10.0"
|
||||
},
|
||||
"packageManager": "yarn@3.2.3"
|
||||
}
|
14
bin/db-converter/program.js
Normal file
14
bin/db-converter/program.js
Normal file
|
@ -0,0 +1,14 @@
|
|||
import { Command } from 'commander';
|
||||
|
||||
const program = new Command();
|
||||
|
||||
program
|
||||
.name('db-converter')
|
||||
.description('Converts data from local database to MongoDB')
|
||||
.option('--db-path <path>', 'Path to the local database', './db')
|
||||
.option('--mongodb-uri <uri>', 'URI to the MongoDB database', 'mongodb://localhost:27017/docs')
|
||||
.parse();
|
||||
|
||||
const options = program.opts();
|
||||
|
||||
export { options };
|
194
bin/db-converter/yarn.lock
Normal file
194
bin/db-converter/yarn.lock
Normal file
|
@ -0,0 +1,194 @@
|
|||
# This file is generated by running "yarn install" inside your project.
|
||||
# Manual changes might be lost - proceed with caution!
|
||||
|
||||
__metadata:
|
||||
version: 6
|
||||
cacheKey: 8
|
||||
|
||||
"@types/node@npm:*":
|
||||
version: 18.7.23
|
||||
resolution: "@types/node@npm:18.7.23"
|
||||
checksum: 2c8df0830d8345e5cd1ca17feb9cf43fa667aae749888e0a068c5c1b35eaedd2f9b24ed987a0758078395edf7a03681e5e0b7790a518ff7afe1ff6d8459f7b4a
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@types/webidl-conversions@npm:*":
|
||||
version: 7.0.0
|
||||
resolution: "@types/webidl-conversions@npm:7.0.0"
|
||||
checksum: 60142c7ddd9eb6f907d232d6b3a81ecf990f73b5a62a004eba8bd0f54809a42ece68ce512e7e3e1d98af8b6393d66cddb96f3622d2fb223c4e9c8937c61bfed7
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@types/whatwg-url@npm:^8.2.1":
|
||||
version: 8.2.2
|
||||
resolution: "@types/whatwg-url@npm:8.2.2"
|
||||
dependencies:
|
||||
"@types/node": "*"
|
||||
"@types/webidl-conversions": "*"
|
||||
checksum: 5dc5afe078dfa1a8a266745586fa3db9baa8ce7cc904789211d1dca1d34d7f3dd17d0b7423c36bc9beab9d98aa99338f1fc60798c0af6cbb8356f20e20d9f243
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"base64-js@npm:^1.3.1":
|
||||
version: 1.5.1
|
||||
resolution: "base64-js@npm:1.5.1"
|
||||
checksum: 669632eb3745404c2f822a18fc3a0122d2f9a7a13f7fb8b5823ee19d1d2ff9ee5b52c53367176ea4ad093c332fd5ab4bd0ebae5a8e27917a4105a4cfc86b1005
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"bson@npm:^4.7.0":
|
||||
version: 4.7.0
|
||||
resolution: "bson@npm:4.7.0"
|
||||
dependencies:
|
||||
buffer: ^5.6.0
|
||||
checksum: 83e7b64afdad5a505073a7e6206e7b345f59e7888fbcb1948fba72b6101a1baf58b7499314f8e24b650567665f7973eda048aabbb1ddcfbadfba7d6c6b0f5e83
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"buffer@npm:^5.6.0":
|
||||
version: 5.7.1
|
||||
resolution: "buffer@npm:5.7.1"
|
||||
dependencies:
|
||||
base64-js: ^1.3.1
|
||||
ieee754: ^1.1.13
|
||||
checksum: e2cf8429e1c4c7b8cbd30834ac09bd61da46ce35f5c22a78e6c2f04497d6d25541b16881e30a019c6fd3154150650ccee27a308eff3e26229d788bbdeb08ab84
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"commander@npm:^9.4.1":
|
||||
version: 9.4.1
|
||||
resolution: "commander@npm:9.4.1"
|
||||
checksum: bfb18e325a5bdf772763c2213d5c7d9e77144d944124e988bcd8e5e65fb6d45d5d4e86b09155d0f2556c9a59c31e428720e57968bcd050b2306e910a0bf3cf13
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"db-converter@workspace:.":
|
||||
version: 0.0.0-use.local
|
||||
resolution: "db-converter@workspace:."
|
||||
dependencies:
|
||||
commander: ^9.4.1
|
||||
mongodb: ^4.10.0
|
||||
languageName: unknown
|
||||
linkType: soft
|
||||
|
||||
"denque@npm:^2.1.0":
|
||||
version: 2.1.0
|
||||
resolution: "denque@npm:2.1.0"
|
||||
checksum: 1d4ae1d05e59ac3a3481e7b478293f4b4c813819342273f3d5b826c7ffa9753c520919ba264f377e09108d24ec6cf0ec0ac729a5686cbb8f32d797126c5dae74
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"ieee754@npm:^1.1.13":
|
||||
version: 1.2.1
|
||||
resolution: "ieee754@npm:1.2.1"
|
||||
checksum: 5144c0c9815e54ada181d80a0b810221a253562422e7c6c3a60b1901154184f49326ec239d618c416c1c5945a2e197107aee8d986a3dd836b53dffefd99b5e7e
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"ip@npm:^2.0.0":
|
||||
version: 2.0.0
|
||||
resolution: "ip@npm:2.0.0"
|
||||
checksum: cfcfac6b873b701996d71ec82a7dd27ba92450afdb421e356f44044ed688df04567344c36cbacea7d01b1c39a4c732dc012570ebe9bebfb06f27314bca625349
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"memory-pager@npm:^1.0.2":
|
||||
version: 1.5.0
|
||||
resolution: "memory-pager@npm:1.5.0"
|
||||
checksum: d1a2e684583ef55c61cd3a49101da645b11ad57014dfc565e0b43baa9004b743f7e4ab81493d8fff2ab24e9950987cc3209c94bcc4fc8d7e30a475489a1f15e9
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"mongodb-connection-string-url@npm:^2.5.3":
|
||||
version: 2.5.4
|
||||
resolution: "mongodb-connection-string-url@npm:2.5.4"
|
||||
dependencies:
|
||||
"@types/whatwg-url": ^8.2.1
|
||||
whatwg-url: ^11.0.0
|
||||
checksum: 9f431826b229488808e4a8a9e6bdde0162be3e6d5cad40867b69b2199ce009f568b67dc1bf587a43367904d8184f1c68689f7ea6574ed40b396726abde9485e1
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"mongodb@npm:^4.10.0":
|
||||
version: 4.10.0
|
||||
resolution: "mongodb@npm:4.10.0"
|
||||
dependencies:
|
||||
bson: ^4.7.0
|
||||
denque: ^2.1.0
|
||||
mongodb-connection-string-url: ^2.5.3
|
||||
saslprep: ^1.0.3
|
||||
socks: ^2.7.0
|
||||
dependenciesMeta:
|
||||
saslprep:
|
||||
optional: true
|
||||
checksum: 4847fe69b6d3baddc440936d306b4d00fa40a1dafabd387f9fb6f3ecd63b27c41f11b2cc46774ac2bf17e9b508d35908ebe21f47badf3449fb7afcbde2733951
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"punycode@npm:^2.1.1":
|
||||
version: 2.1.1
|
||||
resolution: "punycode@npm:2.1.1"
|
||||
checksum: 823bf443c6dd14f669984dea25757b37993f67e8d94698996064035edd43bed8a5a17a9f12e439c2b35df1078c6bec05a6c86e336209eb1061e8025c481168e8
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"saslprep@npm:^1.0.3":
|
||||
version: 1.0.3
|
||||
resolution: "saslprep@npm:1.0.3"
|
||||
dependencies:
|
||||
sparse-bitfield: ^3.0.3
|
||||
checksum: 4fdc0b70fb5e523f977de405e12cca111f1f10dd68a0cfae0ca52c1a7919a94d1556598ba2d35f447655c3b32879846c77f9274c90806f6673248ae3cea6ee43
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"smart-buffer@npm:^4.2.0":
|
||||
version: 4.2.0
|
||||
resolution: "smart-buffer@npm:4.2.0"
|
||||
checksum: b5167a7142c1da704c0e3af85c402002b597081dd9575031a90b4f229ca5678e9a36e8a374f1814c8156a725d17008ae3bde63b92f9cfd132526379e580bec8b
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"socks@npm:^2.7.0":
|
||||
version: 2.7.1
|
||||
resolution: "socks@npm:2.7.1"
|
||||
dependencies:
|
||||
ip: ^2.0.0
|
||||
smart-buffer: ^4.2.0
|
||||
checksum: 259d9e3e8e1c9809a7f5c32238c3d4d2a36b39b83851d0f573bfde5f21c4b1288417ce1af06af1452569cd1eb0841169afd4998f0e04ba04656f6b7f0e46d748
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"sparse-bitfield@npm:^3.0.3":
|
||||
version: 3.0.3
|
||||
resolution: "sparse-bitfield@npm:3.0.3"
|
||||
dependencies:
|
||||
memory-pager: ^1.0.2
|
||||
checksum: 174da88dbbcc783d5dbd26921931cc83830280b8055fb05333786ebe6fc015b9601b24972b3d55920dd2d9f5fb120576fbfa2469b08e5222c9cadf3f05210aab
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"tr46@npm:^3.0.0":
|
||||
version: 3.0.0
|
||||
resolution: "tr46@npm:3.0.0"
|
||||
dependencies:
|
||||
punycode: ^2.1.1
|
||||
checksum: 44c3cc6767fb800490e6e9fd64fd49041aa4e49e1f6a012b34a75de739cc9ed3a6405296072c1df8b6389ae139c5e7c6496f659cfe13a04a4bff3a1422981270
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"webidl-conversions@npm:^7.0.0":
|
||||
version: 7.0.0
|
||||
resolution: "webidl-conversions@npm:7.0.0"
|
||||
checksum: f05588567a2a76428515333eff87200fae6c83c3948a7482ebb109562971e77ef6dc49749afa58abb993391227c5697b3ecca52018793e0cb4620a48f10bd21b
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"whatwg-url@npm:^11.0.0":
|
||||
version: 11.0.0
|
||||
resolution: "whatwg-url@npm:11.0.0"
|
||||
dependencies:
|
||||
tr46: ^3.0.0
|
||||
webidl-conversions: ^7.0.0
|
||||
checksum: ed4826aaa57e66bb3488a4b25c9cd476c46ba96052747388b5801f137dd740b73fde91ad207d96baf9f17fbcc80fc1a477ad65181b5eb5fa718d27c69501d7af
|
||||
languageName: node
|
||||
linkType: hard
|
Loading…
Add table
Add a link
Reference in a new issue