create-acrylblends 0.2.5 → 0.2.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/docs/framework/UPSTREAM.md +1 -1
- package/docs/framework/guides/data.md +101 -2
- package/docs/framework/upstream.json +2 -2
- package/package.json +2 -2
- package/templates/chat/package.json +5 -2
- package/templates/nodejs/package.json +2 -2
- package/templates/notes/package.json +5 -2
package/dist/index.js
CHANGED
|
@@ -406,6 +406,7 @@ ${template === "notes" ? `
|
|
|
406
406
|
|
|
407
407
|
- \`src/db.ts\`: \`openNotesDb()\` (the \`db\` port on a SQLite file, \`data/notes.sqlite\` or \`$NOTES_DB\`, with \`migrations/\` applied on start; it returns \`{ db, close }\`) and \`notesStore(db)\`, the queries for notes. Every \`db\` call returns a promise: \`await\` it. Use \`?\` bindings, never string-built SQL. See \`docs/framework/guides/data.md\`.
|
|
408
408
|
- \`migrations/\`: the shape of the database, one numbered file per change (\`001-notes.sql\`). A file that has run is never edited; a change is the next file (\`002-name.sql\`).
|
|
409
|
+
- **The dependency rule:** only \`src/db.ts\` (the \`opener\` in \`package.json\`) opens the database. Every other file takes a \`Db\` (\`import type { Db } from '${PACKAGE}/db'\`) as an argument and never imports \`node:sqlite\`, \`pg\`, another driver or \`${PACKAGE}/db/sqlite\`. \`npm test\` and \`npm run check\` run \`${PACKAGE} check-deps\`, which names the file and line of a violation; do not move the \`opener\` entry to silence it.
|
|
409
410
|
- \`src/auth.ts\`: scrypt password hashes (\`node:crypto\`) and the \`sessions\` table; the cookie \`sid\` holds a random token.
|
|
410
411
|
- \`src/schema.ts\`: the rules for a note and for credentials. The HTML forms and the JSON API both use \`checkNote\`.
|
|
411
412
|
- \`src/views.tsx\`: the pages, as JSX components rendered to strings, and the small script for the instant filter.
|
|
@@ -427,6 +428,7 @@ Read \`docs/framework/getting-started/deploy.md\`. In short:
|
|
|
427
428
|
` : ""}${template === "chat" ? `
|
|
428
429
|
## Structure (a chat app: a streamed answer, history in a database)
|
|
429
430
|
|
|
431
|
+
- **The dependency rule:** only \`src/db.ts\` (the \`opener\` in \`package.json\`) opens the database. Every other file takes a \`Db\` (\`import type { Db } from '${PACKAGE}/db'\`) as an argument and never imports \`node:sqlite\`, \`pg\`, another driver or \`${PACKAGE}/db/sqlite\`. \`npm test\` and \`npm run check\` run \`${PACKAGE} check-deps\`, which names the file and line of a violation; do not move the \`opener\` entry to silence it.
|
|
430
432
|
- \`src/llm.ts\`: \`Llm\`, what the app needs from a model (messages in, pieces out, an aborted signal stops the work), and \`openAiCompatible\`, which calls an OpenAI-compatible chat completions API with \`stream: true\`. The base URL is \`DEEPSEEK_BASE_URL\` (default \`https://api.deepseek.com\`), the model \`DEEPSEEK_MODEL\` (default \`deepseek-chat\`), the key **only** the environment variable \`DEEPSEEK_API_KEY\`, read at the moment of the call: never write it to a file, a response or a log.
|
|
431
433
|
- \`src/db.ts\`: \`openChatDb()\` (the \`db\` port on a SQLite file, \`data/chat.sqlite\` or \`$CHAT_DB\`, with \`migrations/\` applied on start; it returns \`{ db, close }\`) and \`chatStore(db)\`. The routes only call \`chatStore\`; keep SQL out of them. Every \`db\` call returns a promise: \`await\` it. The shape of the database is \`migrations/NNN-name.sql\`: to change it add the next numbered file and never edit one that has run. See \`docs/framework/guides/data.md\`.
|
|
432
434
|
- \`src/app.ts\` opens the database (top-level \`await\`) and exports the app and \`close\`; \`src/index.ts\` serves it and closes the database on SIGTERM. \`src/chat-app.ts\`: \`createApp(db, llm)\`. \`POST /api/chat\` answers Server-Sent Events: \`meta\` (the conversation id), a \`token\` per piece, then \`done\` or \`error\`. The request's signal (\`c.req.raw.signal\`) goes to the model call, so a closed tab or the Stop button stops the request to the model; what had arrived is kept.
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../src/names.ts","../src/source.ts","../src/spawn.ts","../src/index.ts"],"sourcesContent":["/**\n * The one place this package names the framework. The templates are written with `__PACKAGE__` and `__RANGE__` (the range is stamped at create time from the framework version this package carries, see `frameworkRange`), and the text of `AGENTS.md` with\n * `__PACKAGE__`, so a rename (for example to `acryl`) is a change here and in `scripts/lib/names.mjs`, which a test keeps equal.\n */\nexport const PACKAGE = 'acrylblends'\nexport const CLASS = 'Acryl'\nexport const CREATE = 'create-acrylblends'\n\n/** The file that makes a folder a template other people can create apps from (`${CREATE} <name> github:owner/repo`). */\nexport const TEMPLATE_MANIFEST = 'acryl.template.json'\n","/**\n * Templates from outside this package: `github:owner/repo[#ref]`, a scoped npm package (`@scope/name[@version]`) or a packed tarball on disk.\n * A source is only ever downloaded and unpacked: no git clone (hooks), no lifecycle script (`npm pack --ignore-scripts`), nothing of it is run.\n */\nimport { spawnSync } from 'node:child_process'\nimport {\n cpSync,\n existsSync,\n lstatSync,\n mkdirSync,\n readdirSync,\n readFileSync,\n rmSync,\n writeFileSync,\n} from 'node:fs'\nimport { join, resolve } from 'node:path'\nimport { PACKAGE, TEMPLATE_MANIFEST } from './names'\n\nexport type Source =\n | { kind: 'github'; owner: string; repo: string; ref: string | undefined }\n | { kind: 'npm'; spec: string }\n | { kind: 'tarball'; path: string }\n\n/** What a template says about itself in `acryl.template.json`. */\nexport interface Manifest {\n name: string\n description: string\n /** Library plugins the template needs, added with `acrylblends add`. */\n plugins: string[]\n}\n\n/** A source that cannot be used; the message says why and is shown as it is. */\nexport class SourceError extends Error {\n override name = 'SourceError'\n}\n\nexport const SOURCE_FORMS = `github:owner/repo[#ref], @scope/name[@version], or a packed .tgz file`\n\nconst LIMITS = { files: 5000, bytes: 50 * 1024 * 1024 }\n\n/** Recognise a source argument, or return `undefined` when it is not one (so the caller can report a usage error). */\nexport function parseSource(text: string, cwd: string): Source | undefined {\n const github = /^github:([A-Za-z0-9_.-]+)\\/([A-Za-z0-9_.-]+)(?:#([A-Za-z0-9_./-]+))?$/.exec(text)\n if (github) return { kind: 'github', owner: github[1]!, repo: github[2]!, ref: github[3] }\n if (text.startsWith('github:')) throw new SourceError(`\"${text}\" is not github:owner/repo[#ref]`)\n if (/^@[a-z0-9][a-z0-9._-]*\\/[a-z0-9][a-z0-9._-]*(@[A-Za-z0-9._-]+)?$/.test(text))\n return { kind: 'npm', spec: text }\n if (text.startsWith('@')) throw new SourceError(`\"${text}\" is not @scope/name[@version]`)\n if (/\\.(tgz|tar\\.gz)$/.test(text)) {\n const path = resolve(cwd, text)\n if (!existsSync(path)) throw new SourceError(`${path} does not exist`)\n return { kind: 'tarball', path }\n }\n return undefined\n}\n\n/** How the bytes of a source are obtained; real by default, replaced in tests. */\nexport interface Fetchers {\n /** The body at a URL (a GitHub tarball). */\n download(url: string): Promise<Uint8Array>\n /** `npm pack <spec> --ignore-scripts` into `dest`; the path of the tarball. */\n pack(spec: string, dest: string): string\n}\n\nexport const realFetchers: Fetchers = {\n async download(url) {\n const response = await fetch(url, { redirect: 'follow' })\n if (!response.ok) throw new SourceError(`${url} answered ${response.status}`)\n return new Uint8Array(await response.arrayBuffer())\n },\n pack(spec, dest) {\n const result = spawnSync(\n 'npm',\n ['pack', spec, '--ignore-scripts', '--json', '--pack-destination', dest],\n {\n encoding: 'utf8',\n shell: false,\n env: { ...process.env, npm_config_ignore_scripts: 'true' },\n },\n )\n if (result.status !== 0)\n throw new SourceError(\n `npm could not pack ${spec}: ${(result.stderr || result.stdout).trim().split('\\n').at(-1)}`,\n )\n const file = (JSON.parse(result.stdout) as { filename: string }[])[0]?.filename\n if (!file) throw new SourceError(`npm packed nothing for ${spec}`)\n return join(dest, file)\n },\n}\n\n/** Unpack a tarball into `dir`, dropping its single top folder; refuses links, paths that leave the folder, and archives that are too big. */\nfunction extract(tarball: string, dir: string): void {\n const list = spawnSync('tar', ['-tzf', tarball], {\n encoding: 'utf8',\n maxBuffer: 64 * 1024 * 1024,\n })\n if (list.status !== 0) throw new SourceError(`${tarball} is not a readable tar.gz archive`)\n const entries = list.stdout.split('\\n').filter(Boolean)\n if (entries.length > LIMITS.files)\n throw new SourceError(`the template has more than ${LIMITS.files} files`)\n for (const entry of entries)\n if (entry.startsWith('/') || entry.split('/').includes('..'))\n throw new SourceError(`the archive holds a path that leaves its folder: ${entry}`)\n mkdirSync(dir, { recursive: true })\n const run = spawnSync('tar', ['-xzf', tarball, '-C', dir, '--strip-components=1'], {\n encoding: 'utf8',\n })\n if (run.status !== 0) throw new SourceError(`could not unpack ${tarball}: ${run.stderr.trim()}`)\n let bytes = 0\n const walk = (folder: string) => {\n for (const entry of readdirSync(folder)) {\n const path = join(folder, entry)\n const info = lstatSync(path)\n if (info.isSymbolicLink())\n throw new SourceError(\n `the template holds a symbolic link (${path.slice(dir.length + 1)}); links are not allowed`,\n )\n if (info.isDirectory()) walk(path)\n else bytes += info.size\n }\n }\n walk(dir)\n if (bytes > LIMITS.bytes)\n throw new SourceError(`the template is larger than ${LIMITS.bytes / 1024 / 1024} MB`)\n}\n\n/** Download or pack a source and unpack it into `dir` (which must not exist yet). Nothing in it is run. */\nexport async function fetchSource(\n source: Source,\n dir: string,\n scratch: string,\n fetchers: Fetchers,\n): Promise<void> {\n mkdirSync(scratch, { recursive: true })\n let tarball: string\n if (source.kind === 'tarball') tarball = source.path\n else if (source.kind === 'npm') tarball = fetchers.pack(source.spec, scratch)\n else {\n tarball = join(scratch, 'source.tar.gz')\n writeFileSync(\n tarball,\n await fetchers.download(\n `https://codeload.github.com/${source.owner}/${source.repo}/tar.gz/${source.ref ?? 'HEAD'}`,\n ),\n )\n }\n extract(tarball, dir)\n}\n\n/** Read and check `acryl.template.json`; a source without it is not a template. */\nexport function readManifest(dir: string): Manifest {\n const file = join(dir, TEMPLATE_MANIFEST)\n if (!existsSync(file))\n throw new SourceError(\n `this source has no ${TEMPLATE_MANIFEST}, so it is not a template: add one with a name and a description (see the create-acrylblends guide)`,\n )\n let data: unknown\n try {\n data = JSON.parse(readFileSync(file, 'utf8'))\n } catch {\n throw new SourceError(`${TEMPLATE_MANIFEST} is not valid JSON`)\n }\n const m = data as Record<string, unknown>\n if (typeof m.name !== 'string' || m.name.trim() === '')\n throw new SourceError(`${TEMPLATE_MANIFEST} needs a \"name\"`)\n if (typeof m.description !== 'string')\n throw new SourceError(`${TEMPLATE_MANIFEST} needs a \"description\"`)\n const plugins = m.plugins ?? []\n if (\n !Array.isArray(plugins) ||\n plugins.some((p) => typeof p !== 'string' || !/^[a-z][a-z0-9-]*$/.test(p))\n )\n throw new SourceError(\n `\"plugins\" in ${TEMPLATE_MANIFEST} is a list of plugin names such as \"desktop\"`,\n )\n return { name: m.name, description: m.description, plugins: plugins as string[] }\n}\n\nconst SKIP = new Set(['.git', 'node_modules', TEMPLATE_MANIFEST])\n/** Lifecycle scripts npm runs on `npm install` in the app's own folder. */\nexport const LIFECYCLE = [\n 'preinstall',\n 'install',\n 'postinstall',\n 'prepublish',\n 'preprepare',\n 'prepare',\n 'postprepare',\n]\n\nconst isText = (buffer: Buffer) => !buffer.subarray(0, 8000).includes(0)\n\n/**\n * Copy the unpacked template into `target`, replacing the placeholders of the built-in templates, naming the app, and pointing a dependency on the framework at\n * the release this package carries. Returns the files written (relative paths) and the lifecycle scripts the app's package.json defines.\n */\nexport function writeTemplate(\n from: string,\n target: string,\n stamp: (text: string) => string,\n range: string,\n name: string,\n): { files: string[]; lifecycle: Record<string, string> } {\n const files: string[] = []\n const walk = (src: string, dst: string, prefix: string) => {\n mkdirSync(dst, { recursive: true })\n for (const entry of readdirSync(src, { withFileTypes: true })) {\n if (SKIP.has(entry.name)) continue\n const outName = prefix === '' && entry.name === 'gitignore' ? '.gitignore' : entry.name\n if (entry.isDirectory())\n walk(join(src, entry.name), join(dst, outName), `${prefix}${entry.name}/`)\n else {\n const buffer = readFileSync(join(src, entry.name))\n writeFileSync(join(dst, outName), isText(buffer) ? stamp(buffer.toString('utf8')) : buffer)\n files.push(`${prefix}${outName}`)\n }\n }\n }\n walk(from, target, '')\n const lifecycle: Record<string, string> = {}\n const pkgFile = join(target, 'package.json')\n if (existsSync(pkgFile)) {\n const pkg = JSON.parse(readFileSync(pkgFile, 'utf8')) as {\n name?: string\n scripts?: Record<string, string>\n dependencies?: Record<string, string>\n devDependencies?: Record<string, string>\n }\n pkg.name = name\n for (const group of [pkg.dependencies, pkg.devDependencies])\n if (group?.[PACKAGE] !== undefined) group[PACKAGE] = range\n writeFileSync(pkgFile, `${JSON.stringify(pkg, null, 2)}\\n`)\n for (const script of LIFECYCLE)\n if (typeof pkg.scripts?.[script] === 'string') lifecycle[script] = pkg.scripts[script]\n }\n return { files, lifecycle }\n}\n\n/** Remove a folder tree quietly. */\nexport const removeTree = (path: string) => rmSync(path, { recursive: true, force: true })\nexport { cpSync }\n","import { existsSync } from 'node:fs'\nimport { dirname, join } from 'node:path'\n\nexport interface Invocation {\n file: string\n args: string[]\n}\n\n/**\n * How to start a package manager without the shell option (Node warns about passing args to a shell, DEP0190, and a `.cmd` shim cannot be spawned directly).\n * Off Windows the command runs as it is. On Windows npm runs as `node npm-cli.js` (the one npm is running from, else the one beside `node`); any other\n * manager goes through `cmd.exe /d /s /c <name>.cmd`, whose arguments stay an array.\n */\nexport function packageManagerInvocation(\n command: string,\n args: readonly string[],\n platform: NodeJS.Platform = process.platform,\n env: NodeJS.ProcessEnv = process.env,\n exists: (path: string) => boolean = existsSync,\n execPath: string = process.execPath,\n): Invocation {\n if (platform !== 'win32') return { file: command, args: [...args] }\n if (command === 'npm') {\n const running = env.npm_execpath\n const cli =\n running !== undefined && /npm-cli\\.c?js$/.test(running)\n ? running\n : join(dirname(execPath), 'node_modules', 'npm', 'bin', 'npm-cli.js')\n if (exists(cli)) return { file: execPath, args: [cli, ...args] }\n }\n return { file: env.ComSpec ?? 'cmd.exe', args: ['/d', '/s', '/c', `${command}.cmd`, ...args] }\n}\n","import { spawn } from 'node:child_process'\nimport {\n cpSync,\n existsSync,\n mkdirSync,\n mkdtempSync,\n readdirSync,\n readFileSync,\n writeFileSync,\n} from 'node:fs'\nimport { createRequire } from 'node:module'\nimport { tmpdir } from 'node:os'\nimport { basename, dirname, join, resolve } from 'node:path'\nimport { createInterface } from 'node:readline/promises'\nimport { fileURLToPath } from 'node:url'\nimport { parseArgs } from 'node:util'\nimport { findSecrets } from '@webboxes/app-persistence'\nimport { CLASS, CREATE, PACKAGE, TEMPLATE_MANIFEST } from './names'\nimport {\n type Fetchers,\n fetchSource,\n LIFECYCLE,\n parseSource,\n readManifest,\n realFetchers,\n removeTree,\n SOURCE_FORMS,\n SourceError,\n writeTemplate,\n} from './source'\nimport { packageManagerInvocation } from './spawn'\n\nexport { CLASS, CREATE, PACKAGE, TEMPLATE_MANIFEST }\n\nexport const TEMPLATES = ['nodejs', 'notes', 'chat', 'bun', 'acryl-app'] as const\nexport type Template = (typeof TEMPLATES)[number]\nexport const PACKAGE_MANAGERS = ['npm', 'pnpm', 'yarn', 'bun'] as const\nexport type PackageManager = (typeof PACKAGE_MANAGERS)[number]\n\n/** The version of this package. */\nexport const VERSION: string = (\n createRequire(import.meta.url)('../package.json') as { version: string }\n).version\n\nexport const HELP = `${CREATE} ${VERSION} - create an ${CLASS} app\n\nUsage:\n npm create ${PACKAGE}@latest [directory] [source] [-- options]\n\nA source makes the app from someone else's template (it is downloaded and unpacked, nothing in it runs):\n github:owner/repo[#ref] a GitHub repository, as a tarball (no clone)\n @scope/name[@version] an npm package (npm pack --ignore-scripts)\n ./template.tgz a packed template on disk\nA template is a folder with an ${TEMPLATE_MANIFEST} (name, description, plugins).\n\nOptions:\n --template <name> nodejs, notes, chat, bun (experimental), acryl-app (asked when not given)\n --install install the dependencies after creating the app (the lifecycle scripts it will run are listed first)\n --pm <manager> ${PACKAGE_MANAGERS.join(', ')} (default: the one that ran this command, else npm)\n -y, --yes ask nothing: template nodejs unless --template is given, directory ${PACKAGE}-app\n -h, --help show this help\n -v, --version show the version\n`\n\n/** A command line mistake. The command prints it with the help text and exits 2. */\nexport class UsageError extends Error {\n override name = 'UsageError'\n}\n\nexport interface Io {\n stdout: { write(text: string): unknown }\n stderr: { write(text: string): unknown }\n cwd: string\n env: Record<string, string | undefined>\n /** Ask one question; `undefined` when there is no terminal to ask on. */\n ask: ((question: string) => Promise<string>) | undefined\n /** Run a program, showing its output; resolves to the exit code. */\n run(command: string, args: string[], cwd: string): Promise<number>\n /** How a template source is fetched; the real network and npm by default. */\n fetchers?: Fetchers\n}\n\nexport function processIo(): Io {\n const interactive = Boolean(process.stdin.isTTY && process.stdout.isTTY)\n return {\n stdout: process.stdout,\n stderr: process.stderr,\n cwd: process.cwd(),\n env: process.env,\n ask: interactive\n ? async (question) => {\n const rl = createInterface({ input: process.stdin, output: process.stdout })\n try {\n return await rl.question(question)\n } finally {\n rl.close()\n }\n }\n : undefined,\n run: (command, args, cwd) =>\n new Promise((done) => {\n const invocation = packageManagerInvocation(command, args)\n const child = spawn(invocation.file, invocation.args, { cwd, stdio: 'inherit' })\n child.on('error', () => done(1))\n child.on('exit', (code) => done(code ?? 1))\n }),\n }\n}\n\nexport interface CreateOptions {\n directory: string | undefined\n template: Template | undefined\n install: boolean\n pm: PackageManager | undefined\n yes: boolean\n /** `github:owner/repo[#ref]`, `@scope/name` or a packed `.tgz`: a template from outside this package. */\n source: string | undefined\n}\n\nexport function isTemplate(value: string): value is Template {\n return (TEMPLATES as readonly string[]).includes(value)\n}\n\nexport function parseCreateOptions(argv: readonly string[]): CreateOptions {\n let parsed: ReturnType<typeof parse>\n try {\n parsed = parse(argv)\n } catch (error) {\n throw new UsageError((error as Error).message)\n }\n const { values, positionals } = parsed\n if (positionals.length > 2)\n throw new UsageError('takes a directory and at most one template source')\n if (positionals[1] !== undefined && values.template !== undefined)\n throw new UsageError('give a template source or --template, not both')\n if (values.template !== undefined && !isTemplate(values.template))\n throw new UsageError(`unknown template \"${values.template}\" (${TEMPLATES.join(', ')})`)\n if (values.pm !== undefined && !(PACKAGE_MANAGERS as readonly string[]).includes(values.pm))\n throw new UsageError(`unknown package manager \"${values.pm}\" (${PACKAGE_MANAGERS.join(', ')})`)\n return {\n directory: positionals[0],\n template: values.template as Template | undefined,\n install: values.install === true,\n pm: values.pm as PackageManager | undefined,\n yes: values.yes === true,\n source: positionals[1],\n }\n}\n\nconst parse = (argv: readonly string[]) =>\n parseArgs({\n args: [...argv],\n allowPositionals: true,\n strict: true,\n options: {\n template: { type: 'string' },\n install: { type: 'boolean' },\n pm: { type: 'string' },\n yes: { type: 'boolean', short: 'y' },\n },\n })\n\n/** A valid package name from a directory name: lower case letters, digits and dashes. */\nexport function nameFrom(directory: string): string {\n const name = basename(resolve(directory))\n .toLowerCase()\n .replace(/[^a-z0-9-]+/g, '-')\n .replace(/^[^a-z]+/, '')\n .replace(/-+$/g, '')\n return name === '' ? 'acryl-app' : name\n}\n\nfunction walkUp(from: string, test: (dir: string) => string | undefined): string {\n let dir = from\n for (;;) {\n const found = test(dir)\n if (found) return found\n const parent = dirname(dir)\n if (parent === dir) throw new Error(`${CREATE} cannot find its files`)\n dir = parent\n }\n}\nconst here = dirname(fileURLToPath(import.meta.url))\nconst templatesRoot = () =>\n walkUp(here, (d) =>\n existsSync(join(d, 'templates', 'nodejs')) ? join(d, 'templates') : undefined,\n )\n/** The framework docs: the copy `prepack` puts in the package, or `docs/framework` of the repository. */\nconst docsRoot = () =>\n walkUp(here, (d) =>\n existsSync(join(d, 'docs', 'framework', 'README.md'))\n ? join(d, 'docs', 'framework')\n : undefined,\n )\n\n/**\n * The range a created app asks for: the framework version this package was released with, so a new app depends on the release that made it (and gets what that release's\n * commands can do), never an older one. A caret range, so it also takes the newer patch releases.\n */\nexport function frameworkRange(): string {\n const file = createRequire(import.meta.url).resolve(`${PACKAGE}/package.json`)\n return `^${(JSON.parse(readFileSync(file, 'utf8')) as { version: string }).version}`\n}\n\nexport function replacePlaceholders(text: string, name: string): string {\n return text\n .replaceAll('__APP_NAME__', name)\n .replaceAll('__PACKAGE__', PACKAGE)\n .replaceAll('__CLASS__', CLASS)\n .replaceAll('__RANGE__', frameworkRange())\n}\n\n/** The guide for a coding agent in a created app: where the API is, how to run it, what must pass. */\nexport function agentsText(template: Exclude<Template, 'acryl-app'>, name: string): string {\n const run = {\n nodejs: 'npm run dev',\n notes: 'npm run dev',\n chat: 'npm run dev',\n bun: 'bun run dev',\n }[template]\n const desktopNote =\n template === 'nodejs' || template === 'notes' || template === 'chat'\n ? `\\nTo run it as a desktop window: \\`npx ${PACKAGE} add desktop\\`, \\`npm install\\`, then \\`npm run desktop\\` (see \\`docs/framework/getting-started/desktop.md\\`).`\n : ''\n const test = {\n nodejs: 'npm test` and `npm run check',\n notes: 'npm test` and `npm run check',\n chat: 'npm test` and `npm run check',\n bun: 'bun test` and `bun run check',\n }[template]\n const jsxNote =\n template === 'nodejs' || template === 'notes' || template === 'chat'\n ? 'Write pages in `.tsx` (see `src/' +\n (template === 'notes' ? 'views.tsx' : 'page.tsx') +\n \"`): the scripts in `package.json` run Node.js with `--import acrylblends/node-server/register`, which compiles `.tsx` with this app's own `typescript`, and `tsconfig.json` sets `jsx: react-jsx` with `jsxImportSource: acrylblends/jsx`. Render a component with `.toString()` and return it with `c.html(...)`. A command that starts the app without those scripts (a bare `node src/index.ts`) cannot load a `.tsx` file. Without a build step you can write the call JSX compiles to instead: `jsx('h1', { class: 'title' }, 'Hello')` from `'acrylblends/jsx'`, children after the props. See `docs/framework/guides/jsx.md`.\"\n : \"Bun compiles `.tsx` itself: write pages in `.tsx`, render a component with `.toString()` and return it with `c.html(...)`. `jsx('h1', { class: 'title' }, 'Hello')` from `'acrylblends/jsx'` (children after the props) is the same thing without JSX syntax. See `docs/framework/guides/jsx.md`.\"\n const clientNote =\n template === 'nodejs'\n ? `- **Client components** (run in the browser) live in \\`src/client/\\`, which has its own \\`tsconfig.json\\` (DOM types, no Node types); \\`clientModules\\` in \\`src/app.ts\\` compiles them when the browser asks, and \\`npm run build\\` compiles them once for production. See \\`src/client/counter.tsx\\` and \\`docs/framework/guides/client-modules.md\\`.\\n`\n : ''\n const chatStructure =\n template === 'chat'\n ? `\n## Structure (a chat app: a streamed answer, history in a database)\n\n- \\`src/llm.ts\\`: \\`Llm\\`, what the app needs from a model (messages in, pieces out, an aborted signal stops the work), and \\`openAiCompatible\\`, which calls an OpenAI-compatible chat completions API with \\`stream: true\\`. The base URL is \\`DEEPSEEK_BASE_URL\\` (default \\`https://api.deepseek.com\\`), the model \\`DEEPSEEK_MODEL\\` (default \\`deepseek-chat\\`), the key **only** the environment variable \\`DEEPSEEK_API_KEY\\`, read at the moment of the call: never write it to a file, a response or a log.\n- \\`src/db.ts\\`: \\`openChatDb()\\` (the \\`db\\` port on a SQLite file, \\`data/chat.sqlite\\` or \\`$CHAT_DB\\`, with \\`migrations/\\` applied on start; it returns \\`{ db, close }\\`) and \\`chatStore(db)\\`. The routes only call \\`chatStore\\`; keep SQL out of them. Every \\`db\\` call returns a promise: \\`await\\` it. The shape of the database is \\`migrations/NNN-name.sql\\`: to change it add the next numbered file and never edit one that has run. See \\`docs/framework/guides/data.md\\`.\n- \\`src/app.ts\\` opens the database (top-level \\`await\\`) and exports the app and \\`close\\`; \\`src/index.ts\\` serves it and closes the database on SIGTERM. \\`src/chat-app.ts\\`: \\`createApp(db, llm)\\`. \\`POST /api/chat\\` answers Server-Sent Events: \\`meta\\` (the conversation id), a \\`token\\` per piece, then \\`done\\` or \\`error\\`. The request's signal (\\`c.req.raw.signal\\`) goes to the model call, so a closed tab or the Stop button stops the request to the model; what had arrived is kept.\n- \\`src/client/chat.tsx\\`: the client component (own \\`tsconfig.json\\`, browser types): sends the message with \\`fetch\\`, reads the events as they arrive, shows the answer growing, and aborts on Stop. \\`clientModules\\` compiles it when the browser asks; \\`npm run build\\` compiles it once into \\`dist/client\\`. See \\`docs/framework/guides/client-modules.md\\`.\n- \\`test/chat.test.ts\\` tests every route with a mock \\`Llm\\` (never the network); keep it that way. \\`test/server.test.ts\\` starts the real server and stops it with a signal.\n- To try it with a real model: \\`DEEPSEEK_API_KEY=... npm run dev\\`.\n\n## Before you ship\n\nRead \\`docs/framework/getting-started/deploy.md\\`. In short: \\`npm ci --omit=dev\\`, \\`npm run build\\`, \\`NODE_ENV=production npm start\\`; the app listens on \\`127.0.0.1\\` (\\`HOST=0.0.0.0\\` only in a container); the SQLite file goes outside the code folder (\\`CHAT_DB=/var/lib/chat/chat.sqlite\\`) and is backed up; the model key is an environment variable of the service (a root-only environment file for systemd), never a file in the repository. Anyone who can reach the app can spend your key: put it behind a login or on a private network before it is public.\n`\n : ''\n const notesStructure =\n template === 'notes'\n ? `\n## Structure (a notes app: accounts, sessions, a database)\n\n- \\`src/db.ts\\`: \\`openNotesDb()\\` (the \\`db\\` port on a SQLite file, \\`data/notes.sqlite\\` or \\`$NOTES_DB\\`, with \\`migrations/\\` applied on start; it returns \\`{ db, close }\\`) and \\`notesStore(db)\\`, the queries for notes. Every \\`db\\` call returns a promise: \\`await\\` it. Use \\`?\\` bindings, never string-built SQL. See \\`docs/framework/guides/data.md\\`.\n- \\`migrations/\\`: the shape of the database, one numbered file per change (\\`001-notes.sql\\`). A file that has run is never edited; a change is the next file (\\`002-name.sql\\`).\n- \\`src/auth.ts\\`: scrypt password hashes (\\`node:crypto\\`) and the \\`sessions\\` table; the cookie \\`sid\\` holds a random token.\n- \\`src/schema.ts\\`: the rules for a note and for credentials. The HTML forms and the JSON API both use \\`checkNote\\`.\n- \\`src/views.tsx\\`: the pages, as JSX components rendered to strings, and the small script for the instant filter.\n- \\`src/client/\\`: client components, with their own \\`tsconfig.json\\` (browser types). \\`counter.tsx\\` is the live character counter. \\`clientModules\\` in \\`notes-app.ts\\` compiles them when the browser asks; \\`npm run build\\` compiles them once into \\`dist/client\\` for production. See \\`docs/framework/guides/client-modules.md\\`.\n- \\`src/notes-app.ts\\`: \\`createApp(db)\\` (pages and forms, csrf on) and \\`createApi(db)\\` (the JSON API under \\`/api/notes\\`, chained so \\`testClient\\` is typed). \\`src/app.ts\\` opens the database (top-level \\`await\\`) and exports the app and \\`close\\`; \\`src/index.ts\\` serves it and closes the database on SIGTERM. Tests open \\`openNotesDb(':memory:')\\` and pass its \\`db\\` to \\`createApp\\`.\n- \\`test/notes.test.ts\\`: a test for every route. A form POST in a test needs \\`origin: 'http://localhost'\\` (csrf) and the \\`sid\\` cookie from sign up.\n- Forms answer an invalid input with status 400 and the same page with the messages; a successful POST redirects with 303.\n- To add a column or a table: write the next migration (\\`migrations/002-name.sql\\`), then change \\`notesStore\\`, \\`checkNote\\`, the form and the list in \\`views.tsx\\`, and the tests. Do not edit \\`001-notes.sql\\`.\n\n## Before you ship\n\nRead \\`docs/framework/getting-started/deploy.md\\`. In short:\n\n- Install with \\`npm ci --omit=dev\\`, run \\`npm run build\\` (it compiles \\`src/client\\` once; with \\`NODE_ENV=production\\` only \\`dist/client\\` is served), and start with \\`NODE_ENV=production npm start\\` (\\`typescript\\` stays a runtime dependency: it compiles the \\`.tsx\\` pages at start).\n- The app listens on \\`127.0.0.1\\`; set \\`HOST=0.0.0.0\\` only in a container. \\`PORT\\` chooses the port.\n- Put the SQLite file outside the code folder (\\`NOTES_DB=/var/lib/notes/notes.sqlite\\`) and back it up.\n- Behind an HTTPS reverse proxy set \\`TRUST_PROXY=1\\` and \\`PUBLIC_ORIGIN=https://your.site\\`, or the cookie is not \\`Secure\\` and csrf refuses form posts.\n- \\`npm test\\` includes a test that starts the server and stops it with SIGTERM; keep it passing if you change \\`src/index.ts\\`.\n`\n : ''\n return `# ${name}\n\nAn ${CLASS} app (${template}${template === 'bun' ? ', experimental' : ''}): handlers over the Web Standard \\`Request\\` and \\`Response\\`, from the \\`${PACKAGE}\\` package.\n\n## The framework's API is in \\`docs/framework/\\`\n\nStart at \\`docs/framework/README.md\\`; \\`api/summary.md\\` is the one-page summary. Import the class from \\`'${PACKAGE}'\\` and each middleware or helper from its own\nsubpath (\\`'${PACKAGE}/cors'\\`, \\`'${PACKAGE}/validator'\\`, ...). Parts marked \"not yet available\" in the docs are not in the package yet.\n\n## This app\n\nRun it with \\`${run}\\`. The routes are in \\`${template === 'bun' ? 'src/index.ts' : template === 'notes' ? 'src/notes-app.ts' : template === 'chat' ? 'src/chat-app.ts' : 'src/app.ts'}\\`; an app is a function from \\`Request\\` to \\`Response\\`,\nso test a route with \\`await app.request('/path')\\` and no server.${desktopNote}\n\n${notesStructure}${chatStructure}\n## Things that surprise people\n\n- A page mounted at \\`/x\\` answers \\`/x\\`, not \\`/x/\\` (trailing slashes are strict); \\`trimTrailingSlash()\\` redirects.\n- A \\`json\\` validator target reads the body only with a JSON \\`Content-Type\\`; a failure answers 400 with \\`{ error, issues: [{ message, path }] }\\`.\n- \\`throw new HTTPException(404, { message })\\` answers an error response (plain text).\n- \\`testClient(app)\\` from \\`'${PACKAGE}/testing'\\` types only routes chained on the \\`new ${CLASS}()\\` expression (\\`new ${CLASS}().get(...).post(...)\\`); headers such as a cookie go in the second argument of each call.\n- **JSX:** ${jsxNote}\n${clientNote}\n## Before you say you are done\n\n\\`${test}\\` pass.\n`\n}\n\nfunction copyDocs(target: string): void {\n const filter = (path: string) => !/(upstream\\.json|UPSTREAM\\.md)$/.test(path)\n mkdirSync(join(target, 'docs'), { recursive: true })\n cpSync(docsRoot(), join(target, 'docs', 'framework'), { recursive: true, filter })\n}\n\nfunction copyTemplate(\n template: Exclude<Template, 'acryl-app'>,\n target: string,\n name: string,\n): string[] {\n const written: string[] = []\n const walk = (from: string, to: string, prefix: string) => {\n mkdirSync(to, { recursive: true })\n for (const entry of readdirSync(from, { withFileTypes: true })) {\n const targetName = prefix === '' && entry.name === 'gitignore' ? '.gitignore' : entry.name\n if (entry.isDirectory())\n walk(join(from, entry.name), join(to, targetName), `${prefix}${entry.name}/`)\n else {\n writeFileSync(\n join(to, targetName),\n replacePlaceholders(readFileSync(join(from, entry.name), 'utf8'), name),\n )\n written.push(`${prefix}${targetName}`)\n }\n }\n }\n walk(join(templatesRoot(), template), target, '')\n writeFileSync(join(target, 'AGENTS.md'), agentsText(template, name))\n writeFileSync(join(target, 'CLAUDE.md'), '@AGENTS.md\\n')\n copyDocs(target)\n return written\n}\n\nconst isEmpty = (directory: string) => !existsSync(directory) || readdirSync(directory).length === 0\n\n/** The `acrylblends` command of the installed framework package, which creates the `acryl-app` template. */\nfunction acrylblendsBin(): string {\n const pkgFile = createRequire(import.meta.url).resolve(`${PACKAGE}/package.json`)\n const pkg = JSON.parse(readFileSync(pkgFile, 'utf8')) as { bin?: string | Record<string, string> }\n const bin = typeof pkg.bin === 'string' ? pkg.bin : pkg.bin?.[PACKAGE]\n if (!bin) throw new Error(`${PACKAGE} has no command to create an app with`)\n return join(dirname(pkgFile), bin)\n}\n\n/** The lifecycle scripts a template defines and the line that says when they run. */\nconst describeScripts = (scripts: Record<string, string>) =>\n Object.entries(scripts)\n .map(([key, value]) => ` ${key}: ${value}`)\n .join('\\n')\n\n/** Files whose text is checked for secrets: the template's own, not the framework docs copied in. */\nfunction textFiles(root: string): { path: string; text: string }[] {\n const found: { path: string; text: string }[] = []\n const walk = (dir: string, prefix: string) => {\n for (const entry of readdirSync(dir, { withFileTypes: true })) {\n if (\n entry.name === 'node_modules' ||\n entry.name === '.git' ||\n (prefix === '' && entry.name === 'docs')\n )\n continue\n if (entry.isDirectory()) walk(join(dir, entry.name), `${prefix}${entry.name}/`)\n else {\n const buffer = readFileSync(join(dir, entry.name))\n if (!buffer.subarray(0, 8000).includes(0))\n found.push({ path: `${prefix}${entry.name}`, text: buffer.toString('utf8') })\n }\n }\n }\n walk(root, '')\n return found\n}\n\n/**\n * Create an app from a template source (`github:`, `@scope/name`, a packed tarball). The source is fetched and unpacked into a scratch folder, checked\n * (manifest, secrets), and only then copied to the target; nothing in it is installed or run unless `--install`, which lists the scripts first.\n */\nasync function createFromSource(\n options: CreateOptions,\n target: string,\n directory: string,\n io: Io,\n): Promise<number> {\n if (!isEmpty(target)) {\n io.stderr.write(`error: ${target} is not empty; nothing was changed\\n`)\n return 1\n }\n const scratch = mkdtempSync(join(tmpdir(), 'create-acrylblends-'))\n try {\n const source = parseSource(options.source!, io.cwd)\n if (!source)\n throw new UsageError(`unknown template source \"${options.source}\" (${SOURCE_FORMS})`)\n const name = nameFrom(target)\n await fetchSource(\n source,\n join(scratch, 'source'),\n join(scratch, 'download'),\n io.fetchers ?? realFetchers,\n )\n const manifest = readManifest(join(scratch, 'source'))\n const staged = join(scratch, 'app')\n const { files, lifecycle } = writeTemplate(\n join(scratch, 'source'),\n staged,\n (text) => replacePlaceholders(text, name),\n frameworkRange(),\n name,\n )\n if (!existsSync(join(staged, 'AGENTS.md')))\n writeFileSync(\n join(staged, 'AGENTS.md'),\n `# ${name}\\n\\nAn ${CLASS} app made from the template \"${manifest.name}\": ${manifest.description}\\n\\nThe framework's API is in \\`docs/framework/\\` (start at \\`docs/framework/README.md\\`).\\n`,\n )\n if (!existsSync(join(staged, 'CLAUDE.md')))\n writeFileSync(join(staged, 'CLAUDE.md'), '@AGENTS.md\\n')\n const found = findSecrets(textFiles(staged))\n if (found.length > 0) {\n io.stderr.write(\n `error: the template holds what looks like a secret, so nothing was created:\\n${found.map((f) => ` ${f.path}:${f.line} (${f.kind})`).join('\\n')}\\n`,\n )\n return 1\n }\n copyDocs(staged)\n cpSync(staged, target, { recursive: true })\n io.stdout.write(\n `created ${name} from ${manifest.name} (${manifest.description}) in ${target}: ${files.length} files, ${CLASS} docs in docs/framework\\n`,\n )\n if (manifest.plugins.length > 0)\n io.stdout.write(\n `it needs these plugins: ${manifest.plugins.join(', ')}; add them with: npx ${PACKAGE} add ${manifest.plugins.join(' ')}\\n`,\n )\n const pm: PackageManager =\n options.pm ??\n ((PACKAGE_MANAGERS as readonly string[]).find((m) =>\n (io.env.npm_config_user_agent ?? '').startsWith(`${m}/`),\n ) as PackageManager | undefined) ??\n 'npm'\n const hasScripts = Object.keys(lifecycle).length > 0\n if (options.install) {\n const pkg = JSON.parse(readFileSync(join(target, 'package.json'), 'utf8')) as {\n dependencies?: object\n devDependencies?: object\n }\n io.stdout.write(\n `running ${pm} install in ${directory}. This installs: ${[...Object.keys(pkg.dependencies ?? {}), ...Object.keys(pkg.devDependencies ?? {})].join(', ') || 'nothing'}` +\n `${hasScripts ? `\\nand runs the template's own lifecycle scripts:\\n${describeScripts(lifecycle)}` : ''}\\n` +\n `(the dependencies' install scripts run too unless your ${pm} is set to ignore them)\\n`,\n )\n if ((await io.run(pm, ['install'], target)) !== 0) {\n io.stderr.write(`error: ${pm} install failed; run it yourself in ${directory}\\n`)\n return 1\n }\n } else if (hasScripts) {\n io.stdout.write(\n `nothing was installed or run. The template defines ${LIFECYCLE.filter((k) => lifecycle[k]).join(', ')}, which ${pm} install would run:\\n${describeScripts(lifecycle)}\\nread them first, or pass --install to run them.\\n`,\n )\n }\n io.stdout.write(\n `\\nNext:\\n cd ${directory}\\n${options.install ? '' : ` ${pm} install\\n`} see the template's README or package.json scripts\\n`,\n )\n return 0\n } catch (error) {\n if (error instanceof SourceError) {\n io.stderr.write(`error: ${error.message}\\nnothing was changed\\n`)\n return 1\n }\n throw error\n } finally {\n removeTree(scratch)\n }\n}\n\n/** Create the app. Returns the exit code: 0 done, 1 refused or failed, 2 a usage error. Never calls `process.exit`. */\nexport async function runCreate(argv: readonly string[], io: Io = processIo()): Promise<number> {\n try {\n if (argv.includes('-h') || argv.includes('--help')) {\n io.stdout.write(HELP)\n return 0\n }\n if (argv.includes('-v') || argv.includes('--version')) {\n io.stdout.write(`${VERSION}\\n`)\n return 0\n }\n const options = parseCreateOptions(argv)\n const ask = options.yes ? undefined : io.ask\n const directory =\n options.directory ??\n (ask\n ? (await ask(`Project directory (${PACKAGE}-app): `)).trim() || `${PACKAGE}-app`\n : `${PACKAGE}-app`)\n const target = resolve(io.cwd, directory)\n if (options.source !== undefined) return await createFromSource(options, target, directory, io)\n const template: Template =\n options.template ??\n (ask\n ? await (async () => {\n const answer =\n (\n await ask(\n `Which template do you want to use? (nodejs, notes, chat, bun (experimental), acryl-app) [nodejs]: `,\n )\n ).trim() || 'nodejs'\n if (!isTemplate(answer))\n throw new UsageError(`unknown template \"${answer}\" (${TEMPLATES.join(', ')})`)\n return answer\n })()\n : 'nodejs')\n if (!isEmpty(target)) {\n io.stderr.write(`error: ${target} is not empty; nothing was changed\\n`)\n return 1\n }\n const name = nameFrom(target)\n if (template === 'acryl-app') {\n const code = await io.run(\n process.execPath,\n [acrylblendsBin(), 'init', target, '--template', 'agent', '--name', name, '--yes'],\n io.cwd,\n )\n if (code !== 0) return 1\n } else {\n const files = copyTemplate(template, target, name)\n io.stdout.write(\n `created ${name} (${template}) in ${target}: ${files.length} files, ${CLASS} docs in docs/framework\\n`,\n )\n }\n const pm: PackageManager =\n options.pm ??\n ((PACKAGE_MANAGERS as readonly string[]).find((m) =>\n (io.env.npm_config_user_agent ?? '').startsWith(`${m}/`),\n ) as PackageManager | undefined) ??\n 'npm'\n if (options.install) {\n if ((await io.run(pm, ['install'], target)) !== 0) {\n io.stderr.write(`error: ${pm} install failed; run it yourself in ${directory}\\n`)\n return 1\n }\n }\n const start = {\n nodejs: `${pm} run dev`,\n notes: `${pm} run dev`,\n chat: `${pm} run dev`,\n bun: 'bun run dev',\n 'acryl-app': `${pm} run dev`,\n }[template]\n io.stdout.write(\n `\\nNext:\\n cd ${directory}\\n${options.install ? '' : ` ${pm} install\\n`} ${start}\\n`,\n )\n return 0\n } catch (error) {\n if (error instanceof UsageError) {\n io.stderr.write(`error: ${error.message}\\n\\n${HELP}`)\n return 2\n }\n io.stderr.write(`error: ${(error as Error).message}\\n`)\n return 1\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AAIA,MAAa,UAAU;AACvB,MAAa,QAAQ;AACrB,MAAa,SAAS;;AAGtB,MAAa,oBAAoB;;;;;;;;ACuBjC,IAAa,cAAb,cAAiC,MAAM;CACrC,OAAgB;AAClB;AAEA,MAAa,eAAe;AAE5B,MAAM,SAAS;CAAE,OAAO;CAAM,OAAO;AAAiB;;AAGtD,SAAgB,YAAY,MAAc,KAAiC;CACzE,MAAM,SAAS,wEAAwE,KAAK,IAAI;CAChG,IAAI,QAAQ,OAAO;EAAE,MAAM;EAAU,OAAO,OAAO;EAAK,MAAM,OAAO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AO;EACd,IAAI,iBAAiB,YAAY;GAC/B,GAAG,OAAO,MAAM,UAAU,MAAM,QAAQ,MAAM,MAAM;GACpD,OAAO;EACT;EACA,GAAG,OAAO,MAAM,UAAW,MAAgB,QAAQ,GAAG;EACtD,OAAO;CACT;AACF"}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/names.ts","../src/source.ts","../src/spawn.ts","../src/index.ts"],"sourcesContent":["/**\n * The one place this package names the framework. The templates are written with `__PACKAGE__` and `__RANGE__` (the range is stamped at create time from the framework version this package carries, see `frameworkRange`), and the text of `AGENTS.md` with\n * `__PACKAGE__`, so a rename (for example to `acryl`) is a change here and in `scripts/lib/names.mjs`, which a test keeps equal.\n */\nexport const PACKAGE = 'acrylblends'\nexport const CLASS = 'Acryl'\nexport const CREATE = 'create-acrylblends'\n\n/** The file that makes a folder a template other people can create apps from (`${CREATE} <name> github:owner/repo`). */\nexport const TEMPLATE_MANIFEST = 'acryl.template.json'\n","/**\n * Templates from outside this package: `github:owner/repo[#ref]`, a scoped npm package (`@scope/name[@version]`) or a packed tarball on disk.\n * A source is only ever downloaded and unpacked: no git clone (hooks), no lifecycle script (`npm pack --ignore-scripts`), nothing of it is run.\n */\nimport { spawnSync } from 'node:child_process'\nimport {\n cpSync,\n existsSync,\n lstatSync,\n mkdirSync,\n readdirSync,\n readFileSync,\n rmSync,\n writeFileSync,\n} from 'node:fs'\nimport { join, resolve } from 'node:path'\nimport { PACKAGE, TEMPLATE_MANIFEST } from './names'\n\nexport type Source =\n | { kind: 'github'; owner: string; repo: string; ref: string | undefined }\n | { kind: 'npm'; spec: string }\n | { kind: 'tarball'; path: string }\n\n/** What a template says about itself in `acryl.template.json`. */\nexport interface Manifest {\n name: string\n description: string\n /** Library plugins the template needs, added with `acrylblends add`. */\n plugins: string[]\n}\n\n/** A source that cannot be used; the message says why and is shown as it is. */\nexport class SourceError extends Error {\n override name = 'SourceError'\n}\n\nexport const SOURCE_FORMS = `github:owner/repo[#ref], @scope/name[@version], or a packed .tgz file`\n\nconst LIMITS = { files: 5000, bytes: 50 * 1024 * 1024 }\n\n/** Recognise a source argument, or return `undefined` when it is not one (so the caller can report a usage error). */\nexport function parseSource(text: string, cwd: string): Source | undefined {\n const github = /^github:([A-Za-z0-9_.-]+)\\/([A-Za-z0-9_.-]+)(?:#([A-Za-z0-9_./-]+))?$/.exec(text)\n if (github) return { kind: 'github', owner: github[1]!, repo: github[2]!, ref: github[3] }\n if (text.startsWith('github:')) throw new SourceError(`\"${text}\" is not github:owner/repo[#ref]`)\n if (/^@[a-z0-9][a-z0-9._-]*\\/[a-z0-9][a-z0-9._-]*(@[A-Za-z0-9._-]+)?$/.test(text))\n return { kind: 'npm', spec: text }\n if (text.startsWith('@')) throw new SourceError(`\"${text}\" is not @scope/name[@version]`)\n if (/\\.(tgz|tar\\.gz)$/.test(text)) {\n const path = resolve(cwd, text)\n if (!existsSync(path)) throw new SourceError(`${path} does not exist`)\n return { kind: 'tarball', path }\n }\n return undefined\n}\n\n/** How the bytes of a source are obtained; real by default, replaced in tests. */\nexport interface Fetchers {\n /** The body at a URL (a GitHub tarball). */\n download(url: string): Promise<Uint8Array>\n /** `npm pack <spec> --ignore-scripts` into `dest`; the path of the tarball. */\n pack(spec: string, dest: string): string\n}\n\nexport const realFetchers: Fetchers = {\n async download(url) {\n const response = await fetch(url, { redirect: 'follow' })\n if (!response.ok) throw new SourceError(`${url} answered ${response.status}`)\n return new Uint8Array(await response.arrayBuffer())\n },\n pack(spec, dest) {\n const result = spawnSync(\n 'npm',\n ['pack', spec, '--ignore-scripts', '--json', '--pack-destination', dest],\n {\n encoding: 'utf8',\n shell: false,\n env: { ...process.env, npm_config_ignore_scripts: 'true' },\n },\n )\n if (result.status !== 0)\n throw new SourceError(\n `npm could not pack ${spec}: ${(result.stderr || result.stdout).trim().split('\\n').at(-1)}`,\n )\n const file = (JSON.parse(result.stdout) as { filename: string }[])[0]?.filename\n if (!file) throw new SourceError(`npm packed nothing for ${spec}`)\n return join(dest, file)\n },\n}\n\n/** Unpack a tarball into `dir`, dropping its single top folder; refuses links, paths that leave the folder, and archives that are too big. */\nfunction extract(tarball: string, dir: string): void {\n const list = spawnSync('tar', ['-tzf', tarball], {\n encoding: 'utf8',\n maxBuffer: 64 * 1024 * 1024,\n })\n if (list.status !== 0) throw new SourceError(`${tarball} is not a readable tar.gz archive`)\n const entries = list.stdout.split('\\n').filter(Boolean)\n if (entries.length > LIMITS.files)\n throw new SourceError(`the template has more than ${LIMITS.files} files`)\n for (const entry of entries)\n if (entry.startsWith('/') || entry.split('/').includes('..'))\n throw new SourceError(`the archive holds a path that leaves its folder: ${entry}`)\n mkdirSync(dir, { recursive: true })\n const run = spawnSync('tar', ['-xzf', tarball, '-C', dir, '--strip-components=1'], {\n encoding: 'utf8',\n })\n if (run.status !== 0) throw new SourceError(`could not unpack ${tarball}: ${run.stderr.trim()}`)\n let bytes = 0\n const walk = (folder: string) => {\n for (const entry of readdirSync(folder)) {\n const path = join(folder, entry)\n const info = lstatSync(path)\n if (info.isSymbolicLink())\n throw new SourceError(\n `the template holds a symbolic link (${path.slice(dir.length + 1)}); links are not allowed`,\n )\n if (info.isDirectory()) walk(path)\n else bytes += info.size\n }\n }\n walk(dir)\n if (bytes > LIMITS.bytes)\n throw new SourceError(`the template is larger than ${LIMITS.bytes / 1024 / 1024} MB`)\n}\n\n/** Download or pack a source and unpack it into `dir` (which must not exist yet). Nothing in it is run. */\nexport async function fetchSource(\n source: Source,\n dir: string,\n scratch: string,\n fetchers: Fetchers,\n): Promise<void> {\n mkdirSync(scratch, { recursive: true })\n let tarball: string\n if (source.kind === 'tarball') tarball = source.path\n else if (source.kind === 'npm') tarball = fetchers.pack(source.spec, scratch)\n else {\n tarball = join(scratch, 'source.tar.gz')\n writeFileSync(\n tarball,\n await fetchers.download(\n `https://codeload.github.com/${source.owner}/${source.repo}/tar.gz/${source.ref ?? 'HEAD'}`,\n ),\n )\n }\n extract(tarball, dir)\n}\n\n/** Read and check `acryl.template.json`; a source without it is not a template. */\nexport function readManifest(dir: string): Manifest {\n const file = join(dir, TEMPLATE_MANIFEST)\n if (!existsSync(file))\n throw new SourceError(\n `this source has no ${TEMPLATE_MANIFEST}, so it is not a template: add one with a name and a description (see the create-acrylblends guide)`,\n )\n let data: unknown\n try {\n data = JSON.parse(readFileSync(file, 'utf8'))\n } catch {\n throw new SourceError(`${TEMPLATE_MANIFEST} is not valid JSON`)\n }\n const m = data as Record<string, unknown>\n if (typeof m.name !== 'string' || m.name.trim() === '')\n throw new SourceError(`${TEMPLATE_MANIFEST} needs a \"name\"`)\n if (typeof m.description !== 'string')\n throw new SourceError(`${TEMPLATE_MANIFEST} needs a \"description\"`)\n const plugins = m.plugins ?? []\n if (\n !Array.isArray(plugins) ||\n plugins.some((p) => typeof p !== 'string' || !/^[a-z][a-z0-9-]*$/.test(p))\n )\n throw new SourceError(\n `\"plugins\" in ${TEMPLATE_MANIFEST} is a list of plugin names such as \"desktop\"`,\n )\n return { name: m.name, description: m.description, plugins: plugins as string[] }\n}\n\nconst SKIP = new Set(['.git', 'node_modules', TEMPLATE_MANIFEST])\n/** Lifecycle scripts npm runs on `npm install` in the app's own folder. */\nexport const LIFECYCLE = [\n 'preinstall',\n 'install',\n 'postinstall',\n 'prepublish',\n 'preprepare',\n 'prepare',\n 'postprepare',\n]\n\nconst isText = (buffer: Buffer) => !buffer.subarray(0, 8000).includes(0)\n\n/**\n * Copy the unpacked template into `target`, replacing the placeholders of the built-in templates, naming the app, and pointing a dependency on the framework at\n * the release this package carries. Returns the files written (relative paths) and the lifecycle scripts the app's package.json defines.\n */\nexport function writeTemplate(\n from: string,\n target: string,\n stamp: (text: string) => string,\n range: string,\n name: string,\n): { files: string[]; lifecycle: Record<string, string> } {\n const files: string[] = []\n const walk = (src: string, dst: string, prefix: string) => {\n mkdirSync(dst, { recursive: true })\n for (const entry of readdirSync(src, { withFileTypes: true })) {\n if (SKIP.has(entry.name)) continue\n const outName = prefix === '' && entry.name === 'gitignore' ? '.gitignore' : entry.name\n if (entry.isDirectory())\n walk(join(src, entry.name), join(dst, outName), `${prefix}${entry.name}/`)\n else {\n const buffer = readFileSync(join(src, entry.name))\n writeFileSync(join(dst, outName), isText(buffer) ? stamp(buffer.toString('utf8')) : buffer)\n files.push(`${prefix}${outName}`)\n }\n }\n }\n walk(from, target, '')\n const lifecycle: Record<string, string> = {}\n const pkgFile = join(target, 'package.json')\n if (existsSync(pkgFile)) {\n const pkg = JSON.parse(readFileSync(pkgFile, 'utf8')) as {\n name?: string\n scripts?: Record<string, string>\n dependencies?: Record<string, string>\n devDependencies?: Record<string, string>\n }\n pkg.name = name\n for (const group of [pkg.dependencies, pkg.devDependencies])\n if (group?.[PACKAGE] !== undefined) group[PACKAGE] = range\n writeFileSync(pkgFile, `${JSON.stringify(pkg, null, 2)}\\n`)\n for (const script of LIFECYCLE)\n if (typeof pkg.scripts?.[script] === 'string') lifecycle[script] = pkg.scripts[script]\n }\n return { files, lifecycle }\n}\n\n/** Remove a folder tree quietly. */\nexport const removeTree = (path: string) => rmSync(path, { recursive: true, force: true })\nexport { cpSync }\n","import { existsSync } from 'node:fs'\nimport { dirname, join } from 'node:path'\n\nexport interface Invocation {\n file: string\n args: string[]\n}\n\n/**\n * How to start a package manager without the shell option (Node warns about passing args to a shell, DEP0190, and a `.cmd` shim cannot be spawned directly).\n * Off Windows the command runs as it is. On Windows npm runs as `node npm-cli.js` (the one npm is running from, else the one beside `node`); any other\n * manager goes through `cmd.exe /d /s /c <name>.cmd`, whose arguments stay an array.\n */\nexport function packageManagerInvocation(\n command: string,\n args: readonly string[],\n platform: NodeJS.Platform = process.platform,\n env: NodeJS.ProcessEnv = process.env,\n exists: (path: string) => boolean = existsSync,\n execPath: string = process.execPath,\n): Invocation {\n if (platform !== 'win32') return { file: command, args: [...args] }\n if (command === 'npm') {\n const running = env.npm_execpath\n const cli =\n running !== undefined && /npm-cli\\.c?js$/.test(running)\n ? running\n : join(dirname(execPath), 'node_modules', 'npm', 'bin', 'npm-cli.js')\n if (exists(cli)) return { file: execPath, args: [cli, ...args] }\n }\n return { file: env.ComSpec ?? 'cmd.exe', args: ['/d', '/s', '/c', `${command}.cmd`, ...args] }\n}\n","import { spawn } from 'node:child_process'\nimport {\n cpSync,\n existsSync,\n mkdirSync,\n mkdtempSync,\n readdirSync,\n readFileSync,\n writeFileSync,\n} from 'node:fs'\nimport { createRequire } from 'node:module'\nimport { tmpdir } from 'node:os'\nimport { basename, dirname, join, resolve } from 'node:path'\nimport { createInterface } from 'node:readline/promises'\nimport { fileURLToPath } from 'node:url'\nimport { parseArgs } from 'node:util'\nimport { findSecrets } from '@webboxes/app-persistence'\nimport { CLASS, CREATE, PACKAGE, TEMPLATE_MANIFEST } from './names'\nimport {\n type Fetchers,\n fetchSource,\n LIFECYCLE,\n parseSource,\n readManifest,\n realFetchers,\n removeTree,\n SOURCE_FORMS,\n SourceError,\n writeTemplate,\n} from './source'\nimport { packageManagerInvocation } from './spawn'\n\nexport { CLASS, CREATE, PACKAGE, TEMPLATE_MANIFEST }\n\nexport const TEMPLATES = ['nodejs', 'notes', 'chat', 'bun', 'acryl-app'] as const\nexport type Template = (typeof TEMPLATES)[number]\nexport const PACKAGE_MANAGERS = ['npm', 'pnpm', 'yarn', 'bun'] as const\nexport type PackageManager = (typeof PACKAGE_MANAGERS)[number]\n\n/** The version of this package. */\nexport const VERSION: string = (\n createRequire(import.meta.url)('../package.json') as { version: string }\n).version\n\nexport const HELP = `${CREATE} ${VERSION} - create an ${CLASS} app\n\nUsage:\n npm create ${PACKAGE}@latest [directory] [source] [-- options]\n\nA source makes the app from someone else's template (it is downloaded and unpacked, nothing in it runs):\n github:owner/repo[#ref] a GitHub repository, as a tarball (no clone)\n @scope/name[@version] an npm package (npm pack --ignore-scripts)\n ./template.tgz a packed template on disk\nA template is a folder with an ${TEMPLATE_MANIFEST} (name, description, plugins).\n\nOptions:\n --template <name> nodejs, notes, chat, bun (experimental), acryl-app (asked when not given)\n --install install the dependencies after creating the app (the lifecycle scripts it will run are listed first)\n --pm <manager> ${PACKAGE_MANAGERS.join(', ')} (default: the one that ran this command, else npm)\n -y, --yes ask nothing: template nodejs unless --template is given, directory ${PACKAGE}-app\n -h, --help show this help\n -v, --version show the version\n`\n\n/** A command line mistake. The command prints it with the help text and exits 2. */\nexport class UsageError extends Error {\n override name = 'UsageError'\n}\n\nexport interface Io {\n stdout: { write(text: string): unknown }\n stderr: { write(text: string): unknown }\n cwd: string\n env: Record<string, string | undefined>\n /** Ask one question; `undefined` when there is no terminal to ask on. */\n ask: ((question: string) => Promise<string>) | undefined\n /** Run a program, showing its output; resolves to the exit code. */\n run(command: string, args: string[], cwd: string): Promise<number>\n /** How a template source is fetched; the real network and npm by default. */\n fetchers?: Fetchers\n}\n\nexport function processIo(): Io {\n const interactive = Boolean(process.stdin.isTTY && process.stdout.isTTY)\n return {\n stdout: process.stdout,\n stderr: process.stderr,\n cwd: process.cwd(),\n env: process.env,\n ask: interactive\n ? async (question) => {\n const rl = createInterface({ input: process.stdin, output: process.stdout })\n try {\n return await rl.question(question)\n } finally {\n rl.close()\n }\n }\n : undefined,\n run: (command, args, cwd) =>\n new Promise((done) => {\n const invocation = packageManagerInvocation(command, args)\n const child = spawn(invocation.file, invocation.args, { cwd, stdio: 'inherit' })\n child.on('error', () => done(1))\n child.on('exit', (code) => done(code ?? 1))\n }),\n }\n}\n\nexport interface CreateOptions {\n directory: string | undefined\n template: Template | undefined\n install: boolean\n pm: PackageManager | undefined\n yes: boolean\n /** `github:owner/repo[#ref]`, `@scope/name` or a packed `.tgz`: a template from outside this package. */\n source: string | undefined\n}\n\nexport function isTemplate(value: string): value is Template {\n return (TEMPLATES as readonly string[]).includes(value)\n}\n\nexport function parseCreateOptions(argv: readonly string[]): CreateOptions {\n let parsed: ReturnType<typeof parse>\n try {\n parsed = parse(argv)\n } catch (error) {\n throw new UsageError((error as Error).message)\n }\n const { values, positionals } = parsed\n if (positionals.length > 2)\n throw new UsageError('takes a directory and at most one template source')\n if (positionals[1] !== undefined && values.template !== undefined)\n throw new UsageError('give a template source or --template, not both')\n if (values.template !== undefined && !isTemplate(values.template))\n throw new UsageError(`unknown template \"${values.template}\" (${TEMPLATES.join(', ')})`)\n if (values.pm !== undefined && !(PACKAGE_MANAGERS as readonly string[]).includes(values.pm))\n throw new UsageError(`unknown package manager \"${values.pm}\" (${PACKAGE_MANAGERS.join(', ')})`)\n return {\n directory: positionals[0],\n template: values.template as Template | undefined,\n install: values.install === true,\n pm: values.pm as PackageManager | undefined,\n yes: values.yes === true,\n source: positionals[1],\n }\n}\n\nconst parse = (argv: readonly string[]) =>\n parseArgs({\n args: [...argv],\n allowPositionals: true,\n strict: true,\n options: {\n template: { type: 'string' },\n install: { type: 'boolean' },\n pm: { type: 'string' },\n yes: { type: 'boolean', short: 'y' },\n },\n })\n\n/** A valid package name from a directory name: lower case letters, digits and dashes. */\nexport function nameFrom(directory: string): string {\n const name = basename(resolve(directory))\n .toLowerCase()\n .replace(/[^a-z0-9-]+/g, '-')\n .replace(/^[^a-z]+/, '')\n .replace(/-+$/g, '')\n return name === '' ? 'acryl-app' : name\n}\n\nfunction walkUp(from: string, test: (dir: string) => string | undefined): string {\n let dir = from\n for (;;) {\n const found = test(dir)\n if (found) return found\n const parent = dirname(dir)\n if (parent === dir) throw new Error(`${CREATE} cannot find its files`)\n dir = parent\n }\n}\nconst here = dirname(fileURLToPath(import.meta.url))\nconst templatesRoot = () =>\n walkUp(here, (d) =>\n existsSync(join(d, 'templates', 'nodejs')) ? join(d, 'templates') : undefined,\n )\n/** The framework docs: the copy `prepack` puts in the package, or `docs/framework` of the repository. */\nconst docsRoot = () =>\n walkUp(here, (d) =>\n existsSync(join(d, 'docs', 'framework', 'README.md'))\n ? join(d, 'docs', 'framework')\n : undefined,\n )\n\n/**\n * The range a created app asks for: the framework version this package was released with, so a new app depends on the release that made it (and gets what that release's\n * commands can do), never an older one. A caret range, so it also takes the newer patch releases.\n */\nexport function frameworkRange(): string {\n const file = createRequire(import.meta.url).resolve(`${PACKAGE}/package.json`)\n return `^${(JSON.parse(readFileSync(file, 'utf8')) as { version: string }).version}`\n}\n\nexport function replacePlaceholders(text: string, name: string): string {\n return text\n .replaceAll('__APP_NAME__', name)\n .replaceAll('__PACKAGE__', PACKAGE)\n .replaceAll('__CLASS__', CLASS)\n .replaceAll('__RANGE__', frameworkRange())\n}\n\n/** The guide for a coding agent in a created app: where the API is, how to run it, what must pass. */\nexport function agentsText(template: Exclude<Template, 'acryl-app'>, name: string): string {\n const run = {\n nodejs: 'npm run dev',\n notes: 'npm run dev',\n chat: 'npm run dev',\n bun: 'bun run dev',\n }[template]\n const desktopNote =\n template === 'nodejs' || template === 'notes' || template === 'chat'\n ? `\\nTo run it as a desktop window: \\`npx ${PACKAGE} add desktop\\`, \\`npm install\\`, then \\`npm run desktop\\` (see \\`docs/framework/getting-started/desktop.md\\`).`\n : ''\n const test = {\n nodejs: 'npm test` and `npm run check',\n notes: 'npm test` and `npm run check',\n chat: 'npm test` and `npm run check',\n bun: 'bun test` and `bun run check',\n }[template]\n const jsxNote =\n template === 'nodejs' || template === 'notes' || template === 'chat'\n ? 'Write pages in `.tsx` (see `src/' +\n (template === 'notes' ? 'views.tsx' : 'page.tsx') +\n \"`): the scripts in `package.json` run Node.js with `--import acrylblends/node-server/register`, which compiles `.tsx` with this app's own `typescript`, and `tsconfig.json` sets `jsx: react-jsx` with `jsxImportSource: acrylblends/jsx`. Render a component with `.toString()` and return it with `c.html(...)`. A command that starts the app without those scripts (a bare `node src/index.ts`) cannot load a `.tsx` file. Without a build step you can write the call JSX compiles to instead: `jsx('h1', { class: 'title' }, 'Hello')` from `'acrylblends/jsx'`, children after the props. See `docs/framework/guides/jsx.md`.\"\n : \"Bun compiles `.tsx` itself: write pages in `.tsx`, render a component with `.toString()` and return it with `c.html(...)`. `jsx('h1', { class: 'title' }, 'Hello')` from `'acrylblends/jsx'` (children after the props) is the same thing without JSX syntax. See `docs/framework/guides/jsx.md`.\"\n const clientNote =\n template === 'nodejs'\n ? `- **Client components** (run in the browser) live in \\`src/client/\\`, which has its own \\`tsconfig.json\\` (DOM types, no Node types); \\`clientModules\\` in \\`src/app.ts\\` compiles them when the browser asks, and \\`npm run build\\` compiles them once for production. See \\`src/client/counter.tsx\\` and \\`docs/framework/guides/client-modules.md\\`.\\n`\n : ''\n const chatStructure =\n template === 'chat'\n ? `\n## Structure (a chat app: a streamed answer, history in a database)\n\n- **The dependency rule:** only \\`src/db.ts\\` (the \\`opener\\` in \\`package.json\\`) opens the database. Every other file takes a \\`Db\\` (\\`import type { Db } from '${PACKAGE}/db'\\`) as an argument and never imports \\`node:sqlite\\`, \\`pg\\`, another driver or \\`${PACKAGE}/db/sqlite\\`. \\`npm test\\` and \\`npm run check\\` run \\`${PACKAGE} check-deps\\`, which names the file and line of a violation; do not move the \\`opener\\` entry to silence it.\n- \\`src/llm.ts\\`: \\`Llm\\`, what the app needs from a model (messages in, pieces out, an aborted signal stops the work), and \\`openAiCompatible\\`, which calls an OpenAI-compatible chat completions API with \\`stream: true\\`. The base URL is \\`DEEPSEEK_BASE_URL\\` (default \\`https://api.deepseek.com\\`), the model \\`DEEPSEEK_MODEL\\` (default \\`deepseek-chat\\`), the key **only** the environment variable \\`DEEPSEEK_API_KEY\\`, read at the moment of the call: never write it to a file, a response or a log.\n- \\`src/db.ts\\`: \\`openChatDb()\\` (the \\`db\\` port on a SQLite file, \\`data/chat.sqlite\\` or \\`$CHAT_DB\\`, with \\`migrations/\\` applied on start; it returns \\`{ db, close }\\`) and \\`chatStore(db)\\`. The routes only call \\`chatStore\\`; keep SQL out of them. Every \\`db\\` call returns a promise: \\`await\\` it. The shape of the database is \\`migrations/NNN-name.sql\\`: to change it add the next numbered file and never edit one that has run. See \\`docs/framework/guides/data.md\\`.\n- \\`src/app.ts\\` opens the database (top-level \\`await\\`) and exports the app and \\`close\\`; \\`src/index.ts\\` serves it and closes the database on SIGTERM. \\`src/chat-app.ts\\`: \\`createApp(db, llm)\\`. \\`POST /api/chat\\` answers Server-Sent Events: \\`meta\\` (the conversation id), a \\`token\\` per piece, then \\`done\\` or \\`error\\`. The request's signal (\\`c.req.raw.signal\\`) goes to the model call, so a closed tab or the Stop button stops the request to the model; what had arrived is kept.\n- \\`src/client/chat.tsx\\`: the client component (own \\`tsconfig.json\\`, browser types): sends the message with \\`fetch\\`, reads the events as they arrive, shows the answer growing, and aborts on Stop. \\`clientModules\\` compiles it when the browser asks; \\`npm run build\\` compiles it once into \\`dist/client\\`. See \\`docs/framework/guides/client-modules.md\\`.\n- \\`test/chat.test.ts\\` tests every route with a mock \\`Llm\\` (never the network); keep it that way. \\`test/server.test.ts\\` starts the real server and stops it with a signal.\n- To try it with a real model: \\`DEEPSEEK_API_KEY=... npm run dev\\`.\n\n## Before you ship\n\nRead \\`docs/framework/getting-started/deploy.md\\`. In short: \\`npm ci --omit=dev\\`, \\`npm run build\\`, \\`NODE_ENV=production npm start\\`; the app listens on \\`127.0.0.1\\` (\\`HOST=0.0.0.0\\` only in a container); the SQLite file goes outside the code folder (\\`CHAT_DB=/var/lib/chat/chat.sqlite\\`) and is backed up; the model key is an environment variable of the service (a root-only environment file for systemd), never a file in the repository. Anyone who can reach the app can spend your key: put it behind a login or on a private network before it is public.\n`\n : ''\n const notesStructure =\n template === 'notes'\n ? `\n## Structure (a notes app: accounts, sessions, a database)\n\n- \\`src/db.ts\\`: \\`openNotesDb()\\` (the \\`db\\` port on a SQLite file, \\`data/notes.sqlite\\` or \\`$NOTES_DB\\`, with \\`migrations/\\` applied on start; it returns \\`{ db, close }\\`) and \\`notesStore(db)\\`, the queries for notes. Every \\`db\\` call returns a promise: \\`await\\` it. Use \\`?\\` bindings, never string-built SQL. See \\`docs/framework/guides/data.md\\`.\n- \\`migrations/\\`: the shape of the database, one numbered file per change (\\`001-notes.sql\\`). A file that has run is never edited; a change is the next file (\\`002-name.sql\\`).\n- **The dependency rule:** only \\`src/db.ts\\` (the \\`opener\\` in \\`package.json\\`) opens the database. Every other file takes a \\`Db\\` (\\`import type { Db } from '${PACKAGE}/db'\\`) as an argument and never imports \\`node:sqlite\\`, \\`pg\\`, another driver or \\`${PACKAGE}/db/sqlite\\`. \\`npm test\\` and \\`npm run check\\` run \\`${PACKAGE} check-deps\\`, which names the file and line of a violation; do not move the \\`opener\\` entry to silence it.\n- \\`src/auth.ts\\`: scrypt password hashes (\\`node:crypto\\`) and the \\`sessions\\` table; the cookie \\`sid\\` holds a random token.\n- \\`src/schema.ts\\`: the rules for a note and for credentials. The HTML forms and the JSON API both use \\`checkNote\\`.\n- \\`src/views.tsx\\`: the pages, as JSX components rendered to strings, and the small script for the instant filter.\n- \\`src/client/\\`: client components, with their own \\`tsconfig.json\\` (browser types). \\`counter.tsx\\` is the live character counter. \\`clientModules\\` in \\`notes-app.ts\\` compiles them when the browser asks; \\`npm run build\\` compiles them once into \\`dist/client\\` for production. See \\`docs/framework/guides/client-modules.md\\`.\n- \\`src/notes-app.ts\\`: \\`createApp(db)\\` (pages and forms, csrf on) and \\`createApi(db)\\` (the JSON API under \\`/api/notes\\`, chained so \\`testClient\\` is typed). \\`src/app.ts\\` opens the database (top-level \\`await\\`) and exports the app and \\`close\\`; \\`src/index.ts\\` serves it and closes the database on SIGTERM. Tests open \\`openNotesDb(':memory:')\\` and pass its \\`db\\` to \\`createApp\\`.\n- \\`test/notes.test.ts\\`: a test for every route. A form POST in a test needs \\`origin: 'http://localhost'\\` (csrf) and the \\`sid\\` cookie from sign up.\n- Forms answer an invalid input with status 400 and the same page with the messages; a successful POST redirects with 303.\n- To add a column or a table: write the next migration (\\`migrations/002-name.sql\\`), then change \\`notesStore\\`, \\`checkNote\\`, the form and the list in \\`views.tsx\\`, and the tests. Do not edit \\`001-notes.sql\\`.\n\n## Before you ship\n\nRead \\`docs/framework/getting-started/deploy.md\\`. In short:\n\n- Install with \\`npm ci --omit=dev\\`, run \\`npm run build\\` (it compiles \\`src/client\\` once; with \\`NODE_ENV=production\\` only \\`dist/client\\` is served), and start with \\`NODE_ENV=production npm start\\` (\\`typescript\\` stays a runtime dependency: it compiles the \\`.tsx\\` pages at start).\n- The app listens on \\`127.0.0.1\\`; set \\`HOST=0.0.0.0\\` only in a container. \\`PORT\\` chooses the port.\n- Put the SQLite file outside the code folder (\\`NOTES_DB=/var/lib/notes/notes.sqlite\\`) and back it up.\n- Behind an HTTPS reverse proxy set \\`TRUST_PROXY=1\\` and \\`PUBLIC_ORIGIN=https://your.site\\`, or the cookie is not \\`Secure\\` and csrf refuses form posts.\n- \\`npm test\\` includes a test that starts the server and stops it with SIGTERM; keep it passing if you change \\`src/index.ts\\`.\n`\n : ''\n return `# ${name}\n\nAn ${CLASS} app (${template}${template === 'bun' ? ', experimental' : ''}): handlers over the Web Standard \\`Request\\` and \\`Response\\`, from the \\`${PACKAGE}\\` package.\n\n## The framework's API is in \\`docs/framework/\\`\n\nStart at \\`docs/framework/README.md\\`; \\`api/summary.md\\` is the one-page summary. Import the class from \\`'${PACKAGE}'\\` and each middleware or helper from its own\nsubpath (\\`'${PACKAGE}/cors'\\`, \\`'${PACKAGE}/validator'\\`, ...). Parts marked \"not yet available\" in the docs are not in the package yet.\n\n## This app\n\nRun it with \\`${run}\\`. The routes are in \\`${template === 'bun' ? 'src/index.ts' : template === 'notes' ? 'src/notes-app.ts' : template === 'chat' ? 'src/chat-app.ts' : 'src/app.ts'}\\`; an app is a function from \\`Request\\` to \\`Response\\`,\nso test a route with \\`await app.request('/path')\\` and no server.${desktopNote}\n\n${notesStructure}${chatStructure}\n## Things that surprise people\n\n- A page mounted at \\`/x\\` answers \\`/x\\`, not \\`/x/\\` (trailing slashes are strict); \\`trimTrailingSlash()\\` redirects.\n- A \\`json\\` validator target reads the body only with a JSON \\`Content-Type\\`; a failure answers 400 with \\`{ error, issues: [{ message, path }] }\\`.\n- \\`throw new HTTPException(404, { message })\\` answers an error response (plain text).\n- \\`testClient(app)\\` from \\`'${PACKAGE}/testing'\\` types only routes chained on the \\`new ${CLASS}()\\` expression (\\`new ${CLASS}().get(...).post(...)\\`); headers such as a cookie go in the second argument of each call.\n- **JSX:** ${jsxNote}\n${clientNote}\n## Before you say you are done\n\n\\`${test}\\` pass.\n`\n}\n\nfunction copyDocs(target: string): void {\n const filter = (path: string) => !/(upstream\\.json|UPSTREAM\\.md)$/.test(path)\n mkdirSync(join(target, 'docs'), { recursive: true })\n cpSync(docsRoot(), join(target, 'docs', 'framework'), { recursive: true, filter })\n}\n\nfunction copyTemplate(\n template: Exclude<Template, 'acryl-app'>,\n target: string,\n name: string,\n): string[] {\n const written: string[] = []\n const walk = (from: string, to: string, prefix: string) => {\n mkdirSync(to, { recursive: true })\n for (const entry of readdirSync(from, { withFileTypes: true })) {\n const targetName = prefix === '' && entry.name === 'gitignore' ? '.gitignore' : entry.name\n if (entry.isDirectory())\n walk(join(from, entry.name), join(to, targetName), `${prefix}${entry.name}/`)\n else {\n writeFileSync(\n join(to, targetName),\n replacePlaceholders(readFileSync(join(from, entry.name), 'utf8'), name),\n )\n written.push(`${prefix}${targetName}`)\n }\n }\n }\n walk(join(templatesRoot(), template), target, '')\n writeFileSync(join(target, 'AGENTS.md'), agentsText(template, name))\n writeFileSync(join(target, 'CLAUDE.md'), '@AGENTS.md\\n')\n copyDocs(target)\n return written\n}\n\nconst isEmpty = (directory: string) => !existsSync(directory) || readdirSync(directory).length === 0\n\n/** The `acrylblends` command of the installed framework package, which creates the `acryl-app` template. */\nfunction acrylblendsBin(): string {\n const pkgFile = createRequire(import.meta.url).resolve(`${PACKAGE}/package.json`)\n const pkg = JSON.parse(readFileSync(pkgFile, 'utf8')) as { bin?: string | Record<string, string> }\n const bin = typeof pkg.bin === 'string' ? pkg.bin : pkg.bin?.[PACKAGE]\n if (!bin) throw new Error(`${PACKAGE} has no command to create an app with`)\n return join(dirname(pkgFile), bin)\n}\n\n/** The lifecycle scripts a template defines and the line that says when they run. */\nconst describeScripts = (scripts: Record<string, string>) =>\n Object.entries(scripts)\n .map(([key, value]) => ` ${key}: ${value}`)\n .join('\\n')\n\n/** Files whose text is checked for secrets: the template's own, not the framework docs copied in. */\nfunction textFiles(root: string): { path: string; text: string }[] {\n const found: { path: string; text: string }[] = []\n const walk = (dir: string, prefix: string) => {\n for (const entry of readdirSync(dir, { withFileTypes: true })) {\n if (\n entry.name === 'node_modules' ||\n entry.name === '.git' ||\n (prefix === '' && entry.name === 'docs')\n )\n continue\n if (entry.isDirectory()) walk(join(dir, entry.name), `${prefix}${entry.name}/`)\n else {\n const buffer = readFileSync(join(dir, entry.name))\n if (!buffer.subarray(0, 8000).includes(0))\n found.push({ path: `${prefix}${entry.name}`, text: buffer.toString('utf8') })\n }\n }\n }\n walk(root, '')\n return found\n}\n\n/**\n * Create an app from a template source (`github:`, `@scope/name`, a packed tarball). The source is fetched and unpacked into a scratch folder, checked\n * (manifest, secrets), and only then copied to the target; nothing in it is installed or run unless `--install`, which lists the scripts first.\n */\nasync function createFromSource(\n options: CreateOptions,\n target: string,\n directory: string,\n io: Io,\n): Promise<number> {\n if (!isEmpty(target)) {\n io.stderr.write(`error: ${target} is not empty; nothing was changed\\n`)\n return 1\n }\n const scratch = mkdtempSync(join(tmpdir(), 'create-acrylblends-'))\n try {\n const source = parseSource(options.source!, io.cwd)\n if (!source)\n throw new UsageError(`unknown template source \"${options.source}\" (${SOURCE_FORMS})`)\n const name = nameFrom(target)\n await fetchSource(\n source,\n join(scratch, 'source'),\n join(scratch, 'download'),\n io.fetchers ?? realFetchers,\n )\n const manifest = readManifest(join(scratch, 'source'))\n const staged = join(scratch, 'app')\n const { files, lifecycle } = writeTemplate(\n join(scratch, 'source'),\n staged,\n (text) => replacePlaceholders(text, name),\n frameworkRange(),\n name,\n )\n if (!existsSync(join(staged, 'AGENTS.md')))\n writeFileSync(\n join(staged, 'AGENTS.md'),\n `# ${name}\\n\\nAn ${CLASS} app made from the template \"${manifest.name}\": ${manifest.description}\\n\\nThe framework's API is in \\`docs/framework/\\` (start at \\`docs/framework/README.md\\`).\\n`,\n )\n if (!existsSync(join(staged, 'CLAUDE.md')))\n writeFileSync(join(staged, 'CLAUDE.md'), '@AGENTS.md\\n')\n const found = findSecrets(textFiles(staged))\n if (found.length > 0) {\n io.stderr.write(\n `error: the template holds what looks like a secret, so nothing was created:\\n${found.map((f) => ` ${f.path}:${f.line} (${f.kind})`).join('\\n')}\\n`,\n )\n return 1\n }\n copyDocs(staged)\n cpSync(staged, target, { recursive: true })\n io.stdout.write(\n `created ${name} from ${manifest.name} (${manifest.description}) in ${target}: ${files.length} files, ${CLASS} docs in docs/framework\\n`,\n )\n if (manifest.plugins.length > 0)\n io.stdout.write(\n `it needs these plugins: ${manifest.plugins.join(', ')}; add them with: npx ${PACKAGE} add ${manifest.plugins.join(' ')}\\n`,\n )\n const pm: PackageManager =\n options.pm ??\n ((PACKAGE_MANAGERS as readonly string[]).find((m) =>\n (io.env.npm_config_user_agent ?? '').startsWith(`${m}/`),\n ) as PackageManager | undefined) ??\n 'npm'\n const hasScripts = Object.keys(lifecycle).length > 0\n if (options.install) {\n const pkg = JSON.parse(readFileSync(join(target, 'package.json'), 'utf8')) as {\n dependencies?: object\n devDependencies?: object\n }\n io.stdout.write(\n `running ${pm} install in ${directory}. This installs: ${[...Object.keys(pkg.dependencies ?? {}), ...Object.keys(pkg.devDependencies ?? {})].join(', ') || 'nothing'}` +\n `${hasScripts ? `\\nand runs the template's own lifecycle scripts:\\n${describeScripts(lifecycle)}` : ''}\\n` +\n `(the dependencies' install scripts run too unless your ${pm} is set to ignore them)\\n`,\n )\n if ((await io.run(pm, ['install'], target)) !== 0) {\n io.stderr.write(`error: ${pm} install failed; run it yourself in ${directory}\\n`)\n return 1\n }\n } else if (hasScripts) {\n io.stdout.write(\n `nothing was installed or run. The template defines ${LIFECYCLE.filter((k) => lifecycle[k]).join(', ')}, which ${pm} install would run:\\n${describeScripts(lifecycle)}\\nread them first, or pass --install to run them.\\n`,\n )\n }\n io.stdout.write(\n `\\nNext:\\n cd ${directory}\\n${options.install ? '' : ` ${pm} install\\n`} see the template's README or package.json scripts\\n`,\n )\n return 0\n } catch (error) {\n if (error instanceof SourceError) {\n io.stderr.write(`error: ${error.message}\\nnothing was changed\\n`)\n return 1\n }\n throw error\n } finally {\n removeTree(scratch)\n }\n}\n\n/** Create the app. Returns the exit code: 0 done, 1 refused or failed, 2 a usage error. Never calls `process.exit`. */\nexport async function runCreate(argv: readonly string[], io: Io = processIo()): Promise<number> {\n try {\n if (argv.includes('-h') || argv.includes('--help')) {\n io.stdout.write(HELP)\n return 0\n }\n if (argv.includes('-v') || argv.includes('--version')) {\n io.stdout.write(`${VERSION}\\n`)\n return 0\n }\n const options = parseCreateOptions(argv)\n const ask = options.yes ? undefined : io.ask\n const directory =\n options.directory ??\n (ask\n ? (await ask(`Project directory (${PACKAGE}-app): `)).trim() || `${PACKAGE}-app`\n : `${PACKAGE}-app`)\n const target = resolve(io.cwd, directory)\n if (options.source !== undefined) return await createFromSource(options, target, directory, io)\n const template: Template =\n options.template ??\n (ask\n ? await (async () => {\n const answer =\n (\n await ask(\n `Which template do you want to use? (nodejs, notes, chat, bun (experimental), acryl-app) [nodejs]: `,\n )\n ).trim() || 'nodejs'\n if (!isTemplate(answer))\n throw new UsageError(`unknown template \"${answer}\" (${TEMPLATES.join(', ')})`)\n return answer\n })()\n : 'nodejs')\n if (!isEmpty(target)) {\n io.stderr.write(`error: ${target} is not empty; nothing was changed\\n`)\n return 1\n }\n const name = nameFrom(target)\n if (template === 'acryl-app') {\n const code = await io.run(\n process.execPath,\n [acrylblendsBin(), 'init', target, '--template', 'agent', '--name', name, '--yes'],\n io.cwd,\n )\n if (code !== 0) return 1\n } else {\n const files = copyTemplate(template, target, name)\n io.stdout.write(\n `created ${name} (${template}) in ${target}: ${files.length} files, ${CLASS} docs in docs/framework\\n`,\n )\n }\n const pm: PackageManager =\n options.pm ??\n ((PACKAGE_MANAGERS as readonly string[]).find((m) =>\n (io.env.npm_config_user_agent ?? '').startsWith(`${m}/`),\n ) as PackageManager | undefined) ??\n 'npm'\n if (options.install) {\n if ((await io.run(pm, ['install'], target)) !== 0) {\n io.stderr.write(`error: ${pm} install failed; run it yourself in ${directory}\\n`)\n return 1\n }\n }\n const start = {\n nodejs: `${pm} run dev`,\n notes: `${pm} run dev`,\n chat: `${pm} run dev`,\n bun: 'bun run dev',\n 'acryl-app': `${pm} run dev`,\n }[template]\n io.stdout.write(\n `\\nNext:\\n cd ${directory}\\n${options.install ? '' : ` ${pm} install\\n`} ${start}\\n`,\n )\n return 0\n } catch (error) {\n if (error instanceof UsageError) {\n io.stderr.write(`error: ${error.message}\\n\\n${HELP}`)\n return 2\n }\n io.stderr.write(`error: ${(error as Error).message}\\n`)\n return 1\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AAIA,MAAa,UAAU;AACvB,MAAa,QAAQ;AACrB,MAAa,SAAS;;AAGtB,MAAa,oBAAoB;;;;;;;;ACuBjC,IAAa,cAAb,cAAiC,MAAM;CACrC,OAAgB;AAClB;AAEA,MAAa,eAAe;AAE5B,MAAM,SAAS;CAAE,OAAO;CAAM,OAAO;AAAiB;;AAGtD,SAAgB,YAAY,MAAc,KAAiC;CACzE,MAAM,SAAS,wEAAwE,KAAK,IAAI;CAChG,IAAI,QAAQ,OAAO;EAAE,MAAM;EAAU,OAAO,OAAO;EAAK,MAAM,OAAO;EAAK,KAAK,OAAO;CAAG;CACzF,IAAI,KAAK,WAAW,SAAS,GAAG,MAAM,IAAI,YAAY,IAAI,KAAK,iCAAiC;CAChG,IAAI,mEAAmE,KAAK,IAAI,GAC9E,OAAO;EAAE,MAAM;EAAO,MAAM;CAAK;CACnC,IAAI,KAAK,WAAW,GAAG,GAAG,MAAM,IAAI,YAAY,IAAI,KAAK,+BAA+B;CACxF,IAAI,mBAAmB,KAAK,IAAI,GAAG;EACjC,MAAM,OAAO,QAAQ,KAAK,IAAI;EAC9B,IAAI,CAAC,WAAW,IAAI,GAAG,MAAM,IAAI,YAAY,GAAG,KAAK,gBAAgB;EACrE,OAAO;GAAE,MAAM;GAAW;EAAK;CACjC;A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;EACA,MAAM,OAAO,SAAS,MAAM;EAC5B,IAAI,aAAa,aAMX;OAAA,MALe,GAAG,IACpB,QAAQ,UACR;IAAC,eAAe;IAAG;IAAQ;IAAQ;IAAc;IAAS;IAAU;IAAM;GAAO,GACjF,GAAG,GACL,MACa,GAAG,OAAO;EAAA,OAClB;GACL,MAAM,QAAQ,aAAa,UAAU,QAAQ,IAAI;GACjD,GAAG,OAAO,MACR,WAAW,KAAK,IAAI,SAAS,OAAO,OAAO,IAAI,MAAM,OAAO,UAAU,MAAM,0BAC9E;EACF;EACA,MAAM,KACJ,QAAQ,MACN,iBAAuC,MAAM,OAC5C,GAAG,IAAI,yBAAyB,GAAA,CAAI,WAAW,GAAG,EAAE,EAAE,CACzD,KACA;EACF,IAAI,QAAQ,SACL;OAAA,MAAM,GAAG,IAAI,IAAI,CAAC,SAAS,GAAG,MAAM,MAAO,GAAG;IACjD,GAAG,OAAO,MAAM,UAAU,GAAG,sCAAsC,UAAU,GAAG;IAChF,OAAO;GACT;;EAEF,MAAM,QAAQ;GACZ,QAAQ,GAAG,GAAG;GACd,OAAO,GAAG,GAAG;GACb,MAAM,GAAG,GAAG;GACZ,KAAK;GACL,aAAa,GAAG,GAAG;EACrB,EAAE;EACF,GAAG,OAAO,MACR,iBAAiB,UAAU,IAAI,QAAQ,UAAU,KAAK,KAAK,GAAG,YAAY,IAAI,MAAM,GACtF;EACA,OAAO;CACT,SAAS,OAAO;EACd,IAAI,iBAAiB,YAAY;GAC/B,GAAG,OAAO,MAAM,UAAU,MAAM,QAAQ,MAAM,MAAM;GACpD,OAAO;EACT;EACA,GAAG,OAAO,MAAM,UAAW,MAAgB,QAAQ,GAAG;EACtD,OAAO;CACT;AACF"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
# Generated copy
|
|
2
2
|
|
|
3
|
-
This folder is a copy of `docs/framework` of acryldev/acryl at commit `
|
|
3
|
+
This folder is a copy of `docs/framework` of acryldev/acryl at commit `f8e385e4389fe2fdc6fd2a4366a7f2a7389faacb`, made by `scripts/sync-framework.mjs`. Do not edit it here: change the text in ACRYL and sync again. `pnpm run verify:framework` fails when a page differs from the recorded digest.
|
|
@@ -10,10 +10,74 @@ provider today; a Postgres provider (Postgres or Supabase through `DATABASE_URL`
|
|
|
10
10
|
| --- | --- | --- |
|
|
11
11
|
| Normal web or desktop app, users, lists, orders | `db` with SQLite (the `notes` and `chat` templates) | available |
|
|
12
12
|
| Hosted, many users | `db` with Postgres or Supabase | planned |
|
|
13
|
-
| Tiny, one person, a few screens | `kv
|
|
13
|
+
| Tiny, one person, a few screens | [`kv`](#a-tiny-app-kv), named JSON documents with no SQL | available |
|
|
14
14
|
| Agents or long tasks that must survive a restart | `durable`, in the same database as `db` | planned |
|
|
15
15
|
|
|
16
|
-
Start with `db
|
|
16
|
+
Start with `db` when the data has users, lists or relations: SQL is what people and coding agents already know. Start with `kv` when the whole
|
|
17
|
+
data is a handful of settings or a small list that one process reads and writes.
|
|
18
|
+
|
|
19
|
+
## A tiny app: `kv`
|
|
20
|
+
|
|
21
|
+
`kv` keeps named JSON documents in one file, with no SQL and no migrations. It suits a settings page, a demo, a one-person tool.
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
import { openKv } from 'acrylblends/kv/json'
|
|
25
|
+
|
|
26
|
+
const { kv, close } = await openKv({ path: 'data/kv.json' })
|
|
27
|
+
|
|
28
|
+
await kv.set('theme', 'dark')
|
|
29
|
+
const theme = await kv.get<string>('theme') // 'dark'; undefined for a key that was never set
|
|
30
|
+
|
|
31
|
+
// Change a value from the value it has now, without losing a concurrent change.
|
|
32
|
+
const visits = await kv.update<number>('visits', (current) => (current ?? 0) + 1)
|
|
33
|
+
|
|
34
|
+
await kv.set('todos/1', { title: 'Buy milk', done: false })
|
|
35
|
+
await kv.set('todos/2', { title: 'Write docs', done: true })
|
|
36
|
+
const keys = await kv.list('todos/') // ['todos/1', 'todos/2'], sorted by code point
|
|
37
|
+
|
|
38
|
+
await kv.delete('todos/1') // a key that is not there is not an error
|
|
39
|
+
await close()
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
- A key is a non-empty string; a prefix such as `todos/` groups related documents. A value is JSON (`null`, booleans, numbers, strings, arrays,
|
|
43
|
+
objects). `undefined`, functions, bigints and `NaN` are refused with a `TypeError` before anything is written, and a value read back is a copy.
|
|
44
|
+
- `update` runs your function with the current value (`undefined` when the key is missing) and stores what it returns. The function is
|
|
45
|
+
**synchronous**: an `async` function is a type error. Read what you need first with `await kv.get(...)`, then update with a plain function.
|
|
46
|
+
If it throws, the value stays as it was.
|
|
47
|
+
- Every write reaches the disk before its promise resolves, and the file is replaced as a whole (a temporary file, then a rename), so a crash
|
|
48
|
+
or a power cut leaves the old file or the new one, never half of one. A file that exists but does not parse stops the app with a message that
|
|
49
|
+
names it; it is never started over.
|
|
50
|
+
- Like `db`, the store is passed to the code that needs it (`createApp(kv)`), opened in one place, and closed when the process stops.
|
|
51
|
+
A test opens a file in a temporary folder.
|
|
52
|
+
|
|
53
|
+
### When to move to SQL
|
|
54
|
+
|
|
55
|
+
The whole file is kept in memory and rewritten on every write, and one process owns it. Move to `db` when:
|
|
56
|
+
|
|
57
|
+
- more than one process must write (two writers would overwrite each other);
|
|
58
|
+
- the file grows past a few megabytes, or you need to search, sort or join the data;
|
|
59
|
+
- the data gets relations (users who own notes).
|
|
60
|
+
|
|
61
|
+
The same `kv` interface runs on SQL, so the code does not change, only the line that opens it. `kvOnDb` keeps the documents in a `kv` table of the
|
|
62
|
+
database from `openDb`, and `copyKv` moves what the file holds:
|
|
63
|
+
|
|
64
|
+
```ts
|
|
65
|
+
import { copyKv } from 'acrylblends/kv'
|
|
66
|
+
import { openKv } from 'acrylblends/kv/json'
|
|
67
|
+
import { kvOnDb } from 'acrylblends/kv/db'
|
|
68
|
+
import { openDb } from 'acrylblends/db/sqlite'
|
|
69
|
+
|
|
70
|
+
const file = await openKv({ path: 'data/kv.json' })
|
|
71
|
+
const sql = await openDb({ path: 'data/app.sqlite', migrations: 'migrations' })
|
|
72
|
+
|
|
73
|
+
const { copied } = await copyKv(file.kv, kvOnDb(sql.db)) // refuses to overwrite a key the table already has, unless you pass { overwrite: true }
|
|
74
|
+
|
|
75
|
+
await file.close()
|
|
76
|
+
await sql.close()
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
On the command line, `npx acrylblends kv import data/kv.json data/app.sqlite` does the same (add `--overwrite` to replace keys the table has).
|
|
80
|
+
The table is created on first use, beside the app's own tables; nothing else changes.
|
|
17
81
|
|
|
18
82
|
## Open the database
|
|
19
83
|
|
|
@@ -182,6 +246,41 @@ process.once('SIGTERM', async () => {
|
|
|
182
246
|
copy of `data/app.sqlite` made afterwards is complete. Keep the file on a disk that outlives a deploy; on a host with only an ephemeral disk the
|
|
183
247
|
data goes with the machine.
|
|
184
248
|
|
|
249
|
+
## Why the database is opened in one place
|
|
250
|
+
|
|
251
|
+
Only one file of an app opens the database: the **opener** (`src/db.ts` in the templates). Every other file receives a `Db` as an argument and
|
|
252
|
+
imports its type from `acrylblends/db`. Nothing outside the opener imports `node:sqlite`, `pg`, `postgres`, `@electric-sql/pglite` or another
|
|
253
|
+
driver, or `acrylblends/db/sqlite` itself.
|
|
254
|
+
|
|
255
|
+
Why it matters:
|
|
256
|
+
|
|
257
|
+
- **Changing the database is one file.** Moving from SQLite to Postgres changes what the opener calls, and no route, store or test.
|
|
258
|
+
- **A test opens its own database.** Code that opens a database by itself cannot be given an in-memory one, and a test that reaches the real file
|
|
259
|
+
breaks the next one.
|
|
260
|
+
- **There is one place to close it.** The code that opened a database closes it; the port has no `close`, so a route cannot do it by mistake.
|
|
261
|
+
- **An agent that adds a feature keeps the shape.** A coding agent asked for "tags" writes a migration and a store function, and has no reason to
|
|
262
|
+
reach for a driver when the interface is in front of it.
|
|
263
|
+
|
|
264
|
+
The rule is checked, not hoped for. The app names its opener once, in `package.json`:
|
|
265
|
+
|
|
266
|
+
```json
|
|
267
|
+
{
|
|
268
|
+
"acryl": { "opener": "src/db.ts" }
|
|
269
|
+
}
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
`acrylblends check-deps` reads every `.ts`, `.tsx` and `.js` file in `src/`, `test/`, `tests/` and `extensions/`, and fails when a file other than
|
|
273
|
+
the opener imports a database driver, an opener such as `acrylblends/db/sqlite` or `acryl-db-sqlite`, or (outside `src/plugins/desktop`) `electron`.
|
|
274
|
+
It names the file and the line:
|
|
275
|
+
|
|
276
|
+
```
|
|
277
|
+
src/routes.ts:3: "node:sqlite" is a database driver; take a Db (import type { Db } from "acrylblends/db") as an argument and let src/db.ts open the database
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
The `notes` and `chat` templates run it in `npm test` and `npm run check`. List more than one opener as an array (`"opener": ["src/db.ts", "src/app.ts"]`).
|
|
281
|
+
In a Blend app, `acrylblends add db` declares `src/app.ts`, where the provider is mounted, and a plugin that declares `inject: ['db']` must not import
|
|
282
|
+
`acryl-db-sqlite`: it receives `ctx.db`.
|
|
283
|
+
|
|
185
284
|
## In a Cordis app
|
|
186
285
|
|
|
187
286
|
An ACRYL app gets the same interface as a service. The `acryl-db-sqlite` plugin row opens the file (by default `data.sqlite` in the app home),
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
"source": {
|
|
3
3
|
"repo": "acryldev/acryl",
|
|
4
4
|
"path": "docs/framework",
|
|
5
|
-
"commit": "
|
|
5
|
+
"commit": "f8e385e4389fe2fdc6fd2a4366a7f2a7389faacb"
|
|
6
6
|
},
|
|
7
7
|
"files": 99,
|
|
8
|
-
"digest": "sha256:
|
|
8
|
+
"digest": "sha256:075d537930a53f7ba46b989ff82f9d83a720270c60d848917e6501bfabff6df1"
|
|
9
9
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-acrylblends",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.7",
|
|
4
4
|
"description": "Create an Acryl app: npm create acrylblends@latest",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"scaffold"
|
|
38
38
|
],
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"acrylblends": "^0.7.
|
|
40
|
+
"acrylblends": "^0.7.7",
|
|
41
41
|
"@webboxes/app-persistence": "0.1.1"
|
|
42
42
|
},
|
|
43
43
|
"publishConfig": {
|
|
@@ -3,14 +3,17 @@
|
|
|
3
3
|
"version": "0.1.0",
|
|
4
4
|
"private": true,
|
|
5
5
|
"type": "module",
|
|
6
|
+
"acryl": {
|
|
7
|
+
"opener": "src/db.ts"
|
|
8
|
+
},
|
|
6
9
|
"engines": {
|
|
7
10
|
"node": ">=22.19.0"
|
|
8
11
|
},
|
|
9
12
|
"scripts": {
|
|
10
13
|
"dev": "node --watch --import acrylblends/node-server/register src/index.ts",
|
|
11
14
|
"start": "node --import acrylblends/node-server/register src/index.ts",
|
|
12
|
-
"test": "node --import acrylblends/node-server/register --test \"test/**/*.test.{ts,tsx}\"",
|
|
13
|
-
"check": "tsc --noEmit && tsc --noEmit -p src/client",
|
|
15
|
+
"test": "acrylblends check-deps && node --import acrylblends/node-server/register --test \"test/**/*.test.{ts,tsx}\"",
|
|
16
|
+
"check": "tsc --noEmit && tsc --noEmit -p src/client && acrylblends check-deps",
|
|
14
17
|
"build": "acrylblends build-client"
|
|
15
18
|
},
|
|
16
19
|
"dependencies": {
|
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
"scripts": {
|
|
10
10
|
"dev": "node --watch --import acrylblends/node-server/register src/index.ts",
|
|
11
11
|
"start": "node --import acrylblends/node-server/register src/index.ts",
|
|
12
|
-
"test": "node --import acrylblends/node-server/register --test \"test/**/*.test.{ts,tsx}\"",
|
|
13
|
-
"check": "tsc --noEmit && tsc --noEmit -p src/client",
|
|
12
|
+
"test": "acrylblends check-deps && node --import acrylblends/node-server/register --test \"test/**/*.test.{ts,tsx}\"",
|
|
13
|
+
"check": "tsc --noEmit && tsc --noEmit -p src/client && acrylblends check-deps",
|
|
14
14
|
"build": "acrylblends build-client"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
@@ -3,14 +3,17 @@
|
|
|
3
3
|
"version": "0.1.0",
|
|
4
4
|
"private": true,
|
|
5
5
|
"type": "module",
|
|
6
|
+
"acryl": {
|
|
7
|
+
"opener": "src/db.ts"
|
|
8
|
+
},
|
|
6
9
|
"engines": {
|
|
7
10
|
"node": ">=22.19.0"
|
|
8
11
|
},
|
|
9
12
|
"scripts": {
|
|
10
13
|
"dev": "node --watch --import acrylblends/node-server/register src/index.ts",
|
|
11
14
|
"start": "node --import acrylblends/node-server/register src/index.ts",
|
|
12
|
-
"test": "node --import acrylblends/node-server/register --test \"test/**/*.test.{ts,tsx}\"",
|
|
13
|
-
"check": "tsc --noEmit && tsc --noEmit -p src/client",
|
|
15
|
+
"test": "acrylblends check-deps && node --import acrylblends/node-server/register --test \"test/**/*.test.{ts,tsx}\"",
|
|
16
|
+
"check": "tsc --noEmit && tsc --noEmit -p src/client && acrylblends check-deps",
|
|
14
17
|
"build": "acrylblends build-client"
|
|
15
18
|
},
|
|
16
19
|
"dependencies": {
|