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