@xanots/sdk 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (106) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +384 -0
  3. package/dist/agent-file-refresh-7XCACU34.js +95 -0
  4. package/dist/bin.d.ts +1 -0
  5. package/dist/bin.js +184 -0
  6. package/dist/capture-HUV5BNTC.js +32 -0
  7. package/dist/chunk-26CNBZE2.js +963 -0
  8. package/dist/chunk-33ND6LKO.js +78 -0
  9. package/dist/chunk-3DUAGYGP.js +1550 -0
  10. package/dist/chunk-3IGNIP6R.js +89 -0
  11. package/dist/chunk-47WDWMBJ.js +14 -0
  12. package/dist/chunk-4BXJGVZ3.js +318 -0
  13. package/dist/chunk-4HT3BNZ7.js +675 -0
  14. package/dist/chunk-4YMD2OOZ.js +23 -0
  15. package/dist/chunk-5WGEURVI.js +156 -0
  16. package/dist/chunk-5YTBTF25.js +29 -0
  17. package/dist/chunk-6DHBYBTO.js +166 -0
  18. package/dist/chunk-76QBEIGO.js +66 -0
  19. package/dist/chunk-7DKX2SPN.js +100 -0
  20. package/dist/chunk-7REDODS2.js +468 -0
  21. package/dist/chunk-C56BC2FY.js +254 -0
  22. package/dist/chunk-DGSF2Q5H.js +60 -0
  23. package/dist/chunk-EMCAWMHC.js +3982 -0
  24. package/dist/chunk-EZG76F7R.js +159 -0
  25. package/dist/chunk-FJ6ZS5KB.js +3607 -0
  26. package/dist/chunk-GNPVYOPB.js +17 -0
  27. package/dist/chunk-HJPTWBLH.js +38 -0
  28. package/dist/chunk-IZW6MK3U.js +248 -0
  29. package/dist/chunk-LH6Z6KFV.js +247 -0
  30. package/dist/chunk-MZUI3JNX.js +93 -0
  31. package/dist/chunk-NDZFBZHC.js +167 -0
  32. package/dist/chunk-NOO35BQ2.js +37 -0
  33. package/dist/chunk-NUQCEOKA.js +13 -0
  34. package/dist/chunk-QTNO2WD6.js +56 -0
  35. package/dist/chunk-RVB7ITKN.js +49 -0
  36. package/dist/chunk-TRU5OHQ5.js +6904 -0
  37. package/dist/chunk-VKFQJEMW.js +814 -0
  38. package/dist/chunk-VTIL47DT.js +125 -0
  39. package/dist/chunk-WHOJWOSV.js +112 -0
  40. package/dist/chunk-WKP4D5MO.js +1692 -0
  41. package/dist/chunk-X4DVXBFY.js +38 -0
  42. package/dist/chunk-XQ22GLYS.js +118 -0
  43. package/dist/chunk-YDZYMZBE.js +670 -0
  44. package/dist/chunk-YGPIY3WT.js +1146 -0
  45. package/dist/chunk-YYRDLFSJ.js +602 -0
  46. package/dist/chunk-ZUTSMMAG.js +46 -0
  47. package/dist/cli.d.ts +331 -0
  48. package/dist/cli.js +33 -0
  49. package/dist/codegen-command-OOKK6AZK.js +40 -0
  50. package/dist/codegen.d.ts +114 -0
  51. package/dist/codegen.js +71 -0
  52. package/dist/completion-TIPPZN7H.js +298 -0
  53. package/dist/config-NL33PN4D.js +84 -0
  54. package/dist/deploy-command-4EQ7XX5G.js +451 -0
  55. package/dist/env-target-IFJ5QDHC.js +16 -0
  56. package/dist/ephemeral-command-3X3I4ULC.js +242 -0
  57. package/dist/index.d.ts +4477 -0
  58. package/dist/index.js +300 -0
  59. package/dist/init-command-R6H7ZXW5.js +27 -0
  60. package/dist/internal.d.ts +74 -0
  61. package/dist/internal.js +2065 -0
  62. package/dist/io-AMIKRLPC.js +11 -0
  63. package/dist/live-diff-Y3AKETHE.js +196 -0
  64. package/dist/lock-3CVKALKT.js +37 -0
  65. package/dist/lock-commands-XTR2YKLY.js +232 -0
  66. package/dist/login-command-ACJF6KWQ.js +167 -0
  67. package/dist/logout-command-MX3MJS5U.js +68 -0
  68. package/dist/loop-OM3P2Z6O.js +93 -0
  69. package/dist/marketplace-command-RATXTKXN.js +379 -0
  70. package/dist/meta-client-OW5WKWW7.js +170 -0
  71. package/dist/node.d.ts +59 -0
  72. package/dist/node.js +442 -0
  73. package/dist/profile-command-SWJ3SPKR.js +77 -0
  74. package/dist/release-command-VV5UVZKL.js +427 -0
  75. package/dist/response-CVAE2kMj.d.ts +1915 -0
  76. package/dist/routes-manifest-SP3ZXLMR.js +244 -0
  77. package/dist/runtime-V4C3AC3A.js +13 -0
  78. package/dist/sandbox-details-command-HJE5SPVG.js +18 -0
  79. package/dist/sandbox-export-command-QCJY4GMV.js +24 -0
  80. package/dist/static-host-D6KS7X45.js +138 -0
  81. package/dist/store-BQ97nKIF.d.ts +7760 -0
  82. package/dist/test-command-TSPBQHBM.js +383 -0
  83. package/dist/validate-command-4ERHJSCO.js +122 -0
  84. package/dist/verify-rollout-FAVQ6EJY.js +40 -0
  85. package/dist/workspace-K72NP7SX.js +49 -0
  86. package/dist/workspace-command-OF23DPNI.js +156 -0
  87. package/dist/workspace-export-AJMGN3CQ.js +10 -0
  88. package/llms/fields.md +104 -0
  89. package/llms/filters.md +183 -0
  90. package/llms/kinds-agent-mcp.md +11 -0
  91. package/llms/kinds-core.md +68 -0
  92. package/llms/kinds-realtime.md +76 -0
  93. package/llms/lambda.md +111 -0
  94. package/llms/legacy.md +43 -0
  95. package/llms/object-kinds.md +31 -0
  96. package/llms/statements-calls.md +23 -0
  97. package/llms/statements-catalog.md +309 -0
  98. package/llms/statements-data.md +58 -0
  99. package/llms/statements-runtime.md +48 -0
  100. package/llms/tests.md +58 -0
  101. package/llms/triggers.md +22 -0
  102. package/llms/values.md +29 -0
  103. package/llms-full.txt +1672 -0
  104. package/llms.txt +483 -0
  105. package/manifest.json +9592 -0
  106. package/package.json +110 -0
@@ -0,0 +1,1692 @@
1
+ import {
2
+ presetFilePath,
3
+ reactPreset,
4
+ resolveAiPresets,
5
+ scaffoldProject
6
+ } from "./chunk-VKFQJEMW.js";
7
+ import {
8
+ readVersion
9
+ } from "./chunk-YGPIY3WT.js";
10
+ import {
11
+ blank,
12
+ detail,
13
+ info,
14
+ step,
15
+ style,
16
+ success
17
+ } from "./chunk-EZG76F7R.js";
18
+
19
+ // src/emit/init-command.ts
20
+ import { basename, resolve } from "path";
21
+
22
+ // src/emit/init-templates.ts
23
+ function sdkDep(sdkVersion) {
24
+ const parsed = /^(\d+)\.(\d+)\.\d+/.exec(sdkVersion);
25
+ if (!parsed) return ">=0.0.1 <0.1.0";
26
+ const [major, minor] = [Number(parsed[1]), Number(parsed[2])];
27
+ const ceiling = major > 0 ? `${major + 1}.0.0` : `0.${minor + 1}.0`;
28
+ return `>=${sdkVersion} <${ceiling}`;
29
+ }
30
+ function renderPackageJson({ appName, sdkVersion }, preset) {
31
+ const check = preset.checkCmd;
32
+ const pkg = {
33
+ name: appName,
34
+ version: "0.1.0",
35
+ private: true,
36
+ type: "module",
37
+ scripts: {
38
+ dev: "vite",
39
+ build: `${check} && vite build`,
40
+ preview: "vite preview",
41
+ typecheck: check,
42
+ // Both are prefixed with a typecheck: the export pass validates what it
43
+ // can see in the encoded bundle, and TypeScript validates the rest. Only
44
+ // `build` used to run `tsc`, so anyone following the documented workflow
45
+ // shipped with the compiler's half of the checks never run.
46
+ // `--lock` on both: object identity derives from `(type, name)`, so
47
+ // without a lock a rename re-derives the guid and the engine does
48
+ // delete-and-recreate instead of rename-in-place. The lock has to be
49
+ // adopted BEFORE the identities matter — by the time a rename lands
50
+ // against data anyone cares about, the guids have already drifted and
51
+ // recovery is `xanots lock adopt`. The scaffold is the earliest possible
52
+ // moment, so it opts in from the first export (issue #26). Once the file
53
+ // exists every export uses it, flag or not.
54
+ "xano:export": `${check} && xanots export ./xano/index.ts --out workspace.json --lock`,
55
+ // Runs `build` rather than `check` directly: `--static ./frontend/dist`
56
+ // needs that directory to EXIST, and only `vite build` writes it. Pointing
57
+ // the flag at a directory the script never produced meant a fresh clone
58
+ // running the one documented command had no `dist` to ship (issue #241).
59
+ // `build` already prefixes the same typecheck, so this is one check, not
60
+ // two.
61
+ "xano:deploy": `npm run build && xanots deploy ./xano/index.ts --static ./frontend/dist --lock`,
62
+ // The CI guard: fails instead of changing xano.lock, so an uncommitted
63
+ // identity change is caught in review rather than on a deploy.
64
+ "xano:check": `${check} && xanots export ./xano/index.ts --out workspace.json --frozen-lock`,
65
+ // No compile step and no entry file: this runs what is DEPLOYED, so it
66
+ // pairs with `xano:deploy` rather than repeating its work. Exits 5 on a
67
+ // failing suite, which is what makes it usable as a CI gate.
68
+ "xano:test": "xanots test run-all",
69
+ // Framework-owned scripts, last so a preset can add to the set but the
70
+ // shared xano:* contract above stays the same in every scaffold.
71
+ ...preset.extraScripts
72
+ },
73
+ dependencies: {
74
+ // `@xanots/sdk` is the only XanoTS dependency a scaffold ships with.
75
+ // Add-ons (`@xanots/auth`, and the packages that follow it) are installed
76
+ // on demand — a project that never registers auth should not carry it,
77
+ // and an add-on's release cadence is its own, not the CLI's.
78
+ "@xanots/sdk": sdkDep(sdkVersion),
79
+ ...preset.dependencies
80
+ },
81
+ devDependencies: { ...preset.devDependencies },
82
+ // Not ">=20": Vite 8 and vite-plugin-svelte 7 both declare
83
+ // `^20.19 || >=22.12`, so 20.0–20.18 installs the toolchain and then fails
84
+ // to run it. Stating the real floor turns that into an install-time
85
+ // warning instead of a confusing crash.
86
+ engines: { node: ">=20.19" }
87
+ };
88
+ return JSON.stringify(pkg, null, 2) + "\n";
89
+ }
90
+ function renderTsconfig(preset) {
91
+ const aliasPaths = Object.keys(preset.tsconfigPaths).length > 0 ? { paths: { ...preset.tsconfigPaths } } : {};
92
+ const tsconfig = {
93
+ // Present only when the framework generates a config to build on — see
94
+ // FrontendPreset.tsconfigExtends. The `include` below is re-declared on
95
+ // top of it deliberately: an extended config's `include` is REPLACED, not
96
+ // merged, and dropping `xano` here would leave the backend unchecked while
97
+ // every command still exits 0.
98
+ ...preset.tsconfigExtends === void 0 ? {} : { extends: preset.tsconfigExtends },
99
+ compilerOptions: {
100
+ target: "ES2022",
101
+ lib: ["ES2022", "DOM", "DOM.Iterable"],
102
+ module: "ESNext",
103
+ moduleResolution: "bundler",
104
+ ...preset.tsconfigOptions,
105
+ strict: true,
106
+ noEmit: true,
107
+ esModuleInterop: true,
108
+ skipLibCheck: true,
109
+ resolveJsonModule: true,
110
+ isolatedModules: true,
111
+ types: ["node", "vite/client"],
112
+ ...aliasPaths
113
+ },
114
+ // Both halves of the project typecheck together: the XanoTS backend and
115
+ // the frontend that derives its types from the backend's defs. A preset
116
+ // that extends a generated config appends whatever that config listed —
117
+ // `include` is replaced, not merged, so anything it declared is otherwise
118
+ // silently dropped. See FrontendPreset.tsconfigInclude.
119
+ include: ["xano", "frontend/src", ...preset.tsconfigInclude ?? []]
120
+ };
121
+ return JSON.stringify(tsconfig, null, 2) + "\n";
122
+ }
123
+ function renderViteConfig(preset) {
124
+ const root = preset.viteRoot === void 0 ? "frontend" : preset.viteRoot;
125
+ const build = preset.viteBuild === void 0 ? { outDir: "dist", emptyOutDir: true } : preset.viteBuild;
126
+ const header = root === null ? `// Vite's root is the project root. The framework resolves its own file
127
+ // locations from the plugin config below \u2014 this file is the ONLY place that
128
+ // config lives \u2014 and routes the build through its adapter, which writes
129
+ // frontend/dist, the directory \`npm run xano:deploy\` ships as the frontend.` : `// Vite's root is the ${root}/ folder, so index.html and the app live there
130
+ // while the XanoTS backend sits in xano/ as a peer. The build lands in
131
+ // ${root}/dist, which \`npm run xano:deploy\` ships as the static frontend.`;
132
+ const rootBlock = root === null ? "" : ` root: ${JSON.stringify(root)},
133
+ // Vite resolves \`.env\` files against \`root\`, which is ${root}/ here \u2014 but
134
+ // \`.env.example\` sits at the project root, so that is where anyone will
135
+ // actually put their \`.env.local\`. Point envDir back at this file's own
136
+ // directory so VITE_XANO_HOST is picked up in dev.
137
+ envDir: fileURLToPath(new URL(".", import.meta.url)),
138
+ `;
139
+ const buildBlock = build === null ? "" : ` build: ${renderInlineObject(build)},
140
+ `;
141
+ const aliasBlock = preset.aliasName === null ? "" : ` resolve: {
142
+ alias: {
143
+ // The alias the UI kit writes its imports against. Resolved from this
144
+ // file rather than from Vite's root so it points at the right directory
145
+ // either way. Keep in sync with the \`paths\` entry in tsconfig.json.
146
+ "${preset.aliasName}": fileURLToPath(new URL("./${preset.aliasTarget}", import.meta.url)),
147
+ },
148
+ },
149
+ `;
150
+ const fileUrlImport = rootBlock === "" && aliasBlock === "" ? "" : `import { fileURLToPath } from "node:url";
151
+ `;
152
+ return `${fileUrlImport}import { defineConfig } from "vite";
153
+ ${preset.viteImports.join("\n")}
154
+
155
+ ${header}
156
+ export default defineConfig({
157
+ ${rootBlock}${buildBlock} plugins: [${preset.vitePlugins.join(", ")}],
158
+ ${aliasBlock} server: { host: "127.0.0.1", port: 5173 },
159
+ });
160
+ `;
161
+ }
162
+ function renderInlineObject(obj) {
163
+ const entries = Object.entries(obj).map(([k, v]) => `${k}: ${JSON.stringify(v)}`);
164
+ return entries.length === 0 ? "{}" : `{ ${entries.join(", ")} }`;
165
+ }
166
+ function renderIndexHtml({ appName }, preset) {
167
+ if (preset.entryScript === void 0) {
168
+ throw new Error(`The ${preset.id} preset owns its own HTML entry; renderIndexHtml does not apply.`);
169
+ }
170
+ return `<!doctype html>
171
+ <html lang="en">
172
+ <head>
173
+ <meta charset="UTF-8" />
174
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
175
+ <title>${appName}</title>
176
+ </head>
177
+ <body>
178
+ <div id="root"></div>
179
+ <script type="module" src="${preset.entryScript}"></script>
180
+ </body>
181
+ </html>
182
+ `;
183
+ }
184
+ function renderGitignore(preset) {
185
+ const framework = (preset?.gitignoreEntries ?? []).map((e) => `${e}
186
+ `).join("");
187
+ return `node_modules/
188
+ dist/
189
+ workspace.json
190
+ .xano/
191
+ .env
192
+ .env.local
193
+ *.local
194
+ ${framework}
195
+ # Not ignored, on purpose: xano/xano.lock pins object identity across renames
196
+ # and environments. Commit it.
197
+ `;
198
+ }
199
+ function renderEnvExample() {
200
+ return `# Point the frontend at a deployed Xano backend. Leave unset to run the UI
201
+ # with no backend. When you \`npm run xano:deploy\`, the backend URL is injected
202
+ # as window.XANO_HOST at runtime instead \u2014 no rebuild needed.
203
+ VITE_XANO_HOST=https://your-instance.xano.io
204
+ `;
205
+ }
206
+ function renderReadme({ appName }, preset) {
207
+ return `# ${appName}
208
+
209
+ A [XanoTS](https://www.npmjs.com/package/@xanots/sdk) project: a Xano
210
+ backend authored in TypeScript under [\`xano/\`](xano/), and a ${preset.label}
211
+ frontend under [\`frontend/\`](frontend/) that derives its request paths and
212
+ types from the backend defs \u2014 so the two can't drift.
213
+
214
+ ## Quick start
215
+
216
+ \`\`\`bash
217
+ npm install
218
+ npm run dev # run the frontend (no backend needed yet)
219
+ \`\`\`
220
+
221
+ Then author your backend in [\`xano/index.ts\`](xano/index.ts) \u2014 start with the
222
+ walkthrough in [\`xano/EXAMPLE.md\`](xano/EXAMPLE.md).
223
+
224
+ ## Deploy
225
+
226
+ \`\`\`bash
227
+ xanots login # once, to authenticate against your Xano account
228
+ npm run xano:deploy # build the frontend, then ship it with the backend
229
+ \`\`\`
230
+
231
+ - \`npm run xano:export\` compiles the backend to \`workspace.json\` (don't commit it).
232
+ - \`npm run xano:deploy\` deploys the backend and the built frontend to a live
233
+ **ephemeral** environment and prints its URL. Run it again to refresh the same
234
+ environment; if it expired, a fresh one is created and the new URL is called out.
235
+ - Deploying to your throwaway singleton sandbox instead: \`xanots deploy ./xano/index.ts --dest sandbox\`.
236
+ - \`npm run xano:test\` runs the tests the DEPLOYED environment carries \u2014 the \`tests\`
237
+ on a query/function/middleware and any \`workflowTest()\`. It compiles nothing, so
238
+ deploy first. A failing suite exits 5, distinct from a crash. \`xanots deploy
239
+ ./xano/index.ts --test\` does both in one step.
240
+
241
+ ## \`xano.lock\` \u2014 commit it
242
+
243
+ Object identity derives from \`(type, name)\`, so a rename would otherwise change
244
+ an object's guid and the engine would **delete and recreate** it rather than
245
+ renaming it in place \u2014 losing its rows on a record-preserving import.
246
+ [\`xano/xano.lock\`](xano/xano.lock) freezes each guid and each API group's
247
+ canonical slug, so renames and re-deploys keep the same identities (and the same
248
+ public URLs).
249
+
250
+ It is created by \`npm run xano:export\` or \`npm run xano:deploy\`, and **must be
251
+ committed**. Adopt it from the first export: once identities have drifted, the
252
+ recovery path is \`xanots lock adopt <live-bundle.json> --lock=xano/xano.lock\`
253
+ against the deployed workspace.
254
+
255
+ \`\`\`bash
256
+ npm run xano:check # CI: fail if the export would change xano.lock
257
+ \`\`\`
258
+
259
+ To rename an object: rename it in code, run \`npm run xano:export\` (stderr prints
260
+ the exact fix-up), run \`xanots lock rename <kind> <old> <new> --lock=xano/xano.lock\`,
261
+ then export again. \`lock rename\` and \`lock adopt\` need that flag here \u2014 they take no
262
+ entry file, so they look for the lock in the current directory, while
263
+ \`lock prune ./xano/index.ts\` derives it from the entry like \`export\` does.
264
+
265
+ ## The one contract
266
+
267
+ [\`frontend/src/lib/api.ts\`](frontend/src/lib/api.ts) imports the XanoTS query
268
+ defs and derives paths (\`getPath()\`) and request/response types
269
+ (\`InferInput\` / \`InferResponse\`) from them. Never hand-type a URL or a request
270
+ body \u2014 change a def and the frontend types follow.
271
+
272
+ > To spot-check a def from Node (read \`getPath()\`/\`verb\`, log a value), run a real
273
+ > file with \`tsx <file.ts>\` **from inside the project root** \u2014 not \`tsx -e\`, not
274
+ > bare \`node file.ts\`, and not from another directory (they mis-resolve the
275
+ > intra-workspace \`.js\` imports and the \`@xanots/sdk\` specifier). Or use
276
+ > \`xanots paths xano/index.ts\` to list every endpoint's verb + path.
277
+
278
+ ## The frontend
279
+
280
+ ${preset.readmeFrontendSection()}
281
+
282
+ ## Add-ons
283
+
284
+ XanoTS is composable with other \`@xanots/*\` packages:
285
+
286
+ - **[\`@xanots/auth\`](https://www.npmjs.com/package/@xanots/auth)** \u2014 turnkey
287
+ authentication (user/login/signup tables and endpoints). Install it with
288
+ \`xanots marketplace install @xanots/auth\`, then register it in
289
+ \`xano/index.ts\`. Authentication only \u2014 **not** authorization: it has no
290
+ roles, permissions, or route guards. Build those with \`@xanots/sdk\` (a role
291
+ column plus a \`s.precondition\` per endpoint).
292
+ - More \`@xanots/*\` packages register onto the same workspace. This list
293
+ does not update itself \u2014 run \`xanots marketplace list\` for the live
294
+ catalogue, \`xanots marketplace search <words>\` to narrow it, and
295
+ \`xanots marketplace details <package>\` to see what an add-on installs and
296
+ how to register it. All three work before you log in.
297
+
298
+ None of these ship with the scaffold. Install one only when you need it \u2014 an
299
+ add-on you never register is weight in \`package.json\` for nothing.
300
+ `;
301
+ }
302
+ function renderXanoIndex({ appName }) {
303
+ return `import { workspace } from "@xanots/sdk";
304
+
305
+ /**
306
+ * The ${appName} backend.
307
+ *
308
+ * A workspace is assembled by registering typed objects onto a workspace()
309
+ * instance and default-exporting it. This starter is intentionally empty and
310
+ * already compiles + deploys \u2014 add your first table and endpoint below.
311
+ *
312
+ * \u2500\u2500 Add your first table + endpoint \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
313
+ *
314
+ * import { workspace, table, apiGroup, query, f, input, s, ref, c, expect, resp } from "@xanots/sdk";
315
+ *
316
+ * const notes = table({
317
+ * name: "notes",
318
+ * // \`id\` (int PK) + \`created_at\` (epochms) are auto-injected.
319
+ * schema: {
320
+ * body: f.text({ required: true }),
321
+ * },
322
+ * });
323
+ *
324
+ * const api = apiGroup({ name: "notes", canonical: "notes" }); // pin the slug
325
+ *
326
+ * const createNote = query({
327
+ * name: "create_note",
328
+ * verb: "POST",
329
+ * apiGroup: api,
330
+ * input: { body: input.text({ required: true }) },
331
+ * // ...build the stack with the s.* statement helpers...
332
+ * // Assertions ride along with the object they cover; \`npm run xano:test\`
333
+ * // runs them against whatever you last deployed.
334
+ * tests: [
335
+ * {
336
+ * name: "creates a note",
337
+ * input: { body: c.text("hello") },
338
+ * expect: [expect.to_be_defined(resp())],
339
+ * },
340
+ * ],
341
+ * });
342
+ *
343
+ * export default workspace("${appName}")
344
+ * .registerTables([notes])
345
+ * .registerApiGroups([api])
346
+ * .registerQueries([createNote]);
347
+ *
348
+ * Discover the exact builders and options from the package's own types and its
349
+ * shipped docs \u2014 read \`node_modules/@xanots/sdk/llms.txt\` first (it ends with a
350
+ * map of the \`llms/*.md\` topic files), then the .d.ts files.
351
+ * See \`xano/EXAMPLE.md\` for the full walkthrough.
352
+ *
353
+ * \u2500\u2500 Optional add-ons \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
354
+ * Nothing below is installed. Reach for an add-on when you need it, not before.
355
+ *
356
+ * @xanots/auth registers turnkey auth (user/login/signup) onto this same
357
+ * workspace. Install it first (\`xanots marketplace install @xanots/auth\`), then
358
+ * \`registerAuth(workspace("${appName}"), { canonical: "authn" })\` returns the
359
+ * instance to chain your own .register*() calls onto:
360
+ *
361
+ * registerAuth(workspace("${appName}"), { canonical: "authn" })
362
+ * .registerTables([notes])
363
+ * .registerApiGroups([api])
364
+ * .registerQueries([createNote]);
365
+ *
366
+ * That is not the whole catalogue. \`xanots marketplace list\` prints every
367
+ * published add-on and \`xanots marketplace details <package>\` prints what one
368
+ * installs plus the registration to paste here \u2014 no login required.
369
+ */
370
+ export default workspace("${appName}");
371
+ `;
372
+ }
373
+ function renderXanoExampleMd({ appName }) {
374
+ return `# Building your ${appName} backend
375
+
376
+ The backend lives in [\`index.ts\`](index.ts) and is a single default-exported
377
+ \`workspace()\`. You grow it by registering typed objects.
378
+
379
+ ## Learn the library from the library
380
+
381
+ Everything you need is in the package itself:
382
+
383
+ - \`node_modules/@xanots/sdk/llms.txt\` \u2014 the router: the mental model, the deploy contract, every gotcha, and control flow. Read it in full first; it ends with a list of topic files and the condition for opening each.
384
+ - \`node_modules/@xanots/sdk/llms/*.md\` \u2014 one file per surface. Open the one or two whose condition matches the task; skip the rest.
385
+ - The published TypeScript types and JSDoc (\`node_modules/@xanots/sdk/**/*.d.ts\`).
386
+ - \`node_modules/@xanots/sdk/manifest.json\` \u2014 the exhaustive reference; grep or \`jq\` the one entry you need rather than reading it whole.
387
+
388
+ Author against those signatures \u2014 don't invent an API that isn't there.
389
+
390
+ ## The shape
391
+
392
+ \`\`\`
393
+ xano/
394
+ \u251C\u2500\u2500 index.ts default export: the workspace registering everything below
395
+ \u251C\u2500\u2500 tables/<name>.ts a table (name, typed schema, indexes)
396
+ \u251C\u2500\u2500 api/<group>.ts an API group; pin its canonical slug so paths are stable
397
+ \u2514\u2500\u2500 api/<endpoint>.ts a query: name, verb, apiGroup, typed input, a stack, a response
398
+ \`\`\`
399
+
400
+ ## Steps
401
+
402
+ 1. **Define a table** under \`tables/\` with \`table({ name, schema: { ... } })\`.
403
+ \`id\` and \`created_at\` are auto-injected.
404
+ 2. **Define an API group** with \`apiGroup({ name, canonical })\`. Pinning the
405
+ canonical slug keeps the public path stable and lets \`getPath()\` resolve in
406
+ the browser bundle without a lock file.
407
+ 3. **Define endpoints** with \`query({ name, verb, apiGroup, input, ... })\`, building
408
+ the logic from the \`s.*\` statement helpers and the expression/column/input/
409
+ reference helpers.
410
+ 4. **Register everything** in \`index.ts\`:
411
+ \`\`\`ts
412
+ export default workspace("${appName}")
413
+ .registerTables([...])
414
+ .registerApiGroups([...])
415
+ .registerQueries([...]);
416
+ \`\`\`
417
+ 5. **Assert it works** \u2014 add a \`tests: [...]\` entry to a query or function
418
+ (named inputs plus \`expect.*\` assertions on its response), or a
419
+ \`workflowTest({ name, stack })\` when the behavior spans several objects.
420
+ They live beside the code they cover and ship with it. See "Testing" below.
421
+ 6. **Compile** with \`npm run xano:export\`, and **deploy** with
422
+ \`npm run xano:deploy\` (after \`xanots login\`). The first of either writes
423
+ \`xano/xano.lock\` \u2014 **commit it**. It pins every object's identity, so a later
424
+ rename renames the object instead of deleting and recreating it. See
425
+ "\`xano.lock\` \u2014 commit it" in the project README.
426
+
427
+ ## Testing
428
+
429
+ Two kinds of test are authored in \`xano/\` alongside the objects they cover, and
430
+ both run against a DEPLOYED environment:
431
+
432
+ - **Unit test** \u2014 \`tests: [...]\` on a \`query\`, \`defineFunction\`, or
433
+ \`middleware\`. Each entry is a named set of inputs run against that object, with
434
+ \`expect.*\` assertions on its response. A statement's \`mock\` (keyed by test
435
+ NAME) makes one step return a value instead of doing its work, but only while
436
+ that test runs.
437
+ - **Workflow test** \u2014 \`workflowTest({ name, stack })\`, a standalone object whose
438
+ stack calls others (\`s.function.call\`, \`s.api.call\`) and asserts with
439
+ \`s.expect.*\`. Use it for behavior that spans objects.
440
+
441
+ \`expect.*\` and \`s.expect.*\` are different builders \u2014 an assertion record versus
442
+ a workflow-test statement \u2014 and are not interchangeable.
443
+
444
+ \`\`\`bash
445
+ npm run xano:deploy # tests run against what is deployed, so deploy first
446
+ npm run xano:test # runs both kinds; exits 5 if any fail
447
+ \`\`\`
448
+
449
+ \`npx xanots deploy ./xano/index.ts --test\` does both in one step, and
450
+ \`npx xanots test list\` shows what a deployed environment carries without running
451
+ anything. Read \`node_modules/@xanots/sdk/llms/tests.md\` before authoring either
452
+ kind.
453
+
454
+ ### Event-driven objects
455
+
456
+ A scheduled \`task\`, an \`mcpServer\`, and every trigger **fire normally on an
457
+ ephemeral** \u2014 \`deploy\`'s default destination \u2014 so test them by deploying and
458
+ letting them run.
459
+
460
+ Under \`--dest sandbox\` they **deploy but do not fire**: they import cleanly, never
461
+ execute, and there's no way to fire one manually (a table insert/update/delete does
462
+ NOT run its trigger). Only synchronously-invoked objects \u2014 queries, functions, and
463
+ the agents an endpoint calls with \`s.ai.agent.run\` \u2014 run there. If you must stay on
464
+ the sandbox, factor the body into a \`defineFunction\` you can also call directly
465
+ (e.g. from a query via \`s.function.run\`) and put the assertions on THAT \u2014 a
466
+ \`tests\` entry on the function, or a \`workflowTest\` that calls it. See
467
+ \`llms.txt\` for the full guidance.
468
+
469
+ ## Wire the frontend
470
+
471
+ In [\`../frontend/src/lib/api.ts\`](../frontend/src/lib/api.ts), derive paths and
472
+ types from your query defs (\`getPath()\`, \`InferInput\`, \`InferResponse\`) \u2014 never
473
+ hand-type a URL or a request body.
474
+
475
+ Keep the client bundle lean (**split route metadata from stack-heavy authoring**):
476
+
477
+ - \`import type\` for shapes \u2014 \`InferInput\`/\`InferResponse\` erase to nothing.
478
+ - Import the **one lean query def** for its \`getPath()\`/\`verb\`, never \`xano/index.ts\`
479
+ (that pulls the whole workspace). A def's \`s.*\`/\`c.*\` stack calls run at module
480
+ load to build it, so they can't be tree-shaken out of the bundle.
481
+ - A def whose stack builds a heavy graph \u2014 an agent + its tools via \`s.ai.agent.run\`
482
+ \u2014 drags that whole graph in. For those, don't import the def in the browser:
483
+ declare its \`{ path, verb }\` as plain metadata (see the \`ROUTES\` example in
484
+ \`api.ts\`) and verify it against the compiled bundle with
485
+ \`npx xanots paths xano/index.ts\`.
486
+ `;
487
+ }
488
+ function describeOrigin(o) {
489
+ switch (o.source) {
490
+ case "workspace":
491
+ return `workspace ${o.origin}`;
492
+ case "sandbox":
493
+ return "the sandbox workspace";
494
+ case "ephemeral":
495
+ return `ephemeral "${o.origin}"`;
496
+ case "file":
497
+ return `the bundle at ${o.origin}`;
498
+ }
499
+ }
500
+ function renderCodegenMarker({ sdkVersion }, origin, generatedAt, report) {
501
+ return JSON.stringify(
502
+ {
503
+ source: origin.source,
504
+ origin: origin.origin,
505
+ sdkVersion,
506
+ generatedAt,
507
+ note: "Written by `xanots \u2026 codegen`. Its presence lets a re-run refresh xano/ in place.",
508
+ // The findings, so parity is trackable release over release and gateable
509
+ // in CI without scraping stderr. Omitted rather than written empty when
510
+ // the caller has none to record.
511
+ ...report === void 0 ? {} : { report }
512
+ },
513
+ null,
514
+ 2
515
+ ) + "\n";
516
+ }
517
+ function renderCodegenReadme({ appName }, origin, envNames, preset) {
518
+ const secrets = envNames.length === 0 ? "" : `
519
+ ## Heads up: this tree contains your workspace env var values
520
+
521
+ The pull carried ${envNames.length} workspace env var${envNames.length === 1 ? "" : "s"} \u2014
522
+ ${envNames.map((n) => `\`${n}\``).join(", ")} \u2014 **with their values**, inline in
523
+ [\`xano/index.ts\`](xano/index.ts), because that is what a deploy has to send. If any of them
524
+ is a secret, do not commit \`xano/\` as-is: add it to \`.gitignore\`, or replace the values
525
+ before committing.
526
+ `;
527
+ return `# ${appName}
528
+
529
+ A [XanoTS](https://www.npmjs.com/package/@xanots/sdk) project pulled from
530
+ ${describeOrigin(origin)}. The Xano backend lives in [\`xano/\`](xano/) as readable
531
+ TypeScript; the ${preset.label} frontend under [\`frontend/\`](frontend/) is a starter \u2014
532
+ the pull carries a backend, not a UI.
533
+
534
+ ## Deploy it
535
+
536
+ \`\`\`bash
537
+ xanots login # once, to authenticate against your Xano account
538
+ npm run xano:deploy # typecheck, build the frontend, ship both
539
+ \`\`\`
540
+
541
+ ## Read this before deploying
542
+
543
+ - **\`xano/\` is disposable.** Re-running \`xanots \u2026 codegen\` on this directory
544
+ rewrites it wholesale \u2014 no merge, no diff, no preservation of hand edits. The rest of
545
+ the project (this README, \`package.json\`, \`frontend/\`) is yours and is left alone.
546
+ - **Deploying is a full replace.** The import path clears the target workspace and
547
+ re-imports. Send this only to an **ephemeral or sandbox** environment \u2014 never to a
548
+ workspace holding data you care about. That is why \`npm run xano:deploy\` targets an
549
+ ephemeral env and there is no deploy-to-your-real-workspace command.
550
+ - **This is schema only.** Table rows are not carried, and neither are payload sections
551
+ this SDK models no kind for. A deploy recreates the structure, not the data.
552
+
553
+ [\`xano/README.md\`](xano/README.md) is the authoritative record of what did and did not
554
+ translate cleanly on this pull. Read it before trusting the tree.
555
+ ${secrets}
556
+ ## Working on it
557
+
558
+ \`\`\`bash
559
+ npm run dev # run the starter frontend
560
+ npm run typecheck # the whole project, both halves
561
+ npm run xano:export # compile the backend to workspace.json (don't commit it)
562
+ npx xanots paths xano/index.ts # list every endpoint's verb + path
563
+ \`\`\`
564
+
565
+ [\`frontend/src/lib/api.ts\`](frontend/src/lib/api.ts) shows the one contract: derive
566
+ request paths and types from the query defs in \`xano/\` rather than hand-typing a URL.
567
+ `;
568
+ }
569
+ var UI_DOCS_CTA = {
570
+ label: "Browse UI components",
571
+ href: "https://ui.shadcn.com/docs/components"
572
+ };
573
+ function initLanding({ appName }) {
574
+ return {
575
+ title: appName,
576
+ lead: [
577
+ { text: "Your XanoTS project is ready. The backend lives in " },
578
+ { code: "xano/" },
579
+ { text: " and this frontend in " },
580
+ { code: "frontend/" },
581
+ { text: "." }
582
+ ],
583
+ steps: [
584
+ [
585
+ { text: "Author your first table + endpoint in " },
586
+ { code: "xano/index.ts" },
587
+ { text: " (see " },
588
+ { code: "xano/EXAMPLE.md" },
589
+ { text: ")." }
590
+ ],
591
+ [{ text: "Wire it into the UI from " }, { code: "frontend/src/lib/api.ts" }, { text: "." }],
592
+ [{ text: "Ship it: " }, { code: "npm run xano:deploy" }, { text: "." }]
593
+ ],
594
+ cta: UI_DOCS_CTA
595
+ };
596
+ }
597
+ function codegenLanding({ appName }, origin) {
598
+ return {
599
+ title: appName,
600
+ lead: [
601
+ { text: `This project was pulled from ${describeOrigin(origin)}. The backend lives in ` },
602
+ { code: "xano/" },
603
+ { text: " as readable TypeScript; this frontend is a starter." }
604
+ ],
605
+ steps: [
606
+ [
607
+ { text: "Read " },
608
+ { code: "xano/README.md" },
609
+ { text: " \u2014 what did and did not translate cleanly on the pull." }
610
+ ],
611
+ [
612
+ { text: "List the endpoints: " },
613
+ { code: "npx xanots paths xano/index.ts" },
614
+ { text: ", then wire them up in " },
615
+ { code: "frontend/src/lib/api.ts" },
616
+ { text: "." }
617
+ ],
618
+ [
619
+ { text: "Ship it: " },
620
+ { code: "npm run xano:deploy" },
621
+ { text: " (a full replace of an ephemeral env)." }
622
+ ]
623
+ ],
624
+ cta: UI_DOCS_CTA
625
+ };
626
+ }
627
+ function renderIndexCss() {
628
+ return `@import "tailwindcss";
629
+ @import "tw-animate-css";
630
+
631
+ @custom-variant dark (&:is(.dark *));
632
+
633
+ /* Map the tokens below into Tailwind's theme so \`bg-primary\` and friends
634
+ resolve. Tailwind v4 does this in CSS; there is no tailwind.config.js. */
635
+ @theme inline {
636
+ --color-background: var(--background);
637
+ --color-foreground: var(--foreground);
638
+ --color-card: var(--card);
639
+ --color-card-foreground: var(--card-foreground);
640
+ --color-popover: var(--popover);
641
+ --color-popover-foreground: var(--popover-foreground);
642
+ --color-primary: var(--primary);
643
+ --color-primary-foreground: var(--primary-foreground);
644
+ --color-secondary: var(--secondary);
645
+ --color-secondary-foreground: var(--secondary-foreground);
646
+ --color-muted: var(--muted);
647
+ --color-muted-foreground: var(--muted-foreground);
648
+ --color-accent: var(--accent);
649
+ --color-accent-foreground: var(--accent-foreground);
650
+ --color-destructive: var(--destructive);
651
+ --color-border: var(--border);
652
+ --color-input: var(--input);
653
+ --color-ring: var(--ring);
654
+ --radius-sm: calc(var(--radius) - 4px);
655
+ --radius-md: calc(var(--radius) - 2px);
656
+ --radius-lg: var(--radius);
657
+ --radius-xl: calc(var(--radius) + 4px);
658
+ }
659
+
660
+ /* Rebrand here: these are the only colors the components know about. */
661
+ :root {
662
+ --radius: 0.625rem;
663
+ --background: oklch(1 0 0);
664
+ --foreground: oklch(0.145 0 0);
665
+ --card: oklch(1 0 0);
666
+ --card-foreground: oklch(0.145 0 0);
667
+ --popover: oklch(1 0 0);
668
+ --popover-foreground: oklch(0.145 0 0);
669
+ --primary: oklch(0.205 0 0);
670
+ --primary-foreground: oklch(0.985 0 0);
671
+ --secondary: oklch(0.97 0 0);
672
+ --secondary-foreground: oklch(0.205 0 0);
673
+ --muted: oklch(0.97 0 0);
674
+ --muted-foreground: oklch(0.556 0 0);
675
+ --accent: oklch(0.97 0 0);
676
+ --accent-foreground: oklch(0.205 0 0);
677
+ --destructive: oklch(0.577 0.245 27.325);
678
+ --border: oklch(0.922 0 0);
679
+ --input: oklch(0.922 0 0);
680
+ --ring: oklch(0.708 0 0);
681
+ }
682
+
683
+ /* Applied by adding \`class="dark"\` to <html> \u2014 wire that to a toggle if you
684
+ want one; the scaffold ships light-only. */
685
+ .dark {
686
+ --background: oklch(0.145 0 0);
687
+ --foreground: oklch(0.985 0 0);
688
+ --card: oklch(0.205 0 0);
689
+ --card-foreground: oklch(0.985 0 0);
690
+ --popover: oklch(0.205 0 0);
691
+ --popover-foreground: oklch(0.985 0 0);
692
+ --primary: oklch(0.922 0 0);
693
+ --primary-foreground: oklch(0.205 0 0);
694
+ --secondary: oklch(0.269 0 0);
695
+ --secondary-foreground: oklch(0.985 0 0);
696
+ --muted: oklch(0.269 0 0);
697
+ --muted-foreground: oklch(0.708 0 0);
698
+ --accent: oklch(0.269 0 0);
699
+ --accent-foreground: oklch(0.985 0 0);
700
+ --destructive: oklch(0.704 0.191 22.216);
701
+ --border: oklch(1 0 0 / 10%);
702
+ --input: oklch(1 0 0 / 15%);
703
+ --ring: oklch(0.556 0 0);
704
+ }
705
+
706
+ @layer base {
707
+ * {
708
+ @apply border-border outline-ring/50;
709
+ }
710
+ body {
711
+ @apply bg-background text-foreground;
712
+ }
713
+ }
714
+ `;
715
+ }
716
+ function renderCnUtil(extra = "") {
717
+ return `import { clsx, type ClassValue } from "clsx";
718
+ import { twMerge } from "tailwind-merge";
719
+
720
+ export function cn(...inputs: ClassValue[]) {
721
+ return twMerge(clsx(inputs));
722
+ }
723
+ ${extra}`;
724
+ }
725
+ function renderApiTs() {
726
+ return `// The one contract: derive paths and request/response *types* from your xanots
727
+ // query defs. Never hand-type a URL or a request body \u2014 change a def and
728
+ // everything here follows.
729
+ //
730
+ // Keep the client bundle lean (the split-route-metadata rule):
731
+ // \u2022 \`import type\` for shapes \u2014 InferInput/InferResponse erase to nothing.
732
+ // \u2022 Import the ONE lean query def module for its getPath()/verb \u2014 never
733
+ // ../../../xano/index.js (that pulls the whole workspace) and never a def
734
+ // whose stack builds a heavy graph (an agent + its tools via s.ai.agent.run):
735
+ // those s.*/c.* factory calls run at module load and can't be tree-shaken out.
736
+ // \u2022 For such a stack-heavy endpoint, don't import its def in the browser at all \u2014
737
+ // declare its { path, verb } in the ROUTES table below and verify it against
738
+ // the compiled bundle with \`npx xanots paths xano/index.ts\`.
739
+ //
740
+ // This starter has no endpoints yet. Once you add one in xano/, wire it like:
741
+ //
742
+ // // Types are free \u2014 always import them type-only.
743
+ // import type { InferInput, InferResponse } from "@xanots/sdk";
744
+ // import type { createNoteQuery } from "../../../xano/api/create-note.js";
745
+ //
746
+ // // Runtime path/verb: import the lean def value, OR (for a stack-heavy def)
747
+ // // read it from ROUTES so the def never enters the bundle.
748
+ // import { createNoteQuery } from "../../../xano/api/create-note.js";
749
+ //
750
+ // export type CreateNoteBody = InferInput<typeof createNoteQuery>;
751
+ // export type Note = InferResponse<typeof createNoteQuery>;
752
+ //
753
+ // export async function createNote(body: CreateNoteBody): Promise<Note> {
754
+ // const res = await fetch(XANO_HOST + createNoteQuery.getPath(), {
755
+ // method: createNoteQuery.verb,
756
+ // headers: { "content-type": "application/json" },
757
+ // body: JSON.stringify(body),
758
+ // });
759
+ // if (!res.ok) throw new Error(await res.text());
760
+ // return res.json();
761
+ // }
762
+ //
763
+ // The stack-heavy escape hatch \u2014 plain metadata, no def import, no bundle cost.
764
+ // Keep it in sync with \`npx xanots paths xano/index.ts\` (it prints verb + path):
765
+ //
766
+ // export const ROUTES = {
767
+ // triageRequest: { path: "/api:notes/triage_request", verb: "POST" },
768
+ // } as const;
769
+
770
+ /**
771
+ * The deployed Xano backend's base URL. Injected as \`window.XANO_HOST\` by
772
+ * \`xanots deploy <entry> --static <dir>\`, or read from \`VITE_XANO_HOST\` in dev.
773
+ * Empty string when neither is set (the UI runs with no backend).
774
+ */
775
+ export const XANO_HOST: string =
776
+ (typeof window !== "undefined" && (window as { XANO_HOST?: string }).XANO_HOST) ||
777
+ import.meta.env.VITE_XANO_HOST ||
778
+ "";
779
+ `;
780
+ }
781
+
782
+ // src/emit/frontend-resolve.ts
783
+ import { createInterface } from "readline/promises";
784
+
785
+ // src/emit/frontend-svelte.ts
786
+ var CODE_CLASS = "bg-muted rounded px-1.5 py-0.5 font-mono text-sm";
787
+ function htmlText(s) {
788
+ return s.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
789
+ }
790
+ function svelteText(s) {
791
+ return htmlText(s).replace(/\{/g, "&#123;").replace(/\}/g, "&#125;");
792
+ }
793
+ function renderNode(node) {
794
+ return "code" in node ? `<code class="${CODE_CLASS}">${svelteText(node.code)}</code>` : svelteText(node.text);
795
+ }
796
+ function renderNodes(nodes) {
797
+ return nodes.map(renderNode).join("");
798
+ }
799
+ function renderApp(landing) {
800
+ const steps = landing.steps.map((step2) => ` <li>${renderNodes(step2)}</li>`).join("\n");
801
+ return `<script lang="ts">
802
+ import ArrowRight from "@lucide/svelte/icons/arrow-right";
803
+
804
+ import { Button } from "$lib/components/ui/button/index.js";
805
+ import * as Card from "$lib/components/ui/card/index.js";
806
+ </script>
807
+
808
+ <main class="mx-auto flex min-h-screen max-w-2xl flex-col justify-center p-8">
809
+ <Card.Root>
810
+ <Card.Header>
811
+ <Card.Title class="text-3xl tracking-tight">${svelteText(landing.title)}</Card.Title>
812
+ <Card.Description class="text-base">
813
+ ${renderNodes(landing.lead)}
814
+ </Card.Description>
815
+ </Card.Header>
816
+ <Card.Content>
817
+ <ol class="text-muted-foreground list-inside list-decimal space-y-2">
818
+ ${steps}
819
+ </ol>
820
+ </Card.Content>
821
+ <Card.Footer>
822
+ <!-- Components come from shadcn-svelte \u2014 add more with
823
+ \`npx shadcn-svelte@latest add <name>\`. -->
824
+ <Button href="${landing.cta.href}" target="_blank" rel="noreferrer">
825
+ ${svelteText(landing.cta.label)}
826
+ <ArrowRight />
827
+ </Button>
828
+ </Card.Footer>
829
+ </Card.Root>
830
+ </main>
831
+ `;
832
+ }
833
+ function renderSvelteKitPlugin() {
834
+ return `sveltekit({
835
+ // RUNES MODE, FORCED \u2014 not left to Svelte 5's per-component detection.
836
+ //
837
+ // By default a component that uses \`export let\` and \`<slot>\` simply
838
+ // compiles in legacy mode and works, so the Svelte 4 API an assistant
839
+ // reaches for from older training data produces no error at all. Pinning
840
+ // runes here turns that into a compile failure naming the file, which is
841
+ // the same guidance the agent brief gives, enforced instead of stated.
842
+ //
843
+ // \`node_modules\` is exempted (returning undefined restores detection):
844
+ // an installed library compiles under whatever mode ITS author wrote for,
845
+ // and forcing ours onto it would break dependencies this project does not
846
+ // own. Removable in Svelte 6, where runes stop being opt-in.
847
+ compilerOptions: {
848
+ runes: ({ filename }) =>
849
+ filename.split(/[/\\\\]/).includes("node_modules") ? undefined : true,
850
+ },
851
+ // No \`preprocess\`. vite-plugin-svelte 7 compiles \`<script lang="ts">\`
852
+ // itself, so \`vitePreprocess()\` is the no-op it looks like \u2014 \`sv create\`
853
+ // emits none either. Verified against a real build: components typecheck
854
+ // and compile without it.
855
+ //
856
+ // The deploy target is a static host with NO server runtime \u2014 Xano is the
857
+ // backend. Routes are PRERENDERED (see frontend/src/routes/+layout.ts):
858
+ // each becomes its own HTML file at build time, and the host resolves a URL
859
+ // to it by trying the exact key, then \`{path}.html\`, then
860
+ // \`{path}/index.html\`. That is why no \`trailingSlash\` is configured \u2014 both
861
+ // output shapes resolve, so this stays on SvelteKit's default.
862
+ //
863
+ // NO \`fallback\`. It looks harmless \u2014 it used to be how every URL got served
864
+ // \u2014 but adapter-static writes the fallback shell AT index.html, overwriting
865
+ // the prerendered home page with an empty document. Measured on a real
866
+ // build: 1936 bytes of empty shell instead of 4920 bytes of rendered page,
867
+ // on the most-visited route in the app.
868
+ //
869
+ // Dropping it also gets the better failure. With no fallback, adapter-static
870
+ // is \`strict\` by default, so a route it cannot prerender (a dynamic \`[id]\`
871
+ // with no \`entries\`) FAILS THE BUILD with a message naming the route \u2014
872
+ // instead of shipping and 404ing for real users.
873
+ //
874
+ // \`xanots deploy --static-env\` still finds its anchor: every prerendered
875
+ // route renders from app.html, so each document has a <head> and each one
876
+ // gets the injected globals.
877
+ adapter: adapter({
878
+ pages: "frontend/dist",
879
+ assets: "frontend/dist",
880
+ precompress: false,
881
+ }),
882
+ // Absolute asset URLs, pinned rather than left to the default. Prerendered
883
+ // pages live at varying URL depths, and a relative \`../_app/\u2026\` computed for
884
+ // one depth 404s at another.
885
+ paths: { relative: false },
886
+ prerender: {
887
+ // A hash link in the shared layout \u2014 \`<a href="#services">\`, the default
888
+ // shape of a one-page site's nav \u2014 renders into EVERY prerendered route,
889
+ // including the scaffold's own /404. There it resolves to /404#services,
890
+ // an anchor that by definition is not on that page, and SvelteKit's
891
+ // default handler THROWS: the vite build succeeds and the prerender pass
892
+ // after it kills the build, with a stack trace naming only files inside
893
+ // node_modules and a route the author never wrote.
894
+ //
895
+ // So ignore a missing id on /404 specifically, rather than reaching for a
896
+ // blanket \`handleMissingId: "warn"\`. A hash link that is genuinely broken
897
+ // on a real route still fails the build, which is the check worth keeping.
898
+ handleMissingId: ({ path, message }) => {
899
+ if (path === "/404") return;
900
+ throw new Error(message);
901
+ },
902
+ },
903
+ // SvelteKit's project layout, redirected under frontend/ so this stays a
904
+ // single-root project: one package.json, one tsconfig.json, and xano/
905
+ // sitting alongside as the backend half. NOTE these are what make
906
+ // frontend/src/routes the routes directory \u2014 a file added under a
907
+ // top-level src/routes/ is not a route and will not be served.
908
+ files: {
909
+ routes: "frontend/src/routes",
910
+ lib: "frontend/src/lib",
911
+ appTemplate: "frontend/src/app.html",
912
+ assets: "frontend/static",
913
+ },
914
+ })`;
915
+ }
916
+ function renderAppHtml({ appName }) {
917
+ return `<!doctype html>
918
+ <html lang="en">
919
+ <head>
920
+ <meta charset="utf-8" />
921
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
922
+ <title>${htmlText(appName)}</title>
923
+ <!-- Drop a favicon.png into frontend/static/ and link it here:
924
+ <link rel="icon" href="%sveltekit.assets%/favicon.png" />
925
+ Everything in that directory is copied to the site root verbatim. -->
926
+ <!-- Keep this inside <head>: \`xanots deploy --static-env\` injects the
927
+ backend URL here as a window global that frontend/src/lib/api.ts reads. -->
928
+ %sveltekit.head%
929
+ </head>
930
+ <body data-sveltekit-preload-data="hover">
931
+ <div style="display: contents">%sveltekit.body%</div>
932
+ </body>
933
+ </html>
934
+ `;
935
+ }
936
+ function renderAppDts() {
937
+ return `// See https://svelte.dev/docs/kit/types#app.d.ts
938
+ declare global {
939
+ namespace App {
940
+ // interface Error {}
941
+ // interface Locals {}
942
+ // interface PageData {}
943
+ // interface PageState {}
944
+ // interface Platform {}
945
+ }
946
+ }
947
+
948
+ export {};
949
+ `;
950
+ }
951
+ function renderLayoutTs() {
952
+ return `// There is no server. The backend is Xano, reached through $lib/api.ts,
953
+ // and \`npm run xano:deploy\` ships this app to a static host with no runtime.
954
+ //
955
+ // prerender: true \u2014 every route is rendered to its own HTML file AT BUILD TIME
956
+ // and served as a real document. That is what makes each page load as itself
957
+ // rather than as an empty shell that fills in afterwards.
958
+ //
959
+ // Prerendering IS server-rendering, just at build time rather than per request.
960
+ // So module-scope \`window\`/\`document\` access now fails the BUILD instead of the
961
+ // browser \u2014 which is the better place to find out. Reach for browser globals
962
+ // inside onMount, or guard with \`import { browser } from "$app/environment"\`.
963
+ //
964
+ // A route with dynamic segments (e.g. /posts/[id]) cannot be prerendered unless
965
+ // the build knows which ones exist, so THE BUILD FAILS and names the route.
966
+ // That is deliberate \u2014 better than shipping a page that 404s for real users.
967
+ // Give it entries, in that route's +page.ts:
968
+ //
969
+ // export const entries = () => [{ id: "1" }, { id: "2" }];
970
+ //
971
+ // Inherited by every route below this one.
972
+ export const prerender = true;
973
+ `;
974
+ }
975
+ function renderErrorState() {
976
+ return `<script lang="ts">
977
+ // Shared by the prerendered /404 route and +error.svelte.
978
+ let { status = 404, message = "" }: { status?: number; message?: string } = $props();
979
+ </script>
980
+
981
+ <main class="grid min-h-screen place-items-center p-8">
982
+ <div class="max-w-md space-y-4 text-center">
983
+ <p class="text-6xl font-semibold tracking-tight">{status}</p>
984
+ <h1 class="text-xl font-medium">
985
+ {status === 404 ? "We can't find that page." : "Something went wrong."}
986
+ </h1>
987
+ <p class="text-muted-foreground text-sm">
988
+ {message !== "" ? message : "The link may be broken, or the page may have moved."}
989
+ </p>
990
+ <a
991
+ href="/"
992
+ class="bg-primary text-primary-foreground ring-offset-background focus-visible:ring-ring inline-flex h-10 items-center rounded-md px-5 text-sm font-medium transition-opacity hover:opacity-90 focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:outline-none"
993
+ >
994
+ Back to safety
995
+ </a>
996
+ </div>
997
+ </main>
998
+ `;
999
+ }
1000
+ function renderNotFoundRoute() {
1001
+ return `<script lang="ts">
1002
+ // Prerendered to 404.html, which is what tells the static host to answer an
1003
+ // unmatched path with a real 404 instead of quietly serving the app shell
1004
+ // with a 200 (a missing asset would then reach the browser as HTML, which it
1005
+ // reports as "Unexpected token '<'").
1006
+ //
1007
+ // It must be a route, not +error.svelte: SvelteKit never prerenders the error
1008
+ // component to a file, so relying on it would ship no 404.html at all.
1009
+ //
1010
+ // Delete this directory and an unmatched path serves the home page with a 200
1011
+ // instead \u2014 which is worse, not better, so keep it unless you have a reason.
1012
+ import ErrorState from "$lib/components/error-state.svelte";
1013
+ </script>
1014
+
1015
+ <svelte:head>
1016
+ <title>Page not found</title>
1017
+ </svelte:head>
1018
+
1019
+ <ErrorState status={404} />
1020
+ `;
1021
+ }
1022
+ function renderErrorSvelte() {
1023
+ return `<script lang="ts">
1024
+ // Rendered when a client-side navigation or load fails inside the running
1025
+ // app. The static host never sees these \u2014 for a path that matched no
1026
+ // document at all, it serves the prerendered routes/404 page instead.
1027
+ import { page } from "$app/state";
1028
+ import ErrorState from "$lib/components/error-state.svelte";
1029
+ </script>
1030
+
1031
+ <svelte:head>
1032
+ <title>{page.status === 404 ? "Page not found" : "Something went wrong"}</title>
1033
+ </svelte:head>
1034
+
1035
+ <ErrorState status={page.status} message={page.error?.message ?? ""} />
1036
+ `;
1037
+ }
1038
+ function renderLayoutSvelte() {
1039
+ return `<script lang="ts">
1040
+ // The shared token stylesheet \u2014 semantic colors (bg-primary,
1041
+ // text-muted-foreground) plus the Tailwind v4 theme. Imported once here so
1042
+ // every route gets it.
1043
+ import "../index.css";
1044
+
1045
+ let { children } = $props();
1046
+ </script>
1047
+
1048
+ {@render children()}
1049
+ `;
1050
+ }
1051
+ function renderComponentsJson() {
1052
+ const config = {
1053
+ $schema: "https://shadcn-svelte.com/schema.json",
1054
+ tailwind: {
1055
+ // v4 has no config file; the theme lives in the stylesheet — the same
1056
+ // shared one the React preset points at.
1057
+ css: "frontend/src/index.css",
1058
+ baseColor: "neutral"
1059
+ },
1060
+ aliases: {
1061
+ components: "$lib/components",
1062
+ utils: "$lib/utils",
1063
+ ui: "$lib/components/ui",
1064
+ hooks: "$lib/hooks",
1065
+ lib: "$lib"
1066
+ },
1067
+ typescript: true,
1068
+ registry: "https://shadcn-svelte.com/registry"
1069
+ };
1070
+ return JSON.stringify(config, null, 2) + "\n";
1071
+ }
1072
+ function renderButtonSvelte() {
1073
+ return `<script lang="ts" module>
1074
+ import { type VariantProps, tv } from "tailwind-variants";
1075
+
1076
+ export const buttonVariants = tv({
1077
+ base: "inline-flex shrink-0 items-center justify-center gap-2 rounded-md text-sm font-medium whitespace-nowrap transition-all outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:pointer-events-none disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
1078
+ variants: {
1079
+ variant: {
1080
+ default: "bg-primary text-primary-foreground hover:bg-primary/90",
1081
+ destructive:
1082
+ "bg-destructive text-white hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:bg-destructive/60 dark:focus-visible:ring-destructive/40",
1083
+ outline:
1084
+ "border bg-background shadow-xs hover:bg-accent hover:text-accent-foreground dark:border-input dark:bg-input/30 dark:hover:bg-input/50",
1085
+ secondary: "bg-secondary text-secondary-foreground hover:bg-secondary/80",
1086
+ ghost: "hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50",
1087
+ link: "text-primary underline-offset-4 hover:underline",
1088
+ },
1089
+ size: {
1090
+ default: "h-9 px-4 py-2 has-[>svg]:px-3",
1091
+ sm: "h-8 gap-1.5 rounded-md px-3 has-[>svg]:px-2.5",
1092
+ lg: "h-10 rounded-md px-6 has-[>svg]:px-4",
1093
+ icon: "size-9",
1094
+ },
1095
+ },
1096
+ defaultVariants: {
1097
+ variant: "default",
1098
+ size: "default",
1099
+ },
1100
+ });
1101
+
1102
+ export type ButtonVariant = VariantProps<typeof buttonVariants>["variant"];
1103
+ export type ButtonSize = VariantProps<typeof buttonVariants>["size"];
1104
+
1105
+ export type ButtonProps = WithElementRef<HTMLButtonAttributes> &
1106
+ WithElementRef<HTMLAnchorAttributes> & {
1107
+ variant?: ButtonVariant;
1108
+ size?: ButtonSize;
1109
+ };
1110
+ </script>
1111
+
1112
+ <script lang="ts">
1113
+ import type { HTMLAnchorAttributes, HTMLButtonAttributes } from "svelte/elements";
1114
+ import type { WithElementRef } from "bits-ui";
1115
+ import { cn } from "$lib/utils.js";
1116
+
1117
+ let {
1118
+ class: className,
1119
+ variant = "default",
1120
+ size = "default",
1121
+ ref = $bindable(null),
1122
+ href = undefined,
1123
+ type = "button",
1124
+ children,
1125
+ ...restProps
1126
+ }: ButtonProps = $props();
1127
+ </script>
1128
+
1129
+ {#if href}
1130
+ <a
1131
+ bind:this={ref}
1132
+ data-slot="button"
1133
+ class={cn(buttonVariants({ variant, size }), className)}
1134
+ {href}
1135
+ {...restProps}
1136
+ >
1137
+ {@render children?.()}
1138
+ </a>
1139
+ {:else}
1140
+ <button
1141
+ bind:this={ref}
1142
+ data-slot="button"
1143
+ class={cn(buttonVariants({ variant, size }), className)}
1144
+ {type}
1145
+ {...restProps}
1146
+ >
1147
+ {@render children?.()}
1148
+ </button>
1149
+ {/if}
1150
+ `;
1151
+ }
1152
+ function renderButtonIndex() {
1153
+ return `export {
1154
+ default as Button,
1155
+ buttonVariants,
1156
+ type ButtonProps,
1157
+ type ButtonSize,
1158
+ type ButtonVariant,
1159
+ } from "./button.svelte";
1160
+ `;
1161
+ }
1162
+ function cardPart(slot, tag, classes) {
1163
+ return `<script lang="ts">
1164
+ import type { HTMLAttributes } from "svelte/elements";
1165
+ import type { WithElementRef } from "bits-ui";
1166
+ import { cn } from "$lib/utils.js";
1167
+
1168
+ let {
1169
+ class: className,
1170
+ ref = $bindable(null),
1171
+ children,
1172
+ ...restProps
1173
+ }: WithElementRef<HTMLAttributes<HTMLDivElement>> = $props();
1174
+ </script>
1175
+
1176
+ <${tag}
1177
+ bind:this={ref}
1178
+ data-slot="${slot}"
1179
+ class={cn("${classes}", className)}
1180
+ {...restProps}
1181
+ >
1182
+ {@render children?.()}
1183
+ </${tag}>
1184
+ `;
1185
+ }
1186
+ function renderCardIndex() {
1187
+ return `import Root from "./card.svelte";
1188
+ import Content from "./card-content.svelte";
1189
+ import Description from "./card-description.svelte";
1190
+ import Footer from "./card-footer.svelte";
1191
+ import Header from "./card-header.svelte";
1192
+ import Title from "./card-title.svelte";
1193
+
1194
+ export {
1195
+ Root,
1196
+ Content,
1197
+ Description,
1198
+ Footer,
1199
+ Header,
1200
+ Title,
1201
+ //
1202
+ Root as Card,
1203
+ Content as CardContent,
1204
+ Description as CardDescription,
1205
+ Footer as CardFooter,
1206
+ Header as CardHeader,
1207
+ Title as CardTitle,
1208
+ };
1209
+ `;
1210
+ }
1211
+ var sveltePreset = {
1212
+ id: "svelte",
1213
+ label: "SvelteKit",
1214
+ dependencies: {
1215
+ // shadcn-svelte's runtime surface. `bits-ui` is the headless primitive
1216
+ // library its components are built on (the Radix equivalent), and
1217
+ // `tailwind-variants` types the variants (the cva equivalent). clsx +
1218
+ // tailwind-merge back `cn()` exactly as in the React preset; @lucide/svelte
1219
+ // is the icon set. Pre-installed so `npx shadcn-svelte@latest add
1220
+ // <component>` works without a separate npm i.
1221
+ "bits-ui": "^2.18.1",
1222
+ clsx: "^2.1.1",
1223
+ // Not the same version line as `lucide-react`: the Svelte icons ship from a
1224
+ // separate package on their own 1.x.
1225
+ "@lucide/svelte": "^1.31.0",
1226
+ "tailwind-merge": "^3.0.1",
1227
+ "tailwind-variants": "^3.3.1"
1228
+ },
1229
+ devDependencies: {
1230
+ // Writes the static bundle `deploy --static` ships. Peer-depends on kit ^2.
1231
+ "@sveltejs/adapter-static": "^3.0.10",
1232
+ // 2.70 peer-accepts vite ^8 and vite-plugin-svelte ^7 — the versions
1233
+ // pinned below. Bump this line and those two together.
1234
+ "@sveltejs/kit": "^2.70.2",
1235
+ // 7.x, matching what `sv create` installs. It peer-requires vite ^8, so
1236
+ // this line and the `vite` pin move together or not at all — and the React
1237
+ // preset's plugin has the same constraint, which is why the two presets
1238
+ // share one Vite major rather than each choosing.
1239
+ "@sveltejs/vite-plugin-svelte": "^7.1.2",
1240
+ "@tailwindcss/vite": "^4.1.5",
1241
+ "@types/node": "^20.19.43",
1242
+ svelte: "^5.56.9",
1243
+ "svelte-check": "^4.7.6",
1244
+ tailwindcss: "^4.1.5",
1245
+ "tw-animate-css": "^1.2.4",
1246
+ tsx: "^4.19.2",
1247
+ // 6.x, the major `sv create` pins. svelte-check peer-accepts `^5 || ^6`;
1248
+ // 7 is out but not yet in that range, so this tracks the canonical
1249
+ // scaffold rather than latest.
1250
+ typescript: "^6.0.3",
1251
+ vite: "^8.0.16"
1252
+ },
1253
+ // svelte-check REPLACES `tsc --noEmit` here rather than joining it.
1254
+ //
1255
+ // It is a superset: reading the same tsconfig, it checks `xano/`'s TypeScript
1256
+ // exactly as `tsc` would AND the components `tsc` cannot parse at all. Running
1257
+ // both is not merely redundant — `tsc` fails outright on the UI kit's barrels,
1258
+ // which re-export types from `.svelte` modules it only knows as default
1259
+ // exports. Verified against a real scaffold: a type error planted in
1260
+ // `xano/index.ts` and one planted in `App.svelte` are each caught by this
1261
+ // command alone.
1262
+ //
1263
+ // `svelte-kit sync` runs first, and is not optional: it generates
1264
+ // `.svelte-kit/tsconfig.json` (which the project's tsconfig extends) and the
1265
+ // route types. Without it svelte-check fails on a missing extends target
1266
+ // rather than on anything the user wrote.
1267
+ checkCmd: "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
1268
+ // SvelteKit supplies `$lib` on both sides — the Vite alias from its plugin
1269
+ // and the tsconfig path from the config it generates. Declaring either by
1270
+ // hand would be a second source of truth that can silently disagree.
1271
+ aliasName: null,
1272
+ aliasTarget: "frontend/src/lib",
1273
+ tsconfigPaths: {},
1274
+ tsconfigExtends: "./.svelte-kit/tsconfig.json",
1275
+ // What `svelte-kit sync` generates and the extended config lists — re-added
1276
+ // because our `include` replaces that config's rather than merging with it.
1277
+ // These are the declarations behind `$app/*`, `$env/*`, and `./$types`.
1278
+ tsconfigInclude: [
1279
+ ".svelte-kit/ambient.d.ts",
1280
+ ".svelte-kit/env.d.ts",
1281
+ ".svelte-kit/non-ambient.d.ts",
1282
+ ".svelte-kit/types/**/$types.d.ts"
1283
+ ],
1284
+ // `prepare` runs on `npm install`, so a fresh clone has `.svelte-kit/`
1285
+ // before anything reads tsconfig.json.
1286
+ extraScripts: { prepare: "svelte-kit sync" },
1287
+ // shadcn-svelte's generated components import these from `$lib/utils.js`
1288
+ // alongside `cn()`. Without them the scaffold type-checks until the first
1289
+ // `npx shadcn-svelte@latest add <name>` — which the agent guidance tells
1290
+ // assistants to run — and then fails inside components the user never wrote,
1291
+ // with an error naming a file they have no reason to suspect.
1292
+ //
1293
+ // Verbatim from shadcn-svelte's own utils.ts, so a component the CLI writes
1294
+ // resolves against exactly what upstream expects.
1295
+ libUtilsExtra: `
1296
+ export type WithoutChild<T> = T extends { child?: any } ? Omit<T, "child"> : T;
1297
+ export type WithoutChildren<T> = T extends { children?: any } ? Omit<T, "children"> : T;
1298
+ export type WithoutChildrenOrChild<T> = WithoutChildren<WithoutChild<T>>;
1299
+ export type WithElementRef<T, U extends HTMLElement = HTMLElement> = T & { ref?: U | null };
1300
+ `,
1301
+ gitignoreEntries: [".svelte-kit/"],
1302
+ // No `jsx`. `verbatimModuleSyntax` is what svelte-check expects so that
1303
+ // type-only imports in components are erased rather than emitted.
1304
+ tsconfigOptions: { verbatimModuleSyntax: true },
1305
+ viteImports: [
1306
+ `import { sveltekit } from "@sveltejs/kit/vite";`,
1307
+ `import adapter from "@sveltejs/adapter-static";`,
1308
+ `import tailwindcss from "@tailwindcss/vite";`
1309
+ ],
1310
+ // tailwindcss() before sveltekit() — the order Tailwind v4 documents for
1311
+ // SvelteKit, so the stylesheet is processed before Kit consumes the graph.
1312
+ //
1313
+ // The whole SvelteKit config rides in the sveltekit() call. There is no
1314
+ // svelte.config.js by design — see renderSvelteKitPlugin().
1315
+ vitePlugins: ["tailwindcss()", renderSvelteKitPlugin()],
1316
+ // SvelteKit resolves its own paths from this file's directory and redirects
1317
+ // them into frontend/ via `files`; moving Vite's root under it puts the two
1318
+ // into disagreement. Output is the adapter's job, not `build.outDir`.
1319
+ viteRoot: null,
1320
+ viteBuild: null,
1321
+ // SvelteKit owns the page template — frontend/src/app.html. No `entryScript`
1322
+ // follows: there is no shared index.html for it to point at.
1323
+ ownsHtmlEntry: true,
1324
+ files(vars, landing) {
1325
+ const ui = "frontend/src/lib/components/ui";
1326
+ return [
1327
+ { path: "components.json", content: renderComponentsJson() },
1328
+ { path: "frontend/src/app.html", content: renderAppHtml(vars) },
1329
+ { path: "frontend/src/app.d.ts", content: renderAppDts() },
1330
+ { path: "frontend/src/routes/+layout.ts", content: renderLayoutTs() },
1331
+ { path: "frontend/src/routes/+layout.svelte", content: renderLayoutSvelte() },
1332
+ { path: "frontend/src/routes/+page.svelte", content: renderApp(landing) },
1333
+ { path: "frontend/src/routes/+error.svelte", content: renderErrorSvelte() },
1334
+ { path: "frontend/src/routes/404/+page.svelte", content: renderNotFoundRoute() },
1335
+ { path: "frontend/src/lib/components/error-state.svelte", content: renderErrorState() },
1336
+ // `kit.files.assets` points here: static files copied to the site root
1337
+ // verbatim. A README rather than a .gitkeep because this one gets
1338
+ // PUBLISHED — everything here lands in frontend/dist, so the placeholder
1339
+ // that keeps the directory in git is a file real users will see deployed.
1340
+ {
1341
+ path: "frontend/static/README.md",
1342
+ content: `Files here are copied to the site root as-is \u2014 \`favicon.png\` is served
1343
+ at \`/favicon.png\`. Reference them from a component with a root-relative
1344
+ path, or from \`app.html\` via \`%sveltekit.assets%\`.
1345
+
1346
+ Delete this file once you add something real.
1347
+ `
1348
+ },
1349
+ { path: `${ui}/button/button.svelte`, content: renderButtonSvelte() },
1350
+ { path: `${ui}/button/index.ts`, content: renderButtonIndex() },
1351
+ {
1352
+ path: `${ui}/card/card.svelte`,
1353
+ content: cardPart(
1354
+ "card",
1355
+ "div",
1356
+ "flex flex-col gap-6 rounded-xl border bg-card py-6 text-card-foreground shadow-sm"
1357
+ )
1358
+ },
1359
+ {
1360
+ path: `${ui}/card/card-header.svelte`,
1361
+ content: cardPart(
1362
+ "card-header",
1363
+ "div",
1364
+ "@container/card-header grid auto-rows-min grid-rows-[auto_auto] items-start gap-2 px-6 has-data-[slot=card-action]:grid-cols-[1fr_auto] [.border-b]:pb-6"
1365
+ )
1366
+ },
1367
+ {
1368
+ path: `${ui}/card/card-title.svelte`,
1369
+ content: cardPart("card-title", "div", "leading-none font-semibold")
1370
+ },
1371
+ {
1372
+ path: `${ui}/card/card-description.svelte`,
1373
+ content: cardPart("card-description", "div", "text-sm text-muted-foreground")
1374
+ },
1375
+ {
1376
+ path: `${ui}/card/card-content.svelte`,
1377
+ content: cardPart("card-content", "div", "px-6")
1378
+ },
1379
+ {
1380
+ path: `${ui}/card/card-footer.svelte`,
1381
+ content: cardPart("card-footer", "div", "flex items-center px-6 [.border-t]:pt-6")
1382
+ },
1383
+ { path: `${ui}/card/index.ts`, content: renderCardIndex() }
1384
+ ];
1385
+ },
1386
+ readmeFrontendSection() {
1387
+ return `[SvelteKit](https://svelte.dev/docs/kit) with Svelte 5, styled with
1388
+ [Tailwind CSS](https://tailwindcss.com) v4 and
1389
+ [shadcn-svelte](https://shadcn-svelte.com).
1390
+
1391
+ Pages live in [\`frontend/src/routes/\`](frontend/src/routes/) \u2014 \`+page.svelte\`
1392
+ is a page, a subdirectory is a nested route. Routes are **prerendered**: each
1393
+ becomes its own HTML document at build time, so a page loads as itself rather
1394
+ than as a shell that fills in afterwards, and an unmatched path returns a real
1395
+ 404 from [\`+error.svelte\`](frontend/src/routes/+error.svelte).
1396
+
1397
+ > **There is no server.** \`npm run xano:deploy\` ships this app to a static host
1398
+ > with no runtime of its own; Xano is the backend, reached through
1399
+ > [\`frontend/src/lib/api.ts\`](frontend/src/lib/api.ts). So \`+page.server.ts\`,
1400
+ > form actions, and server \`load\` have nothing to run on \u2014 and **nothing warns
1401
+ > you**: a project using them builds and deploys green, then fails in the
1402
+ > browser. Treat them as unavailable. That is the trade \u2014 the backend is
1403
+ > authored in [\`xano/\`](xano/) as TypeScript and deployed alongside the
1404
+ > frontend, so it is a real backend, just not this one.
1405
+ >
1406
+ > \`frontend/src/routes/+layout.ts\` sets \`prerender = true\` for the whole app.
1407
+ > Because prerendering renders at build time, module-scope \`window\`/\`document\`
1408
+ > access now fails the **build** rather than the browser \u2014 use \`onMount\`, or
1409
+ > guard with \`import { browser } from "$app/environment"\`.
1410
+
1411
+ **A dynamic route needs \`entries\`, or the build fails.** A route like
1412
+ \`/posts/[id]\` cannot be prerendered unless the build knows which ids exist, so
1413
+ the build stops and names it \u2014 deliberately, rather than shipping a page that
1414
+ 404s for real users:
1415
+
1416
+ \`\`\`ts
1417
+ // frontend/src/routes/posts/[id]/+page.ts
1418
+ export const entries = () => [{ id: "1" }, { id: "2" }];
1419
+ \`\`\`
1420
+
1421
+ [\`frontend/src/routes/404/+page.svelte\`](frontend/src/routes/404/+page.svelte)
1422
+ prerenders to \`404.html\`, which is what makes an unmatched path return a real
1423
+ 404. It has to be a route: SvelteKit never prerenders \`+error.svelte\` to a file,
1424
+ so that alone would ship no \`404.html\` at all.
1425
+
1426
+ shadcn-svelte is not a dependency \u2014
1427
+ its components are copied into
1428
+ [\`frontend/src/lib/components/ui/\`](frontend/src/lib/components/ui/) and owned by
1429
+ this project, so edit them freely. \`Button\` and \`Card\` are already there; add
1430
+ more with:
1431
+
1432
+ \`\`\`bash
1433
+ npx shadcn-svelte@latest add dialog input form
1434
+ \`\`\`
1435
+
1436
+ [\`components.json\`](components.json) is pre-configured, so that works with no
1437
+ \`shadcn-svelte init\` step. Icons are [Lucide](https://lucide.dev/icons),
1438
+ installed as \`@lucide/svelte\`. Import one per module, with the icon name
1439
+ kebab-cased into the path:
1440
+
1441
+ \`\`\`ts
1442
+ import ArrowRight from "@lucide/svelte/icons/arrow-right";
1443
+ \`\`\`
1444
+
1445
+ [\`frontend/src/routes/+page.svelte\`](frontend/src/routes/+page.svelte) already
1446
+ does, and that is the form \`npx shadcn-svelte@latest add\` writes too.
1447
+
1448
+ Components import through the \`$lib\` alias
1449
+ (\`$lib/components/ui/button\`, \`$lib/utils\`), which SvelteKit points at
1450
+ \`frontend/src/lib/\` via \`kit.files\` in
1451
+ [\`vite.config.ts\`](vite.config.ts) \u2014 there is no \`paths\` entry to keep in
1452
+ sync, and adding one would just be a second answer that can disagree.
1453
+
1454
+ To rebrand, edit the color tokens at the top of
1455
+ [\`frontend/src/index.css\`](frontend/src/index.css). Tailwind v4 has no
1456
+ \`tailwind.config.js\`; the theme lives in that stylesheet.
1457
+
1458
+ > \`npm run typecheck\` runs \`svelte-kit sync && svelte-check\`, not \`tsc\`. It
1459
+ > checks both halves \u2014 the backend's TypeScript and the components \u2014 where
1460
+ > \`tsc\` cannot read \`.svelte\` files at all. Keep it in the script: it is what
1461
+ > makes the frontend unable to drift from the backend defs. \`sync\` regenerates
1462
+ > \`.svelte-kit/\`, which \`tsconfig.json\` extends; \`npm install\` runs it too.`;
1463
+ },
1464
+ agentGuidanceSection() {
1465
+ return `- \`frontend/src/\` \u2014 the SvelteKit app. Svelte 5 + Tailwind v4 + shadcn-svelte.
1466
+ - **There is no server.** This deploys to a static host with no runtime, and
1467
+ Xano is the backend. Never write \`+page.server.ts\`, \`+layout.server.ts\`,
1468
+ form actions, or server \`load\` \u2014 reach the backend through
1469
+ \`frontend/src/lib/api.ts\` instead, and never stand up a second backend here.
1470
+ - **The build will not stop you.** A project containing \`+page.server.ts\`
1471
+ compiles and deploys green, then fails in the browser on the live site. A
1472
+ passing build is not evidence that a server feature works \u2014 there is
1473
+ nothing to run it.
1474
+ - \`frontend/src/routes/\` \u2014 file-based routing. A page is \`+page.svelte\`, a
1475
+ nested route is a subdirectory. **Routes live under \`frontend/src/\`, not a
1476
+ top-level \`src/\`** \u2014 \`files\` in the \`sveltekit()\` plugin config in
1477
+ \`vite.config.ts\` points SvelteKit here. A file added under a top-level
1478
+ \`src/routes/\` is not a route and is never served.
1479
+ - **Routes are prerendered.** \`frontend/src/routes/+layout.ts\` sets
1480
+ \`prerender = true\` for the whole app, so every route is rendered to its own
1481
+ HTML document at build time and served as a real page. A static route needs
1482
+ nothing registered \u2014 add \`+page.svelte\` and it works.
1483
+ - **Prerendering renders at BUILD time**, so module-scope \`window\`/\`document\`
1484
+ access now breaks the build, not the browser. Use \`onMount\`, or guard with
1485
+ \`import { browser } from "$app/environment"\`. This is a page option, not a
1486
+ server \u2014 do not "fix" it by reaching for \`ssr\` or a server file.
1487
+ - **A dynamic route needs \`entries\`, or the build fails.** \`/posts/[id]\`
1488
+ cannot be prerendered unless the build knows which ids exist, so the build
1489
+ stops and names the route. Export
1490
+ \`const entries = () => [{ id: "1" }, { id: "2" }]\` from that route's
1491
+ \`+page.ts\`. This is the single most likely thing to catch you out when
1492
+ adding a detail page \u2014 and it is a build error, not a runtime surprise, so
1493
+ you will see it immediately.
1494
+ - \`frontend/src/routes/404/+page.svelte\` prerenders to \`404.html\`, which is
1495
+ what makes an unmatched path return a real 404 instead of silently serving a
1496
+ page with a 200. Keep it: without it a missing asset comes back as HTML and
1497
+ the browser reports \`Unexpected token '<'\`. It has to be a route \u2014 SvelteKit
1498
+ never prerenders \`+error.svelte\` to a file, so that alone would ship no
1499
+ \`404.html\`.
1500
+ - Do NOT add \`fallback\` to the adapter config. It writes an empty shell over
1501
+ the prerendered home page, and it turns the un-prerenderable-route build
1502
+ error into a silent runtime 404.
1503
+ - Data loading: call \`api.ts\` from the component, or from a universal
1504
+ \`+page.ts\` \`load\` if you need it before render. Both run in the browser.
1505
+ - \`frontend/src/lib/components/ui/\` \u2014 shadcn-svelte components, **copied in and
1506
+ owned by this project**. Edit them directly; there is no library to configure
1507
+ around.
1508
+ - Need one that isn't there? \`npx shadcn-svelte@latest add <name>\` \u2014 do not
1509
+ hand-roll it, and do not add a different component library. Note the
1510
+ \`-svelte\` suffix: the plain \`shadcn\` CLI writes React and will not work here.
1511
+ - Icons are [Lucide](https://lucide.dev/icons), already installed as
1512
+ \`@lucide/svelte\` \u2014 **not** \`lucide-react\`, which is the wrong package here in
1513
+ the same way the plain \`shadcn\` CLI is.
1514
+ - **Import icons one per module, and kebab-case the path.** The icon is the
1515
+ module's DEFAULT export, and \`ArrowRight\` lives at \`arrow-right\`:
1516
+ \`import ArrowRight from "@lucide/svelte/icons/arrow-right";\` \u2014
1517
+ \`frontend/src/routes/+page.svelte\` already does. This is the form
1518
+ \`npx shadcn-svelte@latest add\` writes, so matching it keeps the components
1519
+ you write consistent with the ones the CLI generates beside them. Do not add
1520
+ another icon library and do not paste raw inline \`<svg>\` markup.
1521
+ - Import via the \`$lib\` alias (\`$lib/components/ui/button\`, \`$lib/utils\`),
1522
+ which SvelteKit generates for both TypeScript and the bundler. Do not add a
1523
+ \`paths\` entry for it \u2014 a hand-written one is a second source of truth that
1524
+ can disagree with the generated one.
1525
+ - Components are Svelte 5 **runes** (\`$props()\`, \`$bindable()\`,
1526
+ \`{@render children?.()}\`) \u2014 not the Svelte 4 \`export let\` / slot API. Runes
1527
+ mode is FORCED in \`vite.config.ts\`, so \`export let\` is a compile error
1528
+ naming the file rather than a component that quietly builds in legacy mode.
1529
+ Do not "fix" that error by relaxing \`compilerOptions.runes\` \u2014 write the
1530
+ rune.
1531
+ - Style with the semantic tokens (\`bg-primary\`, \`text-muted-foreground\`,
1532
+ \`border-input\`), never raw palette classes like \`bg-gray-100\` \u2014 the tokens are
1533
+ defined in \`frontend/src/index.css\`, which is also where you rebrand. Tailwind
1534
+ v4 has no \`tailwind.config.js\`.
1535
+ - \`npm run typecheck\` runs \`svelte-kit sync && svelte-check\`, which checks both
1536
+ \`xano/\` and the components. Do not swap it for \`tsc --noEmit\`: \`tsc\` cannot
1537
+ read \`.svelte\` files and fails on the UI kit's barrels. \`sync\` regenerates
1538
+ \`.svelte-kit/\`, which \`tsconfig.json\` extends \u2014 run it after adding a route.`;
1539
+ }
1540
+ };
1541
+
1542
+ // src/emit/frontend-presets.ts
1543
+ var FRAMEWORKS = ["react", "svelte"];
1544
+ var DEFAULT_FRAMEWORK = "react";
1545
+ var PRESETS = {
1546
+ react: reactPreset,
1547
+ svelte: sveltePreset
1548
+ };
1549
+ function findFrontendPreset(id) {
1550
+ const normalized = id.trim().toLowerCase();
1551
+ return FRAMEWORKS.includes(normalized) ? PRESETS[normalized] : void 0;
1552
+ }
1553
+ function allFrontendPresets() {
1554
+ return FRAMEWORKS.map((id) => PRESETS[id]);
1555
+ }
1556
+ function resolveFrameworkFlag(raw) {
1557
+ const preset = findFrontendPreset(raw);
1558
+ if (preset === void 0) {
1559
+ throw new Error(
1560
+ `Unknown --framework "${raw}". Valid frameworks: ${FRAMEWORKS.join(", ")}.`
1561
+ );
1562
+ }
1563
+ return preset;
1564
+ }
1565
+
1566
+ // src/emit/frontend-resolve.ts
1567
+ function defaultFrontendPreset() {
1568
+ const preset = findFrontendPreset(DEFAULT_FRAMEWORK);
1569
+ if (preset === void 0) {
1570
+ throw new Error(`Default frontend preset "${DEFAULT_FRAMEWORK}" is missing from the table.`);
1571
+ }
1572
+ return preset;
1573
+ }
1574
+ async function promptFramework() {
1575
+ const presets = allFrontendPresets();
1576
+ const rl = createInterface({ input: process.stdin, output: process.stderr });
1577
+ try {
1578
+ process.stderr.write(
1579
+ `
1580
+ Which frontend framework?
1581
+ ` + presets.map((p, i) => ` ${i + 1}) ${p.label}${p.id === DEFAULT_FRAMEWORK ? " (default)" : ""}`).join("\n") + `
1582
+ `
1583
+ );
1584
+ const answer = await rl.question(`Enter a number or name, or leave blank for the default: `);
1585
+ const token = answer.trim().toLowerCase();
1586
+ if (token === "") return defaultFrontendPreset();
1587
+ const byIndex = Number.parseInt(token, 10);
1588
+ if (Number.isInteger(byIndex) && byIndex >= 1 && byIndex <= presets.length) {
1589
+ return presets[byIndex - 1];
1590
+ }
1591
+ return findFrontendPreset(token) ?? defaultFrontendPreset();
1592
+ } finally {
1593
+ rl.close();
1594
+ }
1595
+ }
1596
+ async function resolveFrontendPreset(flag) {
1597
+ if (flag !== void 0 && flag !== "") return resolveFrameworkFlag(flag);
1598
+ if (process.stdin.isTTY && process.stderr.isTTY) return promptFramework();
1599
+ return defaultFrontendPreset();
1600
+ }
1601
+
1602
+ // src/emit/init-command.ts
1603
+ function sanitizeAppName(raw) {
1604
+ const name = raw.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
1605
+ return name === "" ? "app" : name;
1606
+ }
1607
+ function projectShellFiles(vars, preset, parts) {
1608
+ return [
1609
+ { path: "package.json", content: renderPackageJson(vars, preset) },
1610
+ { path: "tsconfig.json", content: renderTsconfig(preset) },
1611
+ { path: "vite.config.ts", content: renderViteConfig(preset) },
1612
+ { path: ".gitignore", content: renderGitignore(preset) },
1613
+ { path: ".env.example", content: renderEnvExample() },
1614
+ { path: "README.md", content: parts.readme },
1615
+ // Skipped when the framework supplies its own entry document — see
1616
+ // FrontendPreset.ownsHtmlEntry. A second index.html beside SvelteKit's
1617
+ // app.html would never be served and would still read as the entry point.
1618
+ ...preset.ownsHtmlEntry === true ? [] : [{ path: "frontend/index.html", content: renderIndexHtml(vars, preset) }],
1619
+ // Shared across every framework: both UI kits resolve against the same
1620
+ // Tailwind v4 semantic tokens, back `cn()` with clsx + tailwind-merge, and
1621
+ // look for library code at frontend/src/lib/. Only the alias NAME pointing
1622
+ // at that directory differs, and the preset owns that.
1623
+ { path: "frontend/src/index.css", content: renderIndexCss() },
1624
+ { path: "frontend/src/lib/api.ts", content: renderApiTs() },
1625
+ { path: "frontend/src/lib/utils.ts", content: renderCnUtil(preset.libUtilsExtra) },
1626
+ // The framework's own half: entry module, app component, vendored UI kit,
1627
+ // and whatever tool config that kit's CLI reads.
1628
+ ...preset.files(vars, parts.landing)
1629
+ ];
1630
+ }
1631
+ function buildFileSet(vars, preset) {
1632
+ return [
1633
+ ...projectShellFiles(vars, preset, {
1634
+ readme: renderReadme(vars, preset),
1635
+ landing: initLanding(vars)
1636
+ }),
1637
+ { path: "xano/index.ts", content: renderXanoIndex(vars) },
1638
+ { path: "xano/EXAMPLE.md", content: renderXanoExampleMd(vars) }
1639
+ ];
1640
+ }
1641
+ async function runInitCommand(args) {
1642
+ const targetArg = args.positionals[0] ?? ".";
1643
+ const targetDir = resolve(targetArg);
1644
+ const appName = sanitizeAppName(args.name ?? basename(targetDir));
1645
+ const preset = await resolveFrontendPreset(args.framework);
1646
+ const presets = await resolveAiPresets(args.ai);
1647
+ const vars = { appName, sdkVersion: readVersion() };
1648
+ step(`Scaffolding ${style.bold(appName)} (${preset.label}) in ${targetDir}`);
1649
+ const result = await scaffoldProject({
1650
+ targetDir,
1651
+ files: buildFileSet(vars, preset),
1652
+ presets,
1653
+ appName,
1654
+ force: args.force,
1655
+ noInstall: args.noInstall,
1656
+ // An `init` project's `xano/` is hand-authored, never machine-written: it is
1657
+ // not refreshable, and `--force` must not clear it.
1658
+ regenerable: false,
1659
+ sdkVersion: readVersion(),
1660
+ frontend: preset
1661
+ });
1662
+ if (presets.length > 0) {
1663
+ info(`AI instructions: ${presets.map(presetFilePath).join(", ")}`);
1664
+ }
1665
+ blank();
1666
+ success("Project ready.");
1667
+ const cdHint = targetDir === process.cwd() ? "" : ` cd ${targetArg}
1668
+ `;
1669
+ detail(
1670
+ `Next steps:
1671
+ ` + cdHint + (result.install === "installed" ? `` : ` npm install
1672
+ `) + ` npm run dev # run the frontend
1673
+ xanots login # authenticate with Xano
1674
+ npm run xano:deploy # build the frontend, then deploy \u2192 live ephemeral URL
1675
+
1676
+ The first export or deploy writes xano/xano.lock \u2014 commit it. It pins each
1677
+ object's identity, so renaming one later renames it instead of deleting and
1678
+ recreating it. See "xano.lock \u2014 commit it" in the README.`
1679
+ );
1680
+ }
1681
+
1682
+ export {
1683
+ describeOrigin,
1684
+ renderCodegenMarker,
1685
+ renderCodegenReadme,
1686
+ codegenLanding,
1687
+ resolveFrontendPreset,
1688
+ sanitizeAppName,
1689
+ projectShellFiles,
1690
+ runInitCommand
1691
+ };
1692
+ //# sourceMappingURL=chunk-WKP4D5MO.js.map