@valbuild/shared 0.57.0 → 0.59.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.
- package/dist/declarations/src/internal/ValStore.d.ts +46 -0
- package/dist/declarations/src/internal/index.d.ts +1 -1
- package/dist/declarations/src/internal/server/types.d.ts +10 -4
- package/internal/dist/valbuild-shared-internal.cjs.dev.js +727 -10
- package/internal/dist/valbuild-shared-internal.cjs.prod.js +727 -10
- package/internal/dist/valbuild-shared-internal.esm.js +727 -11
- package/package.json +2 -2
- package/dist/declarations/src/internal/IValStore.d.ts +0 -5
@@ -1,6 +1,8 @@
|
|
1
1
|
import { VAL_EXTENSION, Internal, FILE_REF_PROP, FILE_REF_SUBTYPE_TAG, RT_IMAGE_TAG } from '@valbuild/core';
|
2
2
|
import * as marked from 'marked';
|
3
3
|
import { z } from 'zod';
|
4
|
+
import { result } from '@valbuild/core/fp';
|
5
|
+
import { JSONOps, applyPatch } from '@valbuild/core/patch';
|
4
6
|
|
5
7
|
function toPrimitive(t, r) {
|
6
8
|
if ("object" != typeof t || !t) return t;
|
@@ -1146,12 +1148,10 @@ function parseTokens(tokens, sourceNodes, cursor) {
|
|
1146
1148
|
if (i === lines.length - 1) return [line];
|
1147
1149
|
if (i === lines.length - 1 && line === "") return [];
|
1148
1150
|
if (line === "") return {
|
1149
|
-
tag: "br"
|
1150
|
-
children: []
|
1151
|
+
tag: "br"
|
1151
1152
|
};
|
1152
1153
|
return [line, {
|
1153
|
-
tag: "br"
|
1154
|
-
children: []
|
1154
|
+
tag: "br"
|
1155
1155
|
}];
|
1156
1156
|
});
|
1157
1157
|
children.push.apply(children, _toConsumableArray(tags));
|
@@ -1210,8 +1210,7 @@ function parseTokens(tokens, sourceNodes, cursor) {
|
|
1210
1210
|
src: Internal.convertFileSource(sourceNode).url,
|
1211
1211
|
width: (_sourceNode$metadata = sourceNode.metadata) === null || _sourceNode$metadata === void 0 ? void 0 : _sourceNode$metadata.width,
|
1212
1212
|
height: (_sourceNode$metadata2 = sourceNode.metadata) === null || _sourceNode$metadata2 === void 0 ? void 0 : _sourceNode$metadata2.height,
|
1213
|
-
mimeType: (_sourceNode$metadata3 = sourceNode.metadata) === null || _sourceNode$metadata3 === void 0 ? void 0 : _sourceNode$metadata3.mimeType
|
1214
|
-
children: []
|
1213
|
+
mimeType: (_sourceNode$metadata3 = sourceNode.metadata) === null || _sourceNode$metadata3 === void 0 ? void 0 : _sourceNode$metadata3.mimeType
|
1215
1214
|
});
|
1216
1215
|
}
|
1217
1216
|
cursor = subCursor;
|
@@ -1220,8 +1219,7 @@ function parseTokens(tokens, sourceNodes, cursor) {
|
|
1220
1219
|
if (token.text.trim().match(br_html_regex)) {
|
1221
1220
|
var _tokens;
|
1222
1221
|
children.push({
|
1223
|
-
tag: "br"
|
1224
|
-
children: []
|
1222
|
+
tag: "br"
|
1225
1223
|
});
|
1226
1224
|
if (((_tokens = tokens[cursor + 1]) === null || _tokens === void 0 ? void 0 : _tokens.raw.trim()) === "") {
|
1227
1225
|
// if next token is a new line or white-spaces, skip it
|
@@ -1242,8 +1240,7 @@ function parseTokens(tokens, sourceNodes, cursor) {
|
|
1242
1240
|
}
|
1243
1241
|
} else if (token.type === "br") {
|
1244
1242
|
children.push({
|
1245
|
-
tag: "br"
|
1246
|
-
children: []
|
1243
|
+
tag: "br"
|
1247
1244
|
});
|
1248
1245
|
} else {
|
1249
1246
|
console.error("Could not parse markdown: unsupported token type: ".concat(token.type, ". Found: ").concat(token.raw));
|
@@ -1621,4 +1618,723 @@ var VAL_SESSION_COOKIE = Internal.VAL_SESSION_COOKIE;
|
|
1621
1618
|
var VAL_STATE_COOKIE = Internal.VAL_STATE_COOKIE;
|
1622
1619
|
var VAL_ENABLE_COOKIE_NAME = Internal.VAL_ENABLE_COOKIE_NAME;
|
1623
1620
|
|
1624
|
-
|
1621
|
+
function _regeneratorRuntime() {
|
1622
|
+
_regeneratorRuntime = function () {
|
1623
|
+
return e;
|
1624
|
+
};
|
1625
|
+
var t,
|
1626
|
+
e = {},
|
1627
|
+
r = Object.prototype,
|
1628
|
+
n = r.hasOwnProperty,
|
1629
|
+
o = Object.defineProperty || function (t, e, r) {
|
1630
|
+
t[e] = r.value;
|
1631
|
+
},
|
1632
|
+
i = "function" == typeof Symbol ? Symbol : {},
|
1633
|
+
a = i.iterator || "@@iterator",
|
1634
|
+
c = i.asyncIterator || "@@asyncIterator",
|
1635
|
+
u = i.toStringTag || "@@toStringTag";
|
1636
|
+
function define(t, e, r) {
|
1637
|
+
return Object.defineProperty(t, e, {
|
1638
|
+
value: r,
|
1639
|
+
enumerable: !0,
|
1640
|
+
configurable: !0,
|
1641
|
+
writable: !0
|
1642
|
+
}), t[e];
|
1643
|
+
}
|
1644
|
+
try {
|
1645
|
+
define({}, "");
|
1646
|
+
} catch (t) {
|
1647
|
+
define = function (t, e, r) {
|
1648
|
+
return t[e] = r;
|
1649
|
+
};
|
1650
|
+
}
|
1651
|
+
function wrap(t, e, r, n) {
|
1652
|
+
var i = e && e.prototype instanceof Generator ? e : Generator,
|
1653
|
+
a = Object.create(i.prototype),
|
1654
|
+
c = new Context(n || []);
|
1655
|
+
return o(a, "_invoke", {
|
1656
|
+
value: makeInvokeMethod(t, r, c)
|
1657
|
+
}), a;
|
1658
|
+
}
|
1659
|
+
function tryCatch(t, e, r) {
|
1660
|
+
try {
|
1661
|
+
return {
|
1662
|
+
type: "normal",
|
1663
|
+
arg: t.call(e, r)
|
1664
|
+
};
|
1665
|
+
} catch (t) {
|
1666
|
+
return {
|
1667
|
+
type: "throw",
|
1668
|
+
arg: t
|
1669
|
+
};
|
1670
|
+
}
|
1671
|
+
}
|
1672
|
+
e.wrap = wrap;
|
1673
|
+
var h = "suspendedStart",
|
1674
|
+
l = "suspendedYield",
|
1675
|
+
f = "executing",
|
1676
|
+
s = "completed",
|
1677
|
+
y = {};
|
1678
|
+
function Generator() {}
|
1679
|
+
function GeneratorFunction() {}
|
1680
|
+
function GeneratorFunctionPrototype() {}
|
1681
|
+
var p = {};
|
1682
|
+
define(p, a, function () {
|
1683
|
+
return this;
|
1684
|
+
});
|
1685
|
+
var d = Object.getPrototypeOf,
|
1686
|
+
v = d && d(d(values([])));
|
1687
|
+
v && v !== r && n.call(v, a) && (p = v);
|
1688
|
+
var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p);
|
1689
|
+
function defineIteratorMethods(t) {
|
1690
|
+
["next", "throw", "return"].forEach(function (e) {
|
1691
|
+
define(t, e, function (t) {
|
1692
|
+
return this._invoke(e, t);
|
1693
|
+
});
|
1694
|
+
});
|
1695
|
+
}
|
1696
|
+
function AsyncIterator(t, e) {
|
1697
|
+
function invoke(r, o, i, a) {
|
1698
|
+
var c = tryCatch(t[r], t, o);
|
1699
|
+
if ("throw" !== c.type) {
|
1700
|
+
var u = c.arg,
|
1701
|
+
h = u.value;
|
1702
|
+
return h && "object" == typeof h && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) {
|
1703
|
+
invoke("next", t, i, a);
|
1704
|
+
}, function (t) {
|
1705
|
+
invoke("throw", t, i, a);
|
1706
|
+
}) : e.resolve(h).then(function (t) {
|
1707
|
+
u.value = t, i(u);
|
1708
|
+
}, function (t) {
|
1709
|
+
return invoke("throw", t, i, a);
|
1710
|
+
});
|
1711
|
+
}
|
1712
|
+
a(c.arg);
|
1713
|
+
}
|
1714
|
+
var r;
|
1715
|
+
o(this, "_invoke", {
|
1716
|
+
value: function (t, n) {
|
1717
|
+
function callInvokeWithMethodAndArg() {
|
1718
|
+
return new e(function (e, r) {
|
1719
|
+
invoke(t, n, e, r);
|
1720
|
+
});
|
1721
|
+
}
|
1722
|
+
return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
|
1723
|
+
}
|
1724
|
+
});
|
1725
|
+
}
|
1726
|
+
function makeInvokeMethod(e, r, n) {
|
1727
|
+
var o = h;
|
1728
|
+
return function (i, a) {
|
1729
|
+
if (o === f) throw new Error("Generator is already running");
|
1730
|
+
if (o === s) {
|
1731
|
+
if ("throw" === i) throw a;
|
1732
|
+
return {
|
1733
|
+
value: t,
|
1734
|
+
done: !0
|
1735
|
+
};
|
1736
|
+
}
|
1737
|
+
for (n.method = i, n.arg = a;;) {
|
1738
|
+
var c = n.delegate;
|
1739
|
+
if (c) {
|
1740
|
+
var u = maybeInvokeDelegate(c, n);
|
1741
|
+
if (u) {
|
1742
|
+
if (u === y) continue;
|
1743
|
+
return u;
|
1744
|
+
}
|
1745
|
+
}
|
1746
|
+
if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) {
|
1747
|
+
if (o === h) throw o = s, n.arg;
|
1748
|
+
n.dispatchException(n.arg);
|
1749
|
+
} else "return" === n.method && n.abrupt("return", n.arg);
|
1750
|
+
o = f;
|
1751
|
+
var p = tryCatch(e, r, n);
|
1752
|
+
if ("normal" === p.type) {
|
1753
|
+
if (o = n.done ? s : l, p.arg === y) continue;
|
1754
|
+
return {
|
1755
|
+
value: p.arg,
|
1756
|
+
done: n.done
|
1757
|
+
};
|
1758
|
+
}
|
1759
|
+
"throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg);
|
1760
|
+
}
|
1761
|
+
};
|
1762
|
+
}
|
1763
|
+
function maybeInvokeDelegate(e, r) {
|
1764
|
+
var n = r.method,
|
1765
|
+
o = e.iterator[n];
|
1766
|
+
if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y;
|
1767
|
+
var i = tryCatch(o, e.iterator, r.arg);
|
1768
|
+
if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y;
|
1769
|
+
var a = i.arg;
|
1770
|
+
return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y);
|
1771
|
+
}
|
1772
|
+
function pushTryEntry(t) {
|
1773
|
+
var e = {
|
1774
|
+
tryLoc: t[0]
|
1775
|
+
};
|
1776
|
+
1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e);
|
1777
|
+
}
|
1778
|
+
function resetTryEntry(t) {
|
1779
|
+
var e = t.completion || {};
|
1780
|
+
e.type = "normal", delete e.arg, t.completion = e;
|
1781
|
+
}
|
1782
|
+
function Context(t) {
|
1783
|
+
this.tryEntries = [{
|
1784
|
+
tryLoc: "root"
|
1785
|
+
}], t.forEach(pushTryEntry, this), this.reset(!0);
|
1786
|
+
}
|
1787
|
+
function values(e) {
|
1788
|
+
if (e || "" === e) {
|
1789
|
+
var r = e[a];
|
1790
|
+
if (r) return r.call(e);
|
1791
|
+
if ("function" == typeof e.next) return e;
|
1792
|
+
if (!isNaN(e.length)) {
|
1793
|
+
var o = -1,
|
1794
|
+
i = function next() {
|
1795
|
+
for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next;
|
1796
|
+
return next.value = t, next.done = !0, next;
|
1797
|
+
};
|
1798
|
+
return i.next = i;
|
1799
|
+
}
|
1800
|
+
}
|
1801
|
+
throw new TypeError(typeof e + " is not iterable");
|
1802
|
+
}
|
1803
|
+
return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", {
|
1804
|
+
value: GeneratorFunctionPrototype,
|
1805
|
+
configurable: !0
|
1806
|
+
}), o(GeneratorFunctionPrototype, "constructor", {
|
1807
|
+
value: GeneratorFunction,
|
1808
|
+
configurable: !0
|
1809
|
+
}), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) {
|
1810
|
+
var e = "function" == typeof t && t.constructor;
|
1811
|
+
return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name));
|
1812
|
+
}, e.mark = function (t) {
|
1813
|
+
return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t;
|
1814
|
+
}, e.awrap = function (t) {
|
1815
|
+
return {
|
1816
|
+
__await: t
|
1817
|
+
};
|
1818
|
+
}, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () {
|
1819
|
+
return this;
|
1820
|
+
}), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) {
|
1821
|
+
void 0 === i && (i = Promise);
|
1822
|
+
var a = new AsyncIterator(wrap(t, r, n, o), i);
|
1823
|
+
return e.isGeneratorFunction(r) ? a : a.next().then(function (t) {
|
1824
|
+
return t.done ? t.value : a.next();
|
1825
|
+
});
|
1826
|
+
}, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () {
|
1827
|
+
return this;
|
1828
|
+
}), define(g, "toString", function () {
|
1829
|
+
return "[object Generator]";
|
1830
|
+
}), e.keys = function (t) {
|
1831
|
+
var e = Object(t),
|
1832
|
+
r = [];
|
1833
|
+
for (var n in e) r.push(n);
|
1834
|
+
return r.reverse(), function next() {
|
1835
|
+
for (; r.length;) {
|
1836
|
+
var t = r.pop();
|
1837
|
+
if (t in e) return next.value = t, next.done = !1, next;
|
1838
|
+
}
|
1839
|
+
return next.done = !0, next;
|
1840
|
+
};
|
1841
|
+
}, e.values = values, Context.prototype = {
|
1842
|
+
constructor: Context,
|
1843
|
+
reset: function (e) {
|
1844
|
+
if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t);
|
1845
|
+
},
|
1846
|
+
stop: function () {
|
1847
|
+
this.done = !0;
|
1848
|
+
var t = this.tryEntries[0].completion;
|
1849
|
+
if ("throw" === t.type) throw t.arg;
|
1850
|
+
return this.rval;
|
1851
|
+
},
|
1852
|
+
dispatchException: function (e) {
|
1853
|
+
if (this.done) throw e;
|
1854
|
+
var r = this;
|
1855
|
+
function handle(n, o) {
|
1856
|
+
return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o;
|
1857
|
+
}
|
1858
|
+
for (var o = this.tryEntries.length - 1; o >= 0; --o) {
|
1859
|
+
var i = this.tryEntries[o],
|
1860
|
+
a = i.completion;
|
1861
|
+
if ("root" === i.tryLoc) return handle("end");
|
1862
|
+
if (i.tryLoc <= this.prev) {
|
1863
|
+
var c = n.call(i, "catchLoc"),
|
1864
|
+
u = n.call(i, "finallyLoc");
|
1865
|
+
if (c && u) {
|
1866
|
+
if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
|
1867
|
+
if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
|
1868
|
+
} else if (c) {
|
1869
|
+
if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
|
1870
|
+
} else {
|
1871
|
+
if (!u) throw new Error("try statement without catch or finally");
|
1872
|
+
if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
|
1873
|
+
}
|
1874
|
+
}
|
1875
|
+
}
|
1876
|
+
},
|
1877
|
+
abrupt: function (t, e) {
|
1878
|
+
for (var r = this.tryEntries.length - 1; r >= 0; --r) {
|
1879
|
+
var o = this.tryEntries[r];
|
1880
|
+
if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) {
|
1881
|
+
var i = o;
|
1882
|
+
break;
|
1883
|
+
}
|
1884
|
+
}
|
1885
|
+
i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null);
|
1886
|
+
var a = i ? i.completion : {};
|
1887
|
+
return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a);
|
1888
|
+
},
|
1889
|
+
complete: function (t, e) {
|
1890
|
+
if ("throw" === t.type) throw t.arg;
|
1891
|
+
return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y;
|
1892
|
+
},
|
1893
|
+
finish: function (t) {
|
1894
|
+
for (var e = this.tryEntries.length - 1; e >= 0; --e) {
|
1895
|
+
var r = this.tryEntries[e];
|
1896
|
+
if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y;
|
1897
|
+
}
|
1898
|
+
},
|
1899
|
+
catch: function (t) {
|
1900
|
+
for (var e = this.tryEntries.length - 1; e >= 0; --e) {
|
1901
|
+
var r = this.tryEntries[e];
|
1902
|
+
if (r.tryLoc === t) {
|
1903
|
+
var n = r.completion;
|
1904
|
+
if ("throw" === n.type) {
|
1905
|
+
var o = n.arg;
|
1906
|
+
resetTryEntry(r);
|
1907
|
+
}
|
1908
|
+
return o;
|
1909
|
+
}
|
1910
|
+
}
|
1911
|
+
throw new Error("illegal catch attempt");
|
1912
|
+
},
|
1913
|
+
delegateYield: function (e, r, n) {
|
1914
|
+
return this.delegate = {
|
1915
|
+
iterator: values(e),
|
1916
|
+
resultName: r,
|
1917
|
+
nextLoc: n
|
1918
|
+
}, "next" === this.method && (this.arg = t), y;
|
1919
|
+
}
|
1920
|
+
}, e;
|
1921
|
+
}
|
1922
|
+
|
1923
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
1924
|
+
try {
|
1925
|
+
var info = gen[key](arg);
|
1926
|
+
var value = info.value;
|
1927
|
+
} catch (error) {
|
1928
|
+
reject(error);
|
1929
|
+
return;
|
1930
|
+
}
|
1931
|
+
if (info.done) {
|
1932
|
+
resolve(value);
|
1933
|
+
} else {
|
1934
|
+
Promise.resolve(value).then(_next, _throw);
|
1935
|
+
}
|
1936
|
+
}
|
1937
|
+
function _asyncToGenerator(fn) {
|
1938
|
+
return function () {
|
1939
|
+
var self = this,
|
1940
|
+
args = arguments;
|
1941
|
+
return new Promise(function (resolve, reject) {
|
1942
|
+
var gen = fn.apply(self, args);
|
1943
|
+
function _next(value) {
|
1944
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
1945
|
+
}
|
1946
|
+
function _throw(err) {
|
1947
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
1948
|
+
}
|
1949
|
+
_next(undefined);
|
1950
|
+
});
|
1951
|
+
};
|
1952
|
+
}
|
1953
|
+
|
1954
|
+
function _classCallCheck(instance, Constructor) {
|
1955
|
+
if (!(instance instanceof Constructor)) {
|
1956
|
+
throw new TypeError("Cannot call a class as a function");
|
1957
|
+
}
|
1958
|
+
}
|
1959
|
+
|
1960
|
+
function _defineProperties(target, props) {
|
1961
|
+
for (var i = 0; i < props.length; i++) {
|
1962
|
+
var descriptor = props[i];
|
1963
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
1964
|
+
descriptor.configurable = true;
|
1965
|
+
if ("value" in descriptor) descriptor.writable = true;
|
1966
|
+
Object.defineProperty(target, toPropertyKey(descriptor.key), descriptor);
|
1967
|
+
}
|
1968
|
+
}
|
1969
|
+
function _createClass(Constructor, protoProps, staticProps) {
|
1970
|
+
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
1971
|
+
if (staticProps) _defineProperties(Constructor, staticProps);
|
1972
|
+
Object.defineProperty(Constructor, "prototype", {
|
1973
|
+
writable: false
|
1974
|
+
});
|
1975
|
+
return Constructor;
|
1976
|
+
}
|
1977
|
+
|
1978
|
+
var ops = new JSONOps();
|
1979
|
+
var ValStore = /*#__PURE__*/function () {
|
1980
|
+
// uncertain whether this is the optimal way of returning
|
1981
|
+
|
1982
|
+
function ValStore(api) {
|
1983
|
+
var _this = this;
|
1984
|
+
_classCallCheck(this, ValStore);
|
1985
|
+
_defineProperty(this, "subscribe", function (moduleIds) {
|
1986
|
+
return function (listener) {
|
1987
|
+
var subscriberId = createSubscriberId(moduleIds);
|
1988
|
+
if (!_this.listeners[subscriberId]) {
|
1989
|
+
_this.listeners[subscriberId] = [];
|
1990
|
+
_this.subscribers.set(subscriberId, {});
|
1991
|
+
}
|
1992
|
+
_this.listeners[subscriberId].push(listener);
|
1993
|
+
return function () {
|
1994
|
+
_this.listeners[subscriberId].splice(_this.listeners[subscriberId].indexOf(listener), 1);
|
1995
|
+
};
|
1996
|
+
};
|
1997
|
+
});
|
1998
|
+
_defineProperty(this, "getSnapshot", function (moduleIds) {
|
1999
|
+
return function () {
|
2000
|
+
return _this.get(moduleIds);
|
2001
|
+
};
|
2002
|
+
});
|
2003
|
+
_defineProperty(this, "getServerSnapshot", function (moduleIds) {
|
2004
|
+
return function () {
|
2005
|
+
return _this.get(moduleIds);
|
2006
|
+
};
|
2007
|
+
});
|
2008
|
+
_defineProperty(this, "get", function (moduleIds) {
|
2009
|
+
var subscriberId = createSubscriberId(moduleIds);
|
2010
|
+
return _this.subscribers.get(subscriberId);
|
2011
|
+
});
|
2012
|
+
this.api = api;
|
2013
|
+
this.subscribers = new Map();
|
2014
|
+
this.listeners = {};
|
2015
|
+
this.drafts = {};
|
2016
|
+
this.schema = {};
|
2017
|
+
}
|
2018
|
+
_createClass(ValStore, [{
|
2019
|
+
key: "getModule",
|
2020
|
+
value: function () {
|
2021
|
+
var _getModule = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(moduleId) {
|
2022
|
+
var refetch,
|
2023
|
+
data,
|
2024
|
+
fetchedSource,
|
2025
|
+
fetchedSchema,
|
2026
|
+
_args = arguments;
|
2027
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
2028
|
+
while (1) switch (_context.prev = _context.next) {
|
2029
|
+
case 0:
|
2030
|
+
refetch = _args.length > 1 && _args[1] !== undefined ? _args[1] : false;
|
2031
|
+
if (!(!refetch && this.drafts[moduleId] && this.schema[moduleId])) {
|
2032
|
+
_context.next = 3;
|
2033
|
+
break;
|
2034
|
+
}
|
2035
|
+
return _context.abrupt("return", result.ok({
|
2036
|
+
source: this.drafts[moduleId],
|
2037
|
+
schema: this.schema[moduleId]
|
2038
|
+
}));
|
2039
|
+
case 3:
|
2040
|
+
_context.next = 5;
|
2041
|
+
return this.api.getTree({
|
2042
|
+
patch: true,
|
2043
|
+
treePath: moduleId,
|
2044
|
+
includeSource: true
|
2045
|
+
});
|
2046
|
+
case 5:
|
2047
|
+
data = _context.sent;
|
2048
|
+
if (!result.isOk(data)) {
|
2049
|
+
_context.next = 19;
|
2050
|
+
break;
|
2051
|
+
}
|
2052
|
+
fetchedSource = data.value.modules[moduleId].source;
|
2053
|
+
fetchedSchema = data.value.modules[moduleId].schema;
|
2054
|
+
if (!(fetchedSource !== undefined && fetchedSchema !== undefined)) {
|
2055
|
+
_context.next = 15;
|
2056
|
+
break;
|
2057
|
+
}
|
2058
|
+
this.drafts[moduleId] = fetchedSource;
|
2059
|
+
this.schema[moduleId] = fetchedSchema;
|
2060
|
+
return _context.abrupt("return", result.ok({
|
2061
|
+
source: fetchedSource,
|
2062
|
+
schema: fetchedSchema
|
2063
|
+
}));
|
2064
|
+
case 15:
|
2065
|
+
console.error("Val: could not find the module source");
|
2066
|
+
return _context.abrupt("return", result.err({
|
2067
|
+
message: "Could not fetch data. Verify that the module exists."
|
2068
|
+
}));
|
2069
|
+
case 17:
|
2070
|
+
_context.next = 21;
|
2071
|
+
break;
|
2072
|
+
case 19:
|
2073
|
+
console.error("Val: failed to get module", data.error);
|
2074
|
+
return _context.abrupt("return", result.err({
|
2075
|
+
message: "Could not fetch data. Verify that Val is correctly configured."
|
2076
|
+
}));
|
2077
|
+
case 21:
|
2078
|
+
case "end":
|
2079
|
+
return _context.stop();
|
2080
|
+
}
|
2081
|
+
}, _callee, this);
|
2082
|
+
}));
|
2083
|
+
function getModule(_x) {
|
2084
|
+
return _getModule.apply(this, arguments);
|
2085
|
+
}
|
2086
|
+
return getModule;
|
2087
|
+
}()
|
2088
|
+
}, {
|
2089
|
+
key: "applyPatch",
|
2090
|
+
value: function () {
|
2091
|
+
var _applyPatch2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(moduleId, patch) {
|
2092
|
+
var currentSource, currentSchema, data, fetchedSource, fetchedSchema, res, patchRes, _i, _Array$from, _Array$from$_i, subscriberId, subscriberModules;
|
2093
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
2094
|
+
while (1) switch (_context2.prev = _context2.next) {
|
2095
|
+
case 0:
|
2096
|
+
currentSource = this.drafts[moduleId];
|
2097
|
+
currentSchema = this.schema[moduleId];
|
2098
|
+
if (!(!currentSource || !currentSchema)) {
|
2099
|
+
_context2.next = 21;
|
2100
|
+
break;
|
2101
|
+
}
|
2102
|
+
_context2.next = 5;
|
2103
|
+
return this.api.getTree({
|
2104
|
+
patch: true,
|
2105
|
+
treePath: moduleId,
|
2106
|
+
includeSource: true
|
2107
|
+
});
|
2108
|
+
case 5:
|
2109
|
+
data = _context2.sent;
|
2110
|
+
if (!result.isOk(data)) {
|
2111
|
+
_context2.next = 19;
|
2112
|
+
break;
|
2113
|
+
}
|
2114
|
+
fetchedSource = data.value.modules[moduleId].source;
|
2115
|
+
fetchedSchema = data.value.modules[moduleId].schema;
|
2116
|
+
if (!(fetchedSource !== undefined && fetchedSchema !== undefined)) {
|
2117
|
+
_context2.next = 15;
|
2118
|
+
break;
|
2119
|
+
}
|
2120
|
+
currentSource = fetchedSource;
|
2121
|
+
this.drafts[moduleId] = fetchedSource;
|
2122
|
+
this.schema[moduleId] = fetchedSchema;
|
2123
|
+
_context2.next = 17;
|
2124
|
+
break;
|
2125
|
+
case 15:
|
2126
|
+
console.error("Val: could not find the module source");
|
2127
|
+
return _context2.abrupt("return", result.err({
|
2128
|
+
message: "Val: could not fetch data. Verify that the module exists."
|
2129
|
+
}));
|
2130
|
+
case 17:
|
2131
|
+
_context2.next = 21;
|
2132
|
+
break;
|
2133
|
+
case 19:
|
2134
|
+
console.error("Val: failed to get module", data.error);
|
2135
|
+
return _context2.abrupt("return", result.err({
|
2136
|
+
message: "Val: could not fetch data. Verify that Val is correctly configured."
|
2137
|
+
}));
|
2138
|
+
case 21:
|
2139
|
+
_context2.next = 23;
|
2140
|
+
return this.api.postPatches(moduleId, patch);
|
2141
|
+
case 23:
|
2142
|
+
res = _context2.sent;
|
2143
|
+
if (!result.isErr(res)) {
|
2144
|
+
_context2.next = 27;
|
2145
|
+
break;
|
2146
|
+
}
|
2147
|
+
console.error("Val: failed to post patch", res.error);
|
2148
|
+
return _context2.abrupt("return", res);
|
2149
|
+
case 27:
|
2150
|
+
patchRes = applyPatch(currentSource, ops, patch.filter(Internal.notFileOp) // we cannot apply file ops here
|
2151
|
+
);
|
2152
|
+
if (!result.isOk(patchRes)) {
|
2153
|
+
_context2.next = 34;
|
2154
|
+
break;
|
2155
|
+
}
|
2156
|
+
this.drafts[moduleId] = patchRes.value;
|
2157
|
+
for (_i = 0, _Array$from = Array.from(this.subscribers.entries()); _i < _Array$from.length; _i++) {
|
2158
|
+
_Array$from$_i = _slicedToArray(_Array$from[_i], 2), subscriberId = _Array$from$_i[0], subscriberModules = _Array$from$_i[1];
|
2159
|
+
if (subscriberModules[moduleId]) {
|
2160
|
+
this.subscribers.set(subscriberId, _objectSpread2(_objectSpread2({}, subscriberModules), {}, _defineProperty({}, moduleId, this.drafts[moduleId])));
|
2161
|
+
this.emitChange(subscriberId);
|
2162
|
+
}
|
2163
|
+
}
|
2164
|
+
return _context2.abrupt("return", res);
|
2165
|
+
case 34:
|
2166
|
+
console.error("Val: failed to apply patch", patchRes.error);
|
2167
|
+
return _context2.abrupt("return", patchRes);
|
2168
|
+
case 36:
|
2169
|
+
case "end":
|
2170
|
+
return _context2.stop();
|
2171
|
+
}
|
2172
|
+
}, _callee2, this);
|
2173
|
+
}));
|
2174
|
+
function applyPatch$1(_x2, _x3) {
|
2175
|
+
return _applyPatch2.apply(this, arguments);
|
2176
|
+
}
|
2177
|
+
return applyPatch$1;
|
2178
|
+
}()
|
2179
|
+
}, {
|
2180
|
+
key: "update",
|
2181
|
+
value: function () {
|
2182
|
+
var _update = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(moduleIds) {
|
2183
|
+
var _this2 = this;
|
2184
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
2185
|
+
while (1) switch (_context3.prev = _context3.next) {
|
2186
|
+
case 0:
|
2187
|
+
_context3.next = 2;
|
2188
|
+
return Promise.all(moduleIds.map(function (moduleId) {
|
2189
|
+
return _this2.updateTree(moduleId);
|
2190
|
+
}));
|
2191
|
+
case 2:
|
2192
|
+
case "end":
|
2193
|
+
return _context3.stop();
|
2194
|
+
}
|
2195
|
+
}, _callee3);
|
2196
|
+
}));
|
2197
|
+
function update(_x4) {
|
2198
|
+
return _update.apply(this, arguments);
|
2199
|
+
}
|
2200
|
+
return update;
|
2201
|
+
}()
|
2202
|
+
}, {
|
2203
|
+
key: "reset",
|
2204
|
+
value: function () {
|
2205
|
+
var _reset = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
|
2206
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
2207
|
+
while (1) switch (_context4.prev = _context4.next) {
|
2208
|
+
case 0:
|
2209
|
+
return _context4.abrupt("return", this.updateTree());
|
2210
|
+
case 1:
|
2211
|
+
case "end":
|
2212
|
+
return _context4.stop();
|
2213
|
+
}
|
2214
|
+
}, _callee4, this);
|
2215
|
+
}));
|
2216
|
+
function reset() {
|
2217
|
+
return _reset.apply(this, arguments);
|
2218
|
+
}
|
2219
|
+
return reset;
|
2220
|
+
}()
|
2221
|
+
}, {
|
2222
|
+
key: "updateTree",
|
2223
|
+
value: function () {
|
2224
|
+
var _updateTree = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(treePath) {
|
2225
|
+
var data, moduleIds, updatedSubscriberIds, subscriberIds, _loop, _i2, _arr, _i3, _Array$from2, _Array$from2$_i, updatedSubscriberId, _moduleIds, subscriberModules, msg;
|
2226
|
+
return _regeneratorRuntime().wrap(function _callee5$(_context6) {
|
2227
|
+
while (1) switch (_context6.prev = _context6.next) {
|
2228
|
+
case 0:
|
2229
|
+
_context6.next = 2;
|
2230
|
+
return this.api.getTree({
|
2231
|
+
patch: true,
|
2232
|
+
treePath: treePath,
|
2233
|
+
includeSource: true
|
2234
|
+
});
|
2235
|
+
case 2:
|
2236
|
+
data = _context6.sent;
|
2237
|
+
moduleIds = [];
|
2238
|
+
if (!result.isOk(data)) {
|
2239
|
+
_context6.next = 18;
|
2240
|
+
break;
|
2241
|
+
}
|
2242
|
+
updatedSubscriberIds = new Map();
|
2243
|
+
subscriberIds = Array.from(this.subscribers.keys()); // Figure out which modules have been updated and map to updated subscribed id
|
2244
|
+
_loop = /*#__PURE__*/_regeneratorRuntime().mark(function _loop() {
|
2245
|
+
var moduleId, source, updatedSubscriberId;
|
2246
|
+
return _regeneratorRuntime().wrap(function _loop$(_context5) {
|
2247
|
+
while (1) switch (_context5.prev = _context5.next) {
|
2248
|
+
case 0:
|
2249
|
+
moduleId = _arr[_i2];
|
2250
|
+
moduleIds.push(moduleId);
|
2251
|
+
source = data.value.modules[moduleId].source;
|
2252
|
+
if (typeof source !== "undefined") {
|
2253
|
+
updatedSubscriberId = subscriberIds.find(function (subscriberId) {
|
2254
|
+
return subscriberId.includes(moduleId);
|
2255
|
+
} // NOTE: dependent on
|
2256
|
+
);
|
2257
|
+
if (updatedSubscriberId) {
|
2258
|
+
updatedSubscriberIds.set(updatedSubscriberId, (updatedSubscriberIds.get(updatedSubscriberId) || []).concat(moduleId));
|
2259
|
+
}
|
2260
|
+
}
|
2261
|
+
case 4:
|
2262
|
+
case "end":
|
2263
|
+
return _context5.stop();
|
2264
|
+
}
|
2265
|
+
}, _loop);
|
2266
|
+
});
|
2267
|
+
_i2 = 0, _arr = Object.keys(data.value.modules);
|
2268
|
+
case 9:
|
2269
|
+
if (!(_i2 < _arr.length)) {
|
2270
|
+
_context6.next = 14;
|
2271
|
+
break;
|
2272
|
+
}
|
2273
|
+
return _context6.delegateYield(_loop(), "t0", 11);
|
2274
|
+
case 11:
|
2275
|
+
_i2++;
|
2276
|
+
_context6.next = 9;
|
2277
|
+
break;
|
2278
|
+
case 14:
|
2279
|
+
// For all updated subscribers: set new module data and emit change
|
2280
|
+
for (_i3 = 0, _Array$from2 = Array.from(updatedSubscriberIds.entries()); _i3 < _Array$from2.length; _i3++) {
|
2281
|
+
_Array$from2$_i = _slicedToArray(_Array$from2[_i3], 2), updatedSubscriberId = _Array$from2$_i[0], _moduleIds = _Array$from2$_i[1];
|
2282
|
+
subscriberModules = Object.fromEntries(_moduleIds.flatMap(function (moduleId) {
|
2283
|
+
var source = data.value.modules[moduleId].source;
|
2284
|
+
if (!source) {
|
2285
|
+
return [];
|
2286
|
+
}
|
2287
|
+
return [[moduleId, source]];
|
2288
|
+
}));
|
2289
|
+
this.subscribers.set(updatedSubscriberId, subscriberModules);
|
2290
|
+
this.emitChange(updatedSubscriberId);
|
2291
|
+
}
|
2292
|
+
return _context6.abrupt("return", result.ok(moduleIds));
|
2293
|
+
case 18:
|
2294
|
+
msg = "Failed to fetch content. ";
|
2295
|
+
if (data.error.statusCode === 401) {
|
2296
|
+
msg += "Authorization failed - check that you are logged in.";
|
2297
|
+
} else {
|
2298
|
+
msg += "Get a developer to verify that Val is correctly setup.";
|
2299
|
+
}
|
2300
|
+
return _context6.abrupt("return", result.err({
|
2301
|
+
message: msg,
|
2302
|
+
details: {
|
2303
|
+
fetchError: data.error
|
2304
|
+
}
|
2305
|
+
}));
|
2306
|
+
case 21:
|
2307
|
+
case "end":
|
2308
|
+
return _context6.stop();
|
2309
|
+
}
|
2310
|
+
}, _callee5, this);
|
2311
|
+
}));
|
2312
|
+
function updateTree(_x5) {
|
2313
|
+
return _updateTree.apply(this, arguments);
|
2314
|
+
}
|
2315
|
+
return updateTree;
|
2316
|
+
}()
|
2317
|
+
}, {
|
2318
|
+
key: "emitChange",
|
2319
|
+
value: function emitChange(subscriberId) {
|
2320
|
+
var _iterator = _createForOfIteratorHelper(this.listeners[subscriberId]),
|
2321
|
+
_step;
|
2322
|
+
try {
|
2323
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
2324
|
+
var listener = _step.value;
|
2325
|
+
listener();
|
2326
|
+
}
|
2327
|
+
} catch (err) {
|
2328
|
+
_iterator.e(err);
|
2329
|
+
} finally {
|
2330
|
+
_iterator.f();
|
2331
|
+
}
|
2332
|
+
}
|
2333
|
+
}]);
|
2334
|
+
return ValStore;
|
2335
|
+
}();
|
2336
|
+
function createSubscriberId(moduleIds) {
|
2337
|
+
return moduleIds.slice().sort().join("&");
|
2338
|
+
}
|
2339
|
+
|
2340
|
+
export { EXT_TO_MIME_TYPES, MIME_TYPES_TO_EXT, RemirrorBr, RemirrorBulletList, RemirrorHeading, RemirrorImage, RemirrorJSON, RemirrorLinkMark, RemirrorListItem, RemirrorOrderedList, RemirrorParagraph, RemirrorText, RemirrorTextMark, VAL_ENABLE_COOKIE_NAME, VAL_SESSION_COOKIE, VAL_STATE_COOKIE, ValStore, filenameToMimeType, getMimeType, mimeTypeToFileExt, parseRichTextSource, remirrorToRichTextSource, richTextToRemirror };
|