@getstrata/cli 2.2.57 → 2.2.58
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/CHANGELOG.md +8 -0
- package/README.md +7 -1
- package/package.json +3 -3
- package/src/scaffold/index.ts +6 -0
- package/src/scaffold/makeModel.ts +84 -0
- package/src/scaffold/makeView.ts +49 -0
- package/src/scaffold/scaffoldFile.ts +53 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# @getstrata/cli changelog
|
|
2
2
|
|
|
3
|
+
## 2.2.58
|
|
4
|
+
|
|
5
|
+
PostgreSQL runtime privilege fix: Replace broad table/sequence grants with explicit CRUD and sequence usage/read permissions. Repair legacy helper-managed grants that allowed TRUNCATE across RLS tenant boundaries. Preserve provisioning locks and transactional rollback. Resolves #364 through #370.
|
|
6
|
+
UUID schema columns: Add table.uuid() with PostgreSQL native UUID, MySQL CHAR(36) and SQLite TEXT. Supports explicit constraints and application-supplied identifiers; existing schemas remain unchanged. #365
|
|
7
|
+
Model and view generators: Add make:model for declarative models with automatic repositories, and make:view for escaped Eta templates. Support nested names and explicit model metadata, with path validation and overwrite protection. Migrations remain explicit and separate. #368
|
|
8
|
+
Repeated form values: Add opt-in { preserveRepeated: true } parsing through core form helpers and WebFormRequest, retaining repeated text and files in order. Existing parsing defaults remain unchanged; applications retain responsibility for duplicate validation. #366
|
|
9
|
+
Mail extension documentation and coverage: Qualify existing injected MailDriver integrations, including HTTPS providers, cancellation, deadlines, error propagation and provider-controlled idempotency. This adds tests and guidance without changing stock mail transports. #367
|
|
10
|
+
|
|
3
11
|
## 2.2.57
|
|
4
12
|
|
|
5
13
|
Align the CLI with the compatible 2.2.57 core/bootstrap runtime. No new command or implicit proxy trust is introduced.
|
package/README.md
CHANGED
|
@@ -55,11 +55,17 @@ From the current working directory, `strata` loads `strata.config.ts` if present
|
|
|
55
55
|
|
|
56
56
|
Helpers live on package subpaths: `@getstrata/cli/queueWorker`, `@getstrata/cli/queueFailed`, `@getstrata/cli/scaffold`, `@getstrata/cli/openapi`, and `@getstrata/cli/schedule`. `queue:work` takes `{ boot, close }` and does not call `assertProductionSecrets()` (that belongs in app boot). Scaffold commands resolve paths from the app working directory (`src/modules`, `src/db/migrations`, `src/jobs`, `views/` or `resources/views`). See [docs/BUILDING-APPS.md](https://github.com/EyK-26/strata/blob/main/docs/BUILDING-APPS.md#extending-the-cli).
|
|
57
57
|
|
|
58
|
+
`make:model <Name|Group/Name>` generates an id-only declarative model under `src/models`; its repository comes from `defineModel(table)` and normal startup discovery. Use `--table=existing_table`, `--primary-key=id`, and `--key-type=number|string` for explicit metadata. UUID keys use `string`. Add domain fields to the record, table columns and allowlist before writing them. Migration generation is always separate: `make:migration <name>`. No route or custom repository is generated, and existing files/symlinked parents are refused.
|
|
59
|
+
|
|
60
|
+
Existing apps must register `makeModelCommand` from `@getstrata/cli/scaffold` (or merge its `scaffoldCommands` map). A dependency upgrade does not rewrite the app-owned command registry. Use `make:model --help` for options.
|
|
61
|
+
|
|
62
|
+
`make:view reports/summary[.eta]` creates an Eta HTML template under an existing `views/`, or `resources/views/` otherwise. It supports nested names, leading-underscore partials and numeric error pages, and refuses unsafe paths, symlinks and overwrites. It does not create routes/controllers, enable views or change the app's layout/directory configuration. Register `makeViewCommand` from the same scaffold subpath in existing apps; fresh generated registries include it.
|
|
63
|
+
|
|
58
64
|
A migrate entry may export `close()`. The CLI calls it after `migrate()` and `fresh()` so pooled drivers such as `mysql2` release the event loop instead of hanging the command.
|
|
59
65
|
|
|
60
66
|
## Creating a new app
|
|
61
67
|
|
|
62
|
-
This package does not
|
|
68
|
+
This package does not create whole application projects. Use the starter:
|
|
63
69
|
|
|
64
70
|
```bash
|
|
65
71
|
bunx create-strata my-app
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@getstrata/cli",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.58",
|
|
4
4
|
"description": "Strata CLI: framework commands for Bun apps (dev, start, migrate, run)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -54,8 +54,8 @@
|
|
|
54
54
|
],
|
|
55
55
|
"scripts": {},
|
|
56
56
|
"peerDependencies": {
|
|
57
|
-
"@getstrata/bootstrap": "^2.2.
|
|
58
|
-
"@getstrata/core": "^2.2.
|
|
57
|
+
"@getstrata/bootstrap": "^2.2.58",
|
|
58
|
+
"@getstrata/core": "^2.2.58"
|
|
59
59
|
},
|
|
60
60
|
"publishConfig": {
|
|
61
61
|
"access": "public"
|
package/src/scaffold/index.ts
CHANGED
|
@@ -3,9 +3,11 @@ import { makeFactoryCommand } from "./makeFactory.ts";
|
|
|
3
3
|
import { makeJobCommand } from "./makeJob.ts";
|
|
4
4
|
import { makeListenerCommand } from "./makeListener.ts";
|
|
5
5
|
import { makeMigrationCommand } from "./makeMigration.ts";
|
|
6
|
+
import { makeModelCommand } from "./makeModel.ts";
|
|
6
7
|
import { makeModuleCommand } from "./makeModule.ts";
|
|
7
8
|
import { makePolicyCommand } from "./makePolicy.ts";
|
|
8
9
|
import { makeRequestCommand } from "./makeRequest.ts";
|
|
10
|
+
import { makeViewCommand } from "./makeView.ts";
|
|
9
11
|
import {
|
|
10
12
|
ensureDirectory,
|
|
11
13
|
migrationDirectory,
|
|
@@ -18,6 +20,8 @@ import {
|
|
|
18
20
|
} from "./utils.ts";
|
|
19
21
|
|
|
20
22
|
const scaffoldCommands: StrataCommandMap = {
|
|
23
|
+
"make:model": async () => makeModelCommand,
|
|
24
|
+
"make:view": async () => makeViewCommand,
|
|
21
25
|
"make:module": async () => makeModuleCommand,
|
|
22
26
|
"make:policy": async () => makePolicyCommand,
|
|
23
27
|
"make:job": async () => makeJobCommand,
|
|
@@ -33,9 +37,11 @@ export {
|
|
|
33
37
|
makeJobCommand,
|
|
34
38
|
makeListenerCommand,
|
|
35
39
|
makeMigrationCommand,
|
|
40
|
+
makeModelCommand,
|
|
36
41
|
makeModuleCommand,
|
|
37
42
|
makePolicyCommand,
|
|
38
43
|
makeRequestCommand,
|
|
44
|
+
makeViewCommand,
|
|
39
45
|
migrationDirectory,
|
|
40
46
|
moduleDirectory,
|
|
41
47
|
scaffoldCommands,
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { scaffoldNameParts, writeScaffoldFile } from "./scaffoldFile";
|
|
2
|
+
import { toKebabCase, toPascalCase } from "./utils";
|
|
3
|
+
|
|
4
|
+
function modelIdentifier(value: string, option: string): string {
|
|
5
|
+
if (
|
|
6
|
+
!/^[A-Za-z_][A-Za-z0-9_]*$/.test(value) ||
|
|
7
|
+
["__proto__", "prototype", "constructor"].includes(value)
|
|
8
|
+
)
|
|
9
|
+
throw new Error(`${option} must be a simple identifier.`);
|
|
10
|
+
return value;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
async function makeModelCommand(...args: string[]): Promise<void> {
|
|
14
|
+
if (args.includes("--help") || args.includes("-h")) {
|
|
15
|
+
console.log(
|
|
16
|
+
"Usage: strata make:model <Name|Group/Name> [--table=name] [--primary-key=id] [--key-type=number|string]",
|
|
17
|
+
);
|
|
18
|
+
console.log("Creates an id-only declarative model in src/models with an automatic repository.");
|
|
19
|
+
console.log("No schema changes: run strata make:migration <name> separately.");
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
const names = args.filter((value) => !value.startsWith("--"));
|
|
23
|
+
if (names.length > 1) throw new Error("make:model accepts one model name.");
|
|
24
|
+
const parts = scaffoldNameParts(names[0], "make:model");
|
|
25
|
+
const options = new Map<string, string>();
|
|
26
|
+
for (const arg of args.filter((value) => value.startsWith("--"))) {
|
|
27
|
+
const match = /^--(table|primary-key|key-type)=(.*)$/.exec(arg);
|
|
28
|
+
if (!match?.[1] || options.has(match[1]))
|
|
29
|
+
throw new Error(
|
|
30
|
+
`Unsupported or duplicate make:model option: ${arg}; use --help. Migrations use make:migration separately.`,
|
|
31
|
+
);
|
|
32
|
+
options.set(match[1], match[2] ?? "");
|
|
33
|
+
}
|
|
34
|
+
if (["index", "register"].includes((parts.at(-1) ?? "").toLowerCase()))
|
|
35
|
+
throw new Error("make:model name is reserved for model discovery orchestration.");
|
|
36
|
+
const classParts = parts.map(toPascalCase);
|
|
37
|
+
const className = classParts.join("");
|
|
38
|
+
const key = modelIdentifier(options.get("primary-key") ?? "id", "--primary-key");
|
|
39
|
+
const table = modelIdentifier(
|
|
40
|
+
options.get("table") ?? `${parts.map(toKebabCase).join("_").replaceAll("-", "_")}s`,
|
|
41
|
+
"--table",
|
|
42
|
+
);
|
|
43
|
+
const keyType = options.get("key-type") ?? "number";
|
|
44
|
+
if (keyType !== "number" && keyType !== "string")
|
|
45
|
+
throw new Error("--key-type must be number or string; UUID model keys use string.");
|
|
46
|
+
const fillable = keyType === "string" ? JSON.stringify(key) : "";
|
|
47
|
+
const content = `import { defineModel } from "@getstrata/core/database/model";
|
|
48
|
+
import { defineTable } from "@getstrata/core/database/table";
|
|
49
|
+
|
|
50
|
+
interface ${className}Record {
|
|
51
|
+
${key}: ${keyType};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const table = defineTable<${className}Record, "${key}">({
|
|
55
|
+
name: "${table}",
|
|
56
|
+
primaryKey: "${key}",
|
|
57
|
+
columns: ["${key}"],
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
class ${className} extends defineModel(table) {
|
|
61
|
+
// Add writable fields to the record, table columns and this explicit allowlist.
|
|
62
|
+
static override $fillable = [${fillable}] as const;
|
|
63
|
+
// Enable only after adding the corresponding timestamp columns to your schema.
|
|
64
|
+
static override $timestamps = false;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export type { ${className}Record };
|
|
68
|
+
export { ${className} };
|
|
69
|
+
`;
|
|
70
|
+
const path = await writeScaffoldFile(
|
|
71
|
+
["src", "models", ...classParts.slice(0, -1), `${classParts.at(-1)}.ts`],
|
|
72
|
+
content,
|
|
73
|
+
"Model",
|
|
74
|
+
);
|
|
75
|
+
console.log(`Created model: ${path}`);
|
|
76
|
+
console.log(
|
|
77
|
+
"src/models discovery supplies its default repository; no custom repository is required.",
|
|
78
|
+
);
|
|
79
|
+
console.log(
|
|
80
|
+
`Next: strata make:migration create_${table}; define schema explicitly before strata migrate.`,
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export { makeModelCommand };
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { lstat } from "node:fs/promises";
|
|
2
|
+
import { join, relative, sep } from "node:path";
|
|
3
|
+
import { scaffoldNameParts, writeScaffoldFile } from "./scaffoldFile";
|
|
4
|
+
import { toKebabCase, webViewsDirectory } from "./utils";
|
|
5
|
+
|
|
6
|
+
async function makeViewCommand(...args: string[]): Promise<void> {
|
|
7
|
+
if (args.includes("--help") || args.includes("-h")) {
|
|
8
|
+
console.log("Usage: strata make:view <name|group/name[.eta]>");
|
|
9
|
+
console.log(
|
|
10
|
+
"Uses views when it exists, otherwise resources/views. Existing files are never overwritten.",
|
|
11
|
+
);
|
|
12
|
+
console.log(
|
|
13
|
+
"Creates only an Eta template; no routes, controllers, providers or schema changes.",
|
|
14
|
+
);
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
if (args.some((arg) => arg.startsWith("-")))
|
|
18
|
+
throw new Error("Unsupported make:view option; use --help. Overwrite is not supported.");
|
|
19
|
+
if (args.length > 1) throw new Error("make:view accepts one view name.");
|
|
20
|
+
const raw = args[0]?.endsWith(".eta") ? args[0].slice(0, -4) : args[0];
|
|
21
|
+
const parts = scaffoldNameParts(raw, "make:view", { filename: true }).map((part) =>
|
|
22
|
+
part.startsWith("_") ? `_${toKebabCase(part.slice(1))}` : toKebabCase(part),
|
|
23
|
+
);
|
|
24
|
+
// A dangling link must not silently select a different root through existsSync().
|
|
25
|
+
try {
|
|
26
|
+
if ((await lstat(join(process.cwd(), "views"))).isSymbolicLink())
|
|
27
|
+
throw new Error("Refusing symbolic link in scaffold output: views");
|
|
28
|
+
} catch (error) {
|
|
29
|
+
if (!(error instanceof Error) || !("code" in error) || error.code !== "ENOENT") throw error;
|
|
30
|
+
}
|
|
31
|
+
const base = relative(process.cwd(), webViewsDirectory("")).split(sep);
|
|
32
|
+
const title = JSON.stringify(parts.join(" / "));
|
|
33
|
+
const content = `<section>
|
|
34
|
+
<h1><%= it.title ?? ${title} %></h1>
|
|
35
|
+
<p><%= it.message ?? "" %></p>
|
|
36
|
+
</section>
|
|
37
|
+
`;
|
|
38
|
+
const path = await writeScaffoldFile(
|
|
39
|
+
[...base, ...parts.slice(0, -1), `${parts.at(-1)}.eta`],
|
|
40
|
+
content,
|
|
41
|
+
"View",
|
|
42
|
+
);
|
|
43
|
+
console.log(`Created view: ${path}`);
|
|
44
|
+
console.log(
|
|
45
|
+
`Render as "${parts.join("/")}" using the app's Eta view renderer; no routes were added.`,
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export { makeViewCommand };
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { Stats } from "node:fs";
|
|
2
|
+
import { lstat, mkdir, writeFile } from "node:fs/promises";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
|
|
5
|
+
/** Validate before normalization so traversal and punctuation cannot become a different name. */
|
|
6
|
+
function scaffoldNameParts(
|
|
7
|
+
value: string | undefined,
|
|
8
|
+
command: string,
|
|
9
|
+
options: { filename?: boolean } = {},
|
|
10
|
+
): string[] {
|
|
11
|
+
if (!value) throw new Error(`${command} requires a name.`);
|
|
12
|
+
const parts = value.split("/");
|
|
13
|
+
const pattern = options.filename ? /^_?[A-Za-z0-9][A-Za-z0-9 _-]*$/ : /^[A-Za-z][A-Za-z0-9 _-]*$/;
|
|
14
|
+
if (parts.some((part) => !pattern.test(part) || part !== part.trim()))
|
|
15
|
+
throw new Error(
|
|
16
|
+
`${command} requires a valid relative name; use letters, digits, spaces, _ or - within slash-separated names.`,
|
|
17
|
+
);
|
|
18
|
+
return parts;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** Exclusive creation; never overwrite existing files or follow existing output symlinks. */
|
|
22
|
+
async function writeScaffoldFile(
|
|
23
|
+
segments: string[],
|
|
24
|
+
content: string,
|
|
25
|
+
label: string,
|
|
26
|
+
): Promise<string> {
|
|
27
|
+
let directory = process.cwd();
|
|
28
|
+
for (const segment of segments.slice(0, -1)) {
|
|
29
|
+
directory = join(directory, segment);
|
|
30
|
+
let entry: Stats;
|
|
31
|
+
try {
|
|
32
|
+
entry = await lstat(directory);
|
|
33
|
+
} catch (error) {
|
|
34
|
+
if (!(error instanceof Error) || !("code" in error) || error.code !== "ENOENT") throw error;
|
|
35
|
+
await mkdir(directory, { recursive: true });
|
|
36
|
+
entry = await lstat(directory);
|
|
37
|
+
}
|
|
38
|
+
if (entry.isSymbolicLink())
|
|
39
|
+
throw new Error(`Refusing symbolic link in scaffold output: ${directory}`);
|
|
40
|
+
if (!entry.isDirectory()) throw new Error(`Scaffold parent is not a directory: ${directory}`);
|
|
41
|
+
}
|
|
42
|
+
const path = join(directory, segments.at(-1) ?? "");
|
|
43
|
+
try {
|
|
44
|
+
await writeFile(path, content, { flag: "wx" });
|
|
45
|
+
} catch (error) {
|
|
46
|
+
if (error instanceof Error && "code" in error && error.code === "EEXIST")
|
|
47
|
+
throw new Error(`${label} already exists: ${path}; overwrite refused.`, { cause: error });
|
|
48
|
+
throw error;
|
|
49
|
+
}
|
|
50
|
+
return path;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export { scaffoldNameParts, writeScaffoldFile };
|