@hostlink/light 0.0.24 → 1.0.1

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