@velastack/patterns 0.0.59 → 0.0.61
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.
|
@@ -111,8 +111,8 @@ var x = e`
|
|
|
111
111
|
import * as main from '$locales/main.loader.server.svelte.js';
|
|
112
112
|
import * as js from '$locales/js.loader.server.js';
|
|
113
113
|
|
|
114
|
-
loadLocales(main.key, main.
|
|
115
|
-
loadLocales(js.key, js.
|
|
114
|
+
loadLocales(main.key, main.loadCount, main.loadCatalog, locales);
|
|
115
|
+
loadLocales(js.key, js.loadCount, js.loadCatalog, locales);
|
|
116
116
|
|
|
117
117
|
const handleWuchale = async ({ event, resolve }: any) => {
|
|
118
118
|
const locale = getLocale(event.url);
|
|
@@ -135,8 +135,8 @@ var x = e`
|
|
|
135
135
|
import * as main from '$locales/main.loader.server.svelte.js';
|
|
136
136
|
import * as js from '$locales/js.loader.server.js';
|
|
137
137
|
|
|
138
|
-
loadLocales(main.key, main.
|
|
139
|
-
loadLocales(js.key, js.
|
|
138
|
+
loadLocales(main.key, main.loadCount, main.loadCatalog, locales);
|
|
139
|
+
loadLocales(js.key, js.loadCount, js.loadCatalog, locales);
|
|
140
140
|
|
|
141
141
|
const handleWuchale = async ({ event, resolve }: any) => {
|
|
142
142
|
const locale = getLocale(event.url);
|
|
@@ -192,8 +192,8 @@ function T(t) {
|
|
|
192
192
|
};
|
|
193
193
|
C(r, "@sveltejs/kit/hooks", "sequence"), C(r, "wuchale/load-utils/server", "runWithLocale"), C(r, "wuchale/load-utils/server", "loadLocales"), C(r, "$locales/main.url", "getLocale"), C(r, "$locales/data", "locales"), w(r, "$locales/main.loader.server.svelte.js", "main"), w(r, "$locales/js.loader.server.js", "js");
|
|
194
194
|
let o = r.getStatements().findIndex((e) => e === a), s = "handleWuchale", c = e`
|
|
195
|
-
loadLocales(main.key, main.
|
|
196
|
-
loadLocales(js.key, js.
|
|
195
|
+
loadLocales(main.key, main.loadCount, main.loadCatalog, locales);
|
|
196
|
+
loadLocales(js.key, js.loadCount, js.loadCatalog, locales);
|
|
197
197
|
`, l = e`
|
|
198
198
|
const ${s} = async ({ event, resolve }: any) => {
|
|
199
199
|
const locale = getLocale(event.url);
|
|
@@ -414,4 +414,4 @@ async function z(e) {
|
|
|
414
414
|
//#endregion
|
|
415
415
|
export { z as generate };
|
|
416
416
|
|
|
417
|
-
//# sourceMappingURL=generate.runtime-
|
|
417
|
+
//# sourceMappingURL=generate.runtime-rfNiROHo.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate.runtime-rfNiROHo.js","names":[],"sources":["../../src/patterns/enable/i18n/modifies/vite-config.ts","../../src/patterns/enable/i18n/modifies/svelte-config.ts","../../src/patterns/enable/i18n/modifies/hooks.server.ts","../../src/patterns/enable/i18n/modifies/app-html.ts","../../src/patterns/enable/i18n/modifies/gitignore.ts","../../src/patterns/enable/i18n/modifies/+layout.ts","../../src/patterns/enable/i18n/modifies/root-layout.svelte.ts","../../src/patterns/enable/i18n/generate.runtime.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport { Project, QuoteKind, SyntaxKind } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nconst FAILURE_HINT = [\n \"Add the wuchale plugin to your Vite config:\",\n \"\",\n \"import { wuchale } from 'wuchale/vite';\",\n \"\",\n \"export default defineConfig({\",\n \" plugins: [wuchale(), /* ...existing plugins */],\",\n \"});\",\n].join(\"\\n\");\n\nconst NOT_FOUND_HINT = [\n \"Create a Vite config with the wuchale plugin:\",\n \"\",\n \"import { defineConfig } from 'vite';\",\n \"import { wuchale } from 'wuchale/vite';\",\n \"\",\n \"export default defineConfig({\",\n \" plugins: [wuchale()],\",\n \"});\",\n].join(\"\\n\");\n\nexport function modifyViteConfig(viteConfigPath: string): ModifyOutcome {\n if (!fs.existsSync(viteConfigPath)) {\n return { status: \"not-found\", message: NOT_FOUND_HINT };\n }\n\n const project = new Project({\n compilerOptions: { allowJs: true },\n manipulationSettings: { quoteKind: QuoteKind.Single },\n });\n const sourceFile = project.addSourceFileAtPath(viteConfigPath);\n\n let changed = false;\n let failed = false;\n\n const hasImport = sourceFile\n .getImportDeclarations()\n .some((d) => d.getModuleSpecifierValue() === \"wuchale/vite\");\n\n if (!hasImport) {\n sourceFile.insertImportDeclaration(0, {\n namedImports: [\"wuchale\"],\n moduleSpecifier: \"wuchale/vite\",\n });\n changed = true;\n }\n\n const defineConfigCall = sourceFile\n .getDescendantsOfKind(SyntaxKind.CallExpression)\n .find((ce) => ce.getExpression().getText() === \"defineConfig\");\n\n const configArg = defineConfigCall?.getArguments()?.[0];\n const configObj =\n configArg?.getKind() === SyntaxKind.ObjectLiteralExpression\n ? (configArg as import(\"ts-morph\").ObjectLiteralExpression)\n : null;\n\n if (!configObj) {\n failed = true;\n } else {\n const pluginsProp = configObj.getProperty(\"plugins\");\n if (!pluginsProp) {\n configObj.addPropertyAssignment({\n name: \"plugins\",\n initializer: \"[wuchale()]\",\n });\n changed = true;\n } else if (pluginsProp.getKind() !== SyntaxKind.PropertyAssignment) {\n failed = true;\n } else {\n const pluginsInit = (\n pluginsProp as import(\"ts-morph\").PropertyAssignment\n ).getInitializer();\n\n if (!pluginsInit) {\n (pluginsProp as import(\"ts-morph\").PropertyAssignment).setInitializer(\n \"[wuchale()]\",\n );\n changed = true;\n } else if (pluginsInit.getKind() !== SyntaxKind.ArrayLiteralExpression) {\n failed = true;\n } else {\n const arr = pluginsInit as import(\"ts-morph\").ArrayLiteralExpression;\n const hasWuchale = arr\n .getElements()\n .some((el) => el.getText().replace(/\\s/g, \"\") === \"wuchale()\");\n\n if (!hasWuchale) {\n arr.insertElement(0, \"wuchale()\");\n changed = true;\n }\n }\n }\n }\n\n if (changed) {\n sourceFile.formatText();\n sourceFile.saveSync();\n }\n\n if (failed) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n return { status: \"success\", changed };\n}\n","import { SyntaxKind, type PropertyAssignment } from \"ts-morph\";\nimport {\n getOrCreateObjectLiteralProperty,\n modifyConfig,\n type ConfigModifyResult,\n} from \"../../../../runtime/config-target\";\n\nconst FAILURE_HINT = [\n \"Add the $locales alias to your config (sveltekit() arg in vite.config, or svelte.config):\",\n \"\",\n \"alias: {\",\n \" $locales: 'src/locales',\",\n \"},\",\n].join(\"\\n\");\n\nconst NOT_FOUND_HINT = [\n \"Add the $locales alias by passing config to the sveltekit() plugin in vite.config.ts:\",\n \"\",\n \"import { sveltekit } from '@sveltejs/kit/vite';\",\n \"import { defineConfig } from 'vite';\",\n \"\",\n \"export default defineConfig({\",\n \" plugins: [sveltekit({ alias: { $locales: 'src/locales' } })],\",\n \"});\",\n].join(\"\\n\");\n\n/** Ensure the `$locales` alias points at `src/locales`. */\nexport function modifySvelteConfig(root: string): ConfigModifyResult {\n return modifyConfig(\n root,\n { notFound: NOT_FOUND_HINT, failed: FAILURE_HINT },\n (target) => {\n const kit = target.kitContainer();\n if (!kit) return false;\n const aliasObj = getOrCreateObjectLiteralProperty(kit, \"alias\", \"{}\");\n if (!aliasObj) return false;\n\n const existing = aliasObj.getProperty(\"$locales\");\n if (!existing) {\n aliasObj.addPropertyAssignment({\n name: \"$locales\",\n initializer: \"'src/locales'\",\n });\n return true;\n }\n if (existing.getKind() !== SyntaxKind.PropertyAssignment) return false;\n\n const init = (existing as PropertyAssignment).getInitializer();\n const current = init?.getText()?.replace(/['\"`]/g, \"\");\n if (current !== \"src/locales\") {\n (existing as PropertyAssignment).setInitializer(\"'src/locales'\");\n }\n return true;\n },\n );\n}\n","import fs from \"node:fs\";\nimport dedent from \"dedent\";\nimport { Project, QuoteKind, SyntaxKind } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nconst FAILURE_HINT = dedent`\n Wrap your exported handle with the wuchale i18n handler:\n\n import { sequence } from '@sveltejs/kit/hooks';\n import { runWithLocale, loadLocales } from 'wuchale/load-utils/server';\n import { getLocale } from '$locales/main.url';\n import { locales } from '$locales/data';\n import * as main from '$locales/main.loader.server.svelte.js';\n import * as js from '$locales/js.loader.server.js';\n\n loadLocales(main.key, main.loadCount, main.loadCatalog, locales);\n loadLocales(js.key, js.loadCount, js.loadCatalog, locales);\n\n const handleWuchale = async ({ event, resolve }: any) => {\n const locale = getLocale(event.url);\n return await runWithLocale(locale, () =>\n resolve(event, {\n transformPageChunk: ({ html }: { html: string }) =>\n html.replace('%sveltekit.lang%', locale),\n }),\n );\n };\n\n export const handle = sequence(handleWuchale, /* your existing handle */);\n`;\n\nconst NOT_FOUND_HINT = dedent`\n Create src/hooks.server.ts with an i18n handle:\n\n import { sequence } from '@sveltejs/kit/hooks';\n import { runWithLocale, loadLocales } from 'wuchale/load-utils/server';\n import { getLocale } from '$locales/main.url';\n import { locales } from '$locales/data';\n import * as main from '$locales/main.loader.server.svelte.js';\n import * as js from '$locales/js.loader.server.js';\n\n loadLocales(main.key, main.loadCount, main.loadCatalog, locales);\n loadLocales(js.key, js.loadCount, js.loadCatalog, locales);\n\n const handleWuchale = async ({ event, resolve }: any) => {\n const locale = getLocale(event.url);\n return await runWithLocale(locale, () =>\n resolve(event, {\n transformPageChunk: ({ html }: { html: string }) =>\n html.replace('%sveltekit.lang%', locale),\n }),\n );\n };\n\n export const handle = handleWuchale;\n`;\n\nfunction ensureNamedImport(\n sourceFile: import(\"ts-morph\").SourceFile,\n moduleSpecifier: string,\n name: string,\n) {\n const existing = sourceFile\n .getImportDeclarations()\n .find((d) => d.getModuleSpecifierValue() === moduleSpecifier);\n if (existing) {\n const has = existing.getNamedImports().some((ni) => ni.getName() === name);\n if (!has) existing.addNamedImport(name);\n return;\n }\n sourceFile.addImportDeclaration({ namedImports: [name], moduleSpecifier });\n}\n\nfunction ensureNamespaceImport(\n sourceFile: import(\"ts-morph\").SourceFile,\n moduleSpecifier: string,\n ns: string,\n) {\n const existing = sourceFile\n .getImportDeclarations()\n .find((d) => d.getModuleSpecifierValue() === moduleSpecifier);\n if (existing) return;\n sourceFile.addImportDeclaration({ namespaceImport: ns, moduleSpecifier });\n}\n\nexport function modifyHooksServerI18n(hooksServerPath: string): 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(\"runWithLocale\") || original.includes(\"loadLocales(\")) {\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 handleDecl = sourceFile.getVariableDeclaration(\"handle\");\n if (!handleDecl) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n const handleStmt = handleDecl.getFirstAncestorByKind(\n SyntaxKind.VariableStatement,\n );\n if (!handleStmt?.hasExportKeyword()) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n ensureNamedImport(sourceFile, \"@sveltejs/kit/hooks\", \"sequence\");\n ensureNamedImport(sourceFile, \"wuchale/load-utils/server\", \"runWithLocale\");\n ensureNamedImport(sourceFile, \"wuchale/load-utils/server\", \"loadLocales\");\n ensureNamedImport(sourceFile, \"$locales/main.url\", \"getLocale\");\n ensureNamedImport(sourceFile, \"$locales/data\", \"locales\");\n ensureNamespaceImport(\n sourceFile,\n \"$locales/main.loader.server.svelte.js\",\n \"main\",\n );\n ensureNamespaceImport(sourceFile, \"$locales/js.loader.server.js\", \"js\");\n\n const statements = sourceFile.getStatements();\n const handleStmtIndex = statements.findIndex((s) => s === handleStmt);\n const i18nHandleName = \"handleWuchale\";\n\n const startupSnippet = dedent`\n loadLocales(main.key, main.loadCount, main.loadCatalog, locales);\n loadLocales(js.key, js.loadCount, js.loadCatalog, locales);\n `;\n\n const i18nHandleSnippet = dedent`\n const ${i18nHandleName} = async ({ event, resolve }: any) => {\n const locale = getLocale(event.url);\n return await runWithLocale(locale, () =>\n resolve(event, {\n transformPageChunk: ({ html }: { html: string }) =>\n html.replace('%sveltekit.lang%', locale)\n })\n );\n };\n `;\n\n if (handleStmtIndex >= 0) {\n sourceFile.insertStatements(\n handleStmtIndex,\n `\\n${startupSnippet}\\n\\n${i18nHandleSnippet}\\n`,\n );\n } else {\n sourceFile.addStatements(`\\n${startupSnippet}\\n\\n${i18nHandleSnippet}\\n`);\n }\n\n const init = handleDecl.getInitializer();\n if (!init) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n const initText = init.getText();\n if (initText.includes(i18nHandleName) || initText.includes(\"runWithLocale\")) {\n return { status: \"success\", changed: false };\n }\n\n handleDecl.setInitializer(`sequence(${i18nHandleName}, ${initText})`);\n sourceFile.formatText();\n sourceFile.saveSync();\n return { status: \"success\", changed: true };\n}\n","import fs from \"node:fs\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nconst FAILURE_HINT = [\n \"Add the sveltekit lang placeholder to the <html> tag:\",\n \"\",\n '<html lang=\"%sveltekit.lang%\">',\n].join(\"\\n\");\n\nconst NOT_FOUND_HINT = [\n \"Create src/app.html with a lang placeholder:\",\n \"\",\n \"<!doctype html>\",\n '<html lang=\"%sveltekit.lang%\">',\n \" <head>\",\n ' <meta charset=\"utf-8\" />',\n \" %sveltekit.head%\",\n \" </head>\",\n ' <body data-sveltekit-preload-data=\"hover\">',\n ' <div style=\"display: contents\">%sveltekit.body%</div>',\n \" </body>\",\n \"</html>\",\n].join(\"\\n\");\n\nexport function modifyAppHtml(appHtmlPath: string): ModifyOutcome {\n if (!fs.existsSync(appHtmlPath)) {\n return { status: \"not-found\", message: NOT_FOUND_HINT };\n }\n\n const original = fs.readFileSync(appHtmlPath, \"utf8\");\n if (\n original.includes('lang=\"%sveltekit.lang%\"') ||\n original.includes(\"lang='%sveltekit.lang%'\")\n ) {\n return { status: \"success\", changed: false };\n }\n\n const updated = original.replace(/<html(\\s[^>]*?)?>/i, (match) => {\n if (/lang\\s*=/.test(match)) {\n return match;\n }\n return match.replace(/<html/i, '<html lang=\"%sveltekit.lang%\"');\n });\n\n if (updated === original) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n fs.writeFileSync(appHtmlPath, updated);\n return { status: \"success\", changed: true };\n}\n","import fs from \"node:fs\";\nimport dedent from \"dedent\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nconst NOT_FOUND_HINT = [\n \"Create a .gitignore with the wuchale cache ignored:\",\n \"\",\n \"# Wuchale\",\n \"src/locales/.wuchale\",\n].join(\"\\n\");\n\nexport function modifyGitignore(gitignorePath: string): ModifyOutcome {\n if (!fs.existsSync(gitignorePath)) {\n return { status: \"not-found\", message: NOT_FOUND_HINT };\n }\n\n const original = fs.readFileSync(gitignorePath, \"utf8\");\n if (original.includes(\"src/locales/.wuchale\")) {\n return { status: \"success\", changed: false };\n }\n\n const block = dedent`\n # Wuchale\n src/locales/.wuchale\n `;\n\n const needsNewline = original.length > 0 && !original.endsWith(\"\\n\");\n const updated = original + (needsNewline ? \"\\n\" : \"\") + \"\\n\" + block + \"\\n\";\n fs.writeFileSync(gitignorePath, updated);\n return { status: \"success\", changed: true };\n}\n","import fs from \"node:fs\";\nimport path from \"node:path\";\nimport dedent from \"dedent\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nconst LOAD_SNIPPET = dedent`\n import { browser } from '$app/environment';\n import { loadLocale } from 'wuchale/load-utils';\n\n import { getLocale } from '$locales/main.url';\n import '$locales/main.loader.svelte';\n import '$locales/js.loader';\n\n export const load = async ({ url, data }) => {\n const locale = getLocale(url);\n\n if (browser) {\n await loadLocale(locale);\n }\n\n return data;\n };\n`;\n\nconst FAILURE_HINT = [\n \"Merge the wuchale loader into your existing load function in +layout.ts:\",\n \"\",\n LOAD_SNIPPET,\n].join(\"\\n\");\n\nexport function ensureRootLayoutI18n(layoutPath: string): ModifyOutcome {\n if (fs.existsSync(layoutPath)) {\n const existing = fs.readFileSync(layoutPath, \"utf8\");\n if (existing.includes(\"loadLocale\") || existing.includes(\"translateUrl\")) {\n return { status: \"success\", changed: false };\n }\n\n if (/\\bexport\\s+(const|function)\\s+load\\b/.test(existing)) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n }\n\n fs.mkdirSync(path.dirname(layoutPath), { recursive: true });\n fs.writeFileSync(layoutPath, LOAD_SNIPPET + \"\\n\");\n return { status: \"success\", changed: true };\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 LANGUAGE_SELECT_SNIPPET = `<Navbar.Item>\n\t\t\t\t<LanguageSelect />\n\t\t\t</Navbar.Item>\n\t\t\t`;\n\nconst IMPORT_SNIPPET = dedent`\n import LanguageSelect from '$lib/components/language-select.svelte';\n`;\n\nconst FAILURE_HINT = [\n \"Add the language select inside your <Navbar.List> in the root layout.\",\n \"\",\n \"Import to add to the <script> tag:\",\n \"\",\n IMPORT_SNIPPET,\n \"\",\n \"Markup to add at the end of <Navbar.List>:\",\n LANGUAGE_SELECT_SNIPPET,\n].join(\"\\n\");\n\nconst NOT_FOUND_HINT = [\n \"Create a root layout that includes a language select inside <Navbar.List>.\",\n \"\",\n \"Import for the <script> tag:\",\n \"\",\n IMPORT_SNIPPET,\n \"\",\n \"Markup at the end of <Navbar.List>:\",\n LANGUAGE_SELECT_SNIPPET,\n].join(\"\\n\");\n\nexport function modifyRootLayoutLanguageSelect(\n layoutPath: string,\n): 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(\"Navbar.List\")) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n if (file.hasElement(\"LanguageSelect\")) {\n return { status: \"success\", changed: false };\n }\n\n file.modifyScript((source) => {\n const { source: out } = withInMemoryScript(source, (sf) => {\n ensureImports(sf, [\n {\n defaultImport: \"LanguageSelect\",\n moduleSpecifier: \"$lib/components/language-select.svelte\",\n },\n ]);\n });\n return out;\n });\n\n file.insertBeforeClosingTag(\"Navbar.List\", LANGUAGE_SELECT_SNIPPET);\n file.writeTo(layoutPath);\n return { status: \"success\", changed: file.hasChanged() };\n}\n","import fs from \"node:fs\";\nimport path from \"node:path\";\nimport type { File, Options, Result } from \"../../../core/types\";\nimport { getLogger } from \"../../../core/logger\";\nimport { modifyOutcomeToFile } from \"../../../runtime/modify-file\";\nimport {\n probeFirstExisting,\n VITE_CONFIG_CANDIDATES,\n} from \"../../../runtime/config-target\";\nimport { modifyViteConfig } from \"./modifies/vite-config\";\nimport { modifySvelteConfig } from \"./modifies/svelte-config\";\nimport { modifyHooksServerI18n } from \"./modifies/hooks.server\";\nimport { modifyAppHtml } from \"./modifies/app-html\";\nimport { modifyGitignore } from \"./modifies/gitignore\";\nimport { ensureRootLayoutI18n } from \"./modifies/+layout\";\nimport { modifyRootLayoutLanguageSelect } 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 vite.config\");\n const viteConfigPath =\n probeFirstExisting(options.root, VITE_CONFIG_CANDIDATES) ??\n path.join(options.root, VITE_CONFIG_CANDIDATES[0]);\n pushResult(\n modifyOutcomeToFile(viteConfigPath, modifyViteConfig(viteConfigPath)),\n );\n\n logger.info(\"Modifying config for i18n alias\");\n const alias = modifySvelteConfig(options.root);\n pushResult(modifyOutcomeToFile(alias.filePath, alias.outcome));\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 modifyHooksServerI18n(hooksServerPath),\n ),\n );\n\n logger.info(\"Modifying app.html\");\n const appHtmlPath = path.join(options.root, \"src\", \"app.html\");\n pushResult(modifyOutcomeToFile(appHtmlPath, modifyAppHtml(appHtmlPath)));\n\n logger.info(\"Modifying root +layout.ts\");\n const layoutPath = path.join(options.root, \"src\", \"routes\", \"+layout.ts\");\n pushResult(modifyOutcomeToFile(layoutPath, ensureRootLayoutI18n(layoutPath)));\n\n logger.info(\"Modifying root layout language select\");\n const rootLayoutCandidates = [\n path.join(options.root, \"src\", \"routes\", \"(public)\", \"root-layout.svelte\"),\n path.join(options.root, \"src\", \"routes\", \"root-layout.svelte\"),\n path.join(options.root, \"src\", \"routes\", \"(public)\", \"+layout.svelte\"),\n path.join(options.root, \"src\", \"routes\", \"+layout.svelte\"),\n ];\n const rootLayoutPath =\n rootLayoutCandidates.find((p) => fs.existsSync(p)) ??\n rootLayoutCandidates[0];\n pushResult(\n modifyOutcomeToFile(\n rootLayoutPath,\n modifyRootLayoutLanguageSelect(rootLayoutPath),\n ),\n );\n\n logger.info(\"Updating .gitignore\");\n const gitignorePath = path.join(options.root, \".gitignore\");\n pushResult(\n modifyOutcomeToFile(gitignorePath, modifyGitignore(gitignorePath)),\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":";;;;;;;;;AAIA,IAAM,IAAe;CACnB;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC,CAAC,KAAK,IAAI,GAEL,IAAiB;CACrB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC,CAAC,KAAK,IAAI;AAEX,SAAgB,EAAiB,GAAuC;CACtE,IAAI,CAAC,EAAG,WAAW,CAAc,GAC/B,OAAO;EAAE,QAAQ;EAAa,SAAS;CAAe;CAOxD,IAAM,IAAa,IAJC,EAAQ;EAC1B,iBAAiB,EAAE,SAAS,GAAK;EACjC,sBAAsB,EAAE,WAAW,EAAU,OAAO;CACtD,CACmB,CAAA,CAAQ,oBAAoB,CAAc,GAEzD,IAAU,IACV,IAAS;CAMb,AAJkB,EACf,sBAAsB,CAAC,CACvB,MAAM,MA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vB,AAPA,EACE,EACE,GACA,EAA+B,CAAc,CAC/C,CACF,GAEA,EAAO,KAAK,qBAAqB;CACjC,IAAM,IAAgB,EAAK,KAAK,EAAQ,MAAM,YAAY;CAK1D,OAJA,EACE,EAAoB,GAAe,EAAgB,CAAa,CAAC,CACnE,GAEO;EACL,SAAS,CAAC;EACV;EACA,SAAS,CAAC;EACV,YAAY,CAAC;EACb,UAAU,CAAC;EACX,aAAa,CAAC;EACd,mBAAmB,CAAC;EACpB,iBAAiB,CAAC;CACpB;AACF"}
|
package/dist/index.js
CHANGED
|
@@ -26,7 +26,7 @@ var le = Object.create, ue = Object.defineProperty, de = Object.getOwnPropertyDe
|
|
|
26
26
|
throw Error("Calling `require` for \"" + e + "\" in an environment that doesn't expose the `require` function. See https://rolldown.rs/in-depth/bundling-cjs#require-external-modules for more details.");
|
|
27
27
|
}), ye = {
|
|
28
28
|
name: "@velastack/patterns",
|
|
29
|
-
version: "0.0.
|
|
29
|
+
version: "0.0.61",
|
|
30
30
|
description: "Registry of VelaStack patterns: generators and modifications applied to SvelteKit projects by the VelaStack CLI.",
|
|
31
31
|
type: "module",
|
|
32
32
|
private: !1,
|
|
@@ -68,7 +68,7 @@ var le = Object.create, ue = Object.defineProperty, de = Object.getOwnPropertyDe
|
|
|
68
68
|
"prettier-plugin-svelte": "^4.1.1"
|
|
69
69
|
},
|
|
70
70
|
peerDependencies: {
|
|
71
|
-
"@velastack/pocketbase": "^0.0
|
|
71
|
+
"@velastack/pocketbase": "^0.1.0",
|
|
72
72
|
"cross-spawn": "^7.0.6",
|
|
73
73
|
"magic-string": "^0.30.21",
|
|
74
74
|
"package-manager-detector": "^1.6.0",
|
|
@@ -91,7 +91,7 @@ var le = Object.create, ue = Object.defineProperty, de = Object.getOwnPropertyDe
|
|
|
91
91
|
"@types/cross-spawn": "^6.0.6",
|
|
92
92
|
"@types/node": "^22.0.0",
|
|
93
93
|
"@types/pluralize": "^0.0.33",
|
|
94
|
-
"@velastack/pocketbase": "^0.0
|
|
94
|
+
"@velastack/pocketbase": "^0.1.0",
|
|
95
95
|
"change-case": "^5.4.4",
|
|
96
96
|
"cross-spawn": "^7.0.6",
|
|
97
97
|
dedent: "^1.7.2",
|
|
@@ -4400,7 +4400,7 @@ var ks = {
|
|
|
4400
4400
|
tests: 1,
|
|
4401
4401
|
baseline: "velastack",
|
|
4402
4402
|
generate: Os
|
|
4403
|
-
}, As = "import { z } from \"zod\";\nimport type { Schemas } from \"@velastack/pocketbase\";\n\nexport const apiKeySchema = z.object({\n label: z.string(),\n}) satisfies Schemas[\"api_keys\"];\n", js = "export const load = async ({ locals }) => {\n const apiKeys = await locals.pb.collection('api_keys').getFullList();\n return { apiKeys };\n};\n", Ms = "<script lang=\"ts\">\n import { getFlash } from 'sveltekit-flash-message';\n import { page } from '$app/state';\n import { toast } from 'svelte-sonner';\n import * as AlertDialog from '$lib/components/ui/alert-dialog';\n import { Button } from '$lib/components/ui/button';\n import { Badge } from '$lib/components/ui/badge';\n import { timeAgo } from '$lib/utils';\n import PlusIcon from '@lucide/svelte/icons/plus';\n import SquareDashedMousePointerIcon from '@lucide/svelte/icons/square-dashed-mouse-pointer';\n\n const flash = getFlash(page);\n\n let open = $state(false);\n let message = $state('');\n let title = $state('');\n let apiKey = $state('');\n\n $effect(() => {\n if (!$flash) return;\n\n if ($flash.type === 'success') {\n message = $flash.message;\n title = $flash.title;\n apiKey = $flash.apiKey;\n open = true;\n }\n\n $flash = undefined;\n });\n\n async function handleAction() {\n open = false;\n await navigator.clipboard.writeText(apiKey);\n toast.success('API key copied to clipboard');\n }\n\n let { data, children } = $props();\n<\/script>\n\n<section data-role=\"content\">\n <div class=\"flex justify-between items-center mb-4\">\n <h1 class=\"text-3xl font-bold tracking-tight\">API keys</h1>\n <Button href=\"/api-keys/new\" variant=\"outline\">\n <PlusIcon class=\"w-4 h-4\" />\n New API key\n </Button>\n </div>\n\n <AlertDialog.Root bind:open>\n <AlertDialog.Content class=\"max-w-120!\">\n <AlertDialog.Header>\n <AlertDialog.Title>{title}</AlertDialog.Title>\n <AlertDialog.Description class=\"text-wrap\">\n <p>{@html message}</p>\n <Badge variant=\"outline\" class=\"font-mono my-3 text-base\">{apiKey}</Badge>\n </AlertDialog.Description>\n </AlertDialog.Header>\n <AlertDialog.Footer>\n <AlertDialog.Cancel>Close</AlertDialog.Cancel>\n <AlertDialog.Action onclick={handleAction}>Copy</AlertDialog.Action>\n </AlertDialog.Footer>\n </AlertDialog.Content>\n </AlertDialog.Root>\n\n <div class=\"rounded-lg border bg-card overflow-hidden\">\n <div class=\"relative w-full overflow-auto\">\n {#if data.apiKeys.length === 0}\n <div class=\"p-4 text-center text-muted-foreground space-y-4 py-12\">\n <SquareDashedMousePointerIcon strokeWidth={1.2} class=\"w-8 h-8 mx-auto mb-2\" />\n <p>Seems like there are no API keys yet, but you can create the first one</p>\n <p class=\"text-sm text-muted-foreground\">\n <Button href=\"/api-keys/new\" variant=\"outline\">\n <PlusIcon class=\"w-4 h-4\" />\n New API key\n </Button>\n </p>\n </div>\n {:else}\n <table class=\"w-full caption-bottom text-sm\">\n <thead>\n <tr class=\"border-b\">\n <th class=\"h-12 px-4 text-left align-middle font-medium text-muted-foreground\"\n >Label</th\n >\n <th class=\"h-12 px-4 text-left align-middle font-medium text-muted-foreground\"\n >API key</th\n >\n <th class=\"h-12 px-4 text-left align-middle font-medium text-muted-foreground\"\n >Created</th\n >\n <th class=\"h-12 px-4 text-left align-middle font-medium text-muted-foreground\"\n >Last used</th\n >\n <th class=\"h-12 px-4 text-right align-middle font-medium text-muted-foreground\"></th>\n </tr>\n </thead>\n <tbody>\n {#each data.apiKeys as apiKey}\n <tr\n class=\"border-t transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted\"\n >\n <td class=\"p-4 align-middle font-medium\">{apiKey.label}</td>\n\n <td class=\"p-4 align-middle font-medium\">\n <Badge variant=\"outline\" class=\"font-mono\">\n {apiKey.id}.***************\n </Badge>\n </td>\n\n <td class=\"p-4 align-middle font-medium\">\n {#if apiKey.created}\n <span title={new Date(apiKey.created).toLocaleString()}>\n {timeAgo(apiKey.created)}\n </span>\n {/if}\n </td>\n\n <td class=\"p-4 align-middle font-medium\">\n {#if apiKey.last_used}\n <span title={new Date(apiKey.last_used).toLocaleString()}>\n {timeAgo(apiKey.last_used)}\n </span>\n {:else}\n Never\n {/if}\n </td>\n\n <td class=\"p-4 align-middle text-right\">\n <form method=\"POST\" action=\"/api-keys/{apiKey.id}?/delete\" class=\"contents\">\n <Button\n variant=\"ghost\"\n class=\"h-8 px-2 text-destructive hover:text-destructive\"\n type=\"submit\">Delete</Button\n >\n </form>\n </td>\n </tr>\n {/each}\n </tbody>\n </table>\n {/if}\n </div>\n </div>\n</section>\n\n{@render children?.()}\n", Ns = "import { definePageMetaTags } from 'svelte-meta-tags';\n\nexport const load = async ({ parent }) => {\n await parent();\n\n const { pageMetaTags } = definePageMetaTags({\n title: 'API keys'\n });\n\n return { pageMetaTags };\n};\n", Ps = "import { redirect } from \"@sveltejs/kit\";\n\nexport const actions = {\n delete: async ({ locals, params }) => {\n await locals.pb.collection(\"api_keys\").delete(params.id);\n redirect(303, \"/api-keys\");\n },\n};\n", Fs = "import { fail, superValidate } from \"sveltekit-superforms\";\nimport { zod4 } from \"sveltekit-superforms/adapters\";\nimport { redirect } from \"sveltekit-flash-message/server\";\nimport { apiKeySchema } from \"$lib/schemas/apiKey\";\nimport { setPocketbaseErrors } from \"@velastack/pocketbase\";\nimport { createApiKey } from \"./create-api-key\";\n\nexport const load = async () => {\n return { form: await superValidate(zod4(apiKeySchema)) };\n};\n\nexport const actions = {\n default: async ({ locals, request, cookies }) => {\n const form = await superValidate(request, zod4(apiKeySchema));\n\n if (!form.valid) {\n return fail(400, { form });\n }\n\n let apiKey: string;\n\n try {\n apiKey = await createApiKey(\n locals.pb,\n locals.pb.authStore.record?.id,\n form.data.label,\n );\n } catch (error) {\n setPocketbaseErrors(form, error);\n return fail(400, { form });\n }\n\n return redirect(\n \"/api-keys\",\n {\n type: \"success\",\n title: \"You've created a new API key\",\n message: `Copy the following API key in a safe location. It will only be shown once.`,\n apiKey,\n },\n cookies,\n );\n },\n};\n", Is = "<script lang=\"ts\">\n import { untrack } from 'svelte';\n import { superForm } from 'sveltekit-superforms';\n import { zod4Client } from 'sveltekit-superforms/adapters';\n import { apiKeySchema } from '$lib/schemas/apiKey';\n import * as Form from '$lib/components/ui/form';\n import { Input } from '$lib/components/ui/input';\n import { Button } from '$lib/components/ui/button';\n import * as Dialog from '$lib/components/ui/dialog';\n import { goto } from '$app/navigation';\n\n let { data } = $props();\n\n const form = superForm(\n untrack(() => data.form),\n {\n validators: zod4Client(apiKeySchema)\n }\n );\n\n const { form: formData } = form;\n\n function onOpenChange(open: boolean) {\n if (!open) {\n form.reset();\n goto('/api-keys');\n }\n }\n<\/script>\n\n<Dialog.Root open={true} {onOpenChange}>\n <Dialog.Content>\n <form method=\"POST\">\n <div class=\"grid grid-cols-1 gap-4\">\n <Form.Field {form} name=\"label\" class=\"col-span-1\">\n <Form.Control>\n {#snippet children({ props })}\n <Form.Label>API key label</Form.Label>\n <Input {...props} type=\"text\" bind:value={$formData.label} autofocus />\n {/snippet}\n </Form.Control>\n <Form.FieldErrors class=\"contents text-destructive\" />\n </Form.Field>\n </div>\n\n <div class=\"mt-4 flex gap-2 border-t pt-4 -mx-4 px-4\">\n <Form.Button>Save</Form.Button>\n <Button href=\"/api-keys\" variant=\"outline\">Cancel</Button>\n </div>\n </form>\n </Dialog.Content>\n</Dialog.Root>\n", Ls = "import { definePageMetaTags } from 'svelte-meta-tags';\n\nexport const load = async ({ parent, data }) => {\n await parent();\n\n const { pageMetaTags } = definePageMetaTags({\n title: 'New API key'\n });\n\n return { ...data, pageMetaTags };\n};\n", Rs = "import PocketBase from \"pocketbase-sveltekit\";\nimport argon2 from \"argon2\";\nimport { randomBytes } from \"node:crypto\";\n\nexport const createApiKey = async (\n pb: PocketBase,\n userId: string | undefined,\n label: string,\n) => {\n const keySecret = randomBytes(10).toString(\"hex\");\n const keyHash = await argon2.hash(keySecret, { type: argon2.argon2id });\n const apiKey = await pb\n .collection(\"api_keys\")\n .create({ key_hash: keyHash, user: userId, label });\n\n return `${apiKey.id}.${keySecret}`;\n};\n", zs = "import { describe, it, expect, beforeEach } from \"vitest\";\nimport type { Match } from \"@velastack/pocketbase\";\nimport { createApiKey } from \"./create-api-key\";\nimport type { RouteId } from \"./$types\";\n\ndescribe(\"GET /api-keys/new\", () => {\n beforeEach(async (context) => {\n await context.agent.authenticateUser();\n });\n\n it(\"should return a 200 status code\", async (context) => {\n const response = await context.agent.get(\n \"/api-keys/new\" satisfies Match<RouteId>,\n );\n expect(response.status).toBe(200);\n });\n});\n\ndescribe(\"POST /api-keys/new\", () => {\n beforeEach(async (context) => {\n await context.agent.authenticateUser();\n });\n\n it(\"should create a new API key\", async (context) => {\n const response = await context.agent\n .post(\"/api-keys/new\")\n .type(\"form\")\n .send({ label: \"Test API Key\" });\n expect(response.body.status).toBe(303);\n expect(response.body.location).toBe(\"/api-keys\");\n });\n});\n\ndescribe(\"api keys authenticate as a user\", () => {\n it(\"should create a new api key\", async (context) => {\n const apiKey = await createApiKey(\n context.pb,\n context.user.id,\n \"Test API Key\",\n );\n expect(apiKey).toBeDefined();\n });\n\n it(\"should throw an error when creating for a non-existent user\", async (context) => {\n await expect(async () => {\n await createApiKey(context.pb, \"non-existent-user-id\", \"Test API Key\");\n }).rejects.toThrow();\n });\n\n it(\"should give access to the api\", async (context) => {\n const response = await context.request.get(\n `/api/collections/users/records/${context.user.id}`,\n );\n expect(response.status).toBe(404);\n\n const apiKey = await createApiKey(\n context.pb,\n context.user.id,\n \"Test API Key\",\n );\n const response2 = await context.request\n .get(`/api/collections/users/records/${context.user.id}`)\n .set(\"Authorization\", `Bearer ${apiKey}`);\n expect(response2.status).toBe(200);\n });\n});\n", Bs = "import { describe, it, expect, beforeEach } from \"vitest\";\nimport type { Match } from \"@velastack/pocketbase\";\nimport type { RouteId } from \"./$types\";\n\ndescribe(\"GET /api-keys\", () => {\n beforeEach(async (context) => {\n await context.agent.authenticateUser();\n });\n\n it(\"should return a 200 status code\", async (context) => {\n const response = await context.agent.get(\n \"/api-keys\" satisfies Match<RouteId>,\n );\n expect(response.status).toBe(200);\n });\n});\n", Vs = /* #__PURE__ */ Object.assign({
|
|
4403
|
+
}, As = "import { z } from \"zod\";\nimport type { Schemas } from \"@velastack/pocketbase\";\n\nexport const apiKeySchema = z.object({\n label: z.string(),\n}) satisfies Schemas[\"api_keys\"];\n", js = "export const load = async ({ locals }) => {\n const apiKeys = await locals.pb.collection('api_keys').getFullList();\n return { apiKeys };\n};\n", Ms = "<script lang=\"ts\">\n import { getFlash } from 'sveltekit-flash-message';\n import { page } from '$app/state';\n import { toast } from 'svelte-sonner';\n import * as AlertDialog from '$lib/components/ui/alert-dialog';\n import { Button } from '$lib/components/ui/button';\n import { Badge } from '$lib/components/ui/badge';\n import { timeAgo } from '$lib/utils';\n import PlusIcon from '@lucide/svelte/icons/plus';\n import SquareDashedMousePointerIcon from '@lucide/svelte/icons/square-dashed-mouse-pointer';\n\n const flash = getFlash(page);\n\n let open = $state(false);\n let message = $state('');\n let title = $state('');\n let apiKey = $state('');\n\n $effect(() => {\n if (!$flash) return;\n\n if ($flash.type === 'success') {\n message = $flash.message;\n title = $flash.title;\n apiKey = $flash.apiKey;\n open = true;\n }\n\n $flash = undefined;\n });\n\n async function handleAction() {\n open = false;\n await navigator.clipboard.writeText(apiKey);\n toast.success('API key copied to clipboard');\n }\n\n let { data, children } = $props();\n<\/script>\n\n<section data-role=\"content\">\n <div class=\"flex justify-between items-center mb-4\">\n <h1 class=\"text-3xl font-bold tracking-tight\">API keys</h1>\n <Button href=\"/api-keys/new\" variant=\"outline\">\n <PlusIcon class=\"w-4 h-4\" />\n New API key\n </Button>\n </div>\n\n <AlertDialog.Root bind:open>\n <AlertDialog.Content class=\"max-w-120!\">\n <AlertDialog.Header>\n <AlertDialog.Title>{title}</AlertDialog.Title>\n <AlertDialog.Description class=\"text-wrap\">\n <p>{@html message}</p>\n <Badge variant=\"outline\" class=\"font-mono my-3 text-base\">{apiKey}</Badge>\n </AlertDialog.Description>\n </AlertDialog.Header>\n <AlertDialog.Footer>\n <AlertDialog.Cancel>Close</AlertDialog.Cancel>\n <AlertDialog.Action onclick={handleAction}>Copy</AlertDialog.Action>\n </AlertDialog.Footer>\n </AlertDialog.Content>\n </AlertDialog.Root>\n\n <div class=\"rounded-lg border bg-card overflow-hidden\">\n <div class=\"relative w-full overflow-auto\">\n {#if data.apiKeys.length === 0}\n <div class=\"p-4 text-center text-muted-foreground space-y-4 py-12\">\n <SquareDashedMousePointerIcon strokeWidth={1.2} class=\"w-8 h-8 mx-auto mb-2\" />\n <p>Seems like there are no API keys yet, but you can create the first one</p>\n <p class=\"text-sm text-muted-foreground\">\n <Button href=\"/api-keys/new\" variant=\"outline\">\n <PlusIcon class=\"w-4 h-4\" />\n New API key\n </Button>\n </p>\n </div>\n {:else}\n <table class=\"w-full caption-bottom text-sm\">\n <thead>\n <tr class=\"border-b\">\n <th class=\"h-12 px-4 text-left align-middle font-medium text-muted-foreground\"\n >Label</th\n >\n <th class=\"h-12 px-4 text-left align-middle font-medium text-muted-foreground\"\n >API key</th\n >\n <th class=\"h-12 px-4 text-left align-middle font-medium text-muted-foreground\"\n >Created</th\n >\n <th class=\"h-12 px-4 text-left align-middle font-medium text-muted-foreground\"\n >Last used</th\n >\n <th class=\"h-12 px-4 text-right align-middle font-medium text-muted-foreground\"></th>\n </tr>\n </thead>\n <tbody>\n {#each data.apiKeys as apiKey}\n <tr\n class=\"border-t transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted\"\n >\n <td class=\"p-4 align-middle font-medium\">{apiKey.label}</td>\n\n <td class=\"p-4 align-middle font-medium\">\n <Badge variant=\"outline\" class=\"font-mono\">\n {apiKey.id}.***************\n </Badge>\n </td>\n\n <td class=\"p-4 align-middle font-medium\">\n {#if apiKey.created}\n <span title={new Date(apiKey.created).toLocaleString()}>\n {timeAgo(apiKey.created)}\n </span>\n {/if}\n </td>\n\n <td class=\"p-4 align-middle font-medium\">\n {#if apiKey.last_used}\n <span title={new Date(apiKey.last_used).toLocaleString()}>\n {timeAgo(apiKey.last_used)}\n </span>\n {:else}\n Never\n {/if}\n </td>\n\n <td class=\"p-4 align-middle text-right\">\n <form method=\"POST\" action=\"/api-keys/{apiKey.id}?/delete\" class=\"contents\">\n <Button\n variant=\"ghost\"\n class=\"h-8 px-2 text-destructive hover:text-destructive\"\n type=\"submit\">Delete</Button\n >\n </form>\n </td>\n </tr>\n {/each}\n </tbody>\n </table>\n {/if}\n </div>\n </div>\n</section>\n\n{@render children?.()}\n", Ns = "import { definePageMetaTags } from 'svelte-meta-tags';\n\nexport const load = async ({ parent }) => {\n await parent();\n\n const { pageMetaTags } = definePageMetaTags({\n title: 'API keys'\n });\n\n return { pageMetaTags };\n};\n", Ps = "import { redirect } from \"@sveltejs/kit\";\n\nexport const actions = {\n delete: async ({ locals, params }) => {\n await locals.pb.collection(\"api_keys\").delete(params.id);\n redirect(303, \"/api-keys\");\n },\n};\n", Fs = "import { fail, superValidate } from \"sveltekit-superforms\";\nimport { zod4 } from \"sveltekit-superforms/adapters\";\nimport { redirect } from \"sveltekit-flash-message/server\";\nimport { apiKeySchema } from \"$lib/schemas/apiKey\";\nimport { setPocketbaseErrors } from \"@velastack/pocketbase\";\nimport { createApiKey } from \"./create-api-key\";\n\nexport const load = async () => {\n return { form: await superValidate(zod4(apiKeySchema)) };\n};\n\nexport const actions = {\n default: async ({ locals, request, cookies }) => {\n const form = await superValidate(request, zod4(apiKeySchema));\n\n if (!form.valid) {\n return fail(400, { form });\n }\n\n let apiKey: string;\n\n try {\n apiKey = await createApiKey(\n locals.pb,\n locals.pb.authStore.record?.id,\n form.data.label,\n );\n } catch (error) {\n setPocketbaseErrors(form, error);\n return fail(400, { form });\n }\n\n return redirect(\n \"/api-keys\",\n {\n type: \"success\",\n title: \"You've created a new API key\",\n message: `Copy the following API key in a safe location. It will only be shown once.`,\n apiKey,\n },\n cookies,\n );\n },\n};\n", Is = "<script lang=\"ts\">\n import { untrack } from 'svelte';\n import { superForm } from 'sveltekit-superforms';\n import { zod4Client } from 'sveltekit-superforms/adapters';\n import { apiKeySchema } from '$lib/schemas/apiKey';\n import * as Form from '$lib/components/ui/form';\n import { Input } from '$lib/components/ui/input';\n import { Button } from '$lib/components/ui/button';\n import * as Dialog from '$lib/components/ui/dialog';\n import { goto } from '$app/navigation';\n\n let { data } = $props();\n\n const form = superForm(\n untrack(() => data.form),\n {\n validators: zod4Client(apiKeySchema)\n }\n );\n\n const { form: formData } = form;\n\n function onOpenChange(open: boolean) {\n if (!open) {\n form.reset();\n goto('/api-keys');\n }\n }\n<\/script>\n\n<Dialog.Root open={true} {onOpenChange}>\n <Dialog.Content>\n <form method=\"POST\">\n <div class=\"grid grid-cols-1 gap-4\">\n <Form.Field {form} name=\"label\" class=\"col-span-1\">\n <Form.Control>\n {#snippet children({ props })}\n <Form.Label>API key label</Form.Label>\n <Input {...props} type=\"text\" bind:value={$formData.label} autofocus />\n {/snippet}\n </Form.Control>\n <Form.FieldErrors class=\"contents text-destructive\" />\n </Form.Field>\n </div>\n\n <div class=\"mt-4 flex gap-2 border-t pt-4 -mx-4 px-4\">\n <Form.Button>Save</Form.Button>\n <Button href=\"/api-keys\" variant=\"outline\">Cancel</Button>\n </div>\n </form>\n </Dialog.Content>\n</Dialog.Root>\n", Ls = "import { definePageMetaTags } from 'svelte-meta-tags';\n\nexport const load = async ({ parent, data }) => {\n await parent();\n\n const { pageMetaTags } = definePageMetaTags({\n title: 'New API key'\n });\n\n return { ...data, pageMetaTags };\n};\n", Rs = "import PocketBase from \"pocketbase-sveltekit\";\nimport { generateApiKeySecret, hashApiKey } from \"@velastack/pocketbase\";\n\nexport const createApiKey = async (\n pb: PocketBase,\n userId: string | undefined,\n label: string,\n) => {\n const keySecret = generateApiKeySecret();\n const apiKey = await pb\n .collection(\"api_keys\")\n .create({ key_hash: hashApiKey(keySecret), user: userId, label });\n\n return `${apiKey.id}.${keySecret}`;\n};\n", zs = "import { describe, it, expect, beforeEach } from \"vitest\";\nimport type { Match } from \"@velastack/pocketbase\";\nimport { createApiKey } from \"./create-api-key\";\nimport type { RouteId } from \"./$types\";\n\ndescribe(\"GET /api-keys/new\", () => {\n beforeEach(async (context) => {\n await context.agent.authenticateUser();\n });\n\n it(\"should return a 200 status code\", async (context) => {\n const response = await context.agent.get(\n \"/api-keys/new\" satisfies Match<RouteId>,\n );\n expect(response.status).toBe(200);\n });\n});\n\ndescribe(\"POST /api-keys/new\", () => {\n beforeEach(async (context) => {\n await context.agent.authenticateUser();\n });\n\n it(\"should create a new API key\", async (context) => {\n const response = await context.agent\n .post(\"/api-keys/new\")\n .type(\"form\")\n .send({ label: \"Test API Key\" });\n expect(response.body.status).toBe(303);\n expect(response.body.location).toBe(\"/api-keys\");\n });\n});\n\ndescribe(\"api keys authenticate as a user\", () => {\n it(\"should create a new api key\", async (context) => {\n const apiKey = await createApiKey(\n context.pb,\n context.user.id,\n \"Test API Key\",\n );\n expect(apiKey).toBeDefined();\n });\n\n it(\"should throw an error when creating for a non-existent user\", async (context) => {\n await expect(async () => {\n await createApiKey(context.pb, \"non-existent-user-id\", \"Test API Key\");\n }).rejects.toThrow();\n });\n\n it(\"should give access to the api\", async (context) => {\n const response = await context.request.get(\n `/api/collections/users/records/${context.user.id}`,\n );\n expect(response.status).toBe(404);\n\n const apiKey = await createApiKey(\n context.pb,\n context.user.id,\n \"Test API Key\",\n );\n const response2 = await context.request\n .get(`/api/collections/users/records/${context.user.id}`)\n .set(\"Authorization\", `Bearer ${apiKey}`);\n expect(response2.status).toBe(200);\n });\n});\n", Bs = "import { describe, it, expect, beforeEach } from \"vitest\";\nimport type { Match } from \"@velastack/pocketbase\";\nimport type { RouteId } from \"./$types\";\n\ndescribe(\"GET /api-keys\", () => {\n beforeEach(async (context) => {\n await context.agent.authenticateUser();\n });\n\n it(\"should return a 200 status code\", async (context) => {\n const response = await context.agent.get(\n \"/api-keys\" satisfies Match<RouteId>,\n );\n expect(response.status).toBe(200);\n });\n});\n", Vs = /* #__PURE__ */ Object.assign({
|
|
4404
4404
|
"./creates/src/lib/schemas/apiKey.ts": As,
|
|
4405
4405
|
"./creates/src/routes/(app)/api-keys/+layout.server.ts": js,
|
|
4406
4406
|
"./creates/src/routes/(app)/api-keys/+layout.svelte": Ms,
|
|
@@ -4473,7 +4473,7 @@ async function Ws(e) {
|
|
|
4473
4473
|
"button",
|
|
4474
4474
|
"badge"
|
|
4475
4475
|
],
|
|
4476
|
-
packages: ["
|
|
4476
|
+
packages: ["@types/node"],
|
|
4477
4477
|
collections: [Us],
|
|
4478
4478
|
collectionPatches: [],
|
|
4479
4479
|
collectionDrops: []
|
|
@@ -4901,7 +4901,7 @@ var vl = {
|
|
|
4901
4901
|
tests: 0,
|
|
4902
4902
|
baseline: "velastack",
|
|
4903
4903
|
generate: _l
|
|
4904
|
-
}, yl = "import { deLocalizeDefault } from \"wuchale/url\";\nimport { matchUrl } from \"$locales/main.url\";\nimport { locales } from \"$locales/data\";\n\nconst rerouteDeLocalize = (url: string) => {\n const [upath, locale] = deLocalizeDefault(url, locales);\n const { path } = matchUrl(upath, locale);\n return path ?? url;\n};\n\nexport const reroute = ({ url }) => rerouteDeLocalize(url.pathname);\n", bl = "<script lang=\"ts\">\n import * as Select from \"$lib/components/ui/select/index.js\";\n import { locales, type Locale } from \"$locales/data.js\";\n import { page } from \"$app/state\";\n import { goto } from \"$app/navigation\";\n import { deLocalizeDefault } from \"wuchale/url\";\n import { defaultLocale, translateUrl } from \"$lib/url\";\n\n let locale: Locale = $derived.by(() => {\n const [_, locale] = deLocalizeDefault(page.url.pathname, locales);\n return locale ?? defaultLocale;\n });\n\n function localeDisplayName(code: Locale): string {\n const names = new Intl.DisplayNames([code], { type: \"language\" });\n const raw = names.of(code);\n if (!raw) return code;\n return raw.charAt(0).toLocaleUpperCase(code) + raw.slice(1);\n }\n\n const localeNames: Record<string, string> = locales.reduce(\n (acc, loc) => {\n acc[loc] = localeDisplayName(loc);\n return acc;\n },\n {} as Record<string, string>,\n );\n\n const handleValueChange = (value: string) => {\n const translatedUrl = translateUrl(\n page.url.pathname,\n locale,\n value as Locale,\n );\n goto(translatedUrl, { invalidateAll: true });\n };\n\n let { class: className }: { class?: string } = $props();\n<\/script>\n\n<Select.Root type=\"single\" value={locale} onValueChange={handleValueChange}>\n <Select.Trigger class={className}>{localeNames[locale]}</Select.Trigger>\n <Select.Content>\n {#each locales as locale}\n <Select.Item value={locale}>{localeNames[locale]}</Select.Item>\n {/each}\n </Select.Content>\n</Select.Root>\n", xl = "import { deLocalizeDefault,
|
|
4904
|
+
}, yl = "import { deLocalizeDefault } from \"wuchale/url\";\nimport { matchUrl } from \"$locales/main.url\";\nimport { locales } from \"$locales/data\";\n\nconst rerouteDeLocalize = (url: string) => {\n const [upath, locale] = deLocalizeDefault(url, locales);\n const { path } = matchUrl(upath, locale);\n return path ?? url;\n};\n\nexport const reroute = ({ url }) => rerouteDeLocalize(url.pathname);\n", bl = "<script lang=\"ts\">\n import * as Select from \"$lib/components/ui/select/index.js\";\n import { locales, type Locale } from \"$locales/data.js\";\n import { page } from \"$app/state\";\n import { goto } from \"$app/navigation\";\n import { deLocalizeDefault } from \"wuchale/url\";\n import { defaultLocale, translateUrl } from \"$lib/url\";\n\n let locale: Locale = $derived.by(() => {\n const [_, locale] = deLocalizeDefault(page.url.pathname, locales);\n return locale ?? defaultLocale;\n });\n\n function localeDisplayName(code: Locale): string {\n const names = new Intl.DisplayNames([code], { type: \"language\" });\n const raw = names.of(code);\n if (!raw) return code;\n return raw.charAt(0).toLocaleUpperCase(code) + raw.slice(1);\n }\n\n const localeNames: Record<string, string> = locales.reduce(\n (acc, loc) => {\n acc[loc] = localeDisplayName(loc);\n return acc;\n },\n {} as Record<string, string>,\n );\n\n const handleValueChange = (value: string) => {\n const translatedUrl = translateUrl(\n page.url.pathname,\n locale,\n value as Locale,\n );\n goto(translatedUrl, { invalidateAll: true });\n };\n\n let { class: className }: { class?: string } = $props();\n<\/script>\n\n<Select.Root type=\"single\" value={locale} onValueChange={handleValueChange}>\n <Select.Trigger class={className}>{localeNames[locale]}</Select.Trigger>\n <Select.Content>\n {#each locales as locale}\n <Select.Item value={locale}>{localeNames[locale]}</Select.Item>\n {/each}\n </Select.Content>\n</Select.Root>\n", xl = "import { deLocalizeDefault, stringifyPattern } from \"wuchale/url\";\nimport type { Locale } from \"../locales/data\";\nimport { matchUrl } from \"../locales/main.url\";\nimport { locales } from \"../locales/data\";\n\n// wuchale treats locales[0] as the source locale, so it is the one served unprefixed\nexport const defaultLocale: Locale = locales[0];\n\n/**\n * Localizer for wuchale's `url.localize` config. Compiled URLs in components\n * are passed through this, so the default locale stays unprefixed.\n */\nexport function localize(path: string, locale: Locale) {\n if (locale === defaultLocale) {\n return path;\n }\n\n // matches wuchale's localizeDefault, which drops the trailing slash\n const localized = `/${locale}${path}`;\n return localized.endsWith(\"/\") ? localized.slice(0, -1) : localized;\n}\n\nexport function translateUrl(\n url: string,\n fromLocale: Locale,\n toLocale: Locale,\n) {\n const [pathOnly] = deLocalizeDefault(url, locales);\n const result = matchUrl(pathOnly, fromLocale);\n if (result.path !== null) {\n const targetPath = stringifyPattern(\n result.altPatterns[toLocale],\n result.params,\n );\n return localize(targetPath, toLocale);\n }\n return localize(pathOnly, toLocale);\n}\n", Sl = "// @ts-check\nimport { adapter as svelte } from \"@wuchale/svelte\";\nimport { adapter as js } from \"wuchale/adapter-vanilla\";\nimport { defineConfig } from \"wuchale\";\n\nexport default defineConfig({\n locales: [\"en\", \"es\"],\n adapters: {\n main: svelte({\n loader: \"sveltekit\",\n url: { localize: \"src/lib/url.ts\", patterns: [\"/\"] },\n }),\n js: js({\n loader: \"vite\",\n files: [\n \"src/**/+{page,layout}.{js,ts}\",\n \"src/**/+{page,layout}.server.{js,ts}\",\n ],\n }),\n },\n});\n", Cl = /* #__PURE__ */ Object.assign({
|
|
4905
4905
|
"./creates/src/hooks.ts": yl,
|
|
4906
4906
|
"./creates/src/lib/components/language-select.svelte": bl,
|
|
4907
4907
|
"./creates/src/lib/url.ts": xl,
|
|
@@ -4931,7 +4931,7 @@ async function Tl(e) {
|
|
|
4931
4931
|
//#region src/patterns/enable/i18n/generate.preview.ts
|
|
4932
4932
|
var El = /* #__PURE__ */ Object.assign({
|
|
4933
4933
|
"./preview-modifies/src/app.html": "<!doctype html>\n<!-- [!code highlight:1] -->\n<html lang=\"%sveltekit.lang%\">\n <head>\n <meta charset=\"utf-8\" />\n </head>\n\n <body>\n <div style=\"display: contents\">%sveltekit.body%</div>\n </body>\n</html>\n",
|
|
4934
|
-
"./preview-modifies/src/hooks.server.ts": "import { env } from \"$env/dynamic/private\";\nimport { handlePocketbase } from \"@velastack/pocketbase\";\n// [!code highlight:6]\nimport { sequence } from \"@sveltejs/kit/hooks\";\nimport { runWithLocale, loadLocales } from \"wuchale/load-utils/server\";\nimport { getLocale } from \"$locales/main.url\";\nimport { locales } from \"$locales/data\";\nimport * as main from \"$locales/main.loader.server.svelte.js\";\nimport * as js from \"$locales/js.loader.server.js\";\n\n// [!code highlight:2]\nloadLocales(main.key, main.
|
|
4934
|
+
"./preview-modifies/src/hooks.server.ts": "import { env } from \"$env/dynamic/private\";\nimport { handlePocketbase } from \"@velastack/pocketbase\";\n// [!code highlight:6]\nimport { sequence } from \"@sveltejs/kit/hooks\";\nimport { runWithLocale, loadLocales } from \"wuchale/load-utils/server\";\nimport { getLocale } from \"$locales/main.url\";\nimport { locales } from \"$locales/data\";\nimport * as main from \"$locales/main.loader.server.svelte.js\";\nimport * as js from \"$locales/js.loader.server.js\";\n\n// [!code highlight:2]\nloadLocales(main.key, main.loadCount, main.loadCatalog, locales);\nloadLocales(js.key, js.loadCount, js.loadCatalog, locales);\n\n// [!code highlight:9]\nconst handleWuchale = async ({ event, resolve }: any) => {\n const locale = getLocale(event.url);\n return await runWithLocale(locale, () =>\n resolve(event, {\n transformPageChunk: ({ html }: { html: string }) =>\n html.replace(\"%sveltekit.lang%\", locale),\n }),\n );\n};\n\nexport const handle = sequence(\n // [!code highlight:1]\n handleWuchale,\n handlePocketbase({\n pocketbaseUrl: env.POCKETBASE_URL,\n superuserEmail: env.POCKETBASE_SUPERUSER_EMAIL,\n superuserPassword: env.POCKETBASE_SUPERUSER_PASSWORD,\n }),\n);\n",
|
|
4935
4935
|
"./preview-modifies/src/routes/(public)/root-layout.svelte": "<script lang=\"ts\">\n import { toggleMode } from 'mode-watcher';\n import * as Navbar from '$lib/components/ui/navbar';\n import { Button } from '$lib/components/ui/button';\n // [!code highlight]\n import LanguageSelect from '$lib/components/language-select.svelte';\n\n let { children, data } = $props();\n<\/script>\n\n<div class=\"min-h-dvh grid grid-rows-[max-content_1fr_max-content] root-layout\">\n <Navbar.Root>\n <Navbar.Brand href=\"/\">\n <Navbar.Logo src=\"/favicon.svg\" alt=\"Logo\" />\n </Navbar.Brand>\n\n <Navbar.MobileToggle />\n\n <Navbar.List>\n <Navbar.Item>\n <Button class=\"w-full justify-start md:justify-center md:w-auto\" href=\"/\" variant=\"ghost\">\n Home\n </Button>\n </Navbar.Item>\n <!-- [!code highlight:3] -->\n <Navbar.Item>\n <LanguageSelect />\n </Navbar.Item>\n </Navbar.List>\n </Navbar.Root>\n\n {@render children?.()}\n\n <footer class=\"border-t border-border py-4\">\n <div\n class=\"mx-auto flex max-w-7xl px-4 flex-col items-center justify-between gap-3 sm:flex-row\"\n >\n <p class=\"text-muted-foreground text-sm\">\n © {new Date().getFullYear()}\n {data.meta.appName}. All rights reserved.\n </p>\n <nav class=\"flex items-center gap-4 text-sm\">\n <Button onclick={toggleMode} variant=\"ghost\" size=\"icon\">\n <Navbar.Mode />\n </Button>\n <a href=\"/privacy\" class=\"underline-offset-4 hover:underline\">Privacy</a>\n <a href=\"/terms\" class=\"underline-offset-4 hover:underline\">Terms</a>\n </nav>\n </div>\n </footer>\n</div>\n\n<style lang=\"postcss\">\n @reference \"tailwindcss\";\n\n .root-layout :global(section[data-role='content']) {\n @apply container mx-auto max-w-7xl px-4 py-8 w-full;\n }\n</style>\n",
|
|
4936
4936
|
"./preview-modifies/src/routes/+layout.ts": "import { browser } from \"$app/environment\";\n// [!code highlight:4]\nimport { loadLocale } from \"wuchale/load-utils\";\nimport { getLocale } from \"$locales/main.url\";\nimport \"$locales/main.loader.svelte\";\nimport \"$locales/js.loader\";\n\nexport const load = async ({ url, data }) => {\n // [!code highlight:5]\n const locale = getLocale(url);\n\n if (browser) {\n await loadLocale(locale);\n }\n\n return data;\n};\n",
|
|
4937
4937
|
"./preview-modifies/svelte.config.js": "import adapter from \"@sveltejs/adapter-auto\";\nimport { vitePreprocess } from \"@sveltejs/vite-plugin-svelte\";\n\nconst config = {\n preprocess: vitePreprocess(),\n kit: {\n adapter,\n // [!code highlight:3]\n alias: {\n $locales: \"src/locales\",\n },\n },\n};\n\nexport default config;\n",
|
|
@@ -4959,14 +4959,14 @@ async function Ol(e) {
|
|
|
4959
4959
|
}
|
|
4960
4960
|
//#endregion
|
|
4961
4961
|
//#region src/patterns/enable/i18n/index.ts
|
|
4962
|
-
var kl = "enable-i18n", Al = "1.0.
|
|
4962
|
+
var kl = "enable-i18n", Al = "1.0.1", jl = "src/patterns/enable/i18n", Ml = "/enable/i18n";
|
|
4963
4963
|
async function Nl(e) {
|
|
4964
4964
|
let t = await Tl(e);
|
|
4965
4965
|
if (e.env === "preview") {
|
|
4966
4966
|
let r = await Ol(e);
|
|
4967
4967
|
return y(n([t, r]));
|
|
4968
4968
|
}
|
|
4969
|
-
let { generate: r } = await import("./chunks/generate.runtime-
|
|
4969
|
+
let { generate: r } = await import("./chunks/generate.runtime-rfNiROHo.js"), i = await r(e), { writeResult: a } = await import("./chunks/write-result-DtTqt0Cs.js");
|
|
4970
4970
|
return a(await y(n([t, i])), e);
|
|
4971
4971
|
}
|
|
4972
4972
|
var Pl = {
|