@velastack/patterns 0.15.1 → 0.15.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunks/{_page-Cg7LjaOE.js → _page-BFUn0CG1.js} +2 -2
- package/dist/chunks/{_page-Cg7LjaOE.js.map → _page-BFUn0CG1.js.map} +1 -1
- package/dist/chunks/{auth-pages-DSBqKjO0.js → auth-pages-D8n8gfCL.js} +2 -2
- package/dist/chunks/{auth-pages-DSBqKjO0.js.map → auth-pages-D8n8gfCL.js.map} +1 -1
- package/dist/chunks/{collections-D2_2cxWD.js → collections-Daxlnbm0.js} +2 -2
- package/dist/chunks/{collections-D2_2cxWD.js.map → collections-Daxlnbm0.js.map} +1 -1
- package/dist/chunks/{constants-DbpctM1D.js → constants-E1I-__KI.js} +18 -18
- package/dist/chunks/{constants-DbpctM1D.js.map → constants-E1I-__KI.js.map} +1 -1
- package/dist/chunks/{currency.server-CFrwmYra.js → currency.server-BkzwY17R.js} +2 -2
- package/dist/chunks/{currency.server-CFrwmYra.js.map → currency.server-BkzwY17R.js.map} +1 -1
- package/dist/chunks/{env-vars-Dm3Xy4rl.js → env-vars-C3TSZc4f.js} +3 -3
- package/dist/chunks/{env-vars-Dm3Xy4rl.js.map → env-vars-C3TSZc4f.js.map} +1 -1
- package/dist/chunks/{generate-BMWoD9E2.js → generate-CAYM7OUF.js} +2 -2
- package/dist/chunks/{generate-BMWoD9E2.js.map → generate-CAYM7OUF.js.map} +1 -1
- package/dist/chunks/{generate-DZ9kT3iC.js → generate-CL7wG0ZC.js} +3 -3
- package/dist/chunks/{generate-DZ9kT3iC.js.map → generate-CL7wG0ZC.js.map} +1 -1
- package/dist/chunks/{generate-BRTIGlqT.js → generate-CbchamhA.js} +3 -3
- package/dist/chunks/{generate-BRTIGlqT.js.map → generate-CbchamhA.js.map} +1 -1
- package/dist/chunks/{generate-Cs_fdfD7.js → generate-DI58vuk1.js} +2 -2
- package/dist/chunks/{generate-Cs_fdfD7.js.map → generate-DI58vuk1.js.map} +1 -1
- package/dist/chunks/{generate-BvQ6VwYH.js → generate-DR2wkVPY.js} +2 -2
- package/dist/chunks/{generate-BvQ6VwYH.js.map → generate-DR2wkVPY.js.map} +1 -1
- package/dist/chunks/{generate.runtime-1eTnPFmA.js → generate.runtime-B11mOr45.js} +2 -2
- package/dist/chunks/{generate.runtime-1eTnPFmA.js.map → generate.runtime-B11mOr45.js.map} +1 -1
- package/dist/chunks/{generate.runtime-CjLath7N.js → generate.runtime-B1Y2JrGW.js} +5 -5
- package/dist/chunks/{generate.runtime-CjLath7N.js.map → generate.runtime-B1Y2JrGW.js.map} +1 -1
- package/dist/chunks/{generate.runtime-CnNtG_x5.js → generate.runtime-B7VubPTW.js} +3 -3
- package/dist/chunks/{generate.runtime-CnNtG_x5.js.map → generate.runtime-B7VubPTW.js.map} +1 -1
- package/dist/chunks/{generate.runtime-BvHK8IN-.js → generate.runtime-BCv4F1Wm.js} +5 -5
- package/dist/chunks/{generate.runtime-BvHK8IN-.js.map → generate.runtime-BCv4F1Wm.js.map} +1 -1
- package/dist/chunks/{generate.runtime-D8G8cwCr.js → generate.runtime-BEWp57Y7.js} +2 -2
- package/dist/chunks/{generate.runtime-D8G8cwCr.js.map → generate.runtime-BEWp57Y7.js.map} +1 -1
- package/dist/chunks/{generate.runtime-B4mQEW54.js → generate.runtime-BH6hHygm.js} +3 -3
- package/dist/chunks/{generate.runtime-B4mQEW54.js.map → generate.runtime-BH6hHygm.js.map} +1 -1
- package/dist/chunks/{generate.runtime-CfCDLJ6Y.js → generate.runtime-BL6DpWFI.js} +3 -3
- package/dist/chunks/{generate.runtime-CfCDLJ6Y.js.map → generate.runtime-BL6DpWFI.js.map} +1 -1
- package/dist/chunks/{generate.runtime-BJwSyslL.js → generate.runtime-BRV9hIl5.js} +2 -2
- package/dist/chunks/{generate.runtime-BJwSyslL.js.map → generate.runtime-BRV9hIl5.js.map} +1 -1
- package/dist/chunks/{generate.runtime-B9nVU5iO.js → generate.runtime-BRcP6sFt.js} +2 -2
- package/dist/chunks/{generate.runtime-B9nVU5iO.js.map → generate.runtime-BRcP6sFt.js.map} +1 -1
- package/dist/chunks/{generate.runtime-BC1GJUXE.js → generate.runtime-Bhs7ttZS.js} +2 -2
- package/dist/chunks/{generate.runtime-BC1GJUXE.js.map → generate.runtime-Bhs7ttZS.js.map} +1 -1
- package/dist/chunks/{generate.runtime-Bda2_WK7.js → generate.runtime-BjrtdoYE.js} +2 -2
- package/dist/chunks/{generate.runtime-Bda2_WK7.js.map → generate.runtime-BjrtdoYE.js.map} +1 -1
- package/dist/chunks/{generate.runtime-DBQvnQmR.js → generate.runtime-Bo_s7gYB.js} +2 -2
- package/dist/chunks/{generate.runtime-DBQvnQmR.js.map → generate.runtime-Bo_s7gYB.js.map} +1 -1
- package/dist/chunks/{generate.runtime-DQUZRJH8.js → generate.runtime-Bs77Oc8P.js} +3 -3
- package/dist/chunks/{generate.runtime-DQUZRJH8.js.map → generate.runtime-Bs77Oc8P.js.map} +1 -1
- package/dist/chunks/{generate.runtime-Cd742Yqf.js → generate.runtime-C3IswX7B.js} +2 -2
- package/dist/chunks/{generate.runtime-Cd742Yqf.js.map → generate.runtime-C3IswX7B.js.map} +1 -1
- package/dist/chunks/{generate.runtime-B-H2F-sH.js → generate.runtime-C90_2L-8.js} +3 -3
- package/dist/chunks/{generate.runtime-B-H2F-sH.js.map → generate.runtime-C90_2L-8.js.map} +1 -1
- package/dist/chunks/{generate.runtime-B4rG6gSK.js → generate.runtime-CDY0Ot_t.js} +6 -6
- package/dist/chunks/{generate.runtime-B4rG6gSK.js.map → generate.runtime-CDY0Ot_t.js.map} +1 -1
- package/dist/chunks/{generate.runtime-Doumu0TL.js → generate.runtime-CZMVPVjS.js} +6 -6
- package/dist/chunks/{generate.runtime-Doumu0TL.js.map → generate.runtime-CZMVPVjS.js.map} +1 -1
- package/dist/chunks/{generate.runtime-liAz2TOE.js → generate.runtime-C_hrLPD4.js} +3 -3
- package/dist/chunks/{generate.runtime-liAz2TOE.js.map → generate.runtime-C_hrLPD4.js.map} +1 -1
- package/dist/chunks/{generate.runtime-DE-vPcn4.js → generate.runtime-CdZ3GzPS.js} +6 -6
- package/dist/chunks/{generate.runtime-DE-vPcn4.js.map → generate.runtime-CdZ3GzPS.js.map} +1 -1
- package/dist/chunks/{generate.runtime-BkQPchHe.js → generate.runtime-ChSVP7cD.js} +6 -6
- package/dist/chunks/{generate.runtime-BkQPchHe.js.map → generate.runtime-ChSVP7cD.js.map} +1 -1
- package/dist/chunks/{generate.runtime-C1HlZnLC.js → generate.runtime-Cs73i6Zf.js} +2 -2
- package/dist/chunks/{generate.runtime-C1HlZnLC.js.map → generate.runtime-Cs73i6Zf.js.map} +1 -1
- package/dist/chunks/{generate.runtime-GmsldrGj.js → generate.runtime-D7KYlnvb.js} +3 -3
- package/dist/chunks/{generate.runtime-GmsldrGj.js.map → generate.runtime-D7KYlnvb.js.map} +1 -1
- package/dist/chunks/{generate.runtime-DFSsgOmB.js → generate.runtime-DG9LRwbt.js} +3 -3
- package/dist/chunks/{generate.runtime-DFSsgOmB.js.map → generate.runtime-DG9LRwbt.js.map} +1 -1
- package/dist/chunks/{generate.runtime-CIOi-XSm.js → generate.runtime-DKL7VAAd.js} +6 -6
- package/dist/chunks/{generate.runtime-CIOi-XSm.js.map → generate.runtime-DKL7VAAd.js.map} +1 -1
- package/dist/chunks/{generate.runtime-CQ_U4YTJ.js → generate.runtime-DP63Wwea.js} +4 -4
- package/dist/chunks/{generate.runtime-CQ_U4YTJ.js.map → generate.runtime-DP63Wwea.js.map} +1 -1
- package/dist/chunks/{generate.runtime-C62ChKGg.js → generate.runtime-DRPxOLnB.js} +4 -4
- package/dist/chunks/{generate.runtime-C62ChKGg.js.map → generate.runtime-DRPxOLnB.js.map} +1 -1
- package/dist/chunks/{generate.runtime-DQI69jkX.js → generate.runtime-DW9bqOtC.js} +2 -2
- package/dist/chunks/{generate.runtime-DQI69jkX.js.map → generate.runtime-DW9bqOtC.js.map} +1 -1
- package/dist/chunks/{generate.runtime-Dtum580c.js → generate.runtime-DdY44Ulv.js} +6 -6
- package/dist/chunks/{generate.runtime-Dtum580c.js.map → generate.runtime-DdY44Ulv.js.map} +1 -1
- package/dist/chunks/{generate.runtime-ufoTIUXA.js → generate.runtime-DjEj-n6m.js} +7 -7
- package/dist/chunks/{generate.runtime-ufoTIUXA.js.map → generate.runtime-DjEj-n6m.js.map} +1 -1
- package/dist/chunks/{generate.runtime-rxzMCECc.js → generate.runtime-DlAJQ5Js.js} +4 -4
- package/dist/chunks/{generate.runtime-rxzMCECc.js.map → generate.runtime-DlAJQ5Js.js.map} +1 -1
- package/dist/chunks/{generate.runtime-CZA46Ghe.js → generate.runtime-JftBoKYS.js} +5 -5
- package/dist/chunks/{generate.runtime-CZA46Ghe.js.map → generate.runtime-JftBoKYS.js.map} +1 -1
- package/dist/chunks/{generate.runtime-DNjyaFml.js → generate.runtime-_426A1Ij.js} +3 -3
- package/dist/chunks/{generate.runtime-DNjyaFml.js.map → generate.runtime-_426A1Ij.js.map} +1 -1
- package/dist/chunks/{generate.runtime-DR8z6DyZ.js → generate.runtime-fs6GEMx-.js} +5 -5
- package/dist/chunks/{generate.runtime-DR8z6DyZ.js.map → generate.runtime-fs6GEMx-.js.map} +1 -1
- package/dist/chunks/{generate.runtime-Diix70x4.js → generate.runtime-jIlQ2GMh.js} +2 -2
- package/dist/chunks/{generate.runtime-Diix70x4.js.map → generate.runtime-jIlQ2GMh.js.map} +1 -1
- package/dist/chunks/{generate.runtime-BuQASx9Y.js → generate.runtime-v3KCv1B6.js} +2 -2
- package/dist/chunks/{generate.runtime-BuQASx9Y.js.map → generate.runtime-v3KCv1B6.js.map} +1 -1
- package/dist/chunks/{generate.runtime-lP4eoera.js → generate.runtime-xrxAElb3.js} +3 -3
- package/dist/chunks/{generate.runtime-lP4eoera.js.map → generate.runtime-xrxAElb3.js.map} +1 -1
- package/dist/chunks/{gitignore-2XpeEFmr.js → gitignore-CBiWFRif.js} +3 -3
- package/dist/chunks/{gitignore-2XpeEFmr.js.map → gitignore-CBiWFRif.js.map} +1 -1
- package/dist/chunks/{i18n-CxT1kz8Y.js → i18n-Ho8H91Ze.js} +2 -2
- package/dist/chunks/{i18n-CxT1kz8Y.js.map → i18n-Ho8H91Ze.js.map} +1 -1
- package/dist/chunks/{modify-file-BX9-aZD1.js → modify-file-BOEKlIDw.js} +2 -2
- package/dist/chunks/{modify-file-BX9-aZD1.js.map → modify-file-BOEKlIDw.js.map} +1 -1
- package/dist/chunks/{pocketbase-Dq9UdK_j.js → pocketbase-B2ksFrvH.js} +2 -2
- package/dist/chunks/{pocketbase-Dq9UdK_j.js.map → pocketbase-B2ksFrvH.js.map} +1 -1
- package/dist/chunks/{providers-2UgxXRJW.js → providers-BEjDonyG.js} +2 -2
- package/dist/chunks/{providers-2UgxXRJW.js.map → providers-BEjDonyG.js.map} +1 -1
- package/dist/chunks/{route-BDhlro0V.js → route-9ZVJZkYu.js} +23 -19
- package/dist/chunks/route-9ZVJZkYu.js.map +1 -0
- package/dist/chunks/{schema-2frI_BS2.js → schema-DnMqw2Hn.js} +3 -3
- package/dist/chunks/{schema-2frI_BS2.js.map → schema-DnMqw2Hn.js.map} +1 -1
- package/dist/chunks/{shared-BOFCKWJs.js → shared-CSwGWMcN.js} +2 -2
- package/dist/chunks/{shared-BOFCKWJs.js.map → shared-CSwGWMcN.js.map} +1 -1
- package/dist/chunks/{shared-DJ4KvhTb.js → shared-Cdwm_-Nl.js} +40 -40
- package/dist/chunks/{shared-DJ4KvhTb.js.map → shared-Cdwm_-Nl.js.map} +1 -1
- package/dist/chunks/{site-qASrdyUt.js → site-B5zrFba9.js} +2 -2
- package/dist/chunks/{site-qASrdyUt.js.map → site-B5zrFba9.js.map} +1 -1
- package/dist/chunks/{table-core-s2xjYgRD.js → table-core-ux1xEJxN.js} +2 -2
- package/dist/chunks/{table-core-s2xjYgRD.js.map → table-core-ux1xEJxN.js.map} +1 -1
- package/dist/chunks/{ui-DZuwcswv.js → ui-CpjUq_lm.js} +3 -3
- package/dist/chunks/{ui-DZuwcswv.js.map → ui-CpjUq_lm.js.map} +1 -1
- package/dist/chunks/{whatsapp-BytvTPlS.js → whatsapp-DOSZ_zwn.js} +2 -2
- package/dist/chunks/{whatsapp-BytvTPlS.js.map → whatsapp-DOSZ_zwn.js.map} +1 -1
- package/dist/chunks/{write-result-BhfLWAXf.js → write-result-DlB-id5k.js} +50 -26
- package/dist/chunks/write-result-DlB-id5k.js.map +1 -0
- package/dist/index.js +1863 -1841
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunks/route-BDhlro0V.js.map +0 -1
- package/dist/chunks/write-result-BhfLWAXf.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pocketbase-Dq9UdK_j.js","names":["__exportAll","MIGRATIONS_DIR","DATA_DIR","POCKETBASE_BIN_ENV","path","PocketBase","spawn","net","BAD_PORTS","osAssignedPort","server","reject","host","resolve","port","freePort","waitForPort","attempts","tryConnect","socket","maxAttempts","describeFetchError","error","cause","waitForHealth","lastFailure","tryHealth","response","url","pocketbase_exports","withPocketbase","MIGRATION_DELAY_MS","migrationDelay","getMigrationFile","ending","action","collectionName","migrationFile","readdirSync","options","file","getPocketbaseMetadata","metadataPath","cwd","existsSync","readFileSync","authWithRetries","authSuccess","attempt","pb","email","password","pocketbaseCommand","bin","env","serverArgs","packageManager","detect","resolveCommand","args","dir","migrationsDir","metadata","fn","detached","serverProcess","command","exited","signal","code","stopProcessTree","child"],"sources":["../../src/runtime/net.ts","../../src/runtime/pocketbase.ts"],"sourcesContent":["import net from \"node:net\";\n\n/**\n * Ports the Fetch spec tells clients to refuse outright\n * (https://fetch.spec.whatwg.org/#port-blocking). Node's `fetch` enforces the\n * list, so a server bound to one of them is unreachable from `waitForHealth`\n * and the PocketBase SDK alike: the request fails with cause \"bad port\"\n * before a connection is even attempted. 10080 sat inside the 10000–19999\n * range ports used to be drawn from, and cost a CI run a 30-second health\n * timeout whenever the draw landed on it.\n */\nexport const BAD_PORTS: ReadonlySet<number> = new Set([\n 1, 7, 9, 11, 13, 15, 17, 19, 20, 21, 22, 23, 25, 37, 42, 43, 53, 69, 77, 79,\n 87, 95, 101, 102, 103, 104, 109, 110, 111, 113, 115, 117, 119, 123, 135, 137,\n 139, 143, 161, 179, 389, 427, 465, 512, 513, 514, 515, 526, 530, 531, 532,\n 540, 548, 554, 556, 563, 587, 601, 636, 989, 990, 993, 995, 1719, 1720, 1723,\n 2049, 3659, 4045, 4190, 5060, 5061, 6000, 6566, 6665, 6666, 6667, 6668, 6669,\n 6679, 6697, 10080,\n]);\n\nfunction osAssignedPort(host: string): Promise<number> {\n return new Promise((resolve, reject) => {\n const server = net.createServer();\n server.unref();\n server.once(\"error\", reject);\n server.listen(0, host, () => {\n const { port } = server.address() as net.AddressInfo;\n server.close(() => resolve(port));\n });\n });\n}\n\n/**\n * A port nothing is listening on right now, taken from the OS's ephemeral\n * range so it neither collides with whatever else the machine runs nor hits\n * `BAD_PORTS`. The port is released again before this resolves, so the\n * caller's server has to bind it promptly.\n */\nexport async function freePort(host: string): Promise<number> {\n for (;;) {\n const port = await osAssignedPort(host);\n if (!BAD_PORTS.has(port)) return port;\n }\n}\n\n// Wait for the port to be available. A cold `npx pocketbase-server` on a CI\n// runner can take well over the five seconds the old default allowed.\nexport function waitForPort(\n port: number,\n host: string,\n maxAttempts = 60,\n): Promise<void> {\n return new Promise((resolve, reject) => {\n let attempts = 0;\n\n const tryConnect = () => {\n attempts++;\n\n const socket = new net.Socket();\n\n const onError = () => {\n socket.destroy();\n\n if (attempts === maxAttempts) {\n reject(\n new Error(`Timed out waiting for port ${port} to be available`),\n );\n return;\n }\n\n setTimeout(tryConnect, 500);\n };\n\n socket.once(\"error\", onError);\n\n socket.connect(port, host, () => {\n socket.destroy();\n resolve();\n });\n };\n\n tryConnect();\n });\n}\n\n/**\n * `fetch` wraps the interesting part in `cause`: an errno error for a\n * connection that was refused, or a bare string such as \"bad port\" for a\n * request undici declined to make.\n */\nfunction describeFetchError(error: unknown): string {\n if (!(error instanceof Error)) return String(error);\n const { cause } = error as Error & { cause?: unknown };\n if (cause instanceof Error) {\n const code = (cause as NodeJS.ErrnoException).code;\n return code || cause.message || error.message;\n }\n if (cause !== undefined) return String(cause);\n return error.message;\n}\n\n// Wait for the health check to be successful\nexport function waitForHealth(url: string, maxAttempts = 60): Promise<void> {\n return new Promise((resolve, reject) => {\n let attempts = 0;\n let lastFailure = \"no attempt made\";\n\n const tryHealth = async () => {\n attempts++;\n\n try {\n const response = await fetch(`${url}/api/health`);\n if (response.status === 200) {\n resolve();\n return;\n }\n lastFailure = `HTTP ${response.status}`;\n } catch (error) {\n lastFailure = describeFetchError(error);\n }\n\n if (attempts === maxAttempts) {\n reject(\n new Error(\n `Timed out waiting for health check at ${url}/api/health (last attempt: ${lastFailure})`,\n ),\n );\n return;\n }\n\n setTimeout(tryHealth, 500);\n };\n\n tryHealth();\n });\n}\n","import { existsSync, readdirSync, readFileSync } from \"node:fs\";\nimport path from \"node:path\";\nimport PocketBase from \"pocketbase\";\nimport { detect } from \"package-manager-detector\";\nimport { resolveCommand } from \"package-manager-detector/commands\";\nimport spawn from \"cross-spawn\";\nimport { freePort, waitForPort, waitForHealth } from \"./net\";\nimport type { Options } from \"../core/types\";\nimport {\n DATA_DIR,\n MIGRATIONS_DIR,\n POCKETBASE_BIN_ENV,\n} from \"../core/constants\";\n\n/**\n * PocketBase names migration files with a 1-second-resolution Unix timestamp\n * (e.g. `1776099881_created_users.js`). Two schema operations issued in the\n * same wall-clock second produce files that sort alphabetically by their\n * action/collection suffix — which reverses the intended order whenever a\n * later migration depends on an earlier one. Wait out the full second between\n * migration-producing calls so the timestamps stay distinct.\n */\nconst MIGRATION_DELAY_MS = 1100;\n\nexport function migrationDelay(): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, MIGRATION_DELAY_MS));\n}\n\nexport function getMigrationFile(\n collectionName: string,\n action: \"created\" | \"deleted\" | \"updated\",\n options: Options,\n): string | undefined {\n const ending = `${action}_${collectionName}.js`;\n\n // find last file with ending in migrations dir\n const migrationFiles = readdirSync(\n path.join(options.root, MIGRATIONS_DIR),\n ).filter((file) => file.endsWith(ending));\n\n const migrationFile = migrationFiles.sort().pop();\n\n if (!migrationFile) {\n return undefined;\n }\n\n return path.join(options.root, MIGRATIONS_DIR, migrationFile);\n}\n\nexport function getPocketbaseMetadata(cwd: string): {\n pocketbaseUrl: string;\n vitePort: number;\n} | null {\n const metadataPath = path.join(\n cwd,\n \"node_modules\",\n \".vite\",\n \"_pocketbase_metadata.json\",\n );\n if (existsSync(metadataPath)) {\n return JSON.parse(readFileSync(metadataPath, \"utf8\"));\n }\n return null;\n}\n\nexport async function authWithRetries(\n pb: PocketBase,\n email: string,\n password: string,\n) {\n // Retry authentication up to 3 times with 100ms backoff\n let authSuccess = false;\n for (let attempt = 1; attempt <= 3; attempt++) {\n try {\n await pb.collection(\"_superusers\").authWithPassword(email, password);\n authSuccess = true;\n break;\n } catch {\n if (attempt < 3) {\n await new Promise((resolve) => setTimeout(resolve, 100));\n }\n }\n }\n\n if (!authSuccess) {\n throw new Error(\n \"Failed to authenticate with PocketBase. Check your superuser credentials.\",\n );\n }\n}\n\n/**\n * The command that runs PocketBase with the given arguments (`serve --dir\n * ...`).\n *\n * With `VELA_POCKETBASE_BIN` (`POCKETBASE_BIN_ENV`) set, that binary itself:\n * the caller has resolved it, and nothing about the project's package manager\n * is consulted. `pocketbase-server`'s own bin only forwards its arguments to\n * the binary, so they are the same either way. The value has to be an\n * absolute path to a file that exists; anything else is an error rather than\n * a quiet fall back to the package manager, since whoever set it meant it.\n * Unset or empty, the server is started as before, through the project's\n * package manager (`npx --yes pocketbase-server ...`, `pnpm dlx ...`), which\n * the integration harness and direct callers of this library rely on.\n */\nexport async function pocketbaseCommand(\n cwd: string,\n serverArgs: string[],\n env: Record<string, string | undefined> = process.env,\n): Promise<{ command: string; args: string[] }> {\n const bin = env[POCKETBASE_BIN_ENV];\n if (bin) {\n if (!path.isAbsolute(bin)) {\n throw new Error(\n `${POCKETBASE_BIN_ENV} must be an absolute path to the PocketBase binary; it is \"${bin}\".`,\n );\n }\n if (!existsSync(bin)) {\n throw new Error(\n `${POCKETBASE_BIN_ENV} points at ${bin}, which does not exist.`,\n );\n }\n return { command: bin, args: [...serverArgs] };\n }\n\n const packageManager = (await detect({ cwd }))?.name ?? \"npm\";\n const { command, args } = resolveCommand(packageManager, \"execute\", [\n \"pocketbase-server\",\n ...serverArgs,\n ])!;\n\n // adding --yes as the first parameter helps avoiding the \"Need to install the following packages:\" message\n if (packageManager === \"npm\") args.unshift(\"--yes\");\n\n return { command, args };\n}\n\nexport async function withPocketbase(\n cwd: string,\n fn: (pb: PocketBase) => Promise<void>,\n) {\n const dir = path.join(cwd, DATA_DIR);\n const migrationsDir = path.join(cwd, MIGRATIONS_DIR);\n const host = \"localhost\";\n\n if (!existsSync(dir)) {\n throw new Error(\"PocketBase data directory does not exist\");\n }\n\n // First check if the server is already running by reading node_modules/.vite/_pocketbase_metadata.json\n const metadata = getPocketbaseMetadata(cwd);\n if (metadata) {\n if (metadata.pocketbaseUrl) {\n const pb = new PocketBase(metadata.pocketbaseUrl);\n await authWithRetries(\n pb,\n process.env.POCKETBASE_SUPERUSER_EMAIL!,\n process.env.POCKETBASE_SUPERUSER_PASSWORD!,\n );\n await fn(pb);\n return;\n }\n }\n\n const port = await freePort(host);\n const { command, args } = await pocketbaseCommand(cwd, [\n \"serve\",\n \"--dir\",\n dir,\n \"--migrationsDir\",\n migrationsDir,\n \"--http\",\n `${host}:${port}`,\n ]);\n\n // Start the PocketBase server process. A package manager wrapper (`npx`)\n // spawns the real binary as a grandchild; put the tree in its own process\n // group so it can be killed as a whole, otherwise `pocketbase serve` outlives\n // us and keeps the data directory open.\n const detached = process.platform !== \"win32\";\n const serverProcess = spawn(command, args, {\n cwd,\n stdio: \"ignore\",\n detached,\n });\n\n // A wrapper that dies before the server listens (missing binary, bad\n // arguments) would otherwise only surface as a port timeout a minute later.\n const exited = new Promise<never>((_, reject) => {\n serverProcess.once(\"exit\", (code, signal) => {\n reject(\n new Error(\n `PocketBase (${command}) exited before listening on ${host}:${port} (${signal ?? `code ${code}`})`,\n ),\n );\n });\n serverProcess.once(\"error\", reject);\n });\n\n try {\n // Wait for the server to be ready\n await Promise.race([\n (async () => {\n await waitForPort(port, host);\n await waitForHealth(`http://${host}:${port}`);\n })(),\n exited,\n ]);\n\n const pb = new PocketBase(`http://${host}:${port}`);\n await authWithRetries(\n pb,\n process.env.POCKETBASE_SUPERUSER_EMAIL!,\n process.env.POCKETBASE_SUPERUSER_PASSWORD!,\n );\n await fn(pb);\n } finally {\n // Ensure we always clean up the process tree\n stopProcessTree(serverProcess, detached);\n }\n}\n\nfunction stopProcessTree(\n child: ReturnType<typeof spawn>,\n detached: boolean,\n): void {\n if (detached && child.pid) {\n try {\n process.kill(-child.pid, \"SIGTERM\");\n return;\n } catch {\n // Group already gone or unsupported; fall through to the plain kill.\n }\n }\n child.kill();\n}\n"],"mappings":";;;;;;;;;;AAWA,IAAaQ,oBAAiC,IAAI,IAAI;CACpD;CAAG;CAAG;CAAG;CAAI;CAAI;CAAI;CAAI;CAAI;CAAI;CAAI;CAAI;CAAI;CAAI;CAAI;CAAI;CAAI;CAAI;CAAI;CAAI;CACzE;CAAI;CAAI;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CACzE;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CACtE;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAM;CAAM;CACxE;CAAM;CAAM;CAAM;CAAM;CAAM;CAAM;CAAM;CAAM;CAAM;CAAM;CAAM;CAAM;CACxE;CAAM;CAAM;AACd,CAAC;AAED,SAASC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3D,EAAM4D,GAASP,GAAM;EACzC;EACA,OAAO;EACP;CACF,CAAC,GAIKQ,IAAS,IAAI,SAAgB,GAAG,MAAW;EAQ/C,AAPAF,EAAc,KAAK,SAAS,GAAM,MAAW;GAC3C,EACE,gBAAI,MACF,eAAeC,EAAQ,+BAA+BtD,EAAK,GAAGE,EAAK,IAAIsD,KAAU,QAAQC,IAAO,EAClG,CACF;EACF,CAAC,GACDJ,EAAc,KAAK,SAAStD,CAAM;CACpC,CAAC;CAED,IAAI;EAEF,MAAM,QAAQ,KAAK,EAChB,YAAY;GAEX,AADA,MAAMK,EAAYF,GAAMF,CAAI,GAC5B,MAAMY,EAAc,UAAUZ,EAAK,GAAGE,GAAM;EAC9C,EAAA,CAAG,GACHqD,CACF,CAAC;EAED,IAAMlB,IAAK,IAAI5C,EAAW,UAAUO,EAAK,GAAGE,GAAM;EAMlD,AALA,MAAMgC,EACJG,GACA,QAAQ,IAAI,4BACZ,QAAQ,IAAI,6BACd,GACA,MAAMc,EAAGd,CAAE;CACb,UAAU;EAER,EAAgBgB,GAAeD,CAAQ;CACzC;AACF;AAEA,SAASM,EACP,GACA,GACM;CACN,IAAIN,KAAYO,EAAM,KACpB,IAAI;EACF,QAAQ,KAAK,CAACA,EAAM,KAAK,SAAS;EAClC;CACF,QAAQ,CAER;CAEF,EAAM,KAAK;AACb"}
|
|
1
|
+
{"version":3,"file":"pocketbase-B2ksFrvH.js","names":["__exportAll","MIGRATIONS_DIR","DATA_DIR","POCKETBASE_BIN_ENV","path","PocketBase","spawn","net","BAD_PORTS","osAssignedPort","server","reject","host","resolve","port","freePort","waitForPort","attempts","tryConnect","socket","maxAttempts","describeFetchError","error","cause","waitForHealth","lastFailure","tryHealth","response","url","pocketbase_exports","withPocketbase","MIGRATION_DELAY_MS","migrationDelay","getMigrationFile","ending","action","collectionName","migrationFile","readdirSync","options","file","getPocketbaseMetadata","metadataPath","cwd","existsSync","readFileSync","authWithRetries","authSuccess","attempt","pb","email","password","pocketbaseCommand","bin","env","serverArgs","packageManager","detect","resolveCommand","args","dir","migrationsDir","metadata","fn","detached","serverProcess","command","exited","signal","code","stopProcessTree","child"],"sources":["../../src/runtime/net.ts","../../src/runtime/pocketbase.ts"],"sourcesContent":["import net from \"node:net\";\n\n/**\n * Ports the Fetch spec tells clients to refuse outright\n * (https://fetch.spec.whatwg.org/#port-blocking). Node's `fetch` enforces the\n * list, so a server bound to one of them is unreachable from `waitForHealth`\n * and the PocketBase SDK alike: the request fails with cause \"bad port\"\n * before a connection is even attempted. 10080 sat inside the 10000–19999\n * range ports used to be drawn from, and cost a CI run a 30-second health\n * timeout whenever the draw landed on it.\n */\nexport const BAD_PORTS: ReadonlySet<number> = new Set([\n 1, 7, 9, 11, 13, 15, 17, 19, 20, 21, 22, 23, 25, 37, 42, 43, 53, 69, 77, 79,\n 87, 95, 101, 102, 103, 104, 109, 110, 111, 113, 115, 117, 119, 123, 135, 137,\n 139, 143, 161, 179, 389, 427, 465, 512, 513, 514, 515, 526, 530, 531, 532,\n 540, 548, 554, 556, 563, 587, 601, 636, 989, 990, 993, 995, 1719, 1720, 1723,\n 2049, 3659, 4045, 4190, 5060, 5061, 6000, 6566, 6665, 6666, 6667, 6668, 6669,\n 6679, 6697, 10080,\n]);\n\nfunction osAssignedPort(host: string): Promise<number> {\n return new Promise((resolve, reject) => {\n const server = net.createServer();\n server.unref();\n server.once(\"error\", reject);\n server.listen(0, host, () => {\n const { port } = server.address() as net.AddressInfo;\n server.close(() => resolve(port));\n });\n });\n}\n\n/**\n * A port nothing is listening on right now, taken from the OS's ephemeral\n * range so it neither collides with whatever else the machine runs nor hits\n * `BAD_PORTS`. The port is released again before this resolves, so the\n * caller's server has to bind it promptly.\n */\nexport async function freePort(host: string): Promise<number> {\n for (;;) {\n const port = await osAssignedPort(host);\n if (!BAD_PORTS.has(port)) return port;\n }\n}\n\n// Wait for the port to be available. A cold `npx pocketbase-server` on a CI\n// runner can take well over the five seconds the old default allowed.\nexport function waitForPort(\n port: number,\n host: string,\n maxAttempts = 60,\n): Promise<void> {\n return new Promise((resolve, reject) => {\n let attempts = 0;\n\n const tryConnect = () => {\n attempts++;\n\n const socket = new net.Socket();\n\n const onError = () => {\n socket.destroy();\n\n if (attempts === maxAttempts) {\n reject(\n new Error(`Timed out waiting for port ${port} to be available`),\n );\n return;\n }\n\n setTimeout(tryConnect, 500);\n };\n\n socket.once(\"error\", onError);\n\n socket.connect(port, host, () => {\n socket.destroy();\n resolve();\n });\n };\n\n tryConnect();\n });\n}\n\n/**\n * `fetch` wraps the interesting part in `cause`: an errno error for a\n * connection that was refused, or a bare string such as \"bad port\" for a\n * request undici declined to make.\n */\nfunction describeFetchError(error: unknown): string {\n if (!(error instanceof Error)) return String(error);\n const { cause } = error as Error & { cause?: unknown };\n if (cause instanceof Error) {\n const code = (cause as NodeJS.ErrnoException).code;\n return code || cause.message || error.message;\n }\n if (cause !== undefined) return String(cause);\n return error.message;\n}\n\n// Wait for the health check to be successful\nexport function waitForHealth(url: string, maxAttempts = 60): Promise<void> {\n return new Promise((resolve, reject) => {\n let attempts = 0;\n let lastFailure = \"no attempt made\";\n\n const tryHealth = async () => {\n attempts++;\n\n try {\n const response = await fetch(`${url}/api/health`);\n if (response.status === 200) {\n resolve();\n return;\n }\n lastFailure = `HTTP ${response.status}`;\n } catch (error) {\n lastFailure = describeFetchError(error);\n }\n\n if (attempts === maxAttempts) {\n reject(\n new Error(\n `Timed out waiting for health check at ${url}/api/health (last attempt: ${lastFailure})`,\n ),\n );\n return;\n }\n\n setTimeout(tryHealth, 500);\n };\n\n tryHealth();\n });\n}\n","import { existsSync, readdirSync, readFileSync } from \"node:fs\";\nimport path from \"node:path\";\nimport PocketBase from \"pocketbase\";\nimport { detect } from \"package-manager-detector\";\nimport { resolveCommand } from \"package-manager-detector/commands\";\nimport spawn from \"cross-spawn\";\nimport { freePort, waitForPort, waitForHealth } from \"./net\";\nimport type { Options } from \"../core/types\";\nimport {\n DATA_DIR,\n MIGRATIONS_DIR,\n POCKETBASE_BIN_ENV,\n} from \"../core/constants\";\n\n/**\n * PocketBase names migration files with a 1-second-resolution Unix timestamp\n * (e.g. `1776099881_created_users.js`). Two schema operations issued in the\n * same wall-clock second produce files that sort alphabetically by their\n * action/collection suffix — which reverses the intended order whenever a\n * later migration depends on an earlier one. Wait out the full second between\n * migration-producing calls so the timestamps stay distinct.\n */\nconst MIGRATION_DELAY_MS = 1100;\n\nexport function migrationDelay(): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, MIGRATION_DELAY_MS));\n}\n\nexport function getMigrationFile(\n collectionName: string,\n action: \"created\" | \"deleted\" | \"updated\",\n options: Options,\n): string | undefined {\n const ending = `${action}_${collectionName}.js`;\n\n // find last file with ending in migrations dir\n const migrationFiles = readdirSync(\n path.join(options.root, MIGRATIONS_DIR),\n ).filter((file) => file.endsWith(ending));\n\n const migrationFile = migrationFiles.sort().pop();\n\n if (!migrationFile) {\n return undefined;\n }\n\n return path.join(options.root, MIGRATIONS_DIR, migrationFile);\n}\n\nexport function getPocketbaseMetadata(cwd: string): {\n pocketbaseUrl: string;\n vitePort: number;\n} | null {\n const metadataPath = path.join(\n cwd,\n \"node_modules\",\n \".vite\",\n \"_pocketbase_metadata.json\",\n );\n if (existsSync(metadataPath)) {\n return JSON.parse(readFileSync(metadataPath, \"utf8\"));\n }\n return null;\n}\n\nexport async function authWithRetries(\n pb: PocketBase,\n email: string,\n password: string,\n) {\n // Retry authentication up to 3 times with 100ms backoff\n let authSuccess = false;\n for (let attempt = 1; attempt <= 3; attempt++) {\n try {\n await pb.collection(\"_superusers\").authWithPassword(email, password);\n authSuccess = true;\n break;\n } catch {\n if (attempt < 3) {\n await new Promise((resolve) => setTimeout(resolve, 100));\n }\n }\n }\n\n if (!authSuccess) {\n throw new Error(\n \"Failed to authenticate with PocketBase. Check your superuser credentials.\",\n );\n }\n}\n\n/**\n * The command that runs PocketBase with the given arguments (`serve --dir\n * ...`).\n *\n * With `VELA_POCKETBASE_BIN` (`POCKETBASE_BIN_ENV`) set, that binary itself:\n * the caller has resolved it, and nothing about the project's package manager\n * is consulted. `pocketbase-server`'s own bin only forwards its arguments to\n * the binary, so they are the same either way. The value has to be an\n * absolute path to a file that exists; anything else is an error rather than\n * a quiet fall back to the package manager, since whoever set it meant it.\n * Unset or empty, the server is started as before, through the project's\n * package manager (`npx --yes pocketbase-server ...`, `pnpm dlx ...`), which\n * the integration harness and direct callers of this library rely on.\n */\nexport async function pocketbaseCommand(\n cwd: string,\n serverArgs: string[],\n env: Record<string, string | undefined> = process.env,\n): Promise<{ command: string; args: string[] }> {\n const bin = env[POCKETBASE_BIN_ENV];\n if (bin) {\n if (!path.isAbsolute(bin)) {\n throw new Error(\n `${POCKETBASE_BIN_ENV} must be an absolute path to the PocketBase binary; it is \"${bin}\".`,\n );\n }\n if (!existsSync(bin)) {\n throw new Error(\n `${POCKETBASE_BIN_ENV} points at ${bin}, which does not exist.`,\n );\n }\n return { command: bin, args: [...serverArgs] };\n }\n\n const packageManager = (await detect({ cwd }))?.name ?? \"npm\";\n const { command, args } = resolveCommand(packageManager, \"execute\", [\n \"pocketbase-server\",\n ...serverArgs,\n ])!;\n\n // adding --yes as the first parameter helps avoiding the \"Need to install the following packages:\" message\n if (packageManager === \"npm\") args.unshift(\"--yes\");\n\n return { command, args };\n}\n\nexport async function withPocketbase(\n cwd: string,\n fn: (pb: PocketBase) => Promise<void>,\n) {\n const dir = path.join(cwd, DATA_DIR);\n const migrationsDir = path.join(cwd, MIGRATIONS_DIR);\n const host = \"localhost\";\n\n if (!existsSync(dir)) {\n throw new Error(\"PocketBase data directory does not exist\");\n }\n\n // First check if the server is already running by reading node_modules/.vite/_pocketbase_metadata.json\n const metadata = getPocketbaseMetadata(cwd);\n if (metadata) {\n if (metadata.pocketbaseUrl) {\n const pb = new PocketBase(metadata.pocketbaseUrl);\n await authWithRetries(\n pb,\n process.env.POCKETBASE_SUPERUSER_EMAIL!,\n process.env.POCKETBASE_SUPERUSER_PASSWORD!,\n );\n await fn(pb);\n return;\n }\n }\n\n const port = await freePort(host);\n const { command, args } = await pocketbaseCommand(cwd, [\n \"serve\",\n \"--dir\",\n dir,\n \"--migrationsDir\",\n migrationsDir,\n \"--http\",\n `${host}:${port}`,\n ]);\n\n // Start the PocketBase server process. A package manager wrapper (`npx`)\n // spawns the real binary as a grandchild; put the tree in its own process\n // group so it can be killed as a whole, otherwise `pocketbase serve` outlives\n // us and keeps the data directory open.\n const detached = process.platform !== \"win32\";\n const serverProcess = spawn(command, args, {\n cwd,\n stdio: \"ignore\",\n detached,\n });\n\n // A wrapper that dies before the server listens (missing binary, bad\n // arguments) would otherwise only surface as a port timeout a minute later.\n const exited = new Promise<never>((_, reject) => {\n serverProcess.once(\"exit\", (code, signal) => {\n reject(\n new Error(\n `PocketBase (${command}) exited before listening on ${host}:${port} (${signal ?? `code ${code}`})`,\n ),\n );\n });\n serverProcess.once(\"error\", reject);\n });\n\n try {\n // Wait for the server to be ready\n await Promise.race([\n (async () => {\n await waitForPort(port, host);\n await waitForHealth(`http://${host}:${port}`);\n })(),\n exited,\n ]);\n\n const pb = new PocketBase(`http://${host}:${port}`);\n await authWithRetries(\n pb,\n process.env.POCKETBASE_SUPERUSER_EMAIL!,\n process.env.POCKETBASE_SUPERUSER_PASSWORD!,\n );\n await fn(pb);\n } finally {\n // Ensure we always clean up the process tree\n stopProcessTree(serverProcess, detached);\n }\n}\n\nfunction stopProcessTree(\n child: ReturnType<typeof spawn>,\n detached: boolean,\n): void {\n if (detached && child.pid) {\n try {\n process.kill(-child.pid, \"SIGTERM\");\n return;\n } catch {\n // Group already gone or unsupported; fall through to the plain kill.\n }\n }\n child.kill();\n}\n"],"mappings":";;;;;;;;;;AAWA,IAAaQ,oBAAiC,IAAI,IAAI;CACpD;CAAG;CAAG;CAAG;CAAI;CAAI;CAAI;CAAI;CAAI;CAAI;CAAI;CAAI;CAAI;CAAI;CAAI;CAAI;CAAI;CAAI;CAAI;CAAI;CACzE;CAAI;CAAI;CAAK;CAAK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
1
1
|
import { n as e, s as t } from "./providers-DrK_hjSr.js";
|
|
2
|
-
import { readEnvVarNames as n } from "./env-vars-
|
|
2
|
+
import { readEnvVarNames as n } from "./env-vars-C3TSZc4f.js";
|
|
3
3
|
import r from "node:fs";
|
|
4
4
|
import i from "node:path";
|
|
5
5
|
// src/runtime/providers.ts
|
|
@@ -34,4 +34,4 @@ function s(e) {
|
|
|
34
34
|
}
|
|
35
35
|
export { a as detectProviders };
|
|
36
36
|
|
|
37
|
-
//# sourceMappingURL=providers-
|
|
37
|
+
//# sourceMappingURL=providers-BEjDonyG.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"providers-
|
|
1
|
+
{"version":3,"file":"providers-BEjDonyG.js","names":["capabilityName","providerMarkers","fs","path","detectProviders","detected","present","markerProbe","root","pattern","patterns","ids","provider","capability","envNames","dependencies","marker","readEnvVarNames","readDependencies","file","pkg"],"sources":["../../src/runtime/providers.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport path from \"node:path\";\nimport { capabilityName, providerMarkers } from \"../core/providers\";\nimport type { DetectedProviders, Pattern, ProviderMarker } from \"../core/types\";\nimport { readEnvVarNames } from \"./env-vars\";\n\ntype DetectablePattern = Pick<\n Pattern,\n \"slug\" | \"providers\" | \"inheritsProvider\"\n>;\n\n/**\n * The provider in use for each capability, read from what the providers left\n * in the project. Nothing records the choice, so this is the only way to know\n * it. A pattern that inherits its provider is skipped: its files say nothing\n * the capability it is built on doesn't already.\n *\n * The registry is passed in rather than imported, so this module and the\n * package entry don't import each other.\n */\nexport function detectProviders(\n root: string,\n patterns: readonly DetectablePattern[],\n): DetectedProviders {\n const detected: DetectedProviders = { providers: {}, ambiguous: [] };\n const present = markerProbe(root);\n\n for (const pattern of patterns) {\n if (!pattern.providers?.length || pattern.inheritsProvider) continue;\n const ids = pattern.providers\n .filter((provider) => providerMarkers(provider).some(present))\n .map((provider) => provider.id);\n\n const capability = capabilityName(pattern.slug);\n if (ids.length === 1) detected.providers[capability] = ids[0];\n if (ids.length > 1) detected.ambiguous.push({ capability, ids });\n }\n\n return detected;\n}\n\n/** Checks one marker against the project; `src/env.ts` and `package.json` are read once. */\nfunction markerProbe(root: string): (marker: ProviderMarker) => boolean {\n let envNames: Set<string> | undefined;\n let dependencies: Set<string> | undefined;\n\n return (marker) => {\n if (\"env\" in marker) {\n envNames ??= readEnvVarNames(root);\n return envNames.has(marker.env);\n }\n if (\"path\" in marker) {\n return fs.existsSync(path.join(root, marker.path));\n }\n dependencies ??= readDependencies(root);\n return dependencies.has(marker.dependency);\n };\n}\n\nfunction readDependencies(root: string): Set<string> {\n const file = path.join(root, \"package.json\");\n if (!fs.existsSync(file)) return new Set();\n try {\n const pkg = JSON.parse(fs.readFileSync(file, \"utf8\")) as {\n dependencies?: Record<string, string>;\n devDependencies?: Record<string, string>;\n };\n return new Set([\n ...Object.keys(pkg.dependencies ?? {}),\n ...Object.keys(pkg.devDependencies ?? {}),\n ]);\n } catch {\n return new Set();\n }\n}\n"],"mappings":";;;;;AAoBA,SAAgBI,EACd,GACA,GACmB;CACnB,IAAMC,IAA8B;EAAE,WAAW,CAAC;EAAG,WAAW,CAAC;CAAE,GAC7DC,IAAUC,EAAYC,CAAI;CAEhC,KAAK,IAAMC,KAAWC,GAAU;EAC9B,IAAI,CAACD,EAAQ,WAAW,UAAUA,EAAQ,kBAAkB;EAC5D,IAAME,IAAMF,EAAQ,UACjB,QAAQ,MAAaR,EAAgBW,CAAQ,CAAC,CAAC,KAAKN,CAAO,CAAC,CAAC,CAC7D,KAAK,MAAaM,EAAS,EAAE,GAE1BC,IAAab,EAAeS,EAAQ,IAAI;EAE9C,AADIE,EAAI,WAAW,MAAG,EAAS,UAAUE,KAAcF,EAAI,KACvDA,EAAI,SAAS,KAAGN,EAAS,UAAU,KAAK;GAAE;GAAY;EAAI,CAAC;CACjE;CAEA,OAAOA;AACT;AAGA,SAASE,EAAY,GAAmD;CACtE,IAAIO,GACAC;CAEJ,QAAQ,MACF,SAASC,KACX,MAAaC,EAAgBT,CAAI,GAC1BM,EAAS,IAAIE,EAAO,GAAG,KAE5B,UAAUA,IACLd,EAAG,WAAWC,EAAK,KAAKK,GAAMQ,EAAO,IAAI,CAAC,KAEnD,MAAiBE,EAAiBV,CAAI,GAC/BO,EAAa,IAAIC,EAAO,UAAU;AAE7C;AAEA,SAASE,EAAiB,GAA2B;CACnD,IAAMC,IAAOhB,EAAK,KAAKK,GAAM,cAAc;CAC3C,IAAI,CAACN,EAAG,WAAWiB,CAAI,GAAG,uBAAO,IAAI,IAAI;CACzC,IAAI;EACF,IAAMC,IAAM,KAAK,MAAMlB,EAAG,aAAaiB,GAAM,MAAM,CAAC;EAIpD,uBAAO,IAAI,IAAI,CACb,GAAG,OAAO,KAAKC,EAAI,gBAAgB,CAAC,CAAC,GACrC,GAAG,OAAO,KAAKA,EAAI,mBAAmB,CAAC,CAAC,CAC1C,CAAC;CACH,QAAQ;EACN,uBAAO,IAAI,IAAI;CACjB;AACF"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import "./constants-
|
|
1
|
+
import "./constants-E1I-__KI.js";
|
|
2
2
|
import { t as e } from "./errors-DdSUZI8f.js";
|
|
3
3
|
// node_modules/change-case/dist/index.js
|
|
4
4
|
var t = /([\p{Ll}\d])(\p{Lu})/gu, n = /(\p{Lu})([\p{Lu}][\p{Ll}])/gu, r = /(\d)\p{Ll}|(\p{L})\d/u, i = /[^\p{L}\d]+/giu, a = "$1\0$2", o = "";
|
|
@@ -92,25 +92,29 @@ function C({ features: e, routeGroups: t }) {
|
|
|
92
92
|
};
|
|
93
93
|
return e.auth ? n.app ?? n.public : n.public;
|
|
94
94
|
}
|
|
95
|
-
function w(e, t) {
|
|
95
|
+
function w(e, { features: t, routeGroups: n }) {
|
|
96
|
+
let r = (n ?? { app: "(app)" }).app;
|
|
97
|
+
return !!(t.auth && r && e.fileBase.split("/").includes(r));
|
|
98
|
+
}
|
|
99
|
+
function T(e, t) {
|
|
96
100
|
return [
|
|
97
101
|
b,
|
|
98
102
|
e,
|
|
99
103
|
t
|
|
100
104
|
].filter(Boolean).join("/");
|
|
101
105
|
}
|
|
102
|
-
function
|
|
106
|
+
function E(e, t) {
|
|
103
107
|
return p(t === "scaffold" ? e.pluralDisplayName : e.displayName);
|
|
104
108
|
}
|
|
105
|
-
function
|
|
109
|
+
function D(e) {
|
|
106
110
|
return `/${(e.startsWith(`${b}/`) ? e.slice(11) : e).split("/").filter((e) => !(e.startsWith("(") && e.endsWith(")"))).join("/")}`;
|
|
107
111
|
}
|
|
108
|
-
function
|
|
112
|
+
function O(e) {
|
|
109
113
|
let t = [];
|
|
110
114
|
for (let n of e.matchAll(x)) t.push(n[1]);
|
|
111
115
|
return t;
|
|
112
116
|
}
|
|
113
|
-
function
|
|
117
|
+
function k(t) {
|
|
114
118
|
if (t.startsWith("/")) throw new e(`Route must not start with "/". Got: "${t}"`);
|
|
115
119
|
if (t.startsWith(`${b}/`) || t === b) throw new e(`Route must not start with "${b}/" — paths are rooted there automatically. Got: "${t}"`);
|
|
116
120
|
let n = t.split("/");
|
|
@@ -121,27 +125,27 @@ function O(t) {
|
|
|
121
125
|
if (!S.test(r)) throw new e(`Route segment "${r}" contains invalid characters. Allowed: letters, digits, underscore, dash, brackets, parentheses.`);
|
|
122
126
|
}
|
|
123
127
|
}
|
|
124
|
-
function
|
|
128
|
+
function A(e) {
|
|
125
129
|
return e.split("/").some((e) => e.startsWith("(") && e.endsWith(")"));
|
|
126
130
|
}
|
|
127
|
-
function
|
|
131
|
+
function j(e, t, n, r) {
|
|
128
132
|
if (e === void 0 || e === "") {
|
|
129
|
-
let e =
|
|
133
|
+
let e = E(t, r), i = T(C(n), e);
|
|
130
134
|
return {
|
|
131
135
|
fileBase: i,
|
|
132
|
-
urlBase:
|
|
133
|
-
dynamicParams:
|
|
136
|
+
urlBase: D(i),
|
|
137
|
+
dynamicParams: O(i)
|
|
134
138
|
};
|
|
135
139
|
}
|
|
136
|
-
|
|
137
|
-
let i =
|
|
140
|
+
k(e);
|
|
141
|
+
let i = T(A(e) ? null : C(n), e);
|
|
138
142
|
return {
|
|
139
143
|
fileBase: i,
|
|
140
|
-
urlBase:
|
|
141
|
-
dynamicParams:
|
|
144
|
+
urlBase: D(i),
|
|
145
|
+
dynamicParams: O(i)
|
|
142
146
|
};
|
|
143
147
|
}
|
|
144
|
-
function
|
|
148
|
+
function M(e) {
|
|
145
149
|
return {
|
|
146
150
|
list: e.fileBase,
|
|
147
151
|
new: `${e.fileBase}/new`,
|
|
@@ -149,7 +153,7 @@ function j(e) {
|
|
|
149
153
|
edit: `${e.fileBase}/[id]/edit`
|
|
150
154
|
};
|
|
151
155
|
}
|
|
152
|
-
function
|
|
156
|
+
function N(e) {
|
|
153
157
|
return {
|
|
154
158
|
list: e.urlBase,
|
|
155
159
|
new: `${e.urlBase}/new`,
|
|
@@ -157,6 +161,6 @@ function M(e) {
|
|
|
157
161
|
edit: `${e.urlBase}/[id]/edit`
|
|
158
162
|
};
|
|
159
163
|
}
|
|
160
|
-
export {
|
|
164
|
+
export { N as a, p as c, M as i, d as l, w as n, u as o, j as r, f as s, C as t, m as u };
|
|
161
165
|
|
|
162
|
-
//# sourceMappingURL=route-
|
|
166
|
+
//# sourceMappingURL=route-9ZVJZkYu.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"route-9ZVJZkYu.js","names":["changeCase.kebabCase","InvalidArgumentError","SPLIT_LOWER_UPPER_RE","SPLIT_UPPER_UPPER_RE","SPLIT_SEPARATE_NUMBER_RE","DEFAULT_STRIP_REGEXP","SPLIT_REPLACE_VALUE","DEFAULT_PREFIX_SUFFIX_CHARACTERS","split","result","value","start","end","splitSeparateNumbers","words","i","word","match","offset","noCase","prefix","suffix","splitPrefixSuffix","input","options","lowerFactory","camelCase","lower","upper","upperFactory","transform","capitalCaseTransformFactory","pascalCaseTransformFactory","index","pascalCase","capitalCase","kebabCase","snakeCase","locale","char0","splitFn","prefixCharacters","suffixCharacters","prefixIndex","suffixIndex","char","ROUTES_ROOT","DYNAMIC_PARAM_RE","VALID_SEGMENT_RE","defaultGroup","groups","routeGroups","features","isProtectedRoute","app","route","routeFileBase","group","defaultRouteSegment","kind","model","stripRouteGroups","filePath","segment","extractDynamicParams","params","validateRouteInput","segments","hasRouteGroup","parseRoute","routeInput","fileBase","scaffoldFilePaths","scaffoldUrls"],"sources":["../../node_modules/change-case/dist/index.js","../../src/parse/route.ts"],"sourcesContent":["// Regexps involved with splitting words in various case formats.\nconst SPLIT_LOWER_UPPER_RE = /([\\p{Ll}\\d])(\\p{Lu})/gu;\nconst SPLIT_UPPER_UPPER_RE = /(\\p{Lu})([\\p{Lu}][\\p{Ll}])/gu;\n// Used to iterate over the initial split result and separate numbers.\nconst SPLIT_SEPARATE_NUMBER_RE = /(\\d)\\p{Ll}|(\\p{L})\\d/u;\n// Regexp involved with stripping non-word characters from the result.\nconst DEFAULT_STRIP_REGEXP = /[^\\p{L}\\d]+/giu;\n// The replacement value for splits.\nconst SPLIT_REPLACE_VALUE = \"$1\\0$2\";\n// The default characters to keep after transforming case.\nconst DEFAULT_PREFIX_SUFFIX_CHARACTERS = \"\";\n/**\n * Split any cased input strings into an array of words.\n */\nexport function split(value) {\n let result = value.trim();\n result = result\n .replace(SPLIT_LOWER_UPPER_RE, SPLIT_REPLACE_VALUE)\n .replace(SPLIT_UPPER_UPPER_RE, SPLIT_REPLACE_VALUE);\n result = result.replace(DEFAULT_STRIP_REGEXP, \"\\0\");\n let start = 0;\n let end = result.length;\n // Trim the delimiter from around the output string.\n while (result.charAt(start) === \"\\0\")\n start++;\n if (start === end)\n return [];\n while (result.charAt(end - 1) === \"\\0\")\n end--;\n return result.slice(start, end).split(/\\0/g);\n}\n/**\n * Split the input string into an array of words, separating numbers.\n */\nexport function splitSeparateNumbers(value) {\n const words = split(value);\n for (let i = 0; i < words.length; i++) {\n const word = words[i];\n const match = SPLIT_SEPARATE_NUMBER_RE.exec(word);\n if (match) {\n const offset = match.index + (match[1] ?? match[2]).length;\n words.splice(i, 1, word.slice(0, offset), word.slice(offset));\n }\n }\n return words;\n}\n/**\n * Convert a string to space separated lower case (`foo bar`).\n */\nexport function noCase(input, options) {\n const [prefix, words, suffix] = splitPrefixSuffix(input, options);\n return (prefix +\n words.map(lowerFactory(options?.locale)).join(options?.delimiter ?? \" \") +\n suffix);\n}\n/**\n * Convert a string to camel case (`fooBar`).\n */\nexport function camelCase(input, options) {\n const [prefix, words, suffix] = splitPrefixSuffix(input, options);\n const lower = lowerFactory(options?.locale);\n const upper = upperFactory(options?.locale);\n const transform = options?.mergeAmbiguousCharacters\n ? capitalCaseTransformFactory(lower, upper)\n : pascalCaseTransformFactory(lower, upper);\n return (prefix +\n words\n .map((word, index) => {\n if (index === 0)\n return lower(word);\n return transform(word, index);\n })\n .join(options?.delimiter ?? \"\") +\n suffix);\n}\n/**\n * Convert a string to pascal case (`FooBar`).\n */\nexport function pascalCase(input, options) {\n const [prefix, words, suffix] = splitPrefixSuffix(input, options);\n const lower = lowerFactory(options?.locale);\n const upper = upperFactory(options?.locale);\n const transform = options?.mergeAmbiguousCharacters\n ? capitalCaseTransformFactory(lower, upper)\n : pascalCaseTransformFactory(lower, upper);\n return prefix + words.map(transform).join(options?.delimiter ?? \"\") + suffix;\n}\n/**\n * Convert a string to pascal snake case (`Foo_Bar`).\n */\nexport function pascalSnakeCase(input, options) {\n return capitalCase(input, { delimiter: \"_\", ...options });\n}\n/**\n * Convert a string to capital case (`Foo Bar`).\n */\nexport function capitalCase(input, options) {\n const [prefix, words, suffix] = splitPrefixSuffix(input, options);\n const lower = lowerFactory(options?.locale);\n const upper = upperFactory(options?.locale);\n return (prefix +\n words\n .map(capitalCaseTransformFactory(lower, upper))\n .join(options?.delimiter ?? \" \") +\n suffix);\n}\n/**\n * Convert a string to constant case (`FOO_BAR`).\n */\nexport function constantCase(input, options) {\n const [prefix, words, suffix] = splitPrefixSuffix(input, options);\n return (prefix +\n words.map(upperFactory(options?.locale)).join(options?.delimiter ?? \"_\") +\n suffix);\n}\n/**\n * Convert a string to dot case (`foo.bar`).\n */\nexport function dotCase(input, options) {\n return noCase(input, { delimiter: \".\", ...options });\n}\n/**\n * Convert a string to kebab case (`foo-bar`).\n */\nexport function kebabCase(input, options) {\n return noCase(input, { delimiter: \"-\", ...options });\n}\n/**\n * Convert a string to path case (`foo/bar`).\n */\nexport function pathCase(input, options) {\n return noCase(input, { delimiter: \"/\", ...options });\n}\n/**\n * Convert a string to path case (`Foo bar`).\n */\nexport function sentenceCase(input, options) {\n const [prefix, words, suffix] = splitPrefixSuffix(input, options);\n const lower = lowerFactory(options?.locale);\n const upper = upperFactory(options?.locale);\n const transform = capitalCaseTransformFactory(lower, upper);\n return (prefix +\n words\n .map((word, index) => {\n if (index === 0)\n return transform(word);\n return lower(word);\n })\n .join(options?.delimiter ?? \" \") +\n suffix);\n}\n/**\n * Convert a string to snake case (`foo_bar`).\n */\nexport function snakeCase(input, options) {\n return noCase(input, { delimiter: \"_\", ...options });\n}\n/**\n * Convert a string to header case (`Foo-Bar`).\n */\nexport function trainCase(input, options) {\n return capitalCase(input, { delimiter: \"-\", ...options });\n}\nfunction lowerFactory(locale) {\n return locale === false\n ? (input) => input.toLowerCase()\n : (input) => input.toLocaleLowerCase(locale);\n}\nfunction upperFactory(locale) {\n return locale === false\n ? (input) => input.toUpperCase()\n : (input) => input.toLocaleUpperCase(locale);\n}\nfunction capitalCaseTransformFactory(lower, upper) {\n return (word) => `${upper(word[0])}${lower(word.slice(1))}`;\n}\nfunction pascalCaseTransformFactory(lower, upper) {\n return (word, index) => {\n const char0 = word[0];\n const initial = index > 0 && char0 >= \"0\" && char0 <= \"9\" ? \"_\" + char0 : upper(char0);\n return initial + lower(word.slice(1));\n };\n}\nfunction splitPrefixSuffix(input, options = {}) {\n const splitFn = options.split ?? (options.separateNumbers ? splitSeparateNumbers : split);\n const prefixCharacters = options.prefixCharacters ?? DEFAULT_PREFIX_SUFFIX_CHARACTERS;\n const suffixCharacters = options.suffixCharacters ?? DEFAULT_PREFIX_SUFFIX_CHARACTERS;\n let prefixIndex = 0;\n let suffixIndex = input.length;\n while (prefixIndex < input.length) {\n const char = input.charAt(prefixIndex);\n if (!prefixCharacters.includes(char))\n break;\n prefixIndex++;\n }\n while (suffixIndex > prefixIndex) {\n const index = suffixIndex - 1;\n const char = input.charAt(index);\n if (!suffixCharacters.includes(char))\n break;\n suffixIndex = index;\n }\n return [\n input.slice(0, prefixIndex),\n splitFn(input.slice(prefixIndex, suffixIndex)),\n input.slice(suffixIndex),\n ];\n}\n//# sourceMappingURL=index.js.map","import * as changeCase from \"change-case\";\nimport { APP_DIR, PUBLIC_DIR } from \"../core/constants\";\nimport { InvalidArgumentError } from \"../core/errors\";\nimport type { Options } from \"../core/types\";\nimport type {\n Model,\n RouteInfo,\n RouteKind,\n ScaffoldFilePaths,\n ScaffoldUrls,\n} from \"./types\";\n\nconst ROUTES_ROOT = \"src/routes\";\nconst DYNAMIC_PARAM_RE = /\\[([^\\]]+)\\]/g;\nconst VALID_SEGMENT_RE = /^[a-zA-Z0-9_\\-[\\]()]+$/;\n\ntype RouteOptions = Pick<Options, \"features\" | \"routeGroups\">;\n\n/**\n * The group a route lands in when none is given, or null for a project that\n * has no such group. Without `routeGroups` this is the vela layout.\n */\nexport function defaultGroup({\n features,\n routeGroups,\n}: RouteOptions): string | null {\n const groups = routeGroups ?? { public: PUBLIC_DIR, app: APP_DIR };\n return features.auth ? (groups.app ?? groups.public) : groups.public;\n}\n\n/**\n * Whether a route is in the group that needs a session (`(app)`), in a\n * project with auth: `protectedRoutes` covers its pages, form actions and\n * endpoints. It does not cover a remote function written there, which is why\n * the generators ask: such a function checks the session itself.\n */\nexport function isProtectedRoute(\n route: { fileBase: string },\n { features, routeGroups }: RouteOptions,\n): boolean {\n const app = (routeGroups ?? { app: APP_DIR }).app;\n return Boolean(\n features.auth && app && route.fileBase.split(\"/\").includes(app),\n );\n}\n\nfunction routeFileBase(group: string | null, route: string): string {\n return [ROUTES_ROOT, group, route].filter(Boolean).join(\"/\");\n}\n\nfunction defaultRouteSegment(model: Model, kind: RouteKind): string {\n return kind === \"scaffold\"\n ? changeCase.kebabCase(model.pluralDisplayName)\n : changeCase.kebabCase(model.displayName);\n}\n\nfunction stripRouteGroups(filePath: string): string {\n const withoutRoot = filePath.startsWith(`${ROUTES_ROOT}/`)\n ? filePath.slice(ROUTES_ROOT.length + 1)\n : filePath;\n const segments = withoutRoot.split(\"/\").filter((segment) => {\n return !(segment.startsWith(\"(\") && segment.endsWith(\")\"));\n });\n return `/${segments.join(\"/\")}`;\n}\n\nfunction extractDynamicParams(filePath: string): string[] {\n const params: string[] = [];\n for (const match of filePath.matchAll(DYNAMIC_PARAM_RE)) {\n params.push(match[1]);\n }\n return params;\n}\n\nfunction validateRouteInput(input: string): void {\n if (input.startsWith(\"/\")) {\n throw new InvalidArgumentError(\n `Route must not start with \"/\". Got: \"${input}\"`,\n );\n }\n if (input.startsWith(`${ROUTES_ROOT}/`) || input === ROUTES_ROOT) {\n throw new InvalidArgumentError(\n `Route must not start with \"${ROUTES_ROOT}/\" — paths are rooted there automatically. Got: \"${input}\"`,\n );\n }\n const segments = input.split(\"/\");\n for (const segment of segments) {\n if (segment.length === 0) {\n throw new InvalidArgumentError(\n `Route must not contain empty segments. Got: \"${input}\"`,\n );\n }\n if (segment === \".\" || segment === \"..\") {\n throw new InvalidArgumentError(\n `Route must not contain \".\" or \"..\" segments. Got: \"${input}\"`,\n );\n }\n if (segment.startsWith(\"_\")) {\n throw new InvalidArgumentError(\n `Route segments must not start with underscore. Got: \"${segment}\"`,\n );\n }\n if (!VALID_SEGMENT_RE.test(segment)) {\n throw new InvalidArgumentError(\n `Route segment \"${segment}\" contains invalid characters. Allowed: letters, digits, underscore, dash, brackets, parentheses.`,\n );\n }\n }\n}\n\nfunction hasRouteGroup(input: string): boolean {\n return input\n .split(\"/\")\n .some((segment) => segment.startsWith(\"(\") && segment.endsWith(\")\"));\n}\n\nexport function parseRoute(\n routeInput: string | undefined,\n model: Model,\n options: RouteOptions,\n kind: RouteKind,\n): RouteInfo {\n if (routeInput === undefined || routeInput === \"\") {\n const segment = defaultRouteSegment(model, kind);\n const fileBase = routeFileBase(defaultGroup(options), segment);\n return {\n fileBase,\n urlBase: stripRouteGroups(fileBase),\n dynamicParams: extractDynamicParams(fileBase),\n };\n }\n\n validateRouteInput(routeInput);\n\n const fileBase = routeFileBase(\n hasRouteGroup(routeInput) ? null : defaultGroup(options),\n routeInput,\n );\n\n return {\n fileBase,\n urlBase: stripRouteGroups(fileBase),\n dynamicParams: extractDynamicParams(fileBase),\n };\n}\n\nexport function scaffoldFilePaths(route: RouteInfo): ScaffoldFilePaths {\n return {\n list: route.fileBase,\n new: `${route.fileBase}/new`,\n show: `${route.fileBase}/[id]`,\n edit: `${route.fileBase}/[id]/edit`,\n };\n}\n\nexport function scaffoldUrls(route: RouteInfo): ScaffoldUrls {\n return {\n list: route.urlBase,\n new: `${route.urlBase}/new`,\n show: `${route.urlBase}/[id]`,\n edit: `${route.urlBase}/[id]/edit`,\n };\n}\n"],"ignoreList":[0],"mappings":";;;AACA,IAAME,IAAuB,0BACvBC,IAAuB,gCAEvBC,IAA2B,yBAE3BC,IAAuB,kBAEvBC,IAAsB,UAEtBC,IAAmC;AAIzC,SAAgBC,EAAM,GAAO;CACzB,IAAIC,IAASC,EAAM,KAAK;CAIxB,AAHA,IAASD,EACJ,QAAQP,GAAsBI,CAAmB,CAAC,CAClD,QAAQH,GAAsBG,CAAmB,GACtD,IAASG,EAAO,QAAQJ,GAAsB,IAAI;CAClD,IAAIM,IAAQ,GACRC,IAAMH,EAAO;CAEjB,OAAOA,EAAO,OAAOE,CAAK,MAAM,OAC5B;CACJ,IAAIA,MAAUC,GACV,OAAO,CAAC;CACZ,OAAOH,EAAO,OAAOG,IAAM,CAAC,MAAM,OAC9B;CACJ,OAAOH,EAAO,MAAME,GAAOC,CAAG,CAAC,CAAC,MAAM,KAAK;AAC/C;AAIA,SAAgB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,IAAUL,EAAoBE,GAAOD,CAAI,GACzCY,IAAWf,EAAcP,EAAazB,CAAO,GAAGuC,CAAO;EAC7D,OAAO;GACL;GACA,SAASF,EAAiBU,CAAQ;GAClC,eAAeP,EAAqBO,CAAQ;EAC9C;CACF;CAEA,EAAmBD,CAAU;CAE7B,IAAMC,IAAWf,EACfY,EAAcE,CAAU,IAAI,OAAOrB,EAAazB,CAAO,GACvD8C,CACF;CAEA,OAAO;EACL;EACA,SAAST,EAAiBU,CAAQ;EAClC,eAAeP,EAAqBO,CAAQ;CAC9C;AACF;AAEA,SAAgBC,EAAkB,GAAqC;CACrE,OAAO;EACL,MAAMjB,EAAM;EACZ,KAAK,GAAGA,EAAM,SAAS;EACvB,MAAM,GAAGA,EAAM,SAAS;EACxB,MAAM,GAAGA,EAAM,SAAS;CAC1B;AACF;AAEA,SAAgBkB,EAAa,GAAgC;CAC3D,OAAO;EACL,MAAMlB,EAAM;EACZ,KAAK,GAAGA,EAAM,QAAQ;EACtB,MAAM,GAAGA,EAAM,QAAQ;EACvB,MAAM,GAAGA,EAAM,QAAQ;CACzB;AACF"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { d as e } from "./shared-
|
|
2
|
-
import { r as t } from "./modify-file-
|
|
1
|
+
import { d as e } from "./shared-Cdwm_-Nl.js";
|
|
2
|
+
import { r as t } from "./modify-file-BOEKlIDw.js";
|
|
3
3
|
import { o as n } from "./ts-morph-helpers-B4KZXP44.js";
|
|
4
4
|
import r from "node:fs";
|
|
5
5
|
import i from "node:path";
|
|
@@ -113,4 +113,4 @@ function g(n, { model: a, added: o, changes: s }) {
|
|
|
113
113
|
}
|
|
114
114
|
export { g as modifySchemaForMigration };
|
|
115
115
|
|
|
116
|
-
//# sourceMappingURL=schema-
|
|
116
|
+
//# sourceMappingURL=schema-DnMqw2Hn.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema-2frI_BS2.js","names":["schemaEntriesForFields","modifyOutcomeToFile","formatLikeSource","fs","path","KEY_SUFFIXES","propertyKey","name","unquote","findZodObject","declarations","sourceFile","candidates","d","schemaName","found","declaration","node","Node","callee","shape","findProperty","property","describeChange","change","entry","applyChange","changed","suffix","to","modifySchema","schemaPath","changes","Project","backsRemoteForm","routes","root","imported","modelName","file","modifySchemaForMigration","model","schemaChanges","added"],"sources":["../../src/patterns/generate/migration/modifies/schema.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport path from \"node:path\";\nimport {\n Node,\n Project,\n SyntaxKind,\n type ObjectLiteralExpression,\n type PropertyAssignment,\n type ShorthandPropertyAssignment,\n type SourceFile,\n} from \"ts-morph\";\nimport { schemaEntriesForFields } from \"../../../../core/shared\";\nimport type { File, ModifyOutcome } from \"../../../../core/types\";\nimport { modifyOutcomeToFile } from \"../../../../runtime/modify-file\";\nimport { formatLikeSource } from \"../../../../runtime/ts-morph-helpers\";\nimport type { ResolvedMigration } from \"../generate\";\n\n/** One key of a zod object: its name and the schema it is given. */\nexport interface SchemaEntry {\n name: string;\n schema: string;\n}\n\n/**\n * What a migration did to a collection, as it applies to the zod schema that\n * describes it. An `add` carries every key its field needs (a multi-file\n * field has three); `remove` and `rename` name the field, and take its\n * `name+` / `name-` keys along.\n */\nexport type SchemaChange =\n | { op: \"add\"; entries: SchemaEntry[] }\n | { op: \"remove\"; fieldName: string }\n | { op: \"rename\"; from: string; to: string };\n\n/** The keys a field may have in a schema: its own, and a multi-file field's two. */\nconst KEY_SUFFIXES = [\"\", \"+\", \"-\"];\n\nfunction propertyKey(name: string): string {\n return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(name) ? name : `'${name}'`;\n}\n\nfunction unquote(name: string): string {\n return name.replace(/^([\"'`])(.*)\\1$/, \"$2\");\n}\n\n/**\n * The object literal of `export const <name> = z.object({ ... })`, through a\n * trailing `satisfies` / `as` and any methods chained on (`.strict()`,\n * `.refine(...)`).\n */\nfunction findZodObject(\n sourceFile: SourceFile,\n schemaName: string,\n): ObjectLiteralExpression | undefined {\n const declarations = sourceFile.getVariableDeclarations();\n const candidates = [\n ...declarations.filter((d) => d.getName() === schemaName),\n ...declarations.filter((d) => d.getName() !== schemaName),\n ];\n\n const found: ObjectLiteralExpression[] = [];\n for (const declaration of candidates) {\n let node: Node | undefined = declaration.getInitializer();\n while (node) {\n if (\n Node.isSatisfiesExpression(node) ||\n Node.isAsExpression(node) ||\n Node.isParenthesizedExpression(node)\n ) {\n node = node.getExpression();\n continue;\n }\n if (!Node.isCallExpression(node)) break;\n const callee = node.getExpression();\n if (\n Node.isPropertyAccessExpression(callee) &&\n callee.getName() === \"object\" &&\n callee.getExpression().getText() === \"z\"\n ) {\n const [shape] = node.getArguments();\n if (shape && Node.isObjectLiteralExpression(shape)) found.push(shape);\n break;\n }\n // `<something>.method(...)`: look at what the method was called on.\n node = Node.isPropertyAccessExpression(callee)\n ? callee.getExpression()\n : undefined;\n }\n // The schema under its generated name wins; otherwise the file has to\n // hold exactly one, or there is no telling which the collection's is.\n if (declaration.getName() === schemaName && found.length === 1) {\n return found[0];\n }\n }\n return found.length === 1 ? found[0] : undefined;\n}\n\nfunction findProperty(\n shape: ObjectLiteralExpression,\n name: string,\n): PropertyAssignment | ShorthandPropertyAssignment | undefined {\n return shape\n .getProperties()\n .filter(\n (property) =>\n Node.isPropertyAssignment(property) ||\n Node.isShorthandPropertyAssignment(property),\n )\n .find((property) => unquote(property.getName()) === name);\n}\n\n/** What the user would write to make the change by hand. */\nfunction describeChange(change: SchemaChange): string {\n if (change.op === \"add\") {\n return change.entries\n .map((entry) => `add \\`${propertyKey(entry.name)}: ${entry.schema}\\``)\n .join(\", \");\n }\n if (change.op === \"remove\") return `remove \\`${change.fieldName}\\``;\n return `rename \\`${change.from}\\` to \\`${change.to}\\``;\n}\n\nfunction applyChange(\n shape: ObjectLiteralExpression,\n change: SchemaChange,\n): boolean {\n let changed = false;\n\n if (change.op === \"add\") {\n for (const entry of change.entries) {\n // Already there: added by hand, most likely. Theirs stands.\n if (findProperty(shape, entry.name)) continue;\n shape.addPropertyAssignment({\n name: propertyKey(entry.name),\n initializer: entry.schema,\n });\n changed = true;\n }\n return changed;\n }\n\n for (const suffix of KEY_SUFFIXES) {\n const name =\n (change.op === \"remove\" ? change.fieldName : change.from) + suffix;\n const property = findProperty(shape, name);\n if (!property) continue;\n\n if (change.op === \"remove\") {\n property.remove();\n changed = true;\n continue;\n }\n\n const to = change.to + suffix;\n if (findProperty(shape, to)) continue;\n if (Node.isPropertyAssignment(property)) {\n property.getNameNode().replaceWithText(propertyKey(to));\n } else {\n // `{ title }` → `{ heading: title }`: the value keeps its name.\n property.replaceWithText(`${propertyKey(to)}: ${property.getName()}`);\n }\n changed = true;\n }\n return changed;\n}\n\n/**\n * Brings the zod schema of a collection in line with a migration just applied\n * to it: `generate resource` and the scaffolds write the schema once, and a\n * field added later is optional, so nothing else notices it is missing.\n *\n * Only the keys the migration names are touched. A file without a\n * recognisable `z.object({ ... })` is left as it is and reported, with the\n * edit to make by hand.\n */\nexport function modifySchema(\n schemaPath: string,\n schemaName: string,\n changes: SchemaChange[],\n): ModifyOutcome {\n if (!fs.existsSync(schemaPath) || changes.length === 0) {\n return { status: \"success\", changed: false };\n }\n\n const project = new Project({\n skipAddingFilesFromTsConfig: true,\n skipFileDependencyResolution: true,\n });\n const sourceFile = project.addSourceFileAtPath(schemaPath);\n const shape = findZodObject(sourceFile, schemaName);\n\n if (!shape) {\n return {\n status: \"failed\",\n message: `The collection changed, but no \\`z.object({ ... })\\` schema was found in this file to change with it. Update it by hand: ${changes.map(describeChange).join(\"; \")}.`,\n };\n }\n\n let changed = false;\n for (const change of changes) {\n changed = applyChange(shape, change) || changed;\n }\n if (!changed) {\n return { status: \"success\", changed: false };\n }\n\n formatLikeSource(sourceFile);\n sourceFile.saveSync();\n return { status: \"success\", changed: true };\n}\n\n/**\n * Whether a remote form validates with the model's schema. Its json fields\n * are then typed as the text a textarea posts, not `z.any()`; see\n * `generateSchemaSnippet`.\n */\nfunction backsRemoteForm(root: string, modelName: string): boolean {\n const routes = path.join(root, \"src\", \"routes\");\n if (!fs.existsSync(routes)) return false;\n const imported = new RegExp(`lib/schemas/${modelName}(\\\\.js|\\\\.ts)?[\"']`);\n return fs\n .readdirSync(routes, { recursive: true, encoding: \"utf8\" })\n .filter((file) => file.endsWith(\".remote.ts\"))\n .some((file) =>\n imported.test(fs.readFileSync(path.join(routes, file), \"utf8\")),\n );\n}\n\n/**\n * `modifySchema` for a migration the generator just applied, on the schema\n * file `generate resource` and the scaffolds write for its collection. `null`\n * when there is nothing to report: no such file, or nothing to change in it.\n */\nexport function modifySchemaForMigration(\n root: string,\n { model, added, changes }: ResolvedMigration,\n): File | null {\n const schemaPath = path.join(\n root,\n \"src\",\n \"lib\",\n \"schemas\",\n `${model.name}.ts`,\n );\n if (!fs.existsSync(schemaPath)) return null;\n\n const schemaChanges: SchemaChange[] = [];\n if (added.length > 0) {\n schemaChanges.push({\n op: \"add\",\n entries: schemaEntriesForFields(added, {\n forForm: true,\n remote: backsRemoteForm(root, model.name),\n }),\n });\n }\n for (const change of changes) {\n if (change.op !== \"add\") schemaChanges.push(change);\n }\n\n return modifyOutcomeToFile(\n schemaPath,\n modifySchema(schemaPath, model.schemaName, schemaChanges),\n );\n}\n"],"mappings":";;;;;;;AAmCA,IAAMK,IAAe;CAAC;CAAI;CAAK;AAAG;AAElC,SAASC,EAAY,GAAsB;CACzC,OAAO,6BAA6B,KAAKC,CAAI,IAAIA,IAAO,IAAIA,EAAK;AACnE;AAEA,SAASC,EAAQ,GAAsB;CACrC,OAAOD,EAAK,QAAQ,mBAAmB,IAAI;AAC7C;AAOA,SAASE,EACP,GACA,GACqC;CACrC,IAAMC,IAAeC,EAAW,wBAAwB,GAClDC,IAAa,CACjB,GAAGF,EAAa,QAAQ,MAAMG,EAAE,QAAQ,MAAMC,CAAU,GACxD,GAAGJ,EAAa,QAAQ,MAAMG,EAAE,QAAQ,MAAMC,CAAU,CAC1D,GAEMC,IAAmC,CAAC;CAC1C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AiBS,CAAU,GAC3BA,EAAW,SAAS,GACb;EAAE,QAAQ;EAAW,SAAS;CAAK,KALjC;EAAE,QAAQ;EAAW,SAAS;CAAM;AAM/C;AAOA,SAASuB,EAAgB,GAAc,GAA4B;CACjE,IAAMC,IAAS/B,EAAK,KAAKgC,GAAM,OAAO,QAAQ;CAC9C,IAAI,CAACjC,EAAG,WAAWgC,CAAM,GAAG,OAAO;CACnC,IAAME,IAAe,OAAO,eAAeC,EAAU,mBAAmB;CACxE,OAAOnC,EACJ,YAAYgC,GAAQ;EAAE,WAAW;EAAM,UAAU;CAAO,CAAC,CAAC,CAC1D,QAAQ,MAASI,EAAK,SAAS,YAAY,CAAC,CAAC,CAC7C,MAAM,MACLF,EAAS,KAAKlC,EAAG,aAAaC,EAAK,KAAK+B,GAAQI,CAAI,GAAG,MAAM,CAAC,CAChE;AACJ;AAOA,SAAgBC,EACd,GACA,EAAE,UAAO,UAAO,cACH;CACb,IAAMT,IAAa3B,EAAK,KACtBgC,GACA,OACA,OACA,WACA,GAAGK,EAAM,KAAK,IAChB;CACA,IAAI,CAACtC,EAAG,WAAW4B,CAAU,GAAG,OAAO;CAEvC,IAAMW,IAAgC,CAAC;CACvC,AAAIC,EAAM,SAAS,KACjBD,EAAc,KAAK;EACjB,IAAI;EACJ,SAAS1C,EAAuB2C,GAAO;GACrC,SAAS;GACT,QAAQT,EAAgBE,GAAMK,EAAM,IAAI;EAC1C,CAAC;CACH,CAAC;CAEH,KAAK,IAAMjB,KAAUQ,GACnB,AAAIR,EAAO,OAAO,SAAOkB,EAAc,KAAKlB,CAAM;CAGpD,OAAOvB,EACL8B,GACAD,EAAaC,GAAYU,EAAM,YAAYC,CAAa,CAC1D;AACF"}
|
|
1
|
+
{"version":3,"file":"schema-DnMqw2Hn.js","names":["schemaEntriesForFields","modifyOutcomeToFile","formatLikeSource","fs","path","KEY_SUFFIXES","propertyKey","name","unquote","findZodObject","declarations","sourceFile","candidates","d","schemaName","found","declaration","node","Node","callee","shape","findProperty","property","describeChange","change","entry","applyChange","changed","suffix","to","modifySchema","schemaPath","changes","Project","backsRemoteForm","routes","root","imported","modelName","file","modifySchemaForMigration","model","schemaChanges","added"],"sources":["../../src/patterns/generate/migration/modifies/schema.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport path from \"node:path\";\nimport {\n Node,\n Project,\n SyntaxKind,\n type ObjectLiteralExpression,\n type PropertyAssignment,\n type ShorthandPropertyAssignment,\n type SourceFile,\n} from \"ts-morph\";\nimport { schemaEntriesForFields } from \"../../../../core/shared\";\nimport type { File, ModifyOutcome } from \"../../../../core/types\";\nimport { modifyOutcomeToFile } from \"../../../../runtime/modify-file\";\nimport { formatLikeSource } from \"../../../../runtime/ts-morph-helpers\";\nimport type { ResolvedMigration } from \"../generate\";\n\n/** One key of a zod object: its name and the schema it is given. */\nexport interface SchemaEntry {\n name: string;\n schema: string;\n}\n\n/**\n * What a migration did to a collection, as it applies to the zod schema that\n * describes it. An `add` carries every key its field needs (a multi-file\n * field has three); `remove` and `rename` name the field, and take its\n * `name+` / `name-` keys along.\n */\nexport type SchemaChange =\n | { op: \"add\"; entries: SchemaEntry[] }\n | { op: \"remove\"; fieldName: string }\n | { op: \"rename\"; from: string; to: string };\n\n/** The keys a field may have in a schema: its own, and a multi-file field's two. */\nconst KEY_SUFFIXES = [\"\", \"+\", \"-\"];\n\nfunction propertyKey(name: string): string {\n return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(name) ? name : `'${name}'`;\n}\n\nfunction unquote(name: string): string {\n return name.replace(/^([\"'`])(.*)\\1$/, \"$2\");\n}\n\n/**\n * The object literal of `export const <name> = z.object({ ... })`, through a\n * trailing `satisfies` / `as` and any methods chained on (`.strict()`,\n * `.refine(...)`).\n */\nfunction findZodObject(\n sourceFile: SourceFile,\n schemaName: string,\n): ObjectLiteralExpression | undefined {\n const declarations = sourceFile.getVariableDeclarations();\n const candidates = [\n ...declarations.filter((d) => d.getName() === schemaName),\n ...declarations.filter((d) => d.getName() !== schemaName),\n ];\n\n const found: ObjectLiteralExpression[] = [];\n for (const declaration of candidates) {\n let node: Node | undefined = declaration.getInitializer();\n while (node) {\n if (\n Node.isSatisfiesExpression(node) ||\n Node.isAsExpression(node) ||\n Node.isParenthesizedExpression(node)\n ) {\n node = node.getExpression();\n continue;\n }\n if (!Node.isCallExpression(node)) break;\n const callee = node.getExpression();\n if (\n Node.isPropertyAccessExpression(callee) &&\n callee.getName() === \"object\" &&\n callee.getExpression().getText() === \"z\"\n ) {\n const [shape] = node.getArguments();\n if (shape && Node.isObjectLiteralExpression(shape)) found.push(shape);\n break;\n }\n // `<something>.method(...)`: look at what the method was called on.\n node = Node.isPropertyAccessExpression(callee)\n ? callee.getExpression()\n : undefined;\n }\n // The schema under its generated name wins; otherwise the file has to\n // hold exactly one, or there is no telling which the collection's is.\n if (declaration.getName() === schemaName && found.length === 1) {\n return found[0];\n }\n }\n return found.length === 1 ? found[0] : undefined;\n}\n\nfunction findProperty(\n shape: ObjectLiteralExpression,\n name: string,\n): PropertyAssignment | ShorthandPropertyAssignment | undefined {\n return shape\n .getProperties()\n .filter(\n (property) =>\n Node.isPropertyAssignment(property) ||\n Node.isShorthandPropertyAssignment(property),\n )\n .find((property) => unquote(property.getName()) === name);\n}\n\n/** What the user would write to make the change by hand. */\nfunction describeChange(change: SchemaChange): string {\n if (change.op === \"add\") {\n return change.entries\n .map((entry) => `add \\`${propertyKey(entry.name)}: ${entry.schema}\\``)\n .join(\", \");\n }\n if (change.op === \"remove\") return `remove \\`${change.fieldName}\\``;\n return `rename \\`${change.from}\\` to \\`${change.to}\\``;\n}\n\nfunction applyChange(\n shape: ObjectLiteralExpression,\n change: SchemaChange,\n): boolean {\n let changed = false;\n\n if (change.op === \"add\") {\n for (const entry of change.entries) {\n // Already there: added by hand, most likely. Theirs stands.\n if (findProperty(shape, entry.name)) continue;\n shape.addPropertyAssignment({\n name: propertyKey(entry.name),\n initializer: entry.schema,\n });\n changed = true;\n }\n return changed;\n }\n\n for (const suffix of KEY_SUFFIXES) {\n const name =\n (change.op === \"remove\" ? change.fieldName : change.from) + suffix;\n const property = findProperty(shape, name);\n if (!property) continue;\n\n if (change.op === \"remove\") {\n property.remove();\n changed = true;\n continue;\n }\n\n const to = change.to + suffix;\n if (findProperty(shape, to)) continue;\n if (Node.isPropertyAssignment(property)) {\n property.getNameNode().replaceWithText(propertyKey(to));\n } else {\n // `{ title }` → `{ heading: title }`: the value keeps its name.\n property.replaceWithText(`${propertyKey(to)}: ${property.getName()}`);\n }\n changed = true;\n }\n return changed;\n}\n\n/**\n * Brings the zod schema of a collection in line with a migration just applied\n * to it: `generate resource` and the scaffolds write the schema once, and a\n * field added later is optional, so nothing else notices it is missing.\n *\n * Only the keys the migration names are touched. A file without a\n * recognisable `z.object({ ... })` is left as it is and reported, with the\n * edit to make by hand.\n */\nexport function modifySchema(\n schemaPath: string,\n schemaName: string,\n changes: SchemaChange[],\n): ModifyOutcome {\n if (!fs.existsSync(schemaPath) || changes.length === 0) {\n return { status: \"success\", changed: false };\n }\n\n const project = new Project({\n skipAddingFilesFromTsConfig: true,\n skipFileDependencyResolution: true,\n });\n const sourceFile = project.addSourceFileAtPath(schemaPath);\n const shape = findZodObject(sourceFile, schemaName);\n\n if (!shape) {\n return {\n status: \"failed\",\n message: `The collection changed, but no \\`z.object({ ... })\\` schema was found in this file to change with it. Update it by hand: ${changes.map(describeChange).join(\"; \")}.`,\n };\n }\n\n let changed = false;\n for (const change of changes) {\n changed = applyChange(shape, change) || changed;\n }\n if (!changed) {\n return { status: \"success\", changed: false };\n }\n\n formatLikeSource(sourceFile);\n sourceFile.saveSync();\n return { status: \"success\", changed: true };\n}\n\n/**\n * Whether a remote form validates with the model's schema. Its json fields\n * are then typed as the text a textarea posts, not `z.any()`; see\n * `generateSchemaSnippet`.\n */\nfunction backsRemoteForm(root: string, modelName: string): boolean {\n const routes = path.join(root, \"src\", \"routes\");\n if (!fs.existsSync(routes)) return false;\n const imported = new RegExp(`lib/schemas/${modelName}(\\\\.js|\\\\.ts)?[\"']`);\n return fs\n .readdirSync(routes, { recursive: true, encoding: \"utf8\" })\n .filter((file) => file.endsWith(\".remote.ts\"))\n .some((file) =>\n imported.test(fs.readFileSync(path.join(routes, file), \"utf8\")),\n );\n}\n\n/**\n * `modifySchema` for a migration the generator just applied, on the schema\n * file `generate resource` and the scaffolds write for its collection. `null`\n * when there is nothing to report: no such file, or nothing to change in it.\n */\nexport function modifySchemaForMigration(\n root: string,\n { model, added, changes }: ResolvedMigration,\n): File | null {\n const schemaPath = path.join(\n root,\n \"src\",\n \"lib\",\n \"schemas\",\n `${model.name}.ts`,\n );\n if (!fs.existsSync(schemaPath)) return null;\n\n const schemaChanges: SchemaChange[] = [];\n if (added.length > 0) {\n schemaChanges.push({\n op: \"add\",\n entries: schemaEntriesForFields(added, {\n forForm: true,\n remote: backsRemoteForm(root, model.name),\n }),\n });\n }\n for (const change of changes) {\n if (change.op !== \"add\") schemaChanges.push(change);\n }\n\n return modifyOutcomeToFile(\n schemaPath,\n modifySchema(schemaPath, model.schemaName, schemaChanges),\n );\n}\n"],"mappings":";;;;;;;AAmCA,IAAMK,IAAe;CAAC;CAAI;CAAK;AAAG;AAElC,SAASC,EAAY,GAAsB;CACzC,OAAO,6BAA6B,KAAKC,CAAI,IAAIA,IAAO,IAAIA,EAAK;AACnE;AAEA,SAASC,EAAQ,GAAsB;CACrC,OAAOD,EAAK,QAAQ,mBAAmB,IAAI;AAC7C;AAOA,SAASE,EACP,GACA,GACqC;CACrC,IAAMC,IAAeC,EAAW,wBAAwB,GAClDC,IAAa,CACjB,GAAGF,EAAa,QAAQ,MAAMG,EAAE,QAAQ,MAAMC,CAAU,GACxD,GAAGJ,EAAa,QAAQ,MAAMG,EAAE,QAAQ,MAAMC,CAAU,CAC1D,GAEMC,IAAmC,CAAC;CAC1C,KAAK,IAAMC,KAAeJ,GAAY;EACpC,IAAIK,IAAyBD,EAAY,eAAe;EACxD,OAAOC,IAAM;GACX,IACEC,EAAK,s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CAAM;AAM/C;AAOA,SAASuB,EAAgB,GAAc,GAA4B;CACjE,IAAMC,IAAS/B,EAAK,KAAKgC,GAAM,OAAO,QAAQ;CAC9C,IAAI,CAACjC,EAAG,WAAWgC,CAAM,GAAG,OAAO;CACnC,IAAME,IAAe,OAAO,eAAeC,EAAU,mBAAmB;CACxE,OAAOnC,EACJ,YAAYgC,GAAQ;EAAE,WAAW;EAAM,UAAU;CAAO,CAAC,CAAC,CAC1D,QAAQ,MAASI,EAAK,SAAS,YAAY,CAAC,CAAC,CAC7C,MAAM,MACLF,EAAS,KAAKlC,EAAG,aAAaC,EAAK,KAAK+B,GAAQI,CAAI,GAAG,MAAM,CAAC,CAChE;AACJ;AAOA,SAAgBC,EACd,GACA,EAAE,UAAO,UAAO,cACH;CACb,IAAMT,IAAa3B,EAAK,KACtBgC,GACA,OACA,OACA,WACA,GAAGK,EAAM,KAAK,IAChB;CACA,IAAI,CAACtC,EAAG,WAAW4B,CAAU,GAAG,OAAO;CAEvC,IAAMW,IAAgC,CAAC;CACvC,AAAIC,EAAM,SAAS,KACjBD,EAAc,KAAK;EACjB,IAAI;EACJ,SAAS1C,EAAuB2C,GAAO;GACrC,SAAS;GACT,QAAQT,EAAgBE,GAAMK,EAAM,IAAI;EAC1C,CAAC;CACH,CAAC;CAEH,KAAK,IAAMjB,KAAUQ,GACnB,AAAIR,EAAO,OAAO,SAAOkB,EAAc,KAAKlB,CAAM;CAGpD,OAAOvB,EACL8B,GACAD,EAAaC,GAAYU,EAAM,YAAYC,CAAa,CAC1D;AACF"}
|
|
@@ -15,7 +15,7 @@ async function n(e, t) {
|
|
|
15
15
|
exists: !0,
|
|
16
16
|
rowCount: 0
|
|
17
17
|
}));
|
|
18
|
-
let { withPocketbase: n } = await import("./pocketbase-
|
|
18
|
+
let { withPocketbase: n } = await import("./pocketbase-B2ksFrvH.js").then((e) => e.r), { planCollectionDrops: r } = await import("./collections-Daxlnbm0.js").then((e) => e.n), i = [];
|
|
19
19
|
return await n(t.root, async (t) => {
|
|
20
20
|
let n = await r(t, e);
|
|
21
21
|
i.push(...n);
|
|
@@ -23,4 +23,4 @@ async function n(e, t) {
|
|
|
23
23
|
}
|
|
24
24
|
export { t as n, n as t };
|
|
25
25
|
|
|
26
|
-
//# sourceMappingURL=shared-
|
|
26
|
+
//# sourceMappingURL=shared-CSwGWMcN.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shared-
|
|
1
|
+
{"version":3,"file":"shared-CSwGWMcN.js","names":["languageFromPath","toDeleteEntry","path","planDropsForCollections","collectionNames","options","n","drops","withPocketbase","plans","planCollectionDrops","pb"],"sources":["../../src/patterns/destroy/shared.ts"],"sourcesContent":["import type { CollectionDropSpec, File, Options } from \"../../core/types\";\nimport { languageFromPath } from \"../../core/util\";\n\nexport function toDeleteEntry(path: string): File {\n return {\n path,\n language: languageFromPath(path),\n content: \"\",\n status: \"success\",\n };\n}\n\n/**\n * Build `CollectionDropSpec` entries for each collection name, with live row\n * counts from PocketBase when `env === \"runtime\"`. In preview mode, returns\n * `{ exists: true, rowCount: 0 }` placeholders.\n */\nexport async function planDropsForCollections(\n collectionNames: string[],\n options: Options,\n): Promise<CollectionDropSpec[]> {\n if (collectionNames.length === 0) return [];\n\n if (options.env !== \"runtime\") {\n return collectionNames.map((name) => ({\n name,\n exists: true,\n rowCount: 0,\n }));\n }\n\n const { withPocketbase } = await import(\"../../runtime/pocketbase\");\n const { planCollectionDrops } = await import(\"../../runtime/collections\");\n const drops: CollectionDropSpec[] = [];\n await withPocketbase(options.root, async (pb) => {\n const plans = await planCollectionDrops(pb, collectionNames);\n drops.push(...plans);\n });\n return drops;\n}\n"],"mappings":";;AAGA,SAAgBC,EAAc,GAAoB;CAChD,OAAO;EACL;EACA,UAAUD,EAAiBE,CAAI;EAC/B,SAAS;EACT,QAAQ;CACV;AACF;AAOA,eAAsBC,EACpB,GACA,GAC+B;CAC/B,IAAIC,EAAgB,WAAW,GAAG,OAAO,CAAC;CAE1C,IAAIC,EAAQ,QAAQ,WAClB,OAAOD,EAAgB,KAAK,OAAU;EACpC;EACA,QAAQ;EACR,UAAU;CACZ,EAAE;CAGJ,IAAM,EAAE,sBAAmB,MAAM,OAAO,2BAAA,CAAA,MAAA,MAAAE,EAAA,CAAA,GAClC,EAAE,2BAAwB,MAAM,OAAO,4BAAA,CAAA,MAAA,MAAAA,EAAA,CAAA,GACvCC,IAA8B,CAAC;CAKrC,OAJA,MAAMC,EAAeH,EAAQ,MAAM,OAAO,MAAO;EAC/C,IAAMI,IAAQ,MAAMC,EAAoBC,GAAIP,CAAe;EAC3D,EAAM,KAAK,GAAGK,CAAK;CACrB,CAAC,GACMF;AACT"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { i as e, r as t, t as n } from "./rolldown-runtime-CwxnZyOB.js";
|
|
2
|
-
import {
|
|
2
|
+
import { l as r, o as i, s as a, u as o } from "./route-9ZVJZkYu.js";
|
|
3
3
|
import { t as s } from "./dedent-CCUOcPFW.js";
|
|
4
4
|
import { t as c } from "./errors-DdSUZI8f.js";
|
|
5
5
|
// src/parse/syntax.ts
|
|
@@ -464,12 +464,12 @@ function w(e) {
|
|
|
464
464
|
if (!/^[a-zA-Z][a-zA-Z0-9_-]*$/.test(e)) throw new c("Model name must start with a letter and contain only alphanumeric characters, dash, or underscore. Use --route to specify a custom route path.");
|
|
465
465
|
}
|
|
466
466
|
function T(e) {
|
|
467
|
-
let t = S.default.singular(
|
|
467
|
+
let t = S.default.singular(a(e)), n = S.default.plural(t), s = i(t);
|
|
468
468
|
return {
|
|
469
469
|
name: C(s),
|
|
470
|
-
pluralName: C(
|
|
471
|
-
typeName:
|
|
472
|
-
tableName:
|
|
470
|
+
pluralName: C(i(n)),
|
|
471
|
+
typeName: r(t),
|
|
472
|
+
tableName: o(n),
|
|
473
473
|
displayName: t,
|
|
474
474
|
pluralDisplayName: n,
|
|
475
475
|
schemaName: `${C(s)}Schema`
|
|
@@ -678,14 +678,14 @@ function F(e) {
|
|
|
678
678
|
let t = S.default.singular(e);
|
|
679
679
|
return e === S.default.plural(t) ? 99 : 1;
|
|
680
680
|
}
|
|
681
|
-
function I(e, t, n,
|
|
681
|
+
function I(e, t, n, r, a) {
|
|
682
682
|
let o = T(t), s = S.default.singular(e), c = S.default.plural(s);
|
|
683
683
|
return {
|
|
684
|
-
collectionId:
|
|
684
|
+
collectionId: r[t],
|
|
685
685
|
displayField: a[t] ?? "id",
|
|
686
686
|
relatedModel: o,
|
|
687
|
-
singularRelationName:
|
|
688
|
-
pluralRelationName:
|
|
687
|
+
singularRelationName: i(`${n.displayName} ${o.displayName}`),
|
|
688
|
+
pluralRelationName: i(`${n.displayName} ${o.pluralDisplayName}`),
|
|
689
689
|
maxSelect: e === c ? 999 : 1
|
|
690
690
|
};
|
|
691
691
|
}
|
|
@@ -720,7 +720,7 @@ function R(e, t, n) {
|
|
|
720
720
|
return e;
|
|
721
721
|
}
|
|
722
722
|
function z(e, t, n, r, i) {
|
|
723
|
-
let
|
|
723
|
+
let o = a(e), { type: s, required: u, selectOptions: d } = t, f = re(r), p = ie(r), m = D(r), h = f.map((e) => S.default.singular(e));
|
|
724
724
|
if (s === "current_user") {
|
|
725
725
|
if (!i.features.auth) throw new c("Field type \"current_user\" requires the auth feature. Run `vela enable auth` to enable it.");
|
|
726
726
|
if (!p.users) throw new c("Field type \"current_user\" requires a \"users\" collection but none was found.");
|
|
@@ -728,7 +728,7 @@ function z(e, t, n, r, i) {
|
|
|
728
728
|
return {
|
|
729
729
|
type: "relation",
|
|
730
730
|
name: e,
|
|
731
|
-
title:
|
|
731
|
+
title: o,
|
|
732
732
|
required: !0,
|
|
733
733
|
collectionId: t.collectionId,
|
|
734
734
|
maxSelect: 1,
|
|
@@ -747,7 +747,7 @@ function z(e, t, n, r, i) {
|
|
|
747
747
|
return {
|
|
748
748
|
type: "relation",
|
|
749
749
|
name: e,
|
|
750
|
-
title:
|
|
750
|
+
title: o,
|
|
751
751
|
required: !0,
|
|
752
752
|
collectionId: t.collectionId,
|
|
753
753
|
maxSelect: 1,
|
|
@@ -765,7 +765,7 @@ function z(e, t, n, r, i) {
|
|
|
765
765
|
return {
|
|
766
766
|
type: "autodate",
|
|
767
767
|
name: e,
|
|
768
|
-
title:
|
|
768
|
+
title: o,
|
|
769
769
|
required: u,
|
|
770
770
|
...t
|
|
771
771
|
};
|
|
@@ -773,7 +773,7 @@ function z(e, t, n, r, i) {
|
|
|
773
773
|
if (s === "select") return {
|
|
774
774
|
type: "select",
|
|
775
775
|
name: e,
|
|
776
|
-
title:
|
|
776
|
+
title: o,
|
|
777
777
|
required: u,
|
|
778
778
|
maxSelect: Math.max(1, Math.min(F(e), d.length)),
|
|
779
779
|
options: d
|
|
@@ -781,7 +781,7 @@ function z(e, t, n, r, i) {
|
|
|
781
781
|
if (s === "file") return {
|
|
782
782
|
type: "file",
|
|
783
783
|
name: e,
|
|
784
|
-
title:
|
|
784
|
+
title: o,
|
|
785
785
|
required: u,
|
|
786
786
|
maxSelect: F(e)
|
|
787
787
|
};
|
|
@@ -791,7 +791,7 @@ function z(e, t, n, r, i) {
|
|
|
791
791
|
return {
|
|
792
792
|
type: "relation",
|
|
793
793
|
name: e,
|
|
794
|
-
title:
|
|
794
|
+
title: o,
|
|
795
795
|
required: u,
|
|
796
796
|
...I(e, r, n, p, m),
|
|
797
797
|
isCurrentUser: !1,
|
|
@@ -801,7 +801,7 @@ function z(e, t, n, r, i) {
|
|
|
801
801
|
if (f.includes(s)) return {
|
|
802
802
|
type: "relation",
|
|
803
803
|
name: e,
|
|
804
|
-
title:
|
|
804
|
+
title: o,
|
|
805
805
|
required: u,
|
|
806
806
|
...I(e, s, n, p, m),
|
|
807
807
|
isCurrentUser: !1,
|
|
@@ -814,7 +814,7 @@ function z(e, t, n, r, i) {
|
|
|
814
814
|
return {
|
|
815
815
|
type: "relation",
|
|
816
816
|
name: e,
|
|
817
|
-
title:
|
|
817
|
+
title: o,
|
|
818
818
|
required: u,
|
|
819
819
|
collectionId: r.collectionId,
|
|
820
820
|
displayField: r.displayField,
|
|
@@ -839,7 +839,7 @@ function z(e, t, n, r, i) {
|
|
|
839
839
|
return {
|
|
840
840
|
type: s,
|
|
841
841
|
name: e,
|
|
842
|
-
title:
|
|
842
|
+
title: o,
|
|
843
843
|
required: u
|
|
844
844
|
};
|
|
845
845
|
}
|
|
@@ -1013,31 +1013,31 @@ function fe(e) {
|
|
|
1013
1013
|
return t;
|
|
1014
1014
|
}
|
|
1015
1015
|
function pe(e, t, n) {
|
|
1016
|
-
let
|
|
1017
|
-
if (!
|
|
1018
|
-
let
|
|
1019
|
-
for (let t of
|
|
1016
|
+
let r = t.find((t) => t.name === e.tableName);
|
|
1017
|
+
if (!r) throw Error(`Collection "${e.tableName}" not found`);
|
|
1018
|
+
let o = D(t), s = new Map(t.map((e) => [e.id, e])), c = [];
|
|
1019
|
+
for (let t of r.fields) {
|
|
1020
1020
|
if (t.name === "id" || t.system || t.type === "autodate" && X(t.name)) continue;
|
|
1021
|
-
let
|
|
1022
|
-
if (
|
|
1023
|
-
let
|
|
1024
|
-
if (!
|
|
1025
|
-
let
|
|
1021
|
+
let r = fe(t.type), l = !!t.required, u = a(t.name);
|
|
1022
|
+
if (r === "relation") {
|
|
1023
|
+
let r = t.collectionId ? s.get(t.collectionId) : void 0;
|
|
1024
|
+
if (!r) continue;
|
|
1025
|
+
let a = T(r.name);
|
|
1026
1026
|
c.push({
|
|
1027
1027
|
name: t.name,
|
|
1028
1028
|
title: u,
|
|
1029
1029
|
type: "relation",
|
|
1030
1030
|
required: l,
|
|
1031
|
-
collectionId:
|
|
1031
|
+
collectionId: r.id,
|
|
1032
1032
|
maxSelect: t.maxSelect ?? 1,
|
|
1033
|
-
displayField:
|
|
1034
|
-
relatedModel:
|
|
1035
|
-
singularRelationName:
|
|
1036
|
-
pluralRelationName:
|
|
1037
|
-
isCurrentUser: n.features.auth &&
|
|
1038
|
-
isCurrentTeam: n.features.teams &&
|
|
1033
|
+
displayField: o[r.name] ?? "id",
|
|
1034
|
+
relatedModel: a,
|
|
1035
|
+
singularRelationName: i(`${e.displayName} ${a.displayName}`),
|
|
1036
|
+
pluralRelationName: i(`${e.displayName} ${a.pluralDisplayName}`),
|
|
1037
|
+
isCurrentUser: n.features.auth && r.name === "users" && /user|owner|author/i.test(t.name),
|
|
1038
|
+
isCurrentTeam: n.features.teams && r.name === "teams" && /team/i.test(t.name)
|
|
1039
1039
|
});
|
|
1040
|
-
} else
|
|
1040
|
+
} else r === "select" ? c.push({
|
|
1041
1041
|
name: t.name,
|
|
1042
1042
|
title: u,
|
|
1043
1043
|
type: "select",
|
|
@@ -1047,13 +1047,13 @@ function pe(e, t, n) {
|
|
|
1047
1047
|
label: e,
|
|
1048
1048
|
value: e
|
|
1049
1049
|
}))
|
|
1050
|
-
}) :
|
|
1050
|
+
}) : r === "file" ? c.push({
|
|
1051
1051
|
name: t.name,
|
|
1052
1052
|
title: u,
|
|
1053
1053
|
type: "file",
|
|
1054
1054
|
required: l,
|
|
1055
1055
|
maxSelect: t.maxSelect ?? 1
|
|
1056
|
-
}) :
|
|
1056
|
+
}) : r === "autodate" ? c.push({
|
|
1057
1057
|
name: t.name,
|
|
1058
1058
|
title: u,
|
|
1059
1059
|
type: "autodate",
|
|
@@ -1063,7 +1063,7 @@ function pe(e, t, n) {
|
|
|
1063
1063
|
}) : c.push({
|
|
1064
1064
|
name: t.name,
|
|
1065
1065
|
title: u,
|
|
1066
|
-
type:
|
|
1066
|
+
type: r,
|
|
1067
1067
|
required: l
|
|
1068
1068
|
});
|
|
1069
1069
|
}
|
|
@@ -1179,4 +1179,4 @@ function Ce(e, t, n, r) {
|
|
|
1179
1179
|
}
|
|
1180
1180
|
export { w as _, me as a, ue as c, K as d, J as f, T as g, B as h, G as i, xe as l, q as m, Ce as n, he as o, $ as p, de as r, ge as s, Z as t, be as u, x as v, b as y };
|
|
1181
1181
|
|
|
1182
|
-
//# sourceMappingURL=shared-
|
|
1182
|
+
//# sourceMappingURL=shared-Cdwm_-Nl.js.map
|