cursedops 0.9.0 → 0.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/package.json +3 -2
- package/src/d1Schema.ts +80 -0
package/README.md
CHANGED
|
@@ -17,7 +17,7 @@ bun add cursedops
|
|
|
17
17
|
| `cursedops/worker-secrets` | a Worker holding EXACTLY its deployment's secrets, uploaded over a pipe, read back (0.5.0) |
|
|
18
18
|
| `cursedops/worker-rollback` | a hostname back on its Mac origin: origin first, route second, the route found rather than typed (0.5.0) |
|
|
19
19
|
| `cursedops/edge-fetch` | a request to a deployed Worker as a script must make it — curl pinned past the Mac's negative DNS cache (0.5.0) |
|
|
20
|
-
| `cursedops/d1-import` | a cutover's data proof — SQL literals and the row-for-row comparison, never a count (0.5.0); and `d1SchemaText`, the generated `db/schema.sql` that refuses a statement spanning lines, because D1's exec splits on newlines (0.9.0, lifted from five apps, task 2153) |
|
|
20
|
+
| `cursedops/d1-import` | a cutover's data proof — SQL literals and the row-for-row comparison, never a count (0.5.0); and `d1SchemaText`, the generated `db/schema.sql` that refuses a statement spanning lines, because D1's exec splits on newlines (0.9.0, lifted from five apps, task 2153) — and its `forge-d1-schema` bin (0.9.1), so no app carries its own schema script at all |
|
|
21
21
|
| `cursedops/backups` | `BACKUP_KEEP`, the fleet's one retention for dated snapshots — six apps each exported `KEEP = 14` (0.9.0, task 2153) |
|
|
22
22
|
| `cursedops/serve` | the static tier's four helpers — the path-traversal guard, the MIME table, the hashed-asset test, the crash handlers |
|
|
23
23
|
| `cursedops/api-floor` | the rule that an unmatched `/api/...` is a phrase and never the app shell — the namespace predicates, the trailing-slash normaliser and the default 404 body. No `node:` import, so it mounts inside a Worker |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cursedops",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.1",
|
|
4
4
|
"description": "The build-and-ops answers this generation's apps wrote independently and identically: finding a generation's roots — and printing a command that runs when pasted — without knowing a path, the generation's whole-tree laws run over one repo from a checkout or a worktree, macOS launchd agent install/replace/remove and the live port a job serves, the scaffolding and verdicts of a deployed smoke (origin probe, the smoke's own environment, a network that lies about DNS, a settled version), the static-serving helpers eight apps copied — the path-traversal guard among them — the API floor that keeps an unmatched /api/... from ever being answered with the app shell, the commit and dirty flag a checkout-served process reports, the Cloudflare Worker deploy toolkit four apps copied (the deploy sequence, exact-set secrets over a pipe, origin-first rollback, the curl edge fetch, the row-for-row D1 import proof, the billed-CPU tail check around a deploy's walk and smoke, and each app's worker:secrets and worker:smoke main as one function of its data), the Worker import-graph and await-port checks every Worker app's suite runs over its own source, and the public-surface ratchet three published libraries each carried a forked copy of. Mechanism only — no app knows its name from here. Bun, zero runtime dependencies (typescript is an optional peer, for public-surface only), ships source.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
@@ -126,7 +126,8 @@
|
|
|
126
126
|
"bin": {
|
|
127
127
|
"public-surface": "./src/publicSurface.ts",
|
|
128
128
|
"forge-paths": "./src/paths.ts",
|
|
129
|
-
"forge-client": "./src/stagedClient.ts"
|
|
129
|
+
"forge-client": "./src/stagedClient.ts",
|
|
130
|
+
"forge-d1-schema": "./src/d1Schema.ts"
|
|
130
131
|
},
|
|
131
132
|
"files": [
|
|
132
133
|
"src",
|
package/src/d1Schema.ts
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
/**
|
|
3
|
+
* `forge-d1-schema --database <name> --from <module> [--note "<line>"]…` — write `db/schema.sql`,
|
|
4
|
+
* the shape a Worker app's D1 is given, from the module's `schemaStatements()`.
|
|
5
|
+
*
|
|
6
|
+
* ```jsonc
|
|
7
|
+
* // an app's package.json — the script line IS the configuration
|
|
8
|
+
* "schema": "forge-d1-schema --database music --from src/server/localDb.ts"
|
|
9
|
+
* ```
|
|
10
|
+
*
|
|
11
|
+
* ## 🔴 Why the file is GENERATED and never hand-written
|
|
12
|
+
*
|
|
13
|
+
* A Worker has no boot. An app's `migrate()` issues dozens of statements and inspects
|
|
14
|
+
* `PRAGMA table_info` as it goes; running that on every invocation would spend a D1 invocation's
|
|
15
|
+
* query budget before the request started, and D1 has no `PRAGMA table_info` to inspect with. So
|
|
16
|
+
* D1's schema is applied ONCE, by hand — `bunx wrangler d1 execute <name> --remote --file
|
|
17
|
+
* db/schema.sql` — and there are two descriptions of the app's tables. Each app's own
|
|
18
|
+
* schema-matches test fails its gate when they disagree, so the file is a build product with a
|
|
19
|
+
* checker rather than a document with a convention. {@link d1SchemaText} writes it, and refuses a
|
|
20
|
+
* statement that spans lines, because D1's `exec` splits on newlines.
|
|
21
|
+
*
|
|
22
|
+
* ## Why this is a bin and not a function each app calls
|
|
23
|
+
*
|
|
24
|
+
* Five apps (auth, collections, family, music, vault) each carried its own schema script until task
|
|
25
|
+
* 2153 (2026-09-24). A thinner wrapper around {@link d1SchemaText} was still five files that agree
|
|
26
|
+
* line for line on everything but two strings, and `tools/check-copies.ts` rightly priced them as
|
|
27
|
+
* one file forked five ways. The only thing that differs per app is data — the database name, the
|
|
28
|
+
* module, a note — and data fits in the one line of `package.json` that already names the command.
|
|
29
|
+
*/
|
|
30
|
+
import { mkdirSync, writeFileSync } from "node:fs";
|
|
31
|
+
import { dirname, isAbsolute, join, resolve } from "node:path";
|
|
32
|
+
import { d1SchemaText } from "cursedops/d1-import";
|
|
33
|
+
|
|
34
|
+
export type D1SchemaArgs = { database: string; from: string; exportName: string; notes: string[]; out: string };
|
|
35
|
+
|
|
36
|
+
/** The flags, or the sentence saying what is missing. */
|
|
37
|
+
export function parseD1SchemaArgs(argv: readonly string[]): D1SchemaArgs | string {
|
|
38
|
+
const args: D1SchemaArgs = { database: "", from: "", exportName: "schemaStatements", notes: [], out: join("db", "schema.sql") };
|
|
39
|
+
for (let i = 0; i < argv.length; i++) {
|
|
40
|
+
const flag = argv[i];
|
|
41
|
+
const value = argv[i + 1];
|
|
42
|
+
if (value === undefined) return `${flag} needs a value`;
|
|
43
|
+
if (flag === "--database") args.database = value;
|
|
44
|
+
else if (flag === "--from") args.from = value;
|
|
45
|
+
else if (flag === "--export") args.exportName = value;
|
|
46
|
+
else if (flag === "--note") args.notes.push(value);
|
|
47
|
+
else if (flag === "--out") args.out = value;
|
|
48
|
+
else return `unknown flag ${flag}`;
|
|
49
|
+
i++;
|
|
50
|
+
}
|
|
51
|
+
if (!args.database) return "--database <name> is required — the D1 database, as `wrangler d1 execute` takes it";
|
|
52
|
+
if (!args.from) return "--from <module> is required — the module whose schemaStatements() is the schema";
|
|
53
|
+
return args;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Write the file under `cwd` (the app's root, where `bun run` starts a script). Exit code. */
|
|
57
|
+
export async function runD1SchemaCli(argv: readonly string[], cwd: string = process.cwd()): Promise<number> {
|
|
58
|
+
const args = parseD1SchemaArgs(argv);
|
|
59
|
+
if (typeof args === "string") {
|
|
60
|
+
console.error(`✗ forge-d1-schema: ${args}\nusage: forge-d1-schema --database <name> --from <module> [--export <fn>] [--note "<line>"]… [--out <file>]`);
|
|
61
|
+
return 2;
|
|
62
|
+
}
|
|
63
|
+
const module = (await import(resolve(cwd, args.from))) as Record<string, unknown>;
|
|
64
|
+
const read = module[args.exportName];
|
|
65
|
+
if (typeof read !== "function") {
|
|
66
|
+
console.error(`✗ forge-d1-schema: ${args.from} exports no function ${args.exportName}()`);
|
|
67
|
+
return 2;
|
|
68
|
+
}
|
|
69
|
+
const statements = (await read()) as string[];
|
|
70
|
+
const out = isAbsolute(args.out) ? args.out : join(cwd, args.out);
|
|
71
|
+
const text = d1SchemaText({ database: args.database, source: `${args.from}'s ${args.exportName}()`, statements, notes: args.notes });
|
|
72
|
+
mkdirSync(dirname(out), { recursive: true });
|
|
73
|
+
writeFileSync(out, text);
|
|
74
|
+
console.log(`[${args.database}] wrote ${statements.length} statement(s) to ${args.out}`);
|
|
75
|
+
return 0;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (import.meta.main) {
|
|
79
|
+
process.exit(await runD1SchemaCli(process.argv.slice(2)));
|
|
80
|
+
}
|