import{S as St,i as At,s as Lt,V as Mt,W as Ht,X as Q,h as d,d as Re,t as Y,a as x,I as jt,Z as Pt,_ as Nt,C as Ut,$ as Jt,D as zt,l as u,n as t,m as Te,E as Wt,G as Gt,u as o,A as _,v as i,c as Pe,w as b,J as Ft,p as Kt,k as ee,o as Vt}from"./index-D5lV2xwk.js";function Bt(a,s,n){const c=a.slice();return c[6]=s[n],c}function Et(a,s,n){const c=a.slice();return c[6]=s[n],c}function Ot(a,s){let n,c,y;function f(){return s[5](s[6])}return{key:a,first:null,c(){n=o("button"),n.textContent=`${s[6].code} `,b(n,"class","tab-item"),ee(n,"active",s[1]===s[6].code),this.first=n},m(r,h){u(r,n,h),c||(y=Vt(n,"click",f),c=!0)},p(r,h){s=r,h&10&&ee(n,"active",s[1]===s[6].code)},d(r){r&&d(n),c=!1,y()}}}function It(a,s){let n,c,y,f;return c=new Ht({props:{content:s[6].body}}),{key:a,first:null,c(){n=o("div"),Pe(c.$$.fragment),y=i(),b(n,"class","tab-item"),ee(n,"active",s[1]===s[6].code),this.first=n},m(r,h){u(r,n,h),Te(c,n,null),t(n,y),f=!0},p(r,h){s=r,(!f||h&10)&&ee(n,"active",s[1]===s[6].code)},i(r){f||(x(c.$$.fragment,r),f=!0)},o(r){Y(c.$$.fragment,r),f=!1},d(r){r&&d(n),Re(c)}}}function Xt(a){var pt,mt,bt,ht,ft,_t,yt,kt;let s,n,c=a[0].name+"",y,f,r,h,F,g,U,Fe,P,B,Be,E,Ee,Oe,te,le,w,oe,O,ae,I,se,H,ne,J,ie,q,ce,Ie,re,S,z,He,k,W,Se,de,Ae,D,G,Le,ue,Me,K,je,pe,Ne,C,Ue,me,Je,ze,We,V,Ge,X,Ke,be,Ve,he,Xe,fe,Ze,p,_e,Qe,ye,Ye,ke,xe,$e,et,ge,tt,ve,lt,ot,at,De,st,R,Ce,A,we,T,L,v=[],nt=new Map,it,M,$=[],ct=new Map,j,qe,rt;w=new Mt({props:{js:` import PocketBase from 'pocketbase'; const pb = new PocketBase('${a[2]}'); ... const batch = pb.createBatch(); batch.collection('${(pt=a[0])==null?void 0:pt.name}').create({ ... }); batch.collection('${(mt=a[0])==null?void 0:mt.name}').update('RECORD_ID', { ... }); batch.collection('${(bt=a[0])==null?void 0:bt.name}').delete('RECORD_ID'); batch.collection('${(ht=a[0])==null?void 0:ht.name}').upsert({ ... }); const result = await batch.send(); `,dart:` import 'package:pocketbase/pocketbase.dart'; final pb = PocketBase('${a[2]}'); ... final batch = pb.createBatch(); batch.collection('${(ft=a[0])==null?void 0:ft.name}').create(body: { ... }); batch.collection('${(_t=a[0])==null?void 0:_t.name}').update('RECORD_ID', body: { ... }); batch.collection('${(yt=a[0])==null?void 0:yt.name}').delete('RECORD_ID'); batch.collection('${(kt=a[0])==null?void 0:kt.name}').upsert(body: { ... }); final result = await batch.send(); `}}),R=new Ht({props:{language:"javascript",content:` const formData = new FormData(); formData.append("@jsonPayload", JSON.stringify({ requests: [ { method: "POST", url: "/api/collections/${a[0].name}/records?fields=id", body: { someField: "test1" } }, { method: "PATCH", url: "/api/collections/${a[0].name}/records/RECORD_ID", body: { someField: "test2" } } ] })) // file for the first request formData.append("requests.0.someFileField", new File(...)) // file for the second request formData.append("requests.1.someFileField", new File(...)) `}});let Z=Q(a[3]);const dt=e=>e[6].code;for(let e=0;ee[6].code;for(let e=0;eBatch and transactional create/update/upsert/delete of multiple records in a single request.

",F=i(),g=o("div"),U=o("div"),U.innerHTML='',Fe=i(),P=o("div"),B=o("p"),Be=_(`The batch Web API need to be explicitly enabled and configured from the `),E=o("a"),E.textContent="Dashboard settings",Ee=_("."),Oe=i(),te=o("p"),te.innerHTML=`Because this endpoint process the requests in a single DB transaction it could degrade the performance of your application if not used with proper care and configuration (prefer smaller max processing and body size limits, avoid large file uploads over slow S3 networks and custom hooks that communicate with slow external APIs).`,le=i(),Pe(w.$$.fragment),oe=i(),O=o("h6"),O.textContent="API details",ae=i(),I=o("div"),I.innerHTML='POST
/api/batch
',se=i(),H=o("div"),H.textContent="Body Parameters",ne=i(),J=o("p"),J.innerHTML=`Body parameters could be sent as application/json or multipart/form-data.
File upload is supported only via multipart/form-data (see below for more details).`,ie=i(),q=o("table"),ce=o("thead"),ce.innerHTML='Param Description',Ie=i(),re=o("tbody"),S=o("tr"),z=o("td"),z.innerHTML='
Required requests
',He=i(),k=o("td"),W=o("span"),W.textContent="Array",Se=_(` - List of the requests to process. `),de=o("p"),de.textContent="The supported batch request actions are:",Ae=i(),D=o("ul"),G=o("li"),Le=_("record create - "),ue=o("code"),ue.textContent="POST /api/collections/{collection}/records",Me=i(),K=o("li"),je=_(`record update - `),pe=o("code"),pe.textContent="PATCH /api/collections/{collection}/records/{id}",Ne=i(),C=o("li"),Ue=_("record upsert - "),me=o("code"),me.textContent="PUT /api/collections/{collection}/records",Je=i(),ze=o("br"),We=i(),V=o("small"),V.innerHTML='(the body must have id field)',Ge=i(),X=o("li"),Ke=_(`record delete - `),be=o("code"),be.textContent="DELETE /api/collections/{collection}/records/{id}",Ve=i(),he=o("p"),he.textContent="Each batch Request element have the following properties:",Xe=i(),fe=o("ul"),fe.innerHTML=`
  • url path (could include query parameters)
  • method (GET, POST, PUT, PATCH, DELETE)
  • headers
    (custom per-request Authorization header is not supported at the moment, aka. all batch requests have the same auth state)
  • body
  • `,Ze=i(),p=o("p"),_e=o("strong"),_e.textContent="NB!",Qe=_(` When the batch request is send as `),ye=o("code"),ye.textContent="multipart/form-data",Ye=_(`, the regular batch action fields are expected to be submitted as serailized json under the `),ke=o("code"),ke.textContent="@jsonPayload",xe=_(` field and file keys need to follow the pattern `),$e=o("code"),$e.textContent="requests.N.fileField",et=_(` or `),ge=o("code"),ge.textContent="requests[N].fileField",tt=i(),ve=o("em"),ve.textContent=`(this is usually handled transparently by the SDKs when their specific object notation is used) `,lt=_(`. `),ot=o("br"),at=_(` If you don't use the SDKs or prefer manually to construct the `),De=o("code"),De.textContent="FormData",st=_(` body, then it could look something like: `),Pe(R.$$.fragment),Ce=i(),A=o("div"),A.textContent="Responses",we=i(),T=o("div"),L=o("div");for(let e=0;en(1,r=g.code);return a.$$set=g=>{"collection"in g&&n(0,f=g.collection)},a.$$.update=()=>{a.$$.dirty&1&&n(4,y=Ft.dummyCollectionRecord(f)),a.$$.dirty&17&&f!=null&&f.id&&(h.push({code:200,body:JSON.stringify([{status:200,body:y},{status:200,body:Object.assign({},y,{id:y.id+"2"})}],null,2)}),h.push({code:400,body:` { "status": 400, "message": "Batch transaction failed.", "data": { "requests": { "1": { "code": "batch_request_failed", "message": "Batch request failed.", "response": { "status": 400, "message": "Failed to create record.", "data": { "id": { "code": "validation_min_text_constraint", "message": "Must be at least 3 character(s).", "params": { "min": 3 } } } } } } } } `}),h.push({code:403,body:` { "status": 403, "message": "Batch requests are not allowed.", "data": {} } `}))},n(2,c=Ft.getApiExampleUrl(Kt.baseURL)),[f,r,c,h,y,F]}class Yt extends St{constructor(s){super(),At(this,s,Zt,Xt,Lt,{collection:0})}}export{Yt as default};