@velastack/patterns 0.0.1 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunks/{collections-BRabBN4M.js → collections-Hdx-NhPn.js} +3 -3
- package/dist/chunks/{collections-BRabBN4M.js.map → collections-Hdx-NhPn.js.map} +1 -1
- package/dist/chunks/{env.runtime-_7lT2q35.js → env.runtime-B18zkdjb.js} +2 -2
- package/dist/chunks/{env.runtime-_7lT2q35.js.map → env.runtime-B18zkdjb.js.map} +1 -1
- package/dist/chunks/{generate.runtime-BR_qnQ-6.js → generate.runtime-B5XT4Q2Z.js} +75 -141
- package/dist/chunks/{generate.runtime-BR_qnQ-6.js.map → generate.runtime-B5XT4Q2Z.js.map} +1 -1
- package/dist/chunks/{index-D5FMXkZu.js → index-Crknwby3.js} +669 -561
- package/dist/chunks/index-Crknwby3.js.map +1 -0
- package/dist/chunks/{pocketbase-D612ARa5.js → pocketbase-BBMFXc3L.js} +2 -2
- package/dist/chunks/{pocketbase-D612ARa5.js.map → pocketbase-BBMFXc3L.js.map} +1 -1
- package/dist/index.d.ts +27 -0
- package/dist/index.js +1 -1
- package/package.json +4 -2
- package/dist/chunks/index-D5FMXkZu.js.map +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { readFileSync as s } from "node:fs";
|
|
2
|
-
import { l as c } from "./index-
|
|
3
|
-
import { w as l, g as u } from "./pocketbase-
|
|
2
|
+
import { l as c } from "./index-Crknwby3.js";
|
|
3
|
+
import { w as l, g as u } from "./pocketbase-BBMFXc3L.js";
|
|
4
4
|
function m(o) {
|
|
5
5
|
var n, a, t, e;
|
|
6
6
|
if (((t = (a = (n = o.response) == null ? void 0 : n.data) == null ? void 0 : a.name) == null ? void 0 : t.code) === "validation_not_unique")
|
|
@@ -35,4 +35,4 @@ async function h(o, r) {
|
|
|
35
35
|
export {
|
|
36
36
|
h as createCollections
|
|
37
37
|
};
|
|
38
|
-
//# sourceMappingURL=collections-
|
|
38
|
+
//# sourceMappingURL=collections-Hdx-NhPn.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"collections-
|
|
1
|
+
{"version":3,"file":"collections-Hdx-NhPn.js","sources":["../../src/runtime/collections.ts"],"sourcesContent":["import { readFileSync } from \"node:fs\";\nimport type { CollectionSpec, File, Options } from \"../core/types\";\nimport { languageFromPath } from \"../core/util\";\nimport { getMigrationFile, withPocketbase } from \"./pocketbase\";\n\ninterface PocketBaseCollectionCreateError {\n response?: {\n data?: {\n name?: {\n code?: string;\n };\n };\n };\n message?: string;\n}\n\nfunction isCollectionAlreadyExistsError(\n error: PocketBaseCollectionCreateError,\n): boolean {\n if (error.response?.data?.name?.code === \"validation_not_unique\") {\n return true;\n }\n\n const message = error.message?.toLowerCase() ?? \"\";\n return message.includes(\"already exists\") || message.includes(\"must be unique\");\n}\n\nexport async function createCollections(\n collections: CollectionSpec[],\n options: Options,\n): Promise<File[]> {\n if (collections.length === 0) {\n return [];\n }\n\n const migrations: File[] = [];\n\n await withPocketbase(options.root, async (pb) => {\n for (const collection of collections) {\n try {\n await pb.collections.create(collection);\n } catch (error) {\n if (\n isCollectionAlreadyExistsError(\n error as PocketBaseCollectionCreateError,\n )\n ) {\n throw new Error(\n `Collection \"${collection.name}\" already exists. Choose a different model name or remove the existing collection first.`,\n );\n }\n throw error;\n }\n\n const migrationFile = getMigrationFile(collection.name, \"created\", options);\n if (!migrationFile) {\n continue;\n }\n\n migrations.push({\n path: migrationFile,\n language: languageFromPath(migrationFile),\n content: readFileSync(migrationFile, \"utf8\"),\n });\n }\n });\n\n return migrations;\n}\n"],"names":["isCollectionAlreadyExistsError","error","_c","_b","_a","message","_d","createCollections","collections","options","migrations","withPocketbase","pb","collection","migrationFile","getMigrationFile","languageFromPath","readFileSync"],"mappings":";;;AAgBA,SAASA,EACPC,GACS;;AACT,QAAIC,KAAAC,KAAAC,IAAAH,EAAM,aAAN,gBAAAG,EAAgB,SAAhB,gBAAAD,EAAsB,SAAtB,gBAAAD,EAA4B,UAAS;AACvC,WAAO;AAGT,QAAMG,MAAUC,IAAAL,EAAM,YAAN,gBAAAK,EAAe,kBAAiB;AAChD,SAAOD,EAAQ,SAAS,gBAAgB,KAAKA,EAAQ,SAAS,gBAAgB;AAChF;AAEA,eAAsBE,EACpBC,GACAC,GACiB;AACjB,MAAID,EAAY,WAAW;AACzB,WAAO,CAAA;AAGT,QAAME,IAAqB,CAAA;AAE3B,eAAMC,EAAeF,EAAQ,MAAM,OAAOG,MAAO;AAC/C,eAAWC,KAAcL,GAAa;AACpC,UAAI;AACF,cAAMI,EAAG,YAAY,OAAOC,CAAU;AAAA,MACxC,SAASZ,GAAO;AACd,cACED;AAAA,UACEC;AAAA,QAAA,IAGI,IAAI;AAAA,UACR,eAAeY,EAAW,IAAI;AAAA,QAAA,IAG5BZ;AAAA,MACR;AAEA,YAAMa,IAAgBC,EAAiBF,EAAW,MAAM,WAAWJ,CAAO;AAC1E,MAAKK,KAILJ,EAAW,KAAK;AAAA,QACd,MAAMI;AAAA,QACN,UAAUE,EAAiBF,CAAa;AAAA,QACxC,SAASG,EAAaH,GAAe,MAAM;AAAA,MAAA,CAC5C;AAAA,IACH;AAAA,EACF,CAAC,GAEMJ;AACT;"}
|
|
@@ -2,7 +2,7 @@ import { getCollections as i } from "@velastack/pocketbase/internal";
|
|
|
2
2
|
import s from "node:fs";
|
|
3
3
|
import r from "node:path";
|
|
4
4
|
import t from "node:process";
|
|
5
|
-
import { D as c } from "./index-
|
|
5
|
+
import { D as c } from "./index-Crknwby3.js";
|
|
6
6
|
function a(o) {
|
|
7
7
|
return s.existsSync(r.join(o, "package.json")) && s.existsSync(r.join(o, c));
|
|
8
8
|
}
|
|
@@ -33,4 +33,4 @@ export {
|
|
|
33
33
|
S as getCollections,
|
|
34
34
|
p as resolveProjectRoot
|
|
35
35
|
};
|
|
36
|
-
//# sourceMappingURL=env.runtime-
|
|
36
|
+
//# sourceMappingURL=env.runtime-B18zkdjb.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"env.runtime-
|
|
1
|
+
{"version":3,"file":"env.runtime-B18zkdjb.js","sources":["../../src/parse/env.runtime.ts"],"sourcesContent":["import { getCollections as getCollectionsFromPB } from \"@velastack/pocketbase/internal\";\nimport fs from \"node:fs\";\nimport path from \"node:path\";\nimport process from \"node:process\";\nimport { DATA_DIR } from \"../core/constants\";\nimport type { Collection } from \"./types\";\n\nfunction hasProjectMarkers(dir: string): boolean {\n return (\n fs.existsSync(path.join(dir, \"package.json\")) &&\n fs.existsSync(path.join(dir, DATA_DIR))\n );\n}\n\nexport function resolveProjectRoot(startDir = process.cwd()): string {\n let current = path.resolve(startDir);\n\n while (true) {\n if (hasProjectMarkers(current)) {\n return current;\n }\n\n const parent = path.dirname(current);\n if (parent === current) {\n break;\n }\n current = parent;\n }\n\n throw new Error(\n `Could not resolve project root from \"${startDir}\". Expected package.json, and ${DATA_DIR}.`,\n );\n}\n\nexport async function getCollections(): Promise<Collection[]> {\n const root = resolveProjectRoot();\n\n return getCollectionsFromPB({\n pocketbaseUrl: \"\",\n superuserEmail: process.env.POCKETBASE_SUPERUSER_EMAIL!,\n superuserPassword: process.env.POCKETBASE_SUPERUSER_PASSWORD!,\n root,\n }) as Promise<Collection[]>;\n}\n"],"names":["hasProjectMarkers","dir","fs","path","DATA_DIR","resolveProjectRoot","startDir","process","current","parent","getCollections","root","getCollectionsFromPB"],"mappings":";;;;;AAOA,SAASA,EAAkBC,GAAsB;AAC/C,SACEC,EAAG,WAAWC,EAAK,KAAKF,GAAK,cAAc,CAAC,KAC5CC,EAAG,WAAWC,EAAK,KAAKF,GAAKG,CAAQ,CAAC;AAE1C;AAEO,SAASC,EAAmBC,IAAWC,EAAQ,OAAe;AACnE,MAAIC,IAAUL,EAAK,QAAQG,CAAQ;AAEnC,aAAa;AACX,QAAIN,EAAkBQ,CAAO;AAC3B,aAAOA;AAGT,UAAMC,IAASN,EAAK,QAAQK,CAAO;AACnC,QAAIC,MAAWD;AACb;AAEF,IAAAA,IAAUC;AAAA,EACZ;AAEA,QAAM,IAAI;AAAA,IACR,wCAAwCH,CAAQ,iCAAiCF,CAAQ;AAAA,EAAA;AAE7F;AAEA,eAAsBM,IAAwC;AAC5D,QAAMC,IAAON,EAAA;AAEb,SAAOO,EAAqB;AAAA,IAC1B,eAAe;AAAA,IACf,gBAAgBL,EAAQ,IAAI;AAAA,IAC5B,mBAAmBA,EAAQ,IAAI;AAAA,IAC/B,MAAAI;AAAA,EAAA,CACD;AACH;"}
|
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
import y from "node:path";
|
|
2
|
-
import
|
|
3
|
-
import { w as
|
|
4
|
-
import { d as
|
|
2
|
+
import m from "node:fs";
|
|
3
|
+
import { w as v, g as S } from "./pocketbase-BBMFXc3L.js";
|
|
4
|
+
import { d as A } from "./index-Crknwby3.js";
|
|
5
5
|
import { Project as b, SyntaxKind as s } from "ts-morph";
|
|
6
|
-
function w(
|
|
7
|
-
if (!
|
|
8
|
-
const e =
|
|
6
|
+
function w(u) {
|
|
7
|
+
if (!m.existsSync(u)) {
|
|
8
|
+
const e = A`
|
|
9
9
|
export const load = async ({ locals }) => {
|
|
10
10
|
return { user: locals.pb.authStore.record };
|
|
11
11
|
};
|
|
12
12
|
`;
|
|
13
|
-
|
|
13
|
+
m.writeFileSync(u, e);
|
|
14
14
|
return;
|
|
15
15
|
}
|
|
16
|
-
const n = new b().addSourceFileAtPath(
|
|
16
|
+
const n = new b().addSourceFileAtPath(u), a = (e) => {
|
|
17
17
|
!!e.getProperty("user") || e.addPropertyAssignment({
|
|
18
18
|
name: "user",
|
|
19
19
|
initializer: "locals.pb.authStore.record"
|
|
20
20
|
});
|
|
21
21
|
};
|
|
22
|
-
let
|
|
22
|
+
let l, i;
|
|
23
23
|
const f = n.getVariableDeclaration("load");
|
|
24
24
|
if (f) {
|
|
25
25
|
const e = f.getFirstAncestorByKind(s.VariableStatement);
|
|
@@ -28,15 +28,15 @@ function w(l) {
|
|
|
28
28
|
s.ArrowFunction
|
|
29
29
|
);
|
|
30
30
|
if (c)
|
|
31
|
-
|
|
31
|
+
l = c;
|
|
32
32
|
else {
|
|
33
33
|
const t = f.getInitializer();
|
|
34
34
|
if (t) {
|
|
35
|
-
const
|
|
35
|
+
const g = t.getFirstDescendantByKind(
|
|
36
36
|
s.ArrowFunction
|
|
37
37
|
);
|
|
38
|
-
if (
|
|
39
|
-
|
|
38
|
+
if (g)
|
|
39
|
+
l = g;
|
|
40
40
|
else {
|
|
41
41
|
const h = t.getFirstDescendantByKind(
|
|
42
42
|
s.FunctionExpression
|
|
@@ -47,11 +47,11 @@ function w(l) {
|
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
|
-
if (!
|
|
50
|
+
if (!l) {
|
|
51
51
|
const e = n.getFunction("load");
|
|
52
52
|
e && e.isExported() && (i = e);
|
|
53
53
|
}
|
|
54
|
-
if (!
|
|
54
|
+
if (!l && !i) {
|
|
55
55
|
n.addFunction({
|
|
56
56
|
isExported: !0,
|
|
57
57
|
isAsync: !0,
|
|
@@ -61,7 +61,7 @@ function w(l) {
|
|
|
61
61
|
}), n.formatText(), n.saveSync();
|
|
62
62
|
return;
|
|
63
63
|
}
|
|
64
|
-
const d =
|
|
64
|
+
const d = l ?? i, p = d.getParameters();
|
|
65
65
|
if (p.length === 0)
|
|
66
66
|
d.insertParameter(0, { name: "{ locals }" });
|
|
67
67
|
else {
|
|
@@ -85,17 +85,17 @@ function w(l) {
|
|
|
85
85
|
});
|
|
86
86
|
}
|
|
87
87
|
}
|
|
88
|
-
if (
|
|
89
|
-
const e =
|
|
88
|
+
if (l) {
|
|
89
|
+
const e = l.getBody();
|
|
90
90
|
if (e.getKind() === s.Block)
|
|
91
91
|
e.getDescendantsOfKind(s.ReturnStatement).forEach((c) => {
|
|
92
92
|
const t = c.getExpression();
|
|
93
93
|
if (t) {
|
|
94
94
|
if (t.getKind() === s.ObjectLiteralExpression)
|
|
95
|
-
|
|
95
|
+
a(t);
|
|
96
96
|
else if (t.getKind() === s.ParenthesizedExpression) {
|
|
97
|
-
const
|
|
98
|
-
|
|
97
|
+
const g = t.getExpression();
|
|
98
|
+
g.getKind() === s.ObjectLiteralExpression && a(g);
|
|
99
99
|
}
|
|
100
100
|
}
|
|
101
101
|
});
|
|
@@ -103,8 +103,8 @@ function w(l) {
|
|
|
103
103
|
const r = e;
|
|
104
104
|
if (r.getKind() === s.ParenthesizedExpression) {
|
|
105
105
|
const c = r.getExpression();
|
|
106
|
-
c.getKind() === s.ObjectLiteralExpression &&
|
|
107
|
-
} else r.getKind() === s.ObjectLiteralExpression &&
|
|
106
|
+
c.getKind() === s.ObjectLiteralExpression && a(c);
|
|
107
|
+
} else r.getKind() === s.ObjectLiteralExpression && a(r);
|
|
108
108
|
}
|
|
109
109
|
} else if (i) {
|
|
110
110
|
const e = i.getBody();
|
|
@@ -112,54 +112,54 @@ function w(l) {
|
|
|
112
112
|
const t = c.getExpression();
|
|
113
113
|
if (t) {
|
|
114
114
|
if (t.getKind() === s.ObjectLiteralExpression)
|
|
115
|
-
|
|
115
|
+
a(t);
|
|
116
116
|
else if (t.getKind() === s.ParenthesizedExpression) {
|
|
117
|
-
const
|
|
118
|
-
|
|
117
|
+
const g = t.getExpression();
|
|
118
|
+
g.getKind() === s.ObjectLiteralExpression && a(g);
|
|
119
119
|
}
|
|
120
120
|
}
|
|
121
121
|
});
|
|
122
122
|
}
|
|
123
123
|
n.formatText(), n.saveSync();
|
|
124
124
|
}
|
|
125
|
-
function P(
|
|
126
|
-
let
|
|
127
|
-
const n =
|
|
125
|
+
function P(u) {
|
|
126
|
+
let o = m.readFileSync(u, "utf8");
|
|
127
|
+
const n = o.match(/<Navbar\.Root>([\s\S]*?)<\/Navbar\.Root>/);
|
|
128
128
|
if (!n)
|
|
129
129
|
return;
|
|
130
|
-
const
|
|
130
|
+
const a = n[1].match(
|
|
131
131
|
/<Navbar\.List>([\s\S]*?)<\/Navbar\.List>/
|
|
132
132
|
);
|
|
133
|
-
if (!
|
|
133
|
+
if (!a)
|
|
134
134
|
return;
|
|
135
|
-
const
|
|
135
|
+
const l = A`
|
|
136
136
|
import * as AuthMenu from '$lib/components/ui/auth-menu';
|
|
137
137
|
import * as Avatar from '$lib/components/ui/avatar';
|
|
138
|
-
`, i =
|
|
138
|
+
`, i = o.indexOf("<script");
|
|
139
139
|
if (i !== -1) {
|
|
140
|
-
const d =
|
|
140
|
+
const d = o.indexOf(">", i), p = d !== -1 ? o.indexOf("<\/script>", d + 1) : -1;
|
|
141
141
|
if (d !== -1 && p !== -1) {
|
|
142
|
-
const e =
|
|
142
|
+
const e = o.slice(d + 1, p);
|
|
143
143
|
let r = -1;
|
|
144
144
|
const c = /^\s*import[\s\S]*?;[ \t]*$/gm;
|
|
145
145
|
let t;
|
|
146
146
|
for (; (t = c.exec(e)) !== null; )
|
|
147
147
|
r = t.index + t[0].length;
|
|
148
148
|
if (r !== -1) {
|
|
149
|
-
const
|
|
150
|
-
${
|
|
149
|
+
const g = e.slice(0, r), h = e.slice(r), x = `${g}
|
|
150
|
+
${l}
|
|
151
151
|
${h}`;
|
|
152
|
-
|
|
152
|
+
o = o.slice(0, d + 1) + x + o.slice(p);
|
|
153
153
|
} else
|
|
154
|
-
|
|
154
|
+
o = o.replace("<\/script>", `${l}
|
|
155
155
|
<\/script>`);
|
|
156
156
|
} else
|
|
157
|
-
|
|
157
|
+
o = o.replace("<\/script>", `${l}
|
|
158
158
|
<\/script>`);
|
|
159
159
|
} else
|
|
160
|
-
|
|
160
|
+
o = o.replace("<\/script>", `${l}
|
|
161
161
|
<\/script>`);
|
|
162
|
-
const f =
|
|
162
|
+
const f = a[1] + `
|
|
163
163
|
<Navbar.Item
|
|
164
164
|
class="flex flex-col md:flex-row items-center space-y-2 md:space-y-0 md:space-x-4"
|
|
165
165
|
>
|
|
@@ -207,22 +207,22 @@ ${h}`;
|
|
|
207
207
|
</AuthMenu.Root>
|
|
208
208
|
</Navbar.Item>
|
|
209
209
|
`;
|
|
210
|
-
|
|
210
|
+
o = o.replace(a[1], f), m.writeFileSync(u, o);
|
|
211
211
|
}
|
|
212
|
-
function K(
|
|
213
|
-
const n = new b().addSourceFileAtPath(
|
|
214
|
-
if (!
|
|
212
|
+
function K(u) {
|
|
213
|
+
const n = new b().addSourceFileAtPath(u), a = n.getDescendantsOfKind(s.CallExpression).find((p) => p.getExpression().getText() === "handlePocketbase");
|
|
214
|
+
if (!a) {
|
|
215
215
|
n.saveSync();
|
|
216
216
|
return;
|
|
217
217
|
}
|
|
218
|
-
const
|
|
219
|
-
if (
|
|
220
|
-
|
|
218
|
+
const l = a.getArguments();
|
|
219
|
+
if (l.length === 0) {
|
|
220
|
+
a.addArgument("{ auth: { protectedRoutes: ['/(app)'] } }"), n.formatText(), n.saveSync();
|
|
221
221
|
return;
|
|
222
222
|
}
|
|
223
|
-
const i =
|
|
223
|
+
const i = l[0];
|
|
224
224
|
if (i.getKind() !== s.ObjectLiteralExpression) {
|
|
225
|
-
|
|
225
|
+
a.insertArgument(0, "{ auth: { protectedRoutes: ['/(app)'] } }"), n.formatText(), n.saveSync();
|
|
226
226
|
return;
|
|
227
227
|
}
|
|
228
228
|
const f = i.asKindOrThrow(s.ObjectLiteralExpression), d = f.getProperty("auth");
|
|
@@ -256,14 +256,14 @@ function K(l) {
|
|
|
256
256
|
}
|
|
257
257
|
n.formatText(), n.saveSync();
|
|
258
258
|
}
|
|
259
|
-
async function
|
|
260
|
-
const { input:
|
|
259
|
+
async function R(u) {
|
|
260
|
+
const { input: o } = u;
|
|
261
261
|
let n = [];
|
|
262
|
-
await
|
|
262
|
+
await v(u.root, async (d) => {
|
|
263
263
|
await d.settings.update({
|
|
264
264
|
meta: {
|
|
265
|
-
senderName:
|
|
266
|
-
senderAddress:
|
|
265
|
+
senderName: o.senderName,
|
|
266
|
+
senderAddress: o.senderAddress
|
|
267
267
|
}
|
|
268
268
|
});
|
|
269
269
|
const p = await d.collections.getOne("users");
|
|
@@ -296,117 +296,51 @@ async function O(l) {
|
|
|
296
296
|
body: c
|
|
297
297
|
}
|
|
298
298
|
});
|
|
299
|
-
const t =
|
|
299
|
+
const t = S("users", "updated", u);
|
|
300
300
|
t && n.push({
|
|
301
301
|
path: t,
|
|
302
302
|
language: "ts",
|
|
303
|
-
content:
|
|
304
|
-
}), await d.collections.create({
|
|
305
|
-
listRule: "@request.auth.id = user.id",
|
|
306
|
-
viewRule: "@request.auth.id = user.id",
|
|
307
|
-
name: "oauth_accounts",
|
|
308
|
-
type: "base",
|
|
309
|
-
fields: [
|
|
310
|
-
{
|
|
311
|
-
collectionId: p.id,
|
|
312
|
-
name: "user",
|
|
313
|
-
type: "relation",
|
|
314
|
-
required: !0,
|
|
315
|
-
maxSelect: 1
|
|
316
|
-
},
|
|
317
|
-
{
|
|
318
|
-
name: "providerId",
|
|
319
|
-
required: !0,
|
|
320
|
-
type: "text"
|
|
321
|
-
},
|
|
322
|
-
{
|
|
323
|
-
name: "provider",
|
|
324
|
-
required: !0,
|
|
325
|
-
type: "text"
|
|
326
|
-
},
|
|
327
|
-
{
|
|
328
|
-
name: "accessToken",
|
|
329
|
-
type: "text"
|
|
330
|
-
},
|
|
331
|
-
{
|
|
332
|
-
name: "refreshToken",
|
|
333
|
-
type: "text"
|
|
334
|
-
},
|
|
335
|
-
{
|
|
336
|
-
name: "avatarURL",
|
|
337
|
-
type: "text"
|
|
338
|
-
},
|
|
339
|
-
{
|
|
340
|
-
name: "expiry",
|
|
341
|
-
type: "date"
|
|
342
|
-
},
|
|
343
|
-
{
|
|
344
|
-
name: "email",
|
|
345
|
-
type: "text"
|
|
346
|
-
},
|
|
347
|
-
{
|
|
348
|
-
name: "name",
|
|
349
|
-
type: "text"
|
|
350
|
-
},
|
|
351
|
-
{
|
|
352
|
-
name: "username",
|
|
353
|
-
type: "text"
|
|
354
|
-
},
|
|
355
|
-
{
|
|
356
|
-
name: "rawUser",
|
|
357
|
-
type: "json"
|
|
358
|
-
}
|
|
359
|
-
]
|
|
360
|
-
});
|
|
361
|
-
const m = A(
|
|
362
|
-
"oauth_accounts",
|
|
363
|
-
"created",
|
|
364
|
-
l
|
|
365
|
-
);
|
|
366
|
-
m && n.push({
|
|
367
|
-
path: m,
|
|
368
|
-
language: "ts",
|
|
369
|
-
content: g.readFileSync(m, "utf8")
|
|
303
|
+
content: m.readFileSync(t, "utf8")
|
|
370
304
|
});
|
|
371
305
|
});
|
|
372
|
-
let
|
|
373
|
-
const
|
|
374
|
-
|
|
306
|
+
let a = [];
|
|
307
|
+
const l = y.join(
|
|
308
|
+
u.root,
|
|
375
309
|
"src",
|
|
376
310
|
"routes",
|
|
377
311
|
"+layout.server.ts"
|
|
378
312
|
);
|
|
379
|
-
await w(
|
|
380
|
-
path:
|
|
313
|
+
await w(l), a.push({
|
|
314
|
+
path: l,
|
|
381
315
|
language: "ts",
|
|
382
|
-
content:
|
|
316
|
+
content: m.readFileSync(l, "utf8")
|
|
383
317
|
});
|
|
384
318
|
let i = y.join(
|
|
385
|
-
|
|
319
|
+
u.root,
|
|
386
320
|
"src",
|
|
387
321
|
"routes",
|
|
388
322
|
"(public)",
|
|
389
323
|
"root-layout.svelte"
|
|
390
324
|
);
|
|
391
|
-
|
|
392
|
-
|
|
325
|
+
m.existsSync(i) || (i = y.join(u.root, "src", "routes", "root-layout.svelte")), m.existsSync(i) || (i = y.join(
|
|
326
|
+
u.root,
|
|
393
327
|
"src",
|
|
394
328
|
"routes",
|
|
395
329
|
"(public)",
|
|
396
330
|
"+layout.svelte"
|
|
397
|
-
)),
|
|
331
|
+
)), m.existsSync(i) || (i = y.join(u.root, "src", "routes", "+layout.svelte")), m.existsSync(i) && (P(i), a.push({
|
|
398
332
|
path: i,
|
|
399
333
|
language: "svelte",
|
|
400
|
-
content:
|
|
334
|
+
content: m.readFileSync(i, "utf8")
|
|
401
335
|
}));
|
|
402
|
-
const f = y.join(
|
|
403
|
-
return
|
|
336
|
+
const f = y.join(u.root, "src", "hooks.server.ts");
|
|
337
|
+
return m.existsSync(f) && (K(f), a.push({
|
|
404
338
|
path: f,
|
|
405
339
|
language: "ts",
|
|
406
|
-
content:
|
|
340
|
+
content: m.readFileSync(f, "utf8")
|
|
407
341
|
})), {
|
|
408
342
|
creates: [],
|
|
409
|
-
modifies:
|
|
343
|
+
modifies: a,
|
|
410
344
|
deletes: [],
|
|
411
345
|
components: [],
|
|
412
346
|
packages: [],
|
|
@@ -414,6 +348,6 @@ async function O(l) {
|
|
|
414
348
|
};
|
|
415
349
|
}
|
|
416
350
|
export {
|
|
417
|
-
|
|
351
|
+
R as generate
|
|
418
352
|
};
|
|
419
|
-
//# sourceMappingURL=generate.runtime-
|
|
353
|
+
//# sourceMappingURL=generate.runtime-B5XT4Q2Z.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate.runtime-BR_qnQ-6.js","sources":["../../src/patterns/enable/auth/modifies/+layout.server.ts","../../src/patterns/enable/auth/modifies/+layout.svelte.ts","../../src/patterns/enable/auth/modifies/hooks.server.ts","../../src/patterns/enable/auth/generate.runtime.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport dedent from \"dedent\";\nimport { Project, SyntaxKind } from \"ts-morph\";\n\nexport function modifyLayoutServer(layoutPath: string) {\n if (!fs.existsSync(layoutPath)) {\n // write file directly\n\n const snippet = dedent`\n\t\t\texport const load = async ({ locals }) => {\n\t\t\t\treturn { user: locals.pb.authStore.record };\n\t\t\t};\n\t\t`;\n\n fs.writeFileSync(layoutPath, snippet);\n return;\n }\n\n const project = new Project();\n const sourceFile = project.addSourceFileAtPath(layoutPath);\n\n // helper to add user property to an object literal if missing\n const addUserProp = (obj: import(\"ts-morph\").ObjectLiteralExpression) => {\n const hasUser = !!obj.getProperty(\"user\");\n if (!hasUser) {\n obj.addPropertyAssignment({\n name: \"user\",\n initializer: \"locals.pb.authStore.record\",\n });\n }\n };\n\n // find existing exported load (function or const with arrow)\n let loadArrow: import(\"ts-morph\").ArrowFunction | undefined;\n let loadFn:\n | import(\"ts-morph\").FunctionDeclaration\n | import(\"ts-morph\").FunctionExpression\n | undefined;\n\n const varDecl = sourceFile.getVariableDeclaration(\"load\");\n if (varDecl) {\n const vs = varDecl.getFirstAncestorByKind(SyntaxKind.VariableStatement);\n const isExported = !!vs?.hasExportKeyword();\n if (isExported) {\n const directArrow = varDecl.getInitializerIfKind(\n SyntaxKind.ArrowFunction,\n );\n if (directArrow) {\n loadArrow = directArrow;\n } else {\n const init = varDecl.getInitializer();\n if (init) {\n const innerArrow = init.getFirstDescendantByKind(\n SyntaxKind.ArrowFunction,\n );\n if (innerArrow) {\n loadArrow = innerArrow;\n } else {\n const innerFnExpr = init.getFirstDescendantByKind(\n SyntaxKind.FunctionExpression,\n );\n if (innerFnExpr) {\n loadFn = innerFnExpr;\n }\n }\n }\n }\n }\n }\n\n if (!loadArrow) {\n const maybeFn = sourceFile.getFunction(\"load\");\n if (maybeFn && maybeFn.isExported()) {\n loadFn = maybeFn;\n }\n }\n\n // if no load found, create one\n if (!loadArrow && !loadFn) {\n sourceFile.addFunction({\n isExported: true,\n isAsync: true,\n name: \"load\",\n parameters: [{ name: \"{ locals }\" }],\n statements: `return { user: locals.pb.authStore.record };`,\n });\n sourceFile.formatText();\n sourceFile.saveSync();\n return;\n }\n\n // normalize function-like to a single handle\n const fnLike:\n | import(\"ts-morph\").ArrowFunction\n | import(\"ts-morph\").FunctionDeclaration\n | import(\"ts-morph\").FunctionExpression = (loadArrow ?? loadFn!) as any;\n\n // ensure first parameter destructures locals, preserving existing information\n const params = fnLike.getParameters();\n if (params.length === 0) {\n fnLike.insertParameter(0, { name: \"{ locals }\" });\n } else {\n const first = params[0];\n const original = first.getStructure();\n const nameNode = first.getNameNode();\n if (nameNode.getKind() === SyntaxKind.ObjectBindingPattern) {\n const obp = nameNode as import(\"ts-morph\").ObjectBindingPattern;\n const hasLocals = obp\n .getElements()\n .some((el) => el.getName() === \"locals\");\n if (!hasLocals) {\n const parts = obp\n .getElements()\n .map((el) => el.getText())\n .filter(Boolean);\n const tail = parts.length > 0 ? \", \" + parts.join(\", \") : \"\";\n first.set({\n name: `{ locals${tail} }`,\n type: original.type,\n initializer: (original as any).initializer,\n });\n }\n } else {\n const currentName = first.getName();\n if (currentName !== \"locals\") {\n first.set({\n name: `{ locals, ...${currentName} }`,\n type: original.type,\n initializer: (original as any).initializer,\n });\n }\n }\n }\n\n // add user to returned object literals without altering other properties\n if (loadArrow) {\n const body = loadArrow.getBody();\n if (body.getKind() === SyntaxKind.Block) {\n const returns = body.getDescendantsOfKind(SyntaxKind.ReturnStatement);\n returns.forEach((ret) => {\n const expr = ret.getExpression();\n if (!expr) return;\n if (expr.getKind() === SyntaxKind.ObjectLiteralExpression) {\n addUserProp(expr as import(\"ts-morph\").ObjectLiteralExpression);\n } else if (expr.getKind() === SyntaxKind.ParenthesizedExpression) {\n const inner = (\n expr as import(\"ts-morph\").ParenthesizedExpression\n ).getExpression();\n if (inner.getKind() === SyntaxKind.ObjectLiteralExpression) {\n addUserProp(inner as import(\"ts-morph\").ObjectLiteralExpression);\n }\n }\n });\n } else {\n // concise body\n const bodyExpr = body as import(\"ts-morph\").Expression;\n if (bodyExpr.getKind() === SyntaxKind.ParenthesizedExpression) {\n const inner = (\n bodyExpr as import(\"ts-morph\").ParenthesizedExpression\n ).getExpression();\n if (inner.getKind() === SyntaxKind.ObjectLiteralExpression) {\n addUserProp(inner as import(\"ts-morph\").ObjectLiteralExpression);\n }\n } else if (bodyExpr.getKind() === SyntaxKind.ObjectLiteralExpression) {\n addUserProp(bodyExpr as import(\"ts-morph\").ObjectLiteralExpression);\n }\n }\n } else if (loadFn) {\n const body = loadFn.getBody();\n if (body) {\n const returns = body.getDescendantsOfKind(SyntaxKind.ReturnStatement);\n returns.forEach((ret) => {\n const expr = ret.getExpression();\n if (!expr) return;\n if (expr.getKind() === SyntaxKind.ObjectLiteralExpression) {\n addUserProp(expr as import(\"ts-morph\").ObjectLiteralExpression);\n } else if (expr.getKind() === SyntaxKind.ParenthesizedExpression) {\n const inner = (\n expr as import(\"ts-morph\").ParenthesizedExpression\n ).getExpression();\n if (inner.getKind() === SyntaxKind.ObjectLiteralExpression) {\n addUserProp(inner as import(\"ts-morph\").ObjectLiteralExpression);\n }\n }\n });\n }\n }\n\n sourceFile.formatText();\n sourceFile.saveSync();\n}\n","import fs from \"node:fs\";\nimport dedent from \"dedent\";\n\nexport function modifyLayoutSvelte(layoutPath: string) {\n let layout = fs.readFileSync(layoutPath, \"utf8\");\n // TODO: use magic-string to modify the layout\n\n // find the navbar.root > navbar.list\n const navbarRoot = layout.match(/<Navbar\\.Root>([\\s\\S]*?)<\\/Navbar\\.Root>/);\n if (!navbarRoot) {\n return;\n }\n\n const navbarList = navbarRoot[1].match(\n /<Navbar\\.List>([\\s\\S]*?)<\\/Navbar\\.List>/,\n );\n if (!navbarList) {\n return;\n }\n\n // add imports\n const imports = dedent`\n\t\timport * as AuthMenu from '$lib/components/ui/auth-menu';\n\t\timport * as Avatar from '$lib/components/ui/avatar';\n\t`;\n\n // Insert imports after the last existing import inside the first <script> block (if any)\n const scriptOpenIdx = layout.indexOf(\"<script\");\n if (scriptOpenIdx !== -1) {\n const scriptOpenEnd = layout.indexOf(\">\", scriptOpenIdx);\n const scriptCloseIdx =\n scriptOpenEnd !== -1\n ? layout.indexOf(\"</script>\", scriptOpenEnd + 1)\n : -1;\n if (scriptOpenEnd !== -1 && scriptCloseIdx !== -1) {\n const scriptContent = layout.slice(scriptOpenEnd + 1, scriptCloseIdx);\n let lastImportEnd = -1;\n const importRegex = /^\\s*import[\\s\\S]*?;[ \\t]*$/gm;\n let match: RegExpExecArray | null;\n while ((match = importRegex.exec(scriptContent)) !== null) {\n lastImportEnd = match.index + match[0].length;\n }\n\n if (lastImportEnd !== -1) {\n const before = scriptContent.slice(0, lastImportEnd);\n const after = scriptContent.slice(lastImportEnd);\n const newScriptContent = `${before}\\n${imports}\\n${after}`;\n layout =\n layout.slice(0, scriptOpenEnd + 1) +\n newScriptContent +\n layout.slice(scriptCloseIdx);\n } else {\n layout = layout.replace(\"</script>\", `${imports}\\n</script>`);\n }\n } else {\n layout = layout.replace(\"</script>\", `${imports}\\n</script>`);\n }\n } else {\n layout = layout.replace(\"</script>\", `${imports}\\n</script>`);\n }\n\n // add the auth menu to the navbar.list\n const newNavbarList =\n navbarList[1] +\n `\n\t\t\t<Navbar.Item\n\t\t\t\t\tclass=\"flex flex-col md:flex-row items-center space-y-2 md:space-y-0 md:space-x-4\"\n\t\t\t>\n\t\t\t\t\t<AuthMenu.Root>\n\t\t\t\t\t\t\t{#snippet user()}\n\t\t\t\t\t\t\t\t\t<AuthMenu.Trigger>\n\t\t\t\t\t\t\t\t\t\t\t<Avatar.Root>\n\t\t\t\t\t\t\t\t\t\t\t\t\t{#if data.user?.avatar}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<Avatar.Image\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tsrc=\"/api/files/users/{data.user?.id}/{data.user?.avatar}\"\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\talt={data.user?.email}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t\t\t\t\t{/if}\n\t\t\t\t\t\t\t\t\t\t\t\t\t<Avatar.Fallback>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t{data.user?.email?.charAt(0).toUpperCase()}\n\t\t\t\t\t\t\t\t\t\t\t\t\t</Avatar.Fallback>\n\t\t\t\t\t\t\t\t\t\t\t</Avatar.Root>\n\t\t\t\t\t\t\t\t\t</AuthMenu.Trigger>\n\n\t\t\t\t\t\t\t\t\t<AuthMenu.Content align=\"end\">\n\t\t\t\t\t\t\t\t\t\t\t<AuthMenu.Item href=\"/dashboard\">Dashboard</AuthMenu.Item>\n\t\t\t\t\t\t\t\t\t\t\t<AuthMenu.Group>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<AuthMenu.Item href=\"/settings\">Settings</AuthMenu.Item>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<AuthMenu.Item>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<form action=\"/logout\" method=\"post\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<button type=\"submit\" class=\"contents\">Logout</button>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t</form>\n\t\t\t\t\t\t\t\t\t\t\t\t\t</AuthMenu.Item>\n\t\t\t\t\t\t\t\t\t\t\t</AuthMenu.Group>\n\t\t\t\t\t\t\t\t\t</AuthMenu.Content>\n\t\t\t\t\t\t\t{/snippet}\n\n\t\t\t\t\t\t\t{#snippet guest()}\n\t\t\t\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t\t\t\t\tclass=\"w-full justify-start md:justify-center md:w-auto\"\n\t\t\t\t\t\t\t\t\t\t\tvariant=\"ghost\"\n\t\t\t\t\t\t\t\t\t\t\thref=\"/login\">Login</Button\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t\t\t\t\tclass=\"w-full justify-start md:justify-center md:w-auto\"\n\t\t\t\t\t\t\t\t\t\t\tvariant=\"outline\"\n\t\t\t\t\t\t\t\t\t\t\thref=\"/signup\">Sign up</Button\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{/snippet}\n\t\t\t\t\t</AuthMenu.Root>\n\t\t\t</Navbar.Item>\n\t\t`;\n\n // replace the navbar.list with the new one\n layout = layout.replace(navbarList[1], newNavbarList);\n\n fs.writeFileSync(layoutPath, layout);\n}\n","import { Project, SyntaxKind } from \"ts-morph\";\n\nexport function modifyHooksServer(hooksServerPath: string) {\n const project = new Project();\n const sourceFile = project.addSourceFileAtPath(hooksServerPath);\n\n // Find the handlePocketbase(...) call\n const callExpr = sourceFile\n .getDescendantsOfKind(SyntaxKind.CallExpression)\n .find((ce) => ce.getExpression().getText() === \"handlePocketbase\");\n\n if (!callExpr) {\n sourceFile.saveSync();\n return;\n }\n\n const args = callExpr.getArguments();\n if (args.length === 0) {\n // Create an options object if missing\n callExpr.addArgument(`{ auth: { protectedRoutes: ['/(app)'] } }`);\n sourceFile.formatText();\n sourceFile.saveSync();\n return;\n }\n\n const firstArg = args[0];\n if (firstArg.getKind() !== SyntaxKind.ObjectLiteralExpression) {\n // Replace non-object first arg with an object including auth\n callExpr.insertArgument(0, `{ auth: { protectedRoutes: ['/(app)'] } }`);\n sourceFile.formatText();\n sourceFile.saveSync();\n return;\n }\n\n const optionsObj = firstArg.asKindOrThrow(SyntaxKind.ObjectLiteralExpression);\n\n // Ensure auth property exists\n const authProp = optionsObj.getProperty(\"auth\");\n if (!authProp) {\n optionsObj.addPropertyAssignment({\n name: \"auth\",\n initializer: `{ protectedRoutes: ['/(app)'] }`,\n });\n sourceFile.formatText();\n sourceFile.saveSync();\n return;\n }\n\n // If auth exists, ensure protectedRoutes includes '/(app)'\n if (authProp.getKind() === SyntaxKind.PropertyAssignment) {\n const authInit = (\n authProp as import(\"ts-morph\").PropertyAssignment\n ).getInitializer();\n if (authInit && authInit.getKind() === SyntaxKind.ObjectLiteralExpression) {\n const authObj = authInit as import(\"ts-morph\").ObjectLiteralExpression;\n const prProp = authObj.getProperty(\"protectedRoutes\");\n if (!prProp) {\n authObj.addPropertyAssignment({\n name: \"protectedRoutes\",\n initializer: `['/(app)']`,\n });\n } else if (prProp.getKind() === SyntaxKind.PropertyAssignment) {\n const prInit = (\n prProp as import(\"ts-morph\").PropertyAssignment\n ).getInitializer();\n if (prInit && prInit.getKind() === SyntaxKind.ArrayLiteralExpression) {\n const arr = prInit as import(\"ts-morph\").ArrayLiteralExpression;\n const hasApp = arr\n .getElements()\n .some((el) => el.getText().replace(/['\"`]/g, \"\") === \"/(app)\");\n if (!hasApp) {\n arr.addElement(`'/(app)'`);\n }\n } else {\n // Replace non-array with desired value\n (prProp as import(\"ts-morph\").PropertyAssignment).setInitializer(\n `['/(app)']`,\n );\n }\n }\n }\n }\n\n sourceFile.formatText();\n sourceFile.saveSync();\n}\n","import path from \"node:path\";\nimport fs from \"node:fs\";\nimport { Options, Result, File } from \"../../../core/types\";\nimport { getMigrationFile, withPocketbase } from \"../../../runtime/pocketbase\";\n\nimport { modifyLayoutServer } from \"./modifies/+layout.server\";\nimport { modifyLayoutSvelte } from \"./modifies/+layout.svelte\";\nimport { modifyHooksServer } from \"./modifies/hooks.server\";\n\nexport async function generate(options: Options) {\n const { input } = options;\n\n let creates: File[] = [];\n\n // Update PocketBase\n await withPocketbase(options.root, async (pb) => {\n await pb.settings.update({\n meta: {\n senderName: input.senderName,\n senderAddress: input.senderAddress,\n },\n });\n\n const userCollection = await pb.collections.getOne(\"users\");\n\n if (!userCollection) {\n throw new Error(\"Users collection not found\");\n }\n\n const verificationTemplate =\n userCollection.verificationTemplate.body.replace(\n \"{APP_URL}/_/#/auth/confirm-verification/{TOKEN}\",\n \"{APP_URL}/confirm-verification/{TOKEN}\",\n );\n const resetPasswordTemplate =\n userCollection.resetPasswordTemplate.body.replace(\n \"{APP_URL}/_/#/auth/confirm-password-reset/{TOKEN}\",\n \"{APP_URL}/confirm-password-reset/{TOKEN}\",\n );\n const confirmEmailChangeTemplate =\n userCollection.confirmEmailChangeTemplate.body.replace(\n \"{APP_URL}/_/#/auth/confirm-email-change/{TOKEN}\",\n \"{APP_URL}/confirm-email-change/{TOKEN}\",\n );\n\n // Update user auth rules to lock down access to the user's own account\n await pb.collections.update(\"users\", {\n listRule: \"@request.auth.id = id\",\n viewRule: \"@request.auth.id = id\",\n createRule: \"@request.auth.id = id\",\n updateRule: \"@request.auth.id = id\",\n deleteRule: \"@request.auth.id = id\",\n\n // Update email templates to VelaStack auth urls\n verificationTemplate: {\n body: verificationTemplate,\n },\n resetPasswordTemplate: {\n body: resetPasswordTemplate,\n },\n confirmEmailChangeTemplate: {\n body: confirmEmailChangeTemplate,\n },\n });\n\n const migrationFile = getMigrationFile(\"users\", \"updated\", options);\n if (migrationFile) {\n creates.push({\n path: migrationFile,\n language: \"ts\",\n content: fs.readFileSync(migrationFile, \"utf8\"),\n });\n }\n\n await pb.collections.create({\n listRule: \"@request.auth.id = user.id\",\n viewRule: \"@request.auth.id = user.id\",\n name: \"oauth_accounts\",\n type: \"base\",\n fields: [\n {\n collectionId: userCollection.id,\n name: \"user\",\n type: \"relation\",\n required: true,\n maxSelect: 1,\n },\n {\n name: \"providerId\",\n required: true,\n type: \"text\",\n },\n {\n name: \"provider\",\n required: true,\n type: \"text\",\n },\n {\n name: \"accessToken\",\n type: \"text\",\n },\n {\n name: \"refreshToken\",\n type: \"text\",\n },\n {\n name: \"avatarURL\",\n type: \"text\",\n },\n {\n name: \"expiry\",\n type: \"date\",\n },\n {\n name: \"email\",\n type: \"text\",\n },\n {\n name: \"name\",\n type: \"text\",\n },\n {\n name: \"username\",\n type: \"text\",\n },\n {\n name: \"rawUser\",\n type: \"json\",\n },\n ],\n });\n\n const migrationFileCreated = getMigrationFile(\n \"oauth_accounts\",\n \"created\",\n options,\n );\n if (migrationFileCreated) {\n creates.push({\n path: migrationFileCreated,\n language: \"ts\",\n content: fs.readFileSync(migrationFileCreated, \"utf8\"),\n });\n }\n });\n\n // Modify files\n let modifies: File[] = [];\n\n const layoutServerFile = path.join(\n options.root,\n \"src\",\n \"routes\",\n \"+layout.server.ts\",\n );\n\n await modifyLayoutServer(layoutServerFile);\n modifies.push({\n path: layoutServerFile,\n language: \"ts\",\n content: fs.readFileSync(layoutServerFile, \"utf8\"),\n });\n\n // TODO: make this more robust by searching for Navbar.Root > Navbar.List\n // src/routes/(public)/root-layout.svelte is what vela creates by default\n let layoutFile = path.join(\n options.root,\n \"src\",\n \"routes\",\n \"(public)\",\n \"root-layout.svelte\",\n );\n\n if (!fs.existsSync(layoutFile)) {\n layoutFile = path.join(options.root, \"src\", \"routes\", \"root-layout.svelte\");\n }\n\n if (!fs.existsSync(layoutFile)) {\n layoutFile = path.join(\n options.root,\n \"src\",\n \"routes\",\n \"(public)\",\n \"+layout.svelte\",\n );\n }\n\n if (!fs.existsSync(layoutFile)) {\n layoutFile = path.join(options.root, \"src\", \"routes\", \"+layout.svelte\");\n }\n\n if (fs.existsSync(layoutFile)) {\n modifyLayoutSvelte(layoutFile);\n modifies.push({\n path: layoutFile,\n language: \"svelte\",\n content: fs.readFileSync(layoutFile, \"utf8\"),\n });\n }\n\n const hooksServerFile = path.join(options.root, \"src\", \"hooks.server.ts\");\n\n if (fs.existsSync(hooksServerFile)) {\n modifyHooksServer(hooksServerFile);\n modifies.push({\n path: hooksServerFile,\n language: \"ts\",\n content: fs.readFileSync(hooksServerFile, \"utf8\"),\n });\n }\n\n return {\n creates: [],\n modifies,\n deletes: [],\n components: [],\n packages: [],\n collections: [],\n } satisfies Result;\n}\n"],"names":["modifyLayoutServer","layoutPath","fs","snippet","dedent","sourceFile","Project","addUserProp","obj","loadArrow","loadFn","varDecl","vs","SyntaxKind","directArrow","init","innerArrow","innerFnExpr","maybeFn","fnLike","params","first","original","nameNode","obp","el","parts","tail","currentName","body","ret","expr","inner","bodyExpr","modifyLayoutSvelte","layout","navbarRoot","navbarList","imports","scriptOpenIdx","scriptOpenEnd","scriptCloseIdx","scriptContent","lastImportEnd","importRegex","match","before","after","newScriptContent","newNavbarList","modifyHooksServer","hooksServerPath","callExpr","ce","args","firstArg","optionsObj","authProp","authInit","authObj","prProp","prInit","arr","generate","options","input","creates","withPocketbase","pb","userCollection","verificationTemplate","resetPasswordTemplate","confirmEmailChangeTemplate","migrationFile","getMigrationFile","migrationFileCreated","modifies","layoutServerFile","path","layoutFile","hooksServerFile"],"mappings":";;;;;AAIO,SAASA,EAAmBC,GAAoB;AACrD,MAAI,CAACC,EAAG,WAAWD,CAAU,GAAG;AAG9B,UAAME,IAAUC;AAAA;AAAA;AAAA;AAAA;AAMhB,IAAAF,EAAG,cAAcD,GAAYE,CAAO;AACpC;AAAA,EACF;AAGA,QAAME,IADU,IAAIC,EAAA,EACO,oBAAoBL,CAAU,GAGnDM,IAAc,CAACC,MAAoD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3E,EAAG,aAAa2E,GAAkB,MAAM;AAAA,EAAA,CAClD;AAID,MAAIE,IAAaD,EAAK;AAAA,IACpBd,EAAQ;AAAA,IACR;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EAAA;AAGF,EAAK9D,EAAG,WAAW6E,CAAU,MAC3BA,IAAaD,EAAK,KAAKd,EAAQ,MAAM,OAAO,UAAU,oBAAoB,IAGvE9D,EAAG,WAAW6E,CAAU,MAC3BA,IAAaD,EAAK;AAAA,IAChBd,EAAQ;AAAA,IACR;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EAAA,IAIC9D,EAAG,WAAW6E,CAAU,MAC3BA,IAAaD,EAAK,KAAKd,EAAQ,MAAM,OAAO,UAAU,gBAAgB,IAGpE9D,EAAG,WAAW6E,CAAU,MAC1B7C,EAAmB6C,CAAU,GAC7BH,EAAS,KAAK;AAAA,IACZ,MAAMG;AAAA,IACN,UAAU;AAAA,IACV,SAAS7E,EAAG,aAAa6E,GAAY,MAAM;AAAA,EAAA,CAC5C;AAGH,QAAMC,IAAkBF,EAAK,KAAKd,EAAQ,MAAM,OAAO,iBAAiB;AAExE,SAAI9D,EAAG,WAAW8E,CAAe,MAC/B9B,EAAkB8B,CAAe,GACjCJ,EAAS,KAAK;AAAA,IACZ,MAAMI;AAAA,IACN,UAAU;AAAA,IACV,SAAS9E,EAAG,aAAa8E,GAAiB,MAAM;AAAA,EAAA,CACjD,IAGI;AAAA,IACL,SAAS,CAAA;AAAA,IACT,UAAAJ;AAAA,IACA,SAAS,CAAA;AAAA,IACT,YAAY,CAAA;AAAA,IACZ,UAAU,CAAA;AAAA,IACV,aAAa,CAAA;AAAA,EAAC;AAElB;"}
|
|
1
|
+
{"version":3,"file":"generate.runtime-B5XT4Q2Z.js","sources":["../../src/patterns/enable/auth/modifies/+layout.server.ts","../../src/patterns/enable/auth/modifies/+layout.svelte.ts","../../src/patterns/enable/auth/modifies/hooks.server.ts","../../src/patterns/enable/auth/generate.runtime.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport dedent from \"dedent\";\nimport { Project, SyntaxKind } from \"ts-morph\";\n\nexport function modifyLayoutServer(layoutPath: string) {\n if (!fs.existsSync(layoutPath)) {\n // write file directly\n\n const snippet = dedent`\n\t\t\texport const load = async ({ locals }) => {\n\t\t\t\treturn { user: locals.pb.authStore.record };\n\t\t\t};\n\t\t`;\n\n fs.writeFileSync(layoutPath, snippet);\n return;\n }\n\n const project = new Project();\n const sourceFile = project.addSourceFileAtPath(layoutPath);\n\n // helper to add user property to an object literal if missing\n const addUserProp = (obj: import(\"ts-morph\").ObjectLiteralExpression) => {\n const hasUser = !!obj.getProperty(\"user\");\n if (!hasUser) {\n obj.addPropertyAssignment({\n name: \"user\",\n initializer: \"locals.pb.authStore.record\",\n });\n }\n };\n\n // find existing exported load (function or const with arrow)\n let loadArrow: import(\"ts-morph\").ArrowFunction | undefined;\n let loadFn:\n | import(\"ts-morph\").FunctionDeclaration\n | import(\"ts-morph\").FunctionExpression\n | undefined;\n\n const varDecl = sourceFile.getVariableDeclaration(\"load\");\n if (varDecl) {\n const vs = varDecl.getFirstAncestorByKind(SyntaxKind.VariableStatement);\n const isExported = !!vs?.hasExportKeyword();\n if (isExported) {\n const directArrow = varDecl.getInitializerIfKind(\n SyntaxKind.ArrowFunction,\n );\n if (directArrow) {\n loadArrow = directArrow;\n } else {\n const init = varDecl.getInitializer();\n if (init) {\n const innerArrow = init.getFirstDescendantByKind(\n SyntaxKind.ArrowFunction,\n );\n if (innerArrow) {\n loadArrow = innerArrow;\n } else {\n const innerFnExpr = init.getFirstDescendantByKind(\n SyntaxKind.FunctionExpression,\n );\n if (innerFnExpr) {\n loadFn = innerFnExpr;\n }\n }\n }\n }\n }\n }\n\n if (!loadArrow) {\n const maybeFn = sourceFile.getFunction(\"load\");\n if (maybeFn && maybeFn.isExported()) {\n loadFn = maybeFn;\n }\n }\n\n // if no load found, create one\n if (!loadArrow && !loadFn) {\n sourceFile.addFunction({\n isExported: true,\n isAsync: true,\n name: \"load\",\n parameters: [{ name: \"{ locals }\" }],\n statements: `return { user: locals.pb.authStore.record };`,\n });\n sourceFile.formatText();\n sourceFile.saveSync();\n return;\n }\n\n // normalize function-like to a single handle\n const fnLike:\n | import(\"ts-morph\").ArrowFunction\n | import(\"ts-morph\").FunctionDeclaration\n | import(\"ts-morph\").FunctionExpression = (loadArrow ?? loadFn!) as any;\n\n // ensure first parameter destructures locals, preserving existing information\n const params = fnLike.getParameters();\n if (params.length === 0) {\n fnLike.insertParameter(0, { name: \"{ locals }\" });\n } else {\n const first = params[0];\n const original = first.getStructure();\n const nameNode = first.getNameNode();\n if (nameNode.getKind() === SyntaxKind.ObjectBindingPattern) {\n const obp = nameNode as import(\"ts-morph\").ObjectBindingPattern;\n const hasLocals = obp\n .getElements()\n .some((el) => el.getName() === \"locals\");\n if (!hasLocals) {\n const parts = obp\n .getElements()\n .map((el) => el.getText())\n .filter(Boolean);\n const tail = parts.length > 0 ? \", \" + parts.join(\", \") : \"\";\n first.set({\n name: `{ locals${tail} }`,\n type: original.type,\n initializer: (original as any).initializer,\n });\n }\n } else {\n const currentName = first.getName();\n if (currentName !== \"locals\") {\n first.set({\n name: `{ locals, ...${currentName} }`,\n type: original.type,\n initializer: (original as any).initializer,\n });\n }\n }\n }\n\n // add user to returned object literals without altering other properties\n if (loadArrow) {\n const body = loadArrow.getBody();\n if (body.getKind() === SyntaxKind.Block) {\n const returns = body.getDescendantsOfKind(SyntaxKind.ReturnStatement);\n returns.forEach((ret) => {\n const expr = ret.getExpression();\n if (!expr) return;\n if (expr.getKind() === SyntaxKind.ObjectLiteralExpression) {\n addUserProp(expr as import(\"ts-morph\").ObjectLiteralExpression);\n } else if (expr.getKind() === SyntaxKind.ParenthesizedExpression) {\n const inner = (\n expr as import(\"ts-morph\").ParenthesizedExpression\n ).getExpression();\n if (inner.getKind() === SyntaxKind.ObjectLiteralExpression) {\n addUserProp(inner as import(\"ts-morph\").ObjectLiteralExpression);\n }\n }\n });\n } else {\n // concise body\n const bodyExpr = body as import(\"ts-morph\").Expression;\n if (bodyExpr.getKind() === SyntaxKind.ParenthesizedExpression) {\n const inner = (\n bodyExpr as import(\"ts-morph\").ParenthesizedExpression\n ).getExpression();\n if (inner.getKind() === SyntaxKind.ObjectLiteralExpression) {\n addUserProp(inner as import(\"ts-morph\").ObjectLiteralExpression);\n }\n } else if (bodyExpr.getKind() === SyntaxKind.ObjectLiteralExpression) {\n addUserProp(bodyExpr as import(\"ts-morph\").ObjectLiteralExpression);\n }\n }\n } else if (loadFn) {\n const body = loadFn.getBody();\n if (body) {\n const returns = body.getDescendantsOfKind(SyntaxKind.ReturnStatement);\n returns.forEach((ret) => {\n const expr = ret.getExpression();\n if (!expr) return;\n if (expr.getKind() === SyntaxKind.ObjectLiteralExpression) {\n addUserProp(expr as import(\"ts-morph\").ObjectLiteralExpression);\n } else if (expr.getKind() === SyntaxKind.ParenthesizedExpression) {\n const inner = (\n expr as import(\"ts-morph\").ParenthesizedExpression\n ).getExpression();\n if (inner.getKind() === SyntaxKind.ObjectLiteralExpression) {\n addUserProp(inner as import(\"ts-morph\").ObjectLiteralExpression);\n }\n }\n });\n }\n }\n\n sourceFile.formatText();\n sourceFile.saveSync();\n}\n","import fs from \"node:fs\";\nimport dedent from \"dedent\";\n\nexport function modifyLayoutSvelte(layoutPath: string) {\n let layout = fs.readFileSync(layoutPath, \"utf8\");\n // TODO: use magic-string to modify the layout\n\n // find the navbar.root > navbar.list\n const navbarRoot = layout.match(/<Navbar\\.Root>([\\s\\S]*?)<\\/Navbar\\.Root>/);\n if (!navbarRoot) {\n return;\n }\n\n const navbarList = navbarRoot[1].match(\n /<Navbar\\.List>([\\s\\S]*?)<\\/Navbar\\.List>/,\n );\n if (!navbarList) {\n return;\n }\n\n // add imports\n const imports = dedent`\n\t\timport * as AuthMenu from '$lib/components/ui/auth-menu';\n\t\timport * as Avatar from '$lib/components/ui/avatar';\n\t`;\n\n // Insert imports after the last existing import inside the first <script> block (if any)\n const scriptOpenIdx = layout.indexOf(\"<script\");\n if (scriptOpenIdx !== -1) {\n const scriptOpenEnd = layout.indexOf(\">\", scriptOpenIdx);\n const scriptCloseIdx =\n scriptOpenEnd !== -1\n ? layout.indexOf(\"</script>\", scriptOpenEnd + 1)\n : -1;\n if (scriptOpenEnd !== -1 && scriptCloseIdx !== -1) {\n const scriptContent = layout.slice(scriptOpenEnd + 1, scriptCloseIdx);\n let lastImportEnd = -1;\n const importRegex = /^\\s*import[\\s\\S]*?;[ \\t]*$/gm;\n let match: RegExpExecArray | null;\n while ((match = importRegex.exec(scriptContent)) !== null) {\n lastImportEnd = match.index + match[0].length;\n }\n\n if (lastImportEnd !== -1) {\n const before = scriptContent.slice(0, lastImportEnd);\n const after = scriptContent.slice(lastImportEnd);\n const newScriptContent = `${before}\\n${imports}\\n${after}`;\n layout =\n layout.slice(0, scriptOpenEnd + 1) +\n newScriptContent +\n layout.slice(scriptCloseIdx);\n } else {\n layout = layout.replace(\"</script>\", `${imports}\\n</script>`);\n }\n } else {\n layout = layout.replace(\"</script>\", `${imports}\\n</script>`);\n }\n } else {\n layout = layout.replace(\"</script>\", `${imports}\\n</script>`);\n }\n\n // add the auth menu to the navbar.list\n const newNavbarList =\n navbarList[1] +\n `\n\t\t\t<Navbar.Item\n\t\t\t\t\tclass=\"flex flex-col md:flex-row items-center space-y-2 md:space-y-0 md:space-x-4\"\n\t\t\t>\n\t\t\t\t\t<AuthMenu.Root>\n\t\t\t\t\t\t\t{#snippet user()}\n\t\t\t\t\t\t\t\t\t<AuthMenu.Trigger>\n\t\t\t\t\t\t\t\t\t\t\t<Avatar.Root>\n\t\t\t\t\t\t\t\t\t\t\t\t\t{#if data.user?.avatar}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<Avatar.Image\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tsrc=\"/api/files/users/{data.user?.id}/{data.user?.avatar}\"\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\talt={data.user?.email}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t\t\t\t\t{/if}\n\t\t\t\t\t\t\t\t\t\t\t\t\t<Avatar.Fallback>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t{data.user?.email?.charAt(0).toUpperCase()}\n\t\t\t\t\t\t\t\t\t\t\t\t\t</Avatar.Fallback>\n\t\t\t\t\t\t\t\t\t\t\t</Avatar.Root>\n\t\t\t\t\t\t\t\t\t</AuthMenu.Trigger>\n\n\t\t\t\t\t\t\t\t\t<AuthMenu.Content align=\"end\">\n\t\t\t\t\t\t\t\t\t\t\t<AuthMenu.Item href=\"/dashboard\">Dashboard</AuthMenu.Item>\n\t\t\t\t\t\t\t\t\t\t\t<AuthMenu.Group>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<AuthMenu.Item href=\"/settings\">Settings</AuthMenu.Item>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<AuthMenu.Item>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<form action=\"/logout\" method=\"post\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<button type=\"submit\" class=\"contents\">Logout</button>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t</form>\n\t\t\t\t\t\t\t\t\t\t\t\t\t</AuthMenu.Item>\n\t\t\t\t\t\t\t\t\t\t\t</AuthMenu.Group>\n\t\t\t\t\t\t\t\t\t</AuthMenu.Content>\n\t\t\t\t\t\t\t{/snippet}\n\n\t\t\t\t\t\t\t{#snippet guest()}\n\t\t\t\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t\t\t\t\tclass=\"w-full justify-start md:justify-center md:w-auto\"\n\t\t\t\t\t\t\t\t\t\t\tvariant=\"ghost\"\n\t\t\t\t\t\t\t\t\t\t\thref=\"/login\">Login</Button\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t\t\t\t\tclass=\"w-full justify-start md:justify-center md:w-auto\"\n\t\t\t\t\t\t\t\t\t\t\tvariant=\"outline\"\n\t\t\t\t\t\t\t\t\t\t\thref=\"/signup\">Sign up</Button\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{/snippet}\n\t\t\t\t\t</AuthMenu.Root>\n\t\t\t</Navbar.Item>\n\t\t`;\n\n // replace the navbar.list with the new one\n layout = layout.replace(navbarList[1], newNavbarList);\n\n fs.writeFileSync(layoutPath, layout);\n}\n","import { Project, SyntaxKind } from \"ts-morph\";\n\nexport function modifyHooksServer(hooksServerPath: string) {\n const project = new Project();\n const sourceFile = project.addSourceFileAtPath(hooksServerPath);\n\n // Find the handlePocketbase(...) call\n const callExpr = sourceFile\n .getDescendantsOfKind(SyntaxKind.CallExpression)\n .find((ce) => ce.getExpression().getText() === \"handlePocketbase\");\n\n if (!callExpr) {\n sourceFile.saveSync();\n return;\n }\n\n const args = callExpr.getArguments();\n if (args.length === 0) {\n // Create an options object if missing\n callExpr.addArgument(`{ auth: { protectedRoutes: ['/(app)'] } }`);\n sourceFile.formatText();\n sourceFile.saveSync();\n return;\n }\n\n const firstArg = args[0];\n if (firstArg.getKind() !== SyntaxKind.ObjectLiteralExpression) {\n // Replace non-object first arg with an object including auth\n callExpr.insertArgument(0, `{ auth: { protectedRoutes: ['/(app)'] } }`);\n sourceFile.formatText();\n sourceFile.saveSync();\n return;\n }\n\n const optionsObj = firstArg.asKindOrThrow(SyntaxKind.ObjectLiteralExpression);\n\n // Ensure auth property exists\n const authProp = optionsObj.getProperty(\"auth\");\n if (!authProp) {\n optionsObj.addPropertyAssignment({\n name: \"auth\",\n initializer: `{ protectedRoutes: ['/(app)'] }`,\n });\n sourceFile.formatText();\n sourceFile.saveSync();\n return;\n }\n\n // If auth exists, ensure protectedRoutes includes '/(app)'\n if (authProp.getKind() === SyntaxKind.PropertyAssignment) {\n const authInit = (\n authProp as import(\"ts-morph\").PropertyAssignment\n ).getInitializer();\n if (authInit && authInit.getKind() === SyntaxKind.ObjectLiteralExpression) {\n const authObj = authInit as import(\"ts-morph\").ObjectLiteralExpression;\n const prProp = authObj.getProperty(\"protectedRoutes\");\n if (!prProp) {\n authObj.addPropertyAssignment({\n name: \"protectedRoutes\",\n initializer: `['/(app)']`,\n });\n } else if (prProp.getKind() === SyntaxKind.PropertyAssignment) {\n const prInit = (\n prProp as import(\"ts-morph\").PropertyAssignment\n ).getInitializer();\n if (prInit && prInit.getKind() === SyntaxKind.ArrayLiteralExpression) {\n const arr = prInit as import(\"ts-morph\").ArrayLiteralExpression;\n const hasApp = arr\n .getElements()\n .some((el) => el.getText().replace(/['\"`]/g, \"\") === \"/(app)\");\n if (!hasApp) {\n arr.addElement(`'/(app)'`);\n }\n } else {\n // Replace non-array with desired value\n (prProp as import(\"ts-morph\").PropertyAssignment).setInitializer(\n `['/(app)']`,\n );\n }\n }\n }\n }\n\n sourceFile.formatText();\n sourceFile.saveSync();\n}\n","import path from \"node:path\";\nimport fs from \"node:fs\";\nimport { Options, Result, File } from \"../../../core/types\";\nimport { getMigrationFile, withPocketbase } from \"../../../runtime/pocketbase\";\n\nimport { modifyLayoutServer } from \"./modifies/+layout.server\";\nimport { modifyLayoutSvelte } from \"./modifies/+layout.svelte\";\nimport { modifyHooksServer } from \"./modifies/hooks.server\";\n\nexport async function generate(options: Options) {\n const { input } = options;\n\n let creates: File[] = [];\n\n // Update PocketBase\n await withPocketbase(options.root, async (pb) => {\n await pb.settings.update({\n meta: {\n senderName: input.senderName,\n senderAddress: input.senderAddress,\n },\n });\n\n const userCollection = await pb.collections.getOne(\"users\");\n\n if (!userCollection) {\n throw new Error(\"Users collection not found\");\n }\n\n const verificationTemplate =\n userCollection.verificationTemplate.body.replace(\n \"{APP_URL}/_/#/auth/confirm-verification/{TOKEN}\",\n \"{APP_URL}/confirm-verification/{TOKEN}\",\n );\n const resetPasswordTemplate =\n userCollection.resetPasswordTemplate.body.replace(\n \"{APP_URL}/_/#/auth/confirm-password-reset/{TOKEN}\",\n \"{APP_URL}/confirm-password-reset/{TOKEN}\",\n );\n const confirmEmailChangeTemplate =\n userCollection.confirmEmailChangeTemplate.body.replace(\n \"{APP_URL}/_/#/auth/confirm-email-change/{TOKEN}\",\n \"{APP_URL}/confirm-email-change/{TOKEN}\",\n );\n\n // Update user auth rules to lock down access to the user's own account\n await pb.collections.update(\"users\", {\n listRule: \"@request.auth.id = id\",\n viewRule: \"@request.auth.id = id\",\n createRule: \"@request.auth.id = id\",\n updateRule: \"@request.auth.id = id\",\n deleteRule: \"@request.auth.id = id\",\n\n // Update email templates to VelaStack auth urls\n verificationTemplate: {\n body: verificationTemplate,\n },\n resetPasswordTemplate: {\n body: resetPasswordTemplate,\n },\n confirmEmailChangeTemplate: {\n body: confirmEmailChangeTemplate,\n },\n });\n\n const migrationFile = getMigrationFile(\"users\", \"updated\", options);\n if (migrationFile) {\n creates.push({\n path: migrationFile,\n language: \"ts\",\n content: fs.readFileSync(migrationFile, \"utf8\"),\n });\n }\n\n });\n\n // Modify files\n let modifies: File[] = [];\n\n const layoutServerFile = path.join(\n options.root,\n \"src\",\n \"routes\",\n \"+layout.server.ts\",\n );\n\n await modifyLayoutServer(layoutServerFile);\n modifies.push({\n path: layoutServerFile,\n language: \"ts\",\n content: fs.readFileSync(layoutServerFile, \"utf8\"),\n });\n\n // TODO: make this more robust by searching for Navbar.Root > Navbar.List\n // src/routes/(public)/root-layout.svelte is what vela creates by default\n let layoutFile = path.join(\n options.root,\n \"src\",\n \"routes\",\n \"(public)\",\n \"root-layout.svelte\",\n );\n\n if (!fs.existsSync(layoutFile)) {\n layoutFile = path.join(options.root, \"src\", \"routes\", \"root-layout.svelte\");\n }\n\n if (!fs.existsSync(layoutFile)) {\n layoutFile = path.join(\n options.root,\n \"src\",\n \"routes\",\n \"(public)\",\n \"+layout.svelte\",\n );\n }\n\n if (!fs.existsSync(layoutFile)) {\n layoutFile = path.join(options.root, \"src\", \"routes\", \"+layout.svelte\");\n }\n\n if (fs.existsSync(layoutFile)) {\n modifyLayoutSvelte(layoutFile);\n modifies.push({\n path: layoutFile,\n language: \"svelte\",\n content: fs.readFileSync(layoutFile, \"utf8\"),\n });\n }\n\n const hooksServerFile = path.join(options.root, \"src\", \"hooks.server.ts\");\n\n if (fs.existsSync(hooksServerFile)) {\n modifyHooksServer(hooksServerFile);\n modifies.push({\n path: hooksServerFile,\n language: \"ts\",\n content: fs.readFileSync(hooksServerFile, \"utf8\"),\n });\n }\n\n return {\n creates: [],\n modifies,\n deletes: [],\n components: [],\n packages: [],\n collections: [],\n } satisfies Result;\n}\n"],"names":["modifyLayoutServer","layoutPath","fs","snippet","dedent","sourceFile","Project","addUserProp","obj","loadArrow","loadFn","varDecl","vs","SyntaxKind","directArrow","init","innerArrow","innerFnExpr","maybeFn","fnLike","params","first","original","nameNode","obp","el","parts","tail","currentName","body","ret","expr","inner","bodyExpr","modifyLayoutSvelte","layout","navbarRoot","navbarList","imports","scriptOpenIdx","scriptOpenEnd","scriptCloseIdx","scriptContent","lastImportEnd","importRegex","match","before","after","newScriptContent","newNavbarList","modifyHooksServer","hooksServerPath","callExpr","ce","args","firstArg","optionsObj","authProp","authInit","authObj","prProp","prInit","arr","generate","options","input","creates","withPocketbase","pb","userCollection","verificationTemplate","resetPasswordTemplate","confirmEmailChangeTemplate","migrationFile","getMigrationFile","modifies","layoutServerFile","path","layoutFile","hooksServerFile"],"mappings":";;;;;AAIO,SAASA,EAAmBC,GAAoB;AACrD,MAAI,CAACC,EAAG,WAAWD,CAAU,GAAG;AAG9B,UAAME,IAAUC;AAAA;AAAA;AAAA;AAAA;AAMhB,IAAAF,EAAG,cAAcD,GAAYE,CAAO;AACpC;AAAA,EACF;AAGA,QAAME,IADU,IAAIC,EAAA,EACO,oBAAoBL,CAAU,GAGnDM,IAAc,CAACC,MAAoD;AAEvE,IADgB,CAAC,CAACA,EAAI,YAAY,MAAM,KAEtCA,EAAI,sBAAsB;AAAA,MACxB,MAAM;AAAA,MACN,aAAa;AAAA,IAAA,CACd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