@kirejs/h3 0.2.3 → 0.2.5
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/AGENT.md +27 -0
- package/README.md +13 -0
- package/dist/cjs/index.js +275 -217
- package/dist/esm/index.js +276 -218
- package/dist/types/types.d.ts +23 -0
- package/llms.txt +48 -0
- package/package.json +7 -3
package/dist/esm/index.js
CHANGED
|
@@ -831,7 +831,7 @@ var init_builtins = __esm(() => {
|
|
|
831
831
|
});
|
|
832
832
|
|
|
833
833
|
// packages/wire/src/kirewire.ts
|
|
834
|
-
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
834
|
+
import { randomBytes, randomUUID as randomUUID2 } from "node:crypto";
|
|
835
835
|
function serializeSnapshotAttr(snapshot) {
|
|
836
836
|
return JSON.stringify(snapshot).replace(/&/g, "&").replace(/'/g, "'");
|
|
837
837
|
}
|
|
@@ -850,9 +850,12 @@ class Kirewire {
|
|
|
850
850
|
features;
|
|
851
851
|
broadcaster;
|
|
852
852
|
constructor(opts) {
|
|
853
|
-
if (
|
|
854
|
-
|
|
855
|
-
|
|
853
|
+
if (opts.secret) {
|
|
854
|
+
this.secret = opts.secret;
|
|
855
|
+
} else {
|
|
856
|
+
this.secret = randomBytes(32).toString("hex");
|
|
857
|
+
console.warn("[kirewire] No `secret` provided; using a random per-process secret. " + "Set a stable `secret` in production (and across instances) so component " + "snapshots verify after restarts.");
|
|
858
|
+
}
|
|
856
859
|
this.synth = opts.synth ?? createDefaultSynthRegistry();
|
|
857
860
|
this.registry = opts.registry ?? new ComponentRegistry;
|
|
858
861
|
this.features = opts.features ?? createDefaultFeatures();
|
|
@@ -1392,18 +1395,37 @@ function kirewirePlugin(kirewire, options = {}) {
|
|
|
1392
1395
|
}
|
|
1393
1396
|
const scriptUrl = options.scriptUrl ?? "/kirewire.js";
|
|
1394
1397
|
const updatePath = options.path ?? "/_wire";
|
|
1398
|
+
const wsAttr = options.wsPath ? ` data-kirewire-ws="${options.wsPath}"` : "";
|
|
1399
|
+
const channelAttr = options.channel ? ` data-kirewire-channel="${options.channel}"` : "";
|
|
1395
1400
|
kire.directive({
|
|
1396
1401
|
name: "kirewireScripts",
|
|
1397
1402
|
description: "Inject the Kirewire client runtime script tag.",
|
|
1398
1403
|
example: "@kirewireScripts",
|
|
1399
1404
|
onCall: (api) => {
|
|
1400
|
-
api.append(`<script src="${scriptUrl}" data-kirewire-url="${updatePath}" defer></script>`);
|
|
1405
|
+
api.append(`<script src="${scriptUrl}" data-kirewire-url="${updatePath}"${wsAttr}${channelAttr} defer></script>`);
|
|
1401
1406
|
}
|
|
1402
1407
|
});
|
|
1403
1408
|
}
|
|
1404
1409
|
};
|
|
1405
1410
|
}
|
|
1406
1411
|
|
|
1412
|
+
// packages/wire/src/server/fivem.ts
|
|
1413
|
+
function createFiveMHandler(kirewire, engineFactory) {
|
|
1414
|
+
return (data, cb) => {
|
|
1415
|
+
Promise.resolve(kirewire.handle(data, engineFactory?.())).then((response) => cb(response)).catch(() => cb({ v: 1, components: [] }));
|
|
1416
|
+
};
|
|
1417
|
+
}
|
|
1418
|
+
|
|
1419
|
+
class FiveMBroadcaster {
|
|
1420
|
+
sendNuiMessage;
|
|
1421
|
+
constructor(sendNuiMessage) {
|
|
1422
|
+
this.sendNuiMessage = sendNuiMessage;
|
|
1423
|
+
}
|
|
1424
|
+
publish(push) {
|
|
1425
|
+
this.sendNuiMessage(JSON.stringify({ type: "kirewire:push", push }));
|
|
1426
|
+
}
|
|
1427
|
+
}
|
|
1428
|
+
|
|
1407
1429
|
// packages/wire/src/server/hub.ts
|
|
1408
1430
|
class Hub {
|
|
1409
1431
|
byChannel = new Map;
|
|
@@ -1449,23 +1471,6 @@ function serveWs(kirewire, hub, conn, options = {}) {
|
|
|
1449
1471
|
}
|
|
1450
1472
|
}
|
|
1451
1473
|
|
|
1452
|
-
// packages/wire/src/server/fivem.ts
|
|
1453
|
-
function createFiveMHandler(kirewire, engineFactory) {
|
|
1454
|
-
return (data, cb) => {
|
|
1455
|
-
Promise.resolve(kirewire.handle(data, engineFactory?.())).then((response) => cb(response)).catch(() => cb({ v: 1, components: [] }));
|
|
1456
|
-
};
|
|
1457
|
-
}
|
|
1458
|
-
|
|
1459
|
-
class FiveMBroadcaster {
|
|
1460
|
-
sendNuiMessage;
|
|
1461
|
-
constructor(sendNuiMessage) {
|
|
1462
|
-
this.sendNuiMessage = sendNuiMessage;
|
|
1463
|
-
}
|
|
1464
|
-
publish(push) {
|
|
1465
|
-
this.sendNuiMessage(JSON.stringify({ type: "kirewire:push", push }));
|
|
1466
|
-
}
|
|
1467
|
-
}
|
|
1468
|
-
|
|
1469
1474
|
// packages/wire/src/server/index.ts
|
|
1470
1475
|
var init_server = __esm(() => {
|
|
1471
1476
|
init_http();
|
|
@@ -1594,6 +1599,170 @@ var init_src = __esm(() => {
|
|
|
1594
1599
|
init_class();
|
|
1595
1600
|
});
|
|
1596
1601
|
|
|
1602
|
+
// core/src/utils/regex.ts
|
|
1603
|
+
var NullProtoObj = function() {
|
|
1604
|
+
return Object.create(null);
|
|
1605
|
+
};
|
|
1606
|
+
var TAG_OPEN_REGEX = /^<([a-zA-Z0-9_\-:.]+)/;
|
|
1607
|
+
var TAG_CLOSE_REGEX = /^<\/([a-zA-Z0-9_\-:.]+)>/;
|
|
1608
|
+
var ATTR_NAME_BREAK_REGEX = /\s|=|>|\/|\(/;
|
|
1609
|
+
var WHITESPACE_REGEX = /\s/;
|
|
1610
|
+
var HTML_VOID_TAGS = new Set([
|
|
1611
|
+
"area",
|
|
1612
|
+
"base",
|
|
1613
|
+
"br",
|
|
1614
|
+
"col",
|
|
1615
|
+
"embed",
|
|
1616
|
+
"hr",
|
|
1617
|
+
"img",
|
|
1618
|
+
"input",
|
|
1619
|
+
"link",
|
|
1620
|
+
"meta",
|
|
1621
|
+
"param",
|
|
1622
|
+
"source",
|
|
1623
|
+
"track",
|
|
1624
|
+
"wbr"
|
|
1625
|
+
]);
|
|
1626
|
+
var DIRECTIVE_NAME_REGEX = /^@([a-zA-Z0-9_\-.:]+)/;
|
|
1627
|
+
var JS_IDENTIFIER_REGEX = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/;
|
|
1628
|
+
var INTERPOLATION_PURE_REGEX = /^\s*\{\{\s*(.*?)\s*\}\}\s*$/;
|
|
1629
|
+
var INTERPOLATION_GLOBAL_REGEX = /\{\{\s*(.*?)\s*\}\}/g;
|
|
1630
|
+
var RESERVED_KEYWORDS_REGEX = /^(?:break|case|catch|class|const|continue|debugger|default|delete|do|else|export|extends|finally|for|function|if|import|in|instanceof|new|return|super|switch|this|throw|try|typeof|var|void|while|with|yield|enum|await|true|false|null|of)$/;
|
|
1631
|
+
var HTML_ESCAPE_CHECK_REGEX = /[&<>"']/;
|
|
1632
|
+
var HTML_ESCAPE_GLOBAL_REGEX = /[&<>"']/g;
|
|
1633
|
+
var INTERPOLATION_START_REGEX = /{{/;
|
|
1634
|
+
var WILDCARD_CHAR_REGEX = /\*/;
|
|
1635
|
+
var AWAIT_KEYWORD_REGEX = /\bawait\b/g;
|
|
1636
|
+
var QUOTED_STR_CHECK_REGEX = /^['"]/;
|
|
1637
|
+
var STRIP_QUOTES_REGEX = /^['"]|['"]$/g;
|
|
1638
|
+
function createFastMatcher(list) {
|
|
1639
|
+
const sources = list.map((item) => {
|
|
1640
|
+
if (item instanceof RegExp)
|
|
1641
|
+
return item.source;
|
|
1642
|
+
if (item.includes("*")) {
|
|
1643
|
+
const parts = item.split("*");
|
|
1644
|
+
const escapedParts = parts.map((p) => p.replace(/[.*+?^${}()|[\]\\]/g, (m) => `\\${m}`));
|
|
1645
|
+
return escapedParts.join(".*");
|
|
1646
|
+
}
|
|
1647
|
+
return item.replace(/[.*+?^${}()|[\]\\]/g, (m) => `\\${m}`);
|
|
1648
|
+
});
|
|
1649
|
+
sources.sort((a, b) => b.length - a.length);
|
|
1650
|
+
return new RegExp(`(?:${sources.join("|")})`);
|
|
1651
|
+
}
|
|
1652
|
+
|
|
1653
|
+
// core/src/utils/html.ts
|
|
1654
|
+
var ESCAPE_MAP = {
|
|
1655
|
+
"&": "&",
|
|
1656
|
+
"<": "<",
|
|
1657
|
+
">": ">",
|
|
1658
|
+
'"': """,
|
|
1659
|
+
"'": "'"
|
|
1660
|
+
};
|
|
1661
|
+
function escapeHtml(unsafe) {
|
|
1662
|
+
if (unsafe === null || unsafe === undefined)
|
|
1663
|
+
return "";
|
|
1664
|
+
const type = typeof unsafe;
|
|
1665
|
+
if (type === "number" || type === "boolean")
|
|
1666
|
+
return String(unsafe);
|
|
1667
|
+
if (type === "object" && typeof unsafe.toHtml === "function") {
|
|
1668
|
+
return unsafe.toHtml();
|
|
1669
|
+
}
|
|
1670
|
+
const s = type === "string" ? unsafe : String(unsafe);
|
|
1671
|
+
const n = s.length;
|
|
1672
|
+
if (n <= 16) {
|
|
1673
|
+
for (let i = 0;i < n; i++) {
|
|
1674
|
+
const c = s.charCodeAt(i);
|
|
1675
|
+
if (c === 38 || c === 60 || c === 62 || c === 34 || c === 39) {
|
|
1676
|
+
return s.replace(HTML_ESCAPE_GLOBAL_REGEX, (m) => ESCAPE_MAP[m]);
|
|
1677
|
+
}
|
|
1678
|
+
}
|
|
1679
|
+
return s;
|
|
1680
|
+
}
|
|
1681
|
+
if (!HTML_ESCAPE_CHECK_REGEX.test(s))
|
|
1682
|
+
return s;
|
|
1683
|
+
return s.replace(HTML_ESCAPE_GLOBAL_REGEX, (m) => ESCAPE_MAP[m]);
|
|
1684
|
+
}
|
|
1685
|
+
|
|
1686
|
+
// core/src/compiler/attr-codegen.ts
|
|
1687
|
+
class AttrCodegen {
|
|
1688
|
+
scanner;
|
|
1689
|
+
onAsync;
|
|
1690
|
+
usesEscape = false;
|
|
1691
|
+
mixedAttrIdents = new Set;
|
|
1692
|
+
interpRx = new RegExp(INTERPOLATION_GLOBAL_REGEX.source, "g");
|
|
1693
|
+
constructor(scanner, onAsync) {
|
|
1694
|
+
this.scanner = scanner;
|
|
1695
|
+
this.onAsync = onAsync;
|
|
1696
|
+
}
|
|
1697
|
+
reset() {
|
|
1698
|
+
this.usesEscape = false;
|
|
1699
|
+
this.mixedAttrIdents.clear();
|
|
1700
|
+
}
|
|
1701
|
+
esc(str) {
|
|
1702
|
+
return "`" + str.replace(/\\/g, "\\\\").replace(/`/g, "\\`").replace(/\$/g, "\\$") + "`";
|
|
1703
|
+
}
|
|
1704
|
+
escapeChunk(str) {
|
|
1705
|
+
return str.replace(/\\/g, "\\\\").replace(/`/g, "\\`").replace(/\$/g, "\\$");
|
|
1706
|
+
}
|
|
1707
|
+
parseAttrCode(val) {
|
|
1708
|
+
if (!INTERPOLATION_START_REGEX.test(val))
|
|
1709
|
+
return val;
|
|
1710
|
+
const pureMatch = val.match(INTERPOLATION_PURE_REGEX);
|
|
1711
|
+
if (pureMatch)
|
|
1712
|
+
return pureMatch[1];
|
|
1713
|
+
this.usesEscape = true;
|
|
1714
|
+
const res = val.replace(INTERPOLATION_GLOBAL_REGEX, (_, expr) => {
|
|
1715
|
+
this.collectExpressionIdents(expr);
|
|
1716
|
+
return `\${$escape(${expr})}`;
|
|
1717
|
+
});
|
|
1718
|
+
return `\`${res}\``;
|
|
1719
|
+
}
|
|
1720
|
+
parseHtmlAttrCode(val) {
|
|
1721
|
+
if (!INTERPOLATION_START_REGEX.test(val))
|
|
1722
|
+
return this.esc(escapeHtml(val));
|
|
1723
|
+
const pureMatch = val.match(INTERPOLATION_PURE_REGEX);
|
|
1724
|
+
if (pureMatch) {
|
|
1725
|
+
const expr = pureMatch[1];
|
|
1726
|
+
if (this.scanner.containsAwait(expr))
|
|
1727
|
+
this.onAsync();
|
|
1728
|
+
this.usesEscape = true;
|
|
1729
|
+
return `$escape(${expr})`;
|
|
1730
|
+
}
|
|
1731
|
+
this.usesEscape = true;
|
|
1732
|
+
let out = "";
|
|
1733
|
+
let lastIndex = 0;
|
|
1734
|
+
const rx = this.interpRx;
|
|
1735
|
+
rx.lastIndex = 0;
|
|
1736
|
+
let match;
|
|
1737
|
+
while ((match = rx.exec(val)) !== null) {
|
|
1738
|
+
const literalChunk = val.slice(lastIndex, match.index);
|
|
1739
|
+
if (literalChunk)
|
|
1740
|
+
out += this.escapeChunk(escapeHtml(literalChunk));
|
|
1741
|
+
const expr = match[1] || "";
|
|
1742
|
+
this.collectExpressionIdents(expr);
|
|
1743
|
+
if (this.scanner.containsAwait(expr))
|
|
1744
|
+
this.onAsync();
|
|
1745
|
+
out += `\${$escape(${expr})}`;
|
|
1746
|
+
lastIndex = match.index + match[0].length;
|
|
1747
|
+
}
|
|
1748
|
+
const tail = val.slice(lastIndex);
|
|
1749
|
+
if (tail)
|
|
1750
|
+
out += this.escapeChunk(escapeHtml(tail));
|
|
1751
|
+
return `\`${out}\``;
|
|
1752
|
+
}
|
|
1753
|
+
collectExpressionIdents(expr) {
|
|
1754
|
+
const rx = /[a-zA-Z_$][a-zA-Z0-9_$]*/g;
|
|
1755
|
+
let m;
|
|
1756
|
+
while ((m = rx.exec(expr)) !== null) {
|
|
1757
|
+
const id = m[0];
|
|
1758
|
+
if (RESERVED_KEYWORDS_REGEX.test(id))
|
|
1759
|
+
continue;
|
|
1760
|
+
if (expr[m.index - 1] === ".")
|
|
1761
|
+
continue;
|
|
1762
|
+
this.mixedAttrIdents.add(id);
|
|
1763
|
+
}
|
|
1764
|
+
}
|
|
1765
|
+
}
|
|
1597
1766
|
// core/src/lexer/balance.ts
|
|
1598
1767
|
function findInterpolationEnd(template, from, close) {
|
|
1599
1768
|
let inQuote = null;
|
|
@@ -1716,90 +1885,6 @@ function parseArgs(argsStr) {
|
|
|
1716
1885
|
return args;
|
|
1717
1886
|
}
|
|
1718
1887
|
|
|
1719
|
-
// core/src/utils/regex.ts
|
|
1720
|
-
var NullProtoObj = function() {
|
|
1721
|
-
return Object.create(null);
|
|
1722
|
-
};
|
|
1723
|
-
var TAG_OPEN_REGEX = /^<([a-zA-Z0-9_\-:.]+)/;
|
|
1724
|
-
var TAG_CLOSE_REGEX = /^<\/([a-zA-Z0-9_\-:.]+)>/;
|
|
1725
|
-
var ATTR_NAME_BREAK_REGEX = /\s|=|>|\/|\(/;
|
|
1726
|
-
var WHITESPACE_REGEX = /\s/;
|
|
1727
|
-
var HTML_VOID_TAGS = new Set([
|
|
1728
|
-
"area",
|
|
1729
|
-
"base",
|
|
1730
|
-
"br",
|
|
1731
|
-
"col",
|
|
1732
|
-
"embed",
|
|
1733
|
-
"hr",
|
|
1734
|
-
"img",
|
|
1735
|
-
"input",
|
|
1736
|
-
"link",
|
|
1737
|
-
"meta",
|
|
1738
|
-
"param",
|
|
1739
|
-
"source",
|
|
1740
|
-
"track",
|
|
1741
|
-
"wbr"
|
|
1742
|
-
]);
|
|
1743
|
-
var DIRECTIVE_NAME_REGEX = /^@([a-zA-Z0-9_\-.:]+)/;
|
|
1744
|
-
var JS_IDENTIFIER_REGEX = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/;
|
|
1745
|
-
var INTERPOLATION_PURE_REGEX = /^\s*\{\{\s*(.*?)\s*\}\}\s*$/;
|
|
1746
|
-
var INTERPOLATION_GLOBAL_REGEX = /\{\{\s*(.*?)\s*\}\}/g;
|
|
1747
|
-
var RESERVED_KEYWORDS_REGEX = /^(?:break|case|catch|class|const|continue|debugger|default|delete|do|else|export|extends|finally|for|function|if|import|in|instanceof|new|return|super|switch|this|throw|try|typeof|var|void|while|with|yield|enum|await|true|false|null|of)$/;
|
|
1748
|
-
var HTML_ESCAPE_CHECK_REGEX = /[&<>"']/;
|
|
1749
|
-
var HTML_ESCAPE_GLOBAL_REGEX = /[&<>"']/g;
|
|
1750
|
-
var INTERPOLATION_START_REGEX = /{{/;
|
|
1751
|
-
var WILDCARD_CHAR_REGEX = /\*/;
|
|
1752
|
-
var AWAIT_KEYWORD_REGEX = /\bawait\b/g;
|
|
1753
|
-
var QUOTED_STR_CHECK_REGEX = /^['"]/;
|
|
1754
|
-
var STRIP_QUOTES_REGEX = /^['"]|['"]$/g;
|
|
1755
|
-
function createFastMatcher(list) {
|
|
1756
|
-
const sources = list.map((item) => {
|
|
1757
|
-
if (item instanceof RegExp)
|
|
1758
|
-
return item.source;
|
|
1759
|
-
if (item.includes("*")) {
|
|
1760
|
-
const parts = item.split("*");
|
|
1761
|
-
const escapedParts = parts.map((p) => p.replace(/[.*+?^${}()|[\]\\]/g, (m) => `\\${m}`));
|
|
1762
|
-
return escapedParts.join(".*");
|
|
1763
|
-
}
|
|
1764
|
-
return item.replace(/[.*+?^${}()|[\]\\]/g, (m) => `\\${m}`);
|
|
1765
|
-
});
|
|
1766
|
-
sources.sort((a, b) => b.length - a.length);
|
|
1767
|
-
return new RegExp(`(?:${sources.join("|")})`);
|
|
1768
|
-
}
|
|
1769
|
-
|
|
1770
|
-
// core/src/utils/html.ts
|
|
1771
|
-
var ESCAPE_MAP = {
|
|
1772
|
-
"&": "&",
|
|
1773
|
-
"<": "<",
|
|
1774
|
-
">": ">",
|
|
1775
|
-
'"': """,
|
|
1776
|
-
"'": "'"
|
|
1777
|
-
};
|
|
1778
|
-
function escapeHtml(unsafe) {
|
|
1779
|
-
if (unsafe === null || unsafe === undefined)
|
|
1780
|
-
return "";
|
|
1781
|
-
const type = typeof unsafe;
|
|
1782
|
-
if (type === "number" || type === "boolean")
|
|
1783
|
-
return String(unsafe);
|
|
1784
|
-
if (type === "object" && typeof unsafe.toHtml === "function") {
|
|
1785
|
-
return unsafe.toHtml();
|
|
1786
|
-
}
|
|
1787
|
-
const s = type === "string" ? unsafe : String(unsafe);
|
|
1788
|
-
const n = s.length;
|
|
1789
|
-
if (n <= 16) {
|
|
1790
|
-
for (let i = 0;i < n; i++) {
|
|
1791
|
-
const c = s.charCodeAt(i);
|
|
1792
|
-
if (c === 38 || c === 60 || c === 62 || c === 34 || c === 39) {
|
|
1793
|
-
return s.replace(HTML_ESCAPE_GLOBAL_REGEX, (m) => ESCAPE_MAP[m]);
|
|
1794
|
-
}
|
|
1795
|
-
}
|
|
1796
|
-
return s;
|
|
1797
|
-
}
|
|
1798
|
-
if (!HTML_ESCAPE_CHECK_REGEX.test(s))
|
|
1799
|
-
return s;
|
|
1800
|
-
return s.replace(HTML_ESCAPE_GLOBAL_REGEX, (m) => ESCAPE_MAP[m]);
|
|
1801
|
-
}
|
|
1802
|
-
|
|
1803
1888
|
// core/src/utils/base64.ts
|
|
1804
1889
|
function hasNodeBuffer() {
|
|
1805
1890
|
return typeof Buffer !== "undefined" && typeof Buffer.from === "function";
|
|
@@ -1990,87 +2075,6 @@ function resolveSourceLocation(map, genLine, genCol) {
|
|
|
1990
2075
|
return bestMatch;
|
|
1991
2076
|
}
|
|
1992
2077
|
|
|
1993
|
-
// core/src/compiler/attr-codegen.ts
|
|
1994
|
-
class AttrCodegen {
|
|
1995
|
-
scanner;
|
|
1996
|
-
onAsync;
|
|
1997
|
-
usesEscape = false;
|
|
1998
|
-
mixedAttrIdents = new Set;
|
|
1999
|
-
interpRx = new RegExp(INTERPOLATION_GLOBAL_REGEX.source, "g");
|
|
2000
|
-
constructor(scanner, onAsync) {
|
|
2001
|
-
this.scanner = scanner;
|
|
2002
|
-
this.onAsync = onAsync;
|
|
2003
|
-
}
|
|
2004
|
-
reset() {
|
|
2005
|
-
this.usesEscape = false;
|
|
2006
|
-
this.mixedAttrIdents.clear();
|
|
2007
|
-
}
|
|
2008
|
-
esc(str) {
|
|
2009
|
-
return "`" + str.replace(/\\/g, "\\\\").replace(/`/g, "\\`").replace(/\$/g, "\\$") + "`";
|
|
2010
|
-
}
|
|
2011
|
-
escapeChunk(str) {
|
|
2012
|
-
return str.replace(/\\/g, "\\\\").replace(/`/g, "\\`").replace(/\$/g, "\\$");
|
|
2013
|
-
}
|
|
2014
|
-
parseAttrCode(val) {
|
|
2015
|
-
if (!INTERPOLATION_START_REGEX.test(val))
|
|
2016
|
-
return val;
|
|
2017
|
-
const pureMatch = val.match(INTERPOLATION_PURE_REGEX);
|
|
2018
|
-
if (pureMatch)
|
|
2019
|
-
return pureMatch[1];
|
|
2020
|
-
this.usesEscape = true;
|
|
2021
|
-
const res = val.replace(INTERPOLATION_GLOBAL_REGEX, (_, expr) => {
|
|
2022
|
-
this.collectExpressionIdents(expr);
|
|
2023
|
-
return `\${$escape(${expr})}`;
|
|
2024
|
-
});
|
|
2025
|
-
return "`" + res + "`";
|
|
2026
|
-
}
|
|
2027
|
-
parseHtmlAttrCode(val) {
|
|
2028
|
-
if (!INTERPOLATION_START_REGEX.test(val))
|
|
2029
|
-
return this.esc(escapeHtml(val));
|
|
2030
|
-
const pureMatch = val.match(INTERPOLATION_PURE_REGEX);
|
|
2031
|
-
if (pureMatch) {
|
|
2032
|
-
const expr = pureMatch[1];
|
|
2033
|
-
if (this.scanner.containsAwait(expr))
|
|
2034
|
-
this.onAsync();
|
|
2035
|
-
this.usesEscape = true;
|
|
2036
|
-
return `$escape(${expr})`;
|
|
2037
|
-
}
|
|
2038
|
-
this.usesEscape = true;
|
|
2039
|
-
let out = "";
|
|
2040
|
-
let lastIndex = 0;
|
|
2041
|
-
const rx = this.interpRx;
|
|
2042
|
-
rx.lastIndex = 0;
|
|
2043
|
-
let match;
|
|
2044
|
-
while ((match = rx.exec(val)) !== null) {
|
|
2045
|
-
const literalChunk = val.slice(lastIndex, match.index);
|
|
2046
|
-
if (literalChunk)
|
|
2047
|
-
out += this.escapeChunk(escapeHtml(literalChunk));
|
|
2048
|
-
const expr = match[1] || "";
|
|
2049
|
-
this.collectExpressionIdents(expr);
|
|
2050
|
-
if (this.scanner.containsAwait(expr))
|
|
2051
|
-
this.onAsync();
|
|
2052
|
-
out += `\${$escape(${expr})}`;
|
|
2053
|
-
lastIndex = match.index + match[0].length;
|
|
2054
|
-
}
|
|
2055
|
-
const tail = val.slice(lastIndex);
|
|
2056
|
-
if (tail)
|
|
2057
|
-
out += this.escapeChunk(escapeHtml(tail));
|
|
2058
|
-
return "`" + out + "`";
|
|
2059
|
-
}
|
|
2060
|
-
collectExpressionIdents(expr) {
|
|
2061
|
-
const rx = /[a-zA-Z_$][a-zA-Z0-9_$]*/g;
|
|
2062
|
-
let m;
|
|
2063
|
-
while ((m = rx.exec(expr)) !== null) {
|
|
2064
|
-
const id = m[0];
|
|
2065
|
-
if (RESERVED_KEYWORDS_REGEX.test(id))
|
|
2066
|
-
continue;
|
|
2067
|
-
if (expr[m.index - 1] === ".")
|
|
2068
|
-
continue;
|
|
2069
|
-
this.mixedAttrIdents.add(id);
|
|
2070
|
-
}
|
|
2071
|
-
}
|
|
2072
|
-
}
|
|
2073
|
-
|
|
2074
2078
|
// core/src/compiler/js-scanner.ts
|
|
2075
2079
|
class JsScanner {
|
|
2076
2080
|
containsAwait(code) {
|
|
@@ -4411,7 +4415,14 @@ var checks_default = (kire) => {
|
|
|
4411
4415
|
signature: [`expr:any`],
|
|
4412
4416
|
children: true,
|
|
4413
4417
|
relatedTo: [`for`, `each`, `foreach`, `forelse`],
|
|
4414
|
-
closeBy: [
|
|
4418
|
+
closeBy: [
|
|
4419
|
+
`endempty`,
|
|
4420
|
+
`endfor`,
|
|
4421
|
+
`endeach`,
|
|
4422
|
+
`endforeach`,
|
|
4423
|
+
`endforelse`,
|
|
4424
|
+
`end`
|
|
4425
|
+
],
|
|
4415
4426
|
description: "Fallback branch for empty collections or falsy values, often used alongside @for or @each.",
|
|
4416
4427
|
example: `@empty(items)
|
|
4417
4428
|
<p>No items</p>
|
|
@@ -4627,7 +4638,6 @@ var loop_default = (kire) => {
|
|
|
4627
4638
|
const id = api.uid("fe");
|
|
4628
4639
|
const relatedNodes = api.node.related || [];
|
|
4629
4640
|
const hasEmptyBranch = relatedNodes.some((n) => n?.name === "empty");
|
|
4630
|
-
const exposeKey = key ? true : api.fullBody.includes("$loop") || api.allIdentifiers.has("$loop");
|
|
4631
4641
|
const exposeLoop = api.fullBody.includes("$loop") || api.allIdentifiers.has("$loop");
|
|
4632
4642
|
api.write(`{
|
|
4633
4643
|
const _src${id} = ${source};
|
|
@@ -5051,7 +5061,6 @@ var KireDirectives = {
|
|
|
5051
5061
|
natives_default(kire);
|
|
5052
5062
|
}
|
|
5053
5063
|
};
|
|
5054
|
-
|
|
5055
5064
|
// core/src/lexer/cursor.ts
|
|
5056
5065
|
class Cursor {
|
|
5057
5066
|
template;
|
|
@@ -5115,7 +5124,6 @@ class Cursor {
|
|
|
5115
5124
|
this.column = this.baseColumn;
|
|
5116
5125
|
}
|
|
5117
5126
|
}
|
|
5118
|
-
|
|
5119
5127
|
// core/src/lexer/lexer.ts
|
|
5120
5128
|
class Lexer extends Cursor {
|
|
5121
5129
|
kire;
|
|
@@ -5385,7 +5393,13 @@ class Lexer extends Cursor {
|
|
|
5385
5393
|
this.reportError(hasOpenDirective ? `@${rawName} does not close the current block` : `@${rawName} has no matching opening directive`, this.cursor, this.cursor + rawName.length + 1, loc);
|
|
5386
5394
|
}
|
|
5387
5395
|
this.advance(rawName.length + 1);
|
|
5388
|
-
this.addNode({
|
|
5396
|
+
this.addNode({
|
|
5397
|
+
type: "directive",
|
|
5398
|
+
name: rawName,
|
|
5399
|
+
args: [],
|
|
5400
|
+
children: [],
|
|
5401
|
+
loc
|
|
5402
|
+
});
|
|
5389
5403
|
return true;
|
|
5390
5404
|
}
|
|
5391
5405
|
const name = matchedName;
|
|
@@ -5674,7 +5688,11 @@ class Lexer extends Cursor {
|
|
|
5674
5688
|
end++;
|
|
5675
5689
|
}
|
|
5676
5690
|
if (end > this.cursor) {
|
|
5677
|
-
this.addNode({
|
|
5691
|
+
this.addNode({
|
|
5692
|
+
type: "text",
|
|
5693
|
+
content: this.slice(this.cursor, end),
|
|
5694
|
+
loc
|
|
5695
|
+
});
|
|
5678
5696
|
this.advance(end - this.cursor);
|
|
5679
5697
|
} else {
|
|
5680
5698
|
this.addNode({ type: "text", content: this.char(), loc });
|
|
@@ -5725,29 +5743,6 @@ function createKireFunction(_kire, execute, meta) {
|
|
|
5725
5743
|
return fn;
|
|
5726
5744
|
}
|
|
5727
5745
|
|
|
5728
|
-
// core/src/utils/browser.ts
|
|
5729
|
-
var throwNoAPI = (name) => {
|
|
5730
|
-
return () => {
|
|
5731
|
-
throw new Error(`Platform API '${name}' is not available in browser. Provide it via store or use virtual files.`);
|
|
5732
|
-
};
|
|
5733
|
-
};
|
|
5734
|
-
var platform = {
|
|
5735
|
-
readFile: throwNoAPI("readFile"),
|
|
5736
|
-
exists: () => false,
|
|
5737
|
-
readDir: throwNoAPI("readDir"),
|
|
5738
|
-
stat: throwNoAPI("stat"),
|
|
5739
|
-
writeFile: throwNoAPI("writeFile"),
|
|
5740
|
-
resolve: (...args) => args.join("/").replace(/\/+/g, "/"),
|
|
5741
|
-
join: (...args) => args.join("/").replace(/\/+/g, "/"),
|
|
5742
|
-
isAbsolute: (path) => path.startsWith("/") || path.startsWith("http"),
|
|
5743
|
-
relative: (_from, to) => to,
|
|
5744
|
-
cwd: () => "/",
|
|
5745
|
-
env: (_key) => {
|
|
5746
|
-
return;
|
|
5747
|
-
},
|
|
5748
|
-
isProd: () => false
|
|
5749
|
-
};
|
|
5750
|
-
|
|
5751
5746
|
// core/src/utils/attributes-bag.ts
|
|
5752
5747
|
function classString(input) {
|
|
5753
5748
|
if (input == null || input === false)
|
|
@@ -5885,6 +5880,29 @@ function createAttributes(attrs = {}) {
|
|
|
5885
5880
|
return new KireAttributes(attrs);
|
|
5886
5881
|
}
|
|
5887
5882
|
|
|
5883
|
+
// core/src/utils/browser.ts
|
|
5884
|
+
var throwNoAPI = (name) => {
|
|
5885
|
+
return () => {
|
|
5886
|
+
throw new Error(`Platform API '${name}' is not available in browser. Provide it via store or use virtual files.`);
|
|
5887
|
+
};
|
|
5888
|
+
};
|
|
5889
|
+
var platform = {
|
|
5890
|
+
readFile: throwNoAPI("readFile"),
|
|
5891
|
+
exists: () => false,
|
|
5892
|
+
readDir: throwNoAPI("readDir"),
|
|
5893
|
+
stat: throwNoAPI("stat"),
|
|
5894
|
+
writeFile: throwNoAPI("writeFile"),
|
|
5895
|
+
resolve: (...args) => args.join("/").replace(/\/+/g, "/"),
|
|
5896
|
+
join: (...args) => args.join("/").replace(/\/+/g, "/"),
|
|
5897
|
+
isAbsolute: (path) => path.startsWith("/") || path.startsWith("http"),
|
|
5898
|
+
relative: (_from, to) => to,
|
|
5899
|
+
cwd: () => "/",
|
|
5900
|
+
env: (_key) => {
|
|
5901
|
+
return;
|
|
5902
|
+
},
|
|
5903
|
+
isProd: () => false
|
|
5904
|
+
};
|
|
5905
|
+
|
|
5888
5906
|
// core/src/utils/error.ts
|
|
5889
5907
|
var SOURCE_MAP_PREFIX = "//# sourceMappingURL=data:application/json;charset=utf-8;base64,";
|
|
5890
5908
|
var STACK_FRAME_REGEX = /^\s*at\s+(?:(.*?)\s+\()?(.+?):(\d+):(\d+)\)?$/;
|
|
@@ -7129,7 +7147,14 @@ function prepareInlineWire(engine, wire) {
|
|
|
7129
7147
|
const wirePkg = requireWire();
|
|
7130
7148
|
const wirePath = wire.path ?? "/_wire";
|
|
7131
7149
|
const scriptUrl = wire.scriptUrl ?? "/kirewire.js";
|
|
7132
|
-
|
|
7150
|
+
const ws = resolveWs(wire);
|
|
7151
|
+
const wsActive = ws ? attachNodeWs(wirePkg, wire.instance, ws) : false;
|
|
7152
|
+
engine.plugin(wirePkg.kirewirePlugin(wire.instance, {
|
|
7153
|
+
scriptUrl,
|
|
7154
|
+
path: wirePath,
|
|
7155
|
+
wsPath: wsActive ? ws.path : undefined,
|
|
7156
|
+
channel: wsActive ? ws.channel : undefined
|
|
7157
|
+
}));
|
|
7133
7158
|
const clientScript = resolveClientScript(wire);
|
|
7134
7159
|
return (event) => {
|
|
7135
7160
|
const method = event.req.method;
|
|
@@ -7148,6 +7173,39 @@ function prepareInlineWire(engine, wire) {
|
|
|
7148
7173
|
return null;
|
|
7149
7174
|
};
|
|
7150
7175
|
}
|
|
7176
|
+
function resolveWs(wire) {
|
|
7177
|
+
if (!wire.ws)
|
|
7178
|
+
return null;
|
|
7179
|
+
const ws = wire.ws === true ? {} : wire.ws;
|
|
7180
|
+
return {
|
|
7181
|
+
path: ws.path ?? "/_wire/ws",
|
|
7182
|
+
channel: ws.channel,
|
|
7183
|
+
server: ws.server,
|
|
7184
|
+
hub: ws.hub
|
|
7185
|
+
};
|
|
7186
|
+
}
|
|
7187
|
+
function attachNodeWs(wirePkg, instance, ws) {
|
|
7188
|
+
if (!ws.server) {
|
|
7189
|
+
console.warn("[@kirejs/h3] wire.ws is enabled but no `server` was provided; " + "pass the http.Server (e.g. from app.listen or http.createServer(app)). " + "Falling back to the HTTP transport.");
|
|
7190
|
+
return false;
|
|
7191
|
+
}
|
|
7192
|
+
let WebSocketServer;
|
|
7193
|
+
try {
|
|
7194
|
+
({ WebSocketServer } = __require("ws"));
|
|
7195
|
+
} catch {
|
|
7196
|
+
throw new Error("@kirejs/h3: wire.ws requires the `ws` package to be installed.");
|
|
7197
|
+
}
|
|
7198
|
+
const hub = ws.hub ?? new wirePkg.Hub;
|
|
7199
|
+
const wss = new WebSocketServer({ server: ws.server, path: ws.path });
|
|
7200
|
+
wss.on("connection", (socket) => {
|
|
7201
|
+
wirePkg.serveWs(instance, hub, {
|
|
7202
|
+
send: (data) => socket.send(data),
|
|
7203
|
+
onMessage: (cb) => socket.on("message", (d) => cb(d.toString())),
|
|
7204
|
+
onClose: (cb) => socket.on("close", cb)
|
|
7205
|
+
}, { channel: ws.channel });
|
|
7206
|
+
});
|
|
7207
|
+
return true;
|
|
7208
|
+
}
|
|
7151
7209
|
function requireWire() {
|
|
7152
7210
|
try {
|
|
7153
7211
|
return init_src(), __toCommonJS(exports_src);
|
|
@@ -7161,7 +7219,7 @@ function resolveClientScript(wire) {
|
|
|
7161
7219
|
try {
|
|
7162
7220
|
const nodePath = __require("node:path");
|
|
7163
7221
|
const { existsSync } = __require("node:fs");
|
|
7164
|
-
const main = __require.resolve("
|
|
7222
|
+
const main = __require.resolve(["@kirejs", "wire"].join("/")).replace(/\\/g, "/");
|
|
7165
7223
|
const marker = main.includes("/dist/") ? "/dist/" : main.includes("/src/") ? "/src/" : null;
|
|
7166
7224
|
const pkgDir = marker ? main.slice(0, main.indexOf(marker)) : nodePath.dirname(main);
|
|
7167
7225
|
const candidate = nodePath.join(pkgDir, "dist", "client", "auto.js");
|
package/dist/types/types.d.ts
CHANGED
|
@@ -1,6 +1,23 @@
|
|
|
1
1
|
import type { Kire, KirePlugin } from "kire";
|
|
2
2
|
/** A Kire plugin, optionally with its options. */
|
|
3
3
|
export type PluginEntry = KirePlugin<any> | [KirePlugin<any>, any];
|
|
4
|
+
/** WebSocket transport options for the Kirewire integration. */
|
|
5
|
+
export interface WireWsOptions {
|
|
6
|
+
/** WebSocket endpoint path (default `/_wire/ws`). */
|
|
7
|
+
path?: string;
|
|
8
|
+
/** Server-push channel the client subscribes to on connect. */
|
|
9
|
+
channel?: string;
|
|
10
|
+
/** Shared Kirewire `Hub` for server pushes (optional; one is created if omitted). */
|
|
11
|
+
hub?: any;
|
|
12
|
+
/**
|
|
13
|
+
* Node `http.Server` to attach the WebSocket upgrade to. Required for h3
|
|
14
|
+
* (the middleware does not own the server): pass the server returned by
|
|
15
|
+
* `app.listen(...)` or `http.createServer(app)`. Without it WebSocket is
|
|
16
|
+
* skipped, the client stays on HTTP, and a warning is logged. Needs the `ws`
|
|
17
|
+
* package installed.
|
|
18
|
+
*/
|
|
19
|
+
server?: any;
|
|
20
|
+
}
|
|
4
21
|
/** Optional Kirewire (reactive components) integration. */
|
|
5
22
|
export interface WireIntegration {
|
|
6
23
|
/** A Kirewire instance (from `@kirejs/wire`). */
|
|
@@ -13,6 +30,12 @@ export interface WireIntegration {
|
|
|
13
30
|
clientScript?: string;
|
|
14
31
|
/** Optional file-upload store. */
|
|
15
32
|
store?: any;
|
|
33
|
+
/**
|
|
34
|
+
* Enable the duplex WebSocket transport. `true` uses the default path
|
|
35
|
+
* `/_wire/ws`; an object customizes it. When active, the injected client
|
|
36
|
+
* script connects over WebSocket instead of HTTP POST.
|
|
37
|
+
*/
|
|
38
|
+
ws?: boolean | WireWsOptions;
|
|
16
39
|
}
|
|
17
40
|
export interface KireH3Options {
|
|
18
41
|
/** Directory that holds the `.kire` views. */
|