@hostlink/light 0.0.24 → 1.0.0

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.
@@ -0,0 +1,5 @@
1
+ export default function (): {
2
+ merge: (obj1: any, obj2: any) => any;
3
+ add: (f: any) => void;
4
+ get(): any;
5
+ };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  export * from './auth';
2
2
  export * from './axios';
3
3
  export * from './granted';
4
+ export * from './model';
4
5
  import query from './query';
5
6
  import mutation from './mutation';
6
7
  import toQuery from './toQuery';
package/dist/light.js CHANGED
@@ -1,6 +1,6 @@
1
- import R from "axios";
2
- import { jsonToGraphQLQuery as b, VariableType as x } from "json-to-graphql-query";
3
- const M = (e, t, r = "") => c("login", {
1
+ import x from "axios";
2
+ import { jsonToGraphQLQuery as h, VariableType as E } from "json-to-graphql-query";
3
+ const G = (e, t, r = "") => c("login", {
4
4
  username: e,
5
5
  password: t,
6
6
  code: r
@@ -11,25 +11,53 @@ const M = (e, t, r = "") => c("login", {
11
11
  email: e,
12
12
  password: t,
13
13
  code: r
14
- }), Q = (e) => c("forgetPassword", {
14
+ }), z = (e) => c("forgetPassword", {
15
15
  email: e
16
16
  });
17
- let g;
18
- const z = (e) => {
19
- g = e;
20
- }, h = () => (g || (g = R.create({
17
+ let w;
18
+ const $ = (e) => {
19
+ w = e;
20
+ }, y = () => (w || (w = x.create({
21
21
  withCredentials: !0
22
- })), g), $ = async (e) => (await d({
22
+ })), w), H = async (e) => (await d({
23
23
  granted: {
24
24
  __args: {
25
25
  rights: e
26
26
  }
27
27
  }
28
- })).granted, w = (e) => {
28
+ })).granted, g = {}, X = (e, t) => {
29
+ g[e] = {};
30
+ for (const r of Object.entries(t)) {
31
+ const [n, s] = r;
32
+ g[e][n] = () => ({
33
+ getName: () => s.name ? s.name : n,
34
+ getGQLField: () => s.gqlField !== void 0 ? s.gqlField : s.name || n,
35
+ getRaw() {
36
+ return s;
37
+ },
38
+ getValue(u) {
39
+ return s.field && typeof s.field == "function" ? s.field(u) : s.field && typeof s.field == "string" ? u[s.field] : u[this.getName()];
40
+ },
41
+ getFormattedValue(u) {
42
+ const f = this.getValue(u);
43
+ return s.format ? s.format(f) : f;
44
+ }
45
+ });
46
+ }
47
+ }, q = (e, t) => !g[e] || !g[e][t] ? null : g[e][t](), Y = (e, t) => {
48
+ const r = [];
49
+ for (const n of t)
50
+ if (typeof n == "string") {
51
+ const s = q(e, n);
52
+ s && r.push(s.getGQLField());
53
+ } else
54
+ typeof n == "object" && r.push(n);
55
+ return r;
56
+ }, m = (e) => {
29
57
  let t = {};
30
58
  return typeof e == "string" ? (t[e] = !0, t) : e instanceof Array ? (e.forEach((r) => {
31
- Object.entries(w(r)).forEach(([n, i]) => {
32
- t[n] = i;
59
+ Object.entries(m(r)).forEach(([n, s]) => {
60
+ t[n] = s;
33
61
  });
34
62
  }), t) : (Object.entries(e).forEach(([r, n]) => {
35
63
  if (r == "__args" || r == "__aliasFor" || r == "__variables" || r == "__directives" || r == "__all_on" || r == "__name") {
@@ -40,11 +68,11 @@ const z = (e) => {
40
68
  t[r] = n;
41
69
  return;
42
70
  }
43
- t[r] = w(n);
71
+ t[r] = m(n);
44
72
  }), t);
45
- }, y = (e) => w(e), d = async (e) => {
46
- let t = b(y(e));
47
- const r = await h().post(_(), {
73
+ }, F = (e) => m(e), d = async (e) => {
74
+ let t = h(F(e));
75
+ const r = await y().post(_(), {
48
76
  query: `{ ${t} }`
49
77
  });
50
78
  if (r.data.errors)
@@ -54,28 +82,28 @@ const z = (e) => {
54
82
  const n = {
55
83
  mutation: {}
56
84
  };
57
- n.mutation[e] = !0, r instanceof Array && r.length != 0 && (n.mutation[e] = {}), t && (n.mutation[e] = {}, n.mutation[e].__args = t), Object.entries(y(r)).forEach(([l, f]) => {
58
- n.mutation[e][l] = f;
85
+ n.mutation[e] = !0, r instanceof Array && r.length != 0 && (n.mutation[e] = {}), t && (n.mutation[e] = {}, n.mutation[e].__args = t), Object.entries(F(r)).forEach(([u, f]) => {
86
+ n.mutation[e][u] = f;
59
87
  });
60
- const i = await h().post(_(), {
61
- query: b(n)
88
+ const s = await y().post(_(), {
89
+ query: h(n)
62
90
  });
63
- if (i.data.errors)
64
- throw new Error(i.data.errors[0].message);
65
- return i.data.data[e];
91
+ if (s.data.errors)
92
+ throw new Error(s.data.errors[0].message);
93
+ return s.data.data[e];
66
94
  };
67
- let F = "/api/";
68
- const G = (e) => {
69
- F = e;
70
- }, _ = () => F;
71
- async function H(e) {
95
+ let O = "/api/";
96
+ const Z = (e) => {
97
+ O = e;
98
+ }, _ = () => O;
99
+ async function k(e) {
72
100
  const t = {
73
101
  __variables: {
74
102
  file: "Upload!"
75
103
  },
76
104
  fsUploadTempFile: {
77
105
  __args: {
78
- file: new x("file")
106
+ file: new E("file")
79
107
  },
80
108
  name: !0,
81
109
  path: !0,
@@ -84,185 +112,185 @@ async function H(e) {
84
112
  }
85
113
  }, r = new FormData();
86
114
  r.append("operations", JSON.stringify({
87
- query: b({ mutation: t })
115
+ query: h({ mutation: t })
88
116
  })), r.append("map", JSON.stringify({ 0: ["variables.file"] })), r.append("0", e);
89
- const n = await h().post(_(), r);
117
+ const n = await y().post(_(), r);
90
118
  if (n.data.errors)
91
119
  throw new Error(n.data.errors[0].message);
92
120
  return n.data.data.fsUploadTempFile;
93
121
  }
94
- const X = (e, t, r) => c("sendMail", {
122
+ const ee = (e, t, r) => c("sendMail", {
95
123
  email: e,
96
124
  subject: t,
97
125
  message: r
98
- }), Y = async (e) => (await d({
126
+ }), te = async (e) => (await d({
99
127
  config: {
100
128
  __args: {
101
129
  name: e
102
130
  }
103
131
  }
104
132
  })).config;
105
- function O(e) {
106
- const t = "==".slice(0, (4 - e.length % 4) % 4), r = e.replace(/-/g, "+").replace(/_/g, "/") + t, n = atob(r), i = new ArrayBuffer(n.length), l = new Uint8Array(i);
133
+ function v(e) {
134
+ const t = "==".slice(0, (4 - e.length % 4) % 4), r = e.replace(/-/g, "+").replace(/_/g, "/") + t, n = atob(r), s = new ArrayBuffer(n.length), u = new Uint8Array(s);
107
135
  for (let f = 0; f < n.length; f++)
108
- l[f] = n.charCodeAt(f);
109
- return i;
136
+ u[f] = n.charCodeAt(f);
137
+ return s;
110
138
  }
111
- function v(e) {
139
+ function A(e) {
112
140
  const t = new Uint8Array(e);
113
141
  let r = "";
114
- for (const l of t)
115
- r += String.fromCharCode(l);
142
+ for (const u of t)
143
+ r += String.fromCharCode(u);
116
144
  return btoa(r).replace(/\+/g, "-").replace(
117
145
  /\//g,
118
146
  "_"
119
147
  ).replace(/=/g, "");
120
148
  }
121
- var s = "copy", u = "convert";
149
+ var a = "copy", l = "convert";
122
150
  function p(e, t, r) {
123
- if (t === s)
151
+ if (t === a)
124
152
  return r;
125
- if (t === u)
153
+ if (t === l)
126
154
  return e(r);
127
155
  if (t instanceof Array)
128
156
  return r.map((n) => p(e, t[0], n));
129
157
  if (t instanceof Object) {
130
158
  const n = {};
131
- for (const [i, l] of Object.entries(t)) {
132
- if (l.derive) {
133
- const f = l.derive(r);
134
- f !== void 0 && (r[i] = f);
159
+ for (const [s, u] of Object.entries(t)) {
160
+ if (u.derive) {
161
+ const f = u.derive(r);
162
+ f !== void 0 && (r[s] = f);
135
163
  }
136
- if (!(i in r)) {
137
- if (l.required)
138
- throw new Error(`Missing key: ${i}`);
164
+ if (!(s in r)) {
165
+ if (u.required)
166
+ throw new Error(`Missing key: ${s}`);
139
167
  continue;
140
168
  }
141
- if (r[i] == null) {
142
- n[i] = null;
169
+ if (r[s] == null) {
170
+ n[s] = null;
143
171
  continue;
144
172
  }
145
- n[i] = p(
173
+ n[s] = p(
146
174
  e,
147
- l.schema,
148
- r[i]
175
+ u.schema,
176
+ r[s]
149
177
  );
150
178
  }
151
179
  return n;
152
180
  }
153
181
  }
154
- function m(e, t) {
182
+ function b(e, t) {
155
183
  return {
156
184
  required: !0,
157
185
  schema: e,
158
186
  derive: t
159
187
  };
160
188
  }
161
- function a(e) {
189
+ function o(e) {
162
190
  return {
163
191
  required: !0,
164
192
  schema: e
165
193
  };
166
194
  }
167
- function o(e) {
195
+ function i(e) {
168
196
  return {
169
197
  required: !1,
170
198
  schema: e
171
199
  };
172
200
  }
173
- var A = {
174
- type: a(s),
175
- id: a(u),
176
- transports: o(s)
177
- }, C = {
178
- appid: o(s),
179
- appidExclude: o(s),
180
- credProps: o(s)
201
+ var C = {
202
+ type: o(a),
203
+ id: o(l),
204
+ transports: i(a)
181
205
  }, S = {
182
- appid: o(s),
183
- appidExclude: o(s),
184
- credProps: o(s)
185
- }, E = {
186
- publicKey: a({
187
- rp: a(s),
188
- user: a({
189
- id: a(u),
190
- name: a(s),
191
- displayName: a(s)
206
+ appid: i(a),
207
+ appidExclude: i(a),
208
+ credProps: i(a)
209
+ }, R = {
210
+ appid: i(a),
211
+ appidExclude: i(a),
212
+ credProps: i(a)
213
+ }, N = {
214
+ publicKey: o({
215
+ rp: o(a),
216
+ user: o({
217
+ id: o(l),
218
+ name: o(a),
219
+ displayName: o(a)
192
220
  }),
193
- challenge: a(u),
194
- pubKeyCredParams: a(s),
195
- timeout: o(s),
196
- excludeCredentials: o([A]),
197
- authenticatorSelection: o(s),
198
- attestation: o(s),
199
- extensions: o(C)
221
+ challenge: o(l),
222
+ pubKeyCredParams: o(a),
223
+ timeout: i(a),
224
+ excludeCredentials: i([C]),
225
+ authenticatorSelection: i(a),
226
+ attestation: i(a),
227
+ extensions: i(S)
200
228
  }),
201
- signal: o(s)
202
- }, q = {
203
- type: a(s),
204
- id: a(s),
205
- rawId: a(u),
206
- authenticatorAttachment: o(s),
207
- response: a({
208
- clientDataJSON: a(u),
209
- attestationObject: a(u),
210
- transports: m(
211
- s,
229
+ signal: i(a)
230
+ }, J = {
231
+ type: o(a),
232
+ id: o(a),
233
+ rawId: o(l),
234
+ authenticatorAttachment: i(a),
235
+ response: o({
236
+ clientDataJSON: o(l),
237
+ attestationObject: o(l),
238
+ transports: b(
239
+ a,
212
240
  (e) => {
213
241
  var t;
214
242
  return ((t = e.getTransports) == null ? void 0 : t.call(e)) || [];
215
243
  }
216
244
  )
217
245
  }),
218
- clientExtensionResults: m(
219
- S,
246
+ clientExtensionResults: b(
247
+ R,
220
248
  (e) => e.getClientExtensionResults()
221
249
  )
222
- }, J = {
223
- mediation: o(s),
224
- publicKey: a({
225
- challenge: a(u),
226
- timeout: o(s),
227
- rpId: o(s),
228
- allowCredentials: o([A]),
229
- userVerification: o(s),
230
- extensions: o(C)
250
+ }, j = {
251
+ mediation: i(a),
252
+ publicKey: o({
253
+ challenge: o(l),
254
+ timeout: i(a),
255
+ rpId: i(a),
256
+ allowCredentials: i([C]),
257
+ userVerification: i(a),
258
+ extensions: i(S)
231
259
  }),
232
- signal: o(s)
233
- }, N = {
234
- type: a(s),
235
- id: a(s),
236
- rawId: a(u),
237
- authenticatorAttachment: o(s),
238
- response: a({
239
- clientDataJSON: a(u),
240
- authenticatorData: a(u),
241
- signature: a(u),
242
- userHandle: a(u)
260
+ signal: i(a)
261
+ }, L = {
262
+ type: o(a),
263
+ id: o(a),
264
+ rawId: o(l),
265
+ authenticatorAttachment: i(a),
266
+ response: o({
267
+ clientDataJSON: o(l),
268
+ authenticatorData: o(l),
269
+ signature: o(l),
270
+ userHandle: o(l)
243
271
  }),
244
- clientExtensionResults: m(
245
- S,
272
+ clientExtensionResults: b(
273
+ R,
246
274
  (e) => e.getClientExtensionResults()
247
275
  )
248
276
  };
249
277
  function P(e) {
250
- return p(O, E, e);
278
+ return p(v, N, e);
251
279
  }
252
- function j(e) {
280
+ function D(e) {
253
281
  return p(
254
- v,
255
- q,
282
+ A,
283
+ J,
256
284
  e
257
285
  );
258
286
  }
259
- function D(e) {
260
- return p(O, J, e);
261
- }
262
287
  function T(e) {
288
+ return p(v, j, e);
289
+ }
290
+ function V(e) {
263
291
  return p(
264
- v,
265
- N,
292
+ A,
293
+ L,
266
294
  e
267
295
  );
268
296
  }
@@ -270,30 +298,30 @@ async function K(e) {
270
298
  const t = await navigator.credentials.create(
271
299
  e
272
300
  );
273
- return t.toJSON = () => j(t), t;
301
+ return t.toJSON = () => D(t), t;
274
302
  }
275
- async function L(e) {
303
+ async function M(e) {
276
304
  const t = await navigator.credentials.get(
277
305
  e
278
306
  );
279
- return t.toJSON = () => T(t), t;
307
+ return t.toJSON = () => V(t), t;
280
308
  }
281
- async function Z(e) {
309
+ async function re(e) {
282
310
  const r = (await d({
283
311
  webAuthnRequestOptions: {
284
312
  __args: {
285
313
  username: e
286
314
  }
287
315
  }
288
- })).webAuthnRequestOptions, n = D({
316
+ })).webAuthnRequestOptions, n = T({
289
317
  publicKey: r
290
- }), i = await L(n);
318
+ }), s = await M(n);
291
319
  await c("webAuthnAssertion", {
292
320
  username: e,
293
- assertion: i.toJSON()
321
+ assertion: s.toJSON()
294
322
  });
295
323
  }
296
- async function k() {
324
+ async function ne() {
297
325
  const e = await d({ webAuthnCreationOptions: !0 }), t = P({
298
326
  publicKey: e.webAuthnCreationOptions
299
327
  }), r = await K(t);
@@ -301,7 +329,7 @@ async function k() {
301
329
  registration: r.toJSON()
302
330
  });
303
331
  }
304
- const ee = async (e) => (await d({
332
+ const se = async (e) => (await d({
305
333
  fsListFiles: {
306
334
  __args: {
307
335
  path: e
@@ -313,7 +341,7 @@ const ee = async (e) => (await d({
313
341
  canPreview: !0,
314
342
  imagePath: !0
315
343
  }
316
- })).fsListFiles, te = async (e) => (await d({
344
+ })).fsListFiles, ae = async (e) => (await d({
317
345
  fsListFolders: {
318
346
  __args: {
319
347
  path: e
@@ -321,7 +349,7 @@ const ee = async (e) => (await d({
321
349
  name: !0,
322
350
  path: !0
323
351
  }
324
- })).fsListFolders, re = async (e) => {
352
+ })).fsListFolders, oe = async (e) => {
325
353
  let t = await d({
326
354
  fsFile: {
327
355
  __args: {
@@ -331,52 +359,55 @@ const ee = async (e) => (await d({
331
359
  }
332
360
  });
333
361
  return window.atob(t.fsFile.base64Content);
334
- }, ne = (e, t) => c("fsWriteFile", {
362
+ }, ie = (e, t) => c("fsWriteFile", {
335
363
  path: e,
336
364
  content: t
337
- }), se = (e) => c("fsDeleteFile", {
365
+ }), ue = (e) => c("fsDeleteFile", {
338
366
  path: e
339
- }), ae = (e) => c("fsCreateFolder", {
367
+ }), ce = (e) => c("fsCreateFolder", {
340
368
  path: e
341
- }), oe = (e) => c("fsDeleteFolder", {
369
+ }), le = (e) => c("fsDeleteFolder", {
342
370
  path: e
343
- }), ie = (e, t) => c("fsRenameFile", {
371
+ }), fe = (e, t) => c("fsRenameFile", {
344
372
  path: e,
345
373
  name: t
346
- }), ce = (e, t) => c("fsRenameFolder", {
374
+ }), de = (e, t) => c("fsRenameFolder", {
347
375
  path: e,
348
376
  name: t
349
- }), ue = (e, t) => c("fsMoveFile", {
377
+ }), pe = (e, t) => c("fsMoveFile", {
350
378
  source: e,
351
379
  target: t
352
380
  });
353
381
  export {
354
- Q as forgetPassword,
355
- ae as fsCreateFolder,
356
- se as fsDeleteFile,
357
- oe as fsDeleteFolder,
358
- ee as fsListFiles,
359
- te as fsListFolders,
360
- ue as fsMoveFile,
361
- re as fsReadFile,
362
- ie as fsRenameFile,
363
- ce as fsRenameFolder,
364
- ne as fsWriteFile,
382
+ X as defineModel,
383
+ z as forgetPassword,
384
+ ce as fsCreateFolder,
385
+ ue as fsDeleteFile,
386
+ le as fsDeleteFolder,
387
+ se as fsListFiles,
388
+ ae as fsListFolders,
389
+ pe as fsMoveFile,
390
+ oe as fsReadFile,
391
+ fe as fsRenameFile,
392
+ de as fsRenameFolder,
393
+ ie as fsWriteFile,
365
394
  _ as getApiUrl,
366
- h as getAxios,
367
- Y as getConfig,
368
- $ as granted,
369
- M as login,
395
+ y as getAxios,
396
+ te as getConfig,
397
+ Y as getGQLFields,
398
+ q as getModelField,
399
+ H as granted,
400
+ G as login,
370
401
  W as logout,
371
402
  c as mutation,
372
403
  d as query,
373
404
  I as resetPassword,
374
- X as sendMail,
375
- G as setApiUrl,
376
- z as setAxios,
377
- y as toQuery,
405
+ ee as sendMail,
406
+ Z as setApiUrl,
407
+ $ as setAxios,
408
+ F as toQuery,
378
409
  B as updatePassword,
379
- H as uploadFile,
380
- Z as webauthnLogin,
381
- k as webauthnRegister
410
+ k as uploadFile,
411
+ re as webauthnLogin,
412
+ ne as webauthnRegister
382
413
  };
@@ -1 +1 @@
1
- (function(n,w){typeof exports=="object"&&typeof module<"u"?w(exports,require("axios"),require("json-to-graphql-query")):typeof define=="function"&&define.amd?define(["exports","axios","json-to-graphql-query"],w):(n=typeof globalThis<"u"?globalThis:n||self,w(n.light={},n.axios,n.jsonToGraphqlQuery))})(this,function(n,w,m){"use strict";const E=(e,t,r="")=>l("login",{username:e,password:t,code:r}),P=()=>l("logout"),j=(e,t)=>l("updatePassword",{old_password:e,new_password:t}),J=(e,t,r)=>l("resetPassword",{email:e,password:t,code:r}),L=e=>l("forgetPassword",{email:e});let h;const N=e=>{h=e},b=()=>(h||(h=w.create({withCredentials:!0})),h),D=async e=>(await g({granted:{__args:{rights:e}}})).granted,F=e=>{let t={};return typeof e=="string"?(t[e]=!0,t):e instanceof Array?(e.forEach(r=>{Object.entries(F(r)).forEach(([s,u])=>{t[s]=u})}),t):(Object.entries(e).forEach(([r,s])=>{if(r=="__args"||r=="__aliasFor"||r=="__variables"||r=="__directives"||r=="__all_on"||r=="__name"){t[r]=s;return}if(typeof s=="boolean"){t[r]=s;return}t[r]=F(s)}),t)},_=e=>F(e),g=async e=>{let t=m.jsonToGraphQLQuery(_(e));const r=await b().post(y(),{query:`{ ${t} }`});if(r.data.errors)throw new Error(r.data.errors[0].message);return r.data.data},l=async(e,t=null,r=[])=>{const s={mutation:{}};s.mutation[e]=!0,r instanceof Array&&r.length!=0&&(s.mutation[e]={}),t&&(s.mutation[e]={},s.mutation[e].__args=t),Object.entries(_(r)).forEach(([f,d])=>{s.mutation[e][f]=d});const u=await b().post(y(),{query:m.jsonToGraphQLQuery(s)});if(u.data.errors)throw new Error(u.data.errors[0].message);return u.data.data[e]};let O="/api/";const T=e=>{O=e},y=()=>O;async function U(e){const t={__variables:{file:"Upload!"},fsUploadTempFile:{__args:{file:new m.VariableType("file")},name:!0,path:!0,size:!0,mime:!0}},r=new FormData;r.append("operations",JSON.stringify({query:m.jsonToGraphQLQuery({mutation:t})})),r.append("map",JSON.stringify({0:["variables.file"]})),r.append("0",e);const s=await b().post(y(),r);if(s.data.errors)throw new Error(s.data.errors[0].message);return s.data.data.fsUploadTempFile}const K=(e,t,r)=>l("sendMail",{email:e,subject:t,message:r}),M=async e=>(await g({config:{__args:{name:e}}})).config;function v(e){const t="==".slice(0,(4-e.length%4)%4),r=e.replace(/-/g,"+").replace(/_/g,"/")+t,s=atob(r),u=new ArrayBuffer(s.length),f=new Uint8Array(u);for(let d=0;d<s.length;d++)f[d]=s.charCodeAt(d);return u}function C(e){const t=new Uint8Array(e);let r="";for(const f of t)r+=String.fromCharCode(f);return btoa(r).replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")}var a="copy",c="convert";function p(e,t,r){if(t===a)return r;if(t===c)return e(r);if(t instanceof Array)return r.map(s=>p(e,t[0],s));if(t instanceof Object){const s={};for(const[u,f]of Object.entries(t)){if(f.derive){const d=f.derive(r);d!==void 0&&(r[u]=d)}if(!(u in r)){if(f.required)throw new Error(`Missing key: ${u}`);continue}if(r[u]==null){s[u]=null;continue}s[u]=p(e,f.schema,r[u])}return s}}function A(e,t){return{required:!0,schema:e,derive:t}}function i(e){return{required:!0,schema:e}}function o(e){return{required:!1,schema:e}}var R={type:i(a),id:i(c),transports:o(a)},S={appid:o(a),appidExclude:o(a),credProps:o(a)},q={appid:o(a),appidExclude:o(a),credProps:o(a)},Q={publicKey:i({rp:i(a),user:i({id:i(c),name:i(a),displayName:i(a)}),challenge:i(c),pubKeyCredParams:i(a),timeout:o(a),excludeCredentials:o([R]),authenticatorSelection:o(a),attestation:o(a),extensions:o(S)}),signal:o(a)},V={type:i(a),id:i(a),rawId:i(c),authenticatorAttachment:o(a),response:i({clientDataJSON:i(c),attestationObject:i(c),transports:A(a,e=>{var t;return((t=e.getTransports)==null?void 0:t.call(e))||[]})}),clientExtensionResults:A(q,e=>e.getClientExtensionResults())},W={mediation:o(a),publicKey:i({challenge:i(c),timeout:o(a),rpId:o(a),allowCredentials:o([R]),userVerification:o(a),extensions:o(S)}),signal:o(a)},B={type:i(a),id:i(a),rawId:i(c),authenticatorAttachment:o(a),response:i({clientDataJSON:i(c),authenticatorData:i(c),signature:i(c),userHandle:i(c)}),clientExtensionResults:A(q,e=>e.getClientExtensionResults())};function I(e){return p(v,Q,e)}function z(e){return p(C,V,e)}function $(e){return p(v,W,e)}function G(e){return p(C,B,e)}async function H(e){const t=await navigator.credentials.create(e);return t.toJSON=()=>z(t),t}async function X(e){const t=await navigator.credentials.get(e);return t.toJSON=()=>G(t),t}async function Y(e){const r=(await g({webAuthnRequestOptions:{__args:{username:e}}})).webAuthnRequestOptions,s=$({publicKey:r}),u=await X(s);await l("webAuthnAssertion",{username:e,assertion:u.toJSON()})}async function Z(){const e=await g({webAuthnCreationOptions:!0}),t=I({publicKey:e.webAuthnCreationOptions}),r=await H(t);await l("webAuthnRegister",{registration:r.toJSON()})}const k=async e=>(await g({fsListFiles:{__args:{path:e},name:!0,path:!0,size:!0,mime:!0,canPreview:!0,imagePath:!0}})).fsListFiles,x=async e=>(await g({fsListFolders:{__args:{path:e},name:!0,path:!0}})).fsListFolders,ee=async e=>{let t=await g({fsFile:{__args:{path:e},base64Content:!0}});return window.atob(t.fsFile.base64Content)},te=(e,t)=>l("fsWriteFile",{path:e,content:t}),re=e=>l("fsDeleteFile",{path:e}),ne=e=>l("fsCreateFolder",{path:e}),se=e=>l("fsDeleteFolder",{path:e}),ae=(e,t)=>l("fsRenameFile",{path:e,name:t}),ie=(e,t)=>l("fsRenameFolder",{path:e,name:t}),oe=(e,t)=>l("fsMoveFile",{source:e,target:t});n.forgetPassword=L,n.fsCreateFolder=ne,n.fsDeleteFile=re,n.fsDeleteFolder=se,n.fsListFiles=k,n.fsListFolders=x,n.fsMoveFile=oe,n.fsReadFile=ee,n.fsRenameFile=ae,n.fsRenameFolder=ie,n.fsWriteFile=te,n.getApiUrl=y,n.getAxios=b,n.getConfig=M,n.granted=D,n.login=E,n.logout=P,n.mutation=l,n.query=g,n.resetPassword=J,n.sendMail=K,n.setApiUrl=T,n.setAxios=N,n.toQuery=_,n.updatePassword=j,n.uploadFile=U,n.webauthnLogin=Y,n.webauthnRegister=Z,Object.defineProperty(n,Symbol.toStringTag,{value:"Module"})});
1
+ (function(s,w){typeof exports=="object"&&typeof module<"u"?w(exports,require("axios"),require("json-to-graphql-query")):typeof define=="function"&&define.amd?define(["exports","axios","json-to-graphql-query"],w):(s=typeof globalThis<"u"?globalThis:s||self,w(s.light={},s.axios,s.jsonToGraphqlQuery))})(this,function(s,w,h){"use strict";const E=(e,t,r="")=>l("login",{username:e,password:t,code:r}),N=()=>l("logout"),P=(e,t)=>l("updatePassword",{old_password:e,new_password:t}),J=(e,t,r)=>l("resetPassword",{email:e,password:t,code:r}),D=e=>l("forgetPassword",{email:e});let y;const M=e=>{y=e},F=()=>(y||(y=w.create({withCredentials:!0})),y),T=async e=>(await g({granted:{__args:{rights:e}}})).granted,m={},Q=(e,t)=>{m[e]={};for(const r of Object.entries(t)){const[n,i]=r;m[e][n]=()=>({getName:()=>i.name?i.name:n,getGQLField:()=>i.gqlField!==void 0?i.gqlField:i.name||n,getRaw(){return i},getValue(c){return i.field&&typeof i.field=="function"?i.field(c):i.field&&typeof i.field=="string"?c[i.field]:c[this.getName()]},getFormattedValue(c){const d=this.getValue(c);return i.format?i.format(d):d}})}},O=(e,t)=>!m[e]||!m[e][t]?null:m[e][t](),U=(e,t)=>{const r=[];for(const n of t)if(typeof n=="string"){const i=O(e,n);i&&r.push(i.getGQLField())}else typeof n=="object"&&r.push(n);return r},_=e=>{let t={};return typeof e=="string"?(t[e]=!0,t):e instanceof Array?(e.forEach(r=>{Object.entries(_(r)).forEach(([n,i])=>{t[n]=i})}),t):(Object.entries(e).forEach(([r,n])=>{if(r=="__args"||r=="__aliasFor"||r=="__variables"||r=="__directives"||r=="__all_on"||r=="__name"){t[r]=n;return}if(typeof n=="boolean"){t[r]=n;return}t[r]=_(n)}),t)},v=e=>_(e),g=async e=>{let t=h.jsonToGraphQLQuery(v(e));const r=await F().post(b(),{query:`{ ${t} }`});if(r.data.errors)throw new Error(r.data.errors[0].message);return r.data.data},l=async(e,t=null,r=[])=>{const n={mutation:{}};n.mutation[e]=!0,r instanceof Array&&r.length!=0&&(n.mutation[e]={}),t&&(n.mutation[e]={},n.mutation[e].__args=t),Object.entries(v(r)).forEach(([c,d])=>{n.mutation[e][c]=d});const i=await F().post(b(),{query:h.jsonToGraphQLQuery(n)});if(i.data.errors)throw new Error(i.data.errors[0].message);return i.data.data[e]};let C="/api/";const V=e=>{C=e},b=()=>C;async function K(e){const t={__variables:{file:"Upload!"},fsUploadTempFile:{__args:{file:new h.VariableType("file")},name:!0,path:!0,size:!0,mime:!0}},r=new FormData;r.append("operations",JSON.stringify({query:h.jsonToGraphQLQuery({mutation:t})})),r.append("map",JSON.stringify({0:["variables.file"]})),r.append("0",e);const n=await F().post(b(),r);if(n.data.errors)throw new Error(n.data.errors[0].message);return n.data.data.fsUploadTempFile}const G=(e,t,r)=>l("sendMail",{email:e,subject:t,message:r}),W=async e=>(await g({config:{__args:{name:e}}})).config;function R(e){const t="==".slice(0,(4-e.length%4)%4),r=e.replace(/-/g,"+").replace(/_/g,"/")+t,n=atob(r),i=new ArrayBuffer(n.length),c=new Uint8Array(i);for(let d=0;d<n.length;d++)c[d]=n.charCodeAt(d);return i}function S(e){const t=new Uint8Array(e);let r="";for(const c of t)r+=String.fromCharCode(c);return btoa(r).replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")}var a="copy",f="convert";function p(e,t,r){if(t===a)return r;if(t===f)return e(r);if(t instanceof Array)return r.map(n=>p(e,t[0],n));if(t instanceof Object){const n={};for(const[i,c]of Object.entries(t)){if(c.derive){const d=c.derive(r);d!==void 0&&(r[i]=d)}if(!(i in r)){if(c.required)throw new Error(`Missing key: ${i}`);continue}if(r[i]==null){n[i]=null;continue}n[i]=p(e,c.schema,r[i])}return n}}function A(e,t){return{required:!0,schema:e,derive:t}}function o(e){return{required:!0,schema:e}}function u(e){return{required:!1,schema:e}}var q={type:o(a),id:o(f),transports:u(a)},L={appid:u(a),appidExclude:u(a),credProps:u(a)},j={appid:u(a),appidExclude:u(a),credProps:u(a)},B={publicKey:o({rp:o(a),user:o({id:o(f),name:o(a),displayName:o(a)}),challenge:o(f),pubKeyCredParams:o(a),timeout:u(a),excludeCredentials:u([q]),authenticatorSelection:u(a),attestation:u(a),extensions:u(L)}),signal:u(a)},I={type:o(a),id:o(a),rawId:o(f),authenticatorAttachment:u(a),response:o({clientDataJSON:o(f),attestationObject:o(f),transports:A(a,e=>{var t;return((t=e.getTransports)==null?void 0:t.call(e))||[]})}),clientExtensionResults:A(j,e=>e.getClientExtensionResults())},z={mediation:u(a),publicKey:o({challenge:o(f),timeout:u(a),rpId:u(a),allowCredentials:u([q]),userVerification:u(a),extensions:u(L)}),signal:u(a)},$={type:o(a),id:o(a),rawId:o(f),authenticatorAttachment:u(a),response:o({clientDataJSON:o(f),authenticatorData:o(f),signature:o(f),userHandle:o(f)}),clientExtensionResults:A(j,e=>e.getClientExtensionResults())};function H(e){return p(R,B,e)}function X(e){return p(S,I,e)}function Y(e){return p(R,z,e)}function Z(e){return p(S,$,e)}async function k(e){const t=await navigator.credentials.create(e);return t.toJSON=()=>X(t),t}async function x(e){const t=await navigator.credentials.get(e);return t.toJSON=()=>Z(t),t}async function ee(e){const r=(await g({webAuthnRequestOptions:{__args:{username:e}}})).webAuthnRequestOptions,n=Y({publicKey:r}),i=await x(n);await l("webAuthnAssertion",{username:e,assertion:i.toJSON()})}async function te(){const e=await g({webAuthnCreationOptions:!0}),t=H({publicKey:e.webAuthnCreationOptions}),r=await k(t);await l("webAuthnRegister",{registration:r.toJSON()})}const re=async e=>(await g({fsListFiles:{__args:{path:e},name:!0,path:!0,size:!0,mime:!0,canPreview:!0,imagePath:!0}})).fsListFiles,ne=async e=>(await g({fsListFolders:{__args:{path:e},name:!0,path:!0}})).fsListFolders,se=async e=>{let t=await g({fsFile:{__args:{path:e},base64Content:!0}});return window.atob(t.fsFile.base64Content)},ie=(e,t)=>l("fsWriteFile",{path:e,content:t}),ae=e=>l("fsDeleteFile",{path:e}),oe=e=>l("fsCreateFolder",{path:e}),ue=e=>l("fsDeleteFolder",{path:e}),le=(e,t)=>l("fsRenameFile",{path:e,name:t}),ce=(e,t)=>l("fsRenameFolder",{path:e,name:t}),fe=(e,t)=>l("fsMoveFile",{source:e,target:t});s.defineModel=Q,s.forgetPassword=D,s.fsCreateFolder=oe,s.fsDeleteFile=ae,s.fsDeleteFolder=ue,s.fsListFiles=re,s.fsListFolders=ne,s.fsMoveFile=fe,s.fsReadFile=se,s.fsRenameFile=le,s.fsRenameFolder=ce,s.fsWriteFile=ie,s.getApiUrl=b,s.getAxios=F,s.getConfig=W,s.getGQLFields=U,s.getModelField=O,s.granted=T,s.login=E,s.logout=N,s.mutation=l,s.query=g,s.resetPassword=J,s.sendMail=G,s.setApiUrl=V,s.setAxios=M,s.toQuery=v,s.updatePassword=P,s.uploadFile=K,s.webauthnLogin=ee,s.webauthnRegister=te,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})});
@@ -0,0 +1,23 @@
1
+ export type ModelField = {
2
+ getName: () => string;
3
+ getGQLField: () => string | object;
4
+ getRaw: () => FieldOption;
5
+ getValue: (model: object) => any;
6
+ getFormattedValue: (model: object) => any;
7
+ };
8
+ export type FieldOption = {
9
+ label: string;
10
+ name?: string;
11
+ gqlField?: string | object;
12
+ sortable?: boolean;
13
+ searchable?: boolean;
14
+ searchableType?: string;
15
+ align?: string;
16
+ field?: any;
17
+ format?: any;
18
+ };
19
+ export declare const defineModel: (name: string, fields: {
20
+ [key: string]: FieldOption;
21
+ }) => void;
22
+ export declare const getModelField: (name: string, field: string) => ModelField | null;
23
+ export declare const getGQLFields: (model: string, fields: (string | object)[]) => any;
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hostlink/light",
3
- "version": "0.0.24",
3
+ "version": "1.0.0",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"