@hostlink/light 2.7.0 → 2.7.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/light.js CHANGED
@@ -20,14 +20,14 @@ function J(t) {
20
20
  "_"
21
21
  ).replace(/=/g, "");
22
22
  }
23
- var f = "copy", F = "convert";
24
- function D(t, e, r) {
25
- if (e === f)
23
+ var p = "copy", F = "convert";
24
+ function v(t, e, r) {
25
+ if (e === p)
26
26
  return r;
27
27
  if (e === F)
28
28
  return t(r);
29
29
  if (e instanceof Array)
30
- return r.map((s) => D(t, e[0], s));
30
+ return r.map((s) => v(t, e[0], s));
31
31
  if (e instanceof Object) {
32
32
  const s = {};
33
33
  for (const [n, i] of Object.entries(e)) {
@@ -44,7 +44,7 @@ function D(t, e, r) {
44
44
  s[n] = null;
45
45
  continue;
46
46
  }
47
- s[n] = D(
47
+ s[n] = v(
48
48
  t,
49
49
  i.schema,
50
50
  r[n]
@@ -73,44 +73,44 @@ function g(t) {
73
73
  };
74
74
  }
75
75
  var B = {
76
- type: h(f),
76
+ type: h(p),
77
77
  id: h(F),
78
- transports: g(f)
78
+ transports: g(p)
79
79
  }, j = {
80
- appid: g(f),
81
- appidExclude: g(f),
82
- credProps: g(f)
80
+ appid: g(p),
81
+ appidExclude: g(p),
82
+ credProps: g(p)
83
83
  }, U = {
84
- appid: g(f),
85
- appidExclude: g(f),
86
- credProps: g(f)
84
+ appid: g(p),
85
+ appidExclude: g(p),
86
+ credProps: g(p)
87
87
  }, K = {
88
88
  publicKey: h({
89
- rp: h(f),
89
+ rp: h(p),
90
90
  user: h({
91
91
  id: h(F),
92
- name: h(f),
93
- displayName: h(f)
92
+ name: h(p),
93
+ displayName: h(p)
94
94
  }),
95
95
  challenge: h(F),
96
- pubKeyCredParams: h(f),
97
- timeout: g(f),
96
+ pubKeyCredParams: h(p),
97
+ timeout: g(p),
98
98
  excludeCredentials: g([B]),
99
- authenticatorSelection: g(f),
100
- attestation: g(f),
99
+ authenticatorSelection: g(p),
100
+ attestation: g(p),
101
101
  extensions: g(j)
102
102
  }),
103
- signal: g(f)
103
+ signal: g(p)
104
104
  }, M = {
105
- type: h(f),
106
- id: h(f),
105
+ type: h(p),
106
+ id: h(p),
107
107
  rawId: h(F),
108
- authenticatorAttachment: g(f),
108
+ authenticatorAttachment: g(p),
109
109
  response: h({
110
110
  clientDataJSON: h(F),
111
111
  attestationObject: h(F),
112
112
  transports: q(
113
- f,
113
+ p,
114
114
  (t) => {
115
115
  var e;
116
116
  return ((e = t.getTransports) == null ? void 0 : e.call(t)) || [];
@@ -122,21 +122,21 @@ var B = {
122
122
  (t) => t.getClientExtensionResults()
123
123
  )
124
124
  }, G = {
125
- mediation: g(f),
125
+ mediation: g(p),
126
126
  publicKey: h({
127
127
  challenge: h(F),
128
- timeout: g(f),
129
- rpId: g(f),
128
+ timeout: g(p),
129
+ rpId: g(p),
130
130
  allowCredentials: g([B]),
131
- userVerification: g(f),
131
+ userVerification: g(p),
132
132
  extensions: g(j)
133
133
  }),
134
- signal: g(f)
134
+ signal: g(p)
135
135
  }, I = {
136
- type: h(f),
137
- id: h(f),
136
+ type: h(p),
137
+ id: h(p),
138
138
  rawId: h(F),
139
- authenticatorAttachment: g(f),
139
+ authenticatorAttachment: g(p),
140
140
  response: h({
141
141
  clientDataJSON: h(F),
142
142
  authenticatorData: h(F),
@@ -149,20 +149,20 @@ var B = {
149
149
  )
150
150
  };
151
151
  function Q(t) {
152
- return D(R, K, t);
152
+ return v(R, K, t);
153
153
  }
154
154
  function z(t) {
155
- return D(
155
+ return v(
156
156
  J,
157
157
  M,
158
158
  t
159
159
  );
160
160
  }
161
161
  function $(t) {
162
- return D(R, G, t);
162
+ return v(R, G, t);
163
163
  }
164
164
  function H(t) {
165
- return D(
165
+ return v(
166
166
  J,
167
167
  I,
168
168
  t
@@ -249,7 +249,7 @@ const Z = (t) => ({
249
249
  old_password: r,
250
250
  new_password: s
251
251
  }),
252
- updatePassword: (e, r) => u(t, "updatePassword", {
252
+ updatePassword: (e, r) => u(t, "changeUserPassword", {
253
253
  old_password: e,
254
254
  new_password: r
255
255
  }),
@@ -290,11 +290,11 @@ const Z = (t) => ({
290
290
  },
291
291
  gqlFields(a) {
292
292
  const l = [];
293
- for (const p of a)
294
- if (typeof p == "string") {
295
- const _ = o(p);
293
+ for (const f of a)
294
+ if (typeof f == "string") {
295
+ const _ = o(f);
296
296
  _ && l.push(_.getGQLField());
297
- } else typeof p == "object" && l.push(p);
297
+ } else typeof f == "object" && l.push(f);
298
298
  return l;
299
299
  },
300
300
  async update(a, l) {
@@ -308,8 +308,8 @@ const Z = (t) => ({
308
308
  },
309
309
  fields(a) {
310
310
  let l = [];
311
- for (let p of a) {
312
- const _ = o(p);
311
+ for (let f of a) {
312
+ const _ = o(f);
313
313
  _ && l.push(_);
314
314
  }
315
315
  return l;
@@ -348,7 +348,7 @@ function et(t) {
348
348
  var e, r, s, n, i, c = String, o = 255;
349
349
  for (t.slice(0, 2) === "<~" && t.slice(-2), t = t.slice(2, -2).replace(/\s/g, "").replace("z", "!!!!!"), e = "uuuuu".slice(t.length % 5 || 5), t += e, s = [], n = 0, i = t.length; i > n; n += 5) r = 52200625 * (t.charCodeAt(n) - 33) + 614125 * (t.charCodeAt(n + 1) - 33) + 7225 * (t.charCodeAt(n + 2) - 33) + 85 * (t.charCodeAt(n + 3) - 33) + (t.charCodeAt(n + 4) - 33), s.push(o & r >> 24, o & r >> 16, o & r >> 8, o & r);
350
350
  return function(a, l) {
351
- for (var p = l; p > 0; p--) a.pop();
351
+ for (var f = l; f > 0; f--) a.pop();
352
352
  }(s, e.length), c.fromCharCode.apply(c, s);
353
353
  }
354
354
  const k = (t = "") => {
@@ -419,22 +419,22 @@ const u = async (t, e, r = null, s = []) => {
419
419
  const i = new FormData();
420
420
  let c = !1;
421
421
  if (r) {
422
- const l = {}, p = {}, _ = {};
422
+ const l = {}, f = {}, _ = {};
423
423
  let b = 0;
424
424
  Object.entries(r).forEach(([y, w]) => {
425
425
  if (w instanceof Array && rt(w)) {
426
426
  c = !0;
427
- let A = 0;
428
- w.forEach((v) => {
429
- v instanceof File && (l[y] = new S(y), p[b] = ["variables." + y + "." + A], i.append(b.toString(), v), b++);
427
+ let D = 0;
428
+ w.forEach((A) => {
429
+ A instanceof File && (l[y] = new S(y), f[b] = ["variables." + y + "." + D], i.append(b.toString(), A), b++);
430
430
  }), _[y] = "[Upload!]!";
431
- } else w instanceof File ? (c = !0, l[y] = new S(y), p[b] = ["variables." + y], i.append(b.toString(), w), _[y] = "Upload!", b++) : w instanceof Object && st(w) ? (c = !0, l[y] = {}, Object.entries(w).forEach(([A, v]) => {
432
- v instanceof File ? (l[y][A] = new S(A), p[b] = ["variables." + A], i.append(b.toString(), v), _[A] = "Upload!", b++) : l[y][A] = v;
431
+ } else w instanceof File ? (c = !0, l[y] = new S(y), f[b] = ["variables." + y], i.append(b.toString(), w), _[y] = "Upload!", b++) : w instanceof Object && st(w) ? (c = !0, l[y] = {}, Object.entries(w).forEach(([D, A]) => {
432
+ A instanceof File ? (l[y][D] = new S(D), f[b] = ["variables." + D], i.append(b.toString(), A), _[D] = "Upload!", b++) : l[y][D] = A;
433
433
  })) : w !== void 0 && (l[y] = w);
434
- }), n[e].__args = l, n.__variables = _, c && i.append("map", JSON.stringify(p));
434
+ }), n[e].__args = l, n.__variables = _, c && i.append("map", JSON.stringify(f));
435
435
  }
436
- Object.entries(O(s)).forEach(([l, p]) => {
437
- n[e][l] = p;
436
+ Object.entries(O(s)).forEach(([l, f]) => {
437
+ n[e][l] = f;
438
438
  }), Object.entries(n[e]).length === 0 && (n[e] = !0);
439
439
  let o = null;
440
440
  const a = E({ mutation: n });
@@ -546,8 +546,8 @@ const u = async (t, e, r = null, s = []) => {
546
546
  return a.field && typeof a.field == "function" ? a.field(l) : a.field && typeof a.field == "string" ? l[a.field] : l[this.getName()];
547
547
  },
548
548
  getFormattedValue(l) {
549
- const p = this.getValue(l);
550
- return a.format ? a.format(p) : p;
549
+ const f = this.getValue(l);
550
+ return a.format ? a.format(f) : f;
551
551
  }
552
552
  });
553
553
  }
@@ -594,7 +594,7 @@ const u = async (t, e, r = null, s = []) => {
594
594
  "slice",
595
595
  "tap",
596
596
  "sort"
597
- ], pt = [
597
+ ], ft = [
598
598
  "avg",
599
599
  "count",
600
600
  "countBy",
@@ -712,7 +712,7 @@ for (const t of ct)
712
712
  const r = this.clone();
713
713
  return r.steps.push({ type: t, args: e }), r;
714
714
  };
715
- for (const t of pt)
715
+ for (const t of ft)
716
716
  d.prototype[t] = async function(...e) {
717
717
  return (await this.clone().processData())[t](...e);
718
718
  };
@@ -721,31 +721,33 @@ d.prototype.first = async function() {
721
721
  return this.take(1), (await this.processData()).first();
722
722
  };
723
723
  d.prototype.where = function(...t) {
724
+ if (this._batchData)
725
+ return this.steps.push({ type: "where", args: t }), this;
724
726
  if (t.length == 2)
725
727
  this.filters[t[0]] = t[1];
726
728
  else if (t.length == 3) {
727
729
  let e = "==", r = t[0], s = null;
728
730
  t.length == 3 && (e = t[1], s = t[2]), e === "==" && (this.filters[r] = s), e === "<" && (this.filters[r] = { lt: s }), e === "<=" && (this.filters[r] = { lte: s }), e === ">" && (this.filters[r] = { gt: s }), e === ">=" && (this.filters[r] = { gte: s }), e === "!==" && (this.filters[r] = { ne: s });
729
731
  }
730
- return this.steps.push({ type: "where", args: t }), this;
732
+ return this;
731
733
  };
732
734
  d.prototype.whereContains = function(t, e) {
733
- return this.steps.push({ type: "whereContains", args: [t, e] }), this.filters[t] = { contains: e }, this;
735
+ return this._batchData ? (this.steps.push({ type: "whereContains", args: [t, e] }), this) : (this.filters[t] = { contains: e }, this);
734
736
  };
735
737
  d.prototype.forPage = function(t, e) {
736
738
  return t = Math.max(1, t), this.already_limit ? (this.steps.push({ type: "forPage", args: [t, e] }), this) : (this.limit = e, this.offset = (t - 1) * e, this.already_limit = !0, this.already_offset = !0, this);
737
739
  };
738
740
  d.prototype.whereIn = function(t, e) {
739
- return this.steps.push({ type: "whereIn", args: [t, e] }), this.filters[t] = { in: e }, this;
741
+ return this._batchData ? (this.steps.push({ type: "whereIn", args: [t, e] }), this) : (this.filters[t] = { in: e }, this);
740
742
  };
741
743
  d.prototype.whereNotIn = function(t, e) {
742
- return this.steps.push({ type: "whereNotIn", args: [t, e] }), this.filters[t] = { nin: e }, this;
744
+ return this._batchData ? (this.steps.push({ type: "whereNotIn", args: [t, e] }), this) : (this.filters[t] = { nin: e }, this);
743
745
  };
744
746
  d.prototype.whereNotBetween = function(t, e) {
745
- return this.steps.push({ type: "whereNotBetween", args: [t, e] }), this.filters[t] = { notBetween: e }, this;
747
+ return this._batchData ? (this.steps.push({ type: "whereNotBetween", args: [t, e] }), this) : (this.filters[t] = { notBetween: e }, this);
746
748
  };
747
749
  d.prototype.whereBetween = function(t, e) {
748
- return this.steps.push({ type: "whereBetween", args: [t, e] }), this.filters[t] = { between: e }, this;
750
+ return this._batchData ? (this.steps.push({ type: "whereBetween", args: [t, e] }), this) : (this.filters[t] = { between: e }, this);
749
751
  };
750
752
  d.prototype.sortBy = function(t) {
751
753
  return this.steps.push({ type: "sortBy", args: [t] }), typeof t == "string" && (this._sort = t), this;
@@ -765,7 +767,7 @@ d.prototype.splice = function(t, e) {
765
767
  const L = (t, e, r) => {
766
768
  const s = new d(r, e);
767
769
  return s.data_path = "list" + t, s;
768
- }, ft = (t, e) => ({
770
+ }, pt = (t, e) => ({
769
771
  uploadTempFile: (r) => u(e, "lightDriveUploadTempFile", {
770
772
  index: t,
771
773
  file: r
@@ -889,18 +891,18 @@ const L = (t, e, r) => {
889
891
  return o.data_path = n.get(i).getDataPath(), o;
890
892
  },
891
893
  drive(i) {
892
- return ft(i, e);
894
+ return pt(i, e);
893
895
  },
894
896
  async collects(i) {
895
897
  const c = {}, o = {};
896
898
  for (const l in i) {
897
- const p = i[l].getQueryPayload();
898
- o[l] = p.data_path, c[l] = {};
899
- const _ = p.data_path.split(".");
899
+ const f = i[l].getQueryPayload();
900
+ o[l] = f.data_path, c[l] = {};
901
+ const _ = f.data_path.split(".");
900
902
  let b = _[_.length - 1], y = c[l];
901
903
  for (const w of _) {
902
904
  if (w === b) {
903
- y[w] = p.query;
905
+ y[w] = f.query;
904
906
  break;
905
907
  }
906
908
  y[w] = y[w] || {};
@@ -909,9 +911,9 @@ const L = (t, e, r) => {
909
911
  }
910
912
  const a = await m(e, c);
911
913
  for (const l in i) {
912
- const p = o[l].split(".");
913
- let _ = p[p.length - 1], b = a[l];
914
- for (const y of p) {
914
+ const f = o[l].split(".");
915
+ let _ = f[f.length - 1], b = a[l];
916
+ for (const y of f) {
915
917
  if (y === _) {
916
918
  i[l]._batchData = a[l][y];
917
919
  break;
@@ -1 +1 @@
1
- (function(y,m){typeof exports=="object"&&typeof module<"u"?m(exports,require("json-to-graphql-query"),require("axios"),require("collect.js")):typeof define=="function"&&define.amd?define(["exports","json-to-graphql-query","axios","collect.js"],m):(y=typeof globalThis<"u"?globalThis:y||self,m(y.light={},y.jsonToGraphqlQuery,y.axios,y.collect))})(this,function(y,m,O,P){"use strict";var ht=Object.defineProperty;var dt=(y,m,O)=>m in y?ht(y,m,{enumerable:!0,configurable:!0,writable:!0,value:O}):y[m]=O;var A=(y,m,O)=>dt(y,typeof m!="symbol"?m+"":m,O);function J(t){const e="==".slice(0,(4-t.length%4)%4),r=t.replace(/-/g,"+").replace(/_/g,"/")+e,s=atob(r),n=new ArrayBuffer(s.length),i=new Uint8Array(n);for(let c=0;c<s.length;c++)i[c]=s.charCodeAt(c);return n}function B(t){const e=new Uint8Array(t);let r="";for(const i of e)r+=String.fromCharCode(i);return btoa(r).replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")}var f="copy",v="convert";function S(t,e,r){if(e===f)return r;if(e===v)return t(r);if(e instanceof Array)return r.map(s=>S(t,e[0],s));if(e instanceof Object){const s={};for(const[n,i]of Object.entries(e)){if(i.derive){const c=i.derive(r);c!==void 0&&(r[n]=c)}if(!(n in r)){if(i.required)throw new Error(`Missing key: ${n}`);continue}if(r[n]==null){s[n]=null;continue}s[n]=S(t,i.schema,r[n])}return s}}function E(t,e){return{required:!0,schema:t,derive:e}}function h(t){return{required:!0,schema:t}}function g(t){return{required:!1,schema:t}}var T={type:h(f),id:h(v),transports:g(f)},U={appid:g(f),appidExclude:g(f),credProps:g(f)},L={appid:g(f),appidExclude:g(f),credProps:g(f)},V={publicKey:h({rp:h(f),user:h({id:h(v),name:h(f),displayName:h(f)}),challenge:h(v),pubKeyCredParams:h(f),timeout:g(f),excludeCredentials:g([T]),authenticatorSelection:g(f),attestation:g(f),extensions:g(U)}),signal:g(f)},M={type:h(f),id:h(f),rawId:h(v),authenticatorAttachment:g(f),response:h({clientDataJSON:h(v),attestationObject:h(v),transports:E(f,t=>{var e;return((e=t.getTransports)==null?void 0:e.call(t))||[]})}),clientExtensionResults:E(L,t=>t.getClientExtensionResults())},W={mediation:g(f),publicKey:h({challenge:h(v),timeout:g(f),rpId:g(f),allowCredentials:g([T]),userVerification:g(f),extensions:g(U)}),signal:g(f)},K={type:h(f),id:h(f),rawId:h(v),authenticatorAttachment:g(f),response:h({clientDataJSON:h(v),authenticatorData:h(v),signature:h(v),userHandle:h(v)}),clientExtensionResults:E(L,t=>t.getClientExtensionResults())};function I(t){return S(J,V,t)}function Q(t){return S(B,M,t)}function z(t){return S(J,W,t)}function G(t){return S(B,K,t)}async function $(t){const e=await navigator.credentials.create(t);return e.toJSON=()=>Q(e),e}async function H(t){const e=await navigator.credentials.get(t);return e.toJSON=()=>G(e),e}const X=t=>({login:async()=>{const{app:e}=await w(t,{app:{auth:{webAuthnRequestOptions:!0}}}),r=e.auth.webAuthnRequestOptions,s=z({publicKey:r}),n=await H(s);await u(t,"webAuthnAssertion",{assertion:n.toJSON()})},register:async()=>{const{app:e}=await w(t,{app:{auth:{webAuthnCreationOptions:!0}}}),r=I({publicKey:e.auth.webAuthnCreationOptions}),s=await $(r);await u(t,"webAuthnRegister",{registration:s.toJSON()})}}),Y=t=>({WebAuthn:X(t),google:{unlink:()=>u(t,"lightAuthUnlinkGoogle"),login:e=>u(t,"lightAuthLoginGoogle",{credential:e}),register:e=>u(t,"lightAuthRegisterGoogle",{credential:e})},facebook:{unlink:()=>u(t,"lightAuthUnlinkFacebook"),login:e=>u(t,"lightAuthLoginFacebook",{access_token:e}),register:e=>u(t,"lightAuthRegisterFacebook",{access_token:e})},microsoft:{unlink:()=>u(t,"lightAuthUnlinkMicrosoft"),login:e=>u(t,"lightAuthLoginMicrosoft",{access_token:e}),register:e=>u(t,"lightAuthRegisterMicrosoft",{account_id:e})},login:(e,r,s="")=>u(t,"login",{username:e,password:r,code:s}),logout:()=>u(t,"logout"),changeExpiredPassword:(e,r,s)=>u(t,"changeExpiredPassword",{username:e,old_password:r,new_password:s}),updatePassword:(e,r)=>u(t,"updatePassword",{old_password:e,new_password:r}),resetPassword:(e,r,s)=>u(t,"resetPassword",{jwt:e,password:r,code:s}),forgetPassword:(e,r)=>u(t,"forgetPassword",{username:e,email:r}),verifyCode(e,r){return u(t,"forgetPasswordVerifyCode",{jwt:e,code:r})},granted:async e=>(await w(t,{granted:{__args:{rights:e}}})).granted}),Z=(t,e,r)=>{const s=e,n=t,i=r;let c="list"+e;const o=a=>i[a]?i[a]():null;return{field:o,$fields:i,setDataPath(a){return c=a,c},getDataPath(){return c},gqlFields(a){const l=[];for(const p of a)if(typeof p=="string"){const b=o(p);b&&l.push(b.getGQLField())}else typeof p=="object"&&l.push(p);return l},async update(a,l){return await u(n,"update"+s,{id:a,data:l})},async delete(a){return await u(n,"delete"+s,{id:a})},async add(a){return await u(n,"add"+s,{data:a})},fields(a){let l=[];for(let p of a){const b=o(p);b&&l.push(b)}return l},async get(a,l){return(await w(n,{["list"+s]:{__args:{filters:a},data:{__args:{limit:1},...k(l)}}}))["list"+s].data[0]},async list(a,l){return(await w(n,{["list"+s]:{__args:{filters:a},data:{...k(l)}}}))["list"+s].data}}};function x(t){t="<~"+t+"~>";var e,r,s,n,i,c=String,o=255;for(t.slice(0,2)==="<~"&&t.slice(-2),t=t.slice(2,-2).replace(/\s/g,"").replace("z","!!!!!"),e="uuuuu".slice(t.length%5||5),t+=e,s=[],n=0,i=t.length;i>n;n+=5)r=52200625*(t.charCodeAt(n)-33)+614125*(t.charCodeAt(n+1)-33)+7225*(t.charCodeAt(n+2)-33)+85*(t.charCodeAt(n+3)-33)+(t.charCodeAt(n+4)-33),s.push(o&r>>24,o&r>>16,o&r>>8,o&r);return function(a,l){for(var p=l;p>0;p--)a.pop()}(s,e.length),c.fromCharCode.apply(c,s)}const N=(t="")=>{const e=t,r=(s="application/octet-stream")=>{const n=new Uint8Array(e.length);for(let o=0;o<e.length;o++)n[o]=e.charCodeAt(o);const i=new Blob([n],{type:s});return URL.createObjectURL(i)};return{getContent:()=>e,getURL:r,download:s=>{const n=document.createElement("a");n.download=s,n.href=r(),document.body.appendChild(n),n.click(),document.body.removeChild(n)},open:s=>{window.open(r(s),"_blank")}}},tt={fromBase85:t=>N(x(t)),fromBase64:t=>N(atob(t)),fromString:t=>N(t)},R=t=>{let e={};return typeof t=="string"?(e[t]=!0,e):t instanceof Array?(t.forEach(r=>{Object.entries(R(r)).forEach(([s,n])=>{e[s]=n})}),e):(Object.entries(t).forEach(([r,s])=>{if(r=="__args"||r=="__aliasFor"||r=="__variables"||r=="__directives"||r=="__all_on"||r=="__name"){e[r]=s;return}if(typeof s=="boolean"){e[r]=s;return}e[r]=R(s)}),e)},k=t=>R(t),w=async(t,e)=>{let r=m.jsonToGraphQLQuery(k(e));const s=await t.post("",{query:`{ ${r} }`});if(s.data.errors)throw new Error(s.data.errors[0].message);return s.data.data};function et(t){for(let e=0;e<t.length;e++)if(t[e]instanceof File)return!0;return!1}function rt(t){for(let e in t)if(t[e]instanceof File)return!0;return!1}const u=async(t,e,r=null,s=[])=>{let n={[e]:{}};const i=new FormData;let c=!1;if(r){const l={},p={},b={};let F=0;Object.entries(r).forEach(([_,C])=>{if(C instanceof Array&&et(C)){c=!0;let D=0;C.forEach(q=>{q instanceof File&&(l[_]=new m.VariableType(_),p[F]=["variables."+_+"."+D],i.append(F.toString(),q),F++)}),b[_]="[Upload!]!"}else C instanceof File?(c=!0,l[_]=new m.VariableType(_),p[F]=["variables."+_],i.append(F.toString(),C),b[_]="Upload!",F++):C instanceof Object&&rt(C)?(c=!0,l[_]={},Object.entries(C).forEach(([D,q])=>{q instanceof File?(l[_][D]=new m.VariableType(D),p[F]=["variables."+D],i.append(F.toString(),q),b[D]="Upload!",F++):l[_][D]=q})):C!==void 0&&(l[_]=C)}),n[e].__args=l,n.__variables=b,c&&i.append("map",JSON.stringify(p))}Object.entries(k(s)).forEach(([l,p])=>{n[e][l]=p}),Object.entries(n[e]).length===0&&(n[e]=!0);let o=null;const a=m.jsonToGraphQLQuery({mutation:n});if(c?(i.append("operations",JSON.stringify({query:a})),o=await t.post("",i)):o=await t.post("",{query:a}),o.data.errors)throw new Error(o.data.errors[0].message);return o.data.data[e]},st=t=>({uploadTempFile:e=>u(t,"fsUploadTempFile",{file:e},{name:!0,path:!0,size:!0,mime:!0}),folders:{list:async e=>(await w(t,{fsListFolders:{__args:{path:e},name:!0,path:!0}})).fsListFolders,create:e=>u(t,"fsCreateFolder",{path:e}),delete:e=>u(t,"fsDeleteFolder",{path:e}),rename:(e,r)=>u(t,"fsRenameFolder",{path:e,name:r})},files:{list:async e=>(await w(t,{fsListFiles:{__args:{path:e},name:!0,path:!0,size:!0,mime:!0,canPreview:!0,imagePath:!0}})).fsListFiles,read:async e=>{let r=await w(t,{fsFile:{__args:{path:e},base64Content:!0}});return window.atob(r.fsFile.base64Content)},write:(e,r)=>u(t,"fsWriteFile",{path:e,content:r}),delete:e=>u(t,"fsDeleteFile",{path:e}),rename:(e,r)=>u(t,"fsRenameFile",{path:e,name:r}),move:(e,r)=>u(t,"fsMoveFile",{source:e,target:r})}}),nt=t=>({get:async e=>(await t({config:{__args:{name:e}}})).config}),it=t=>({send:(e,r,s)=>u(t,"sendMail",{email:e,subject:r,message:s})}),at=t=>({list:async(e={user_id:!0,username:!0,first_name:!0,last_name:!0,status:!0})=>{const r=j("Users",t,e);return r.data_path="app.users",r.all()}}),ot=t=>{const e=t,r={};return{create(s,n){r[s]=null;let i={};for(const c of Object.entries(n)){const[o,a]=c;i[o]=()=>({name:a.name?a.name:o,raw:a,getName:()=>a.name?a.name:o,getGQLField:()=>a.gqlField!==void 0?a.gqlField:a.name||o,getRaw(){return a},getValue(l){return a.field&&typeof a.field=="function"?a.field(l):a.field&&typeof a.field=="string"?l[a.field]:l[this.getName()]},getFormattedValue(l){const p=this.getValue(l);return a.format?a.format(p):p}})}r[s]=Z(e,s,i)},get(s){return r[s]||this.create(s,{}),r[s]}}},lt=t=>({list:async(e={name:!0})=>{const{app:{roles:r}}=await w(t,{app:{roles:e}});return r}}),ut=["flatMap","chunk","shuffle","splice","sortBy","map","reverse","groupBy","keyBy","keys","mapToDictionary","mapWithKeys","nth","skipUntil","skipWhile","takeUntil","takeWhile","unique","pluck","push","only","pad","slice","tap","sort"],ct=["avg","count","countBy","dd","each","every","filter","firstWhere","isEmpty","isNotEmpty","last","mapToGroups","max","median","min","mode","contains","sole","sort","split","sum","toJson","get","has","implode","partition","sole"];class d{constructor(e,r){A(this,"_batchData",null);A(this,"data_path","");A(this,"axios");A(this,"filters");A(this,"steps");A(this,"fields");A(this,"already_limit",!1);A(this,"already_offset",!1);A(this,"limit",null);A(this,"offset",null);A(this,"_sort",null);A(this,"_sortDesc",!1);A(this,"meta",{});this.axios=r,this.filters={},this.steps=[],this.fields=e}}d.prototype.getQueryPayload=function(){let t={meta:{total:!0,key:!0,name:!0}};return t.__args=this.buildArgs(),t.data=this.fields,t.data.__args=t.data.__args||{},this.limit&&(t.data.__args.limit=this.limit),this.offset&&(t.data.__args.offset=this.offset),{data_path:this.data_path,query:t,steps:this.steps}},d.prototype.dataPath=function(t){const e=this.clone();return e.data_path=t,e},d.prototype.buildArgs=function(){let t={};return Object.keys(this.filters).length>0&&(t.filters=this.filters),this._sort&&(t.sort=this._sort,this._sortDesc&&(t.sort+=":desc")),t},d.prototype.clone=function(){const t=Object.create(this);return t.steps=JSON.parse(JSON.stringify(this.steps)),t.filters=JSON.parse(JSON.stringify(this.filters)),t.fields=JSON.parse(JSON.stringify(this.fields)),t},P().macro("whereContains",function(t,e){return this.filter(r=>r[t].toLowerCase().includes(e.toLowerCase()))}),d.prototype.fetchData=async function(){if(this._batchData){const o=this._batchData;return this.meta=o.meta,P(o.data)}let t={meta:{total:!0,key:!0,name:!0}};t.__args=this.buildArgs(),t.data=this.fields,this.already_limit&&(t.data.__args=t.data.__args||{},t.data.__args.limit=this.limit),this.already_offset&&(t.data.__args=t.data.__args||{},t.data.__args.offset=this.offset);const e=this.data_path.split(".");let r={},s=r,n=e[e.length-1];for(const o of e){if(o===n){s[o]=t;break}s[o]={},s=s[o]}let c=await w(this.axios,r);for(const o of e)c=c[o];return this.meta=c.meta,P(c.data)},d.prototype.processData=async function(){let t=await this.fetchData();for(const e of this.steps)t=t[e.type](...e.args);return t},d.prototype.all=async function(){return(await this.processData()).all()};for(const t of ut)d.prototype[t]=function(...e){const r=this.clone();return r.steps.push({type:t,args:e}),r};for(const t of ct)d.prototype[t]=async function(...e){return(await this.clone().processData())[t](...e)};d.prototype.average=d.prototype.avg,d.prototype.first=async function(){return this.take(1),(await this.processData()).first()},d.prototype.where=function(...t){if(t.length==2)this.filters[t[0]]=t[1];else if(t.length==3){let e="==",r=t[0],s=null;t.length==3&&(e=t[1],s=t[2]),e==="=="&&(this.filters[r]=s),e==="<"&&(this.filters[r]={lt:s}),e==="<="&&(this.filters[r]={lte:s}),e===">"&&(this.filters[r]={gt:s}),e===">="&&(this.filters[r]={gte:s}),e==="!=="&&(this.filters[r]={ne:s})}return this.steps.push({type:"where",args:t}),this},d.prototype.whereContains=function(t,e){return this.steps.push({type:"whereContains",args:[t,e]}),this.filters[t]={contains:e},this},d.prototype.forPage=function(t,e){return t=Math.max(1,t),this.already_limit?(this.steps.push({type:"forPage",args:[t,e]}),this):(this.limit=e,this.offset=(t-1)*e,this.already_limit=!0,this.already_offset=!0,this)},d.prototype.whereIn=function(t,e){return this.steps.push({type:"whereIn",args:[t,e]}),this.filters[t]={in:e},this},d.prototype.whereNotIn=function(t,e){return this.steps.push({type:"whereNotIn",args:[t,e]}),this.filters[t]={nin:e},this},d.prototype.whereNotBetween=function(t,e){return this.steps.push({type:"whereNotBetween",args:[t,e]}),this.filters[t]={notBetween:e},this},d.prototype.whereBetween=function(t,e){return this.steps.push({type:"whereBetween",args:[t,e]}),this.filters[t]={between:e},this},d.prototype.sortBy=function(t){return this.steps.push({type:"sortBy",args:[t]}),typeof t=="string"&&(this._sort=t),this},d.prototype.sortByDesc=function(t){return this.steps.push({type:"sortByDesc",args:[t]}),typeof t=="string"&&(this._sort=t,this._sortDesc=!0),this},d.prototype.skip=function(t){return this.already_offset&&this.steps.push({type:"skip",args:[t]}),this.offset=t,this.already_offset=!0,this},d.prototype.take=function(t){return this.already_limit?(this.steps.push({type:"take",args:[t]}),this):(this.limit=t,this.already_limit=!0,this)},d.prototype.splice=function(t,e){return this.steps.push({type:"splice",args:[t,e]}),this.offset=t,this.limit=e,this.already_limit=!0,this.already_offset=!0,this};const j=(t,e,r)=>{const s=new d(r,e);return s.data_path="list"+t,s},ft=(t,e)=>({uploadTempFile:r=>u(e,"lightDriveUploadTempFile",{index:t,file:r},{name:!0,path:!0,size:!0,mime:!0}),folders:{list:async(r,s={name:!0,path:!0})=>(await w(e,{app:{drive:{__args:{index:t},folders:{__args:{path:r},...s}}}})).app.drive.folders,create:r=>u(e,"lightDriveCreateFolder",{index:t,path:r}),delete:r=>u(e,"lightDriveDeleteFolder",{index:t,path:r}),rename:(r,s)=>u(e,"lightDriveRenameFolder",{index:t,path:r,name:s})},files:{list:async(r,s={name:!0,path:!0,size:!0,mime:!0,url:!0})=>(await w(e,{app:{drive:{__args:{index:t},files:{__args:{path:r},...s}}}})).app.drive.files,get:async(r,s={name:!0,path:!0,size:!0,mime:!0,url:!0})=>(await w(e,{app:{drive:{__args:{index:t},file:{__args:{path:r},...s}}}})).app.drive.file,read:async r=>{let s=await w(e,{app:{drive:{__args:{index:t},file:{__args:{path:r},base64Content:!0}}}});return window.atob(s.app.drive.file.base64Content)},write:(r,s)=>u(e,"lightDriveWriteFile",{index:t,path:r,content:s}),delete:r=>u(e,"lightDriveDeleteFile",{index:t,path:r}),rename:(r,s)=>u(e,"lightDriveRenameFile",{index:t,path:r,name:s}),move:(r,s)=>u(e,"lightDriveMoveFile",{index:t,source:r,destination:s})}}),pt=t=>{const e=O.create({baseURL:t,withCredentials:!0}),r=(i,c=null,o=[])=>u(e,i,c,o),s=i=>w(e,i),n=ot(e);return{baseURL:t,axios:e,auth:Y(e),mutation:r,query:s,config:nt(s),mail:it(e),users:at(e),fs:st(e),models:n,model(i){return n.get(i)},roles:lt(e),collect:(i,c)=>{const o=j(i,e,c);return o.data_path=n.get(i).getDataPath(),o},drive(i){return ft(i,e)},async collects(i){const c={},o={};for(const l in i){const p=i[l].getQueryPayload();o[l]=p.data_path,c[l]={};const b=p.data_path.split(".");let F=b[b.length-1],_=c[l];for(const C of b){if(C===F){_[C]=p.query;break}_[C]=_[C]||{}}c[l].__aliasFor=b[0]}const a=await w(e,c);for(const l in i){const p=o[l].split(".");let b=p[p.length-1],F=a[l];for(const _ of p){if(_===b){i[l]._batchData=a[l][_];break}F[_]=F[_]||{}}}return i}}};y.File=tt,y.createClient=pt,y.createCollection=j,y.file=N,y.mutation=u,y.query=w,y.toQuery=k,Object.defineProperty(y,Symbol.toStringTag,{value:"Module"})});
1
+ (function(y,m){typeof exports=="object"&&typeof module<"u"?m(exports,require("json-to-graphql-query"),require("axios"),require("collect.js")):typeof define=="function"&&define.amd?define(["exports","json-to-graphql-query","axios","collect.js"],m):(y=typeof globalThis<"u"?globalThis:y||self,m(y.light={},y.jsonToGraphqlQuery,y.axios,y.collect))})(this,function(y,m,O,P){"use strict";var ht=Object.defineProperty;var dt=(y,m,O)=>m in y?ht(y,m,{enumerable:!0,configurable:!0,writable:!0,value:O}):y[m]=O;var D=(y,m,O)=>dt(y,typeof m!="symbol"?m+"":m,O);function J(t){const e="==".slice(0,(4-t.length%4)%4),r=t.replace(/-/g,"+").replace(/_/g,"/")+e,s=atob(r),n=new ArrayBuffer(s.length),i=new Uint8Array(n);for(let c=0;c<s.length;c++)i[c]=s.charCodeAt(c);return n}function B(t){const e=new Uint8Array(t);let r="";for(const i of e)r+=String.fromCharCode(i);return btoa(r).replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")}var f="copy",A="convert";function S(t,e,r){if(e===f)return r;if(e===A)return t(r);if(e instanceof Array)return r.map(s=>S(t,e[0],s));if(e instanceof Object){const s={};for(const[n,i]of Object.entries(e)){if(i.derive){const c=i.derive(r);c!==void 0&&(r[n]=c)}if(!(n in r)){if(i.required)throw new Error(`Missing key: ${n}`);continue}if(r[n]==null){s[n]=null;continue}s[n]=S(t,i.schema,r[n])}return s}}function E(t,e){return{required:!0,schema:t,derive:e}}function h(t){return{required:!0,schema:t}}function g(t){return{required:!1,schema:t}}var U={type:h(f),id:h(A),transports:g(f)},T={appid:g(f),appidExclude:g(f),credProps:g(f)},L={appid:g(f),appidExclude:g(f),credProps:g(f)},V={publicKey:h({rp:h(f),user:h({id:h(A),name:h(f),displayName:h(f)}),challenge:h(A),pubKeyCredParams:h(f),timeout:g(f),excludeCredentials:g([U]),authenticatorSelection:g(f),attestation:g(f),extensions:g(T)}),signal:g(f)},M={type:h(f),id:h(f),rawId:h(A),authenticatorAttachment:g(f),response:h({clientDataJSON:h(A),attestationObject:h(A),transports:E(f,t=>{var e;return((e=t.getTransports)==null?void 0:e.call(t))||[]})}),clientExtensionResults:E(L,t=>t.getClientExtensionResults())},W={mediation:g(f),publicKey:h({challenge:h(A),timeout:g(f),rpId:g(f),allowCredentials:g([U]),userVerification:g(f),extensions:g(T)}),signal:g(f)},K={type:h(f),id:h(f),rawId:h(A),authenticatorAttachment:g(f),response:h({clientDataJSON:h(A),authenticatorData:h(A),signature:h(A),userHandle:h(A)}),clientExtensionResults:E(L,t=>t.getClientExtensionResults())};function I(t){return S(J,V,t)}function Q(t){return S(B,M,t)}function z(t){return S(J,W,t)}function G(t){return S(B,K,t)}async function $(t){const e=await navigator.credentials.create(t);return e.toJSON=()=>Q(e),e}async function H(t){const e=await navigator.credentials.get(t);return e.toJSON=()=>G(e),e}const X=t=>({login:async()=>{const{app:e}=await w(t,{app:{auth:{webAuthnRequestOptions:!0}}}),r=e.auth.webAuthnRequestOptions,s=z({publicKey:r}),n=await H(s);await u(t,"webAuthnAssertion",{assertion:n.toJSON()})},register:async()=>{const{app:e}=await w(t,{app:{auth:{webAuthnCreationOptions:!0}}}),r=I({publicKey:e.auth.webAuthnCreationOptions}),s=await $(r);await u(t,"webAuthnRegister",{registration:s.toJSON()})}}),Y=t=>({WebAuthn:X(t),google:{unlink:()=>u(t,"lightAuthUnlinkGoogle"),login:e=>u(t,"lightAuthLoginGoogle",{credential:e}),register:e=>u(t,"lightAuthRegisterGoogle",{credential:e})},facebook:{unlink:()=>u(t,"lightAuthUnlinkFacebook"),login:e=>u(t,"lightAuthLoginFacebook",{access_token:e}),register:e=>u(t,"lightAuthRegisterFacebook",{access_token:e})},microsoft:{unlink:()=>u(t,"lightAuthUnlinkMicrosoft"),login:e=>u(t,"lightAuthLoginMicrosoft",{access_token:e}),register:e=>u(t,"lightAuthRegisterMicrosoft",{account_id:e})},login:(e,r,s="")=>u(t,"login",{username:e,password:r,code:s}),logout:()=>u(t,"logout"),changeExpiredPassword:(e,r,s)=>u(t,"changeExpiredPassword",{username:e,old_password:r,new_password:s}),updatePassword:(e,r)=>u(t,"changeUserPassword",{old_password:e,new_password:r}),resetPassword:(e,r,s)=>u(t,"resetPassword",{jwt:e,password:r,code:s}),forgetPassword:(e,r)=>u(t,"forgetPassword",{username:e,email:r}),verifyCode(e,r){return u(t,"forgetPasswordVerifyCode",{jwt:e,code:r})},granted:async e=>(await w(t,{granted:{__args:{rights:e}}})).granted}),Z=(t,e,r)=>{const s=e,n=t,i=r;let c="list"+e;const o=a=>i[a]?i[a]():null;return{field:o,$fields:i,setDataPath(a){return c=a,c},getDataPath(){return c},gqlFields(a){const l=[];for(const p of a)if(typeof p=="string"){const b=o(p);b&&l.push(b.getGQLField())}else typeof p=="object"&&l.push(p);return l},async update(a,l){return await u(n,"update"+s,{id:a,data:l})},async delete(a){return await u(n,"delete"+s,{id:a})},async add(a){return await u(n,"add"+s,{data:a})},fields(a){let l=[];for(let p of a){const b=o(p);b&&l.push(b)}return l},async get(a,l){return(await w(n,{["list"+s]:{__args:{filters:a},data:{__args:{limit:1},...k(l)}}}))["list"+s].data[0]},async list(a,l){return(await w(n,{["list"+s]:{__args:{filters:a},data:{...k(l)}}}))["list"+s].data}}};function x(t){t="<~"+t+"~>";var e,r,s,n,i,c=String,o=255;for(t.slice(0,2)==="<~"&&t.slice(-2),t=t.slice(2,-2).replace(/\s/g,"").replace("z","!!!!!"),e="uuuuu".slice(t.length%5||5),t+=e,s=[],n=0,i=t.length;i>n;n+=5)r=52200625*(t.charCodeAt(n)-33)+614125*(t.charCodeAt(n+1)-33)+7225*(t.charCodeAt(n+2)-33)+85*(t.charCodeAt(n+3)-33)+(t.charCodeAt(n+4)-33),s.push(o&r>>24,o&r>>16,o&r>>8,o&r);return function(a,l){for(var p=l;p>0;p--)a.pop()}(s,e.length),c.fromCharCode.apply(c,s)}const N=(t="")=>{const e=t,r=(s="application/octet-stream")=>{const n=new Uint8Array(e.length);for(let o=0;o<e.length;o++)n[o]=e.charCodeAt(o);const i=new Blob([n],{type:s});return URL.createObjectURL(i)};return{getContent:()=>e,getURL:r,download:s=>{const n=document.createElement("a");n.download=s,n.href=r(),document.body.appendChild(n),n.click(),document.body.removeChild(n)},open:s=>{window.open(r(s),"_blank")}}},tt={fromBase85:t=>N(x(t)),fromBase64:t=>N(atob(t)),fromString:t=>N(t)},R=t=>{let e={};return typeof t=="string"?(e[t]=!0,e):t instanceof Array?(t.forEach(r=>{Object.entries(R(r)).forEach(([s,n])=>{e[s]=n})}),e):(Object.entries(t).forEach(([r,s])=>{if(r=="__args"||r=="__aliasFor"||r=="__variables"||r=="__directives"||r=="__all_on"||r=="__name"){e[r]=s;return}if(typeof s=="boolean"){e[r]=s;return}e[r]=R(s)}),e)},k=t=>R(t),w=async(t,e)=>{let r=m.jsonToGraphQLQuery(k(e));const s=await t.post("",{query:`{ ${r} }`});if(s.data.errors)throw new Error(s.data.errors[0].message);return s.data.data};function et(t){for(let e=0;e<t.length;e++)if(t[e]instanceof File)return!0;return!1}function rt(t){for(let e in t)if(t[e]instanceof File)return!0;return!1}const u=async(t,e,r=null,s=[])=>{let n={[e]:{}};const i=new FormData;let c=!1;if(r){const l={},p={},b={};let F=0;Object.entries(r).forEach(([_,C])=>{if(C instanceof Array&&et(C)){c=!0;let v=0;C.forEach(q=>{q instanceof File&&(l[_]=new m.VariableType(_),p[F]=["variables."+_+"."+v],i.append(F.toString(),q),F++)}),b[_]="[Upload!]!"}else C instanceof File?(c=!0,l[_]=new m.VariableType(_),p[F]=["variables."+_],i.append(F.toString(),C),b[_]="Upload!",F++):C instanceof Object&&rt(C)?(c=!0,l[_]={},Object.entries(C).forEach(([v,q])=>{q instanceof File?(l[_][v]=new m.VariableType(v),p[F]=["variables."+v],i.append(F.toString(),q),b[v]="Upload!",F++):l[_][v]=q})):C!==void 0&&(l[_]=C)}),n[e].__args=l,n.__variables=b,c&&i.append("map",JSON.stringify(p))}Object.entries(k(s)).forEach(([l,p])=>{n[e][l]=p}),Object.entries(n[e]).length===0&&(n[e]=!0);let o=null;const a=m.jsonToGraphQLQuery({mutation:n});if(c?(i.append("operations",JSON.stringify({query:a})),o=await t.post("",i)):o=await t.post("",{query:a}),o.data.errors)throw new Error(o.data.errors[0].message);return o.data.data[e]},st=t=>({uploadTempFile:e=>u(t,"fsUploadTempFile",{file:e},{name:!0,path:!0,size:!0,mime:!0}),folders:{list:async e=>(await w(t,{fsListFolders:{__args:{path:e},name:!0,path:!0}})).fsListFolders,create:e=>u(t,"fsCreateFolder",{path:e}),delete:e=>u(t,"fsDeleteFolder",{path:e}),rename:(e,r)=>u(t,"fsRenameFolder",{path:e,name:r})},files:{list:async e=>(await w(t,{fsListFiles:{__args:{path:e},name:!0,path:!0,size:!0,mime:!0,canPreview:!0,imagePath:!0}})).fsListFiles,read:async e=>{let r=await w(t,{fsFile:{__args:{path:e},base64Content:!0}});return window.atob(r.fsFile.base64Content)},write:(e,r)=>u(t,"fsWriteFile",{path:e,content:r}),delete:e=>u(t,"fsDeleteFile",{path:e}),rename:(e,r)=>u(t,"fsRenameFile",{path:e,name:r}),move:(e,r)=>u(t,"fsMoveFile",{source:e,target:r})}}),nt=t=>({get:async e=>(await t({config:{__args:{name:e}}})).config}),it=t=>({send:(e,r,s)=>u(t,"sendMail",{email:e,subject:r,message:s})}),at=t=>({list:async(e={user_id:!0,username:!0,first_name:!0,last_name:!0,status:!0})=>{const r=j("Users",t,e);return r.data_path="app.users",r.all()}}),ot=t=>{const e=t,r={};return{create(s,n){r[s]=null;let i={};for(const c of Object.entries(n)){const[o,a]=c;i[o]=()=>({name:a.name?a.name:o,raw:a,getName:()=>a.name?a.name:o,getGQLField:()=>a.gqlField!==void 0?a.gqlField:a.name||o,getRaw(){return a},getValue(l){return a.field&&typeof a.field=="function"?a.field(l):a.field&&typeof a.field=="string"?l[a.field]:l[this.getName()]},getFormattedValue(l){const p=this.getValue(l);return a.format?a.format(p):p}})}r[s]=Z(e,s,i)},get(s){return r[s]||this.create(s,{}),r[s]}}},lt=t=>({list:async(e={name:!0})=>{const{app:{roles:r}}=await w(t,{app:{roles:e}});return r}}),ut=["flatMap","chunk","shuffle","splice","sortBy","map","reverse","groupBy","keyBy","keys","mapToDictionary","mapWithKeys","nth","skipUntil","skipWhile","takeUntil","takeWhile","unique","pluck","push","only","pad","slice","tap","sort"],ct=["avg","count","countBy","dd","each","every","filter","firstWhere","isEmpty","isNotEmpty","last","mapToGroups","max","median","min","mode","contains","sole","sort","split","sum","toJson","get","has","implode","partition","sole"];class d{constructor(e,r){D(this,"_batchData",null);D(this,"data_path","");D(this,"axios");D(this,"filters");D(this,"steps");D(this,"fields");D(this,"already_limit",!1);D(this,"already_offset",!1);D(this,"limit",null);D(this,"offset",null);D(this,"_sort",null);D(this,"_sortDesc",!1);D(this,"meta",{});this.axios=r,this.filters={},this.steps=[],this.fields=e}}d.prototype.getQueryPayload=function(){let t={meta:{total:!0,key:!0,name:!0}};return t.__args=this.buildArgs(),t.data=this.fields,t.data.__args=t.data.__args||{},this.limit&&(t.data.__args.limit=this.limit),this.offset&&(t.data.__args.offset=this.offset),{data_path:this.data_path,query:t,steps:this.steps}},d.prototype.dataPath=function(t){const e=this.clone();return e.data_path=t,e},d.prototype.buildArgs=function(){let t={};return Object.keys(this.filters).length>0&&(t.filters=this.filters),this._sort&&(t.sort=this._sort,this._sortDesc&&(t.sort+=":desc")),t},d.prototype.clone=function(){const t=Object.create(this);return t.steps=JSON.parse(JSON.stringify(this.steps)),t.filters=JSON.parse(JSON.stringify(this.filters)),t.fields=JSON.parse(JSON.stringify(this.fields)),t},P().macro("whereContains",function(t,e){return this.filter(r=>r[t].toLowerCase().includes(e.toLowerCase()))}),d.prototype.fetchData=async function(){if(this._batchData){const o=this._batchData;return this.meta=o.meta,P(o.data)}let t={meta:{total:!0,key:!0,name:!0}};t.__args=this.buildArgs(),t.data=this.fields,this.already_limit&&(t.data.__args=t.data.__args||{},t.data.__args.limit=this.limit),this.already_offset&&(t.data.__args=t.data.__args||{},t.data.__args.offset=this.offset);const e=this.data_path.split(".");let r={},s=r,n=e[e.length-1];for(const o of e){if(o===n){s[o]=t;break}s[o]={},s=s[o]}let c=await w(this.axios,r);for(const o of e)c=c[o];return this.meta=c.meta,P(c.data)},d.prototype.processData=async function(){let t=await this.fetchData();for(const e of this.steps)t=t[e.type](...e.args);return t},d.prototype.all=async function(){return(await this.processData()).all()};for(const t of ut)d.prototype[t]=function(...e){const r=this.clone();return r.steps.push({type:t,args:e}),r};for(const t of ct)d.prototype[t]=async function(...e){return(await this.clone().processData())[t](...e)};d.prototype.average=d.prototype.avg,d.prototype.first=async function(){return this.take(1),(await this.processData()).first()},d.prototype.where=function(...t){if(this._batchData)return this.steps.push({type:"where",args:t}),this;if(t.length==2)this.filters[t[0]]=t[1];else if(t.length==3){let e="==",r=t[0],s=null;t.length==3&&(e=t[1],s=t[2]),e==="=="&&(this.filters[r]=s),e==="<"&&(this.filters[r]={lt:s}),e==="<="&&(this.filters[r]={lte:s}),e===">"&&(this.filters[r]={gt:s}),e===">="&&(this.filters[r]={gte:s}),e==="!=="&&(this.filters[r]={ne:s})}return this},d.prototype.whereContains=function(t,e){return this._batchData?(this.steps.push({type:"whereContains",args:[t,e]}),this):(this.filters[t]={contains:e},this)},d.prototype.forPage=function(t,e){return t=Math.max(1,t),this.already_limit?(this.steps.push({type:"forPage",args:[t,e]}),this):(this.limit=e,this.offset=(t-1)*e,this.already_limit=!0,this.already_offset=!0,this)},d.prototype.whereIn=function(t,e){return this._batchData?(this.steps.push({type:"whereIn",args:[t,e]}),this):(this.filters[t]={in:e},this)},d.prototype.whereNotIn=function(t,e){return this._batchData?(this.steps.push({type:"whereNotIn",args:[t,e]}),this):(this.filters[t]={nin:e},this)},d.prototype.whereNotBetween=function(t,e){return this._batchData?(this.steps.push({type:"whereNotBetween",args:[t,e]}),this):(this.filters[t]={notBetween:e},this)},d.prototype.whereBetween=function(t,e){return this._batchData?(this.steps.push({type:"whereBetween",args:[t,e]}),this):(this.filters[t]={between:e},this)},d.prototype.sortBy=function(t){return this.steps.push({type:"sortBy",args:[t]}),typeof t=="string"&&(this._sort=t),this},d.prototype.sortByDesc=function(t){return this.steps.push({type:"sortByDesc",args:[t]}),typeof t=="string"&&(this._sort=t,this._sortDesc=!0),this},d.prototype.skip=function(t){return this.already_offset&&this.steps.push({type:"skip",args:[t]}),this.offset=t,this.already_offset=!0,this},d.prototype.take=function(t){return this.already_limit?(this.steps.push({type:"take",args:[t]}),this):(this.limit=t,this.already_limit=!0,this)},d.prototype.splice=function(t,e){return this.steps.push({type:"splice",args:[t,e]}),this.offset=t,this.limit=e,this.already_limit=!0,this.already_offset=!0,this};const j=(t,e,r)=>{const s=new d(r,e);return s.data_path="list"+t,s},ft=(t,e)=>({uploadTempFile:r=>u(e,"lightDriveUploadTempFile",{index:t,file:r},{name:!0,path:!0,size:!0,mime:!0}),folders:{list:async(r,s={name:!0,path:!0})=>(await w(e,{app:{drive:{__args:{index:t},folders:{__args:{path:r},...s}}}})).app.drive.folders,create:r=>u(e,"lightDriveCreateFolder",{index:t,path:r}),delete:r=>u(e,"lightDriveDeleteFolder",{index:t,path:r}),rename:(r,s)=>u(e,"lightDriveRenameFolder",{index:t,path:r,name:s})},files:{list:async(r,s={name:!0,path:!0,size:!0,mime:!0,url:!0})=>(await w(e,{app:{drive:{__args:{index:t},files:{__args:{path:r},...s}}}})).app.drive.files,get:async(r,s={name:!0,path:!0,size:!0,mime:!0,url:!0})=>(await w(e,{app:{drive:{__args:{index:t},file:{__args:{path:r},...s}}}})).app.drive.file,read:async r=>{let s=await w(e,{app:{drive:{__args:{index:t},file:{__args:{path:r},base64Content:!0}}}});return window.atob(s.app.drive.file.base64Content)},write:(r,s)=>u(e,"lightDriveWriteFile",{index:t,path:r,content:s}),delete:r=>u(e,"lightDriveDeleteFile",{index:t,path:r}),rename:(r,s)=>u(e,"lightDriveRenameFile",{index:t,path:r,name:s}),move:(r,s)=>u(e,"lightDriveMoveFile",{index:t,source:r,destination:s})}}),pt=t=>{const e=O.create({baseURL:t,withCredentials:!0}),r=(i,c=null,o=[])=>u(e,i,c,o),s=i=>w(e,i),n=ot(e);return{baseURL:t,axios:e,auth:Y(e),mutation:r,query:s,config:nt(s),mail:it(e),users:at(e),fs:st(e),models:n,model(i){return n.get(i)},roles:lt(e),collect:(i,c)=>{const o=j(i,e,c);return o.data_path=n.get(i).getDataPath(),o},drive(i){return ft(i,e)},async collects(i){const c={},o={};for(const l in i){const p=i[l].getQueryPayload();o[l]=p.data_path,c[l]={};const b=p.data_path.split(".");let F=b[b.length-1],_=c[l];for(const C of b){if(C===F){_[C]=p.query;break}_[C]=_[C]||{}}c[l].__aliasFor=b[0]}const a=await w(e,c);for(const l in i){const p=o[l].split(".");let b=p[p.length-1],F=a[l];for(const _ of p){if(_===b){i[l]._batchData=a[l][_];break}F[_]=F[_]||{}}}return i}}};y.File=tt,y.createClient=pt,y.createCollection=j,y.file=N,y.mutation=u,y.query=w,y.toQuery=k,Object.defineProperty(y,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hostlink/light",
3
- "version": "2.7.0",
3
+ "version": "2.7.2",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"