@valbuild/shared 0.63.5 → 0.65.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,8 +5,9 @@ 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
- function toPrimitive(t, r) {
10
+ function _toPrimitive(t, r) {
10
11
  if ("object" != typeof t || !t) return t;
11
12
  var e = t[Symbol.toPrimitive];
12
13
  if (void 0 !== e) {
@@ -17,24 +18,18 @@ function toPrimitive(t, r) {
17
18
  return ("string" === r ? String : Number)(t);
18
19
  }
19
20
 
20
- function toPropertyKey(t) {
21
- var i = toPrimitive(t, "string");
22
- return "symbol" == typeof i ? i : String(i);
21
+ function _toPropertyKey(t) {
22
+ var i = _toPrimitive(t, "string");
23
+ return "symbol" == typeof i ? i : i + "";
23
24
  }
24
25
 
25
- function _defineProperty(obj, key, value) {
26
- key = toPropertyKey(key);
27
- if (key in obj) {
28
- Object.defineProperty(obj, key, {
29
- value: value,
30
- enumerable: true,
31
- configurable: true,
32
- writable: true
33
- });
34
- } else {
35
- obj[key] = value;
36
- }
37
- return obj;
26
+ function _defineProperty(e, r, t) {
27
+ return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
28
+ value: t,
29
+ enumerable: !0,
30
+ configurable: !0,
31
+ writable: !0
32
+ }) : e[r] = t, e;
38
33
  }
39
34
 
40
35
  function ownKeys(e, r) {
@@ -59,840 +54,74 @@ function _objectSpread2(e) {
59
54
  return e;
60
55
  }
61
56
 
62
- function _arrayLikeToArray(arr, len) {
63
- if (len == null || len > arr.length) len = arr.length;
64
- for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
65
- return arr2;
57
+ function _arrayLikeToArray(r, a) {
58
+ (null == a || a > r.length) && (a = r.length);
59
+ for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
60
+ return n;
66
61
  }
67
62
 
68
- function _unsupportedIterableToArray(o, minLen) {
69
- if (!o) return;
70
- if (typeof o === "string") return _arrayLikeToArray(o, minLen);
71
- var n = Object.prototype.toString.call(o).slice(8, -1);
72
- if (n === "Object" && o.constructor) n = o.constructor.name;
73
- if (n === "Map" || n === "Set") return Array.from(o);
74
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
63
+ function _unsupportedIterableToArray(r, a) {
64
+ if (r) {
65
+ if ("string" == typeof r) return _arrayLikeToArray(r, a);
66
+ var t = {}.toString.call(r).slice(8, -1);
67
+ return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
68
+ }
75
69
  }
76
70
 
77
- function _createForOfIteratorHelper(o, allowArrayLike) {
78
- var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
79
- if (!it) {
80
- if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
81
- if (it) o = it;
82
- var i = 0;
83
- var F = function () {};
71
+ function _createForOfIteratorHelper(r, e) {
72
+ var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
73
+ if (!t) {
74
+ if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) {
75
+ t && (r = t);
76
+ var n = 0,
77
+ F = function () {};
84
78
  return {
85
79
  s: F,
86
80
  n: function () {
87
- if (i >= o.length) return {
88
- done: true
89
- };
90
- return {
91
- done: false,
92
- value: o[i++]
81
+ return n >= r.length ? {
82
+ done: !0
83
+ } : {
84
+ done: !1,
85
+ value: r[n++]
93
86
  };
94
87
  },
95
- e: function (e) {
96
- throw e;
88
+ e: function (r) {
89
+ throw r;
97
90
  },
98
91
  f: F
99
92
  };
100
93
  }
101
94
  throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
102
95
  }
103
- var normalCompletion = true,
104
- didErr = false,
105
- err;
96
+ var o,
97
+ a = !0,
98
+ u = !1;
106
99
  return {
107
100
  s: function () {
108
- it = it.call(o);
101
+ t = t.call(r);
109
102
  },
110
103
  n: function () {
111
- var step = it.next();
112
- normalCompletion = step.done;
113
- return step;
104
+ var r = t.next();
105
+ return a = r.done, r;
114
106
  },
115
- e: function (e) {
116
- didErr = true;
117
- err = e;
107
+ e: function (r) {
108
+ u = !0, o = r;
118
109
  },
119
110
  f: function () {
120
111
  try {
121
- if (!normalCompletion && it.return != null) it.return();
112
+ a || null == t.return || t.return();
122
113
  } finally {
123
- if (didErr) throw err;
114
+ if (u) throw o;
124
115
  }
125
116
  }
126
117
  };
127
118
  }
128
119
 
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
120
  function remirrorToRichTextSource(node) {
892
121
  var files = {};
893
122
  var blocks = [];
894
123
  var i = 0;
895
- var _iterator = _createForOfIteratorHelper(node.content),
124
+ var _iterator = _createForOfIteratorHelper((node === null || node === void 0 ? void 0 : node.content) || []),
896
125
  _step;
897
126
  try {
898
127
  for (_iterator.s(); !(_step = _iterator.n()).done;) {
@@ -1069,13 +298,16 @@ var textEncoder = new TextEncoder();
1069
298
  function convertImageNode(path, node, files) {
1070
299
  if (node.attrs && node.attrs.src.startsWith("data:")) {
1071
300
  var sha256 = core.Internal.getSHA256Hash(textEncoder.encode(node.attrs.src));
1072
- var mimeType = getMimeType(node.attrs.src);
301
+ var mimeType = core.Internal.getMimeType(node.attrs.src);
1073
302
  if (mimeType === undefined) {
1074
303
  throw new Error("Could not detect Mime Type for image: ".concat(node.attrs.src));
1075
304
  }
1076
- var fileExt = mimeTypeToFileExt(mimeType);
1077
- var fileName = node.attrs.fileName || "".concat(sha256, ".").concat(fileExt);
1078
- var filePath = "/public/".concat(fileName);
305
+ var fileName = core.Internal.createFilename(node.attrs.src, node.attrs.fileName || "", {
306
+ width: typeof node.attrs.width === "number" ? node.attrs.width : 0,
307
+ height: typeof node.attrs.height === "number" ? node.attrs.height : 0,
308
+ mimeType: mimeType
309
+ }, sha256);
310
+ var filePath = "/public/val/".concat(fileName);
1079
311
  var existingFilesEntry = files[filePath];
1080
312
  var thisPath = path
1081
313
  // file is added as src (see below):
@@ -1093,21 +325,32 @@ function convertImageNode(path, node, files) {
1093
325
  src: _defineProperty(_defineProperty(_defineProperty({}, core.VAL_EXTENSION, "file"), core.FILE_REF_PROP, filePath), "metadata", {
1094
326
  width: typeof node.attrs.width === "number" ? node.attrs.width : 0,
1095
327
  height: typeof node.attrs.height === "number" ? node.attrs.height : 0,
1096
- sha256: sha256 || "",
1097
328
  mimeType: mimeType
1098
329
  })
1099
330
  };
1100
331
  } else if (node.attrs) {
1101
- var _sha = getParam("sha256", node.attrs.src);
1102
- var patchId = getParam("patch_id", node.attrs.src);
1103
- var noParamsSrc = node.attrs.src.split("?")[0];
332
+ var url = node.attrs.src;
333
+ var patchId = getParam("patch_id", url);
334
+ var noParamsUrl = url.split("?")[0];
335
+ if (patchId) {
336
+ if (noParamsUrl.startsWith("/api/val/files/public")) {
337
+ noParamsUrl = noParamsUrl.slice("/api/val/files".length);
338
+ } else {
339
+ console.error("Patched image URL does not start with /api/val/files: " + url);
340
+ }
341
+ } else {
342
+ if (!noParamsUrl.startsWith("/public")) {
343
+ noParamsUrl = "/public".concat(noParamsUrl);
344
+ } else {
345
+ console.error("Unpatched image URL starts with /public: " + url);
346
+ }
347
+ }
1104
348
  var tag = {
1105
349
  tag: "img",
1106
- src: _objectSpread2(_defineProperty(_defineProperty(_defineProperty({}, core.VAL_EXTENSION, "file"), core.FILE_REF_PROP, "/public".concat(node.attrs.src.split("?")[0])), "metadata", {
350
+ src: _objectSpread2(_defineProperty(_defineProperty(_defineProperty({}, core.VAL_EXTENSION, "file"), core.FILE_REF_PROP, noParamsUrl), "metadata", {
1107
351
  width: typeof node.attrs.width === "number" ? node.attrs.width : 0,
1108
352
  height: typeof node.attrs.height === "number" ? node.attrs.height : 0,
1109
- sha256: _sha || "",
1110
- mimeType: noParamsSrc && filenameToMimeType(noParamsSrc) || ""
353
+ mimeType: noParamsUrl && core.Internal.filenameToMimeType(noParamsUrl) || ""
1111
354
  }), patchId ? {
1112
355
  patch_id: patchId
1113
356
  } : {})
@@ -1212,20 +455,20 @@ var RemirrorJSON = zod.z.object({
1212
455
  content: zod.z.array(zod.z.union([RemirrorParagraph, RemirrorHeading, RemirrorBulletList, RemirrorOrderedList]))
1213
456
  });
1214
457
 
1215
- function _arrayWithoutHoles(arr) {
1216
- if (Array.isArray(arr)) return _arrayLikeToArray(arr);
458
+ function _arrayWithoutHoles(r) {
459
+ if (Array.isArray(r)) return _arrayLikeToArray(r);
1217
460
  }
1218
461
 
1219
- function _iterableToArray(iter) {
1220
- if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
462
+ function _iterableToArray(r) {
463
+ if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
1221
464
  }
1222
465
 
1223
466
  function _nonIterableSpread() {
1224
467
  throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
1225
468
  }
1226
469
 
1227
- function _toConsumableArray(arr) {
1228
- return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
470
+ function _toConsumableArray(r) {
471
+ return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread();
1229
472
  }
1230
473
 
1231
474
  function richTextToRemirror(richtext) {
@@ -1477,6 +720,46 @@ var VAL_SESSION_COOKIE = core.Internal.VAL_SESSION_COOKIE;
1477
720
  var VAL_STATE_COOKIE = core.Internal.VAL_STATE_COOKIE;
1478
721
  var VAL_ENABLE_COOKIE_NAME = core.Internal.VAL_ENABLE_COOKIE_NAME;
1479
722
 
723
+ function _arrayWithHoles(r) {
724
+ if (Array.isArray(r)) return r;
725
+ }
726
+
727
+ function _iterableToArrayLimit(r, l) {
728
+ var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
729
+ if (null != t) {
730
+ var e,
731
+ n,
732
+ i,
733
+ u,
734
+ a = [],
735
+ f = !0,
736
+ o = !1;
737
+ try {
738
+ if (i = (t = t.call(r)).next, 0 === l) {
739
+ if (Object(t) !== t) return;
740
+ f = !1;
741
+ } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
742
+ } catch (r) {
743
+ o = !0, n = r;
744
+ } finally {
745
+ try {
746
+ if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
747
+ } finally {
748
+ if (o) throw n;
749
+ }
750
+ }
751
+ return a;
752
+ }
753
+ }
754
+
755
+ function _nonIterableRest() {
756
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
757
+ }
758
+
759
+ function _slicedToArray(r, e) {
760
+ return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
761
+ }
762
+
1480
763
  function _regeneratorRuntime() {
1481
764
  _regeneratorRuntime = function () {
1482
765
  return e;
@@ -1585,7 +868,7 @@ function _regeneratorRuntime() {
1585
868
  function makeInvokeMethod(e, r, n) {
1586
869
  var o = h;
1587
870
  return function (i, a) {
1588
- if (o === f) throw new Error("Generator is already running");
871
+ if (o === f) throw Error("Generator is already running");
1589
872
  if (o === s) {
1590
873
  if ("throw" === i) throw a;
1591
874
  return {
@@ -1727,7 +1010,7 @@ function _regeneratorRuntime() {
1727
1010
  } else if (c) {
1728
1011
  if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
1729
1012
  } else {
1730
- if (!u) throw new Error("try statement without catch or finally");
1013
+ if (!u) throw Error("try statement without catch or finally");
1731
1014
  if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
1732
1015
  }
1733
1016
  }
@@ -1767,7 +1050,7 @@ function _regeneratorRuntime() {
1767
1050
  return o;
1768
1051
  }
1769
1052
  }
1770
- throw new Error("illegal catch attempt");
1053
+ throw Error("illegal catch attempt");
1771
1054
  },
1772
1055
  delegateYield: function (e, r, n) {
1773
1056
  return this.delegate = {
@@ -1779,150 +1062,112 @@ function _regeneratorRuntime() {
1779
1062
  }, e;
1780
1063
  }
1781
1064
 
1782
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
1065
+ function asyncGeneratorStep(n, t, e, r, o, a, c) {
1783
1066
  try {
1784
- var info = gen[key](arg);
1785
- var value = info.value;
1786
- } catch (error) {
1787
- reject(error);
1788
- return;
1789
- }
1790
- if (info.done) {
1791
- resolve(value);
1792
- } else {
1793
- Promise.resolve(value).then(_next, _throw);
1067
+ var i = n[a](c),
1068
+ u = i.value;
1069
+ } catch (n) {
1070
+ return void e(n);
1794
1071
  }
1072
+ i.done ? t(u) : Promise.resolve(u).then(r, o);
1795
1073
  }
1796
- function _asyncToGenerator(fn) {
1074
+ function _asyncToGenerator(n) {
1797
1075
  return function () {
1798
- var self = this,
1799
- args = arguments;
1800
- return new Promise(function (resolve, reject) {
1801
- var gen = fn.apply(self, args);
1802
- function _next(value) {
1803
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
1076
+ var t = this,
1077
+ e = arguments;
1078
+ return new Promise(function (r, o) {
1079
+ var a = n.apply(t, e);
1080
+ function _next(n) {
1081
+ asyncGeneratorStep(a, r, o, _next, _throw, "next", n);
1804
1082
  }
1805
- function _throw(err) {
1806
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
1083
+ function _throw(n) {
1084
+ asyncGeneratorStep(a, r, o, _next, _throw, "throw", n);
1807
1085
  }
1808
- _next(undefined);
1086
+ _next(void 0);
1809
1087
  });
1810
1088
  };
1811
1089
  }
1812
1090
 
1813
- function _classCallCheck(instance, Constructor) {
1814
- if (!(instance instanceof Constructor)) {
1815
- throw new TypeError("Cannot call a class as a function");
1816
- }
1091
+ function _classCallCheck(a, n) {
1092
+ if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function");
1817
1093
  }
1818
1094
 
1819
- function _defineProperties(target, props) {
1820
- for (var i = 0; i < props.length; i++) {
1821
- var descriptor = props[i];
1822
- descriptor.enumerable = descriptor.enumerable || false;
1823
- descriptor.configurable = true;
1824
- if ("value" in descriptor) descriptor.writable = true;
1825
- Object.defineProperty(target, toPropertyKey(descriptor.key), descriptor);
1095
+ function _defineProperties(e, r) {
1096
+ for (var t = 0; t < r.length; t++) {
1097
+ var o = r[t];
1098
+ o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o);
1826
1099
  }
1827
1100
  }
1828
- function _createClass(Constructor, protoProps, staticProps) {
1829
- if (protoProps) _defineProperties(Constructor.prototype, protoProps);
1830
- if (staticProps) _defineProperties(Constructor, staticProps);
1831
- Object.defineProperty(Constructor, "prototype", {
1832
- writable: false
1833
- });
1834
- return Constructor;
1101
+ function _createClass(e, r, t) {
1102
+ return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", {
1103
+ writable: !1
1104
+ }), e;
1835
1105
  }
1836
1106
 
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 = {};
1107
+ var ValCache = /*#__PURE__*/function () {
1108
+ function ValCache(client) {
1109
+ _classCallCheck(this, ValCache);
1110
+ this.client = client;
1873
1111
  this.drafts = {};
1874
1112
  this.schema = {};
1875
1113
  }
1876
- _createClass(ValStore, [{
1114
+ return _createClass(ValCache, [{
1877
1115
  key: "reloadPaths",
1878
1116
  value: function () {
1879
- 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;
1117
+ var _reloadPaths = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(paths) {
1118
+ var patchesResponse, patches, filteredPatches, treeRes, data, _i, _Object$keys, _data$modules, pathS, path;
1881
1119
  return _regeneratorRuntime().wrap(function _callee$(_context) {
1882
1120
  while (1) switch (_context.prev = _context.next) {
1883
1121
  case 0:
1884
1122
  _context.next = 2;
1885
- return this.api.getPatches({
1886
- omitPatches: true,
1887
- moduleFilePaths: paths
1123
+ return this.client("/patches/~", "GET", {
1124
+ query: {
1125
+ omit_patch: true,
1126
+ author: [],
1127
+ patch_id: [],
1128
+ module_file_path: paths
1129
+ }
1888
1130
  });
1889
1131
  case 2:
1890
- patches = _context.sent;
1891
- if (!fp.result.isErr(patches)) {
1132
+ patchesResponse = _context.sent;
1133
+ if (!(patchesResponse.status !== 200)) {
1892
1134
  _context.next = 6;
1893
1135
  break;
1894
1136
  }
1895
- console.error("Val: failed to get patches", patches.error);
1137
+ console.error("Val: failed to get patches", patchesResponse.json.message, patchesResponse.json);
1896
1138
  return _context.abrupt("return");
1897
1139
  case 6:
1898
- filteredPatches = Object.keys(patches.value.patches);
1899
- _context.next = 9;
1900
- return this.api.putTree({
1901
- patchIds: filteredPatches
1140
+ patches = patchesResponse.json;
1141
+ filteredPatches = Object.keys(patches);
1142
+ _context.next = 10;
1143
+ return this.client("/sources", "PUT", {
1144
+ query: {
1145
+ validate_sources: true,
1146
+ validate_all: false,
1147
+ validate_binary_files: false
1148
+ },
1149
+ path: undefined,
1150
+ body: {
1151
+ patchIds: filteredPatches
1152
+ }
1902
1153
  });
1903
- case 9:
1904
- data = _context.sent;
1905
- _context.next = 12;
1154
+ case 10:
1155
+ treeRes = _context.sent;
1156
+ _context.next = 13;
1906
1157
  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++) {
1158
+ case 13:
1159
+ if (treeRes.status === 200) {
1160
+ data = treeRes.json;
1161
+ for (_i = 0, _Object$keys = Object.keys(data.modules); _i < _Object$keys.length; _i++) {
1910
1162
  pathS = _Object$keys[_i];
1911
1163
  path = pathS;
1912
- this.drafts[path] = data.value.modules[path].source;
1164
+ 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
1165
  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
1166
  }
1922
1167
  } else {
1923
- console.error("Val: failed to reload paths", paths, data.error);
1168
+ console.error("Val: failed to reload paths", paths, treeRes.json);
1924
1169
  }
1925
- case 13:
1170
+ case 14:
1926
1171
  case "end":
1927
1172
  return _context.stop();
1928
1173
  }
@@ -1936,50 +1181,100 @@ var ValStore = /*#__PURE__*/function () {
1936
1181
  }, {
1937
1182
  key: "reset",
1938
1183
  value: function () {
1939
- 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;
1184
+ var _reset = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
1185
+ var patchesRes, allPatches, treeRes, initRes, _i2, _Object$keys2, _treeRes$json, pathS, path;
1941
1186
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
1942
1187
  while (1) switch (_context2.prev = _context2.next) {
1943
1188
  case 0:
1944
1189
  _context2.next = 2;
1945
- return this.api.getPatches();
1190
+ return this.client("/patches/~", "GET", {
1191
+ query: {
1192
+ omit_patch: true,
1193
+ author: [],
1194
+ patch_id: [],
1195
+ module_file_path: []
1196
+ }
1197
+ });
1946
1198
  case 2:
1947
- patches = _context2.sent;
1948
- if (!fp.result.isErr(patches)) {
1199
+ patchesRes = _context2.sent;
1200
+ if (!(patchesRes.status !== 200)) {
1949
1201
  _context2.next = 6;
1950
1202
  break;
1951
1203
  }
1952
- console.error("Val: failed to get patches", patches.error);
1953
- return _context2.abrupt("return");
1204
+ console.error("Val: failed to get patches", patchesRes.json);
1205
+ return _context2.abrupt("return", fp.result.err({
1206
+ errorType: "other",
1207
+ message: "Failed to get patches"
1208
+ }));
1954
1209
  case 6:
1955
- allPatches = Object.keys(patches.value.patches);
1210
+ allPatches = Object.keys(patchesRes.json.patches);
1956
1211
  _context2.next = 9;
1957
- return this.api.putTree({
1958
- patchIds: allPatches
1212
+ return this.client("/sources", "PUT", {
1213
+ path: undefined,
1214
+ query: {
1215
+ validate_sources: false,
1216
+ validate_all: false,
1217
+ validate_binary_files: false
1218
+ },
1219
+ body: {
1220
+ patchIds: allPatches
1221
+ }
1959
1222
  });
1960
1223
  case 9:
1961
- data = _context2.sent;
1224
+ treeRes = _context2.sent;
1962
1225
  _context2.next = 12;
1963
1226
  return this.initialize();
1964
1227
  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);
1228
+ initRes = _context2.sent;
1229
+ if (!fp.result.isErr(initRes)) {
1230
+ _context2.next = 16;
1231
+ break;
1981
1232
  }
1982
- case 13:
1233
+ console.error("Failed to initialize inside reset", initRes.error);
1234
+ return _context2.abrupt("return", fp.result.err({
1235
+ errorType: "other",
1236
+ message: initRes.error.message
1237
+ }));
1238
+ case 16:
1239
+ if (!(treeRes.status === 200)) {
1240
+ _context2.next = 21;
1241
+ break;
1242
+ }
1243
+ for (_i2 = 0, _Object$keys2 = Object.keys(treeRes.json.modules); _i2 < _Object$keys2.length; _i2++) {
1244
+ pathS = _Object$keys2[_i2];
1245
+ path = pathS;
1246
+ 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;
1247
+ this.emitEvent(path, this.drafts[path]);
1248
+ }
1249
+ return _context2.abrupt("return", fp.result.ok(undefined));
1250
+ case 21:
1251
+ if (!(treeRes.status === 400 && "type" in treeRes.json)) {
1252
+ _context2.next = 25;
1253
+ break;
1254
+ }
1255
+ return _context2.abrupt("return", fp.result.err({
1256
+ errorType: "patch-error",
1257
+ errors: Object.entries(treeRes.json.errors).flatMap(function (_ref) {
1258
+ var _ref2 = _slicedToArray(_ref, 2),
1259
+ moduleFilePath = _ref2[0],
1260
+ value = _ref2[1];
1261
+ return (value !== null && value !== void 0 ? value : []).map(function (item) {
1262
+ return {
1263
+ moduleFilePath: moduleFilePath,
1264
+ patchError: item.error.message,
1265
+ patchId: item.patchId,
1266
+ skipped: item.skipped
1267
+ };
1268
+ });
1269
+ })
1270
+ }));
1271
+ case 25:
1272
+ console.error("Val: failed to reset", treeRes.json);
1273
+ return _context2.abrupt("return", fp.result.err({
1274
+ errorType: "other",
1275
+ message: "Failed to reset " + JSON.stringify(treeRes.json)
1276
+ }));
1277
+ case 27:
1983
1278
  case "end":
1984
1279
  return _context2.stop();
1985
1280
  }
@@ -1993,9 +1288,11 @@ var ValStore = /*#__PURE__*/function () {
1993
1288
  }, {
1994
1289
  key: "getModule",
1995
1290
  value: function () {
1996
- var _getModule = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(path) {
1291
+ var _getModule = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(path) {
1997
1292
  var refetch,
1998
- data,
1293
+ treeRes,
1294
+ _treeRes$json2,
1295
+ _treeRes$json3,
1999
1296
  fetchedSource,
2000
1297
  schema,
2001
1298
  _args3 = arguments;
@@ -2013,29 +1310,35 @@ var ValStore = /*#__PURE__*/function () {
2013
1310
  }));
2014
1311
  case 3:
2015
1312
  _context3.next = 5;
2016
- return this.api.putTree({
2017
- treePath: path
1313
+ return this.client("/sources", "PUT", {
1314
+ path: path,
1315
+ body: {},
1316
+ query: {
1317
+ validate_sources: false,
1318
+ validate_all: false,
1319
+ validate_binary_files: false
1320
+ }
2018
1321
  });
2019
1322
  case 5:
2020
- data = _context3.sent;
2021
- if (!fp.result.isOk(data)) {
1323
+ treeRes = _context3.sent;
1324
+ if (!(treeRes.status === 200)) {
2022
1325
  _context3.next = 26;
2023
1326
  break;
2024
1327
  }
2025
- if (data.value.modules[path]) {
1328
+ if ((_treeRes$json2 = treeRes.json) !== null && _treeRes$json2 !== void 0 && (_treeRes$json2 = _treeRes$json2.modules) !== null && _treeRes$json2 !== void 0 && _treeRes$json2[path]) {
2026
1329
  _context3.next = 10;
2027
1330
  break;
2028
1331
  }
2029
1332
  console.error("Val: could not find the module", {
2030
- moduleIds: Object.keys(data.value.modules),
1333
+ moduleIds: Object.keys(treeRes.json.modules),
2031
1334
  moduleId: path,
2032
- data: data
1335
+ data: treeRes
2033
1336
  });
2034
1337
  return _context3.abrupt("return", fp.result.err({
2035
1338
  message: "Could not fetch data.\nCould not find the module:\n" + path + "\n\nVerify that the val.modules file includes this module."
2036
1339
  }));
2037
1340
  case 10:
2038
- fetchedSource = data.value.modules[path].source;
1341
+ 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
1342
  schema = this.schema[path];
2040
1343
  if (this.schema[path]) {
2041
1344
  _context3.next = 17;
@@ -2070,18 +1373,18 @@ var ValStore = /*#__PURE__*/function () {
2070
1373
  _context3.next = 33;
2071
1374
  break;
2072
1375
  case 26:
2073
- if (!(data.error.statusCode === 504)) {
1376
+ if (!(treeRes.status === 504)) {
2074
1377
  _context3.next = 31;
2075
1378
  break;
2076
1379
  }
2077
- console.error("Val: timeout", data.error);
1380
+ console.error("Val: timeout", treeRes.json);
2078
1381
  return _context3.abrupt("return", fp.result.err({
2079
1382
  message: "Timed out while fetching data. Try again later."
2080
1383
  }));
2081
1384
  case 31:
2082
- console.error("Val: failed to get module", data.error);
1385
+ console.error("Val: failed to get module", treeRes.json);
2083
1386
  return _context3.abrupt("return", fp.result.err({
2084
- message: "Could not fetch data. Verify that Val is correctly configured."
1387
+ message: "Could not fetch data. Verify that is correctly configured."
2085
1388
  }));
2086
1389
  case 33:
2087
1390
  case "end":
@@ -2095,78 +1398,140 @@ var ValStore = /*#__PURE__*/function () {
2095
1398
  return getModule;
2096
1399
  }()
2097
1400
  }, {
2098
- key: "applyPatch",
1401
+ key: "deletePatches",
2099
1402
  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;
1403
+ var _deletePatches = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4(patchIds) {
1404
+ var patchesRes;
2102
1405
  return _regeneratorRuntime().wrap(function _callee4$(_context4) {
2103
1406
  while (1) switch (_context4.prev = _context4.next) {
2104
1407
  case 0:
2105
1408
  _context4.next = 2;
2106
- return this.api.putTree({
2107
- treePath: path,
2108
- patchIds: patchIds,
2109
- addPatch: {
2110
- path: path,
2111
- patch: patch
1409
+ return this.client("/patches/~", "DELETE", {
1410
+ query: {
1411
+ id: patchIds
1412
+ }
1413
+ });
1414
+ case 2:
1415
+ patchesRes = _context4.sent;
1416
+ if (!(patchesRes.status === 200)) {
1417
+ _context4.next = 7;
1418
+ break;
1419
+ }
1420
+ return _context4.abrupt("return", fp.result.ok(patchesRes.json));
1421
+ case 7:
1422
+ console.error("Val: failed to delete patches", patchesRes.json);
1423
+ return _context4.abrupt("return", fp.result.err({
1424
+ message: patchesRes.json.message
1425
+ }));
1426
+ case 9:
1427
+ case "end":
1428
+ return _context4.stop();
1429
+ }
1430
+ }, _callee4, this);
1431
+ }));
1432
+ function deletePatches(_x3) {
1433
+ return _deletePatches.apply(this, arguments);
1434
+ }
1435
+ return deletePatches;
1436
+ }()
1437
+ }, {
1438
+ key: "applyPatch",
1439
+ value: function () {
1440
+ var _applyPatch = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5(path, patchIds, patch) {
1441
+ var treeRes, _treeRes$json4, newPatchIds, newPatchId, fetchedSource, _treeRes$json5;
1442
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
1443
+ while (1) switch (_context5.prev = _context5.next) {
1444
+ case 0:
1445
+ _context5.next = 2;
1446
+ return this.client("/sources", "PUT", {
1447
+ path: path,
1448
+ query: {
1449
+ validate_sources: false,
1450
+ validate_all: false,
1451
+ validate_binary_files: false
1452
+ },
1453
+ body: {
1454
+ patchIds: patchIds,
1455
+ addPatches: [{
1456
+ path: path,
1457
+ patch: patch
1458
+ }]
2112
1459
  }
2113
1460
  });
2114
1461
  case 2:
2115
- data = _context4.sent;
2116
- if (!fp.result.isOk(data)) {
2117
- _context4.next = 20;
1462
+ treeRes = _context5.sent;
1463
+ if (!(treeRes.status === 200)) {
1464
+ _context5.next = 20;
2118
1465
  break;
2119
1466
  }
2120
- newPatchId = data.value.newPatchId;
2121
- if (newPatchId) {
2122
- _context4.next = 8;
1467
+ newPatchIds = treeRes.json.newPatchIds;
1468
+ if (newPatchIds) {
1469
+ _context5.next = 8;
2123
1470
  break;
2124
1471
  }
2125
- console.error("Val: could create patch", data);
2126
- return _context4.abrupt("return", fp.result.err({
2127
- message: "Val: could not create patch."
1472
+ console.error("Val: could create patch", treeRes);
1473
+ return _context5.abrupt("return", fp.result.err({
1474
+ errorType: "other",
1475
+ message: "Val: could not create patch"
2128
1476
  }));
2129
1477
  case 8:
2130
- fetchedSource = data.value.modules[path].source;
1478
+ newPatchId = newPatchIds[0];
1479
+ 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
1480
  if (!(fetchedSource !== undefined)) {
2132
- _context4.next = 16;
1481
+ _context5.next = 16;
2133
1482
  break;
2134
1483
  }
2135
1484
  this.drafts[path] = fetchedSource;
2136
1485
  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({
1486
+ return _context5.abrupt("return", fp.result.ok({
2145
1487
  newPatchId: newPatchId,
2146
1488
  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) || []
1489
+ 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
1490
  })
2149
1491
  }));
2150
1492
  case 16:
2151
1493
  console.error("Val: could not patch");
2152
- return _context4.abrupt("return", fp.result.err({
1494
+ return _context5.abrupt("return", fp.result.err({
1495
+ errorType: "other",
2153
1496
  message: "Val: could not fetch data. Verify that the module exists."
2154
1497
  }));
2155
1498
  case 18:
2156
- _context4.next = 22;
1499
+ _context5.next = 26;
2157
1500
  break;
2158
1501
  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."
1502
+ if (!(treeRes.status === 400 && "type" in treeRes.json)) {
1503
+ _context5.next = 24;
1504
+ break;
1505
+ }
1506
+ return _context5.abrupt("return", fp.result.err({
1507
+ errorType: "patch-error",
1508
+ errors: Object.entries(treeRes.json.errors).flatMap(function (_ref3) {
1509
+ var _ref4 = _slicedToArray(_ref3, 2),
1510
+ moduleFilePath = _ref4[0],
1511
+ value = _ref4[1];
1512
+ return (value !== null && value !== void 0 ? value : []).map(function (item) {
1513
+ return {
1514
+ moduleFilePath: moduleFilePath,
1515
+ patchError: item.error.message,
1516
+ patchId: item.patchId,
1517
+ skipped: item.skipped
1518
+ };
1519
+ });
1520
+ })
2162
1521
  }));
2163
- case 22:
1522
+ case 24:
1523
+ console.error("Val: failed to get module", treeRes.json);
1524
+ return _context5.abrupt("return", fp.result.err({
1525
+ errorType: "other",
1526
+ message: "Val: could not fetch data. Verify that is correctly configured."
1527
+ }));
1528
+ case 26:
2164
1529
  case "end":
2165
- return _context4.stop();
1530
+ return _context5.stop();
2166
1531
  }
2167
- }, _callee4, this);
1532
+ }, _callee5, this);
2168
1533
  }));
2169
- function applyPatch(_x3, _x4, _x5) {
1534
+ function applyPatch(_x4, _x5, _x6) {
2170
1535
  return _applyPatch.apply(this, arguments);
2171
1536
  }
2172
1537
  return applyPatch;
@@ -2186,78 +1551,1008 @@ var ValStore = /*#__PURE__*/function () {
2186
1551
  }, {
2187
1552
  key: "initialize",
2188
1553
  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) {
1554
+ var _initialize = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
1555
+ var schemaRes, paths, _i3, _arr, moduleId, schema, msg;
1556
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
1557
+ while (1) switch (_context6.prev = _context6.next) {
2193
1558
  case 0:
2194
- _context5.next = 2;
2195
- return this.api.getSchema({});
1559
+ _context6.next = 2;
1560
+ return this.client("/schema", "GET", {});
2196
1561
  case 2:
2197
- data = _context5.sent;
2198
- if (!fp.result.isOk(data)) {
2199
- _context5.next = 9;
1562
+ schemaRes = _context6.sent;
1563
+ if (!(schemaRes.status === 200)) {
1564
+ _context6.next = 9;
2200
1565
  break;
2201
1566
  }
2202
1567
  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];
1568
+ for (_i3 = 0, _arr = Object.keys(schemaRes.json.schemas); _i3 < _arr.length; _i3++) {
1569
+ moduleId = _arr[_i3];
1570
+ schema = schemaRes.json.schemas[moduleId];
2206
1571
  if (schema) {
2207
1572
  paths.push(moduleId);
2208
1573
  this.schema[moduleId] = schema;
2209
1574
  }
2210
1575
  }
2211
- return _context5.abrupt("return", fp.result.ok(paths));
1576
+ return _context6.abrupt("return", fp.result.ok(paths));
2212
1577
  case 9:
2213
1578
  msg = "Failed to fetch content. ";
2214
- if (data.error.statusCode === 401) {
1579
+ if (schemaRes.status === 401) {
2215
1580
  msg += "Authorization failed - check that you are logged in.";
2216
1581
  } else {
2217
- msg += "Get a developer to verify that Val is correctly setup.";
1582
+ msg += "Get a developer to verify that is correctly setup.";
2218
1583
  }
2219
- return _context5.abrupt("return", fp.result.err({
1584
+ return _context6.abrupt("return", fp.result.err({
2220
1585
  message: msg,
2221
1586
  details: {
2222
- fetchError: data.error
1587
+ fetchError: schemaRes.json
2223
1588
  }
2224
1589
  }));
2225
1590
  case 12:
2226
1591
  case "end":
2227
- return _context5.stop();
1592
+ return _context6.stop();
2228
1593
  }
2229
- }, _callee5, this);
1594
+ }, _callee6, this);
2230
1595
  }));
2231
1596
  function initialize() {
2232
1597
  return _initialize.apply(this, arguments);
2233
1598
  }
2234
1599
  return initialize;
2235
1600
  }()
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
1601
  }]);
2253
- return ValStore;
2254
1602
  }();
2255
- function createSubscriberId(paths) {
2256
- return paths.slice().sort().join("&");
1603
+
1604
+ var JSONValueT = zod.z.lazy(function () {
1605
+ return zod.z.union([zod.z.string(), zod.z.number(), zod.z["boolean"](), zod.z["null"](), zod.z.array(JSONValueT), zod.z.record(JSONValueT)]);
1606
+ });
1607
+ var OperationT = zod.z.discriminatedUnion("op", [zod.z.object({
1608
+ op: zod.z.literal("add"),
1609
+ path: zod.z.array(zod.z.string()),
1610
+ value: JSONValueT
1611
+ }).strict(), zod.z.object({
1612
+ op: zod.z.literal("remove"),
1613
+ path: zod.z.array(zod.z.string()).nonempty()
1614
+ }).strict(), zod.z.object({
1615
+ op: zod.z.literal("replace"),
1616
+ path: zod.z.array(zod.z.string()),
1617
+ value: JSONValueT
1618
+ }).strict(), zod.z.object({
1619
+ op: zod.z.literal("move"),
1620
+ from: zod.z.array(zod.z.string()).nonempty(),
1621
+ path: zod.z.array(zod.z.string())
1622
+ }).strict(), zod.z.object({
1623
+ op: zod.z.literal("copy"),
1624
+ from: zod.z.array(zod.z.string()),
1625
+ path: zod.z.array(zod.z.string())
1626
+ }).strict(), zod.z.object({
1627
+ op: zod.z.literal("test"),
1628
+ path: zod.z.array(zod.z.string()),
1629
+ value: JSONValueT
1630
+ }).strict(), zod.z.object({
1631
+ op: zod.z.literal("file"),
1632
+ path: zod.z.array(zod.z.string()),
1633
+ filePath: zod.z.string(),
1634
+ nestedFilePath: zod.z.array(zod.z.string()).optional(),
1635
+ value: zod.z.union([zod.z.string(), zod.z.object({
1636
+ sha256: zod.z.string()
1637
+ })])
1638
+ }).strict()]);
1639
+ var Patch = zod.z.array(OperationT);
1640
+
1641
+ var SourcePath = zod.z.string().transform(function (path) {
1642
+ return path;
1643
+ });
1644
+
1645
+ var SerializedStringSchema = zod.z.object({
1646
+ type: zod.z.literal("string"),
1647
+ options: zod.z.object({
1648
+ maxLength: zod.z.number().optional(),
1649
+ minLength: zod.z.number().optional(),
1650
+ regexp: zod.z.object({
1651
+ source: zod.z.string(),
1652
+ flags: zod.z.string()
1653
+ }).optional()
1654
+ }).optional(),
1655
+ opt: zod.z["boolean"](),
1656
+ raw: zod.z["boolean"]()
1657
+ });
1658
+ var SerializedLiteralSchema = zod.z.object({
1659
+ type: zod.z.literal("literal"),
1660
+ value: zod.z.string(),
1661
+ opt: zod.z["boolean"]()
1662
+ });
1663
+ var SerializedBooleanSchema = zod.z.object({
1664
+ type: zod.z.literal("boolean"),
1665
+ opt: zod.z["boolean"]()
1666
+ });
1667
+ var SerializedNumberSchema = zod.z.object({
1668
+ type: zod.z.literal("number"),
1669
+ options: zod.z.object({
1670
+ max: zod.z.number().optional(),
1671
+ min: zod.z.number().optional()
1672
+ }).optional(),
1673
+ opt: zod.z["boolean"]()
1674
+ });
1675
+ var SerializedObjectSchema = zod.z.lazy(function () {
1676
+ return zod.z.object({
1677
+ type: zod.z.literal("object"),
1678
+ items: zod.z.record(SerializedSchema),
1679
+ opt: zod.z["boolean"]()
1680
+ });
1681
+ });
1682
+ var SerializedArraySchema = zod.z.lazy(function () {
1683
+ return zod.z.object({
1684
+ type: zod.z.literal("array"),
1685
+ item: SerializedSchema,
1686
+ opt: zod.z["boolean"]()
1687
+ });
1688
+ });
1689
+ var SerializedUnionSchema = zod.z.lazy(function () {
1690
+ return zod.z.union([zod.z.object({
1691
+ type: zod.z.literal("union"),
1692
+ key: SerializedLiteralSchema,
1693
+ items: zod.z.array(SerializedLiteralSchema),
1694
+ opt: zod.z["boolean"]()
1695
+ }), zod.z.object({
1696
+ type: zod.z.literal("union"),
1697
+ key: zod.z.string(),
1698
+ items: zod.z.array(SerializedObjectSchema),
1699
+ opt: zod.z["boolean"]()
1700
+ })]);
1701
+ });
1702
+ var RichTextOptions = zod.z.object({
1703
+ style: zod.z.object({
1704
+ bold: zod.z["boolean"]().optional(),
1705
+ italic: zod.z["boolean"]().optional(),
1706
+ lineThrough: zod.z["boolean"]().optional()
1707
+ }).optional(),
1708
+ block: zod.z.object({
1709
+ h1: zod.z["boolean"]().optional(),
1710
+ h2: zod.z["boolean"]().optional(),
1711
+ h3: zod.z["boolean"]().optional(),
1712
+ h4: zod.z["boolean"]().optional(),
1713
+ h5: zod.z["boolean"]().optional(),
1714
+ h6: zod.z["boolean"]().optional(),
1715
+ ul: zod.z["boolean"]().optional(),
1716
+ ol: zod.z["boolean"]().optional()
1717
+ }).optional(),
1718
+ inline: zod.z.object({
1719
+ a: zod.z["boolean"]().optional(),
1720
+ img: zod.z["boolean"]().optional()
1721
+ }).optional()
1722
+ });
1723
+ var SerializedRichTextSchema = zod.z.object({
1724
+ type: zod.z.literal("richtext"),
1725
+ options: RichTextOptions.optional(),
1726
+ opt: zod.z["boolean"]()
1727
+ });
1728
+ var SerializedRecordSchema = zod.z.lazy(function () {
1729
+ return zod.z.object({
1730
+ type: zod.z.literal("record"),
1731
+ item: SerializedSchema,
1732
+ opt: zod.z["boolean"]()
1733
+ });
1734
+ });
1735
+ var SerializedKeyOfSchema = zod.z.lazy(function () {
1736
+ return zod.z.object({
1737
+ type: zod.z.literal("keyOf"),
1738
+ path: SourcePath,
1739
+ schema: SerializedSchema,
1740
+ values: zod.z.union([zod.z.literal("string"), zod.z.array(zod.z.string())]),
1741
+ opt: zod.z["boolean"]()
1742
+ });
1743
+ });
1744
+ var FileOptions = zod.z.object({
1745
+ accept: zod.z.string().optional()
1746
+ });
1747
+ var SerializedFileSchema = zod.z.object({
1748
+ type: zod.z.literal("file"),
1749
+ options: FileOptions.optional(),
1750
+ opt: zod.z["boolean"]()
1751
+ });
1752
+ var SerializedDateSchema = zod.z.object({
1753
+ type: zod.z.literal("date"),
1754
+ opt: zod.z["boolean"]()
1755
+ });
1756
+ var ImageOptions = zod.z.object({
1757
+ ext: zod.z.union([zod.z.tuple([zod.z.literal("jpg")]), zod.z.tuple([zod.z.literal("webp")])]).optional(),
1758
+ directory: zod.z.string().optional(),
1759
+ prefix: zod.z.string().optional(),
1760
+ accept: zod.z.string().optional()
1761
+ });
1762
+ var SerializedImageSchema = zod.z.object({
1763
+ type: zod.z.literal("image"),
1764
+ options: ImageOptions.optional(),
1765
+ opt: zod.z["boolean"]()
1766
+ });
1767
+ var SerializedSchema = zod.z.union([SerializedStringSchema, SerializedLiteralSchema, SerializedBooleanSchema, SerializedNumberSchema, SerializedObjectSchema, SerializedArraySchema, SerializedUnionSchema, SerializedRichTextSchema, SerializedRecordSchema, SerializedKeyOfSchema, SerializedFileSchema, SerializedDateSchema, SerializedImageSchema]);
1768
+
1769
+ var PatchId = zod.z.string().refine(function (_id) {
1770
+ return true;
1771
+ } // TODO:
1772
+ );
1773
+ var ModuleFilePath = zod.z.string().refine(function (_path) {
1774
+ return true;
1775
+ } // TODO:
1776
+ );
1777
+ var ValConfig = zod.z.object({
1778
+ project: zod.z.string().optional(),
1779
+ root: zod.z.string().optional(),
1780
+ files: zod.z.object({
1781
+ directory: zod.z.string() // TODO: validate that it is prefixed by /public/
1782
+ }).optional(),
1783
+ gitCommit: zod.z.string().optional(),
1784
+ gitBranch: zod.z.string().optional()
1785
+ });
1786
+ 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")]);
1787
+ var ValidationError = zod.z.object({
1788
+ message: zod.z.string(),
1789
+ value: zod.z.unknown().optional(),
1790
+ fatal: zod.z["boolean"]().optional(),
1791
+ fixes: zod.z.array(ValidationFixZ).optional()
1792
+ });
1793
+ var notFoundResponse = zod.z.object({
1794
+ status: zod.z.literal(401),
1795
+ json: zod.z.object({
1796
+ message: zod.z.string()
1797
+ })
1798
+ });
1799
+ var GenericError = zod.z.object({
1800
+ message: zod.z.string()
1801
+ });
1802
+ var ModulesError = zod.z.object({
1803
+ message: zod.z.string(),
1804
+ path: ModuleFilePath.optional()
1805
+ });
1806
+ zod.z.union([zod.z.literal("val_session"), zod.z.literal("val_enable"), zod.z.literal("val_state")]);
1807
+ var enableCookieValue = zod.z.object({
1808
+ value: zod.z.literal("true"),
1809
+ options: zod.z.object({
1810
+ httpOnly: zod.z.literal(false),
1811
+ sameSite: zod.z.literal("lax")
1812
+ })
1813
+ });
1814
+ var Api = {
1815
+ "/draft/enable": {
1816
+ GET: {
1817
+ req: {
1818
+ query: {
1819
+ redirect_to: zod.z.string().optional()
1820
+ },
1821
+ cookies: _defineProperty({}, VAL_SESSION_COOKIE, zod.z.string().optional())
1822
+ },
1823
+ res: zod.z.union([zod.z.object({
1824
+ status: zod.z.literal(401),
1825
+ json: GenericError
1826
+ }), zod.z.object({
1827
+ status: zod.z.literal(302),
1828
+ redirectTo: zod.z.string()
1829
+ }), zod.z.object({
1830
+ status: zod.z.literal(400),
1831
+ json: zod.z.object({
1832
+ message: zod.z.string()
1833
+ })
1834
+ })])
1835
+ }
1836
+ },
1837
+ "/draft/disable": {
1838
+ GET: {
1839
+ req: {
1840
+ query: {
1841
+ redirect_to: zod.z.string().optional()
1842
+ },
1843
+ cookies: _defineProperty({}, VAL_SESSION_COOKIE, zod.z.string().optional())
1844
+ },
1845
+ res: zod.z.union([zod.z.object({
1846
+ status: zod.z.literal(401),
1847
+ json: GenericError
1848
+ }), zod.z.object({
1849
+ status: zod.z.literal(302),
1850
+ redirectTo: zod.z.string()
1851
+ }), zod.z.object({
1852
+ status: zod.z.literal(400),
1853
+ json: zod.z.object({
1854
+ message: zod.z.string()
1855
+ })
1856
+ })])
1857
+ }
1858
+ },
1859
+ "/draft/stat": {
1860
+ GET: {
1861
+ req: {
1862
+ cookies: _defineProperty({}, VAL_SESSION_COOKIE, zod.z.string().optional())
1863
+ },
1864
+ res: zod.z.union([zod.z.object({
1865
+ status: zod.z.literal(401),
1866
+ json: GenericError
1867
+ }), zod.z.object({
1868
+ status: zod.z.literal(200),
1869
+ json: zod.z.object({
1870
+ draftMode: zod.z["boolean"]()
1871
+ })
1872
+ })])
1873
+ }
1874
+ },
1875
+ "/enable": {
1876
+ GET: {
1877
+ req: {
1878
+ query: {
1879
+ redirect_to: zod.z.string().optional()
1880
+ },
1881
+ cookies: _defineProperty({}, VAL_SESSION_COOKIE, zod.z.string().optional())
1882
+ },
1883
+ res: zod.z.union([zod.z.object({
1884
+ status: zod.z.literal(401),
1885
+ json: GenericError
1886
+ }), zod.z.object({
1887
+ status: zod.z.literal(302),
1888
+ redirectTo: zod.z.string(),
1889
+ cookies: zod.z.object(_defineProperty(_defineProperty({}, VAL_ENABLE_COOKIE_NAME, enableCookieValue), VAL_STATE_COOKIE, zod.z.object({
1890
+ value: zod.z.string(),
1891
+ options: zod.z.object({
1892
+ httpOnly: zod.z.literal(true),
1893
+ sameSite: zod.z.literal("lax"),
1894
+ expires: zod.z["instanceof"](Date)
1895
+ })
1896
+ })))
1897
+ }), zod.z.object({
1898
+ status: zod.z.literal(302),
1899
+ redirectTo: zod.z.string(),
1900
+ cookies: zod.z.object(_defineProperty({}, VAL_ENABLE_COOKIE_NAME, enableCookieValue))
1901
+ }), zod.z.object({
1902
+ status: zod.z.literal(400),
1903
+ json: zod.z.object({
1904
+ message: zod.z.string()
1905
+ })
1906
+ })])
1907
+ }
1908
+ },
1909
+ "/disable": {
1910
+ GET: {
1911
+ req: {
1912
+ query: {
1913
+ redirect_to: zod.z.string().optional()
1914
+ },
1915
+ cookies: _defineProperty({}, VAL_SESSION_COOKIE, zod.z.string().optional())
1916
+ },
1917
+ res: zod.z.union([zod.z.object({
1918
+ status: zod.z.literal(401),
1919
+ json: GenericError
1920
+ }), zod.z.object({
1921
+ status: zod.z.literal(302),
1922
+ redirectTo: zod.z.string(),
1923
+ cookies: zod.z.object(_defineProperty({}, VAL_ENABLE_COOKIE_NAME, zod.z.object({
1924
+ value: zod.z.literal("false")
1925
+ })))
1926
+ }), zod.z.object({
1927
+ status: zod.z.literal(400),
1928
+ json: zod.z.object({
1929
+ message: zod.z.string()
1930
+ })
1931
+ })])
1932
+ }
1933
+ },
1934
+ "/authorize": {
1935
+ GET: {
1936
+ req: {
1937
+ query: {
1938
+ redirect_to: zod.z.string().optional()
1939
+ }
1940
+ },
1941
+ res: zod.z.union([zod.z.object({
1942
+ status: zod.z.literal(302),
1943
+ redirectTo: zod.z.string(),
1944
+ cookies: zod.z.object(_defineProperty(_defineProperty({}, VAL_ENABLE_COOKIE_NAME, enableCookieValue), VAL_STATE_COOKIE, zod.z.object({
1945
+ value: zod.z.string(),
1946
+ options: zod.z.object({
1947
+ httpOnly: zod.z.literal(true),
1948
+ sameSite: zod.z.literal("lax"),
1949
+ expires: zod.z["instanceof"](Date)
1950
+ })
1951
+ })))
1952
+ }), zod.z.object({
1953
+ status: zod.z.literal(400),
1954
+ json: zod.z.object({
1955
+ message: zod.z.string()
1956
+ })
1957
+ })])
1958
+ }
1959
+ },
1960
+ "/callback": {
1961
+ GET: {
1962
+ req: {
1963
+ query: {
1964
+ code: zod.z.string().optional(),
1965
+ state: zod.z.string().optional()
1966
+ },
1967
+ cookies: _defineProperty({}, VAL_STATE_COOKIE, zod.z.string())
1968
+ },
1969
+ res: zod.z.object({
1970
+ status: zod.z.literal(302),
1971
+ redirectTo: zod.z.string(),
1972
+ cookies: zod.z.object(_defineProperty(_defineProperty(_defineProperty({}, VAL_STATE_COOKIE, zod.z.object({
1973
+ value: zod.z.literal(null)
1974
+ })), VAL_ENABLE_COOKIE_NAME, enableCookieValue.optional()), VAL_SESSION_COOKIE, zod.z.object({
1975
+ value: zod.z.string(),
1976
+ options: zod.z.object({
1977
+ httpOnly: zod.z.literal(true),
1978
+ sameSite: zod.z.literal("strict"),
1979
+ path: zod.z.string(),
1980
+ secure: zod.z.literal(true),
1981
+ expires: zod.z["instanceof"](Date)
1982
+ }).optional()
1983
+ }).optional()))
1984
+ })
1985
+ }
1986
+ },
1987
+ "/session": {
1988
+ GET: {
1989
+ req: {
1990
+ cookies: {
1991
+ val_session: zod.z.string().optional()
1992
+ }
1993
+ },
1994
+ res: zod.z.union([zod.z.object({
1995
+ status: zod.z.literal(200),
1996
+ json: zod.z.object({
1997
+ mode: zod.z.union([zod.z.literal("local"), zod.z.literal("proxy")]),
1998
+ enabled: zod.z["boolean"]()
1999
+ })
2000
+ }), zod.z.object({
2001
+ status: zod.z.union([
2002
+ // TODO: Remove the ones we don't need.
2003
+ zod.z.literal(400), zod.z.literal(401), zod.z.literal(403), zod.z.literal(404), zod.z.literal(500), zod.z.literal(501)]),
2004
+ json: zod.z.object({
2005
+ message: zod.z.string()
2006
+ })
2007
+ }), zod.z.object({
2008
+ status: zod.z.literal(401),
2009
+ json: zod.z.object({
2010
+ message: zod.z.string(),
2011
+ details: zod.z.union([zod.z.string(), zod.z.object({
2012
+ reason: zod.z.string()
2013
+ }), zod.z.object({
2014
+ sub: zod.z.string(),
2015
+ exp: zod.z.number(),
2016
+ token: zod.z.string(),
2017
+ org: zod.z.string(),
2018
+ project: zod.z.string()
2019
+ })])
2020
+ })
2021
+ }), zod.z.object({
2022
+ status: zod.z.literal(500),
2023
+ json: zod.z.object({
2024
+ message: zod.z.string()
2025
+ })
2026
+ })])
2027
+ }
2028
+ },
2029
+ "/logout": {
2030
+ GET: {
2031
+ req: {},
2032
+ // TODO fix req types
2033
+ res: zod.z.object({
2034
+ status: zod.z.literal(200),
2035
+ cookies: zod.z.object(_defineProperty(_defineProperty({}, VAL_SESSION_COOKIE, zod.z.object({
2036
+ value: zod.z.literal(null)
2037
+ })), VAL_STATE_COOKIE, zod.z.object({
2038
+ value: zod.z.literal(null)
2039
+ })))
2040
+ })
2041
+ }
2042
+ },
2043
+ "/stat": {
2044
+ POST: {
2045
+ req: {
2046
+ body: zod.z.object({
2047
+ schemaSha: zod.z.string(),
2048
+ baseSha: zod.z.string(),
2049
+ patches: zod.z.array(zod.z.string()).optional()
2050
+ }).nullable(),
2051
+ cookies: {
2052
+ val_session: zod.z.string().optional()
2053
+ }
2054
+ },
2055
+ res: zod.z.union([zod.z.object({
2056
+ status: zod.z.literal(401),
2057
+ json: GenericError
2058
+ }), zod.z.object({
2059
+ status: zod.z.literal(500),
2060
+ json: GenericError
2061
+ }), zod.z.object({
2062
+ status: zod.z.literal(200),
2063
+ json: zod.z.union([zod.z.object({
2064
+ type: zod.z.union([zod.z.literal("request-again"), zod.z.literal("no-change"), zod.z.literal("did-change")]),
2065
+ baseSha: zod.z.string(),
2066
+ schemaSha: zod.z.string(),
2067
+ patches: zod.z.array(PatchId),
2068
+ config: ValConfig
2069
+ }), zod.z.object({
2070
+ type: zod.z.literal("use-websocket"),
2071
+ url: zod.z.string(),
2072
+ nonce: zod.z.string(),
2073
+ baseSha: zod.z.string(),
2074
+ schemaSha: zod.z.string(),
2075
+ commitSha: zod.z.string(),
2076
+ patches: zod.z.array(PatchId),
2077
+ config: ValConfig
2078
+ })])
2079
+ })])
2080
+ }
2081
+ },
2082
+ "/patches/~": {
2083
+ DELETE: {
2084
+ req: {
2085
+ query: {
2086
+ id: zod.z.array(PatchId)
2087
+ },
2088
+ cookies: {
2089
+ val_session: zod.z.string().optional()
2090
+ }
2091
+ },
2092
+ res: zod.z.union([notFoundResponse, zod.z.object({
2093
+ status: zod.z.literal(500),
2094
+ json: zod.z.object({
2095
+ message: zod.z.string(),
2096
+ details: zod.z.record(PatchId, GenericError)
2097
+ })
2098
+ }), zod.z.object({
2099
+ status: zod.z.literal(200),
2100
+ json: zod.z.array(PatchId)
2101
+ })])
2102
+ },
2103
+ GET: {
2104
+ req: {
2105
+ query: {
2106
+ author: zod.z.array(zod.z.string()).optional(),
2107
+ patch_id: zod.z.array(PatchId).optional(),
2108
+ module_file_path: zod.z.array(ModuleFilePath).optional(),
2109
+ omit_patch: zod.z["boolean"]().optional() // TODO: rename! we mean that we are not including the actual patch / operations in the response
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(500),
2117
+ json: zod.z.object({
2118
+ message: zod.z.string(),
2119
+ details: zod.z.record(PatchId, GenericError)
2120
+ })
2121
+ }), zod.z.object({
2122
+ status: zod.z.literal(200),
2123
+ json: zod.z.object({
2124
+ patches: zod.z.record(PatchId, zod.z.object({
2125
+ path: ModuleFilePath,
2126
+ patch: Patch.optional(),
2127
+ createdAt: zod.z.string(),
2128
+ authorId: zod.z.string().nullable(),
2129
+ appliedAt: zod.z.object({
2130
+ baseSha: zod.z.string(),
2131
+ git: zod.z.object({
2132
+ commitSha: zod.z.string()
2133
+ }).optional(),
2134
+ timestamp: zod.z.string()
2135
+ }).nullable()
2136
+ })),
2137
+ error: GenericError.optional(),
2138
+ errors: zod.z.record(PatchId, GenericError).optional()
2139
+ })
2140
+ })])
2141
+ }
2142
+ },
2143
+ "/schema": {
2144
+ GET: {
2145
+ req: {
2146
+ cookies: {
2147
+ val_session: zod.z.string().optional()
2148
+ }
2149
+ },
2150
+ res: zod.z.union([notFoundResponse, zod.z.object({
2151
+ status: zod.z.literal(500),
2152
+ json: zod.z.object({
2153
+ message: zod.z.string(),
2154
+ details: zod.z.array(ModulesError)
2155
+ })
2156
+ }), zod.z.object({
2157
+ status: zod.z.literal(500),
2158
+ json: zod.z.object({
2159
+ message: zod.z.string(),
2160
+ details: zod.z.array(GenericError)
2161
+ })
2162
+ }), zod.z.object({
2163
+ status: zod.z.literal(200),
2164
+ json: zod.z.object({
2165
+ schemaSha: zod.z.string(),
2166
+ schemas: zod.z.record(ModuleFilePath, SerializedSchema)
2167
+ })
2168
+ })])
2169
+ }
2170
+ },
2171
+ "/sources": {
2172
+ PUT: {
2173
+ req: {
2174
+ path: zod.z.string().optional(),
2175
+ body: zod.z.object({
2176
+ patchIds: zod.z.array(PatchId).optional(),
2177
+ addPatches: zod.z.array(zod.z.object({
2178
+ path: ModuleFilePath,
2179
+ patch: Patch
2180
+ })).optional()
2181
+ }).optional(),
2182
+ query: {
2183
+ validate_all: zod.z["boolean"]().optional(),
2184
+ validate_sources: zod.z["boolean"]().optional(),
2185
+ validate_binary_files: zod.z["boolean"]().optional()
2186
+ },
2187
+ cookies: {
2188
+ val_session: zod.z.string().optional()
2189
+ }
2190
+ },
2191
+ res: zod.z.union([notFoundResponse, zod.z.object({
2192
+ status: zod.z.literal(401),
2193
+ json: GenericError
2194
+ }), zod.z.object({
2195
+ status: zod.z.literal(409),
2196
+ // conflict: i.e. not a head of patches
2197
+ json: GenericError
2198
+ }), zod.z.object({
2199
+ status: zod.z.literal(500),
2200
+ json: zod.z.object({
2201
+ message: zod.z.string(),
2202
+ details: zod.z.union([zod.z.array(ModulesError), GenericError])
2203
+ })
2204
+ }), zod.z.object({
2205
+ status: zod.z.literal(400),
2206
+ json: zod.z.object({
2207
+ message: zod.z.string(),
2208
+ details: zod.z.array(ModulesError)
2209
+ })
2210
+ }), zod.z.object({
2211
+ status: zod.z.literal(400),
2212
+ json: zod.z.object({
2213
+ type: zod.z.literal("patch-error"),
2214
+ message: zod.z.string(),
2215
+ schemaSha: zod.z.string(),
2216
+ modules: zod.z.record(ModuleFilePath, zod.z.object({
2217
+ source: zod.z.any(),
2218
+ //.optional(), // TODO: Json zod type
2219
+ patches: zod.z.object({
2220
+ applied: zod.z.array(PatchId),
2221
+ skipped: zod.z.array(PatchId).optional(),
2222
+ errors: zod.z.record(PatchId, GenericError).optional()
2223
+ }).optional(),
2224
+ validationErrors: zod.z.record(SourcePath, zod.z.array(ValidationError)).optional()
2225
+ })),
2226
+ errors: zod.z.record(ModuleFilePath, zod.z.array(zod.z.object({
2227
+ patchId: PatchId,
2228
+ skipped: zod.z["boolean"](),
2229
+ error: GenericError
2230
+ })))
2231
+ })
2232
+ }), zod.z.object({
2233
+ status: zod.z.literal(200),
2234
+ json: zod.z.object({
2235
+ schemaSha: zod.z.string(),
2236
+ modules: zod.z.record(ModuleFilePath, zod.z.object({
2237
+ source: zod.z.any(),
2238
+ //.optional(), // TODO: Json zod type
2239
+ patches: zod.z.object({
2240
+ applied: zod.z.array(PatchId),
2241
+ skipped: zod.z.array(PatchId).optional(),
2242
+ errors: zod.z.record(PatchId, GenericError).optional()
2243
+ }).optional(),
2244
+ validationErrors: zod.z.record(SourcePath, zod.z.array(ValidationError)).optional()
2245
+ })),
2246
+ newPatchIds: zod.z.array(PatchId).optional()
2247
+ })
2248
+ })])
2249
+ }
2250
+ },
2251
+ "/save": {
2252
+ POST: {
2253
+ req: {
2254
+ body: zod.z.object({
2255
+ patchIds: zod.z.array(PatchId)
2256
+ }),
2257
+ cookies: {
2258
+ val_session: zod.z.string().optional()
2259
+ }
2260
+ },
2261
+ res: zod.z.union([notFoundResponse, zod.z.object({
2262
+ status: zod.z.literal(200),
2263
+ json: zod.z.object({}) // TODO:
2264
+ }), zod.z.object({
2265
+ status: zod.z.literal(409),
2266
+ json: zod.z.object({
2267
+ message: zod.z.string(),
2268
+ isNotFastForward: zod.z.literal(true)
2269
+ })
2270
+ }), zod.z.object({
2271
+ status: zod.z.literal(400),
2272
+ json: zod.z.object({
2273
+ message: zod.z.string(),
2274
+ details: zod.z.union([zod.z.object({
2275
+ sourceFilePatchErrors: zod.z.record(ModuleFilePath, zod.z.array(GenericError)),
2276
+ binaryFilePatchErrors: zod.z.record(GenericError)
2277
+ }), zod.z.array(GenericError)])
2278
+ })
2279
+ })])
2280
+ }
2281
+ },
2282
+ "/files": {
2283
+ GET: {
2284
+ req: {
2285
+ path: zod.z.string(),
2286
+ query: {
2287
+ patch_id: PatchId.optional()
2288
+ }
2289
+ },
2290
+ res: zod.z.union([zod.z.object({
2291
+ status: zod.z.literal(200),
2292
+ body: zod.z["instanceof"](ReadableStream)
2293
+ }), zod.z.object({
2294
+ status: zod.z.literal(404),
2295
+ json: zod.z.object({
2296
+ message: zod.z.string()
2297
+ })
2298
+ })])
2299
+ }
2300
+ }
2301
+ };
2302
+
2303
+ // Types and helper types:
2304
+
2305
+ /**
2306
+ * Extracts the keys of an object where the value is not undefined.
2307
+ */
2308
+
2309
+ /**
2310
+ * Extracts the keys of an object where the value is not undefined.
2311
+ * Then picks the keys from the object.
2312
+ * This is useful for creating a new object type with only the defined keys.
2313
+ * @example
2314
+ * type A = { a: string; b?: number };
2315
+ * type B = DefinedObject<A>; // { a: string }
2316
+ */
2317
+
2318
+ /**
2319
+ * This schema supports:
2320
+ * 1. multiple query params with the same name
2321
+ * 2. simple API route definitions where:
2322
+ * 2.1. z.array means at least one query params this name is required
2323
+ * 2.2. z.optional means no query param of this name is accepted
2324
+ * 2.3. z.array(...).optional() means zero or more query params of this name is accepted
2325
+ *
2326
+ * Do not change this without updating the ValRouter query parsing logic
2327
+ * */
2328
+
2329
+ var createValClient = function createValClient(host) {
2330
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2331
+ var anyApi = Api;
2332
+ return /*#__PURE__*/function () {
2333
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(path, method, req) {
2334
+ var _anyApi$path, _apiEndpoint$req$body;
2335
+ var anyReq, fullPath, params, _i, _Object$keys, _anyReq$query, key, _anyReq$query2, _iterator, _step, value, _anyReq$query3, apiEndpoint, reqBodyResult, res;
2336
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
2337
+ while (1) switch (_context2.prev = _context2.next) {
2338
+ case 0:
2339
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2340
+ anyReq = req;
2341
+ fullPath = path;
2342
+ if (anyReq !== null && anyReq !== void 0 && anyReq.path && anyReq.path.length > 0) {
2343
+ fullPath += anyReq.path;
2344
+ }
2345
+ if (anyReq.query) {
2346
+ params = [];
2347
+ for (_i = 0, _Object$keys = Object.keys(anyReq.query); _i < _Object$keys.length; _i++) {
2348
+ key = _Object$keys[_i];
2349
+ if (Array.isArray((_anyReq$query = anyReq.query) === null || _anyReq$query === void 0 ? void 0 : _anyReq$query[key])) {
2350
+ _iterator = _createForOfIteratorHelper(((_anyReq$query2 = anyReq.query) === null || _anyReq$query2 === void 0 ? void 0 : _anyReq$query2[key]) || []);
2351
+ try {
2352
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
2353
+ value = _step.value;
2354
+ params.push([key, value.toString()]);
2355
+ }
2356
+ } catch (err) {
2357
+ _iterator.e(err);
2358
+ } finally {
2359
+ _iterator.f();
2360
+ }
2361
+ } else {
2362
+ params.push([key, anyReq === null || anyReq === void 0 || (_anyReq$query3 = anyReq.query) === null || _anyReq$query3 === void 0 ? void 0 : _anyReq$query3[key]]);
2363
+ }
2364
+ }
2365
+ if (anyReq !== null && anyReq !== void 0 && anyReq.query && params.length > 0) {
2366
+ fullPath += "?".concat(new URLSearchParams(params).toString());
2367
+ }
2368
+ }
2369
+ apiEndpoint = anyApi === null || anyApi === void 0 || (_anyApi$path = anyApi[path]) === null || _anyApi$path === void 0 ? void 0 : _anyApi$path[method];
2370
+ if (apiEndpoint) {
2371
+ _context2.next = 7;
2372
+ break;
2373
+ }
2374
+ return _context2.abrupt("return", {
2375
+ status: null,
2376
+ json: {
2377
+ message: "Invalid route ".concat(path, " with method ").concat(method, ". This is most likely a Val bug."),
2378
+ type: "client_side_validation_error",
2379
+ details: {
2380
+ validationError: "Route ".concat(path, " with method ").concat(method, " not found."),
2381
+ data: {
2382
+ routes: Object.keys(anyApi || {}),
2383
+ methods: Object.keys((anyApi === null || anyApi === void 0 ? void 0 : anyApi[path]) || {}),
2384
+ route: path,
2385
+ method: method
2386
+ }
2387
+ }
2388
+ }
2389
+ });
2390
+ case 7:
2391
+ reqBodyResult = (_apiEndpoint$req$body = apiEndpoint.req.body) === null || _apiEndpoint$req$body === void 0 ? void 0 : _apiEndpoint$req$body.safeParse(anyReq.body);
2392
+ if (!(reqBodyResult && !reqBodyResult.success)) {
2393
+ _context2.next = 10;
2394
+ break;
2395
+ }
2396
+ return _context2.abrupt("return", {
2397
+ status: null,
2398
+ json: {
2399
+ message: "Invalid request body. This is most likely a Val bug.",
2400
+ type: "client_side_validation_error",
2401
+ details: {
2402
+ validationError: zodValidationError.fromZodError(reqBodyResult.error).toString(),
2403
+ data: anyReq.body
2404
+ }
2405
+ }
2406
+ });
2407
+ case 10:
2408
+ _context2.prev = 10;
2409
+ _context2.next = 13;
2410
+ return fetch("".concat(host).concat(fullPath), {
2411
+ method: method,
2412
+ headers: {
2413
+ "Content-Type": "application/json"
2414
+ },
2415
+ body: anyReq.body !== undefined ? JSON.stringify(anyReq.body) : undefined
2416
+ }).then(/*#__PURE__*/function () {
2417
+ var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(res) {
2418
+ var _apiEndpoint$res;
2419
+ var contentTypeHeaders, json, valClientResult, responseResult;
2420
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
2421
+ while (1) switch (_context.prev = _context.next) {
2422
+ case 0:
2423
+ contentTypeHeaders = res.headers.get("content-type");
2424
+ if (contentTypeHeaders !== null && contentTypeHeaders !== void 0 && contentTypeHeaders.includes("application/json")) {
2425
+ _context.next = 3;
2426
+ break;
2427
+ }
2428
+ return _context.abrupt("return", {
2429
+ status: null,
2430
+ json: {
2431
+ type: "client_side_validation_error",
2432
+ message: "Invalid content type header in response. Could not find application/json in ".concat(Array.from(res.headers.entries()), ". This could be a result of mismatched Val versions."),
2433
+ details: {
2434
+ validationError: "Invalid content type",
2435
+ data: {
2436
+ status: res.status,
2437
+ contentType: contentTypeHeaders
2438
+ }
2439
+ }
2440
+ }
2441
+ });
2442
+ case 3:
2443
+ _context.next = 5;
2444
+ return res.json();
2445
+ case 5:
2446
+ json = _context.sent;
2447
+ valClientResult = {
2448
+ status: res.status,
2449
+ json: json
2450
+ };
2451
+ if (!(res.status === 500)) {
2452
+ _context.next = 10;
2453
+ break;
2454
+ }
2455
+ console.log("Server responded with an error", json);
2456
+ return _context.abrupt("return", {
2457
+ status: 500,
2458
+ json: {
2459
+ message: json.message,
2460
+ type: "unknown"
2461
+ }
2462
+ });
2463
+ case 10:
2464
+ responseResult = (_apiEndpoint$res = apiEndpoint.res) === null || _apiEndpoint$res === void 0 ? void 0 : _apiEndpoint$res.safeParse(valClientResult);
2465
+ if (!(responseResult && !responseResult.success)) {
2466
+ _context.next = 13;
2467
+ break;
2468
+ }
2469
+ return _context.abrupt("return", {
2470
+ status: null,
2471
+ json: {
2472
+ message: "Response could not be validated. This could also be a result of mismatched Val versions.",
2473
+ type: "client_side_validation_error",
2474
+ details: {
2475
+ validationError: zodValidationError.fromZodError(responseResult.error).toString(),
2476
+ data: valClientResult
2477
+ }
2478
+ }
2479
+ });
2480
+ case 13:
2481
+ return _context.abrupt("return", {
2482
+ status: res.status,
2483
+ json: json
2484
+ });
2485
+ case 14:
2486
+ case "end":
2487
+ return _context.stop();
2488
+ }
2489
+ }, _callee);
2490
+ }));
2491
+ return function (_x4) {
2492
+ return _ref2.apply(this, arguments);
2493
+ };
2494
+ }());
2495
+ case 13:
2496
+ res = _context2.sent;
2497
+ return _context2.abrupt("return", res);
2498
+ case 17:
2499
+ _context2.prev = 17;
2500
+ _context2.t0 = _context2["catch"](10);
2501
+ return _context2.abrupt("return", {
2502
+ status: null,
2503
+ json: {
2504
+ message: "Failed to fetch data",
2505
+ type: "network_error",
2506
+ retryable: isRetryable(_context2.t0),
2507
+ details: _context2.t0 instanceof Error ? _context2.t0.message : JSON.stringify(_context2.t0)
2508
+ }
2509
+ });
2510
+ case 20:
2511
+ case "end":
2512
+ return _context2.stop();
2513
+ }
2514
+ }, _callee2, null, [[10, 17]]);
2515
+ }));
2516
+ return function (_x, _x2, _x3) {
2517
+ return _ref.apply(this, arguments);
2518
+ };
2519
+ }();
2520
+ };
2521
+ function isRetryable(error) {
2522
+ if (error instanceof TypeError) {
2523
+ // TypeError is usually thrown by fetch when the network request fails.
2524
+ return true;
2525
+ }
2526
+ if (error instanceof Error && "code" in error) {
2527
+ var errorCode = error.code;
2528
+
2529
+ // Network-specific errors (Node.js specific)
2530
+ var retryableErrorCodes = ["ECONNRESET", "ETIMEDOUT", "ENOTFOUND", "EAI_AGAIN"];
2531
+ return retryableErrorCodes.includes(errorCode);
2532
+ }
2533
+ return false;
2257
2534
  }
2258
2535
 
2259
- exports.EXT_TO_MIME_TYPES = EXT_TO_MIME_TYPES;
2260
- exports.MIME_TYPES_TO_EXT = MIME_TYPES_TO_EXT;
2536
+ var urlOf = function urlOf() {
2537
+ var route = arguments.length <= 0 ? undefined : arguments[0];
2538
+ var query = arguments.length <= 1 ? undefined : arguments[1];
2539
+ if (query) {
2540
+ var params = Object.entries(query).flatMap(function (_ref) {
2541
+ var _ref2 = _slicedToArray(_ref, 2),
2542
+ key = _ref2[0],
2543
+ value = _ref2[1];
2544
+ if (!value) {
2545
+ return [];
2546
+ }
2547
+ return [[key, value.toString()]];
2548
+ });
2549
+ var searchParams = new URLSearchParams(params);
2550
+ return "".concat(route + "?" + searchParams.toString());
2551
+ }
2552
+ return "".concat(route);
2553
+ };
2554
+
2555
+ exports.Api = Api;
2261
2556
  exports.RemirrorBr = RemirrorBr;
2262
2557
  exports.RemirrorBulletList = RemirrorBulletList;
2263
2558
  exports.RemirrorHeading = RemirrorHeading;
@@ -2272,9 +2567,8 @@ exports.RemirrorTextMark = RemirrorTextMark;
2272
2567
  exports.VAL_ENABLE_COOKIE_NAME = VAL_ENABLE_COOKIE_NAME;
2273
2568
  exports.VAL_SESSION_COOKIE = VAL_SESSION_COOKIE;
2274
2569
  exports.VAL_STATE_COOKIE = VAL_STATE_COOKIE;
2275
- exports.ValStore = ValStore;
2276
- exports.filenameToMimeType = filenameToMimeType;
2277
- exports.getMimeType = getMimeType;
2278
- exports.mimeTypeToFileExt = mimeTypeToFileExt;
2570
+ exports.ValCache = ValCache;
2571
+ exports.createValClient = createValClient;
2279
2572
  exports.remirrorToRichTextSource = remirrorToRichTextSource;
2280
2573
  exports.richTextToRemirror = richTextToRemirror;
2574
+ exports.urlOf = urlOf;