mongoku
Version:
[](https://github.com/huggingface/Mongoku/actions/workflows/ci.yml)
123 lines (120 loc) • 4.17 kB
JavaScript
import './async-DUoD1OpG.js';
import { d as derived } from './root-otUAnOAR.js';
import { d as deleteDocument, u as updateDocument } from './servers.remote-CGenkEHX.js';
import { g as goto } from './client2-BIa3wTXU.js';
import { b as base } from './server-Crjo4w1q.js';
import { P as PrettyJson } from './PrettyJson-Bo4UtQ1o.js';
import { n as notificationStore } from './notifications.svelte-CIqkoPWX.js';
import './shared-server-BmU87nph.js';
import './utils-BQzn9ikS.js';
import './shared-DlqhoNLb.js';
import './index-NcxaM188.js';
import './jsonParser-C3QUcODD.js';
import 'esprima';
import './JsonEncoder-Dgtqxb_U.js';
import 'mongodb';
import './logger-PfH_grbh.js';
import 'async_hooks';
import 'node:util';
import './mongo-B92d7zNj.js';
import 'dns/promises';
import 'url';
import 'node:fs';
import 'node:os';
import 'node:path';
import './schema-BZonjzNJ.js';
import 'zod';
import './index-CtYzvcG6.js';
import './exports-B5ORJhfK.js';
import './state.svelte-Bj5yxNNk.js';
import './server2-D_y4YbpC.js';
import './routing-EDfUNu8L.js';
import './JsonValue-CGVfzyTL.js';
import './Tooltip-OVylvwfb.js';
import './Panel-C6VWd6JD.js';
function _page($$renderer, $$props) {
$$renderer.component(($$renderer2) => {
let { data } = $$props;
let loading = false;
let item = derived(() => data.document);
async function editDocument(json) {
const newId = json?._id?.$value ?? json?._id;
const oldId = item()?._id?.$value ?? item()?._id;
if (newId !== oldId) {
notificationStore.notifyError("ObjectId changed. This is not supported, update canceled.");
return;
}
if (!oldId) {
return;
}
loading = true;
try {
const result = await updateDocument({
server: data.server,
database: data.database,
collection: data.collection,
document: oldId,
value: json,
partial: false
});
if (result.ok) {
notificationStore.notifySuccess("Document updated successfully");
item(result.update);
}
} catch (error) {
notificationStore.notifyError(error, "Failed to update document");
} finally {
loading = false;
}
}
async function removeDocument() {
const documentId = item()?._id?.$value ?? item()?._id;
if (!documentId) {
return;
}
try {
await deleteDocument({
server: data.server,
database: data.database,
collection: data.collection,
document: documentId
});
notificationStore.notifySuccess("Document removed successfully");
goto(
/* eslint-disable-next-line svelte/no-navigation-without-resolve */
`${base}/servers/${encodeURIComponent(data.server)}/databases/${encodeURIComponent(data.database)}/collections/${encodeURIComponent(data.collection)}?query=${encodeURIComponent("{}")}&sort=&project=&skip=0&limit=20`
);
} catch (error) {
notificationStore.notifyError(error, "Failed to remove document");
}
}
if (loading) {
$$renderer2.push("<!--[0-->");
$$renderer2.push(`<div class="loading svelte-khslrq">Loading...</div>`);
} else if (item()) {
$$renderer2.push("<!--[1-->");
PrettyJson($$renderer2, {
json: item(),
onedit: data.readOnly ? void 0 : editDocument,
onremove: data.readOnly ? void 0 : removeDocument,
server: data.server,
database: data.database,
collection: data.collection,
mappings: data.mappings
});
} else {
$$renderer2.push("<!--[-1-->");
$$renderer2.push(`<div class="not-found-container svelte-khslrq"><div class="text-center svelte-khslrq">Document not found</div> `);
if (!data.readOnly) {
$$renderer2.push("<!--[0-->");
$$renderer2.push(`<button class="btn btn-success">Insert Document</button>`);
} else {
$$renderer2.push("<!--[-1-->");
}
$$renderer2.push(`<!--]--></div>`);
}
$$renderer2.push(`<!--]-->`);
});
}
export { _page as default };
//# sourceMappingURL=_page.svelte-CPcgVZQj.js.map