@velastack/patterns 0.0.19 → 0.0.20
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 +12 -0
- package/dist/chunks/collections-C7dgGs-E.js +67 -0
- package/dist/chunks/collections-C7dgGs-E.js.map +1 -0
- package/dist/chunks/{env.runtime-C3E02sUH.js → env.runtime-DwDRkEXV.js} +2 -2
- package/dist/chunks/{env.runtime-C3E02sUH.js.map → env.runtime-DwDRkEXV.js.map} +1 -1
- package/dist/chunks/generate.runtime-C7g-zL0o.js.map +1 -1
- package/dist/chunks/generate.runtime-D21wXYWT.js +172 -0
- package/dist/chunks/generate.runtime-D21wXYWT.js.map +1 -0
- package/dist/chunks/generate.runtime-DcDyK2xK.js +334 -0
- package/dist/chunks/generate.runtime-DcDyK2xK.js.map +1 -0
- package/dist/chunks/{generate.runtime-DgtB6hP4.js → generate.runtime-cNqC7P0N.js} +33 -10
- package/dist/chunks/generate.runtime-cNqC7P0N.js.map +1 -0
- package/dist/chunks/generate.runtime-toUqgDQY.js +610 -0
- package/dist/chunks/generate.runtime-toUqgDQY.js.map +1 -0
- package/dist/chunks/{index-E6LAzq1d.js → index-GTS4D08Z.js} +2533 -2246
- package/dist/chunks/index-GTS4D08Z.js.map +1 -0
- package/dist/chunks/{pocketbase-BCvqw1Cr.js → pocketbase-QZ34CciJ.js} +50 -45
- package/dist/chunks/pocketbase-QZ34CciJ.js.map +1 -0
- package/dist/chunks/ts-morph-helpers-BNCluWTs.js +166 -0
- package/dist/chunks/ts-morph-helpers-BNCluWTs.js.map +1 -0
- package/dist/chunks/{write-result-CbUTMeAc.js → write-result-DmD7kWlV.js} +81 -70
- package/dist/chunks/write-result-DmD7kWlV.js.map +1 -0
- package/dist/index.d.ts +67 -0
- package/dist/index.js +1 -1
- package/package.json +16 -1
- package/dist/chunks/collections-CAafgIoZ.js +0 -62
- package/dist/chunks/collections-CAafgIoZ.js.map +0 -1
- package/dist/chunks/generate.runtime-C7YhHvlr.js +0 -353
- package/dist/chunks/generate.runtime-C7YhHvlr.js.map +0 -1
- package/dist/chunks/generate.runtime-DBTOrhnc.js +0 -633
- package/dist/chunks/generate.runtime-DBTOrhnc.js.map +0 -1
- package/dist/chunks/generate.runtime-DgtB6hP4.js.map +0 -1
- package/dist/chunks/generate.runtime-DoQkjIdl.js +0 -227
- package/dist/chunks/generate.runtime-DoQkjIdl.js.map +0 -1
- package/dist/chunks/index-E6LAzq1d.js.map +0 -1
- package/dist/chunks/pocketbase-BCvqw1Cr.js.map +0 -1
- package/dist/chunks/write-result-CbUTMeAc.js.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -9,6 +9,9 @@ export declare const byCategory: Record<"auth" | "generators" | "api" | "i18n",
|
|
|
9
9
|
requires: {
|
|
10
10
|
auth: false;
|
|
11
11
|
api: false;
|
|
12
|
+
apiKeys: false;
|
|
13
|
+
i18n: false;
|
|
14
|
+
teams: false;
|
|
12
15
|
payments: false;
|
|
13
16
|
};
|
|
14
17
|
category: "generators";
|
|
@@ -31,6 +34,9 @@ export declare const byCategory: Record<"auth" | "generators" | "api" | "i18n",
|
|
|
31
34
|
requires: {
|
|
32
35
|
auth: false;
|
|
33
36
|
api: false;
|
|
37
|
+
apiKeys: false;
|
|
38
|
+
i18n: false;
|
|
39
|
+
teams: false;
|
|
34
40
|
payments: false;
|
|
35
41
|
};
|
|
36
42
|
category: "generators";
|
|
@@ -53,6 +59,9 @@ export declare const byCategory: Record<"auth" | "generators" | "api" | "i18n",
|
|
|
53
59
|
requires: {
|
|
54
60
|
auth: false;
|
|
55
61
|
api: false;
|
|
62
|
+
apiKeys: false;
|
|
63
|
+
i18n: false;
|
|
64
|
+
teams: false;
|
|
56
65
|
payments: false;
|
|
57
66
|
};
|
|
58
67
|
category: "generators";
|
|
@@ -75,6 +84,9 @@ export declare const byCategory: Record<"auth" | "generators" | "api" | "i18n",
|
|
|
75
84
|
requires: {
|
|
76
85
|
auth: false;
|
|
77
86
|
api: false;
|
|
87
|
+
apiKeys: false;
|
|
88
|
+
i18n: false;
|
|
89
|
+
teams: false;
|
|
78
90
|
payments: false;
|
|
79
91
|
};
|
|
80
92
|
category: "generators";
|
|
@@ -97,6 +109,9 @@ export declare const byCategory: Record<"auth" | "generators" | "api" | "i18n",
|
|
|
97
109
|
requires: {
|
|
98
110
|
auth: false;
|
|
99
111
|
api: false;
|
|
112
|
+
apiKeys: false;
|
|
113
|
+
i18n: false;
|
|
114
|
+
teams: false;
|
|
100
115
|
payments: false;
|
|
101
116
|
};
|
|
102
117
|
category: "auth";
|
|
@@ -119,6 +134,9 @@ export declare const byCategory: Record<"auth" | "generators" | "api" | "i18n",
|
|
|
119
134
|
requires: {
|
|
120
135
|
auth: false;
|
|
121
136
|
api: false;
|
|
137
|
+
apiKeys: false;
|
|
138
|
+
i18n: false;
|
|
139
|
+
teams: false;
|
|
122
140
|
payments: false;
|
|
123
141
|
};
|
|
124
142
|
category: "api";
|
|
@@ -141,6 +159,9 @@ export declare const byCategory: Record<"auth" | "generators" | "api" | "i18n",
|
|
|
141
159
|
requires: {
|
|
142
160
|
auth: true;
|
|
143
161
|
api: true;
|
|
162
|
+
apiKeys: false;
|
|
163
|
+
i18n: false;
|
|
164
|
+
teams: false;
|
|
144
165
|
payments: false;
|
|
145
166
|
};
|
|
146
167
|
category: "api";
|
|
@@ -163,6 +184,9 @@ export declare const byCategory: Record<"auth" | "generators" | "api" | "i18n",
|
|
|
163
184
|
requires: {
|
|
164
185
|
auth: false;
|
|
165
186
|
api: false;
|
|
187
|
+
apiKeys: false;
|
|
188
|
+
i18n: false;
|
|
189
|
+
teams: false;
|
|
166
190
|
payments: false;
|
|
167
191
|
};
|
|
168
192
|
category: "i18n";
|
|
@@ -185,6 +209,9 @@ export declare const byCategory: Record<"auth" | "generators" | "api" | "i18n",
|
|
|
185
209
|
requires: {
|
|
186
210
|
auth: true;
|
|
187
211
|
api: false;
|
|
212
|
+
apiKeys: false;
|
|
213
|
+
i18n: false;
|
|
214
|
+
teams: false;
|
|
188
215
|
payments: false;
|
|
189
216
|
};
|
|
190
217
|
category: "auth";
|
|
@@ -242,6 +269,9 @@ declare type Component = string;
|
|
|
242
269
|
declare interface Features {
|
|
243
270
|
auth: boolean;
|
|
244
271
|
api: boolean;
|
|
272
|
+
apiKeys: boolean;
|
|
273
|
+
i18n: boolean;
|
|
274
|
+
teams: boolean;
|
|
245
275
|
payments: boolean;
|
|
246
276
|
}
|
|
247
277
|
|
|
@@ -292,6 +322,9 @@ export declare const patterns: ({
|
|
|
292
322
|
requires: {
|
|
293
323
|
auth: false;
|
|
294
324
|
api: false;
|
|
325
|
+
apiKeys: false;
|
|
326
|
+
i18n: false;
|
|
327
|
+
teams: false;
|
|
295
328
|
payments: false;
|
|
296
329
|
};
|
|
297
330
|
category: "generators";
|
|
@@ -314,6 +347,9 @@ export declare const patterns: ({
|
|
|
314
347
|
requires: {
|
|
315
348
|
auth: false;
|
|
316
349
|
api: false;
|
|
350
|
+
apiKeys: false;
|
|
351
|
+
i18n: false;
|
|
352
|
+
teams: false;
|
|
317
353
|
payments: false;
|
|
318
354
|
};
|
|
319
355
|
category: "generators";
|
|
@@ -336,6 +372,9 @@ export declare const patterns: ({
|
|
|
336
372
|
requires: {
|
|
337
373
|
auth: false;
|
|
338
374
|
api: false;
|
|
375
|
+
apiKeys: false;
|
|
376
|
+
i18n: false;
|
|
377
|
+
teams: false;
|
|
339
378
|
payments: false;
|
|
340
379
|
};
|
|
341
380
|
category: "generators";
|
|
@@ -358,6 +397,9 @@ export declare const patterns: ({
|
|
|
358
397
|
requires: {
|
|
359
398
|
auth: false;
|
|
360
399
|
api: false;
|
|
400
|
+
apiKeys: false;
|
|
401
|
+
i18n: false;
|
|
402
|
+
teams: false;
|
|
361
403
|
payments: false;
|
|
362
404
|
};
|
|
363
405
|
category: "generators";
|
|
@@ -380,6 +422,9 @@ export declare const patterns: ({
|
|
|
380
422
|
requires: {
|
|
381
423
|
auth: false;
|
|
382
424
|
api: false;
|
|
425
|
+
apiKeys: false;
|
|
426
|
+
i18n: false;
|
|
427
|
+
teams: false;
|
|
383
428
|
payments: false;
|
|
384
429
|
};
|
|
385
430
|
category: "auth";
|
|
@@ -402,6 +447,9 @@ export declare const patterns: ({
|
|
|
402
447
|
requires: {
|
|
403
448
|
auth: false;
|
|
404
449
|
api: false;
|
|
450
|
+
apiKeys: false;
|
|
451
|
+
i18n: false;
|
|
452
|
+
teams: false;
|
|
405
453
|
payments: false;
|
|
406
454
|
};
|
|
407
455
|
category: "api";
|
|
@@ -424,6 +472,9 @@ export declare const patterns: ({
|
|
|
424
472
|
requires: {
|
|
425
473
|
auth: true;
|
|
426
474
|
api: true;
|
|
475
|
+
apiKeys: false;
|
|
476
|
+
i18n: false;
|
|
477
|
+
teams: false;
|
|
427
478
|
payments: false;
|
|
428
479
|
};
|
|
429
480
|
category: "api";
|
|
@@ -446,6 +497,9 @@ export declare const patterns: ({
|
|
|
446
497
|
requires: {
|
|
447
498
|
auth: false;
|
|
448
499
|
api: false;
|
|
500
|
+
apiKeys: false;
|
|
501
|
+
i18n: false;
|
|
502
|
+
teams: false;
|
|
449
503
|
payments: false;
|
|
450
504
|
};
|
|
451
505
|
category: "i18n";
|
|
@@ -468,6 +522,9 @@ export declare const patterns: ({
|
|
|
468
522
|
requires: {
|
|
469
523
|
auth: true;
|
|
470
524
|
api: false;
|
|
525
|
+
apiKeys: false;
|
|
526
|
+
i18n: false;
|
|
527
|
+
teams: false;
|
|
471
528
|
payments: false;
|
|
472
529
|
};
|
|
473
530
|
category: "auth";
|
|
@@ -495,3 +552,13 @@ export declare type Slug = PatternEntry["slug"];
|
|
|
495
552
|
export declare const version: string;
|
|
496
553
|
|
|
497
554
|
export { }
|
|
555
|
+
|
|
556
|
+
|
|
557
|
+
declare module "vitest" {
|
|
558
|
+
interface Matchers<T = any> extends CustomMatchers<T> {
|
|
559
|
+
}
|
|
560
|
+
interface Assertion<T = any> extends CustomMatchers<T> {
|
|
561
|
+
}
|
|
562
|
+
interface AsymmetricMatchersContaining extends CustomMatchers {
|
|
563
|
+
}
|
|
564
|
+
}
|
package/dist/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@velastack/patterns",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.20",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"private": false,
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -12,6 +12,10 @@
|
|
|
12
12
|
"build": "vite build",
|
|
13
13
|
"dev": "vite build --watch",
|
|
14
14
|
"clean": "rm -rf dist",
|
|
15
|
+
"demo": "vite-node scripts/demo.ts --",
|
|
16
|
+
"lint": "npm run lint:ts && npm run lint:format",
|
|
17
|
+
"lint:ts": "tsc --noEmit",
|
|
18
|
+
"lint:format": "prettier --check .",
|
|
15
19
|
"test": "vitest run --exclude **/integration.test.ts",
|
|
16
20
|
"test:watch": "vitest --watch --exclude **/integration.test.ts",
|
|
17
21
|
"test:integration": "vitest run **/integration.test.ts"
|
|
@@ -23,8 +27,10 @@
|
|
|
23
27
|
"peerDependencies": {
|
|
24
28
|
"@velastack/pocketbase": "^0.0.44",
|
|
25
29
|
"cross-spawn": "^7.0.6",
|
|
30
|
+
"magic-string": "^0.30.0",
|
|
26
31
|
"package-manager-detector": "^1.6.0",
|
|
27
32
|
"pocketbase": "^0.26.8",
|
|
33
|
+
"svelte": "^5.0.0",
|
|
28
34
|
"ts-morph": "^28.0.0"
|
|
29
35
|
},
|
|
30
36
|
"peerDependenciesMeta": {
|
|
@@ -34,12 +40,18 @@
|
|
|
34
40
|
"cross-spawn": {
|
|
35
41
|
"optional": true
|
|
36
42
|
},
|
|
43
|
+
"magic-string": {
|
|
44
|
+
"optional": true
|
|
45
|
+
},
|
|
37
46
|
"package-manager-detector": {
|
|
38
47
|
"optional": true
|
|
39
48
|
},
|
|
40
49
|
"pocketbase": {
|
|
41
50
|
"optional": true
|
|
42
51
|
},
|
|
52
|
+
"svelte": {
|
|
53
|
+
"optional": true
|
|
54
|
+
},
|
|
43
55
|
"ts-morph": {
|
|
44
56
|
"optional": true
|
|
45
57
|
}
|
|
@@ -52,12 +64,15 @@
|
|
|
52
64
|
"change-case": "^5.4.4",
|
|
53
65
|
"cross-spawn": "^7.0.6",
|
|
54
66
|
"dedent": "^1.7.2",
|
|
67
|
+
"magic-string": "^0.30.21",
|
|
55
68
|
"package-manager-detector": "^1.6.0",
|
|
56
69
|
"pluralize": "^8.0.0",
|
|
57
70
|
"pocketbase": "^0.26.8",
|
|
71
|
+
"svelte": "^5.55.4",
|
|
58
72
|
"ts-morph": "^28.0.0",
|
|
59
73
|
"typescript": "^5.0.0",
|
|
60
74
|
"vite": "^6.0.0",
|
|
75
|
+
"vite-node": "^6.0.0",
|
|
61
76
|
"vite-plugin-dts": "^4.4.0",
|
|
62
77
|
"vitest": "^4.1.4"
|
|
63
78
|
}
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import { readFileSync as s } from "node:fs";
|
|
2
|
-
import { l as u } from "./index-E6LAzq1d.js";
|
|
3
|
-
import { w as d, g as c } from "./pocketbase-BCvqw1Cr.js";
|
|
4
|
-
function f(e) {
|
|
5
|
-
var n, l, o, i;
|
|
6
|
-
if (((o = (l = (n = e.response) == null ? void 0 : n.data) == null ? void 0 : l.name) == null ? void 0 : o.code) === "validation_not_unique")
|
|
7
|
-
return !0;
|
|
8
|
-
const t = ((i = e.message) == null ? void 0 : i.toLowerCase()) ?? "";
|
|
9
|
-
return t.includes("already exists") || t.includes("must be unique");
|
|
10
|
-
}
|
|
11
|
-
function m(e) {
|
|
12
|
-
const t = {};
|
|
13
|
-
return e.listRule !== void 0 && (t.listRule = e.listRule), e.viewRule !== void 0 && (t.viewRule = e.viewRule), e.createRule !== void 0 && (t.createRule = e.createRule), e.updateRule !== void 0 && (t.updateRule = e.updateRule), e.deleteRule !== void 0 && (t.deleteRule = e.deleteRule), t;
|
|
14
|
-
}
|
|
15
|
-
async function y(e, t, n) {
|
|
16
|
-
const l = [];
|
|
17
|
-
for (const o of t) {
|
|
18
|
-
const i = o.collectionName.replace(/'/g, "''"), a = await e.collections.getFirstListItem(`name='${i}'`);
|
|
19
|
-
if (await e.collections.update(a.id, m(o)), n) {
|
|
20
|
-
const r = c(
|
|
21
|
-
o.collectionName,
|
|
22
|
-
"updated",
|
|
23
|
-
n
|
|
24
|
-
);
|
|
25
|
-
r && l.push({
|
|
26
|
-
path: r,
|
|
27
|
-
language: u(r),
|
|
28
|
-
content: s(r, "utf8")
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
return l;
|
|
33
|
-
}
|
|
34
|
-
async function v(e, t) {
|
|
35
|
-
if (e.length === 0)
|
|
36
|
-
return [];
|
|
37
|
-
const n = [];
|
|
38
|
-
return await d(t.root, async (l) => {
|
|
39
|
-
for (const o of e) {
|
|
40
|
-
try {
|
|
41
|
-
await l.collections.create(o);
|
|
42
|
-
} catch (a) {
|
|
43
|
-
throw f(
|
|
44
|
-
a
|
|
45
|
-
) ? new Error(
|
|
46
|
-
`Collection "${o.name}" already exists. Choose a different model name or remove the existing collection first.`
|
|
47
|
-
) : a;
|
|
48
|
-
}
|
|
49
|
-
const i = c(o.name, "created", t);
|
|
50
|
-
i && n.push({
|
|
51
|
-
path: i,
|
|
52
|
-
language: u(i),
|
|
53
|
-
content: s(i, "utf8")
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
}), n;
|
|
57
|
-
}
|
|
58
|
-
export {
|
|
59
|
-
y as applyCollectionRulePatches,
|
|
60
|
-
v as createCollections
|
|
61
|
-
};
|
|
62
|
-
//# sourceMappingURL=collections-CAafgIoZ.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"collections-CAafgIoZ.js","sources":["../../src/runtime/collections.ts"],"sourcesContent":["import { readFileSync } from \"node:fs\";\nimport type {\n CollectionRulesPatch,\n CollectionSpec,\n File,\n Options,\n} 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\nfunction rulePayloadFromPatch(patch: CollectionRulesPatch): Record<string, unknown> {\n const payload: Record<string, unknown> = {};\n if (patch.listRule !== undefined) payload.listRule = patch.listRule;\n if (patch.viewRule !== undefined) payload.viewRule = patch.viewRule;\n if (patch.createRule !== undefined) payload.createRule = patch.createRule;\n if (patch.updateRule !== undefined) payload.updateRule = patch.updateRule;\n if (patch.deleteRule !== undefined) payload.deleteRule = patch.deleteRule;\n return payload;\n}\n\n/**\n * Applies API rule updates in array order. Call after all referenced collections exist.\n * Collects migration files produced by each update when `options` is provided.\n */\nexport async function applyCollectionRulePatches(\n pb: {\n collections: {\n getFirstListItem: (filter: string) => Promise<{ id: string }>;\n update: (id: string, body: Record<string, unknown>) => Promise<unknown>;\n };\n },\n patches: CollectionRulesPatch[],\n options?: Options,\n): Promise<File[]> {\n const migrations: File[] = [];\n\n for (const patch of patches) {\n const escaped = patch.collectionName.replace(/'/g, \"''\");\n const col = await pb.collections.getFirstListItem(`name='${escaped}'`);\n await pb.collections.update(col.id, rulePayloadFromPatch(patch));\n\n if (options) {\n const migrationFile = getMigrationFile(\n patch.collectionName,\n \"updated\",\n options,\n );\n if (migrationFile) {\n migrations.push({\n path: migrationFile,\n language: languageFromPath(migrationFile),\n content: readFileSync(migrationFile, \"utf8\"),\n });\n }\n }\n }\n\n return migrations;\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","rulePayloadFromPatch","patch","payload","applyCollectionRulePatches","pb","patches","options","migrations","escaped","col","migrationFile","getMigrationFile","languageFromPath","readFileSync","createCollections","collections","withPocketbase","collection"],"mappings":";;;AAqBA,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,SAASE,EAAqBC,GAAsD;AAClF,QAAMC,IAAmC,CAAA;AACzC,SAAID,EAAM,aAAa,WAAWC,EAAQ,WAAWD,EAAM,WACvDA,EAAM,aAAa,WAAWC,EAAQ,WAAWD,EAAM,WACvDA,EAAM,eAAe,WAAWC,EAAQ,aAAaD,EAAM,aAC3DA,EAAM,eAAe,WAAWC,EAAQ,aAAaD,EAAM,aAC3DA,EAAM,eAAe,WAAWC,EAAQ,aAAaD,EAAM,aACxDC;AACT;AAMA,eAAsBC,EACpBC,GAMAC,GACAC,GACiB;AACjB,QAAMC,IAAqB,CAAA;AAE3B,aAAWN,KAASI,GAAS;AAC3B,UAAMG,IAAUP,EAAM,eAAe,QAAQ,MAAM,IAAI,GACjDQ,IAAM,MAAML,EAAG,YAAY,iBAAiB,SAASI,CAAO,GAAG;AAGrE,QAFA,MAAMJ,EAAG,YAAY,OAAOK,EAAI,IAAIT,EAAqBC,CAAK,CAAC,GAE3DK,GAAS;AACX,YAAMI,IAAgBC;AAAA,QACpBV,EAAM;AAAA,QACN;AAAA,QACAK;AAAA,MAAA;AAEF,MAAII,KACFH,EAAW,KAAK;AAAA,QACd,MAAMG;AAAA,QACN,UAAUE,EAAiBF,CAAa;AAAA,QACxC,SAASG,EAAaH,GAAe,MAAM;AAAA,MAAA,CAC5C;AAAA,IAEL;AAAA,EACF;AAEA,SAAOH;AACT;AAEA,eAAsBO,EACpBC,GACAT,GACiB;AACjB,MAAIS,EAAY,WAAW;AACzB,WAAO,CAAA;AAGT,QAAMR,IAAqB,CAAA;AAE3B,eAAMS,EAAeV,EAAQ,MAAM,OAAOF,MAAO;AAC/C,eAAWa,KAAcF,GAAa;AACpC,UAAI;AACF,cAAMX,EAAG,YAAY,OAAOa,CAAU;AAAA,MACxC,SAASvB,GAAO;AACd,cACED;AAAA,UACEC;AAAA,QAAA,IAGI,IAAI;AAAA,UACR,eAAeuB,EAAW,IAAI;AAAA,QAAA,IAG5BvB;AAAA,MACR;AAEA,YAAMgB,IAAgBC,EAAiBM,EAAW,MAAM,WAAWX,CAAO;AAC1E,MAAKI,KAILH,EAAW,KAAK;AAAA,QACd,MAAMG;AAAA,QACN,UAAUE,EAAiBF,CAAa;AAAA,QACxC,SAASG,EAAaH,GAAe,MAAM;AAAA,MAAA,CAC5C;AAAA,IACH;AAAA,EACF,CAAC,GAEMH;AACT;"}
|
|
@@ -1,353 +0,0 @@
|
|
|
1
|
-
import y from "node:path";
|
|
2
|
-
import m from "node:fs";
|
|
3
|
-
import { w as v, g as S } from "./pocketbase-BCvqw1Cr.js";
|
|
4
|
-
import { d as A } from "./index-E6LAzq1d.js";
|
|
5
|
-
import { Project as b, SyntaxKind as s } from "ts-morph";
|
|
6
|
-
function w(u) {
|
|
7
|
-
if (!m.existsSync(u)) {
|
|
8
|
-
const e = A`
|
|
9
|
-
export const load = async ({ locals }) => {
|
|
10
|
-
return { user: locals.pb.authStore.record };
|
|
11
|
-
};
|
|
12
|
-
`;
|
|
13
|
-
m.writeFileSync(u, e);
|
|
14
|
-
return;
|
|
15
|
-
}
|
|
16
|
-
const n = new b().addSourceFileAtPath(u), a = (e) => {
|
|
17
|
-
!!e.getProperty("user") || e.addPropertyAssignment({
|
|
18
|
-
name: "user",
|
|
19
|
-
initializer: "locals.pb.authStore.record"
|
|
20
|
-
});
|
|
21
|
-
};
|
|
22
|
-
let l, i;
|
|
23
|
-
const f = n.getVariableDeclaration("load");
|
|
24
|
-
if (f) {
|
|
25
|
-
const e = f.getFirstAncestorByKind(s.VariableStatement);
|
|
26
|
-
if (!!(e != null && e.hasExportKeyword())) {
|
|
27
|
-
const c = f.getInitializerIfKind(
|
|
28
|
-
s.ArrowFunction
|
|
29
|
-
);
|
|
30
|
-
if (c)
|
|
31
|
-
l = c;
|
|
32
|
-
else {
|
|
33
|
-
const t = f.getInitializer();
|
|
34
|
-
if (t) {
|
|
35
|
-
const g = t.getFirstDescendantByKind(
|
|
36
|
-
s.ArrowFunction
|
|
37
|
-
);
|
|
38
|
-
if (g)
|
|
39
|
-
l = g;
|
|
40
|
-
else {
|
|
41
|
-
const h = t.getFirstDescendantByKind(
|
|
42
|
-
s.FunctionExpression
|
|
43
|
-
);
|
|
44
|
-
h && (i = h);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
if (!l) {
|
|
51
|
-
const e = n.getFunction("load");
|
|
52
|
-
e && e.isExported() && (i = e);
|
|
53
|
-
}
|
|
54
|
-
if (!l && !i) {
|
|
55
|
-
n.addFunction({
|
|
56
|
-
isExported: !0,
|
|
57
|
-
isAsync: !0,
|
|
58
|
-
name: "load",
|
|
59
|
-
parameters: [{ name: "{ locals }" }],
|
|
60
|
-
statements: "return { user: locals.pb.authStore.record };"
|
|
61
|
-
}), n.formatText(), n.saveSync();
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
const d = l ?? i, p = d.getParameters();
|
|
65
|
-
if (p.length === 0)
|
|
66
|
-
d.insertParameter(0, { name: "{ locals }" });
|
|
67
|
-
else {
|
|
68
|
-
const e = p[0], r = e.getStructure(), c = e.getNameNode();
|
|
69
|
-
if (c.getKind() === s.ObjectBindingPattern) {
|
|
70
|
-
const t = c;
|
|
71
|
-
if (!t.getElements().some((h) => h.getName() === "locals")) {
|
|
72
|
-
const h = t.getElements().map((E) => E.getText()).filter(Boolean), x = h.length > 0 ? ", " + h.join(", ") : "";
|
|
73
|
-
e.set({
|
|
74
|
-
name: `{ locals${x} }`,
|
|
75
|
-
type: r.type,
|
|
76
|
-
initializer: r.initializer
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
} else {
|
|
80
|
-
const t = e.getName();
|
|
81
|
-
t !== "locals" && e.set({
|
|
82
|
-
name: `{ locals, ...${t} }`,
|
|
83
|
-
type: r.type,
|
|
84
|
-
initializer: r.initializer
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
if (l) {
|
|
89
|
-
const e = l.getBody();
|
|
90
|
-
if (e.getKind() === s.Block)
|
|
91
|
-
e.getDescendantsOfKind(s.ReturnStatement).forEach((c) => {
|
|
92
|
-
const t = c.getExpression();
|
|
93
|
-
if (t) {
|
|
94
|
-
if (t.getKind() === s.ObjectLiteralExpression)
|
|
95
|
-
a(t);
|
|
96
|
-
else if (t.getKind() === s.ParenthesizedExpression) {
|
|
97
|
-
const g = t.getExpression();
|
|
98
|
-
g.getKind() === s.ObjectLiteralExpression && a(g);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
});
|
|
102
|
-
else {
|
|
103
|
-
const r = e;
|
|
104
|
-
if (r.getKind() === s.ParenthesizedExpression) {
|
|
105
|
-
const c = r.getExpression();
|
|
106
|
-
c.getKind() === s.ObjectLiteralExpression && a(c);
|
|
107
|
-
} else r.getKind() === s.ObjectLiteralExpression && a(r);
|
|
108
|
-
}
|
|
109
|
-
} else if (i) {
|
|
110
|
-
const e = i.getBody();
|
|
111
|
-
e && e.getDescendantsOfKind(s.ReturnStatement).forEach((c) => {
|
|
112
|
-
const t = c.getExpression();
|
|
113
|
-
if (t) {
|
|
114
|
-
if (t.getKind() === s.ObjectLiteralExpression)
|
|
115
|
-
a(t);
|
|
116
|
-
else if (t.getKind() === s.ParenthesizedExpression) {
|
|
117
|
-
const g = t.getExpression();
|
|
118
|
-
g.getKind() === s.ObjectLiteralExpression && a(g);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
n.formatText(), n.saveSync();
|
|
124
|
-
}
|
|
125
|
-
function P(u) {
|
|
126
|
-
let o = m.readFileSync(u, "utf8");
|
|
127
|
-
const n = o.match(/<Navbar\.Root>([\s\S]*?)<\/Navbar\.Root>/);
|
|
128
|
-
if (!n)
|
|
129
|
-
return;
|
|
130
|
-
const a = n[1].match(
|
|
131
|
-
/<Navbar\.List>([\s\S]*?)<\/Navbar\.List>/
|
|
132
|
-
);
|
|
133
|
-
if (!a)
|
|
134
|
-
return;
|
|
135
|
-
const l = A`
|
|
136
|
-
import * as AuthMenu from '$lib/components/ui/auth-menu';
|
|
137
|
-
import * as Avatar from '$lib/components/ui/avatar';
|
|
138
|
-
`, i = o.indexOf("<script");
|
|
139
|
-
if (i !== -1) {
|
|
140
|
-
const d = o.indexOf(">", i), p = d !== -1 ? o.indexOf("<\/script>", d + 1) : -1;
|
|
141
|
-
if (d !== -1 && p !== -1) {
|
|
142
|
-
const e = o.slice(d + 1, p);
|
|
143
|
-
let r = -1;
|
|
144
|
-
const c = /^\s*import[\s\S]*?;[ \t]*$/gm;
|
|
145
|
-
let t;
|
|
146
|
-
for (; (t = c.exec(e)) !== null; )
|
|
147
|
-
r = t.index + t[0].length;
|
|
148
|
-
if (r !== -1) {
|
|
149
|
-
const g = e.slice(0, r), h = e.slice(r), x = `${g}
|
|
150
|
-
${l}
|
|
151
|
-
${h}`;
|
|
152
|
-
o = o.slice(0, d + 1) + x + o.slice(p);
|
|
153
|
-
} else
|
|
154
|
-
o = o.replace("<\/script>", `${l}
|
|
155
|
-
<\/script>`);
|
|
156
|
-
} else
|
|
157
|
-
o = o.replace("<\/script>", `${l}
|
|
158
|
-
<\/script>`);
|
|
159
|
-
} else
|
|
160
|
-
o = o.replace("<\/script>", `${l}
|
|
161
|
-
<\/script>`);
|
|
162
|
-
const f = a[1] + `
|
|
163
|
-
<Navbar.Item
|
|
164
|
-
class="flex flex-col md:flex-row items-center space-y-2 md:space-y-0 md:space-x-4"
|
|
165
|
-
>
|
|
166
|
-
<AuthMenu.Root>
|
|
167
|
-
{#snippet user()}
|
|
168
|
-
<AuthMenu.Trigger>
|
|
169
|
-
<Avatar.Root>
|
|
170
|
-
{#if data.user?.avatar}
|
|
171
|
-
<Avatar.Image
|
|
172
|
-
src="/api/files/users/{data.user?.id}/{data.user?.avatar}"
|
|
173
|
-
alt={data.user?.email}
|
|
174
|
-
/>
|
|
175
|
-
{/if}
|
|
176
|
-
<Avatar.Fallback>
|
|
177
|
-
{data.user?.email?.charAt(0).toUpperCase()}
|
|
178
|
-
</Avatar.Fallback>
|
|
179
|
-
</Avatar.Root>
|
|
180
|
-
</AuthMenu.Trigger>
|
|
181
|
-
|
|
182
|
-
<AuthMenu.Content align="end">
|
|
183
|
-
<AuthMenu.Item href="/dashboard">Dashboard</AuthMenu.Item>
|
|
184
|
-
<AuthMenu.Group>
|
|
185
|
-
<AuthMenu.Item href="/settings">Settings</AuthMenu.Item>
|
|
186
|
-
<AuthMenu.Item>
|
|
187
|
-
<form action="/logout" method="post">
|
|
188
|
-
<button type="submit" class="contents">Logout</button>
|
|
189
|
-
</form>
|
|
190
|
-
</AuthMenu.Item>
|
|
191
|
-
</AuthMenu.Group>
|
|
192
|
-
</AuthMenu.Content>
|
|
193
|
-
{/snippet}
|
|
194
|
-
|
|
195
|
-
{#snippet guest()}
|
|
196
|
-
<Button
|
|
197
|
-
class="w-full justify-start md:justify-center md:w-auto"
|
|
198
|
-
variant="ghost"
|
|
199
|
-
href="/login">Login</Button
|
|
200
|
-
>
|
|
201
|
-
<Button
|
|
202
|
-
class="w-full justify-start md:justify-center md:w-auto"
|
|
203
|
-
variant="outline"
|
|
204
|
-
href="/signup">Sign up</Button
|
|
205
|
-
>
|
|
206
|
-
{/snippet}
|
|
207
|
-
</AuthMenu.Root>
|
|
208
|
-
</Navbar.Item>
|
|
209
|
-
`;
|
|
210
|
-
o = o.replace(a[1], f), m.writeFileSync(u, o);
|
|
211
|
-
}
|
|
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
|
-
n.saveSync();
|
|
216
|
-
return;
|
|
217
|
-
}
|
|
218
|
-
const l = a.getArguments();
|
|
219
|
-
if (l.length === 0) {
|
|
220
|
-
a.addArgument("{ auth: { protectedRoutes: ['/(app)'] } }"), n.formatText(), n.saveSync();
|
|
221
|
-
return;
|
|
222
|
-
}
|
|
223
|
-
const i = l[0];
|
|
224
|
-
if (i.getKind() !== s.ObjectLiteralExpression) {
|
|
225
|
-
a.insertArgument(0, "{ auth: { protectedRoutes: ['/(app)'] } }"), n.formatText(), n.saveSync();
|
|
226
|
-
return;
|
|
227
|
-
}
|
|
228
|
-
const f = i.asKindOrThrow(s.ObjectLiteralExpression), d = f.getProperty("auth");
|
|
229
|
-
if (!d) {
|
|
230
|
-
f.addPropertyAssignment({
|
|
231
|
-
name: "auth",
|
|
232
|
-
initializer: "{ protectedRoutes: ['/(app)'] }"
|
|
233
|
-
}), n.formatText(), n.saveSync();
|
|
234
|
-
return;
|
|
235
|
-
}
|
|
236
|
-
if (d.getKind() === s.PropertyAssignment) {
|
|
237
|
-
const p = d.getInitializer();
|
|
238
|
-
if (p && p.getKind() === s.ObjectLiteralExpression) {
|
|
239
|
-
const e = p, r = e.getProperty("protectedRoutes");
|
|
240
|
-
if (!r)
|
|
241
|
-
e.addPropertyAssignment({
|
|
242
|
-
name: "protectedRoutes",
|
|
243
|
-
initializer: "['/(app)']"
|
|
244
|
-
});
|
|
245
|
-
else if (r.getKind() === s.PropertyAssignment) {
|
|
246
|
-
const c = r.getInitializer();
|
|
247
|
-
if (c && c.getKind() === s.ArrayLiteralExpression) {
|
|
248
|
-
const t = c;
|
|
249
|
-
t.getElements().some((h) => h.getText().replace(/['"`]/g, "") === "/(app)") || t.addElement("'/(app)'");
|
|
250
|
-
} else
|
|
251
|
-
r.setInitializer(
|
|
252
|
-
"['/(app)']"
|
|
253
|
-
);
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
n.formatText(), n.saveSync();
|
|
258
|
-
}
|
|
259
|
-
async function T(u) {
|
|
260
|
-
const { input: o } = u;
|
|
261
|
-
let n = [];
|
|
262
|
-
await v(u.root, async (d) => {
|
|
263
|
-
await d.settings.update({
|
|
264
|
-
meta: {
|
|
265
|
-
senderName: o.senderName,
|
|
266
|
-
senderAddress: o.senderAddress
|
|
267
|
-
}
|
|
268
|
-
});
|
|
269
|
-
const p = await d.collections.getOne("users");
|
|
270
|
-
if (!p)
|
|
271
|
-
throw new Error("Users collection not found");
|
|
272
|
-
const e = p.verificationTemplate.body.replace(
|
|
273
|
-
"{APP_URL}/_/#/auth/confirm-verification/{TOKEN}",
|
|
274
|
-
"{APP_URL}/confirm-verification/{TOKEN}"
|
|
275
|
-
), r = p.resetPasswordTemplate.body.replace(
|
|
276
|
-
"{APP_URL}/_/#/auth/confirm-password-reset/{TOKEN}",
|
|
277
|
-
"{APP_URL}/confirm-password-reset/{TOKEN}"
|
|
278
|
-
), c = p.confirmEmailChangeTemplate.body.replace(
|
|
279
|
-
"{APP_URL}/_/#/auth/confirm-email-change/{TOKEN}",
|
|
280
|
-
"{APP_URL}/confirm-email-change/{TOKEN}"
|
|
281
|
-
);
|
|
282
|
-
await d.collections.update("users", {
|
|
283
|
-
listRule: "@request.auth.id = id",
|
|
284
|
-
viewRule: "@request.auth.id = id",
|
|
285
|
-
createRule: "@request.auth.id = id",
|
|
286
|
-
updateRule: "@request.auth.id = id",
|
|
287
|
-
deleteRule: "@request.auth.id = id",
|
|
288
|
-
// Update email templates to VelaStack auth urls
|
|
289
|
-
verificationTemplate: {
|
|
290
|
-
body: e
|
|
291
|
-
},
|
|
292
|
-
resetPasswordTemplate: {
|
|
293
|
-
body: r
|
|
294
|
-
},
|
|
295
|
-
confirmEmailChangeTemplate: {
|
|
296
|
-
body: c
|
|
297
|
-
}
|
|
298
|
-
});
|
|
299
|
-
const t = S("users", "updated", u);
|
|
300
|
-
t && n.push({
|
|
301
|
-
path: t,
|
|
302
|
-
language: "ts",
|
|
303
|
-
content: m.readFileSync(t, "utf8")
|
|
304
|
-
});
|
|
305
|
-
});
|
|
306
|
-
let a = [];
|
|
307
|
-
const l = y.join(
|
|
308
|
-
u.root,
|
|
309
|
-
"src",
|
|
310
|
-
"routes",
|
|
311
|
-
"+layout.server.ts"
|
|
312
|
-
);
|
|
313
|
-
await w(l), a.push({
|
|
314
|
-
path: l,
|
|
315
|
-
language: "ts",
|
|
316
|
-
content: m.readFileSync(l, "utf8")
|
|
317
|
-
});
|
|
318
|
-
let i = y.join(
|
|
319
|
-
u.root,
|
|
320
|
-
"src",
|
|
321
|
-
"routes",
|
|
322
|
-
"(public)",
|
|
323
|
-
"root-layout.svelte"
|
|
324
|
-
);
|
|
325
|
-
m.existsSync(i) || (i = y.join(u.root, "src", "routes", "root-layout.svelte")), m.existsSync(i) || (i = y.join(
|
|
326
|
-
u.root,
|
|
327
|
-
"src",
|
|
328
|
-
"routes",
|
|
329
|
-
"(public)",
|
|
330
|
-
"+layout.svelte"
|
|
331
|
-
)), m.existsSync(i) || (i = y.join(u.root, "src", "routes", "+layout.svelte")), m.existsSync(i) && (P(i), a.push({
|
|
332
|
-
path: i,
|
|
333
|
-
language: "svelte",
|
|
334
|
-
content: m.readFileSync(i, "utf8")
|
|
335
|
-
}));
|
|
336
|
-
const f = y.join(u.root, "src", "hooks.server.ts");
|
|
337
|
-
return m.existsSync(f) && (K(f), a.push({
|
|
338
|
-
path: f,
|
|
339
|
-
language: "ts",
|
|
340
|
-
content: m.readFileSync(f, "utf8")
|
|
341
|
-
})), {
|
|
342
|
-
creates: [],
|
|
343
|
-
modifies: a,
|
|
344
|
-
deletes: [],
|
|
345
|
-
components: [],
|
|
346
|
-
packages: [],
|
|
347
|
-
collections: []
|
|
348
|
-
};
|
|
349
|
-
}
|
|
350
|
-
export {
|
|
351
|
-
T as generate
|
|
352
|
-
};
|
|
353
|
-
//# sourceMappingURL=generate.runtime-C7YhHvlr.js.map
|