@velastack/patterns 0.3.4 → 0.4.1
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/README.md +44 -2
- package/dist/chunks/_layout-kkgN0IF7.js +62 -0
- package/dist/chunks/_layout-kkgN0IF7.js.map +1 -0
- package/dist/chunks/{collections-CrOvS2E7.js → collections-Dz2fvKnz.js} +2 -2
- package/dist/chunks/collections-Dz2fvKnz.js.map +1 -0
- package/dist/chunks/{compose-handle-B-CkDcQD.js → compose-handle-D_Rz3Fzo.js} +10 -4
- package/dist/chunks/compose-handle-D_Rz3Fzo.js.map +1 -0
- package/dist/chunks/{config-target-Bln26FJe.js → config-target-Dx3w6WSk.js} +59 -70
- package/dist/chunks/config-target-Dx3w6WSk.js.map +1 -0
- package/dist/chunks/constants-BjyMU5s8.js +6 -0
- package/dist/chunks/constants-BjyMU5s8.js.map +1 -0
- package/dist/chunks/dedent-Gq6Krl4n.js.map +1 -1
- package/dist/chunks/dispatch-CXOXPLFk.js +6 -0
- package/dist/chunks/dispatch-CXOXPLFk.js.map +1 -0
- package/dist/chunks/env-BPfk1VAw.js.map +1 -1
- package/dist/chunks/env-vars-C1NUX-bf.js +268 -0
- package/dist/chunks/env-vars-C1NUX-bf.js.map +1 -0
- package/dist/chunks/env-vars-Cr4lbMD_.js +21 -0
- package/dist/chunks/env-vars-Cr4lbMD_.js.map +1 -0
- package/dist/chunks/env-vars-De0Xs0L2.js +20 -0
- package/dist/chunks/env-vars-De0Xs0L2.js.map +1 -0
- package/dist/chunks/env-vars-file-B_6esJW3.js +34 -0
- package/dist/chunks/env-vars-file-B_6esJW3.js.map +1 -0
- package/dist/chunks/env-vars-mnRA0hOe.js +19 -0
- package/dist/chunks/env-vars-mnRA0hOe.js.map +1 -0
- package/dist/chunks/env.preview-uMRKT5Pc.js.map +1 -1
- package/dist/chunks/errors-DR3gF_7a.js.map +1 -1
- package/dist/chunks/format-result-DZ8De8KY.js.map +1 -1
- package/dist/chunks/generate-BW3l5Fxw.js +252 -0
- package/dist/chunks/generate-BW3l5Fxw.js.map +1 -0
- package/dist/chunks/{generate-CyuY2Ci7.js → generate-DeaBlnK6.js} +25 -24
- package/dist/chunks/generate-DeaBlnK6.js.map +1 -0
- package/dist/chunks/generate-DetW_gbr.js +68 -0
- package/dist/chunks/generate-DetW_gbr.js.map +1 -0
- package/dist/chunks/{generate-DwADTUob.js → generate-Gcc8iRkZ.js} +9 -6
- package/dist/chunks/generate-Gcc8iRkZ.js.map +1 -0
- package/dist/chunks/{generate-DQeWOEPY.js → generate-WMJo3QGZ.js} +9 -6
- package/dist/chunks/generate-WMJo3QGZ.js.map +1 -0
- package/dist/chunks/generate.runtime-1-91UmM8.js +85 -0
- package/dist/chunks/generate.runtime-1-91UmM8.js.map +1 -0
- package/dist/chunks/generate.runtime-6FXJM8hT.js +67 -0
- package/dist/chunks/generate.runtime-6FXJM8hT.js.map +1 -0
- package/dist/chunks/generate.runtime-B1jVAnDI.js +155 -0
- package/dist/chunks/generate.runtime-B1jVAnDI.js.map +1 -0
- package/dist/chunks/generate.runtime-BA3tDKnn.js +147 -0
- package/dist/chunks/generate.runtime-BA3tDKnn.js.map +1 -0
- package/dist/chunks/{generate.runtime-4FDxnvCl.js → generate.runtime-BO778G0r.js} +5 -5
- package/dist/chunks/generate.runtime-BO778G0r.js.map +1 -0
- package/dist/chunks/{generate.runtime-Um77JfwC.js → generate.runtime-B_UVGa3q.js} +7 -7
- package/dist/chunks/generate.runtime-B_UVGa3q.js.map +1 -0
- package/dist/chunks/{generate.runtime-BKiJvE8I.js → generate.runtime-BgTz41Zg.js} +105 -101
- package/dist/chunks/generate.runtime-BgTz41Zg.js.map +1 -0
- package/dist/chunks/{generate.runtime-FdZw277n.js → generate.runtime-C6bSvGMb.js} +108 -142
- package/dist/chunks/generate.runtime-C6bSvGMb.js.map +1 -0
- package/dist/chunks/generate.runtime-C8zJRNYG.js +124 -0
- package/dist/chunks/generate.runtime-C8zJRNYG.js.map +1 -0
- package/dist/chunks/generate.runtime-CCr1lvo4.js +43 -0
- package/dist/chunks/generate.runtime-CCr1lvo4.js.map +1 -0
- package/dist/chunks/generate.runtime-CYagyR5c.js +326 -0
- package/dist/chunks/generate.runtime-CYagyR5c.js.map +1 -0
- package/dist/chunks/{generate.runtime-n9AFWtPp.js → generate.runtime-Ce_rwzNa.js} +4 -4
- package/dist/chunks/generate.runtime-Ce_rwzNa.js.map +1 -0
- package/dist/chunks/{generate.runtime-cQGLxuZM.js → generate.runtime-CexC1Oky.js} +4 -4
- package/dist/chunks/generate.runtime-CexC1Oky.js.map +1 -0
- package/dist/chunks/{generate.runtime-AYQVW1S-.js → generate.runtime-CnPraLKv.js} +35 -31
- package/dist/chunks/generate.runtime-CnPraLKv.js.map +1 -0
- package/dist/chunks/generate.runtime-CslAvllQ.js +112 -0
- package/dist/chunks/generate.runtime-CslAvllQ.js.map +1 -0
- package/dist/chunks/{generate.runtime-onBnOiS7.js → generate.runtime-CuNhY5hn.js} +10 -10
- package/dist/chunks/generate.runtime-CuNhY5hn.js.map +1 -0
- package/dist/chunks/{generate.runtime-B45MvtYm.js → generate.runtime-DD51OSuL.js} +14 -14
- package/dist/chunks/generate.runtime-DD51OSuL.js.map +1 -0
- package/dist/chunks/generate.runtime-DHBRyMAq.js +65 -0
- package/dist/chunks/generate.runtime-DHBRyMAq.js.map +1 -0
- package/dist/chunks/{generate.runtime-D1DNAY6k.js → generate.runtime-DM4o_QYY.js} +9 -9
- package/dist/chunks/generate.runtime-DM4o_QYY.js.map +1 -0
- package/dist/chunks/generate.runtime-DV3WmZtb.js +35 -0
- package/dist/chunks/generate.runtime-DV3WmZtb.js.map +1 -0
- package/dist/chunks/generate.runtime-D_sQOeQa.js +164 -0
- package/dist/chunks/generate.runtime-D_sQOeQa.js.map +1 -0
- package/dist/chunks/{generate.runtime-ofdnLtxS.js → generate.runtime-DqD3PW-W.js} +3 -3
- package/dist/chunks/generate.runtime-DqD3PW-W.js.map +1 -0
- package/dist/chunks/{generate.runtime-VgVwRiiN.js → generate.runtime-Dtgw9IQO.js} +8 -8
- package/dist/chunks/generate.runtime-Dtgw9IQO.js.map +1 -0
- package/dist/chunks/{generate.runtime-CN5c2xH8.js → generate.runtime-IlBCcXvv.js} +14 -14
- package/dist/chunks/generate.runtime-IlBCcXvv.js.map +1 -0
- package/dist/chunks/{generate.runtime-BSRFv4cJ.js → generate.runtime-cwvAoKoH.js} +3 -3
- package/dist/chunks/generate.runtime-cwvAoKoH.js.map +1 -0
- package/dist/chunks/{generate.runtime-DG-3G00z.js → generate.runtime-kvxmTlQb.js} +3 -3
- package/dist/chunks/{generate.runtime-DG-3G00z.js.map → generate.runtime-kvxmTlQb.js.map} +1 -1
- package/dist/chunks/generate.runtime-pVLzzpUM.js +122 -0
- package/dist/chunks/generate.runtime-pVLzzpUM.js.map +1 -0
- package/dist/chunks/{generate.runtime-BFOXm2DD.js → generate.runtime-zJpEufTc.js} +10 -10
- package/dist/chunks/generate.runtime-zJpEufTc.js.map +1 -0
- package/dist/chunks/lib-specifier-Cngo1zF_.js +33 -0
- package/dist/chunks/lib-specifier-Cngo1zF_.js.map +1 -0
- package/dist/chunks/logger-CQONztPm.js.map +1 -1
- package/dist/chunks/{modify-file-Dwfv0dCI.js → modify-file-BlDeeurK.js} +3 -3
- package/dist/chunks/modify-file-BlDeeurK.js.map +1 -0
- package/dist/chunks/{modify-svelte-config-remote-BUU_EaDf.js → modify-svelte-config-remote-p0TfVzxm.js} +8 -10
- package/dist/chunks/modify-svelte-config-remote-p0TfVzxm.js.map +1 -0
- package/dist/chunks/modify-utils-Cw-on_cL.js.map +1 -1
- package/dist/chunks/nav-user-BRIHOOpG.js +6 -0
- package/dist/chunks/nav-user-BRIHOOpG.js.map +1 -0
- package/dist/chunks/package-imports-Bbw3iMPg.js +173 -0
- package/dist/chunks/package-imports-Bbw3iMPg.js.map +1 -0
- package/dist/chunks/pocketbase-C5GS-Dh5.js.map +1 -1
- package/dist/chunks/pocketbase-DpudAAmd.js.map +1 -1
- package/dist/chunks/{pocketbase-BkhUywtb.js → pocketbase-Dry6ry17.js} +2 -2
- package/dist/chunks/pocketbase-Dry6ry17.js.map +1 -0
- package/dist/chunks/{providers-BL9vJP_9.js → providers-BHR6-XZ7.js} +11 -4
- package/dist/chunks/providers-BHR6-XZ7.js.map +1 -0
- package/dist/chunks/{shared-C8GtNxpm.js → shared-CZC4d7Uj.js} +2 -2
- package/dist/chunks/shared-CZC4d7Uj.js.map +1 -0
- package/dist/chunks/{site-BdMX8qrH.js → site-BwCA18Sv.js} +2 -2
- package/dist/chunks/site-BwCA18Sv.js.map +1 -0
- package/dist/chunks/svelte-file-B3RfgVdt.js.map +1 -1
- package/dist/chunks/table-core-AjBpYi-y.js +127 -0
- package/dist/chunks/table-core-AjBpYi-y.js.map +1 -0
- package/dist/chunks/{taggedTemplateLiteral-Dx0fjWiw.js → taggedTemplateLiteral-CswN2AAa.js} +1 -1
- package/dist/chunks/{test-setup-DHEFKEHE.js → test-setup-DEmWd9Ul.js} +76 -67
- package/dist/chunks/test-setup-DEmWd9Ul.js.map +1 -0
- package/dist/chunks/{ts-morph-helpers-CeduA--o.js → ts-morph-helpers-CDW4lhox.js} +77 -63
- package/dist/chunks/ts-morph-helpers-CDW4lhox.js.map +1 -0
- package/dist/chunks/ui-DD4NltyN.js.map +1 -1
- package/dist/chunks/{ui-TlEuI2Sz.js → ui-X698F10c.js} +47 -47
- package/dist/chunks/ui-X698F10c.js.map +1 -0
- package/dist/chunks/{unmodify-load-jfdcVZ_a.js → unmodify-load-CyGzC1Hu.js} +2 -2
- package/dist/chunks/unmodify-load-CyGzC1Hu.js.map +1 -0
- package/dist/chunks/util-BLYliuUK.js.map +1 -1
- package/dist/chunks/write-result-B68lvI57.js +511 -0
- package/dist/chunks/write-result-B68lvI57.js.map +1 -0
- package/dist/index.d.ts +224 -1
- package/dist/index.js +2121 -2064
- package/dist/index.js.map +1 -1
- package/package.json +7 -7
- package/dist/chunks/_layout-B7ujvjnA.js +0 -55
- package/dist/chunks/_layout-B7ujvjnA.js.map +0 -1
- package/dist/chunks/collections-CrOvS2E7.js.map +0 -1
- package/dist/chunks/compose-handle-B-CkDcQD.js.map +0 -1
- package/dist/chunks/config-target-Bln26FJe.js.map +0 -1
- package/dist/chunks/constants-BYkd9jeJ.js +0 -6
- package/dist/chunks/constants-BYkd9jeJ.js.map +0 -1
- package/dist/chunks/dispatch-BRnt8PcW.js +0 -6
- package/dist/chunks/dispatch-BRnt8PcW.js.map +0 -1
- package/dist/chunks/generate-6snrlnpA.js +0 -64
- package/dist/chunks/generate-6snrlnpA.js.map +0 -1
- package/dist/chunks/generate-Ca_6FlPi.js +0 -252
- package/dist/chunks/generate-Ca_6FlPi.js.map +0 -1
- package/dist/chunks/generate-CyuY2Ci7.js.map +0 -1
- package/dist/chunks/generate-DQeWOEPY.js.map +0 -1
- package/dist/chunks/generate-DwADTUob.js.map +0 -1
- package/dist/chunks/generate.runtime-4FDxnvCl.js.map +0 -1
- package/dist/chunks/generate.runtime-AYQVW1S-.js.map +0 -1
- package/dist/chunks/generate.runtime-B2aFFaac.js +0 -117
- package/dist/chunks/generate.runtime-B2aFFaac.js.map +0 -1
- package/dist/chunks/generate.runtime-B45MvtYm.js.map +0 -1
- package/dist/chunks/generate.runtime-BFOXm2DD.js.map +0 -1
- package/dist/chunks/generate.runtime-BHkFmI2Y.js +0 -146
- package/dist/chunks/generate.runtime-BHkFmI2Y.js.map +0 -1
- package/dist/chunks/generate.runtime-BKiJvE8I.js.map +0 -1
- package/dist/chunks/generate.runtime-BSRFv4cJ.js.map +0 -1
- package/dist/chunks/generate.runtime-BUqsF3AF.js +0 -123
- package/dist/chunks/generate.runtime-BUqsF3AF.js.map +0 -1
- package/dist/chunks/generate.runtime-BsaSyTnU.js +0 -82
- package/dist/chunks/generate.runtime-BsaSyTnU.js.map +0 -1
- package/dist/chunks/generate.runtime-CMnvmeVt.js +0 -111
- package/dist/chunks/generate.runtime-CMnvmeVt.js.map +0 -1
- package/dist/chunks/generate.runtime-CN5c2xH8.js.map +0 -1
- package/dist/chunks/generate.runtime-CgoSrP55.js +0 -146
- package/dist/chunks/generate.runtime-CgoSrP55.js.map +0 -1
- package/dist/chunks/generate.runtime-D1DNAY6k.js.map +0 -1
- package/dist/chunks/generate.runtime-DQwSY6Nc.js +0 -38
- package/dist/chunks/generate.runtime-DQwSY6Nc.js.map +0 -1
- package/dist/chunks/generate.runtime-D_yqWLcI.js +0 -66
- package/dist/chunks/generate.runtime-D_yqWLcI.js.map +0 -1
- package/dist/chunks/generate.runtime-Drmahmdl.js +0 -313
- package/dist/chunks/generate.runtime-Drmahmdl.js.map +0 -1
- package/dist/chunks/generate.runtime-FdZw277n.js.map +0 -1
- package/dist/chunks/generate.runtime-Lh1cW9Tz.js +0 -94
- package/dist/chunks/generate.runtime-Lh1cW9Tz.js.map +0 -1
- package/dist/chunks/generate.runtime-QGHToXRY.js +0 -32
- package/dist/chunks/generate.runtime-QGHToXRY.js.map +0 -1
- package/dist/chunks/generate.runtime-Um77JfwC.js.map +0 -1
- package/dist/chunks/generate.runtime-VgVwRiiN.js.map +0 -1
- package/dist/chunks/generate.runtime-YyIVd4oy.js +0 -61
- package/dist/chunks/generate.runtime-YyIVd4oy.js.map +0 -1
- package/dist/chunks/generate.runtime-cQGLxuZM.js.map +0 -1
- package/dist/chunks/generate.runtime-n9AFWtPp.js.map +0 -1
- package/dist/chunks/generate.runtime-ofdnLtxS.js.map +0 -1
- package/dist/chunks/generate.runtime-onBnOiS7.js.map +0 -1
- package/dist/chunks/modify-file-Dwfv0dCI.js.map +0 -1
- package/dist/chunks/modify-svelte-config-remote-BUU_EaDf.js.map +0 -1
- package/dist/chunks/nav-user-BYI-h8Od.js +0 -6
- package/dist/chunks/nav-user-BYI-h8Od.js.map +0 -1
- package/dist/chunks/pocketbase-BkhUywtb.js.map +0 -1
- package/dist/chunks/providers-BL9vJP_9.js.map +0 -1
- package/dist/chunks/shared-C8GtNxpm.js.map +0 -1
- package/dist/chunks/site-BdMX8qrH.js.map +0 -1
- package/dist/chunks/table-core-G9Shld4F.js +0 -126
- package/dist/chunks/table-core-G9Shld4F.js.map +0 -1
- package/dist/chunks/test-setup-DHEFKEHE.js.map +0 -1
- package/dist/chunks/ts-morph-helpers-CeduA--o.js.map +0 -1
- package/dist/chunks/ui-TlEuI2Sz.js.map +0 -1
- package/dist/chunks/unmodify-load-jfdcVZ_a.js.map +0 -1
- package/dist/chunks/write-result-Djy0SZXX.js +0 -376
- package/dist/chunks/write-result-Djy0SZXX.js.map +0 -1
|
@@ -1,252 +0,0 @@
|
|
|
1
|
-
import { t as e } from "./errors-DR3gF_7a.js";
|
|
2
|
-
import { n as t, r as n } from "./util-BLYliuUK.js";
|
|
3
|
-
import { a as r, n as i, r as a } from "./providers-BL9vJP_9.js";
|
|
4
|
-
import { t as o } from "./ui-DD4NltyN.js";
|
|
5
|
-
import { c as s } from "./constants-BYkd9jeJ.js";
|
|
6
|
-
//#region node_modules/change-case/dist/index.js
|
|
7
|
-
var c = /([\p{Ll}\d])(\p{Lu})/gu, l = /(\p{Lu})([\p{Lu}][\p{Ll}])/gu, u = /(\d)\p{Ll}|(\p{L})\d/u, d = /[^\p{L}\d]+/giu, f = "$1\0$2", p = "";
|
|
8
|
-
function m(e) {
|
|
9
|
-
let t = e.trim();
|
|
10
|
-
t = t.replace(c, f).replace(l, f), t = t.replace(d, "\0");
|
|
11
|
-
let n = 0, r = t.length;
|
|
12
|
-
for (; t.charAt(n) === "\0";) n++;
|
|
13
|
-
if (n === r) return [];
|
|
14
|
-
for (; t.charAt(r - 1) === "\0";) r--;
|
|
15
|
-
return t.slice(n, r).split(/\0/g);
|
|
16
|
-
}
|
|
17
|
-
function h(e) {
|
|
18
|
-
let t = m(e);
|
|
19
|
-
for (let e = 0; e < t.length; e++) {
|
|
20
|
-
let n = t[e], r = u.exec(n);
|
|
21
|
-
if (r) {
|
|
22
|
-
let i = r.index + (r[1] ?? r[2]).length;
|
|
23
|
-
t.splice(e, 1, n.slice(0, i), n.slice(i));
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
return t;
|
|
27
|
-
}
|
|
28
|
-
function g(e, t) {
|
|
29
|
-
let [n, r, i] = E(e, t);
|
|
30
|
-
return n + r.map(S(t?.locale)).join(t?.delimiter ?? " ") + i;
|
|
31
|
-
}
|
|
32
|
-
function _(e, t) {
|
|
33
|
-
let [n, r, i] = E(e, t), a = S(t?.locale), o = C(t?.locale), s = t?.mergeAmbiguousCharacters ? w(a, o) : T(a, o);
|
|
34
|
-
return n + r.map((e, t) => t === 0 ? a(e) : s(e, t)).join(t?.delimiter ?? "") + i;
|
|
35
|
-
}
|
|
36
|
-
function v(e, t) {
|
|
37
|
-
let [n, r, i] = E(e, t), a = S(t?.locale), o = C(t?.locale), s = t?.mergeAmbiguousCharacters ? w(a, o) : T(a, o);
|
|
38
|
-
return n + r.map(s).join(t?.delimiter ?? "") + i;
|
|
39
|
-
}
|
|
40
|
-
function y(e, t) {
|
|
41
|
-
let [n, r, i] = E(e, t), a = S(t?.locale), o = C(t?.locale);
|
|
42
|
-
return n + r.map(w(a, o)).join(t?.delimiter ?? " ") + i;
|
|
43
|
-
}
|
|
44
|
-
function b(e, t) {
|
|
45
|
-
return g(e, {
|
|
46
|
-
delimiter: "-",
|
|
47
|
-
...t
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
function x(e, t) {
|
|
51
|
-
return g(e, {
|
|
52
|
-
delimiter: "_",
|
|
53
|
-
...t
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
function S(e) {
|
|
57
|
-
return e === !1 ? (e) => e.toLowerCase() : (t) => t.toLocaleLowerCase(e);
|
|
58
|
-
}
|
|
59
|
-
function C(e) {
|
|
60
|
-
return e === !1 ? (e) => e.toUpperCase() : (t) => t.toLocaleUpperCase(e);
|
|
61
|
-
}
|
|
62
|
-
function w(e, t) {
|
|
63
|
-
return (n) => `${t(n[0])}${e(n.slice(1))}`;
|
|
64
|
-
}
|
|
65
|
-
function T(e, t) {
|
|
66
|
-
return (n, r) => {
|
|
67
|
-
let i = n[0];
|
|
68
|
-
return (r > 0 && i >= "0" && i <= "9" ? "_" + i : t(i)) + e(n.slice(1));
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
function E(e, t = {}) {
|
|
72
|
-
let n = t.split ?? (t.separateNumbers ? h : m), r = t.prefixCharacters ?? p, i = t.suffixCharacters ?? p, a = 0, o = e.length;
|
|
73
|
-
for (; a < e.length;) {
|
|
74
|
-
let t = e.charAt(a);
|
|
75
|
-
if (!r.includes(t)) break;
|
|
76
|
-
a++;
|
|
77
|
-
}
|
|
78
|
-
for (; o > a;) {
|
|
79
|
-
let t = o - 1, n = e.charAt(t);
|
|
80
|
-
if (!i.includes(n)) break;
|
|
81
|
-
o = t;
|
|
82
|
-
}
|
|
83
|
-
return [
|
|
84
|
-
e.slice(0, a),
|
|
85
|
-
n(e.slice(a, o)),
|
|
86
|
-
e.slice(o)
|
|
87
|
-
];
|
|
88
|
-
}
|
|
89
|
-
//#endregion
|
|
90
|
-
//#region src/parse/route.ts
|
|
91
|
-
var D = "src/routes", O = /\[([^\]]+)\]/g, ee = /^[a-zA-Z0-9_\-[\]()]+$/;
|
|
92
|
-
function k({ features: e, routeGroups: t }) {
|
|
93
|
-
let n = t ?? {
|
|
94
|
-
public: "(public)",
|
|
95
|
-
app: "(app)"
|
|
96
|
-
};
|
|
97
|
-
return e.auth ? n.app ?? n.public : n.public;
|
|
98
|
-
}
|
|
99
|
-
function A(e, t) {
|
|
100
|
-
return [
|
|
101
|
-
D,
|
|
102
|
-
e,
|
|
103
|
-
t
|
|
104
|
-
].filter(Boolean).join("/");
|
|
105
|
-
}
|
|
106
|
-
function j(e, t) {
|
|
107
|
-
return b(t === "scaffold" ? e.pluralDisplayName : e.displayName);
|
|
108
|
-
}
|
|
109
|
-
function M(e) {
|
|
110
|
-
return `/${(e.startsWith(`${D}/`) ? e.slice(11) : e).split("/").filter((e) => !(e.startsWith("(") && e.endsWith(")"))).join("/")}`;
|
|
111
|
-
}
|
|
112
|
-
function N(e) {
|
|
113
|
-
let t = [];
|
|
114
|
-
for (let n of e.matchAll(O)) t.push(n[1]);
|
|
115
|
-
return t;
|
|
116
|
-
}
|
|
117
|
-
function P(t) {
|
|
118
|
-
if (t.startsWith("/")) throw new e(`Route must not start with "/". Got: "${t}"`);
|
|
119
|
-
if (t.startsWith(`${D}/`) || t === D) throw new e(`Route must not start with "${D}/" — paths are rooted there automatically. Got: "${t}"`);
|
|
120
|
-
let n = t.split("/");
|
|
121
|
-
for (let r of n) {
|
|
122
|
-
if (r.length === 0) throw new e(`Route must not contain empty segments. Got: "${t}"`);
|
|
123
|
-
if (r === "." || r === "..") throw new e(`Route must not contain "." or ".." segments. Got: "${t}"`);
|
|
124
|
-
if (r.startsWith("_")) throw new e(`Route segments must not start with underscore. Got: "${r}"`);
|
|
125
|
-
if (!ee.test(r)) throw new e(`Route segment "${r}" contains invalid characters. Allowed: letters, digits, underscore, dash, brackets, parentheses.`);
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
function F(e) {
|
|
129
|
-
return e.split("/").some((e) => e.startsWith("(") && e.endsWith(")"));
|
|
130
|
-
}
|
|
131
|
-
function I(e, t, n, r) {
|
|
132
|
-
if (e === void 0 || e === "") {
|
|
133
|
-
let e = j(t, r), i = A(k(n), e);
|
|
134
|
-
return {
|
|
135
|
-
fileBase: i,
|
|
136
|
-
urlBase: M(i),
|
|
137
|
-
dynamicParams: N(i)
|
|
138
|
-
};
|
|
139
|
-
}
|
|
140
|
-
P(e);
|
|
141
|
-
let i = A(F(e) ? null : k(n), e);
|
|
142
|
-
return {
|
|
143
|
-
fileBase: i,
|
|
144
|
-
urlBase: M(i),
|
|
145
|
-
dynamicParams: N(i)
|
|
146
|
-
};
|
|
147
|
-
}
|
|
148
|
-
function L(e) {
|
|
149
|
-
return {
|
|
150
|
-
list: e.fileBase,
|
|
151
|
-
new: `${e.fileBase}/new`,
|
|
152
|
-
show: `${e.fileBase}/[id]`,
|
|
153
|
-
edit: `${e.fileBase}/[id]/edit`
|
|
154
|
-
};
|
|
155
|
-
}
|
|
156
|
-
function R(e) {
|
|
157
|
-
return {
|
|
158
|
-
list: e.urlBase,
|
|
159
|
-
new: `${e.urlBase}/new`,
|
|
160
|
-
show: `${e.urlBase}/[id]`,
|
|
161
|
-
edit: `${e.urlBase}/[id]/edit`
|
|
162
|
-
};
|
|
163
|
-
}
|
|
164
|
-
//#endregion
|
|
165
|
-
//#region src/patterns/enable/ai/creates/src/routes/(public)/ai/+page.svelte?raw
|
|
166
|
-
var z = "<script lang=\"ts\">\n import { Chat } from '@ai-sdk/svelte';\n import { Button } from '$lib/components/ui/button';\n import { Textarea } from '$lib/components/ui/textarea';\n\n // Posts to /api/chat (src/routes/api/chat/+server.ts) and streams the reply\n // into `chat.messages`. This page is a demo, and it is yours to delete.\n const chat = new Chat({});\n\n let input = $state('');\n const busy = $derived(chat.status === 'submitted' || chat.status === 'streaming');\n\n function send(event: SubmitEvent) {\n event.preventDefault();\n const text = input.trim();\n if (!text || busy) return;\n chat.sendMessage({ text });\n input = '';\n }\n\n // Enter sends; Shift+Enter starts a new line.\n function onkeydown(event: KeyboardEvent & { currentTarget: HTMLTextAreaElement }) {\n if (event.key === 'Enter' && !event.shiftKey && !event.isComposing) {\n event.preventDefault();\n event.currentTarget.form?.requestSubmit();\n }\n }\n<\/script>\n\n<div class=\"mx-auto flex w-full max-w-3xl flex-1 flex-col gap-6 px-4 py-10\">\n <div>\n <h1 class=\"text-2xl font-semibold\">AI chat</h1>\n <p class=\"text-muted-foreground text-sm\">\n Replies stream from <code>src/routes/api/chat/+server.ts</code>. Pick the model in\n <code>src/lib/server/ai.ts</code>.\n </p>\n </div>\n\n <div class=\"flex flex-1 flex-col gap-4\" aria-live=\"polite\">\n {#each chat.messages as message (message.id)}\n <div\n class={message.role === 'user'\n ? 'bg-primary text-primary-foreground ml-auto max-w-[80%] rounded-lg px-4 py-2'\n : 'max-w-[80%]'}\n >\n {#each message.parts as part, index (index)}\n {#if part.type === 'text'}\n <p class=\"whitespace-pre-wrap\">{part.text}</p>\n {/if}\n {/each}\n </div>\n {:else}\n <p class=\"text-muted-foreground\">Ask anything to start the conversation.</p>\n {/each}\n\n {#if chat.status === 'submitted'}\n <p class=\"text-muted-foreground text-sm\">Thinking…</p>\n {/if}\n\n {#if chat.error}\n <div\n role=\"alert\"\n class=\"border-destructive text-destructive flex items-center justify-between gap-4 rounded-md border px-4 py-2 text-sm\"\n >\n <span>{chat.error.message}</span>\n <Button variant=\"outline\" size=\"sm\" onclick={() => chat.regenerate()}>Retry</Button>\n </div>\n {/if}\n </div>\n\n <form onsubmit={send} class=\"bg-background sticky bottom-0 flex items-end gap-2 py-2\">\n <Textarea\n bind:value={input}\n {onkeydown}\n rows={1}\n placeholder=\"Send a message\"\n aria-label=\"Message\"\n class=\"max-h-40 min-h-10 resize-none\"\n />\n {#if busy}\n <Button type=\"button\" variant=\"outline\" onclick={() => chat.stop()}>Stop</Button>\n {:else}\n <Button type=\"submit\" disabled={!input.trim()}>Send</Button>\n {/if}\n </form>\n</div>\n", B = "import { text } from '@sveltejs/kit';\nimport { dev } from '$app/environment';\nimport {\n convertToModelMessages,\n createUIMessageStreamResponse,\n safeValidateUIMessages,\n streamText,\n toUIMessageStream\n} from 'ai';\nimport { API_KEY, languageModel } from '$lib/server/ai';\nimport type { RequestHandler } from './$types';\n\n// Sent ahead of every conversation: give the assistant its role here.\nconst INSTRUCTIONS = 'You are a helpful assistant. Keep answers short unless asked for detail.';\n\n/**\n * Where `new Chat()` from @ai-sdk/svelte posts by default: the conversation so\n * far comes in, the model's reply streams back. Anyone who can reach the site\n * can call it, and every reply is billed to your API key, so put it behind\n * sign-in or a rate limit before you deploy.\n *\n * Errors are plain text, which `Chat` shows as `chat.error.message`.\n */\nexport const POST: RequestHandler = async ({ request }) => {\n const body = await request.json().catch(() => null);\n const messages = await safeValidateUIMessages({ messages: body?.messages });\n if (!messages.success) {\n return text('Expected a JSON body with a messages array.', { status: 400 });\n }\n\n const model = languageModel();\n if (!model) {\n return text(`Set ${API_KEY} in .env to start chatting.`, { status: 503 });\n }\n\n const result = streamText({\n model,\n instructions: INSTRUCTIONS,\n messages: await convertToModelMessages(messages.data)\n });\n\n return createUIMessageStreamResponse({\n stream: toUIMessageStream({\n stream: result.stream,\n // Provider errors (a bad key, an unknown model id) reach the chat in\n // dev only; in production they stay in the server log.\n onError: (error) =>\n dev && error instanceof Error ? error.message : 'The model could not answer.'\n })\n });\n};\n", V = "import { describe, it, expect } from 'vitest';\nimport type { Match } from '@velastack/kit';\nimport type { RouteId } from './$types';\n\n// None of these requests reach the model, so they pass without an API key and\n// cost nothing.\ndescribe('POST /api/chat', () => {\n it('should return 400 if the body is not JSON', async (context) => {\n const response = await context.request\n .post('/api/chat' satisfies Match<RouteId>)\n .set('Content-Type', 'application/json')\n .send('not json');\n\n expect(response.status).toBe(400);\n });\n\n it('should return 400 if messages are missing', async (context) => {\n const response = await context.request.post('/api/chat' satisfies Match<RouteId>).send({});\n\n expect(response.status).toBe(400);\n });\n\n it('should return 400 if messages are malformed', async (context) => {\n const response = await context.request\n .post('/api/chat' satisfies Match<RouteId>)\n .send({ messages: [{ role: 'user', content: 'Hello' }] });\n\n expect(response.status).toBe(400);\n });\n});\n", H = "import { text } from '@sveltejs/kit';\nimport { dev } from '$app/environment';\nimport {\n convertToModelMessages,\n createUIMessageStreamResponse,\n safeValidateUIMessages,\n streamText,\n toUIMessageStream\n} from 'ai';\nimport { API_KEY, languageModel } from '$lib/server/ai';\nimport type { RequestHandler } from './$types';\n\n// Sent ahead of every conversation: give the assistant its role here.\nconst INSTRUCTIONS = 'You are a helpful assistant. Keep answers short unless asked for detail.';\n\n/**\n * Where `new Chat()` from @ai-sdk/svelte posts by default: the conversation so\n * far comes in, the model's reply streams back. Every reply is billed to your\n * API key, so only signed-in users get one.\n *\n * Errors are plain text, which `Chat` shows as `chat.error.message`.\n */\nexport const POST: RequestHandler = async ({ request, locals }) => {\n if (!locals.pb.authStore.isValid) {\n return text('Sign in to chat.', { status: 401 });\n }\n\n const body = await request.json().catch(() => null);\n const messages = await safeValidateUIMessages({ messages: body?.messages });\n if (!messages.success) {\n return text('Expected a JSON body with a messages array.', { status: 400 });\n }\n\n const model = languageModel();\n if (!model) {\n return text(`Set ${API_KEY} in .env to start chatting.`, { status: 503 });\n }\n\n const result = streamText({\n model,\n instructions: INSTRUCTIONS,\n messages: await convertToModelMessages(messages.data)\n });\n\n return createUIMessageStreamResponse({\n stream: toUIMessageStream({\n stream: result.stream,\n // Provider errors (a bad key, an unknown model id) reach the chat in\n // dev only; in production they stay in the server log.\n onError: (error) =>\n dev && error instanceof Error ? error.message : 'The model could not answer.'\n })\n });\n};\n", U = "import { describe, it, expect } from 'vitest';\nimport type { Match } from '@velastack/kit';\nimport type { RouteId } from './$types';\n\n// None of these requests reach the model, so they pass without an API key and\n// cost nothing.\ndescribe('POST /api/chat', () => {\n it('should return 401 when signed out', async (context) => {\n const response = await context.request.post('/api/chat' satisfies Match<RouteId>).send({\n messages: [{ id: '1', role: 'user', parts: [{ type: 'text', text: 'Hello' }] }]\n });\n\n expect(response.status).toBe(401);\n });\n\n it('should return 400 if the body is not JSON', async (context) => {\n await context.agent.authenticateUser();\n\n const response = await context.agent\n .post('/api/chat' satisfies Match<RouteId>)\n .set('Content-Type', 'application/json')\n .send('not json');\n\n expect(response.status).toBe(400);\n });\n\n it('should return 400 if messages are missing', async (context) => {\n await context.agent.authenticateUser();\n\n const response = await context.agent.post('/api/chat' satisfies Match<RouteId>).send({});\n\n expect(response.status).toBe(400);\n });\n\n it('should return 400 if messages are malformed', async (context) => {\n await context.agent.authenticateUser();\n\n const response = await context.agent\n .post('/api/chat' satisfies Match<RouteId>)\n .send({ messages: [{ role: 'user', content: 'Hello' }] });\n\n expect(response.status).toBe(400);\n });\n});\n", W = "<script lang=\"ts\">\n import { Chat } from '@ai-sdk/svelte';\n\n // Posts to /api/chat (src/routes/api/chat/+server.ts) and streams the reply\n // into `chat.messages`. This page is a demo, and it is yours to delete.\n const chat = new Chat({});\n\n let input = $state('');\n const busy = $derived(chat.status === 'submitted' || chat.status === 'streaming');\n\n function send(event: SubmitEvent) {\n event.preventDefault();\n const text = input.trim();\n if (!text || busy) return;\n chat.sendMessage({ text });\n input = '';\n }\n\n // Enter sends; Shift+Enter starts a new line.\n function onkeydown(event: KeyboardEvent & { currentTarget: HTMLTextAreaElement }) {\n if (event.key === 'Enter' && !event.shiftKey && !event.isComposing) {\n event.preventDefault();\n event.currentTarget.form?.requestSubmit();\n }\n }\n<\/script>\n\n<h1>AI chat</h1>\n<p>\n Replies stream from <code>src/routes/api/chat/+server.ts</code>. Pick the model in\n <code>src/lib/server/ai.ts</code>.\n</p>\n\n<section aria-live=\"polite\">\n {#each chat.messages as message (message.id)}\n <article data-role={message.role}>\n <strong>{message.role === 'user' ? 'You' : 'Assistant'}</strong>\n {#each message.parts as part, index (index)}\n {#if part.type === 'text'}\n <p style=\"white-space: pre-wrap\">{part.text}</p>\n {/if}\n {/each}\n </article>\n {:else}\n <p>Ask anything to start the conversation.</p>\n {/each}\n\n {#if chat.status === 'submitted'}\n <p>Thinking…</p>\n {/if}\n\n {#if chat.error}\n <p role=\"alert\">\n {chat.error.message}\n <button type=\"button\" onclick={() => chat.regenerate()}>Retry</button>\n </p>\n {/if}\n</section>\n\n<form onsubmit={send}>\n <textarea bind:value={input} {onkeydown} rows=\"2\" placeholder=\"Send a message\" aria-label=\"Message\"\n ></textarea>\n {#if busy}\n <button type=\"button\" onclick={() => chat.stop()}>Stop</button>\n {:else}\n <button type=\"submit\" disabled={!input.trim()}>Send</button>\n {/if}\n</form>\n", G = "import { createAnthropic } from '@ai-sdk/anthropic';\nimport { env } from '$env/dynamic/private';\n\n/** The `.env` key holding the Anthropic API key. */\nexport const API_KEY = 'ANTHROPIC_API_KEY';\n\n/**\n * The model the AI routes talk to, or `undefined` while ANTHROPIC_API_KEY is\n * blank. The key is read on every call, so a new value in `.env` needs no code\n * change. Any id from https://docs.claude.com/en/docs/about-claude/models works\n * in place of this one.\n */\nexport function languageModel() {\n const apiKey = env[API_KEY];\n return apiKey ? createAnthropic({ apiKey })('claude-sonnet-5') : undefined;\n}\n", K = "import { createGateway } from 'ai';\nimport { env } from '$env/dynamic/private';\n\n/** The `.env` key holding the Vercel AI Gateway API key. */\nexport const API_KEY = 'AI_GATEWAY_API_KEY';\n\n/**\n * The model the AI routes talk to, or `undefined` while AI_GATEWAY_API_KEY is\n * blank. The key is read on every call, so a new value in `.env` needs no code\n * change. The gateway routes `creator/model` ids to their provider; any id from\n * https://vercel.com/ai-gateway/models works in place of this one.\n */\nexport function languageModel() {\n const apiKey = env[API_KEY];\n return apiKey ? createGateway({ apiKey })('anthropic/claude-sonnet-5') : undefined;\n}\n", q = "import { createOpenAI } from '@ai-sdk/openai';\nimport { env } from '$env/dynamic/private';\n\n/** The `.env` key holding the OpenAI API key. */\nexport const API_KEY = 'OPENAI_API_KEY';\n\n/**\n * The model the AI routes talk to, or `undefined` while OPENAI_API_KEY is\n * blank. The key is read on every call, so a new value in `.env` needs no code\n * change. Any id from https://platform.openai.com/docs/models works in place of\n * this one.\n */\nexport function languageModel() {\n const apiKey = env[API_KEY];\n return apiKey ? createOpenAI({ apiKey })('gpt-5.5') : undefined;\n}\n", J = [
|
|
167
|
-
{
|
|
168
|
-
id: "gateway",
|
|
169
|
-
label: "Vercel AI Gateway",
|
|
170
|
-
env: [{
|
|
171
|
-
key: "AI_GATEWAY_API_KEY",
|
|
172
|
-
label: "Vercel AI Gateway API key",
|
|
173
|
-
secret: !0
|
|
174
|
-
}]
|
|
175
|
-
},
|
|
176
|
-
{
|
|
177
|
-
id: "openai",
|
|
178
|
-
label: "OpenAI",
|
|
179
|
-
env: [{
|
|
180
|
-
key: "OPENAI_API_KEY",
|
|
181
|
-
label: "OpenAI API key",
|
|
182
|
-
placeholder: "sk-...",
|
|
183
|
-
secret: !0
|
|
184
|
-
}]
|
|
185
|
-
},
|
|
186
|
-
{
|
|
187
|
-
id: "anthropic",
|
|
188
|
-
label: "Anthropic",
|
|
189
|
-
env: [{
|
|
190
|
-
key: "ANTHROPIC_API_KEY",
|
|
191
|
-
label: "Anthropic API key",
|
|
192
|
-
placeholder: "sk-ant-...",
|
|
193
|
-
secret: !0
|
|
194
|
-
}]
|
|
195
|
-
}
|
|
196
|
-
], Y = ["ai@^7.0.107", "@ai-sdk/svelte@^5.0.107"], X = {
|
|
197
|
-
openai: ["@ai-sdk/openai@^4.0.71"],
|
|
198
|
-
anthropic: ["@ai-sdk/anthropic@^4.0.58"]
|
|
199
|
-
}, Z = {
|
|
200
|
-
slug: "enable-ai",
|
|
201
|
-
providers: J
|
|
202
|
-
}, Q = "src/routes/(public)/ai/";
|
|
203
|
-
function $(e) {
|
|
204
|
-
return [
|
|
205
|
-
"src/routes",
|
|
206
|
-
k(e),
|
|
207
|
-
"ai"
|
|
208
|
-
].filter(Boolean).join("/");
|
|
209
|
-
}
|
|
210
|
-
function te(e, t = {}) {
|
|
211
|
-
return a(e, `AI SDK (${e.label})`, t);
|
|
212
|
-
}
|
|
213
|
-
var ne = /* #__PURE__ */ Object.assign({
|
|
214
|
-
"./creates/src/routes/(public)/ai/+page.svelte": z,
|
|
215
|
-
"./creates/src/routes/api/chat/+server.ts": B,
|
|
216
|
-
"./creates/src/routes/api/chat/server.test.ts": V
|
|
217
|
-
}), re = /* #__PURE__ */ Object.assign({
|
|
218
|
-
"./creates-app-mode/src/routes/api/chat/+server.ts": H,
|
|
219
|
-
"./creates-app-mode/src/routes/api/chat/server.test.ts": U
|
|
220
|
-
}), ie = /* #__PURE__ */ Object.assign({ "./variants/plain/src/routes/(public)/ai/+page.svelte": W }), ae = /* #__PURE__ */ Object.assign({
|
|
221
|
-
"./providers/anthropic/src/lib/server/ai.ts": G,
|
|
222
|
-
"./providers/gateway/src/lib/server/ai.ts": K,
|
|
223
|
-
"./providers/openai/src/lib/server/ai.ts": q
|
|
224
|
-
});
|
|
225
|
-
async function oe(e) {
|
|
226
|
-
let a = r(Z, e), c = o(e), l = e.input.serverTests ?? !0, u = {}, d = (e) => {
|
|
227
|
-
for (let t of e) u[t.path] = t;
|
|
228
|
-
};
|
|
229
|
-
d(t(ne, "./creates/", ie, c === "plain" ? "plain" : void 0)), e.features.auth && d(Object.values(n(re, "./creates-app-mode/"))), d(i(ae, a.id));
|
|
230
|
-
let f = `${$(e)}/`;
|
|
231
|
-
return {
|
|
232
|
-
creates: Object.values(u).filter((e) => l || !e.path.endsWith("server.test.ts")).map((e) => e.path.startsWith("src/routes/(public)/ai/") ? {
|
|
233
|
-
...e,
|
|
234
|
-
path: f + e.path.slice(23)
|
|
235
|
-
} : e).sort((e, t) => e.path.localeCompare(t.path)),
|
|
236
|
-
modifies: [],
|
|
237
|
-
deletes: [],
|
|
238
|
-
components: c === "plain" ? [] : ["button", "textarea"],
|
|
239
|
-
packages: [
|
|
240
|
-
...Y,
|
|
241
|
-
s,
|
|
242
|
-
...X[a.id] ?? []
|
|
243
|
-
],
|
|
244
|
-
collections: [],
|
|
245
|
-
collectionPatches: [],
|
|
246
|
-
collectionDrops: []
|
|
247
|
-
};
|
|
248
|
-
}
|
|
249
|
-
//#endregion
|
|
250
|
-
export { v as C, b as S, I as _, X as a, _ as b, oe as c, G as d, U as f, z as g, B as h, J as i, q as l, V as m, Z as n, $ as o, H as p, Y as r, te as s, Q as t, K as u, L as v, x as w, y as x, R as y };
|
|
251
|
-
|
|
252
|
-
//# sourceMappingURL=generate-Ca_6FlPi.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"generate-Ca_6FlPi.js","names":[],"sources":["../../node_modules/change-case/dist/index.js","../../src/parse/route.ts","../../src/patterns/enable/ai/generate.ts"],"sourcesContent":["// Regexps involved with splitting words in various case formats.\nconst SPLIT_LOWER_UPPER_RE = /([\\p{Ll}\\d])(\\p{Lu})/gu;\nconst SPLIT_UPPER_UPPER_RE = /(\\p{Lu})([\\p{Lu}][\\p{Ll}])/gu;\n// Used to iterate over the initial split result and separate numbers.\nconst SPLIT_SEPARATE_NUMBER_RE = /(\\d)\\p{Ll}|(\\p{L})\\d/u;\n// Regexp involved with stripping non-word characters from the result.\nconst DEFAULT_STRIP_REGEXP = /[^\\p{L}\\d]+/giu;\n// The replacement value for splits.\nconst SPLIT_REPLACE_VALUE = \"$1\\0$2\";\n// The default characters to keep after transforming case.\nconst DEFAULT_PREFIX_SUFFIX_CHARACTERS = \"\";\n/**\n * Split any cased input strings into an array of words.\n */\nexport function split(value) {\n let result = value.trim();\n result = result\n .replace(SPLIT_LOWER_UPPER_RE, SPLIT_REPLACE_VALUE)\n .replace(SPLIT_UPPER_UPPER_RE, SPLIT_REPLACE_VALUE);\n result = result.replace(DEFAULT_STRIP_REGEXP, \"\\0\");\n let start = 0;\n let end = result.length;\n // Trim the delimiter from around the output string.\n while (result.charAt(start) === \"\\0\")\n start++;\n if (start === end)\n return [];\n while (result.charAt(end - 1) === \"\\0\")\n end--;\n return result.slice(start, end).split(/\\0/g);\n}\n/**\n * Split the input string into an array of words, separating numbers.\n */\nexport function splitSeparateNumbers(value) {\n const words = split(value);\n for (let i = 0; i < words.length; i++) {\n const word = words[i];\n const match = SPLIT_SEPARATE_NUMBER_RE.exec(word);\n if (match) {\n const offset = match.index + (match[1] ?? match[2]).length;\n words.splice(i, 1, word.slice(0, offset), word.slice(offset));\n }\n }\n return words;\n}\n/**\n * Convert a string to space separated lower case (`foo bar`).\n */\nexport function noCase(input, options) {\n const [prefix, words, suffix] = splitPrefixSuffix(input, options);\n return (prefix +\n words.map(lowerFactory(options?.locale)).join(options?.delimiter ?? \" \") +\n suffix);\n}\n/**\n * Convert a string to camel case (`fooBar`).\n */\nexport function camelCase(input, options) {\n const [prefix, words, suffix] = splitPrefixSuffix(input, options);\n const lower = lowerFactory(options?.locale);\n const upper = upperFactory(options?.locale);\n const transform = options?.mergeAmbiguousCharacters\n ? capitalCaseTransformFactory(lower, upper)\n : pascalCaseTransformFactory(lower, upper);\n return (prefix +\n words\n .map((word, index) => {\n if (index === 0)\n return lower(word);\n return transform(word, index);\n })\n .join(options?.delimiter ?? \"\") +\n suffix);\n}\n/**\n * Convert a string to pascal case (`FooBar`).\n */\nexport function pascalCase(input, options) {\n const [prefix, words, suffix] = splitPrefixSuffix(input, options);\n const lower = lowerFactory(options?.locale);\n const upper = upperFactory(options?.locale);\n const transform = options?.mergeAmbiguousCharacters\n ? capitalCaseTransformFactory(lower, upper)\n : pascalCaseTransformFactory(lower, upper);\n return prefix + words.map(transform).join(options?.delimiter ?? \"\") + suffix;\n}\n/**\n * Convert a string to pascal snake case (`Foo_Bar`).\n */\nexport function pascalSnakeCase(input, options) {\n return capitalCase(input, { delimiter: \"_\", ...options });\n}\n/**\n * Convert a string to capital case (`Foo Bar`).\n */\nexport function capitalCase(input, options) {\n const [prefix, words, suffix] = splitPrefixSuffix(input, options);\n const lower = lowerFactory(options?.locale);\n const upper = upperFactory(options?.locale);\n return (prefix +\n words\n .map(capitalCaseTransformFactory(lower, upper))\n .join(options?.delimiter ?? \" \") +\n suffix);\n}\n/**\n * Convert a string to constant case (`FOO_BAR`).\n */\nexport function constantCase(input, options) {\n const [prefix, words, suffix] = splitPrefixSuffix(input, options);\n return (prefix +\n words.map(upperFactory(options?.locale)).join(options?.delimiter ?? \"_\") +\n suffix);\n}\n/**\n * Convert a string to dot case (`foo.bar`).\n */\nexport function dotCase(input, options) {\n return noCase(input, { delimiter: \".\", ...options });\n}\n/**\n * Convert a string to kebab case (`foo-bar`).\n */\nexport function kebabCase(input, options) {\n return noCase(input, { delimiter: \"-\", ...options });\n}\n/**\n * Convert a string to path case (`foo/bar`).\n */\nexport function pathCase(input, options) {\n return noCase(input, { delimiter: \"/\", ...options });\n}\n/**\n * Convert a string to path case (`Foo bar`).\n */\nexport function sentenceCase(input, options) {\n const [prefix, words, suffix] = splitPrefixSuffix(input, options);\n const lower = lowerFactory(options?.locale);\n const upper = upperFactory(options?.locale);\n const transform = capitalCaseTransformFactory(lower, upper);\n return (prefix +\n words\n .map((word, index) => {\n if (index === 0)\n return transform(word);\n return lower(word);\n })\n .join(options?.delimiter ?? \" \") +\n suffix);\n}\n/**\n * Convert a string to snake case (`foo_bar`).\n */\nexport function snakeCase(input, options) {\n return noCase(input, { delimiter: \"_\", ...options });\n}\n/**\n * Convert a string to header case (`Foo-Bar`).\n */\nexport function trainCase(input, options) {\n return capitalCase(input, { delimiter: \"-\", ...options });\n}\nfunction lowerFactory(locale) {\n return locale === false\n ? (input) => input.toLowerCase()\n : (input) => input.toLocaleLowerCase(locale);\n}\nfunction upperFactory(locale) {\n return locale === false\n ? (input) => input.toUpperCase()\n : (input) => input.toLocaleUpperCase(locale);\n}\nfunction capitalCaseTransformFactory(lower, upper) {\n return (word) => `${upper(word[0])}${lower(word.slice(1))}`;\n}\nfunction pascalCaseTransformFactory(lower, upper) {\n return (word, index) => {\n const char0 = word[0];\n const initial = index > 0 && char0 >= \"0\" && char0 <= \"9\" ? \"_\" + char0 : upper(char0);\n return initial + lower(word.slice(1));\n };\n}\nfunction splitPrefixSuffix(input, options = {}) {\n const splitFn = options.split ?? (options.separateNumbers ? splitSeparateNumbers : split);\n const prefixCharacters = options.prefixCharacters ?? DEFAULT_PREFIX_SUFFIX_CHARACTERS;\n const suffixCharacters = options.suffixCharacters ?? DEFAULT_PREFIX_SUFFIX_CHARACTERS;\n let prefixIndex = 0;\n let suffixIndex = input.length;\n while (prefixIndex < input.length) {\n const char = input.charAt(prefixIndex);\n if (!prefixCharacters.includes(char))\n break;\n prefixIndex++;\n }\n while (suffixIndex > prefixIndex) {\n const index = suffixIndex - 1;\n const char = input.charAt(index);\n if (!suffixCharacters.includes(char))\n break;\n suffixIndex = index;\n }\n return [\n input.slice(0, prefixIndex),\n splitFn(input.slice(prefixIndex, suffixIndex)),\n input.slice(suffixIndex),\n ];\n}\n//# sourceMappingURL=index.js.map","import * as changeCase from \"change-case\";\nimport { APP_DIR, PUBLIC_DIR } from \"../core/constants\";\nimport { InvalidArgumentError } from \"../core/errors\";\nimport type { Options } from \"../core/types\";\nimport type {\n Model,\n RouteInfo,\n RouteKind,\n ScaffoldFilePaths,\n ScaffoldUrls,\n} from \"./types\";\n\nconst ROUTES_ROOT = \"src/routes\";\nconst DYNAMIC_PARAM_RE = /\\[([^\\]]+)\\]/g;\nconst VALID_SEGMENT_RE = /^[a-zA-Z0-9_\\-[\\]()]+$/;\n\ntype RouteOptions = Pick<Options, \"features\" | \"routeGroups\">;\n\n/**\n * The group a route lands in when none is given, or null for a project that\n * has no such group. Without `routeGroups` this is the vela layout.\n */\nexport function defaultGroup({\n features,\n routeGroups,\n}: RouteOptions): string | null {\n const groups = routeGroups ?? { public: PUBLIC_DIR, app: APP_DIR };\n return features.auth ? (groups.app ?? groups.public) : groups.public;\n}\n\nfunction routeFileBase(group: string | null, route: string): string {\n return [ROUTES_ROOT, group, route].filter(Boolean).join(\"/\");\n}\n\nfunction defaultRouteSegment(model: Model, kind: RouteKind): string {\n return kind === \"scaffold\"\n ? changeCase.kebabCase(model.pluralDisplayName)\n : changeCase.kebabCase(model.displayName);\n}\n\nfunction stripRouteGroups(filePath: string): string {\n const withoutRoot = filePath.startsWith(`${ROUTES_ROOT}/`)\n ? filePath.slice(ROUTES_ROOT.length + 1)\n : filePath;\n const segments = withoutRoot.split(\"/\").filter((segment) => {\n return !(segment.startsWith(\"(\") && segment.endsWith(\")\"));\n });\n return `/${segments.join(\"/\")}`;\n}\n\nfunction extractDynamicParams(filePath: string): string[] {\n const params: string[] = [];\n for (const match of filePath.matchAll(DYNAMIC_PARAM_RE)) {\n params.push(match[1]);\n }\n return params;\n}\n\nfunction validateRouteInput(input: string): void {\n if (input.startsWith(\"/\")) {\n throw new InvalidArgumentError(\n `Route must not start with \"/\". Got: \"${input}\"`,\n );\n }\n if (input.startsWith(`${ROUTES_ROOT}/`) || input === ROUTES_ROOT) {\n throw new InvalidArgumentError(\n `Route must not start with \"${ROUTES_ROOT}/\" — paths are rooted there automatically. Got: \"${input}\"`,\n );\n }\n const segments = input.split(\"/\");\n for (const segment of segments) {\n if (segment.length === 0) {\n throw new InvalidArgumentError(\n `Route must not contain empty segments. Got: \"${input}\"`,\n );\n }\n if (segment === \".\" || segment === \"..\") {\n throw new InvalidArgumentError(\n `Route must not contain \".\" or \"..\" segments. Got: \"${input}\"`,\n );\n }\n if (segment.startsWith(\"_\")) {\n throw new InvalidArgumentError(\n `Route segments must not start with underscore. Got: \"${segment}\"`,\n );\n }\n if (!VALID_SEGMENT_RE.test(segment)) {\n throw new InvalidArgumentError(\n `Route segment \"${segment}\" contains invalid characters. Allowed: letters, digits, underscore, dash, brackets, parentheses.`,\n );\n }\n }\n}\n\nfunction hasRouteGroup(input: string): boolean {\n return input\n .split(\"/\")\n .some((segment) => segment.startsWith(\"(\") && segment.endsWith(\")\"));\n}\n\nexport function parseRoute(\n routeInput: string | undefined,\n model: Model,\n options: RouteOptions,\n kind: RouteKind,\n): RouteInfo {\n if (routeInput === undefined || routeInput === \"\") {\n const segment = defaultRouteSegment(model, kind);\n const fileBase = routeFileBase(defaultGroup(options), segment);\n return {\n fileBase,\n urlBase: stripRouteGroups(fileBase),\n dynamicParams: extractDynamicParams(fileBase),\n };\n }\n\n validateRouteInput(routeInput);\n\n const fileBase = routeFileBase(\n hasRouteGroup(routeInput) ? null : defaultGroup(options),\n routeInput,\n );\n\n return {\n fileBase,\n urlBase: stripRouteGroups(fileBase),\n dynamicParams: extractDynamicParams(fileBase),\n };\n}\n\nexport function scaffoldFilePaths(route: RouteInfo): ScaffoldFilePaths {\n return {\n list: route.fileBase,\n new: `${route.fileBase}/new`,\n show: `${route.fileBase}/[id]`,\n edit: `${route.fileBase}/[id]/edit`,\n };\n}\n\nexport function scaffoldUrls(route: RouteInfo): ScaffoldUrls {\n return {\n list: route.urlBase,\n new: `${route.urlBase}/new`,\n show: `${route.urlBase}/[id]`,\n edit: `${route.urlBase}/[id]/edit`,\n };\n}\n","import type {\n File,\n Options,\n Package,\n Provider,\n Result,\n} from \"../../../core/types\";\nimport type { EnvEdit } from \"../../../runtime/env\";\nimport { ZOD } from \"../../../core/constants\";\nimport { resolveUi } from \"../../../core/field/ui\";\nimport {\n providerCreates,\n providerEnvEdits,\n resolveProvider,\n} from \"../../../core/providers\";\nimport { composeCreates, filesFromGlob } from \"../../../core/util\";\nimport { defaultGroup } from \"../../../parse/route\";\n\n/**\n * The providers in prompt order. Each one's `env` key is what the CLI asks\n * for (without echo) and what `generate.runtime.ts` writes to `.env`; the\n * generated `src/lib/server/ai.ts` reads it through `$env/dynamic/private`,\n * and `/api/chat` answers 503 while it is blank.\n */\nexport const PROVIDERS: Provider[] = [\n {\n id: \"gateway\",\n label: \"Vercel AI Gateway\",\n env: [\n {\n key: \"AI_GATEWAY_API_KEY\",\n label: \"Vercel AI Gateway API key\",\n secret: true,\n },\n ],\n },\n {\n id: \"openai\",\n label: \"OpenAI\",\n env: [\n {\n key: \"OPENAI_API_KEY\",\n label: \"OpenAI API key\",\n placeholder: \"sk-...\",\n secret: true,\n },\n ],\n },\n {\n id: \"anthropic\",\n label: \"Anthropic\",\n env: [\n {\n key: \"ANTHROPIC_API_KEY\",\n label: \"Anthropic API key\",\n placeholder: \"sk-ant-...\",\n secret: true,\n },\n ],\n },\n];\n\n/**\n * `ai` carries the gateway provider itself; the others are a package each.\n * zod, a peer of `ai`, is installed alongside but is not listed here: it is\n * not the pattern's to uninstall.\n */\nexport const PACKAGES: Package[] = [\"ai@^7.0.107\", \"@ai-sdk/svelte@^5.0.107\"];\nexport const PROVIDER_PACKAGES: Record<string, Package[]> = {\n openai: [\"@ai-sdk/openai@^4.0.71\"],\n anthropic: [\"@ai-sdk/anthropic@^4.0.58\"],\n};\n\n/** What `resolveProvider` needs; `index.ts` spreads the rest of the metadata. */\nexport const META = { slug: \"enable-ai\", providers: PROVIDERS };\n\n/** Where the demo page is stored; `generate` moves it to the project's default group. */\nexport const DEMO_DIR = \"src/routes/(public)/ai/\";\n\n/**\n * The demo page's directory: `(public)/ai`, `(app)/ai` behind sign-in when\n * auth is on, or `ai` straight under `src/routes` in a project without groups.\n */\nexport function demoDir(\n options: Pick<Options, \"features\" | \"routeGroups\">,\n): string {\n return [\"src/routes\", defaultGroup(options), \"ai\"].filter(Boolean).join(\"/\");\n}\n\n/** The `.env` lines for a provider, under a `# AI SDK (<Label>)` heading. */\nexport function envEditsFor(\n provider: Provider,\n supplied: Record<string, string> = {},\n): EnvEdit[] {\n return providerEnvEdits(provider, `AI SDK (${provider.label})`, supplied);\n}\n\nconst createsRaw = import.meta.glob<string>(\"./creates/**\", {\n query: \"?raw\",\n import: \"default\",\n eager: true,\n});\n\n// With auth, the endpoint answers only signed-in users: every reply is\n// billed to the project's API key.\nconst createsAppModeRaw = import.meta.glob<string>(\"./creates-app-mode/**\", {\n query: \"?raw\",\n import: \"default\",\n eager: true,\n});\n\n// A plain project gets the demo page in native elements, at the same path.\nconst variantsRaw = import.meta.glob<string>(\"./variants/**\", {\n query: \"?raw\",\n import: \"default\",\n eager: true,\n});\n\nconst providersRaw = import.meta.glob<string>(\"./providers/**\", {\n query: \"?raw\",\n import: \"default\",\n eager: true,\n});\n\nexport async function generate(options: Options) {\n const provider = resolveProvider(META, options);\n const ui = resolveUi(options);\n const serverTests = options.input.serverTests ?? true;\n\n const files: Record<string, File> = {};\n const add = (list: File[]) => {\n for (const file of list) files[file.path] = file;\n };\n add(\n composeCreates(\n createsRaw,\n \"./creates/\",\n variantsRaw,\n ui === \"plain\" ? \"plain\" : undefined,\n ),\n );\n if (options.features.auth) {\n add(Object.values(filesFromGlob(createsAppModeRaw, \"./creates-app-mode/\")));\n }\n add(providerCreates(providersRaw, provider.id));\n\n const target = `${demoDir(options)}/`;\n const creates = Object.values(files)\n .filter((file) => serverTests || !file.path.endsWith(\"server.test.ts\"))\n .map((file) =>\n file.path.startsWith(DEMO_DIR)\n ? { ...file, path: target + file.path.slice(DEMO_DIR.length) }\n : file,\n )\n .sort((a, b) => a.path.localeCompare(b.path));\n\n return {\n creates,\n modifies: [],\n deletes: [],\n components: ui === \"plain\" ? [] : [\"button\", \"textarea\"],\n // vela's templates already have zod; a project vela did not create may not.\n packages: [...PACKAGES, ZOD, ...(PROVIDER_PACKAGES[provider.id] ?? [])],\n collections: [],\n collectionPatches: [],\n collectionDrops: [],\n } satisfies Result;\n}\n"],"x_google_ignoreList":[0],"mappings":";;;;;;AACA,IAAM,IAAuB,0BACvB,IAAuB,gCAEvB,IAA2B,yBAE3B,IAAuB,kBAEvB,IAAsB,UAEtB,IAAmC;AAIzC,SAAgB,EAAM,GAAO;CACzB,IAAI,IAAS,EAAM,KAAK;CAIxB,AAHA,IAAS,EACJ,QAAQ,GAAsB,CAAmB,CAAC,CAClD,QAAQ,GAAsB,CAAmB,GACtD,IAAS,EAAO,QAAQ,GAAsB,IAAI;CAClD,IAAI,IAAQ,GACR,IAAM,EAAO;CAEjB,OAAO,EAAO,OAAO,CAAK,MAAM,OAC5B;CACJ,IAAI,MAAU,GACV,OAAO,CAAC;CACZ,OAAO,EAAO,OAAO,IAAM,CAAC,MAAM,OAC9B;CACJ,OAAO,EAAO,MAAM,GAAO,CAAG,CAAC,CAAC,MAAM,KAAK;AAC/C;AAIA,SAAgB,EAAqB,GAAO;CACxC,IAAM,IAAQ,EAAM,CAAK;CACzB,KAAK,IAAI,IAAI,GAAG,IAAI,EAAM,QAAQ,KAAK;EACnC,IAAM,IAAO,EAAM,IACb,IAAQ,EAAyB,KAAK,CAAI;EAChD,IAAI,GAAO;GACP,IAAM,IAAS,EAAM,SAAS,EAAM,MAAM,EAAM,GAAA,CAAI;GACpD,EAAM,OAAO,GAAG,GAAG,EAAK,MAAM,GAAG,CAAM,GAAG,EAAK,MAAM,CAAM,CAAC;EAChE;CACJ;CACA,OAAO;AACX;AAIA,SAAgB,EAAO,GAAO,GAAS;CACnC,IAAM,CAAC,GAAQ,GAAO,KAAU,EAAkB,GAAO,CAAO;CAChE,OAAQ,IACJ,EAAM,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,CACtE,KAAK,MACJ,EAAK,KAAK,WAAA,yBAAmB,IACzB;GAAE,GAAG;GAAM,MAAM,IAAS,EAAK,KAAK,MAAM,EAAe;EAAE,IAC3D,CACN,CAAC,CACA,MAAM,GAAG,MAAM,EAAE,KAAK,cAAc,EAAE,IAAI,CAG3C;EACA,UAAU,CAAC;EACX,SAAS,CAAC;EACV,YAAY,MAAO,UAAU,CAAC,IAAI,CAAC,UAAU,UAAU;EAEvD,UAAU;GAAC,GAAG;GAAU;GAAK,GAAI,EAAkB,EAAS,OAAO,CAAC;EAAE;EACtE,aAAa,CAAC;EACd,mBAAmB,CAAC;EACpB,iBAAiB,CAAC;CACpB;AACF"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"generate-CyuY2Ci7.js","names":[],"sources":["../../src/patterns/enable/cms/generate.ts"],"sourcesContent":["import type { File, Options, Result } from \"../../../core/types\";\nimport { InvalidArgumentError } from \"../../../core/errors\";\nimport { filesFromGlob } from \"../../../core/util\";\n\n// The backend, for an app that hosts the CMS itself: the SQLite-backed HTTP\n// API and the two routes that mount it and serve uploads.\nconst backendRaw = import.meta.glob<string>(\"./creates-backend/**\", {\n query: \"?raw\",\n import: \"default\",\n eager: true,\n});\n\nconst BACKEND_PREFIX = \"./creates-backend/\";\n\n/** Where an app that hosts the backend itself mounts it. Also the admin bar's default. */\nexport const LOCAL_ENDPOINT = \"/api/cms\";\n\nexport const ENDPOINT_EXAMPLE =\n \"https://velastack.dev/v1/projects/<project>/cms\";\n\nexport interface CmsMode {\n /** What the read path and the admin bar talk to. */\n endpoint: string;\n /** Whether this app hosts the backend at `endpoint` itself. */\n local: boolean;\n}\n\n/** `--endpoint <url>` or `--endpoint=<url>`, for callers that hand flags through in argv. */\nfunction endpointFromArgv(argv: string[]): string | undefined {\n for (let i = 0; i < argv.length; i++) {\n const arg = argv[i];\n if (arg === \"--endpoint\") return argv[i + 1];\n if (arg.startsWith(\"--endpoint=\")) return arg.slice(\"--endpoint=\".length);\n }\n return undefined;\n}\n\n/**\n * Which of the two shapes to produce.\n *\n * An explicit `--endpoint` means a hosted CMS: the app only reads from it and\n * the admin bar signs in there, so no backend is installed. Without one, an\n * app with a server hosts the backend itself at `/api/cms`. A static site has\n * no server to host it, so there the endpoint is required.\n */\nexport function resolveMode(options: Options): CmsMode {\n const raw =\n typeof options.input.endpoint === \"string\"\n ? options.input.endpoint\n : endpointFromArgv(options.argv);\n const endpoint = raw?.trim().replace(/\\/+$/, \"\");\n\n if (endpoint) {\n if (!/^https?:\\/\\/\\S+$/.test(endpoint)) {\n throw new InvalidArgumentError(\n `--endpoint must be the absolute URL of a hosted CMS, like ${ENDPOINT_EXAMPLE}; got ${endpoint}`,\n );\n }\n return { endpoint, local: false };\n }\n\n // A PocketBase backend implies a Node server, but it is not the only way to\n // have one: a project on adapter-node alone can host the SQLite backend too.\n // The caller detects that and says so with `input.server`.\n if (!(options.input.server ?? options.features.backend)) {\n throw new InvalidArgumentError(\n \"This site has no server to host the CMS backend. \" +\n `Point it at a hosted CMS instead: vela enable cms --endpoint ${ENDPOINT_EXAMPLE}`,\n );\n }\n\n return { endpoint: LOCAL_ENDPOINT, local: true };\n}\n\n/** `$lib/cms.ts`: the read path, with the endpoint and locales bound. */\nfunction cmsLibSource(mode: CmsMode, i18n: boolean): string {\n const imports = [\n \"import { apiAdapter, createCms } from '@velastack/cms/server';\",\n ];\n if (i18n) imports.push(\"import { locales } from '$locales/data';\");\n\n const where = mode.local\n ? [\n \" * `/api/cms` is where `src/routes/api/cms/[...path]/+server.ts` mounts the\",\n \" * backend. It is also the admin bar's default, so the endpoint is named here\",\n \" * and nowhere else.\",\n ]\n : [\n \" * The CMS is hosted at this endpoint: the app reads published content from\",\n \" * it and the admin bar signs in there. The same URL is given to the `cms()`\",\n \" * plugin in vite.config.ts, which downloads media into the build.\",\n ];\n\n const which = i18n\n ? [\n \" * The locales are the site's own, from wuchale, so the CMS supports exactly\",\n \" * the languages the UI does; the first is the default that a missing\",\n \" * translation falls back to.\",\n ]\n : [\n \" * `locales` lists every locale the site supports; the first is the default\",\n \" * that a missing translation falls back to.\",\n ];\n\n return [\n ...imports,\n \"\",\n \"/**\",\n \" * The CMS read path, called from the root `+layout.server.ts`.\",\n \" *\",\n ...where,\n \" *\",\n ...which,\n \" */\",\n \"export const { load: loadCms, generateEntries } = createCms({\",\n `\\tadapter: apiAdapter({ endpoint: '${mode.endpoint}' }),`,\n `\\tlocales: ${i18n ? \"[...locales]\" : \"['en']\"}`,\n \"});\",\n \"\",\n ].join(\"\\n\");\n}\n\nexport async function generate(options: Options) {\n const mode = resolveMode(options);\n const creates: Record<string, File> = {};\n\n if (mode.local) {\n Object.assign(creates, filesFromGlob(backendRaw, BACKEND_PREFIX));\n }\n\n creates[\"src/lib/cms.ts\"] = {\n path: \"src/lib/cms.ts\",\n language: \"ts\",\n content: cmsLibSource(mode, options.features.i18n),\n status: \"success\",\n };\n\n const sortedCreates = Object.values(creates).sort((a, b) =>\n a.path.localeCompare(b.path),\n );\n\n // better-sqlite3 and marked are the package's optional peers, which npm\n // skips on install precisely because they are optional — so they have to be\n // named here. The backend needs the first; the root entry imports the\n // second statically, so <AdminBar /> cannot render without it.\n // 0.2.2 is the first release whose Vite plugin imports from the package\n // name rather than its own source tree; 0.2.1 breaks every consumer route.\n // 0.2.3 is the first whose shipped admin-bar.css declares its tokens on the\n // @scope root; before it the bar renders unstyled in every consumer.\n // The backend's cms.ts resolves its database with `dataPath` from\n // @velastack/kit, which a backend template has and a project on adapter-node\n // alone does not.\n const packages = mode.local\n ? [\"@velastack/cms@^0.2.3\", \"@velastack/kit\", \"better-sqlite3\", \"marked\"]\n : [\"@velastack/cms@^0.2.3\", \"marked\"];\n\n return {\n creates: sortedCreates,\n modifies: [],\n deletes: [],\n components: [],\n packages,\n collections: [],\n collectionPatches: [],\n collectionDrops: [],\n } satisfies Result;\n}\n"],"mappings":";;;;AAMA,IAAM,IAAa,uBAAA,OAAA;CAAA,2CAAA;CAAA,6DAA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,CAAC;CAgCvC,OA9BI,EAAK,SACP,OAAO,OAAO,GAAS,EAAc,GAAY,CAAc,CAAC,GAGlE,EAAQ,oBAAoB;EAC1B,MAAM;EACN,UAAU;EACV,SAAS,EAAa,GAAM,EAAQ,SAAS,IAAI;EACjD,QAAQ;CACV,GAqBO;EACL,SApBoB,OAAO,OAAO,CAAO,CAAC,CAAC,MAAM,GAAG,MACpD,EAAE,KAAK,cAAc,EAAE,IAAI,CAmBlB;EACT,UAAU,CAAC;EACX,SAAS,CAAC;EACV,YAAY,CAAC;EACb,UATe,EAAK,QAClB;GAAC;GAAyB;GAAkB;GAAkB;EAAQ,IACtE,CAAC,yBAAyB,QAAQ;EAQpC,aAAa,CAAC;EACd,mBAAmB,CAAC;EACpB,iBAAiB,CAAC;CACpB;AACF"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"generate-DQeWOEPY.js","names":[],"sources":["../../src/patterns/disable/analytics/generate.ts"],"sourcesContent":["import type { Options, Result } from \"../../../core/types\";\nimport type { EnvEdit } from \"../../../runtime/env\";\nimport { allProviderPaths } from \"../../../core/providers\";\nimport { toDeleteEntry } from \"../../destroy/shared\";\nimport { envEditsFor, PROVIDERS } from \"../../enable/analytics/generate\";\n\nconst providersRaw = import.meta.glob<string>(\n \"../../enable/analytics/providers/**\",\n { query: \"?raw\", import: \"default\", eager: true },\n);\n\n/**\n * The `.env` lines every provider writes. The project only has one set, but\n * which one is not recorded anywhere, so all are removed; keys that are not\n * there are skipped.\n */\nexport function allEnvEdits(): EnvEdit[] {\n return PROVIDERS.flatMap((provider) => envEditsFor(provider));\n}\n\nexport async function generate(_options: Options) {\n return {\n creates: [],\n modifies: [],\n // Every provider's files: missing ones are skipped, and the emptied\n // components/analytics directory goes with them.\n deletes: allProviderPaths(providersRaw).map(toDeleteEntry),\n components: [],\n packages: [],\n // PostHog's SDK; the other providers load a script and install nothing.\n uninstalls: [\"posthog-js\"],\n collections: [],\n collectionPatches: [],\n collectionDrops: [],\n } satisfies Result;\n}\n"],"mappings":";;;;AAMA,IAAM,IAAe,uBAAA,OAAA;CAAA,yFAAA;CAAA,gFAAA;CAAA,4FAAA;CAAA,0FAAA;AAGrB,CAAA;AAOA,SAAgB,IAAyB;CACvC,OAAO,EAAU,SAAS,MAAa,EAAY,CAAQ,CAAC;AAC9D;AAEA,eAAsB,EAAS,GAAmB;CAChD,OAAO;EACL,SAAS,CAAC;EACV,UAAU,CAAC;EAGX,SAAS,EAAiB,CAAY,CAAC,CAAC,IAAI,CAAa;EACzD,YAAY,CAAC;EACb,UAAU,CAAC;EAEX,YAAY,CAAC,YAAY;EACzB,aAAa,CAAC;EACd,mBAAmB,CAAC;EACpB,iBAAiB,CAAC;CACpB;AACF"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"generate-DwADTUob.js","names":[],"sources":["../../src/patterns/disable/ai/generate.ts"],"sourcesContent":["import type { Options, Result } from \"../../../core/types\";\nimport type { EnvEdit } from \"../../../runtime/env\";\nimport { allProviderPaths } from \"../../../core/providers\";\nimport { appRelativePath } from \"../../../core/util\";\nimport { toDeleteEntry } from \"../../destroy/shared\";\nimport {\n DEMO_DIR,\n demoDir,\n envEditsFor,\n PACKAGES,\n PROVIDER_PACKAGES,\n PROVIDERS,\n} from \"../../enable/ai/generate\";\n\nconst createsRaw = import.meta.glob<string>(\"../../enable/ai/creates/**\", {\n query: \"?raw\",\n import: \"default\",\n eager: true,\n});\n\nconst createsAppModeRaw = import.meta.glob<string>(\n \"../../enable/ai/creates-app-mode/**\",\n { query: \"?raw\", import: \"default\", eager: true },\n);\n\nconst providersRaw = import.meta.glob<string>(\"../../enable/ai/providers/**\", {\n query: \"?raw\",\n import: \"default\",\n eager: true,\n});\n\ntype DemoOptions = Pick<Options, \"features\" | \"routeGroups\">;\n\n/**\n * Where enable-ai may have put the demo page in this project: the group it\n * picks with auth on and with it off. Auth enabled after AI leaves the page\n * in the public group, so both are candidates.\n */\nexport function demoDirs(options: DemoOptions): string[] {\n const dirs = [false, true].map((auth) =>\n demoDir({ ...options, features: { ...options.features, auth } }),\n );\n return [...new Set(dirs)];\n}\n\n/** A path enable-ai writes, with the stored demo directory moved to `dir`. */\nfunction atDemoDir(path: string, dir: string): string {\n return path.startsWith(DEMO_DIR)\n ? `${dir}/${path.slice(DEMO_DIR.length)}`\n : path;\n}\n\n/**\n * Every path enable-ai writes for this project: the model module, the\n * endpoint and its test, and the demo page in its current default group.\n * `generate.runtime.ts` adds the page in the other group when it exists.\n */\nexport function aiPaths(options: DemoOptions): string[] {\n const dir = demoDir(options);\n const paths = new Set<string>(allProviderPaths(providersRaw));\n for (const [raw, prefix] of [\n [createsRaw, \"../../enable/ai/creates/\"],\n [createsAppModeRaw, \"../../enable/ai/creates-app-mode/\"],\n ] as const) {\n for (const key of Object.keys(raw)) {\n paths.add(atDemoDir(appRelativePath(key, prefix), dir));\n }\n }\n return [...paths].sort();\n}\n\n/**\n * The `.env` lines every provider writes. Which provider was chosen is not\n * recorded, so all are removed; keys that are not there are skipped.\n */\nexport function allEnvEdits(): EnvEdit[] {\n return PROVIDERS.flatMap((provider) => envEditsFor(provider));\n}\n\nexport async function generate(options: Options) {\n return {\n creates: [],\n modifies: [],\n // Missing ones are skipped, and emptied directories (api/chat, ai) go too.\n deletes: aiPaths(options).map(toDeleteEntry),\n components: [],\n packages: [],\n // zod and the shadcn button/textarea stay: other code uses them.\n uninstalls: [...PACKAGES, ...Object.values(PROVIDER_PACKAGES).flat()],\n collections: [],\n collectionPatches: [],\n collectionDrops: [],\n } satisfies Result;\n}\n"],"mappings":";;;;;AAcA,IAAM,IAAa,uBAAA,OAAA;CAAA,+DAAA;CAAA,0DAAA;CAAA,8DAAA;AAIlB,CAAA,GAEK,IAAoB,uBAAA,OAAA;CAAA,mEAAA;CAAA,uEAAA;AAG1B,CAAA,GAEM,IAAe,uBAAA,OAAA;CAAA,4DAAA;CAAA,0DAAA;CAAA,yDAAA;AAIpB,CAAA;AASD,SAAgB,EAAS,GAAgC;CACvD,IAAM,IAAO,CAAC,IAAO,EAAI,CAAC,CAAC,KAAK,MAC9B,EAAQ;EAAE,GAAG;EAAS,UAAU;GAAE,GAAG,EAAQ;GAAU;EAAK;CAAE,CAAC,CACjE;CACA,OAAO,CAAC,GAAG,IAAI,IAAI,CAAI,CAAC;AAC1B;AAGA,SAAS,EAAU,GAAc,GAAqB;CACpD,OAAO,EAAK,WAAA,yBAAmB,IAC3B,GAAG,EAAI,GAAG,EAAK,MAAM,EAAS,MAAM,MACpC;AACN;AAOA,SAAgB,EAAQ,GAAgC;CACtD,IAAM,IAAM,EAAQ,CAAO,GACrB,IAAQ,IAAI,IAAY,EAAiB,CAAY,CAAC;CAC5D,KAAK,IAAM,CAAC,GAAK,MAAW,CAC1B,CAAC,GAAY,0BAA0B,GACvC,CAAC,GAAmB,mCAAmC,CACzD,GACE,KAAK,IAAM,KAAO,OAAO,KAAK,CAAG,GAC/B,EAAM,IAAI,EAAU,EAAgB,GAAK,CAAM,GAAG,CAAG,CAAC;CAG1D,OAAO,CAAC,GAAG,CAAK,CAAC,CAAC,KAAK;AACzB;AAMA,SAAgB,IAAyB;CACvC,OAAO,EAAU,SAAS,MAAa,EAAY,CAAQ,CAAC;AAC9D;AAEA,eAAsB,EAAS,GAAkB;CAC/C,OAAO;EACL,SAAS,CAAC;EACV,UAAU,CAAC;EAEX,SAAS,EAAQ,CAAO,CAAC,CAAC,IAAI,CAAa;EAC3C,YAAY,CAAC;EACb,UAAU,CAAC;EAEX,YAAY,CAAC,GAAG,GAAU,GAAG,OAAO,OAAO,CAAiB,CAAC,CAAC,KAAK,CAAC;EACpE,aAAa,CAAC;EACd,mBAAmB,CAAC;EACpB,iBAAiB,CAAC;CACpB;AACF"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"generate.runtime-4FDxnvCl.js","names":[],"sources":["../../src/patterns/disable/subscriptions/modifies/modify-webhook-server.ts","../../src/patterns/disable/subscriptions/modifies/modify-app-layout-svelte.ts","../../src/patterns/disable/subscriptions/modifies/modify-app-sidebar.ts","../../src/patterns/disable/subscriptions/modifies/revert-by-template.ts","../../src/patterns/disable/subscriptions/modifies/modify-app-layout-server.ts","../../src/patterns/disable/subscriptions/modifies/modify-nav-user.ts","../../src/patterns/disable/subscriptions/modifies/modify-billing-page-server.ts","../../src/patterns/disable/subscriptions/modifies/modify-billing-page-svelte.ts","../../src/patterns/disable/subscriptions/generate.runtime.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport { SyntaxKind } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport {\n removeImportByModuleSpecifier,\n withInMemoryScript,\n formatLikeSource,\n} from \"../../../../runtime/ts-morph-helpers\";\n\nconst SUBSCRIPTION_CASE_VALUES = new Set([\n \"customer.subscription.created\",\n \"customer.subscription.updated\",\n \"customer.subscription.deleted\",\n]);\n\nexport function unmodifyWebhookServer(filePath: string): ModifyOutcome {\n if (!fs.existsSync(filePath)) {\n return { status: \"success\", changed: false };\n }\n const original = fs.readFileSync(filePath, \"utf8\");\n if (!original.includes(\"handleSubscriptionCreated\")) {\n return { status: \"success\", changed: false };\n }\n\n const { source } = withInMemoryScript(original, (sf) => {\n removeImportByModuleSpecifier(sf, \"./subscription/created\");\n removeImportByModuleSpecifier(sf, \"./subscription/updated\");\n removeImportByModuleSpecifier(sf, \"./subscription/deleted\");\n\n const switchStmt = sf\n .getDescendantsOfKind(SyntaxKind.SwitchStatement)\n .find((stmt) => stmt.getExpression().getText().includes(\"event.type\"));\n if (!switchStmt) return;\n\n const caseBlock = switchStmt.getCaseBlock();\n // Collect matching case clauses first — removing invalidates node refs.\n const toRemove = caseBlock\n .getClauses()\n .filter((clause) => {\n if (clause.getKind() !== SyntaxKind.CaseClause) return false;\n const caseClause = clause.asKindOrThrow(SyntaxKind.CaseClause);\n const expr = caseClause.getExpression();\n const literal =\n expr.asKind(SyntaxKind.StringLiteral) ??\n expr.asKind(SyntaxKind.NoSubstitutionTemplateLiteral);\n if (!literal) return false;\n return SUBSCRIPTION_CASE_VALUES.has(literal.getLiteralValue());\n })\n .map((c) => c.asKindOrThrow(SyntaxKind.CaseClause));\n\n for (const clause of toRemove.reverse()) {\n clause.remove();\n }\n\n formatLikeSource(sf);\n });\n\n // Removing the clauses takes the blank line before `default:` with them.\n const spaced = source.replace(/(break;)\\n(\\s*default:)/, \"$1\\n\\n$2\");\n\n if (spaced === original) {\n return { status: \"success\", changed: false };\n }\n fs.writeFileSync(filePath, spaced, \"utf8\");\n return { status: \"success\", changed: true };\n}\n","import fs from \"node:fs\";\nimport { SvelteFile } from \"../../../../runtime/svelte-file\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nexport function unmodifyAppLayoutSvelte(filePath: string): ModifyOutcome {\n if (!fs.existsSync(filePath)) {\n return { status: \"success\", changed: false };\n }\n\n const file = SvelteFile.fromPath(filePath);\n if (!file.hasElement(\"AppSidebar\")) {\n return { status: \"success\", changed: false };\n }\n if (!file.hasAttribute(\"AppSidebar\", \"subscription\")) {\n return { status: \"success\", changed: false };\n }\n\n const removed = file.removeAttribute(\"AppSidebar\", \"subscription\");\n if (!removed) {\n return { status: \"success\", changed: false };\n }\n\n file.writeTo(filePath);\n return { status: \"success\", changed: file.hasChanged() };\n}\n","import fs from \"node:fs\";\nimport { SyntaxKind } from \"ts-morph\";\nimport { SvelteFile } from \"../../../../runtime/svelte-file\";\nimport {\n withInMemoryScript,\n formatLikeSource,\n} from \"../../../../runtime/ts-morph-helpers\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nfunction updateScript(source: string): string {\n const { source: out } = withInMemoryScript(source, (sf) => {\n for (const decl of sf.getVariableDeclarations()) {\n const init = decl.getInitializer();\n if (!init || init.getText() !== \"$props()\") continue;\n\n const nameNode = decl.getNameNode();\n if (nameNode.getKind() !== SyntaxKind.ObjectBindingPattern) continue;\n const pattern = nameNode.asKindOrThrow(SyntaxKind.ObjectBindingPattern);\n const elements = pattern.getElements();\n const hasSub = elements.some((e) => e.getName() === \"subscription\");\n\n // Strip subscription from the props type literal (the specific type\n // added by enable-subscriptions — leave unrelated `subscription` props\n // alone).\n const typeNode = decl.getTypeNode();\n if (typeNode?.getKind() === SyntaxKind.IntersectionType) {\n const intersection = typeNode.asKindOrThrow(\n SyntaxKind.IntersectionType,\n );\n for (const member of intersection.getTypeNodes()) {\n if (member.getKind() !== SyntaxKind.TypeLiteral) continue;\n const lit = member.asKindOrThrow(SyntaxKind.TypeLiteral);\n const propTexts = lit\n .getProperties()\n .map((p) => p.getText().replace(/[;,]\\s*$/, \"\"))\n .filter((t) => !/^\\s*subscription\\??\\s*:/.test(t));\n lit.replaceWithText(\n propTexts.length ? `{ ${propTexts.join(\"; \")}; }` : \"{}\",\n );\n break;\n }\n }\n\n if (hasSub) {\n const remaining = elements\n .filter((e) => e.getName() !== \"subscription\")\n .map((e) => e.getText());\n pattern.replaceWithText(`{ ${remaining.join(\", \")} }`);\n }\n }\n formatLikeSource(sf);\n });\n return out;\n}\n\nexport function unmodifyAppSidebar(filePath: string): ModifyOutcome {\n if (!fs.existsSync(filePath)) {\n return { status: \"success\", changed: false };\n }\n\n const source = fs.readFileSync(filePath, \"utf8\");\n const hasSubPropType = /subscription\\??\\s*:\\s*\\{/.test(source);\n const hasSubProp = /\\bsubscription\\s*=\\s*null\\b/.test(source);\n\n const file = new SvelteFile(source);\n const hasNavUserSubAttr =\n file.hasElement(\"NavUser\") && file.hasAttribute(\"NavUser\", \"subscription\");\n\n if (!hasSubPropType && !hasSubProp && !hasNavUserSubAttr) {\n return { status: \"success\", changed: false };\n }\n\n if (hasSubPropType || hasSubProp) {\n file.modifyScript(updateScript);\n }\n if (hasNavUserSubAttr) {\n file.removeAttribute(\"NavUser\", \"subscription\");\n }\n\n file.writeTo(filePath);\n return { status: \"success\", changed: file.hasChanged() };\n}\n","import fs from \"node:fs\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\n/**\n * Rewrites a file to the given `template` if the current content still shows\n * the `enabledMarker` (meaning enable-subscriptions is applied). If the marker\n * is absent (already reverted or never applied), it's a no-op.\n *\n * Strips leading `// [!code highlight:N]` / `<!-- [!code highlight:N] -->`\n * lines so templates can be pulled from `preview-modifies/` directories which\n * use those for documentation highlighting.\n */\nexport function revertByTemplate(\n filePath: string,\n template: string,\n enabledMarker: string,\n): ModifyOutcome {\n if (!fs.existsSync(filePath)) {\n return { status: \"success\", changed: false };\n }\n const current = fs.readFileSync(filePath, \"utf8\");\n if (!current.includes(enabledMarker)) {\n return { status: \"success\", changed: false };\n }\n const stripped = template\n .replace(/^[ \\t]*\\/\\/[ \\t]*\\[!code highlight:\\d+\\][ \\t]*\\r?\\n/gm, \"\")\n .replace(\n /^[ \\t]*<!--[ \\t]*\\[!code highlight:\\d+\\][ \\t]*-->[ \\t]*\\r?\\n/gm,\n \"\",\n );\n if (current === stripped) {\n return { status: \"success\", changed: false };\n }\n fs.writeFileSync(filePath, stripped, \"utf8\");\n return { status: \"success\", changed: true };\n}\n","import dedent from \"dedent\";\nimport { revertByTemplate } from \"./revert-by-template\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\n// Baseline velastack-auth (app)/+layout.server.ts — the state of the file\n// before enable-subscriptions wrapped it with loadActiveSubscription.\nconst BASELINE =\n dedent`\n export const load = ({ locals }) => {\n \\tconst user = locals.pb.authStore.record!;\n \\tconst breadcrumbs = [{ title: 'Home', url: '/dashboard' }];\n\n \\treturn { user, breadcrumbs };\n };\n` + \"\\n\";\n\nexport function unmodifyAppLayoutServer(filePath: string): ModifyOutcome {\n return revertByTemplate(filePath, BASELINE, \"loadActiveSubscription\");\n}\n","import { revertByTemplate } from \"./revert-by-template\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nexport function unmodifyNavUser(\n filePath: string,\n paymentsNavUserTemplate: string,\n): ModifyOutcome {\n return revertByTemplate(filePath, paymentsNavUserTemplate, \"planLabel\");\n}\n","import { revertByTemplate } from \"./revert-by-template\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nexport function unmodifyBillingPageServer(\n filePath: string,\n paymentsBillingPageServerTemplate: string,\n): ModifyOutcome {\n return revertByTemplate(\n filePath,\n paymentsBillingPageServerTemplate,\n \"selectPlan\",\n );\n}\n","import { revertByTemplate } from \"./revert-by-template\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nexport function unmodifyBillingPageSvelte(\n filePath: string,\n paymentsBillingPageSvelteTemplate: string,\n): ModifyOutcome {\n return revertByTemplate(\n filePath,\n paymentsBillingPageSvelteTemplate,\n \"availablePlans\",\n );\n}\n","import path from \"node:path\";\nimport type { File, Options, Result } from \"../../../core/types\";\nimport { getLogger } from \"../../../core/logger\";\nimport { modifyOutcomeToFile } from \"../../../runtime/modify-file\";\nimport { planDropsForCollections } from \"../../destroy/shared\";\nimport { unmodifyWebhookServer } from \"./modifies/modify-webhook-server\";\nimport { unmodifyAppLayoutSvelte } from \"./modifies/modify-app-layout-svelte\";\nimport { unmodifyAppSidebar } from \"./modifies/modify-app-sidebar\";\nimport { unmodifyAppLayoutServer } from \"./modifies/modify-app-layout-server\";\nimport { unmodifyNavUser } from \"./modifies/modify-nav-user\";\nimport { unmodifyBillingPageServer } from \"./modifies/modify-billing-page-server\";\nimport { unmodifyBillingPageSvelte } from \"./modifies/modify-billing-page-svelte\";\n\n// Pull the \"post-payments\" state of files that enable-subscriptions fully\n// overwrote. For the billing pages, that's exactly what enable-payments\n// writes in creates-app-mode; for nav-user it's the payments preview-modifies\n// snapshot (with highlight annotations stripped by the revert helper).\nimport paymentsNavUserTemplate from \"../../enable/payments/preview-modifies/src/lib/components/nav-user.svelte?raw\";\nimport paymentsBillingPageServerTemplate from \"../../enable/payments/creates-app-mode/src/routes/(app)/billing/+page.server.ts?raw\";\nimport paymentsBillingPageSvelteTemplate from \"../../enable/payments/creates-app-mode/src/routes/(app)/billing/+page.svelte?raw\";\n\nexport async function generate(options: Options) {\n const logger = getLogger(options);\n const modifies: File[] = [];\n const pushResult = (file: File | null) => {\n if (file) modifies.push(file);\n };\n\n logger.info(\"Reverting webhooks/stripe/handlers/dispatch.ts\");\n const webhookServerPath = path.join(\n options.root,\n \"src\",\n \"routes\",\n \"webhooks\",\n \"stripe\",\n \"handlers\",\n \"dispatch.ts\",\n );\n pushResult(\n modifyOutcomeToFile(\n webhookServerPath,\n unmodifyWebhookServer(webhookServerPath),\n ),\n );\n\n logger.info(\"Reverting (app)/+layout.server.ts\");\n const appLayoutServerPath = path.join(\n options.root,\n \"src\",\n \"routes\",\n \"(app)\",\n \"+layout.server.ts\",\n );\n pushResult(\n modifyOutcomeToFile(\n appLayoutServerPath,\n unmodifyAppLayoutServer(appLayoutServerPath),\n ),\n );\n\n logger.info(\"Reverting (app)/+layout.svelte\");\n const appLayoutSveltePath = path.join(\n options.root,\n \"src\",\n \"routes\",\n \"(app)\",\n \"+layout.svelte\",\n );\n pushResult(\n modifyOutcomeToFile(\n appLayoutSveltePath,\n unmodifyAppLayoutSvelte(appLayoutSveltePath),\n ),\n );\n\n logger.info(\"Reverting app-sidebar.svelte\");\n const appSidebarPath = path.join(\n options.root,\n \"src\",\n \"lib\",\n \"components\",\n \"app-sidebar.svelte\",\n );\n pushResult(\n modifyOutcomeToFile(appSidebarPath, unmodifyAppSidebar(appSidebarPath)),\n );\n\n logger.info(\"Reverting nav-user.svelte\");\n const navUserPath = path.join(\n options.root,\n \"src\",\n \"lib\",\n \"components\",\n \"nav-user.svelte\",\n );\n pushResult(\n modifyOutcomeToFile(\n navUserPath,\n unmodifyNavUser(navUserPath, paymentsNavUserTemplate),\n ),\n );\n\n logger.info(\"Reverting billing/+page.server.ts\");\n const billingPageServerPath = path.join(\n options.root,\n \"src\",\n \"routes\",\n \"(app)\",\n \"billing\",\n \"+page.server.ts\",\n );\n pushResult(\n modifyOutcomeToFile(\n billingPageServerPath,\n unmodifyBillingPageServer(\n billingPageServerPath,\n paymentsBillingPageServerTemplate,\n ),\n ),\n );\n\n logger.info(\"Reverting billing/+page.svelte\");\n const billingPageSveltePath = path.join(\n options.root,\n \"src\",\n \"routes\",\n \"(app)\",\n \"billing\",\n \"+page.svelte\",\n );\n pushResult(\n modifyOutcomeToFile(\n billingPageSveltePath,\n unmodifyBillingPageSvelte(\n billingPageSveltePath,\n paymentsBillingPageSvelteTemplate,\n ),\n ),\n );\n\n const collectionDrops = await planDropsForCollections(\n [\"stripe_subscriptions\"],\n options,\n );\n\n return {\n creates: [],\n modifies,\n deletes: [],\n components: [],\n packages: [],\n collections: [],\n collectionPatches: [],\n collectionDrops,\n } satisfies Result;\n}\n"],"mappings":";;;;;;;;;;;AASA,IAAM,oBAA2B,IAAI,IAAI;CACvC;CACA;CACA;AACF,CAAC;AAED,SAAgB,EAAsB,GAAiC;CACrE,IAAI,CAAC,EAAG,WAAW,CAAQ,GACzB,OAAO;EAAE,QAAQ;EAAW,SAAS;CAAM;CAE7C,IAAM,IAAW,EAAG,aAAa,GAAU,MAAM;CACjD,IAAI,CAAC,EAAS,SAAS,2BAA2B,GAChD,OAAO;EAAE,QAAQ;EAAW,SAAS;CAAM;CAG7C,IAAM,EAAE,cAAW,EAAmB,IAAW,MAAO;EAGtD,AAFA,EAA8B,GAAI,wBAAwB,GAC1D,EAA8B,GAAI,wBAAwB,GAC1D,EAA8B,GAAI,wBAAwB;EAE1D,IAAM,IAAa,EAChB,qBAAqB,EAAW,eAAe,CAAC,CAChD,MAAM,MAAS,EAAK,cAAc,CAAC,CAAC,QAAQ,CAAC,CAAC,SAAS,YAAY,CAAC;EACvE,IAAI,CAAC,GAAY;EAIjB,IAAM,IAFY,EAAW,aAEZ,CAAA,CACd,WAAW,CAAC,CACZ,QAAQ,MAAW;GAClB,IAAI,EAAO,QAAQ,MAAM,EAAW,YAAY,OAAO;GAEvD,IAAM,IADa,EAAO,cAAc,EAAW,UACtC,CAAA,CAAW,cAAc,GAChC,IACJ,EAAK,OAAO,EAAW,aAAa,KACpC,EAAK,OAAO,EAAW,6BAA6B;GAEtD,OADK,IACE,EAAyB,IAAI,EAAQ,g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,MACR,OACA,UACA,SACA,gBACF;CAQA,AAPA,EACE,EACE,GACA,EAAwB,CAAmB,CAC7C,CACF,GAEA,EAAO,KAAK,8BAA8B;CAC1C,IAAM,IAAiB,EAAK,KAC1B,EAAQ,MACR,OACA,OACA,cACA,oBACF;CAKA,AAJA,EACE,EAAoB,GAAgB,EAAmB,CAAc,CAAC,CACxE,GAEA,EAAO,KAAK,2BAA2B;CACvC,IAAM,IAAc,EAAK,KACvB,EAAQ,MACR,OACA,OACA,cACA,iBACF;CAQA,AAPA,EACE,EACE,GACA,EAAgB,GAAa,CAAuB,CACtD,CACF,GAEA,EAAO,KAAK,mCAAmC;CAC/C,IAAM,IAAwB,EAAK,KACjC,EAAQ,MACR,OACA,UACA,SACA,WACA,iBACF;CAWA,AAVA,EACE,EACE,GACA,EACE,GACA,CACF,CACF,CACF,GAEA,EAAO,KAAK,gCAAgC;CAC5C,IAAM,IAAwB,EAAK,KACjC,EAAQ,MACR,OACA,UACA,SACA,WACA,cACF;CAgBA,OAfA,EACE,EACE,GACA,EACE,GACA,CACF,CACF,CACF,GAOO;EACL,SAAS,CAAC;EACV;EACA,SAAS,CAAC;EACV,YAAY,CAAC;EACb,UAAU,CAAC;EACX,aAAa,CAAC;EACd,mBAAmB,CAAC;EACpB,iBAAA,MAb4B,EAC5B,CAAC,sBAAsB,GACvB,CACF;CAWA;AACF"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"generate.runtime-AYQVW1S-.js","names":[],"sources":["../../src/patterns/enable/workflows/modifies/hooks.server.ts","../../src/patterns/enable/workflows/generate.runtime.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport dedent from \"dedent\";\nimport { Project, QuoteKind, type SourceFile } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport { formatLikeSource } from \"../../../../runtime/ts-morph-helpers\";\n\nconst INIT_SNIPPET = dedent`\n // Runs once when the server starts: executes the workflows in src/lib/workflows.\n export const init: ServerInit = () => startWorker();\n`;\n\nconst FAILURE_HINT = dedent`\n src/hooks.server.ts already exports an init hook. Start the workflow worker from it:\n\n import { startWorker } from '$lib/server/workflows';\n\n export const init: ServerInit = async () => {\n await startWorker();\n // ...the rest of your init\n };\n`;\n\nconst NOT_FOUND_HINT = dedent`\n Create src/hooks.server.ts and start the workflow worker from its init hook:\n\n import type { ServerInit } from '@sveltejs/kit';\n import { startWorker } from '$lib/server/workflows';\n\n export const init: ServerInit = () => startWorker();\n`;\n\nfunction ensureNamedImport(\n sourceFile: SourceFile,\n moduleSpecifier: string,\n name: string,\n typeOnly = false,\n) {\n const existing = sourceFile\n .getImportDeclarations()\n .find((d) => d.getModuleSpecifierValue() === moduleSpecifier);\n if (!existing) {\n sourceFile.addImportDeclaration({\n isTypeOnly: typeOnly,\n namedImports: [name],\n moduleSpecifier,\n });\n return;\n }\n if (existing.getNamedImports().some((ni) => ni.getName() === name)) return;\n // A declaration that is already `import type` covers the new name; a value\n // import takes the name as an inline `type` specifier.\n existing.addNamedImport(\n typeOnly && !existing.isTypeOnly() ? { name, isTypeOnly: true } : name,\n );\n}\n\nfunction hasInitExport(sourceFile: SourceFile): boolean {\n if (sourceFile.getVariableDeclaration(\"init\")) return true;\n if (sourceFile.getFunction(\"init\")) return true;\n return sourceFile\n .getExportDeclarations()\n .some((d) => d.getNamedExports().some((e) => e.getName() === \"init\"));\n}\n\n/**\n * Adds the `init` hook that starts the workflow worker. Projects created from\n * the base template already have it; this is the upgrade path for older ones.\n */\nexport function modifyHooksServerWorkflows(\n hooksServerPath: string,\n): ModifyOutcome {\n if (!fs.existsSync(hooksServerPath)) {\n return { status: \"not-found\", message: NOT_FOUND_HINT };\n }\n\n const original = fs.readFileSync(hooksServerPath, \"utf8\");\n if (original.includes(\"startWorker\")) {\n return { status: \"success\", changed: false };\n }\n\n const project = new Project({\n compilerOptions: { allowJs: true },\n manipulationSettings: { quoteKind: QuoteKind.Single },\n });\n const sourceFile = project.addSourceFileAtPath(hooksServerPath);\n\n if (hasInitExport(sourceFile)) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n ensureNamedImport(sourceFile, \"@sveltejs/kit\", \"ServerInit\", true);\n ensureNamedImport(sourceFile, \"$lib/server/workflows\", \"startWorker\");\n\n // After everything else, so the hook reads as the last thing the server does on start.\n sourceFile.addStatements(`\\n${INIT_SNIPPET}`);\n\n formatLikeSource(sourceFile);\n sourceFile.saveSync();\n return { status: \"success\", changed: true };\n}\n","import path from \"node:path\";\nimport type { File, Options, Result } from \"../../../core/types\";\nimport { getLogger } from \"../../../core/logger\";\nimport { modifyOutcomeToFile } from \"../../../runtime/modify-file\";\nimport { modifyHooksServerWorkflows } from \"./modifies/hooks.server\";\n\nexport async function generate(options: Options) {\n const logger = getLogger(options);\n const modifies: File[] = [];\n\n logger.info(\"Modifying hooks.server.ts\");\n const hooksServerPath = path.join(options.root, \"src\", \"hooks.server.ts\");\n const hooksFile = modifyOutcomeToFile(\n hooksServerPath,\n modifyHooksServerWorkflows(hooksServerPath),\n );\n if (hooksFile) modifies.push(hooksFile);\n\n return {\n creates: [],\n modifies,\n deletes: [],\n components: [],\n packages: [],\n collections: [],\n collectionPatches: [],\n collectionDrops: [],\n } satisfies Result;\n}\n"],"mappings":";;;;;;;;AAMA,IAAM,IAAe,CAAM;;;GAKrB,IAAe,CAAM;;;;;;;;;GAWrB,IAAiB,CAAM;;;;;;;;AAS7B,SAAS,EACP,GACA,GACA,GACA,IAAW,IACX;CACA,IAAM,IAAW,EACd,sBAAsB,CAAC,CACvB,MAAM,MAAM,EAAE,wBAAwB,MAAM,CAAe;CAC9D,IAAI,CAAC,GAAU;EACb,EAAW,qBAAqB;GAC9B,YAAY;GACZ,cAAc,CAAC,CAAI;GACnB;EACF,CAAC;EACD;CACF;CACI,EAAS,gBAAgB,CAAC,CAAC,MAAM,MAAO,EAAG,QAAQ,MAAM,CAAI,KAGjE,EAAS,eACP,KAAY,CAAC,EAAS,WAAW,IAAI;EAAE;EAAM,YAAY;CAAK,I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@ -1,117 +0,0 @@
|
|
|
1
|
-
import { n as e } from "./logger-CQONztPm.js";
|
|
2
|
-
import { t } from "./shared-C8GtNxpm.js";
|
|
3
|
-
import { n } from "./env-BPfk1VAw.js";
|
|
4
|
-
import { f as r, o as i } from "./ts-morph-helpers-CeduA--o.js";
|
|
5
|
-
import { modifyOutcomeToFile as a } from "./modify-file-Dwfv0dCI.js";
|
|
6
|
-
import { t as o } from "./svelte-file-B3RfgVdt.js";
|
|
7
|
-
import s from "node:fs";
|
|
8
|
-
import c from "node:path";
|
|
9
|
-
import { Project as l, QuoteKind as u, SyntaxKind as d } from "ts-morph";
|
|
10
|
-
//#region src/patterns/disable/payments/modifies/modify-nav-user.ts
|
|
11
|
-
function f(e) {
|
|
12
|
-
if (!s.existsSync(e)) return {
|
|
13
|
-
status: "success",
|
|
14
|
-
changed: !1
|
|
15
|
-
};
|
|
16
|
-
let t = s.readFileSync(e, "utf8");
|
|
17
|
-
if (!t.includes("/billing")) return {
|
|
18
|
-
status: "success",
|
|
19
|
-
changed: !1
|
|
20
|
-
};
|
|
21
|
-
let n = new o(t), i = !1, a = (e) => {
|
|
22
|
-
i || e((e) => {
|
|
23
|
-
let t = r(e, "Billing", "@lucide/svelte/icons/credit-card");
|
|
24
|
-
return t.wasRemoved && (i = !0), t.source;
|
|
25
|
-
});
|
|
26
|
-
};
|
|
27
|
-
return a((e) => n.modifyModuleScript(e)), i || a((e) => n.modifyScript(e)), i ? (s.writeFileSync(e, n.toString(), "utf8"), {
|
|
28
|
-
status: "success",
|
|
29
|
-
changed: !0
|
|
30
|
-
}) : {
|
|
31
|
-
status: "success",
|
|
32
|
-
changed: !1
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
//#endregion
|
|
36
|
-
//#region src/patterns/disable/payments/modifies/modify-user-signup.ts
|
|
37
|
-
var p = /* @__PURE__ */ new Set(["linkStripeCustomer.run", "linkStripeCustomer"]);
|
|
38
|
-
function m(e) {
|
|
39
|
-
if (!s.existsSync(e)) return {
|
|
40
|
-
status: "success",
|
|
41
|
-
changed: !1
|
|
42
|
-
};
|
|
43
|
-
let t = s.readFileSync(e, "utf8");
|
|
44
|
-
if (!t.includes("linkStripeCustomer")) return {
|
|
45
|
-
status: "success",
|
|
46
|
-
changed: !1
|
|
47
|
-
};
|
|
48
|
-
let n = new l({ manipulationSettings: { quoteKind: u.Single } }).addSourceFileAtPath(e);
|
|
49
|
-
for (let e of ["$lib/workflows/link-stripe-customer", "$lib/stripe"]) {
|
|
50
|
-
let t = n.getImportDeclarations().find((t) => t.getModuleSpecifierValue() === e);
|
|
51
|
-
t && t.remove();
|
|
52
|
-
}
|
|
53
|
-
let r = n.getVariableStatement((e) => e.getDeclarations().some((e) => e.getName() === "linkStripeCustomer"));
|
|
54
|
-
r && r.remove();
|
|
55
|
-
let a = n.getDescendantsOfKind(d.CallExpression).filter((e) => p.has(e.getExpression().getText()));
|
|
56
|
-
for (let e of a) {
|
|
57
|
-
let t = e.getFirstAncestorByKind(d.ExpressionStatement);
|
|
58
|
-
t && t.remove();
|
|
59
|
-
}
|
|
60
|
-
return i(n), n.saveSync(), {
|
|
61
|
-
status: "success",
|
|
62
|
-
changed: n.getFullText() !== t
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
//#endregion
|
|
66
|
-
//#region src/patterns/disable/payments/generate.runtime.ts
|
|
67
|
-
async function h(r) {
|
|
68
|
-
let i = r.features.auth, o = e(r), s = [], l = (e) => {
|
|
69
|
-
e && s.push(e);
|
|
70
|
-
};
|
|
71
|
-
o.info("Stripping Stripe credentials from .env");
|
|
72
|
-
let u = [
|
|
73
|
-
{
|
|
74
|
-
type: "comment",
|
|
75
|
-
key: "Stripe credentials"
|
|
76
|
-
},
|
|
77
|
-
{
|
|
78
|
-
type: "var",
|
|
79
|
-
key: "STRIPE_SECRET_KEY"
|
|
80
|
-
},
|
|
81
|
-
{
|
|
82
|
-
type: "var",
|
|
83
|
-
key: "PUBLIC_STRIPE_PUBLISHABLE_KEY"
|
|
84
|
-
},
|
|
85
|
-
{
|
|
86
|
-
type: "var",
|
|
87
|
-
key: "STRIPE_WEBHOOK_SECRET"
|
|
88
|
-
}
|
|
89
|
-
], d = c.join(r.root, ".env");
|
|
90
|
-
if (l(a(d, n(d, u))), i) {
|
|
91
|
-
o.info("Reverting nav-user.svelte");
|
|
92
|
-
let e = c.join(r.root, "src", "lib", "components", "nav-user.svelte");
|
|
93
|
-
l(a(e, f(e))), o.info("Reverting signup +page.server.ts");
|
|
94
|
-
let t = c.join(r.root, "src", "routes", "(public)", "(auth)", "signup", "+page.server.ts");
|
|
95
|
-
l(a(t, m(t)));
|
|
96
|
-
}
|
|
97
|
-
return {
|
|
98
|
-
creates: [],
|
|
99
|
-
modifies: s,
|
|
100
|
-
deletes: [],
|
|
101
|
-
components: [],
|
|
102
|
-
packages: [],
|
|
103
|
-
collections: [],
|
|
104
|
-
collectionPatches: [],
|
|
105
|
-
collectionDrops: await t(i ? [
|
|
106
|
-
"transactions",
|
|
107
|
-
"stripe_customers",
|
|
108
|
-
"stripe_payment_methods",
|
|
109
|
-
"stripe_prices",
|
|
110
|
-
"stripe_products"
|
|
111
|
-
] : ["stripe_prices", "stripe_products"], r)
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
|
-
//#endregion
|
|
115
|
-
export { h as generate };
|
|
116
|
-
|
|
117
|
-
//# sourceMappingURL=generate.runtime-B2aFFaac.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"generate.runtime-B2aFFaac.js","names":[],"sources":["../../src/patterns/disable/payments/modifies/modify-nav-user.ts","../../src/patterns/disable/payments/modifies/modify-user-signup.ts","../../src/patterns/disable/payments/generate.runtime.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport { SvelteFile } from \"../../../../runtime/svelte-file\";\nimport { removeNavItemFromScript } from \"../../../../runtime/ts-morph-helpers\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nexport function unmodifyNavUser(navUserPath: string): ModifyOutcome {\n if (!fs.existsSync(navUserPath)) {\n return { status: \"success\", changed: false };\n }\n\n const source = fs.readFileSync(navUserPath, \"utf8\");\n if (!source.includes(\"/billing\")) {\n return { status: \"success\", changed: false };\n }\n\n const file = new SvelteFile(source);\n let wasRemoved = false;\n\n const tryRemove = (run: (fn: (s: string) => string) => boolean) => {\n if (wasRemoved) return;\n run((src) => {\n const result = removeNavItemFromScript(\n src,\n \"Billing\",\n \"@lucide/svelte/icons/credit-card\",\n );\n if (result.wasRemoved) wasRemoved = true;\n return result.source;\n });\n };\n\n tryRemove((fn) => file.modifyModuleScript(fn));\n if (!wasRemoved) tryRemove((fn) => file.modifyScript(fn));\n\n if (!wasRemoved) {\n return { status: \"success\", changed: false };\n }\n\n fs.writeFileSync(navUserPath, file.toString(), \"utf8\");\n return { status: \"success\", changed: true };\n}\n","import fs from \"node:fs\";\nimport { Project, QuoteKind, SyntaxKind } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport { formatLikeSource } from \"../../../../runtime/ts-morph-helpers\";\n\nconst CALL_EXPRESSIONS = new Set([\n \"linkStripeCustomer.run\",\n // Projects from before the workflow: an inline helper called directly.\n \"linkStripeCustomer\",\n]);\n\nexport function unmodifyUserSignup(userSignupPath: string): ModifyOutcome {\n if (!fs.existsSync(userSignupPath)) {\n return { status: \"success\", changed: false };\n }\n\n const originalSource = fs.readFileSync(userSignupPath, \"utf8\");\n if (!originalSource.includes(\"linkStripeCustomer\")) {\n return { status: \"success\", changed: false };\n }\n\n const project = new Project({\n manipulationSettings: { quoteKind: QuoteKind.Single },\n });\n const sourceFile = project.addSourceFileAtPath(userSignupPath);\n\n for (const specifier of [\n \"$lib/workflows/link-stripe-customer\",\n \"$lib/stripe\",\n ]) {\n const decl = sourceFile\n .getImportDeclarations()\n .find((d) => d.getModuleSpecifierValue() === specifier);\n if (decl) decl.remove();\n }\n\n const linkFn = sourceFile.getVariableStatement((s) =>\n s.getDeclarations().some((d) => d.getName() === \"linkStripeCustomer\"),\n );\n if (linkFn) linkFn.remove();\n\n const callStatements = sourceFile\n .getDescendantsOfKind(SyntaxKind.CallExpression)\n .filter((ce) => CALL_EXPRESSIONS.has(ce.getExpression().getText()));\n for (const call of callStatements) {\n const stmt = call.getFirstAncestorByKind(SyntaxKind.ExpressionStatement);\n if (stmt) stmt.remove();\n }\n\n formatLikeSource(sourceFile);\n sourceFile.saveSync();\n\n return {\n status: \"success\",\n changed: sourceFile.getFullText() !== originalSource,\n };\n}\n","import path from \"node:path\";\nimport type { File, Options, Result } from \"../../../core/types\";\nimport { getLogger } from \"../../../core/logger\";\nimport { modifyOutcomeToFile } from \"../../../runtime/modify-file\";\nimport { modifyEnvRemove, type EnvEdit } from \"../../../runtime/env\";\nimport { unmodifyNavUser } from \"./modifies/modify-nav-user\";\nimport { unmodifyUserSignup } from \"./modifies/modify-user-signup\";\nimport { planDropsForCollections } from \"../../destroy/shared\";\n\nexport async function generate(options: Options) {\n const isAppMode = options.features.auth;\n const logger = getLogger(options);\n const modifies: File[] = [];\n const pushResult = (file: File | null) => {\n if (file) modifies.push(file);\n };\n\n logger.info(\"Stripping Stripe credentials from .env\");\n const envEdits: EnvEdit[] = [\n { type: \"comment\", key: \"Stripe credentials\" },\n { type: \"var\", key: \"STRIPE_SECRET_KEY\" },\n { type: \"var\", key: \"PUBLIC_STRIPE_PUBLISHABLE_KEY\" },\n { type: \"var\", key: \"STRIPE_WEBHOOK_SECRET\" },\n ];\n const envPath = path.join(options.root, \".env\");\n pushResult(modifyOutcomeToFile(envPath, modifyEnvRemove(envPath, envEdits)));\n\n if (isAppMode) {\n logger.info(\"Reverting nav-user.svelte\");\n const navUserPath = path.join(\n options.root,\n \"src\",\n \"lib\",\n \"components\",\n \"nav-user.svelte\",\n );\n pushResult(modifyOutcomeToFile(navUserPath, unmodifyNavUser(navUserPath)));\n\n logger.info(\"Reverting signup +page.server.ts\");\n const userSignupPath = path.join(\n options.root,\n \"src\",\n \"routes\",\n \"(public)\",\n \"(auth)\",\n \"signup\",\n \"+page.server.ts\",\n );\n pushResult(\n modifyOutcomeToFile(userSignupPath, unmodifyUserSignup(userSignupPath)),\n );\n }\n\n const collectionNames = [\n \"transactions\",\n \"stripe_customers\",\n \"stripe_payment_methods\",\n \"stripe_prices\",\n \"stripe_products\",\n ];\n const collectionDrops = await planDropsForCollections(\n isAppMode ? collectionNames : [\"stripe_prices\", \"stripe_products\"],\n options,\n );\n\n return {\n creates: [],\n modifies,\n deletes: [],\n components: [],\n packages: [],\n collections: [],\n collectionPatches: [],\n collectionDrops,\n } satisfies Result;\n}\n"],"mappings":";;;;;;;;;;AAKA,SAAgB,EAAgB,GAAoC;CAClE,IAAI,CAAC,EAAG,WAAW,CAAW,GAC5B,OAAO;EAAE,QAAQ;EAAW,SAAS;CAAM;CAG7C,IAAM,IAAS,EAAG,aAAa,GAAa,MAAM;CAClD,IAAI,CAAC,EAAO,SAAS,UAAU,GAC7B,OAAO;EAAE,QAAQ;EAAW,SAAS;CAAM;CAG7C,IAAM,IAAO,IAAI,EAAW,CAAM,GAC9B,IAAa,IAEX,KAAa,MAAgD;EAC7D,KACJ,GAAK,MAAQ;GACX,IAAM,IAAS,EACb,GACA,WACA,kCACF;GAEA,OADI,EAAO,eAAY,IAAa,KAC7B,EAAO;EAChB,CAAC;CACH;CAUA,OARA,GAAW,MAAO,EAAK,mBAAmB,CAAE,CAAC,GACxC,KAAY,GAAW,MAAO,EAAK,aAAa,CAAE,CAAC,GAEnD,KAIL,EAAG,cAAc,GAAa,EAAK,SAAS,GAAG,MAAM,GAC9C;EAAE,QAAQ;EAAW,SAAS;CAAK,KAJjC;EAAE,QAAQ;EAAW,SAAS;CAAM;AAK/C;;;ACnCA,IAAM,oBAAmB,IAAI,IAAI,CAC/B,0BAEA,oBACF,CAAC;AAED,SAAgB,EAAmB,GAAuC;CACxE,IAAI,CAAC,EAAG,WAAW,CAAc,GAC/B,OAAO;EAAE,QAAQ;EAAW,SAAS;CAAM;CAG7C,IAAM,IAAiB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KAAK;EAAwB;CAC9C,GACM,IAAU,EAAK,KAAK,EAAQ,MAAM,MAAM;CAG9C,IAFA,EAAW,EAAoB,GAAS,EAAgB,GAAS,CAAQ,CAAC,CAAC,GAEvE,GAAW;EACb,EAAO,KAAK,2BAA2B;EACvC,IAAM,IAAc,EAAK,KACvB,EAAQ,MACR,OACA,OACA,cACA,iBACF;EAGA,AAFA,EAAW,EAAoB,GAAa,EAAgB,CAAW,CAAC,CAAC,GAEzE,EAAO,KAAK,kCAAkC;EAC9C,IAAM,IAAiB,EAAK,KAC1B,EAAQ,MACR,OACA,UACA,YACA,UACA,UACA,iBACF;EACA,EACE,EAAoB,GAAgB,EAAmB,CAAc,CAAC,CACxE;CACF;CAcA,OAAO;EACL,SAAS,CAAC;EACV;EACA,SAAS,CAAC;EACV,YAAY,CAAC;EACb,UAAU,CAAC;EACX,aAAa,CAAC;EACd,mBAAmB,CAAC;EACpB,iBAAA,MAb4B,EAC5B,IAAY;GAPZ;GACA;GACA;GACA;GACA;EAGY,IAAkB,CAAC,iBAAiB,iBAAiB,GACjE,CACF;CAWA;AACF"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"generate.runtime-B45MvtYm.js","names":[],"sources":["../../src/patterns/enable/content-negotiation/modifies/hooks.server.ts","../../src/patterns/enable/content-negotiation/modifies/hooks.ts","../../src/patterns/enable/content-negotiation/modifies/root-layout.svelte.ts","../../src/patterns/enable/content-negotiation/generate.runtime.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport path from \"node:path\";\nimport dedent from \"dedent\";\nimport { Project, QuoteKind, type SourceFile } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport { addHandle } from \"../../../../runtime/compose-handle\";\nimport { formatLikeSource } from \"../../../../runtime/ts-morph-helpers\";\n\nconst FAILURE_HINT = dedent`\n Wrap your exported handle with the negotiation handler:\n\n import { sequence } from '@sveltejs/kit/hooks';\n import { handle as handleNegotiate } from '$lib/negotiate';\n\n export const handle = sequence(handleNegotiate, /* your existing handle */);\n`;\n\nconst HOOKS_SERVER_SNIPPET = dedent`\n import { handle as handleNegotiate } from '$lib/negotiate';\n\n export const handle = handleNegotiate;\n`;\n\nfunction ensureNegotiateHandleImport(sourceFile: SourceFile) {\n const existing = sourceFile\n .getImportDeclarations()\n .find((d) => d.getModuleSpecifierValue() === \"$lib/negotiate\");\n if (existing) {\n const has = existing.getNamedImports().some((ni) => {\n return (\n ni.getName() === \"handle\" &&\n ni.getAliasNode()?.getText() === \"handleNegotiate\"\n );\n });\n if (!has)\n existing.addNamedImport({ name: \"handle\", alias: \"handleNegotiate\" });\n return;\n }\n sourceFile.addImportDeclaration({\n namedImports: [{ name: \"handle\", alias: \"handleNegotiate\" }],\n moduleSpecifier: \"$lib/negotiate\",\n });\n}\n\nexport function modifyHooksServerNegotiate(\n hooksServerPath: string,\n): ModifyOutcome {\n if (!fs.existsSync(hooksServerPath)) {\n // SvelteKit loads the first `hooks.server.*` it finds, and `.js` sorts\n // first, so a new `.ts` beside it would never run.\n if (fs.existsSync(hooksServerPath.replace(/\\.ts$/, \".js\"))) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n fs.mkdirSync(path.dirname(hooksServerPath), { recursive: true });\n fs.writeFileSync(hooksServerPath, HOOKS_SERVER_SNIPPET + \"\\n\");\n return { status: \"success\", changed: true };\n }\n\n const original = fs.readFileSync(hooksServerPath, \"utf8\");\n if (original.includes(\"handleNegotiate\")) {\n return { status: \"success\", changed: false };\n }\n\n const project = new Project({\n compilerOptions: { allowJs: true },\n manipulationSettings: { quoteKind: QuoteKind.Single },\n });\n const sourceFile = project.addSourceFileAtPath(hooksServerPath);\n\n const composed = addHandle(sourceFile, { expression: \"handleNegotiate\" });\n if (composed.status === \"unsupported\") {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n ensureNegotiateHandleImport(sourceFile);\n formatLikeSource(sourceFile);\n sourceFile.saveSync();\n return {\n status: \"success\",\n changed: sourceFile.getFullText() !== original,\n };\n}\n","import fs from \"node:fs\";\nimport path from \"node:path\";\nimport dedent from \"dedent\";\nimport { Project, QuoteKind, SyntaxKind, type SourceFile } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport { formatLikeSource } from \"../../../../runtime/ts-morph-helpers\";\n\nconst NEGOTIATE_ONLY_SNIPPET = dedent`\n import { reroute as negotiateReroute } from '$lib/negotiate';\n\n export const reroute = ({ url }) => negotiateReroute(url.pathname);\n`;\n\nconst FAILURE_HINT = dedent`\n Compose your existing reroute in src/hooks.ts with the negotiation reroute:\n\n import { reroute as negotiateReroute } from '$lib/negotiate';\n\n export const reroute = ({ url }) => existingReroute(negotiateReroute(url.pathname));\n`;\n\nfunction ensureNegotiateImport(sourceFile: SourceFile) {\n const existing = sourceFile\n .getImportDeclarations()\n .find((d) => d.getModuleSpecifierValue() === \"$lib/negotiate\");\n if (existing) {\n const has = existing.getNamedImports().some((ni) => {\n return (\n ni.getName() === \"reroute\" &&\n ni.getAliasNode()?.getText() === \"negotiateReroute\"\n );\n });\n if (!has) {\n existing.addNamedImport({ name: \"reroute\", alias: \"negotiateReroute\" });\n }\n return;\n }\n sourceFile.addImportDeclaration({\n namedImports: [{ name: \"reroute\", alias: \"negotiateReroute\" }],\n moduleSpecifier: \"$lib/negotiate\",\n });\n}\n\nexport function modifyHooksNegotiate(hooksPath: string): ModifyOutcome {\n if (!fs.existsSync(hooksPath)) {\n fs.mkdirSync(path.dirname(hooksPath), { recursive: true });\n fs.writeFileSync(hooksPath, NEGOTIATE_ONLY_SNIPPET + \"\\n\");\n return { status: \"success\", changed: true };\n }\n\n const original = fs.readFileSync(hooksPath, \"utf8\");\n if (original.includes(\"negotiateReroute\")) {\n return { status: \"success\", changed: false };\n }\n\n const project = new Project({\n compilerOptions: { allowJs: true },\n manipulationSettings: { quoteKind: QuoteKind.Single },\n });\n const sourceFile = project.addSourceFileAtPath(hooksPath);\n\n const rerouteDecl = sourceFile.getVariableDeclaration(\"reroute\");\n\n if (!rerouteDecl) {\n ensureNegotiateImport(sourceFile);\n sourceFile.addStatements(\n `\\nexport const reroute = ({ url }) => negotiateReroute(url.pathname);\\n`,\n );\n formatLikeSource(sourceFile);\n sourceFile.saveSync();\n return { status: \"success\", changed: true };\n }\n\n const rerouteStmt = rerouteDecl.getFirstAncestorByKind(\n SyntaxKind.VariableStatement,\n );\n if (!rerouteStmt?.hasExportKeyword()) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n const init = rerouteDecl.getInitializer();\n if (!init) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n const hasI18nHelper = sourceFile\n .getVariableDeclarations()\n .some((d) => d.getName() === \"rerouteDeLocalize\");\n const initText = init.getText();\n\n if (hasI18nHelper && initText.includes(\"rerouteDeLocalize\")) {\n ensureNegotiateImport(sourceFile);\n rerouteDecl.setInitializer(\n \"({ url }) => rerouteDeLocalize(negotiateReroute(url.pathname))\",\n );\n formatLikeSource(sourceFile);\n sourceFile.saveSync();\n return { status: \"success\", changed: true };\n }\n\n return { status: \"failed\", message: FAILURE_HINT };\n}\n","import fs from \"node:fs\";\nimport dedent from \"dedent\";\nimport { SvelteFile } from \"../../../../runtime/svelte-file\";\nimport {\n ensureImports,\n withInMemoryScript,\n} from \"../../../../runtime/ts-morph-helpers\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nconst IMPORT_SNIPPET = dedent`\n import { Negotiate } from '$lib/negotiate';\n`;\n\nconst MARKUP_SNIPPET = \"\\n<Negotiate />\\n\";\n\nconst NOT_FOUND_HINT = [\n \"Create the root +layout.svelte and mount <Negotiate /> inside it.\",\n \"\",\n \"Import for the <script> tag:\",\n \"\",\n IMPORT_SNIPPET,\n \"\",\n \"Markup to add at the top level of the layout:\",\n MARKUP_SNIPPET.trim(),\n].join(\"\\n\");\n\nexport function modifyRootLayoutNegotiate(layoutPath: string): ModifyOutcome {\n if (!fs.existsSync(layoutPath)) {\n return { status: \"not-found\", message: NOT_FOUND_HINT };\n }\n\n const file = SvelteFile.fromPath(layoutPath);\n if (file.hasElement(\"Negotiate\")) {\n return { status: \"success\", changed: false };\n }\n\n file.modifyScript((source) => {\n const { source: out } = withInMemoryScript(source, (sf) => {\n ensureImports(sf, [\n {\n namedImports: [\"Negotiate\"],\n moduleSpecifier: \"$lib/negotiate\",\n },\n ]);\n });\n return out;\n });\n\n file.appendMarkup(MARKUP_SNIPPET);\n file.writeTo(layoutPath);\n return { status: \"success\", changed: file.hasChanged() };\n}\n","import path from \"node:path\";\nimport type { File, Options, Result } from \"../../../core/types\";\nimport { getLogger } from \"../../../core/logger\";\nimport { modifyOutcomeToFile } from \"../../../runtime/modify-file\";\nimport { modifyHooksServerNegotiate } from \"./modifies/hooks.server\";\nimport { modifyHooksNegotiate } from \"./modifies/hooks\";\nimport { modifyRootLayoutNegotiate } from \"./modifies/root-layout.svelte\";\n\nexport async function generate(options: Options) {\n const logger = getLogger(options);\n const modifies: File[] = [];\n\n const pushResult = (file: File | null) => {\n if (file) modifies.push(file);\n };\n\n logger.info(\"Modifying hooks.server.ts\");\n const hooksServerPath = path.join(options.root, \"src\", \"hooks.server.ts\");\n pushResult(\n modifyOutcomeToFile(\n hooksServerPath,\n modifyHooksServerNegotiate(hooksServerPath),\n ),\n );\n\n logger.info(\"Modifying hooks.ts\");\n const hooksPath = path.join(options.root, \"src\", \"hooks.ts\");\n pushResult(modifyOutcomeToFile(hooksPath, modifyHooksNegotiate(hooksPath)));\n\n logger.info(\"Modifying src/routes/+layout.svelte\");\n const rootLayoutPath = path.join(\n options.root,\n \"src\",\n \"routes\",\n \"+layout.svelte\",\n );\n pushResult(\n modifyOutcomeToFile(\n rootLayoutPath,\n modifyRootLayoutNegotiate(rootLayoutPath),\n ),\n );\n\n return {\n creates: [],\n modifies,\n deletes: [],\n components: [],\n packages: [],\n collections: [],\n collectionPatches: [],\n collectionDrops: [],\n } satisfies Result;\n}\n"],"mappings":";;;;;;;;;;AAQA,IAAM,IAAe,CAAM;;;;;;;GASrB,IAA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