mongoku
Version:
[](https://github.com/huggingface/Mongoku/actions/workflows/ci.yml)
138 lines (131 loc) • 5.41 kB
JavaScript
import { J as JsonEncoder } from './JsonEncoder-Dgtqxb_U.js';
import { l as logger } from './logger-PfH_grbh.js';
import { g as getMongo } from './mongo-B92d7zNj.js';
import 'mongodb';
import './shared-server-BmU87nph.js';
import 'async_hooks';
import 'node:util';
import 'dns/promises';
import 'url';
import 'node:fs';
import 'node:os';
import 'node:path';
const load$1 = async (data) => {
return {
...data.data,
categories: [
{ key: "documents", label: "Documents" },
{ key: "indexes", label: "Indexes" },
{ key: "mappings", label: "Mappings" },
{ key: "schema", label: "Schema" }
]
};
};
var _page_ts = /*#__PURE__*/Object.freeze({
__proto__: null,
load: load$1
});
const load = async ({ params, depends }) => {
depends("app:indexes");
const mongo = await getMongo();
const client = mongo.getClient(params.server);
const collection = client.db(params.database).collection(params.collection);
const indexesPromise = (async () => {
try {
const indexList = await collection.listIndexes().toArray();
client.setIndexes(
params.database,
params.collection,
indexList.map((index) => ({ name: index.name, key: index.key }))
);
let indexStats = {};
try {
const statsResult = await collection.aggregate([{ $indexStats: {} }]).toArray();
indexStats = Object.fromEntries(
statsResult.map((stat) => [
stat.name,
{
ops: stat.accesses?.ops || 0,
since: stat.accesses?.since || /* @__PURE__ */ new Date()
}
])
);
} catch (err) {
logger.error("Error fetching index stats:", err);
}
const buildingIndexes = {};
try {
const currentOp = await client.db("admin").command({
currentOp: true,
"command.createIndexes": params.collection,
$or: [{ "command.$db": params.database }, { ns: `${params.database}.${params.collection}` }]
});
for (const op of currentOp.inprog || []) {
const indexes = op.command?.indexes || [];
const progress = op.progress;
const pct = progress && progress.total > 0 ? Math.round(progress.done / progress.total * 100) : 0;
for (const idx of indexes) {
if (idx.name) {
buildingIndexes[idx.name] = {
done: progress?.done ?? 0,
total: progress?.total ?? 0,
pct,
key: idx.key
};
}
}
}
} catch (err) {
logger.error("Error fetching currentOp for building indexes:", err);
}
let indexSizes = {};
try {
const collStatsResult = await collection.aggregate([
{
$collStats: {
storageStats: {}
}
}
]).next();
if (collStatsResult?.storageStats?.indexSizes) {
indexSizes = collStatsResult.storageStats.indexSizes;
}
} catch (err) {
logger.error("Error fetching index sizes:", err);
}
const indexesWithStats = indexList.map((index) => ({
...index,
stats: index.name ? indexStats[index.name] || null : null,
size: index.name ? indexSizes[index.name] || 0 : 0,
building: index.name ? buildingIndexes[index.name] || null : null
}));
return {
data: indexesWithStats.map((index) => JsonEncoder.encode(index)),
error: null
};
} catch (err) {
logger.error("Error fetching indexes:", err);
return {
data: [],
error: `Failed to fetch indexes: ${err instanceof Error ? err.message : String(err)}`
};
}
})();
return {
indexes: indexesPromise
};
};
var _page_server_ts = /*#__PURE__*/Object.freeze({
__proto__: null,
load: load
});
const index = 13;
let component_cache;
const component = async () => component_cache ??= (await import('./_page.svelte-zD7qndty.js')).default;
const universal_id = "src/routes/servers/[server]/databases/[database]/collections/[collection]/indexes/+page.ts";
const server_id = "src/routes/servers/[server]/databases/[database]/collections/[collection]/indexes/+page.server.ts";
const imports = ["_app/immutable/nodes/13.DPotp8O6.js","_app/immutable/chunks/DaMh_eeB.js","_app/immutable/chunks/IwGwbOe7.js","_app/immutable/chunks/BDGd1aqF.js","_app/immutable/chunks/DFXj4NOH.js","_app/immutable/chunks/951V-MIZ.js","_app/immutable/chunks/CCOVnadf.js","_app/immutable/chunks/DqxUmOYD.js","_app/immutable/chunks/CKvueigk.js","_app/immutable/chunks/CmI1igJD.js","_app/immutable/chunks/Dzt_TFtX.js","_app/immutable/chunks/C6P2UOyZ.js","_app/immutable/chunks/8tf5Lvl3.js","_app/immutable/chunks/BUO1EOQu.js","_app/immutable/chunks/CkMoyTwc.js","_app/immutable/chunks/ChWGK2Ce.js","_app/immutable/chunks/YMZQSnF3.js","_app/immutable/chunks/v8XDA7ui.js","_app/immutable/chunks/CTk2PBcX.js","_app/immutable/chunks/DCAtHodH.js","_app/immutable/chunks/Z7BFksgg.js","_app/immutable/chunks/BN_N9-2s.js"];
const stylesheets = ["_app/immutable/assets/JsonValue.D87iuwcT.css","_app/immutable/assets/Modal.CZgFKXkP.css","_app/immutable/assets/13.I1sSDJ6i.css"];
const fonts = [];
export { component, fonts, imports, index, _page_server_ts as server, server_id, stylesheets, _page_ts as universal, universal_id };
//# sourceMappingURL=13-D1eLiA_r.js.map