@valbuild/shared 0.63.5 → 0.64.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,6 +5,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  var core = require('@valbuild/core');
6
6
  var zod = require('zod');
7
7
  var fp = require('@valbuild/core/fp');
8
+ var zodValidationError = require('zod-validation-error');
8
9
 
9
10
  function toPrimitive(t, r) {
10
11
  if ("object" != typeof t || !t) return t;
@@ -126,768 +127,6 @@ function _createForOfIteratorHelper(o, allowArrayLike) {
126
127
  };
127
128
  }
128
129
 
129
- function _arrayWithHoles(arr) {
130
- if (Array.isArray(arr)) return arr;
131
- }
132
-
133
- function _iterableToArrayLimit(r, l) {
134
- var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
135
- if (null != t) {
136
- var e,
137
- n,
138
- i,
139
- u,
140
- a = [],
141
- f = !0,
142
- o = !1;
143
- try {
144
- if (i = (t = t.call(r)).next, 0 === l) {
145
- if (Object(t) !== t) return;
146
- f = !1;
147
- } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
148
- } catch (r) {
149
- o = !0, n = r;
150
- } finally {
151
- try {
152
- if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
153
- } finally {
154
- if (o) throw n;
155
- }
156
- }
157
- return a;
158
- }
159
- }
160
-
161
- function _nonIterableRest() {
162
- throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
163
- }
164
-
165
- function _slicedToArray(arr, i) {
166
- return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
167
- }
168
-
169
- var EXT_TO_MIME_TYPES = {
170
- x3d: "application/vnd.hzn-3d-crossword",
171
- "3gp": "video/3gpp",
172
- "3g2": "video/3gpp2",
173
- mseq: "application/vnd.mseq",
174
- pwn: "application/vnd.3m.post-it-notes",
175
- plb: "application/vnd.3gpp.pic-bw-large",
176
- psb: "application/vnd.3gpp.pic-bw-small",
177
- pvb: "application/vnd.3gpp.pic-bw-var",
178
- tcap: "application/vnd.3gpp2.tcap",
179
- "7z": "application/x-7z-compressed",
180
- abw: "application/x-abiword",
181
- ace: "application/x-ace-compressed",
182
- acc: "application/vnd.americandynamics.acc",
183
- acu: "application/vnd.acucobol",
184
- atc: "application/vnd.acucorp",
185
- adp: "audio/adpcm",
186
- aab: "application/x-authorware-bin",
187
- aam: "application/x-authorware-map",
188
- aas: "application/x-authorware-seg",
189
- air: "application/vnd.adobe.air-application-installer-package+zip",
190
- swf: "application/x-shockwave-flash",
191
- fxp: "application/vnd.adobe.fxp",
192
- pdf: "application/pdf",
193
- ppd: "application/vnd.cups-ppd",
194
- dir: "application/x-director",
195
- xdp: "application/vnd.adobe.xdp+xml",
196
- xfdf: "application/vnd.adobe.xfdf",
197
- aac: "audio/x-aac",
198
- ahead: "application/vnd.ahead.space",
199
- azf: "application/vnd.airzip.filesecure.azf",
200
- azs: "application/vnd.airzip.filesecure.azs",
201
- azw: "application/vnd.amazon.ebook",
202
- ami: "application/vnd.amiga.ami",
203
- "N/A": "application/andrew-inset",
204
- apk: "application/vnd.android.package-archive",
205
- cii: "application/vnd.anser-web-certificate-issue-initiation",
206
- fti: "application/vnd.anser-web-funds-transfer-initiation",
207
- atx: "application/vnd.antix.game-component",
208
- dmg: "application/x-apple-diskimage",
209
- mpkg: "application/vnd.apple.installer+xml",
210
- aw: "application/applixware",
211
- mp3: "audio/mpeg",
212
- les: "application/vnd.hhe.lesson-player",
213
- swi: "application/vnd.aristanetworks.swi",
214
- s: "text/x-asm",
215
- atomcat: "application/atomcat+xml",
216
- atomsvc: "application/atomsvc+xml",
217
- atom: "application/atom+xml",
218
- ac: "application/pkix-attr-cert",
219
- aif: "audio/x-aiff",
220
- avi: "video/x-msvideo",
221
- aep: "application/vnd.audiograph",
222
- dxf: "image/vnd.dxf",
223
- dwf: "model/vnd.dwf",
224
- par: "text/plain-bas",
225
- bcpio: "application/x-bcpio",
226
- bin: "application/octet-stream",
227
- bmp: "image/bmp",
228
- torrent: "application/x-bittorrent",
229
- cod: "application/vnd.rim.cod",
230
- mpm: "application/vnd.blueice.multipass",
231
- bmi: "application/vnd.bmi",
232
- sh: "application/x-sh",
233
- btif: "image/prs.btif",
234
- rep: "application/vnd.businessobjects",
235
- bz: "application/x-bzip",
236
- bz2: "application/x-bzip2",
237
- csh: "application/x-csh",
238
- c: "text/x-c",
239
- cdxml: "application/vnd.chemdraw+xml",
240
- css: "text/css",
241
- cdx: "chemical/x-cdx",
242
- cml: "chemical/x-cml",
243
- csml: "chemical/x-csml",
244
- cdbcmsg: "application/vnd.contact.cmsg",
245
- cla: "application/vnd.claymore",
246
- c4g: "application/vnd.clonk.c4group",
247
- sub: "image/vnd.dvb.subtitle",
248
- cdmia: "application/cdmi-capability",
249
- cdmic: "application/cdmi-container",
250
- cdmid: "application/cdmi-domain",
251
- cdmio: "application/cdmi-object",
252
- cdmiq: "application/cdmi-queue",
253
- c11amc: "application/vnd.cluetrust.cartomobile-config",
254
- c11amz: "application/vnd.cluetrust.cartomobile-config-pkg",
255
- ras: "image/x-cmu-raster",
256
- dae: "model/vnd.collada+xml",
257
- csv: "text/csv",
258
- cpt: "application/mac-compactpro",
259
- wmlc: "application/vnd.wap.wmlc",
260
- cgm: "image/cgm",
261
- ice: "x-conference/x-cooltalk",
262
- cmx: "image/x-cmx",
263
- xar: "application/vnd.xara",
264
- cmc: "application/vnd.cosmocaller",
265
- cpio: "application/x-cpio",
266
- clkx: "application/vnd.crick.clicker",
267
- clkk: "application/vnd.crick.clicker.keyboard",
268
- clkp: "application/vnd.crick.clicker.palette",
269
- clkt: "application/vnd.crick.clicker.template",
270
- clkw: "application/vnd.crick.clicker.wordbank",
271
- wbs: "application/vnd.criticaltools.wbs+xml",
272
- cryptonote: "application/vnd.rig.cryptonote",
273
- cif: "chemical/x-cif",
274
- cmdf: "chemical/x-cmdf",
275
- cu: "application/cu-seeme",
276
- cww: "application/prs.cww",
277
- curl: "text/vnd.curl",
278
- dcurl: "text/vnd.curl.dcurl",
279
- mcurl: "text/vnd.curl.mcurl",
280
- scurl: "text/vnd.curl.scurl",
281
- car: "application/vnd.curl.car",
282
- pcurl: "application/vnd.curl.pcurl",
283
- cmp: "application/vnd.yellowriver-custom-menu",
284
- dssc: "application/dssc+der",
285
- xdssc: "application/dssc+xml",
286
- deb: "application/x-debian-package",
287
- uva: "audio/vnd.dece.audio",
288
- uvi: "image/vnd.dece.graphic",
289
- uvh: "video/vnd.dece.hd",
290
- uvm: "video/vnd.dece.mobile",
291
- uvu: "video/vnd.uvvu.mp4",
292
- uvp: "video/vnd.dece.pd",
293
- uvs: "video/vnd.dece.sd",
294
- uvv: "video/vnd.dece.video",
295
- dvi: "application/x-dvi",
296
- seed: "application/vnd.fdsn.seed",
297
- dtb: "application/x-dtbook+xml",
298
- res: "application/x-dtbresource+xml",
299
- ait: "application/vnd.dvb.ait",
300
- svc: "application/vnd.dvb.service",
301
- eol: "audio/vnd.digital-winds",
302
- djvu: "image/vnd.djvu",
303
- dtd: "application/xml-dtd",
304
- mlp: "application/vnd.dolby.mlp",
305
- wad: "application/x-doom",
306
- dpg: "application/vnd.dpgraph",
307
- dra: "audio/vnd.dra",
308
- dfac: "application/vnd.dreamfactory",
309
- dts: "audio/vnd.dts",
310
- dtshd: "audio/vnd.dts.hd",
311
- dwg: "image/vnd.dwg",
312
- geo: "application/vnd.dynageo",
313
- es: "application/ecmascript",
314
- mag: "application/vnd.ecowin.chart",
315
- mmr: "image/vnd.fujixerox.edmics-mmr",
316
- rlc: "image/vnd.fujixerox.edmics-rlc",
317
- exi: "application/exi",
318
- mgz: "application/vnd.proteus.magazine",
319
- epub: "application/epub+zip",
320
- eml: "message/rfc822",
321
- nml: "application/vnd.enliven",
322
- xpr: "application/vnd.is-xpr",
323
- xif: "image/vnd.xiff",
324
- xfdl: "application/vnd.xfdl",
325
- emma: "application/emma+xml",
326
- ez2: "application/vnd.ezpix-album",
327
- ez3: "application/vnd.ezpix-package",
328
- fst: "image/vnd.fst",
329
- fvt: "video/vnd.fvt",
330
- fbs: "image/vnd.fastbidsheet",
331
- fe_launch: "application/vnd.denovo.fcselayout-link",
332
- f4v: "video/x-f4v",
333
- flv: "video/x-flv",
334
- fpx: "image/vnd.fpx",
335
- npx: "image/vnd.net-fpx",
336
- flx: "text/vnd.fmi.flexstor",
337
- fli: "video/x-fli",
338
- ftc: "application/vnd.fluxtime.clip",
339
- fdf: "application/vnd.fdf",
340
- f: "text/x-fortran",
341
- mif: "application/vnd.mif",
342
- fm: "application/vnd.framemaker",
343
- fh: "image/x-freehand",
344
- fsc: "application/vnd.fsc.weblaunch",
345
- fnc: "application/vnd.frogans.fnc",
346
- ltf: "application/vnd.frogans.ltf",
347
- ddd: "application/vnd.fujixerox.ddd",
348
- xdw: "application/vnd.fujixerox.docuworks",
349
- xbd: "application/vnd.fujixerox.docuworks.binder",
350
- oas: "application/vnd.fujitsu.oasys",
351
- oa2: "application/vnd.fujitsu.oasys2",
352
- oa3: "application/vnd.fujitsu.oasys3",
353
- fg5: "application/vnd.fujitsu.oasysgp",
354
- bh2: "application/vnd.fujitsu.oasysprs",
355
- spl: "application/x-futuresplash",
356
- fzs: "application/vnd.fuzzysheet",
357
- g3: "image/g3fax",
358
- gmx: "application/vnd.gmx",
359
- gtw: "model/vnd.gtw",
360
- txd: "application/vnd.genomatix.tuxedo",
361
- ggb: "application/vnd.geogebra.file",
362
- ggt: "application/vnd.geogebra.tool",
363
- gdl: "model/vnd.gdl",
364
- gex: "application/vnd.geometry-explorer",
365
- gxt: "application/vnd.geonext",
366
- g2w: "application/vnd.geoplan",
367
- g3w: "application/vnd.geospace",
368
- gsf: "application/x-font-ghostscript",
369
- bdf: "application/x-font-bdf",
370
- gtar: "application/x-gtar",
371
- texinfo: "application/x-texinfo",
372
- gnumeric: "application/x-gnumeric",
373
- kml: "application/vnd.google-earth.kml+xml",
374
- kmz: "application/vnd.google-earth.kmz",
375
- gqf: "application/vnd.grafeq",
376
- gif: "image/gif",
377
- gv: "text/vnd.graphviz",
378
- gac: "application/vnd.groove-account",
379
- ghf: "application/vnd.groove-help",
380
- gim: "application/vnd.groove-identity-message",
381
- grv: "application/vnd.groove-injector",
382
- gtm: "application/vnd.groove-tool-message",
383
- tpl: "application/vnd.groove-tool-template",
384
- vcg: "application/vnd.groove-vcard",
385
- h261: "video/h261",
386
- h263: "video/h263",
387
- h264: "video/h264",
388
- hpid: "application/vnd.hp-hpid",
389
- hps: "application/vnd.hp-hps",
390
- hdf: "application/x-hdf",
391
- rip: "audio/vnd.rip",
392
- hbci: "application/vnd.hbci",
393
- jlt: "application/vnd.hp-jlyt",
394
- pcl: "application/vnd.hp-pcl",
395
- hpgl: "application/vnd.hp-hpgl",
396
- hvs: "application/vnd.yamaha.hv-script",
397
- hvd: "application/vnd.yamaha.hv-dic",
398
- hvp: "application/vnd.yamaha.hv-voice",
399
- "sfd-hdstx": "application/vnd.hydrostatix.sof-data",
400
- stk: "application/hyperstudio",
401
- hal: "application/vnd.hal+xml",
402
- html: "text/html",
403
- irm: "application/vnd.ibm.rights-management",
404
- sc: "application/vnd.ibm.secure-container",
405
- ics: "text/calendar",
406
- icc: "application/vnd.iccprofile",
407
- ico: "image/x-icon",
408
- igl: "application/vnd.igloader",
409
- ief: "image/ief",
410
- ivp: "application/vnd.immervision-ivp",
411
- ivu: "application/vnd.immervision-ivu",
412
- rif: "application/reginfo+xml",
413
- "3dml": "text/vnd.in3d.3dml",
414
- spot: "text/vnd.in3d.spot",
415
- igs: "model/iges",
416
- i2g: "application/vnd.intergeo",
417
- cdy: "application/vnd.cinderella",
418
- xpw: "application/vnd.intercon.formnet",
419
- fcs: "application/vnd.isac.fcs",
420
- ipfix: "application/ipfix",
421
- cer: "application/pkix-cert",
422
- pki: "application/pkixcmp",
423
- crl: "application/pkix-crl",
424
- pkipath: "application/pkix-pkipath",
425
- igm: "application/vnd.insors.igm",
426
- rcprofile: "application/vnd.ipunplugged.rcprofile",
427
- irp: "application/vnd.irepository.package+xml",
428
- jad: "text/vnd.sun.j2me.app-descriptor",
429
- jar: "application/java-archive",
430
- "class": "application/java-vm",
431
- jnlp: "application/x-java-jnlp-file",
432
- ser: "application/java-serialized-object",
433
- java: "text/x-java-source,java",
434
- js: "application/javascript",
435
- json: "application/json",
436
- joda: "application/vnd.joost.joda-archive",
437
- jpm: "video/jpm",
438
- jpeg: "image/jpeg",
439
- jpg: "image/jpeg",
440
- pjpeg: "image/pjpeg",
441
- jpgv: "video/jpeg",
442
- ktz: "application/vnd.kahootz",
443
- mmd: "application/vnd.chipnuts.karaoke-mmd",
444
- karbon: "application/vnd.kde.karbon",
445
- chrt: "application/vnd.kde.kchart",
446
- kfo: "application/vnd.kde.kformula",
447
- flw: "application/vnd.kde.kivio",
448
- kon: "application/vnd.kde.kontour",
449
- kpr: "application/vnd.kde.kpresenter",
450
- ksp: "application/vnd.kde.kspread",
451
- kwd: "application/vnd.kde.kword",
452
- htke: "application/vnd.kenameaapp",
453
- kia: "application/vnd.kidspiration",
454
- kne: "application/vnd.kinar",
455
- sse: "application/vnd.kodak-descriptor",
456
- lasxml: "application/vnd.las.las+xml",
457
- latex: "application/x-latex",
458
- lbd: "application/vnd.llamagraphics.life-balance.desktop",
459
- lbe: "application/vnd.llamagraphics.life-balance.exchange+xml",
460
- jam: "application/vnd.jam",
461
- "123": "application/vnd.lotus-1-2-3",
462
- apr: "application/vnd.lotus-approach",
463
- pre: "application/vnd.lotus-freelance",
464
- nsf: "application/vnd.lotus-notes",
465
- org: "application/vnd.lotus-organizer",
466
- scm: "application/vnd.lotus-screencam",
467
- lwp: "application/vnd.lotus-wordpro",
468
- lvp: "audio/vnd.lucent.voice",
469
- m3u: "audio/x-mpegurl",
470
- m4v: "video/x-m4v",
471
- hqx: "application/mac-binhex40",
472
- portpkg: "application/vnd.macports.portpkg",
473
- mgp: "application/vnd.osgeo.mapguide.package",
474
- mrc: "application/marc",
475
- mrcx: "application/marcxml+xml",
476
- mxf: "application/mxf",
477
- nbp: "application/vnd.wolfram.player",
478
- ma: "application/mathematica",
479
- mathml: "application/mathml+xml",
480
- mbox: "application/mbox",
481
- mc1: "application/vnd.medcalcdata",
482
- mscml: "application/mediaservercontrol+xml",
483
- cdkey: "application/vnd.mediastation.cdkey",
484
- mwf: "application/vnd.mfer",
485
- mfm: "application/vnd.mfmp",
486
- msh: "model/mesh",
487
- mads: "application/mads+xml",
488
- mets: "application/mets+xml",
489
- mods: "application/mods+xml",
490
- meta4: "application/metalink4+xml",
491
- mcd: "application/vnd.mcd",
492
- flo: "application/vnd.micrografx.flo",
493
- igx: "application/vnd.micrografx.igx",
494
- es3: "application/vnd.eszigno3+xml",
495
- mdb: "application/x-msaccess",
496
- asf: "video/x-ms-asf",
497
- exe: "application/x-msdownload",
498
- cil: "application/vnd.ms-artgalry",
499
- cab: "application/vnd.ms-cab-compressed",
500
- ims: "application/vnd.ms-ims",
501
- application: "application/x-ms-application",
502
- clp: "application/x-msclip",
503
- mdi: "image/vnd.ms-modi",
504
- eot: "application/vnd.ms-fontobject",
505
- xls: "application/vnd.ms-excel",
506
- xlam: "application/vnd.ms-excel.addin.macroenabled.12",
507
- xlsb: "application/vnd.ms-excel.sheet.binary.macroenabled.12",
508
- xltm: "application/vnd.ms-excel.template.macroenabled.12",
509
- xlsm: "application/vnd.ms-excel.sheet.macroenabled.12",
510
- chm: "application/vnd.ms-htmlhelp",
511
- crd: "application/x-mscardfile",
512
- lrm: "application/vnd.ms-lrm",
513
- mvb: "application/x-msmediaview",
514
- mny: "application/x-msmoney",
515
- pptx: "application/vnd.openxmlformats-officedocument.presentationml.presentation",
516
- sldx: "application/vnd.openxmlformats-officedocument.presentationml.slide",
517
- ppsx: "application/vnd.openxmlformats-officedocument.presentationml.slideshow",
518
- potx: "application/vnd.openxmlformats-officedocument.presentationml.template",
519
- xlsx: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
520
- xltx: "application/vnd.openxmlformats-officedocument.spreadsheetml.template",
521
- docx: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
522
- dotx: "application/vnd.openxmlformats-officedocument.wordprocessingml.template",
523
- obd: "application/x-msbinder",
524
- thmx: "application/vnd.ms-officetheme",
525
- onetoc: "application/onenote",
526
- pya: "audio/vnd.ms-playready.media.pya",
527
- pyv: "video/vnd.ms-playready.media.pyv",
528
- ppt: "application/vnd.ms-powerpoint",
529
- ppam: "application/vnd.ms-powerpoint.addin.macroenabled.12",
530
- sldm: "application/vnd.ms-powerpoint.slide.macroenabled.12",
531
- pptm: "application/vnd.ms-powerpoint.presentation.macroenabled.12",
532
- ppsm: "application/vnd.ms-powerpoint.slideshow.macroenabled.12",
533
- potm: "application/vnd.ms-powerpoint.template.macroenabled.12",
534
- mpp: "application/vnd.ms-project",
535
- pub: "application/x-mspublisher",
536
- scd: "application/x-msschedule",
537
- xap: "application/x-silverlight-app",
538
- stl: "application/vnd.ms-pki.stl",
539
- cat: "application/vnd.ms-pki.seccat",
540
- vsd: "application/vnd.visio",
541
- vsdx: "application/vnd.visio2013",
542
- wm: "video/x-ms-wm",
543
- wma: "audio/x-ms-wma",
544
- wax: "audio/x-ms-wax",
545
- wmx: "video/x-ms-wmx",
546
- wmd: "application/x-ms-wmd",
547
- wpl: "application/vnd.ms-wpl",
548
- wmz: "application/x-ms-wmz",
549
- wmv: "video/x-ms-wmv",
550
- wvx: "video/x-ms-wvx",
551
- wmf: "application/x-msmetafile",
552
- trm: "application/x-msterminal",
553
- doc: "application/msword",
554
- docm: "application/vnd.ms-word.document.macroenabled.12",
555
- dotm: "application/vnd.ms-word.template.macroenabled.12",
556
- wri: "application/x-mswrite",
557
- wps: "application/vnd.ms-works",
558
- xbap: "application/x-ms-xbap",
559
- xps: "application/vnd.ms-xpsdocument",
560
- mid: "audio/midi",
561
- mpy: "application/vnd.ibm.minipay",
562
- afp: "application/vnd.ibm.modcap",
563
- rms: "application/vnd.jcp.javame.midlet-rms",
564
- tmo: "application/vnd.tmobile-livetv",
565
- prc: "application/x-mobipocket-ebook",
566
- mbk: "application/vnd.mobius.mbk",
567
- dis: "application/vnd.mobius.dis",
568
- plc: "application/vnd.mobius.plc",
569
- mqy: "application/vnd.mobius.mqy",
570
- msl: "application/vnd.mobius.msl",
571
- txf: "application/vnd.mobius.txf",
572
- daf: "application/vnd.mobius.daf",
573
- fly: "text/vnd.fly",
574
- mpc: "application/vnd.mophun.certificate",
575
- mpn: "application/vnd.mophun.application",
576
- mj2: "video/mj2",
577
- mpga: "audio/mpeg",
578
- mxu: "video/vnd.mpegurl",
579
- mpeg: "video/mpeg",
580
- m21: "application/mp21",
581
- mp4a: "audio/mp4",
582
- mp4: "video/mp4",
583
- m3u8: "application/vnd.apple.mpegurl",
584
- mus: "application/vnd.musician",
585
- msty: "application/vnd.muvee.style",
586
- mxml: "application/xv+xml",
587
- ngdat: "application/vnd.nokia.n-gage.data",
588
- "n-gage": "application/vnd.nokia.n-gage.symbian.install",
589
- ncx: "application/x-dtbncx+xml",
590
- nc: "application/x-netcdf",
591
- nlu: "application/vnd.neurolanguage.nlu",
592
- dna: "application/vnd.dna",
593
- nnd: "application/vnd.noblenet-directory",
594
- nns: "application/vnd.noblenet-sealer",
595
- nnw: "application/vnd.noblenet-web",
596
- rpst: "application/vnd.nokia.radio-preset",
597
- rpss: "application/vnd.nokia.radio-presets",
598
- n3: "text/n3",
599
- edm: "application/vnd.novadigm.edm",
600
- edx: "application/vnd.novadigm.edx",
601
- ext: "application/vnd.novadigm.ext",
602
- gph: "application/vnd.flographit",
603
- ecelp4800: "audio/vnd.nuera.ecelp4800",
604
- ecelp7470: "audio/vnd.nuera.ecelp7470",
605
- ecelp9600: "audio/vnd.nuera.ecelp9600",
606
- oda: "application/oda",
607
- ogx: "application/ogg",
608
- oga: "audio/ogg",
609
- ogv: "video/ogg",
610
- dd2: "application/vnd.oma.dd2+xml",
611
- oth: "application/vnd.oasis.opendocument.text-web",
612
- opf: "application/oebps-package+xml",
613
- qbo: "application/vnd.intu.qbo",
614
- oxt: "application/vnd.openofficeorg.extension",
615
- osf: "application/vnd.yamaha.openscoreformat",
616
- weba: "audio/webm",
617
- webm: "video/webm",
618
- odc: "application/vnd.oasis.opendocument.chart",
619
- otc: "application/vnd.oasis.opendocument.chart-template",
620
- odb: "application/vnd.oasis.opendocument.database",
621
- odf: "application/vnd.oasis.opendocument.formula",
622
- odft: "application/vnd.oasis.opendocument.formula-template",
623
- odg: "application/vnd.oasis.opendocument.graphics",
624
- otg: "application/vnd.oasis.opendocument.graphics-template",
625
- odi: "application/vnd.oasis.opendocument.image",
626
- oti: "application/vnd.oasis.opendocument.image-template",
627
- odp: "application/vnd.oasis.opendocument.presentation",
628
- otp: "application/vnd.oasis.opendocument.presentation-template",
629
- ods: "application/vnd.oasis.opendocument.spreadsheet",
630
- ots: "application/vnd.oasis.opendocument.spreadsheet-template",
631
- odt: "application/vnd.oasis.opendocument.text",
632
- odm: "application/vnd.oasis.opendocument.text-master",
633
- ott: "application/vnd.oasis.opendocument.text-template",
634
- ktx: "image/ktx",
635
- sxc: "application/vnd.sun.xml.calc",
636
- stc: "application/vnd.sun.xml.calc.template",
637
- sxd: "application/vnd.sun.xml.draw",
638
- std: "application/vnd.sun.xml.draw.template",
639
- sxi: "application/vnd.sun.xml.impress",
640
- sti: "application/vnd.sun.xml.impress.template",
641
- sxm: "application/vnd.sun.xml.math",
642
- sxw: "application/vnd.sun.xml.writer",
643
- sxg: "application/vnd.sun.xml.writer.global",
644
- stw: "application/vnd.sun.xml.writer.template",
645
- otf: "application/x-font-otf",
646
- osfpvg: "application/vnd.yamaha.openscoreformat.osfpvg+xml",
647
- dp: "application/vnd.osgi.dp",
648
- pdb: "application/vnd.palm",
649
- p: "text/x-pascal",
650
- paw: "application/vnd.pawaafile",
651
- pclxl: "application/vnd.hp-pclxl",
652
- efif: "application/vnd.picsel",
653
- pcx: "image/x-pcx",
654
- psd: "image/vnd.adobe.photoshop",
655
- prf: "application/pics-rules",
656
- pic: "image/x-pict",
657
- chat: "application/x-chat",
658
- p10: "application/pkcs10",
659
- p12: "application/x-pkcs12",
660
- p7m: "application/pkcs7-mime",
661
- p7s: "application/pkcs7-signature",
662
- p7r: "application/x-pkcs7-certreqresp",
663
- p7b: "application/x-pkcs7-certificates",
664
- p8: "application/pkcs8",
665
- plf: "application/vnd.pocketlearn",
666
- pnm: "image/x-portable-anymap",
667
- pbm: "image/x-portable-bitmap",
668
- pcf: "application/x-font-pcf",
669
- pfr: "application/font-tdpfr",
670
- pgn: "application/x-chess-pgn",
671
- pgm: "image/x-portable-graymap",
672
- png: "image/png",
673
- ppm: "image/x-portable-pixmap",
674
- pskcxml: "application/pskc+xml",
675
- pml: "application/vnd.ctc-posml",
676
- ai: "application/postscript",
677
- pfa: "application/x-font-type1",
678
- pbd: "application/vnd.powerbuilder6",
679
- pgp: "application/pgp-signature",
680
- box: "application/vnd.previewsystems.box",
681
- ptid: "application/vnd.pvi.ptid1",
682
- pls: "application/pls+xml",
683
- str: "application/vnd.pg.format",
684
- ei6: "application/vnd.pg.osasli",
685
- dsc: "text/prs.lines.tag",
686
- psf: "application/x-font-linux-psf",
687
- qps: "application/vnd.publishare-delta-tree",
688
- wg: "application/vnd.pmi.widget",
689
- qxd: "application/vnd.quark.quarkxpress",
690
- esf: "application/vnd.epson.esf",
691
- msf: "application/vnd.epson.msf",
692
- ssf: "application/vnd.epson.ssf",
693
- qam: "application/vnd.epson.quickanime",
694
- qfx: "application/vnd.intu.qfx",
695
- qt: "video/quicktime",
696
- rar: "application/x-rar-compressed",
697
- ram: "audio/x-pn-realaudio",
698
- rmp: "audio/x-pn-realaudio-plugin",
699
- rsd: "application/rsd+xml",
700
- rm: "application/vnd.rn-realmedia",
701
- bed: "application/vnd.realvnc.bed",
702
- mxl: "application/vnd.recordare.musicxml",
703
- musicxml: "application/vnd.recordare.musicxml+xml",
704
- rnc: "application/relax-ng-compact-syntax",
705
- rdz: "application/vnd.data-vision.rdz",
706
- rdf: "application/rdf+xml",
707
- rp9: "application/vnd.cloanto.rp9",
708
- jisp: "application/vnd.jisp",
709
- rtf: "application/rtf",
710
- rtx: "text/richtext",
711
- link66: "application/vnd.route66.link66+xml",
712
- rss: "application/rss+xml",
713
- shf: "application/shf+xml",
714
- st: "application/vnd.sailingtracker.track",
715
- svg: "image/svg+xml",
716
- sus: "application/vnd.sus-calendar",
717
- sru: "application/sru+xml",
718
- setpay: "application/set-payment-initiation",
719
- setreg: "application/set-registration-initiation",
720
- sema: "application/vnd.sema",
721
- semd: "application/vnd.semd",
722
- semf: "application/vnd.semf",
723
- see: "application/vnd.seemail",
724
- snf: "application/x-font-snf",
725
- spq: "application/scvp-vp-request",
726
- spp: "application/scvp-vp-response",
727
- scq: "application/scvp-cv-request",
728
- scs: "application/scvp-cv-response",
729
- sdp: "application/sdp",
730
- etx: "text/x-setext",
731
- movie: "video/x-sgi-movie",
732
- ifm: "application/vnd.shana.informed.formdata",
733
- itp: "application/vnd.shana.informed.formtemplate",
734
- iif: "application/vnd.shana.informed.interchange",
735
- ipk: "application/vnd.shana.informed.package",
736
- tfi: "application/thraud+xml",
737
- shar: "application/x-shar",
738
- rgb: "image/x-rgb",
739
- slt: "application/vnd.epson.salt",
740
- aso: "application/vnd.accpac.simply.aso",
741
- imp: "application/vnd.accpac.simply.imp",
742
- twd: "application/vnd.simtech-mindmapper",
743
- csp: "application/vnd.commonspace",
744
- saf: "application/vnd.yamaha.smaf-audio",
745
- mmf: "application/vnd.smaf",
746
- spf: "application/vnd.yamaha.smaf-phrase",
747
- teacher: "application/vnd.smart.teacher",
748
- svd: "application/vnd.svd",
749
- rq: "application/sparql-query",
750
- srx: "application/sparql-results+xml",
751
- gram: "application/srgs",
752
- grxml: "application/srgs+xml",
753
- ssml: "application/ssml+xml",
754
- skp: "application/vnd.koan",
755
- sgml: "text/sgml",
756
- sdc: "application/vnd.stardivision.calc",
757
- sda: "application/vnd.stardivision.draw",
758
- sdd: "application/vnd.stardivision.impress",
759
- smf: "application/vnd.stardivision.math",
760
- sdw: "application/vnd.stardivision.writer",
761
- sgl: "application/vnd.stardivision.writer-global",
762
- sm: "application/vnd.stepmania.stepchart",
763
- sit: "application/x-stuffit",
764
- sitx: "application/x-stuffitx",
765
- sdkm: "application/vnd.solent.sdkm+xml",
766
- xo: "application/vnd.olpc-sugar",
767
- au: "audio/basic",
768
- wqd: "application/vnd.wqd",
769
- sis: "application/vnd.symbian.install",
770
- smi: "application/smil+xml",
771
- xsm: "application/vnd.syncml+xml",
772
- bdm: "application/vnd.syncml.dm+wbxml",
773
- xdm: "application/vnd.syncml.dm+xml",
774
- sv4cpio: "application/x-sv4cpio",
775
- sv4crc: "application/x-sv4crc",
776
- sbml: "application/sbml+xml",
777
- tsv: "text/tab-separated-values",
778
- tiff: "image/tiff",
779
- tao: "application/vnd.tao.intent-module-archive",
780
- tar: "application/x-tar",
781
- tcl: "application/x-tcl",
782
- tex: "application/x-tex",
783
- tfm: "application/x-tex-tfm",
784
- tei: "application/tei+xml",
785
- txt: "text/plain",
786
- dxp: "application/vnd.spotfire.dxp",
787
- sfs: "application/vnd.spotfire.sfs",
788
- tsd: "application/timestamped-data",
789
- tpt: "application/vnd.trid.tpt",
790
- mxs: "application/vnd.triscape.mxs",
791
- t: "text/troff",
792
- tra: "application/vnd.trueapp",
793
- ttf: "application/x-font-ttf",
794
- ttl: "text/turtle",
795
- umj: "application/vnd.umajin",
796
- uoml: "application/vnd.uoml+xml",
797
- unityweb: "application/vnd.unity",
798
- ufd: "application/vnd.ufdl",
799
- uri: "text/uri-list",
800
- utz: "application/vnd.uiq.theme",
801
- ustar: "application/x-ustar",
802
- uu: "text/x-uuencode",
803
- vcs: "text/x-vcalendar",
804
- vcf: "text/x-vcard",
805
- vcd: "application/x-cdlink",
806
- vsf: "application/vnd.vsf",
807
- wrl: "model/vrml",
808
- vcx: "application/vnd.vcx",
809
- mts: "model/vnd.mts",
810
- vtu: "model/vnd.vtu",
811
- vis: "application/vnd.visionary",
812
- viv: "video/vnd.vivo",
813
- ccxml: "application/ccxml+xml,",
814
- vxml: "application/voicexml+xml",
815
- src: "application/x-wais-source",
816
- wbxml: "application/vnd.wap.wbxml",
817
- wbmp: "image/vnd.wap.wbmp",
818
- wav: "audio/x-wav",
819
- davmount: "application/davmount+xml",
820
- woff: "application/x-font-woff",
821
- wspolicy: "application/wspolicy+xml",
822
- webp: "image/webp",
823
- wtb: "application/vnd.webturbo",
824
- wgt: "application/widget",
825
- hlp: "application/winhlp",
826
- wml: "text/vnd.wap.wml",
827
- wmls: "text/vnd.wap.wmlscript",
828
- wmlsc: "application/vnd.wap.wmlscriptc",
829
- wpd: "application/vnd.wordperfect",
830
- stf: "application/vnd.wt.stf",
831
- wsdl: "application/wsdl+xml",
832
- xbm: "image/x-xbitmap",
833
- xpm: "image/x-xpixmap",
834
- xwd: "image/x-xwindowdump",
835
- der: "application/x-x509-ca-cert",
836
- fig: "application/x-xfig",
837
- xhtml: "application/xhtml+xml",
838
- xml: "application/xml",
839
- xdf: "application/xcap-diff+xml",
840
- xenc: "application/xenc+xml",
841
- xer: "application/patch-ops-error+xml",
842
- rl: "application/resource-lists+xml",
843
- rs: "application/rls-services+xml",
844
- rld: "application/resource-lists-diff+xml",
845
- xslt: "application/xslt+xml",
846
- xop: "application/xop+xml",
847
- xpi: "application/x-xpinstall",
848
- xspf: "application/xspf+xml",
849
- xul: "application/vnd.mozilla.xul+xml",
850
- xyz: "chemical/x-xyz",
851
- yaml: "text/yaml",
852
- yang: "application/yang",
853
- yin: "application/yin+xml",
854
- zir: "application/vnd.zul",
855
- zip: "application/zip",
856
- zmm: "application/vnd.handheld-entertainment+xml",
857
- zaz: "application/vnd.zzazz.deck+xml"
858
- };
859
-
860
- // TODO: write this out to avoid compute
861
- var MIME_TYPES_TO_EXT = Object.fromEntries(Object.entries(EXT_TO_MIME_TYPES).map(function (_ref) {
862
- var _ref2 = _slicedToArray(_ref, 2),
863
- k = _ref2[0],
864
- v = _ref2[1];
865
- return [v, k];
866
- }));
867
-
868
- var MIME_TYPE_REGEX = /^data:(.*?);base64,/;
869
- function getMimeType(base64Url) {
870
- var match = MIME_TYPE_REGEX.exec(base64Url);
871
- if (match && match[1]) {
872
- return match[1];
873
- }
874
- return;
875
- }
876
- function mimeTypeToFileExt(mimeType) {
877
- var recognizedMimeType = MIME_TYPES_TO_EXT[mimeType];
878
- if (recognizedMimeType) {
879
- return recognizedMimeType;
880
- }
881
- return mimeType.split("/")[1];
882
- }
883
- function filenameToMimeType(filename) {
884
- var ext = filename.split(".").pop();
885
- var recognizedExt = ext && EXT_TO_MIME_TYPES[ext];
886
- if (recognizedExt) {
887
- return recognizedExt;
888
- }
889
- }
890
-
891
130
  function remirrorToRichTextSource(node) {
892
131
  var files = {};
893
132
  var blocks = [];
@@ -1069,11 +308,11 @@ var textEncoder = new TextEncoder();
1069
308
  function convertImageNode(path, node, files) {
1070
309
  if (node.attrs && node.attrs.src.startsWith("data:")) {
1071
310
  var sha256 = core.Internal.getSHA256Hash(textEncoder.encode(node.attrs.src));
1072
- var mimeType = getMimeType(node.attrs.src);
311
+ var mimeType = core.Internal.getMimeType(node.attrs.src);
1073
312
  if (mimeType === undefined) {
1074
313
  throw new Error("Could not detect Mime Type for image: ".concat(node.attrs.src));
1075
314
  }
1076
- var fileExt = mimeTypeToFileExt(mimeType);
315
+ var fileExt = core.Internal.mimeTypeToFileExt(mimeType);
1077
316
  var fileName = node.attrs.fileName || "".concat(sha256, ".").concat(fileExt);
1078
317
  var filePath = "/public/".concat(fileName);
1079
318
  var existingFilesEntry = files[filePath];
@@ -1107,7 +346,7 @@ function convertImageNode(path, node, files) {
1107
346
  width: typeof node.attrs.width === "number" ? node.attrs.width : 0,
1108
347
  height: typeof node.attrs.height === "number" ? node.attrs.height : 0,
1109
348
  sha256: _sha || "",
1110
- mimeType: noParamsSrc && filenameToMimeType(noParamsSrc) || ""
349
+ mimeType: noParamsSrc && core.Internal.filenameToMimeType(noParamsSrc) || ""
1111
350
  }), patchId ? {
1112
351
  patch_id: patchId
1113
352
  } : {})
@@ -1477,6 +716,46 @@ var VAL_SESSION_COOKIE = core.Internal.VAL_SESSION_COOKIE;
1477
716
  var VAL_STATE_COOKIE = core.Internal.VAL_STATE_COOKIE;
1478
717
  var VAL_ENABLE_COOKIE_NAME = core.Internal.VAL_ENABLE_COOKIE_NAME;
1479
718
 
719
+ function _arrayWithHoles(arr) {
720
+ if (Array.isArray(arr)) return arr;
721
+ }
722
+
723
+ function _iterableToArrayLimit(r, l) {
724
+ var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
725
+ if (null != t) {
726
+ var e,
727
+ n,
728
+ i,
729
+ u,
730
+ a = [],
731
+ f = !0,
732
+ o = !1;
733
+ try {
734
+ if (i = (t = t.call(r)).next, 0 === l) {
735
+ if (Object(t) !== t) return;
736
+ f = !1;
737
+ } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
738
+ } catch (r) {
739
+ o = !0, n = r;
740
+ } finally {
741
+ try {
742
+ if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
743
+ } finally {
744
+ if (o) throw n;
745
+ }
746
+ }
747
+ return a;
748
+ }
749
+ }
750
+
751
+ function _nonIterableRest() {
752
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
753
+ }
754
+
755
+ function _slicedToArray(arr, i) {
756
+ return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
757
+ }
758
+
1480
759
  function _regeneratorRuntime() {
1481
760
  _regeneratorRuntime = function () {
1482
761
  return e;
@@ -1834,95 +1113,71 @@ function _createClass(Constructor, protoProps, staticProps) {
1834
1113
  return Constructor;
1835
1114
  }
1836
1115
 
1837
- var ValStore = /*#__PURE__*/function () {
1838
- // uncertain whether this is the optimal way of returning
1839
-
1840
- function ValStore(api) {
1841
- var _this = this;
1842
- _classCallCheck(this, ValStore);
1843
- _defineProperty(this, "subscribe", function (paths) {
1844
- return function (listener) {
1845
- var subscriberId = createSubscriberId(paths);
1846
- if (!_this.listeners[subscriberId]) {
1847
- _this.listeners[subscriberId] = [];
1848
- _this.subscribers.set(subscriberId, {});
1849
- }
1850
- _this.listeners[subscriberId].push(listener);
1851
- return function () {
1852
- _this.listeners[subscriberId].splice(_this.listeners[subscriberId].indexOf(listener), 1);
1853
- };
1854
- };
1855
- });
1856
- _defineProperty(this, "getSnapshot", function (paths) {
1857
- return function () {
1858
- return _this.get(paths);
1859
- };
1860
- });
1861
- _defineProperty(this, "getServerSnapshot", function (paths) {
1862
- return function () {
1863
- return _this.get(paths);
1864
- };
1865
- });
1866
- _defineProperty(this, "get", function (paths) {
1867
- var subscriberId = createSubscriberId(paths);
1868
- return _this.subscribers.get(subscriberId);
1869
- });
1870
- this.api = api;
1871
- this.subscribers = new Map();
1872
- this.listeners = {};
1116
+ var ValCache = /*#__PURE__*/function () {
1117
+ function ValCache(client) {
1118
+ _classCallCheck(this, ValCache);
1119
+ this.client = client;
1873
1120
  this.drafts = {};
1874
1121
  this.schema = {};
1875
1122
  }
1876
- _createClass(ValStore, [{
1123
+ _createClass(ValCache, [{
1877
1124
  key: "reloadPaths",
1878
1125
  value: function () {
1879
1126
  var _reloadPaths = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(paths) {
1880
- var patches, filteredPatches, data, _i, _Object$keys, pathS, path, _i2, _Array$from, _Array$from$_i, subscriberId, subscriberModules;
1127
+ var patchesResponse, patches, filteredPatches, treeRes, data, _i, _Object$keys, _data$modules, pathS, path;
1881
1128
  return _regeneratorRuntime().wrap(function _callee$(_context) {
1882
1129
  while (1) switch (_context.prev = _context.next) {
1883
1130
  case 0:
1884
1131
  _context.next = 2;
1885
- return this.api.getPatches({
1886
- omitPatches: true,
1887
- moduleFilePaths: paths
1132
+ return this.client("/patches/~", "GET", {
1133
+ query: {
1134
+ omit_patch: true,
1135
+ author: [],
1136
+ patch_id: [],
1137
+ module_file_path: paths
1138
+ }
1888
1139
  });
1889
1140
  case 2:
1890
- patches = _context.sent;
1891
- if (!fp.result.isErr(patches)) {
1141
+ patchesResponse = _context.sent;
1142
+ if (!(patchesResponse.status !== 200)) {
1892
1143
  _context.next = 6;
1893
1144
  break;
1894
1145
  }
1895
- console.error("Val: failed to get patches", patches.error);
1146
+ console.error("Val: failed to get patches", patchesResponse.json.message, patchesResponse.json);
1896
1147
  return _context.abrupt("return");
1897
1148
  case 6:
1898
- filteredPatches = Object.keys(patches.value.patches);
1899
- _context.next = 9;
1900
- return this.api.putTree({
1901
- patchIds: filteredPatches
1149
+ patches = patchesResponse.json;
1150
+ filteredPatches = Object.keys(patches);
1151
+ _context.next = 10;
1152
+ return this.client("/tree/~", "PUT", {
1153
+ query: {
1154
+ validate_sources: true,
1155
+ validate_all: false,
1156
+ validate_binary_files: false
1157
+ },
1158
+ path: undefined,
1159
+ // TODO: reload only the paths the requested paths
1160
+ body: {
1161
+ patchIds: filteredPatches
1162
+ }
1902
1163
  });
1903
- case 9:
1904
- data = _context.sent;
1905
- _context.next = 12;
1164
+ case 10:
1165
+ treeRes = _context.sent;
1166
+ _context.next = 13;
1906
1167
  return this.initialize();
1907
- case 12:
1908
- if (fp.result.isOk(data)) {
1909
- for (_i = 0, _Object$keys = Object.keys(data.value.modules); _i < _Object$keys.length; _i++) {
1168
+ case 13:
1169
+ if (treeRes.status === 200) {
1170
+ data = treeRes.json;
1171
+ for (_i = 0, _Object$keys = Object.keys(data.modules); _i < _Object$keys.length; _i++) {
1910
1172
  pathS = _Object$keys[_i];
1911
1173
  path = pathS;
1912
- this.drafts[path] = data.value.modules[path].source;
1174
+ this.drafts[path] = data === null || data === void 0 || (_data$modules = data.modules) === null || _data$modules === void 0 || (_data$modules = _data$modules[path]) === null || _data$modules === void 0 ? void 0 : _data$modules.source;
1913
1175
  this.emitEvent(path, this.drafts[path]);
1914
- for (_i2 = 0, _Array$from = Array.from(this.subscribers.entries()); _i2 < _Array$from.length; _i2++) {
1915
- _Array$from$_i = _slicedToArray(_Array$from[_i2], 2), subscriberId = _Array$from$_i[0], subscriberModules = _Array$from$_i[1];
1916
- if (subscriberModules[path]) {
1917
- this.subscribers.set(subscriberId, _objectSpread2(_objectSpread2({}, subscriberModules), {}, _defineProperty({}, path, this.drafts[path])));
1918
- this.emitChange(subscriberId);
1919
- }
1920
- }
1921
1176
  }
1922
1177
  } else {
1923
- console.error("Val: failed to reload paths", paths, data.error);
1178
+ console.error("Val: failed to reload paths", paths, treeRes.json);
1924
1179
  }
1925
- case 13:
1180
+ case 14:
1926
1181
  case "end":
1927
1182
  return _context.stop();
1928
1183
  }
@@ -1937,49 +1192,99 @@ var ValStore = /*#__PURE__*/function () {
1937
1192
  key: "reset",
1938
1193
  value: function () {
1939
1194
  var _reset = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
1940
- var patches, allPatches, data, _i3, _Object$keys2, pathS, path, _i4, _Array$from2, _Array$from2$_i, subscriberId, subscriberModules;
1195
+ var patchesRes, allPatches, treeRes, initRes, _i2, _Object$keys2, _treeRes$json, pathS, path;
1941
1196
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
1942
1197
  while (1) switch (_context2.prev = _context2.next) {
1943
1198
  case 0:
1944
1199
  _context2.next = 2;
1945
- return this.api.getPatches();
1200
+ return this.client("/patches/~", "GET", {
1201
+ query: {
1202
+ omit_patch: true,
1203
+ author: [],
1204
+ patch_id: [],
1205
+ module_file_path: []
1206
+ }
1207
+ });
1946
1208
  case 2:
1947
- patches = _context2.sent;
1948
- if (!fp.result.isErr(patches)) {
1209
+ patchesRes = _context2.sent;
1210
+ if (!(patchesRes.status !== 200)) {
1949
1211
  _context2.next = 6;
1950
1212
  break;
1951
1213
  }
1952
- console.error("Val: failed to get patches", patches.error);
1953
- return _context2.abrupt("return");
1214
+ console.error("Val: failed to get patches", patchesRes.json);
1215
+ return _context2.abrupt("return", fp.result.err({
1216
+ errorType: "other",
1217
+ message: "Failed to get patches"
1218
+ }));
1954
1219
  case 6:
1955
- allPatches = Object.keys(patches.value.patches);
1220
+ allPatches = Object.keys(patchesRes.json.patches);
1956
1221
  _context2.next = 9;
1957
- return this.api.putTree({
1958
- patchIds: allPatches
1222
+ return this.client("/tree/~", "PUT", {
1223
+ path: undefined,
1224
+ query: {
1225
+ validate_sources: false,
1226
+ validate_all: false,
1227
+ validate_binary_files: false
1228
+ },
1229
+ body: {
1230
+ patchIds: allPatches
1231
+ }
1959
1232
  });
1960
1233
  case 9:
1961
- data = _context2.sent;
1234
+ treeRes = _context2.sent;
1962
1235
  _context2.next = 12;
1963
1236
  return this.initialize();
1964
1237
  case 12:
1965
- if (fp.result.isOk(data)) {
1966
- for (_i3 = 0, _Object$keys2 = Object.keys(data.value.modules); _i3 < _Object$keys2.length; _i3++) {
1967
- pathS = _Object$keys2[_i3];
1968
- path = pathS;
1969
- this.drafts[path] = data.value.modules[path].source;
1970
- this.emitEvent(path, this.drafts[path]);
1971
- for (_i4 = 0, _Array$from2 = Array.from(this.subscribers.entries()); _i4 < _Array$from2.length; _i4++) {
1972
- _Array$from2$_i = _slicedToArray(_Array$from2[_i4], 2), subscriberId = _Array$from2$_i[0], subscriberModules = _Array$from2$_i[1];
1973
- if (subscriberModules[path]) {
1974
- this.subscribers.set(subscriberId, _objectSpread2(_objectSpread2({}, subscriberModules), {}, _defineProperty({}, path, this.drafts[path])));
1975
- this.emitChange(subscriberId);
1976
- }
1977
- }
1978
- }
1979
- } else {
1980
- console.error("Val: failed to reset", data.error);
1238
+ initRes = _context2.sent;
1239
+ if (!fp.result.isErr(initRes)) {
1240
+ _context2.next = 16;
1241
+ break;
1981
1242
  }
1982
- case 13:
1243
+ console.error("Failed to initialize inside reset", initRes.error);
1244
+ return _context2.abrupt("return", fp.result.err({
1245
+ errorType: "other",
1246
+ message: initRes.error.message
1247
+ }));
1248
+ case 16:
1249
+ if (!(treeRes.status === 200)) {
1250
+ _context2.next = 21;
1251
+ break;
1252
+ }
1253
+ for (_i2 = 0, _Object$keys2 = Object.keys(treeRes.json.modules); _i2 < _Object$keys2.length; _i2++) {
1254
+ pathS = _Object$keys2[_i2];
1255
+ path = pathS;
1256
+ this.drafts[path] = (_treeRes$json = treeRes.json) === null || _treeRes$json === void 0 || (_treeRes$json = _treeRes$json.modules) === null || _treeRes$json === void 0 || (_treeRes$json = _treeRes$json[path]) === null || _treeRes$json === void 0 ? void 0 : _treeRes$json.source;
1257
+ this.emitEvent(path, this.drafts[path]);
1258
+ }
1259
+ return _context2.abrupt("return", fp.result.ok(undefined));
1260
+ case 21:
1261
+ if (!(treeRes.status === 400 && "type" in treeRes.json)) {
1262
+ _context2.next = 25;
1263
+ break;
1264
+ }
1265
+ return _context2.abrupt("return", fp.result.err({
1266
+ errorType: "patch-error",
1267
+ errors: Object.entries(treeRes.json.errors).flatMap(function (_ref) {
1268
+ var _ref2 = _slicedToArray(_ref, 2),
1269
+ moduleFilePath = _ref2[0],
1270
+ value = _ref2[1];
1271
+ return (value !== null && value !== void 0 ? value : []).map(function (item) {
1272
+ return {
1273
+ moduleFilePath: moduleFilePath,
1274
+ patchError: item.error.message,
1275
+ patchId: item.patchId,
1276
+ skipped: item.skipped
1277
+ };
1278
+ });
1279
+ })
1280
+ }));
1281
+ case 25:
1282
+ console.error("Val: failed to reset", treeRes.json);
1283
+ return _context2.abrupt("return", fp.result.err({
1284
+ errorType: "other",
1285
+ message: "Failed to reset " + JSON.stringify(treeRes.json)
1286
+ }));
1287
+ case 27:
1983
1288
  case "end":
1984
1289
  return _context2.stop();
1985
1290
  }
@@ -1995,7 +1300,9 @@ var ValStore = /*#__PURE__*/function () {
1995
1300
  value: function () {
1996
1301
  var _getModule = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(path) {
1997
1302
  var refetch,
1998
- data,
1303
+ treeRes,
1304
+ _treeRes$json2,
1305
+ _treeRes$json3,
1999
1306
  fetchedSource,
2000
1307
  schema,
2001
1308
  _args3 = arguments;
@@ -2013,29 +1320,35 @@ var ValStore = /*#__PURE__*/function () {
2013
1320
  }));
2014
1321
  case 3:
2015
1322
  _context3.next = 5;
2016
- return this.api.putTree({
2017
- treePath: path
1323
+ return this.client("/tree/~", "PUT", {
1324
+ path: path,
1325
+ body: {},
1326
+ query: {
1327
+ validate_sources: false,
1328
+ validate_all: false,
1329
+ validate_binary_files: false
1330
+ }
2018
1331
  });
2019
1332
  case 5:
2020
- data = _context3.sent;
2021
- if (!fp.result.isOk(data)) {
1333
+ treeRes = _context3.sent;
1334
+ if (!(treeRes.status === 200)) {
2022
1335
  _context3.next = 26;
2023
1336
  break;
2024
1337
  }
2025
- if (data.value.modules[path]) {
1338
+ if ((_treeRes$json2 = treeRes.json) !== null && _treeRes$json2 !== void 0 && (_treeRes$json2 = _treeRes$json2.modules) !== null && _treeRes$json2 !== void 0 && _treeRes$json2[path]) {
2026
1339
  _context3.next = 10;
2027
1340
  break;
2028
1341
  }
2029
1342
  console.error("Val: could not find the module", {
2030
- moduleIds: Object.keys(data.value.modules),
1343
+ moduleIds: Object.keys(treeRes.json.modules),
2031
1344
  moduleId: path,
2032
- data: data
1345
+ data: treeRes
2033
1346
  });
2034
1347
  return _context3.abrupt("return", fp.result.err({
2035
1348
  message: "Could not fetch data.\nCould not find the module:\n" + path + "\n\nVerify that the val.modules file includes this module."
2036
1349
  }));
2037
1350
  case 10:
2038
- fetchedSource = data.value.modules[path].source;
1351
+ fetchedSource = (_treeRes$json3 = treeRes.json) === null || _treeRes$json3 === void 0 || (_treeRes$json3 = _treeRes$json3.modules) === null || _treeRes$json3 === void 0 || (_treeRes$json3 = _treeRes$json3[path]) === null || _treeRes$json3 === void 0 ? void 0 : _treeRes$json3.source;
2039
1352
  schema = this.schema[path];
2040
1353
  if (this.schema[path]) {
2041
1354
  _context3.next = 17;
@@ -2070,18 +1383,18 @@ var ValStore = /*#__PURE__*/function () {
2070
1383
  _context3.next = 33;
2071
1384
  break;
2072
1385
  case 26:
2073
- if (!(data.error.statusCode === 504)) {
1386
+ if (!(treeRes.status === 504)) {
2074
1387
  _context3.next = 31;
2075
1388
  break;
2076
1389
  }
2077
- console.error("Val: timeout", data.error);
1390
+ console.error("Val: timeout", treeRes.json);
2078
1391
  return _context3.abrupt("return", fp.result.err({
2079
1392
  message: "Timed out while fetching data. Try again later."
2080
1393
  }));
2081
1394
  case 31:
2082
- console.error("Val: failed to get module", data.error);
1395
+ console.error("Val: failed to get module", treeRes.json);
2083
1396
  return _context3.abrupt("return", fp.result.err({
2084
- message: "Could not fetch data. Verify that Val is correctly configured."
1397
+ message: "Could not fetch data. Verify that is correctly configured."
2085
1398
  }));
2086
1399
  case 33:
2087
1400
  case "end":
@@ -2095,78 +1408,139 @@ var ValStore = /*#__PURE__*/function () {
2095
1408
  return getModule;
2096
1409
  }()
2097
1410
  }, {
2098
- key: "applyPatch",
1411
+ key: "deletePatches",
2099
1412
  value: function () {
2100
- var _applyPatch = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(path, patchIds, patch) {
2101
- var data, newPatchId, fetchedSource, _data$value$modules$p, _i5, _Array$from3, _Array$from3$_i, subscriberId, subscriberModules;
1413
+ var _deletePatches = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(patchIds) {
1414
+ var patchesRes;
2102
1415
  return _regeneratorRuntime().wrap(function _callee4$(_context4) {
2103
1416
  while (1) switch (_context4.prev = _context4.next) {
2104
1417
  case 0:
2105
1418
  _context4.next = 2;
2106
- return this.api.putTree({
2107
- treePath: path,
2108
- patchIds: patchIds,
2109
- addPatch: {
2110
- path: path,
2111
- patch: patch
1419
+ return this.client("/patches/~", "DELETE", {
1420
+ query: {
1421
+ id: patchIds
2112
1422
  }
2113
1423
  });
2114
1424
  case 2:
2115
- data = _context4.sent;
2116
- if (!fp.result.isOk(data)) {
2117
- _context4.next = 20;
1425
+ patchesRes = _context4.sent;
1426
+ if (!(patchesRes.status === 200)) {
1427
+ _context4.next = 7;
2118
1428
  break;
2119
1429
  }
2120
- newPatchId = data.value.newPatchId;
1430
+ return _context4.abrupt("return", fp.result.ok(patchesRes.json));
1431
+ case 7:
1432
+ console.error("Val: failed to delete patches", patchesRes.json);
1433
+ return _context4.abrupt("return", fp.result.err({
1434
+ message: patchesRes.json.message
1435
+ }));
1436
+ case 9:
1437
+ case "end":
1438
+ return _context4.stop();
1439
+ }
1440
+ }, _callee4, this);
1441
+ }));
1442
+ function deletePatches(_x3) {
1443
+ return _deletePatches.apply(this, arguments);
1444
+ }
1445
+ return deletePatches;
1446
+ }()
1447
+ }, {
1448
+ key: "applyPatch",
1449
+ value: function () {
1450
+ var _applyPatch = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(path, patchIds, patch) {
1451
+ var treeRes, _treeRes$json4, newPatchId, fetchedSource, _treeRes$json5;
1452
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
1453
+ while (1) switch (_context5.prev = _context5.next) {
1454
+ case 0:
1455
+ _context5.next = 2;
1456
+ return this.client("/tree/~", "PUT", {
1457
+ path: path,
1458
+ query: {
1459
+ validate_sources: false,
1460
+ validate_all: false,
1461
+ validate_binary_files: false
1462
+ },
1463
+ body: {
1464
+ patchIds: patchIds,
1465
+ addPatch: {
1466
+ path: path,
1467
+ patch: patch
1468
+ }
1469
+ }
1470
+ });
1471
+ case 2:
1472
+ treeRes = _context5.sent;
1473
+ if (!(treeRes.status === 200)) {
1474
+ _context5.next = 19;
1475
+ break;
1476
+ }
1477
+ newPatchId = treeRes.json.newPatchId;
2121
1478
  if (newPatchId) {
2122
- _context4.next = 8;
1479
+ _context5.next = 8;
2123
1480
  break;
2124
1481
  }
2125
- console.error("Val: could create patch", data);
2126
- return _context4.abrupt("return", fp.result.err({
2127
- message: "Val: could not create patch."
1482
+ console.error("Val: could create patch", treeRes);
1483
+ return _context5.abrupt("return", fp.result.err({
1484
+ errorType: "other",
1485
+ message: "Val: could not create patch"
2128
1486
  }));
2129
1487
  case 8:
2130
- fetchedSource = data.value.modules[path].source;
1488
+ fetchedSource = (_treeRes$json4 = treeRes.json) === null || _treeRes$json4 === void 0 || (_treeRes$json4 = _treeRes$json4.modules) === null || _treeRes$json4 === void 0 || (_treeRes$json4 = _treeRes$json4[path]) === null || _treeRes$json4 === void 0 ? void 0 : _treeRes$json4.source;
2131
1489
  if (!(fetchedSource !== undefined)) {
2132
- _context4.next = 16;
1490
+ _context5.next = 15;
2133
1491
  break;
2134
1492
  }
2135
1493
  this.drafts[path] = fetchedSource;
2136
1494
  this.emitEvent(path, fetchedSource);
2137
- for (_i5 = 0, _Array$from3 = Array.from(this.subscribers.entries()); _i5 < _Array$from3.length; _i5++) {
2138
- _Array$from3$_i = _slicedToArray(_Array$from3[_i5], 2), subscriberId = _Array$from3$_i[0], subscriberModules = _Array$from3$_i[1];
2139
- if (subscriberModules[path]) {
2140
- this.subscribers.set(subscriberId, _objectSpread2(_objectSpread2({}, subscriberModules), {}, _defineProperty({}, path, this.drafts[path])));
2141
- this.emitChange(subscriberId);
2142
- }
2143
- }
2144
- return _context4.abrupt("return", fp.result.ok({
1495
+ return _context5.abrupt("return", fp.result.ok({
2145
1496
  newPatchId: newPatchId,
2146
1497
  modules: _defineProperty({}, path, {
2147
- patchIds: ((_data$value$modules$p = data.value.modules[path].patches) === null || _data$value$modules$p === void 0 ? void 0 : _data$value$modules$p.applied) || []
1498
+ patchIds: ((_treeRes$json5 = treeRes.json) === null || _treeRes$json5 === void 0 || (_treeRes$json5 = _treeRes$json5.modules) === null || _treeRes$json5 === void 0 || (_treeRes$json5 = _treeRes$json5[path]) === null || _treeRes$json5 === void 0 || (_treeRes$json5 = _treeRes$json5.patches) === null || _treeRes$json5 === void 0 ? void 0 : _treeRes$json5.applied) || []
2148
1499
  })
2149
1500
  }));
2150
- case 16:
1501
+ case 15:
2151
1502
  console.error("Val: could not patch");
2152
- return _context4.abrupt("return", fp.result.err({
1503
+ return _context5.abrupt("return", fp.result.err({
1504
+ errorType: "other",
2153
1505
  message: "Val: could not fetch data. Verify that the module exists."
2154
1506
  }));
2155
- case 18:
2156
- _context4.next = 22;
1507
+ case 17:
1508
+ _context5.next = 25;
2157
1509
  break;
2158
- case 20:
2159
- console.error("Val: failed to get module", data.error);
2160
- return _context4.abrupt("return", fp.result.err({
2161
- message: "Val: could not fetch data. Verify that Val is correctly configured."
1510
+ case 19:
1511
+ if (!(treeRes.status === 400 && "type" in treeRes.json)) {
1512
+ _context5.next = 23;
1513
+ break;
1514
+ }
1515
+ return _context5.abrupt("return", fp.result.err({
1516
+ errorType: "patch-error",
1517
+ errors: Object.entries(treeRes.json.errors).flatMap(function (_ref3) {
1518
+ var _ref4 = _slicedToArray(_ref3, 2),
1519
+ moduleFilePath = _ref4[0],
1520
+ value = _ref4[1];
1521
+ return (value !== null && value !== void 0 ? value : []).map(function (item) {
1522
+ return {
1523
+ moduleFilePath: moduleFilePath,
1524
+ patchError: item.error.message,
1525
+ patchId: item.patchId,
1526
+ skipped: item.skipped
1527
+ };
1528
+ });
1529
+ })
2162
1530
  }));
2163
- case 22:
1531
+ case 23:
1532
+ console.error("Val: failed to get module", treeRes.json);
1533
+ return _context5.abrupt("return", fp.result.err({
1534
+ errorType: "other",
1535
+ message: "Val: could not fetch data. Verify that is correctly configured."
1536
+ }));
1537
+ case 25:
2164
1538
  case "end":
2165
- return _context4.stop();
1539
+ return _context5.stop();
2166
1540
  }
2167
- }, _callee4, this);
1541
+ }, _callee5, this);
2168
1542
  }));
2169
- function applyPatch(_x3, _x4, _x5) {
1543
+ function applyPatch(_x4, _x5, _x6) {
2170
1544
  return _applyPatch.apply(this, arguments);
2171
1545
  }
2172
1546
  return applyPatch;
@@ -2186,78 +1560,819 @@ var ValStore = /*#__PURE__*/function () {
2186
1560
  }, {
2187
1561
  key: "initialize",
2188
1562
  value: function () {
2189
- var _initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
2190
- var data, paths, _i6, _arr, moduleId, schema, msg;
2191
- return _regeneratorRuntime().wrap(function _callee5$(_context5) {
2192
- while (1) switch (_context5.prev = _context5.next) {
1563
+ var _initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
1564
+ var schemaRes, paths, _i3, _arr, moduleId, schema, msg;
1565
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
1566
+ while (1) switch (_context6.prev = _context6.next) {
2193
1567
  case 0:
2194
- _context5.next = 2;
2195
- return this.api.getSchema({});
1568
+ _context6.next = 2;
1569
+ return this.client("/schema", "GET", {});
2196
1570
  case 2:
2197
- data = _context5.sent;
2198
- if (!fp.result.isOk(data)) {
2199
- _context5.next = 9;
1571
+ schemaRes = _context6.sent;
1572
+ if (!(schemaRes.status === 200)) {
1573
+ _context6.next = 9;
2200
1574
  break;
2201
1575
  }
2202
1576
  paths = [];
2203
- for (_i6 = 0, _arr = Object.keys(data.value.schemas); _i6 < _arr.length; _i6++) {
2204
- moduleId = _arr[_i6];
2205
- schema = data.value.schemas[moduleId];
1577
+ for (_i3 = 0, _arr = Object.keys(schemaRes.json.schemas); _i3 < _arr.length; _i3++) {
1578
+ moduleId = _arr[_i3];
1579
+ schema = schemaRes.json.schemas[moduleId];
2206
1580
  if (schema) {
2207
1581
  paths.push(moduleId);
2208
1582
  this.schema[moduleId] = schema;
2209
1583
  }
2210
1584
  }
2211
- return _context5.abrupt("return", fp.result.ok(paths));
1585
+ return _context6.abrupt("return", fp.result.ok(paths));
2212
1586
  case 9:
2213
1587
  msg = "Failed to fetch content. ";
2214
- if (data.error.statusCode === 401) {
1588
+ if (schemaRes.status === 401) {
2215
1589
  msg += "Authorization failed - check that you are logged in.";
2216
1590
  } else {
2217
- msg += "Get a developer to verify that Val is correctly setup.";
1591
+ msg += "Get a developer to verify that is correctly setup.";
2218
1592
  }
2219
- return _context5.abrupt("return", fp.result.err({
1593
+ return _context6.abrupt("return", fp.result.err({
2220
1594
  message: msg,
2221
1595
  details: {
2222
- fetchError: data.error
1596
+ fetchError: schemaRes.json
2223
1597
  }
2224
1598
  }));
2225
1599
  case 12:
2226
1600
  case "end":
2227
- return _context5.stop();
1601
+ return _context6.stop();
2228
1602
  }
2229
- }, _callee5, this);
1603
+ }, _callee6, this);
2230
1604
  }));
2231
1605
  function initialize() {
2232
1606
  return _initialize.apply(this, arguments);
2233
1607
  }
2234
1608
  return initialize;
2235
1609
  }()
2236
- }, {
2237
- key: "emitChange",
2238
- value: function emitChange(subscriberId) {
2239
- var _iterator = _createForOfIteratorHelper(this.listeners[subscriberId]),
2240
- _step;
2241
- try {
2242
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
2243
- var listener = _step.value;
2244
- listener();
2245
- }
2246
- } catch (err) {
2247
- _iterator.e(err);
2248
- } finally {
2249
- _iterator.f();
2250
- }
2251
- }
2252
1610
  }]);
2253
- return ValStore;
1611
+ return ValCache;
2254
1612
  }();
2255
- function createSubscriberId(paths) {
2256
- return paths.slice().sort().join("&");
2257
- }
2258
1613
 
2259
- exports.EXT_TO_MIME_TYPES = EXT_TO_MIME_TYPES;
2260
- exports.MIME_TYPES_TO_EXT = MIME_TYPES_TO_EXT;
1614
+ var JSONValueT = zod.z.lazy(function () {
1615
+ return zod.z.union([zod.z.string(), zod.z.number(), zod.z["boolean"](), zod.z["null"](), zod.z.array(JSONValueT), zod.z.record(JSONValueT)]);
1616
+ });
1617
+ var OperationT = zod.z.discriminatedUnion("op", [zod.z.object({
1618
+ op: zod.z.literal("add"),
1619
+ path: zod.z.array(zod.z.string()),
1620
+ value: JSONValueT
1621
+ }).strict(), zod.z.object({
1622
+ op: zod.z.literal("remove"),
1623
+ path: zod.z.array(zod.z.string()).nonempty()
1624
+ }).strict(), zod.z.object({
1625
+ op: zod.z.literal("replace"),
1626
+ path: zod.z.array(zod.z.string()),
1627
+ value: JSONValueT
1628
+ }).strict(), zod.z.object({
1629
+ op: zod.z.literal("move"),
1630
+ from: zod.z.array(zod.z.string()).nonempty(),
1631
+ path: zod.z.array(zod.z.string())
1632
+ }).strict(), zod.z.object({
1633
+ op: zod.z.literal("copy"),
1634
+ from: zod.z.array(zod.z.string()),
1635
+ path: zod.z.array(zod.z.string())
1636
+ }).strict(), zod.z.object({
1637
+ op: zod.z.literal("test"),
1638
+ path: zod.z.array(zod.z.string()),
1639
+ value: JSONValueT
1640
+ }).strict(), zod.z.object({
1641
+ op: zod.z.literal("file"),
1642
+ path: zod.z.array(zod.z.string()),
1643
+ filePath: zod.z.string(),
1644
+ nestedFilePath: zod.z.array(zod.z.string()).optional(),
1645
+ value: zod.z.union([zod.z.string(), zod.z.object({
1646
+ sha256: zod.z.string()
1647
+ })])
1648
+ }).strict()]);
1649
+ var Patch = zod.z.array(OperationT);
1650
+
1651
+ var SourcePath = zod.z.string().transform(function (path) {
1652
+ return path;
1653
+ });
1654
+
1655
+ var SerializedStringSchema = zod.z.object({
1656
+ type: zod.z.literal("string"),
1657
+ options: zod.z.object({
1658
+ maxLength: zod.z.number().optional(),
1659
+ minLength: zod.z.number().optional(),
1660
+ regexp: zod.z.object({
1661
+ source: zod.z.string(),
1662
+ flags: zod.z.string()
1663
+ }).optional()
1664
+ }).optional(),
1665
+ opt: zod.z["boolean"](),
1666
+ raw: zod.z["boolean"]()
1667
+ });
1668
+ var SerializedLiteralSchema = zod.z.object({
1669
+ type: zod.z.literal("literal"),
1670
+ value: zod.z.string(),
1671
+ opt: zod.z["boolean"]()
1672
+ });
1673
+ var SerializedBooleanSchema = zod.z.object({
1674
+ type: zod.z.literal("boolean"),
1675
+ opt: zod.z["boolean"]()
1676
+ });
1677
+ var SerializedNumberSchema = zod.z.object({
1678
+ type: zod.z.literal("number"),
1679
+ options: zod.z.object({
1680
+ max: zod.z.number().optional(),
1681
+ min: zod.z.number().optional()
1682
+ }).optional(),
1683
+ opt: zod.z["boolean"]()
1684
+ });
1685
+ var SerializedObjectSchema = zod.z.lazy(function () {
1686
+ return zod.z.object({
1687
+ type: zod.z.literal("object"),
1688
+ items: zod.z.record(SerializedSchema),
1689
+ opt: zod.z["boolean"]()
1690
+ });
1691
+ });
1692
+ var SerializedArraySchema = zod.z.lazy(function () {
1693
+ return zod.z.object({
1694
+ type: zod.z.literal("array"),
1695
+ item: SerializedSchema,
1696
+ opt: zod.z["boolean"]()
1697
+ });
1698
+ });
1699
+ var SerializedUnionSchema = zod.z.lazy(function () {
1700
+ return zod.z.object({
1701
+ type: zod.z.literal("union"),
1702
+ key: zod.z.union([zod.z.string(), SerializedSchema]),
1703
+ items: zod.z.array(SerializedSchema),
1704
+ opt: zod.z["boolean"]()
1705
+ });
1706
+ });
1707
+ var RichTextOptions = zod.z.object({
1708
+ style: zod.z.object({
1709
+ bold: zod.z["boolean"]().optional(),
1710
+ italic: zod.z["boolean"]().optional(),
1711
+ lineThrough: zod.z["boolean"]().optional()
1712
+ }).optional(),
1713
+ block: zod.z.object({
1714
+ h1: zod.z["boolean"]().optional(),
1715
+ h2: zod.z["boolean"]().optional(),
1716
+ h3: zod.z["boolean"]().optional(),
1717
+ h4: zod.z["boolean"]().optional(),
1718
+ h5: zod.z["boolean"]().optional(),
1719
+ h6: zod.z["boolean"]().optional(),
1720
+ ul: zod.z["boolean"]().optional(),
1721
+ ol: zod.z["boolean"]().optional()
1722
+ }).optional(),
1723
+ inline: zod.z.object({
1724
+ a: zod.z["boolean"]().optional(),
1725
+ img: zod.z["boolean"]().optional()
1726
+ }).optional()
1727
+ });
1728
+ var SerializedRichTextSchema = zod.z.object({
1729
+ type: zod.z.literal("richtext"),
1730
+ options: RichTextOptions.optional(),
1731
+ opt: zod.z["boolean"]()
1732
+ });
1733
+ var SerializedRecordSchema = zod.z.lazy(function () {
1734
+ return zod.z.object({
1735
+ type: zod.z.literal("record"),
1736
+ item: SerializedSchema,
1737
+ opt: zod.z["boolean"]()
1738
+ });
1739
+ });
1740
+ var SerializedKeyOfSchema = zod.z.lazy(function () {
1741
+ return zod.z.object({
1742
+ type: zod.z.literal("keyOf"),
1743
+ path: SourcePath,
1744
+ schema: SerializedSchema,
1745
+ values: zod.z.union([zod.z.literal("string"), zod.z.literal("number"), zod.z.array(zod.z.string())]),
1746
+ opt: zod.z["boolean"]()
1747
+ });
1748
+ });
1749
+ var FileOptions = zod.z.record(zod.z.never());
1750
+ var SerializedFileSchema = zod.z.object({
1751
+ type: zod.z.literal("file"),
1752
+ options: FileOptions.optional(),
1753
+ opt: zod.z["boolean"]()
1754
+ });
1755
+ var SerializedDateSchema = zod.z.object({
1756
+ type: zod.z.literal("date"),
1757
+ opt: zod.z["boolean"]()
1758
+ });
1759
+ var ImageOptions = zod.z.object({
1760
+ ext: zod.z.union([zod.z.tuple([zod.z.literal("jpg")]), zod.z.tuple([zod.z.literal("webp")])]).optional(),
1761
+ directory: zod.z.string().optional(),
1762
+ prefix: zod.z.string().optional()
1763
+ });
1764
+ var SerializedImageSchema = zod.z.object({
1765
+ type: zod.z.literal("image"),
1766
+ options: ImageOptions.optional(),
1767
+ opt: zod.z["boolean"]()
1768
+ });
1769
+ var SerializedSchema = zod.z.union([SerializedStringSchema, SerializedLiteralSchema, SerializedBooleanSchema, SerializedNumberSchema, SerializedObjectSchema, SerializedArraySchema, SerializedUnionSchema, SerializedRichTextSchema, SerializedRecordSchema, SerializedKeyOfSchema, SerializedFileSchema, SerializedDateSchema, SerializedImageSchema]);
1770
+
1771
+ var PatchId = zod.z.string().refine(function (_id) {
1772
+ return true;
1773
+ } // TODO:
1774
+ );
1775
+ var ModuleFilePath = zod.z.string().refine(function (_path) {
1776
+ return true;
1777
+ } // TODO:
1778
+ );
1779
+ var ValidationFixZ = zod.z.union([zod.z.literal("image:add-metadata"), zod.z.literal("image:replace-metadata"), zod.z.literal("file:add-metadata"), zod.z.literal("file:check-metadata"), zod.z.literal("fix:deprecated-richtext")]);
1780
+ var ValidationError = zod.z.object({
1781
+ message: zod.z.string(),
1782
+ value: zod.z.unknown().optional(),
1783
+ fatal: zod.z["boolean"]().optional(),
1784
+ fixes: zod.z.array(ValidationFixZ).optional()
1785
+ });
1786
+ var notFoundResponse = zod.z.object({
1787
+ status: zod.z.literal(401),
1788
+ json: zod.z.object({
1789
+ message: zod.z.string()
1790
+ })
1791
+ });
1792
+ var GenericError = zod.z.object({
1793
+ message: zod.z.string()
1794
+ });
1795
+ var ModulesError = zod.z.object({
1796
+ message: zod.z.string(),
1797
+ path: ModuleFilePath.optional()
1798
+ });
1799
+ zod.z.union([zod.z.literal("val_session"), zod.z.literal("val_enable"), zod.z.literal("val_state")]);
1800
+ var enableCookieValue = zod.z.object({
1801
+ value: zod.z.literal("true"),
1802
+ options: zod.z.object({
1803
+ httpOnly: zod.z.literal(false),
1804
+ sameSite: zod.z.literal("lax")
1805
+ })
1806
+ });
1807
+ var Api = {
1808
+ "/enable": {
1809
+ GET: {
1810
+ req: {
1811
+ query: {
1812
+ redirect_to: zod.z.string().optional()
1813
+ }
1814
+ },
1815
+ res: zod.z.union([zod.z.object({
1816
+ status: zod.z.literal(302),
1817
+ redirectTo: zod.z.string(),
1818
+ cookies: zod.z.object(_defineProperty({}, VAL_ENABLE_COOKIE_NAME, enableCookieValue))
1819
+ }), zod.z.object({
1820
+ status: zod.z.literal(400),
1821
+ json: zod.z.object({
1822
+ message: zod.z.string()
1823
+ })
1824
+ })])
1825
+ }
1826
+ },
1827
+ "/disable": {
1828
+ GET: {
1829
+ req: {
1830
+ query: {
1831
+ redirect_to: zod.z.string().optional()
1832
+ }
1833
+ },
1834
+ res: zod.z.union([zod.z.object({
1835
+ status: zod.z.literal(302),
1836
+ redirectTo: zod.z.string(),
1837
+ cookies: zod.z.object(_defineProperty({}, VAL_ENABLE_COOKIE_NAME, zod.z.object({
1838
+ value: zod.z.literal("false")
1839
+ })))
1840
+ }), zod.z.object({
1841
+ status: zod.z.literal(400),
1842
+ json: zod.z.object({
1843
+ message: zod.z.string()
1844
+ })
1845
+ })])
1846
+ }
1847
+ },
1848
+ "/authorize": {
1849
+ GET: {
1850
+ req: {
1851
+ query: {
1852
+ redirect_to: zod.z.string().optional()
1853
+ }
1854
+ },
1855
+ res: zod.z.union([zod.z.object({
1856
+ status: zod.z.literal(302),
1857
+ redirectTo: zod.z.string(),
1858
+ cookies: zod.z.object(_defineProperty(_defineProperty({}, VAL_ENABLE_COOKIE_NAME, enableCookieValue), VAL_STATE_COOKIE, zod.z.object({
1859
+ value: zod.z.string(),
1860
+ options: zod.z.object({
1861
+ httpOnly: zod.z.literal(true),
1862
+ sameSite: zod.z.literal("lax"),
1863
+ expires: zod.z["instanceof"](Date)
1864
+ })
1865
+ })))
1866
+ }), zod.z.object({
1867
+ status: zod.z.literal(400),
1868
+ json: zod.z.object({
1869
+ message: zod.z.string()
1870
+ })
1871
+ })])
1872
+ }
1873
+ },
1874
+ "/callback": {
1875
+ GET: {
1876
+ req: {
1877
+ query: {
1878
+ code: zod.z.string().optional(),
1879
+ state: zod.z.string().optional()
1880
+ },
1881
+ cookies: _defineProperty({}, VAL_STATE_COOKIE, zod.z.string())
1882
+ },
1883
+ res: zod.z.object({
1884
+ status: zod.z.literal(302),
1885
+ redirectTo: zod.z.string(),
1886
+ cookies: zod.z.object(_defineProperty(_defineProperty(_defineProperty({}, VAL_STATE_COOKIE, zod.z.object({
1887
+ value: zod.z.literal(null)
1888
+ })), VAL_ENABLE_COOKIE_NAME, enableCookieValue.optional()), VAL_SESSION_COOKIE, zod.z.object({
1889
+ value: zod.z.string(),
1890
+ options: zod.z.object({
1891
+ httpOnly: zod.z.literal(true),
1892
+ sameSite: zod.z.literal("strict"),
1893
+ path: zod.z.string(),
1894
+ secure: zod.z.literal(true),
1895
+ expires: zod.z["instanceof"](Date)
1896
+ }).optional()
1897
+ }).optional()))
1898
+ })
1899
+ }
1900
+ },
1901
+ "/session": {
1902
+ GET: {
1903
+ req: {
1904
+ cookies: {
1905
+ val_session: zod.z.string().optional()
1906
+ }
1907
+ },
1908
+ res: zod.z.union([zod.z.object({
1909
+ status: zod.z.literal(200),
1910
+ json: zod.z.object({
1911
+ mode: zod.z.union([zod.z.literal("local"), zod.z.literal("proxy")]),
1912
+ enabled: zod.z["boolean"]()
1913
+ })
1914
+ }), zod.z.object({
1915
+ status: zod.z.union([
1916
+ // TODO: Remove the ones we don't need.
1917
+ zod.z.literal(400), zod.z.literal(401), zod.z.literal(403), zod.z.literal(404), zod.z.literal(500), zod.z.literal(501)]),
1918
+ json: zod.z.object({
1919
+ message: zod.z.string()
1920
+ })
1921
+ }), zod.z.object({
1922
+ status: zod.z.literal(401),
1923
+ json: zod.z.object({
1924
+ message: zod.z.string(),
1925
+ details: zod.z.union([zod.z.string(), zod.z.object({
1926
+ reason: zod.z.string()
1927
+ }), zod.z.object({
1928
+ sub: zod.z.string(),
1929
+ exp: zod.z.number(),
1930
+ token: zod.z.string(),
1931
+ org: zod.z.string(),
1932
+ project: zod.z.string()
1933
+ })])
1934
+ })
1935
+ }), zod.z.object({
1936
+ status: zod.z.literal(500),
1937
+ json: zod.z.object({
1938
+ message: zod.z.string()
1939
+ })
1940
+ })])
1941
+ }
1942
+ },
1943
+ "/logout": {
1944
+ GET: {
1945
+ req: {},
1946
+ // TODO fix req types
1947
+ res: zod.z.object({
1948
+ status: zod.z.literal(200),
1949
+ cookies: zod.z.object(_defineProperty(_defineProperty({}, VAL_SESSION_COOKIE, zod.z.object({
1950
+ value: zod.z.literal(null)
1951
+ })), VAL_STATE_COOKIE, zod.z.object({
1952
+ value: zod.z.literal(null)
1953
+ })))
1954
+ })
1955
+ }
1956
+ },
1957
+ "/patches/~": {
1958
+ DELETE: {
1959
+ req: {
1960
+ query: {
1961
+ id: zod.z.array(PatchId)
1962
+ },
1963
+ cookies: {
1964
+ val_session: zod.z.string().optional()
1965
+ }
1966
+ },
1967
+ res: zod.z.union([notFoundResponse, zod.z.object({
1968
+ status: zod.z.literal(500),
1969
+ json: zod.z.object({
1970
+ message: zod.z.string(),
1971
+ details: zod.z.record(PatchId, GenericError)
1972
+ })
1973
+ }), zod.z.object({
1974
+ status: zod.z.literal(200),
1975
+ json: zod.z.array(PatchId)
1976
+ })])
1977
+ },
1978
+ GET: {
1979
+ req: {
1980
+ query: {
1981
+ author: zod.z.array(zod.z.string()).optional(),
1982
+ patch_id: zod.z.array(PatchId).optional(),
1983
+ module_file_path: zod.z.array(ModuleFilePath).optional(),
1984
+ omit_patch: zod.z["boolean"]().optional() // TODO: rename! we mean that we are not including the actual patch / operations in the response
1985
+ },
1986
+ cookies: {
1987
+ val_session: zod.z.string().optional()
1988
+ }
1989
+ },
1990
+ res: zod.z.union([notFoundResponse, zod.z.object({
1991
+ status: zod.z.literal(500),
1992
+ json: zod.z.object({
1993
+ message: zod.z.string(),
1994
+ details: zod.z.record(PatchId, GenericError)
1995
+ })
1996
+ }), zod.z.object({
1997
+ status: zod.z.literal(200),
1998
+ json: zod.z.object({
1999
+ patches: zod.z.record(PatchId, zod.z.object({
2000
+ path: ModuleFilePath,
2001
+ patch: Patch.optional(),
2002
+ createdAt: zod.z.string(),
2003
+ authorId: zod.z.string().nullable(),
2004
+ appliedAt: zod.z.object({
2005
+ baseSha: zod.z.string(),
2006
+ git: zod.z.object({
2007
+ commitSha: zod.z.string()
2008
+ }).optional(),
2009
+ timestamp: zod.z.string()
2010
+ }).nullable()
2011
+ })),
2012
+ error: GenericError.optional(),
2013
+ errors: zod.z.record(PatchId, GenericError).optional()
2014
+ })
2015
+ })])
2016
+ }
2017
+ },
2018
+ "/schema": {
2019
+ GET: {
2020
+ req: {
2021
+ cookies: {
2022
+ val_session: zod.z.string().optional()
2023
+ }
2024
+ },
2025
+ res: zod.z.union([notFoundResponse, zod.z.object({
2026
+ status: zod.z.literal(500),
2027
+ json: zod.z.object({
2028
+ message: zod.z.string(),
2029
+ details: zod.z.array(ModulesError)
2030
+ })
2031
+ }), zod.z.object({
2032
+ status: zod.z.literal(200),
2033
+ json: zod.z.object({
2034
+ schemaSha: zod.z.string(),
2035
+ schemas: zod.z.record(ModuleFilePath, SerializedSchema)
2036
+ })
2037
+ })])
2038
+ }
2039
+ },
2040
+ "/tree/~": {
2041
+ PUT: {
2042
+ req: {
2043
+ path: zod.z.string().optional(),
2044
+ body: zod.z.object({
2045
+ patchIds: zod.z.array(PatchId).optional(),
2046
+ addPatch: zod.z.object({
2047
+ path: ModuleFilePath,
2048
+ patch: Patch
2049
+ }).optional()
2050
+ }).optional(),
2051
+ query: {
2052
+ validate_all: zod.z["boolean"]().optional(),
2053
+ validate_sources: zod.z["boolean"]().optional(),
2054
+ validate_binary_files: zod.z["boolean"]().optional()
2055
+ },
2056
+ cookies: {
2057
+ val_session: zod.z.string().optional()
2058
+ }
2059
+ },
2060
+ res: zod.z.union([notFoundResponse, zod.z.object({
2061
+ status: zod.z.literal(401),
2062
+ json: GenericError
2063
+ }), zod.z.object({
2064
+ status: zod.z.literal(500),
2065
+ json: zod.z.object({
2066
+ message: zod.z.string(),
2067
+ details: zod.z.union([zod.z.array(ModulesError), GenericError])
2068
+ })
2069
+ }), zod.z.object({
2070
+ status: zod.z.literal(400),
2071
+ json: zod.z.object({
2072
+ message: zod.z.string(),
2073
+ details: zod.z.array(ModulesError)
2074
+ })
2075
+ }), zod.z.object({
2076
+ status: zod.z.literal(400),
2077
+ json: zod.z.object({
2078
+ type: zod.z.literal("patch-error"),
2079
+ message: zod.z.string(),
2080
+ errors: zod.z.record(ModuleFilePath, zod.z.array(zod.z.object({
2081
+ patchId: PatchId,
2082
+ skipped: zod.z["boolean"](),
2083
+ error: GenericError
2084
+ })))
2085
+ })
2086
+ }), zod.z.object({
2087
+ status: zod.z.literal(200),
2088
+ json: zod.z.object({
2089
+ schemaSha: zod.z.string(),
2090
+ modules: zod.z.record(ModuleFilePath, zod.z.object({
2091
+ source: zod.z.any(),
2092
+ //.optional(), // TODO: Json zod type
2093
+ patches: zod.z.object({
2094
+ applied: zod.z.array(PatchId),
2095
+ skipped: zod.z.array(PatchId).optional(),
2096
+ errors: zod.z.record(PatchId, GenericError).optional()
2097
+ }).optional(),
2098
+ validationErrors: zod.z.record(SourcePath, zod.z.array(ValidationError)).optional()
2099
+ })),
2100
+ newPatchId: PatchId.optional()
2101
+ })
2102
+ })])
2103
+ }
2104
+ },
2105
+ "/save": {
2106
+ POST: {
2107
+ req: {
2108
+ body: zod.z.object({
2109
+ patchIds: zod.z.array(PatchId)
2110
+ }),
2111
+ cookies: {
2112
+ val_session: zod.z.string().optional()
2113
+ }
2114
+ },
2115
+ res: zod.z.union([notFoundResponse, zod.z.object({
2116
+ status: zod.z.literal(200),
2117
+ json: zod.z.object({}) // TODO:
2118
+ }), zod.z.object({
2119
+ status: zod.z.literal(400),
2120
+ json: zod.z.object({
2121
+ message: zod.z.string(),
2122
+ details: zod.z.union([zod.z.object({
2123
+ sourceFilePatchErrors: zod.z.record(ModuleFilePath, zod.z.array(GenericError)),
2124
+ binaryFilePatchErrors: zod.z.record(GenericError)
2125
+ }), zod.z.array(GenericError)])
2126
+ })
2127
+ })])
2128
+ }
2129
+ },
2130
+ "/files": {
2131
+ GET: {
2132
+ req: {
2133
+ path: zod.z.string(),
2134
+ query: {
2135
+ patch_id: PatchId.optional()
2136
+ }
2137
+ },
2138
+ res: zod.z.union([zod.z.object({
2139
+ status: zod.z.literal(200),
2140
+ body: zod.z["instanceof"](ReadableStream)
2141
+ }), zod.z.object({
2142
+ status: zod.z.literal(404),
2143
+ json: zod.z.object({
2144
+ message: zod.z.string()
2145
+ })
2146
+ })])
2147
+ }
2148
+ }
2149
+ };
2150
+
2151
+ // Types and helper types:
2152
+
2153
+ /**
2154
+ * Extracts the keys of an object where the value is not undefined.
2155
+ */
2156
+
2157
+ /**
2158
+ * Extracts the keys of an object where the value is not undefined.
2159
+ * Then picks the keys from the object.
2160
+ * This is useful for creating a new object type with only the defined keys.
2161
+ * @example
2162
+ * type A = { a: string; b?: number };
2163
+ * type B = DefinedObject<A>; // { a: string }
2164
+ */
2165
+
2166
+ /**
2167
+ * This schema supports:
2168
+ * 1. multiple query params with the same name
2169
+ * 2. simple API route definitions where:
2170
+ * 2.1. z.array means at least one query params this name is required
2171
+ * 2.2. z.optional means no query param of this name is accepted
2172
+ * 2.3. z.array(...).optional() means zero or more query params of this name is accepted
2173
+ *
2174
+ * Do not change this without updating the ValRouter query parsing logic
2175
+ * */
2176
+
2177
+ var createValClient = function createValClient(host) {
2178
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2179
+ var anyApi = Api;
2180
+ return /*#__PURE__*/function () {
2181
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(path, method, req) {
2182
+ var _anyApi$path, _apiEndpoint$req$body;
2183
+ var anyReq, fullPath, params, _i, _Object$keys, _anyReq$query, key, _anyReq$query2, _iterator, _step, value, _anyReq$query3, apiEndpoint, reqBodyResult, res;
2184
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
2185
+ while (1) switch (_context2.prev = _context2.next) {
2186
+ case 0:
2187
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2188
+ anyReq = req;
2189
+ fullPath = path;
2190
+ if (anyReq !== null && anyReq !== void 0 && anyReq.path && anyReq.path.length > 0) {
2191
+ fullPath += anyReq.path;
2192
+ }
2193
+ if (anyReq.query) {
2194
+ params = [];
2195
+ for (_i = 0, _Object$keys = Object.keys(anyReq.query); _i < _Object$keys.length; _i++) {
2196
+ key = _Object$keys[_i];
2197
+ if (Array.isArray((_anyReq$query = anyReq.query) === null || _anyReq$query === void 0 ? void 0 : _anyReq$query[key])) {
2198
+ _iterator = _createForOfIteratorHelper(((_anyReq$query2 = anyReq.query) === null || _anyReq$query2 === void 0 ? void 0 : _anyReq$query2[key]) || []);
2199
+ try {
2200
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
2201
+ value = _step.value;
2202
+ params.push([key, value.toString()]);
2203
+ }
2204
+ } catch (err) {
2205
+ _iterator.e(err);
2206
+ } finally {
2207
+ _iterator.f();
2208
+ }
2209
+ } else {
2210
+ params.push([key, anyReq === null || anyReq === void 0 || (_anyReq$query3 = anyReq.query) === null || _anyReq$query3 === void 0 ? void 0 : _anyReq$query3[key]]);
2211
+ }
2212
+ }
2213
+ if (anyReq !== null && anyReq !== void 0 && anyReq.query && params.length > 0) {
2214
+ fullPath += "?".concat(new URLSearchParams(params).toString());
2215
+ }
2216
+ }
2217
+ apiEndpoint = anyApi === null || anyApi === void 0 || (_anyApi$path = anyApi[path]) === null || _anyApi$path === void 0 ? void 0 : _anyApi$path[method];
2218
+ if (apiEndpoint) {
2219
+ _context2.next = 7;
2220
+ break;
2221
+ }
2222
+ return _context2.abrupt("return", {
2223
+ status: null,
2224
+ json: {
2225
+ message: "Invalid route ".concat(path, " with method ").concat(method, ". This is most likely a Val bug."),
2226
+ type: "client_side_validation_error",
2227
+ details: {
2228
+ validationError: "Route ".concat(path, " with method ").concat(method, " not found."),
2229
+ data: {
2230
+ routes: Object.keys(anyApi || {}),
2231
+ methods: Object.keys((anyApi === null || anyApi === void 0 ? void 0 : anyApi[path]) || {}),
2232
+ route: path,
2233
+ method: method
2234
+ }
2235
+ }
2236
+ }
2237
+ });
2238
+ case 7:
2239
+ reqBodyResult = (_apiEndpoint$req$body = apiEndpoint.req.body) === null || _apiEndpoint$req$body === void 0 ? void 0 : _apiEndpoint$req$body.safeParse(anyReq.body);
2240
+ if (!(reqBodyResult && !reqBodyResult.success)) {
2241
+ _context2.next = 10;
2242
+ break;
2243
+ }
2244
+ return _context2.abrupt("return", {
2245
+ status: null,
2246
+ json: {
2247
+ message: "Invalid request body. This is most likely a Val bug.",
2248
+ type: "client_side_validation_error",
2249
+ details: {
2250
+ validationError: zodValidationError.fromZodError(reqBodyResult.error).toString(),
2251
+ data: anyReq.body
2252
+ }
2253
+ }
2254
+ });
2255
+ case 10:
2256
+ _context2.prev = 10;
2257
+ _context2.next = 13;
2258
+ return fetch("".concat(host).concat(fullPath), {
2259
+ method: method,
2260
+ headers: {
2261
+ "Content-Type": "application/json"
2262
+ },
2263
+ body: anyReq.body ? JSON.stringify(anyReq.body) : undefined
2264
+ }).then( /*#__PURE__*/function () {
2265
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(res) {
2266
+ var _apiEndpoint$res;
2267
+ var contentTypeHeaders, json, valClientResult, responseResult;
2268
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
2269
+ while (1) switch (_context.prev = _context.next) {
2270
+ case 0:
2271
+ contentTypeHeaders = res.headers.get("content-type");
2272
+ if (contentTypeHeaders !== null && contentTypeHeaders !== void 0 && contentTypeHeaders.includes("application/json")) {
2273
+ _context.next = 3;
2274
+ break;
2275
+ }
2276
+ return _context.abrupt("return", {
2277
+ status: null,
2278
+ json: {
2279
+ type: "client_side_validation_error",
2280
+ message: "Invalid content type. This could be a result of mismatched Val versions.",
2281
+ details: {
2282
+ validationError: "Invalid content type",
2283
+ data: {
2284
+ status: res.status,
2285
+ contentType: contentTypeHeaders
2286
+ }
2287
+ }
2288
+ }
2289
+ });
2290
+ case 3:
2291
+ _context.next = 5;
2292
+ return res.json();
2293
+ case 5:
2294
+ json = _context.sent;
2295
+ valClientResult = {
2296
+ status: res.status,
2297
+ json: json
2298
+ };
2299
+ responseResult = (_apiEndpoint$res = apiEndpoint.res) === null || _apiEndpoint$res === void 0 ? void 0 : _apiEndpoint$res.safeParse(valClientResult);
2300
+ if (!(responseResult && !responseResult.success)) {
2301
+ _context.next = 10;
2302
+ break;
2303
+ }
2304
+ return _context.abrupt("return", {
2305
+ status: null,
2306
+ json: {
2307
+ message: "Response could not be validated. This could be a result of mismatched Val versions.",
2308
+ type: "client_side_validation_error",
2309
+ details: {
2310
+ validationError: zodValidationError.fromZodError(responseResult.error).toString(),
2311
+ data: valClientResult
2312
+ }
2313
+ }
2314
+ });
2315
+ case 10:
2316
+ return _context.abrupt("return", {
2317
+ status: res.status,
2318
+ json: json
2319
+ });
2320
+ case 11:
2321
+ case "end":
2322
+ return _context.stop();
2323
+ }
2324
+ }, _callee);
2325
+ }));
2326
+ return function (_x4) {
2327
+ return _ref2.apply(this, arguments);
2328
+ };
2329
+ }());
2330
+ case 13:
2331
+ res = _context2.sent;
2332
+ return _context2.abrupt("return", res);
2333
+ case 17:
2334
+ _context2.prev = 17;
2335
+ _context2.t0 = _context2["catch"](10);
2336
+ return _context2.abrupt("return", {
2337
+ status: null,
2338
+ json: {
2339
+ message: "Failed to fetch data. This is likely a network error.",
2340
+ type: "network_error",
2341
+ details: _context2.t0 instanceof Error ? _context2.t0.message : JSON.stringify(_context2.t0)
2342
+ }
2343
+ });
2344
+ case 20:
2345
+ case "end":
2346
+ return _context2.stop();
2347
+ }
2348
+ }, _callee2, null, [[10, 17]]);
2349
+ }));
2350
+ return function (_x, _x2, _x3) {
2351
+ return _ref.apply(this, arguments);
2352
+ };
2353
+ }();
2354
+ };
2355
+
2356
+ var urlOf = function urlOf() {
2357
+ var route = arguments.length <= 0 ? undefined : arguments[0];
2358
+ var query = arguments.length <= 1 ? undefined : arguments[1];
2359
+ if (query) {
2360
+ var params = Object.entries(query).flatMap(function (_ref) {
2361
+ var _ref2 = _slicedToArray(_ref, 2),
2362
+ key = _ref2[0],
2363
+ value = _ref2[1];
2364
+ if (!value) {
2365
+ return [];
2366
+ }
2367
+ return [[key, value.toString()]];
2368
+ });
2369
+ var searchParams = new URLSearchParams(params);
2370
+ return "".concat(route + "?" + searchParams.toString());
2371
+ }
2372
+ return "".concat(route);
2373
+ };
2374
+
2375
+ exports.Api = Api;
2261
2376
  exports.RemirrorBr = RemirrorBr;
2262
2377
  exports.RemirrorBulletList = RemirrorBulletList;
2263
2378
  exports.RemirrorHeading = RemirrorHeading;
@@ -2272,9 +2387,8 @@ exports.RemirrorTextMark = RemirrorTextMark;
2272
2387
  exports.VAL_ENABLE_COOKIE_NAME = VAL_ENABLE_COOKIE_NAME;
2273
2388
  exports.VAL_SESSION_COOKIE = VAL_SESSION_COOKIE;
2274
2389
  exports.VAL_STATE_COOKIE = VAL_STATE_COOKIE;
2275
- exports.ValStore = ValStore;
2276
- exports.filenameToMimeType = filenameToMimeType;
2277
- exports.getMimeType = getMimeType;
2278
- exports.mimeTypeToFileExt = mimeTypeToFileExt;
2390
+ exports.ValCache = ValCache;
2391
+ exports.createValClient = createValClient;
2279
2392
  exports.remirrorToRichTextSource = remirrorToRichTextSource;
2280
2393
  exports.richTextToRemirror = richTextToRemirror;
2394
+ exports.urlOf = urlOf;