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