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