UNPKG

mongoku

Version:

[![CI](https://github.com/huggingface/Mongoku/actions/workflows/ci.yml/badge.svg)](https://github.com/huggingface/Mongoku/actions/workflows/ci.yml)

2 lines (1 loc) 3.26 kB
import{c as J,a as u,f}from"../chunks/DaMh_eeB.js";import{p as L,f as M,a as T,g as o,b as I,u as v,c as g,r as y,s as _,t as z,d as s}from"../chunks/IwGwbOe7.js";import{d as A,s as B,a as k}from"../chunks/BDGd1aqF.js";import{i as D}from"../chunks/CCOVnadf.js";import{i as G,b as H,u as K}from"../chunks/YMZQSnF3.js";import{g as N}from"../chunks/v8XDA7ui.js";import{b as Q}from"../chunks/Dzt_TFtX.js";import{P as w}from"../chunks/IixngxlS.js";import{n as c}from"../chunks/DqxUmOYD.js";var V=f('<div class="loading svelte-khslrq">Loading...</div>'),W=f('<div class="insert-container svelte-khslrq"><h3 class="svelte-khslrq"> </h3> <!> <button class="btn btn-default mt-4">Cancel</button></div>'),X=f('<button class="btn btn-success">Insert Document</button>'),Y=f('<div class="not-found-container svelte-khslrq"><div class="text-center svelte-khslrq">Document not found</div> <!></div>');function dt(q,t){L(t,!0);let l=I(!1),d=v(()=>t.data.document),b=I(!1);async function C(e){const a=e?._id?.$value??e?._id,n=o(d)?._id?.$value??o(d)?._id;if(a!==n){c.notifyError("ObjectId changed. This is not supported, update canceled.");return}if(n){s(l,!0);try{const r=await K({server:t.data.server,database:t.data.database,collection:t.data.collection,document:n,value:e,partial:!1});r.ok&&(c.notifySuccess("Document updated successfully"),s(d,r.update))}catch(r){c.notifyError(r,"Failed to update document")}finally{s(l,!1)}}}async function E(){const e=o(d)?._id?.$value??o(d)?._id;if(e)try{await H({server:t.data.server,database:t.data.database,collection:t.data.collection,document:e}),c.notifySuccess("Document removed successfully"),N(`${Q}/servers/${encodeURIComponent(t.data.server)}/databases/${encodeURIComponent(t.data.database)}/collections/${encodeURIComponent(t.data.collection)}?query=${encodeURIComponent("{}")}&sort=&project=&skip=0&limit=20`)}catch(a){c.notifyError(a,"Failed to remove document")}}async function O(e){s(l,!0);try{(await G({server:t.data.server,database:t.data.database,collection:t.data.collection,document:t.data.documentId,value:e})).ok&&(c.notifySuccess("Document inserted successfully"),window.location.reload())}catch(a){c.notifyError(a,"Failed to insert document")}finally{s(l,!1)}}function x(){s(b,!0)}var h=J(),R=M(h);{var S=e=>{var a=V();u(e,a)},U=e=>{{let a=v(()=>t.data.readOnly?void 0:C),n=v(()=>t.data.readOnly?void 0:E);w(e,{get json(){return o(d)},get onedit(){return o(a)},get onremove(){return o(n)},get server(){return t.data.server},get database(){return t.data.database},get collection(){return t.data.collection},get mappings(){return t.data.mappings}})}},j=e=>{var a=W(),n=g(a),r=g(n);y(n);var i=_(n,2);{let P=v(()=>({_id:{$type:"ObjectId",$value:t.data.documentId}}));w(i,{get json(){return o(P)},onedit:O,get server(){return t.data.server},get database(){return t.data.database},get collection(){return t.data.collection},get mappings(){return t.data.mappings},startInEditMode:!0})}var m=_(i,2);y(a),z(()=>B(r,`Insert Document with ID: ${t.data.documentId??""}`)),k("click",m,()=>s(b,!1)),u(e,a)},F=e=>{var a=Y(),n=_(g(a),2);{var r=i=>{var m=X();k("click",m,x),u(i,m)};D(n,i=>{t.data.readOnly||i(r)})}y(a),u(e,a)};D(R,e=>{o(l)?e(S):o(d)?e(U,1):o(b)?e(j,2):e(F,-1)})}u(q,h),T()}A(["click"]);export{dt as component};