Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
eee1169
FullStack takes any column's name: one named like a member it generat…
ejsmith Nov 26, 2026
36d79b1
LookupEnums and Csla warn whoever generates with CodeTemplate.Warning…
ejsmith Nov 26, 2026
98d0217
Legacy README: PLINQO's entity files can use today's C# and VB (=> me…
ejsmith Nov 26, 2026
199e687
Csla: a schema snapshot's web app is wired for the database it was ta…
ejsmith Nov 26, 2026
f23d4f8
Merge branch 'fix/codefileparser-modern-csharp' into fix/pending-2026…
ejsmith Nov 26, 2026
fbf6967
ModernEntities' EF Core templates (and FullStack's and Csla's copies)…
ejsmith Nov 26, 2026
887a5f8
ModernEntities' EF Core templates (and FullStack's and Csla's copies)…
ejsmith Nov 26, 2026
32a58d3
PLINQO's Entities.cst keeps each member of an entity's Metadata class…
ejsmith Nov 26, 2026
76427d9
PLINQO's Dbml.cst fills in the dbml's default values (Mode="Connectio…
ejsmith Nov 26, 2026
812e7a5
PLINQO-EF-DbContext's sample Petshop.csp no longer sets IgnoreList an…
ejsmith Nov 26, 2026
05a94c2
PLINQO: README.md describes the templates and the Metadata class (wha…
ejsmith Nov 26, 2026
f780a4f
FullStack's and Csla's labels come from one routine, NameWords.Label,…
ejsmith Nov 26, 2026
e0f9850
TableToClass's Records.cst and ModernEntities' (and FullStack's) Enti…
ejsmith Nov 26, 2026
08e58ce
FullStack takes a real schema: PostgreSQL arrays are lists, bit strin…
ejsmith Nov 26, 2026
97ee589
Csla takes a real database's schema: arrays are read-only lists CSLA'…
ejsmith Nov 26, 2026
3fc805e
DBDocumenter's title and server are the database's name and the serve…
ejsmith Nov 26, 2026
98c0379
ModernEntities' README says what the configurations map for each data…
ejsmith Nov 26, 2026
a184fc0
Merge branch 'fix/d4-csla' into fix/pending-2026-11-25
ejsmith Nov 26, 2026
34e7b5b
Merge branch 'fix/d4-fullstack' into fix/pending-2026-11-25
ejsmith Nov 26, 2026
bff214e
Merge branch 'fix/d4-plinqo' into fix/pending-2026-11-25
ejsmith Nov 26, 2026
0009ba3
FullStack README: a nullable column with a database default gets it o…
ejsmith Nov 27, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
FullStack takes any column's name: one named like a member it generat…
…es on its records (From, ToEntity, ApplyTo, or a record's own name) keeps its name and the member gives way (FromEntity, CreateEntity, ApplyToEntity, TripResponseRecord: the API didn't compile, CS0102 and CS0542); a key's or a filter's parameter named like a C# or TypeScript keyword (debugger, eval, arguments) or like the endpoints' and the client's own names (db, request, entity, row, call, items, total, the UI's q) gets Value (a filter: Filter) after it, and a number where another column's has that name; and the kit's form reads its maps' own entries, so a field named constructor or valueOf isn't shown as wrong from the start
  • Loading branch information
ejsmith committed Nov 26, 2026
commit eee1169caf32e1d848d058728a5711c64b5f6067
33 changes: 19 additions & 14 deletions Templates/Web/FullStack/Endpoints.cst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
<%
string entity = Names.Entity(Table);
string set = Names.Set(Table);
// the records, and the response's factory: their own names unless a column has them (Web.cs)
string response = Web.Response(Table);
string create = Web.CreateRequest(Table);
string update = Web.UpdateRequest(Table);
string fromEntity = Web.From(Table);
var key = Web.Key(Table);
// the key as parameters, arguments and a route ("string productId", "productId", "/{productId}")
string keyParameters = string.Join(", ", key.Select(c => Names.Type(c).TrimEnd('?') + " " + Web.Parameter(c)));
Expand Down Expand Up @@ -67,13 +72,13 @@ using <%= DataNamespace %>;
namespace <%= Namespace %>;

/// <summary>A row of <%= Table.Name %>, as the API returns it.</summary>
public sealed record <%= entity %>Response
public sealed record <%= response %>
{
<% foreach (ColumnSchema column in Names.Columns(Table)) { %>
public required <%= Names.Type(column) %> <%= Names.Property(column) %> { get; init; }
<% } %>

public static <%= entity %>Response From(<%= entity %> entity) => new()
public static <%= response %> <%= fromEntity %>(<%= entity %> entity) => new()
{
<% foreach (ColumnSchema column in Names.Columns(Table)) { %>
<%= Names.Property(column) %> = entity.<%= Names.Property(column) %>,
Expand All @@ -82,15 +87,15 @@ public sealed record <%= entity %>Response
}

/// <summary>A new row of <%= Table.Name %>.</summary>
public sealed record Create<%= entity %>Request
public sealed record <%= create %>
{
<% foreach (ColumnSchema column in Web.Creates(Table)) { if (Web.Validation(column) != null) { %>
<%= Web.Validation(column) %>
<% } %>
public <%= Names.Required(column) %><%= Names.Type(column) %> <%= Names.Property(column) %> { get; init; }
<% } %>

public <%= entity %> ToEntity() => new()
public <%= entity %> <%= Web.ToEntity(Table) %>() => new()
{
<% foreach (ColumnSchema column in Names.Columns(Table)) { %>
<% if (Web.Creates(Table).Contains(column)) { %>
Expand All @@ -103,15 +108,15 @@ public sealed record Create<%= entity %>Request
}

/// <summary>Changes to a row of <%= Table.Name %>: everything but its key.</summary>
public sealed record Update<%= entity %>Request
public sealed record <%= update %>
{
<% foreach (ColumnSchema column in Web.Updates(Table)) { if (Web.Validation(column) != null) { %>
<%= Web.Validation(column) %>
<% } %>
public <%= Names.Required(column) %><%= Names.Type(column) %> <%= Names.Property(column) %> { get; init; }
<% } %>

public void ApplyTo(<%= entity %> entity)
public void <%= Web.ApplyTo(Table) %>(<%= entity %> entity)
{
<% foreach (ColumnSchema column in Web.Updates(Table)) { %>
entity.<%= Names.Property(column) %> = <%= Names.Property(column) %>;
Expand Down Expand Up @@ -167,30 +172,30 @@ public static class <%= entity %>Endpoints
};
<% } %>
var items = await rows.Skip((page - 1) * pageSize).Take(pageSize).ToListAsync();
return TypedResults.Ok(new PagedList<<%= entity %>Response>(items.Select(<%= entity %>Response.From).ToList(), total, page, pageSize));
return TypedResults.Ok(new PagedList<<%= response %>>(items.Select(<%= response %>.<%= fromEntity %>).ToList(), total, page, pageSize));
}).WithName("List<%= set %>");
<% if (key.Count > 0) { %>

group.MapGet("/<%= Web.KeyRoute(Table) %>", async Task<Results<Ok<<%= entity %>Response>, NotFound>> (<%= keyParameters %>, <%= ContextName %> db) =>
group.MapGet("/<%= Web.KeyRoute(Table) %>", async Task<Results<Ok<<%= response %>>, NotFound>> (<%= keyParameters %>, <%= ContextName %> db) =>
await db.<%= set %>.FindAsync(<%= keyArguments %>) is { } entity
? TypedResults.Ok(<%= entity %>Response.From(entity))
? TypedResults.Ok(<%= response %>.<%= fromEntity %>(entity))
: TypedResults.NotFound())
.WithName("Get<%= entity %>");

group.MapPost("/", async Task<Results<Created<<%= entity %>Response>, ProblemHttpResult>> (Create<%= entity %>Request request, <%= ContextName %> db, IHostEnvironment environment) =>
group.MapPost("/", async Task<Results<Created<<%= response %>>, ProblemHttpResult>> (<%= create %> request, <%= ContextName %> db, IHostEnvironment environment) =>
{
var entity = request.ToEntity();
var entity = request.<%= Web.ToEntity(Table) %>();
db.<%= set %>.Add(entity);
if (await <%= ApiName %>Api.SaveAsync(db, environment<%= explain %>) is { } problem)
return problem;
return TypedResults.Created($"<%= location %>", <%= entity %>Response.From(entity));
return TypedResults.Created($"<%= location %>", <%= response %>.<%= fromEntity %>(entity));
}).WithName("Create<%= entity %>").ProducesProblem(StatusCodes.Status409Conflict);

group.MapPut("/<%= Web.KeyRoute(Table) %>", async Task<Results<NoContent, NotFound, ProblemHttpResult>> (<%= keyParameters %>, Update<%= entity %>Request request, <%= ContextName %> db, IHostEnvironment environment) =>
group.MapPut("/<%= Web.KeyRoute(Table) %>", async Task<Results<NoContent, NotFound, ProblemHttpResult>> (<%= keyParameters %>, <%= update %> request, <%= ContextName %> db, IHostEnvironment environment) =>
{
if (await db.<%= set %>.FindAsync(<%= keyArguments %>) is not { } entity)
return TypedResults.NotFound();
request.ApplyTo(entity);
request.<%= Web.ApplyTo(Table) %>(entity);
if (await <%= ApiName %>Api.SaveAsync(db, environment<%= explain %>) is { } problem)
return problem;
return TypedResults.NoContent();
Expand Down
5 changes: 5 additions & 0 deletions Templates/Web/FullStack/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ names, its other names' words) and a few common ones (`id`, `name`, `date`, `pri
this category. Delete or change them first." `refusal` says which: `unique`, `reference`, `referenced` or `other`.
SQLite, SQL Server, PostgreSQL and MySQL each say it with a code of their own, which the API reads.
- The database's own message (`database`) is there only in Development: it can name tables, columns and values.
- Any column's name works. A column keeps its name in the entity, the records and the JSON; where it's named like
a member a record has (`From`, `ToEntity`, `ApplyTo`, or the record itself), the member gives way (`FromEntity`,
`CreateEntity`, `ApplyToEntity`, `TripResponseRecord`). A key's or a filter's parameter named like a C# or
TypeScript keyword, or like one the code around it has (`db`, `request`, `row`; a list's `page`, `sort`, `items`,
the UI's `q`), gets `Value` after it (a filter: `Filter`): `classValue`, `dbValue`, `?pageFilter=2`.
- **Client** (`client/src/generated/petshop.ts`): a Zod schema and a type for each table's rows and requests, and
`createPetShopClient`, with a typed call per endpoint that checks what it sends and what comes back.
- **Ui** (`client/src/generated/ui/`): the web UI's tables and routes.
Expand Down
114 changes: 99 additions & 15 deletions Templates/Web/FullStack/Web.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,17 @@ public static class Web
"public", "readonly", "ref", "return", "sbyte", "sealed", "short", "sizeof", "stackalloc", "static", "string",
"struct", "switch", "this", "throw", "true", "try", "typeof", "uint", "ulong", "unchecked", "unsafe", "ushort",
"using", "virtual", "void", "volatile", "while",
// and TypeScript's, which the client's parameters can't be either
"delete", "export", "extends", "function", "import", "let", "super", "var", "with", "yield", "await",
// and TypeScript's, which the client's parameters can't be either (a module is strict: eval, arguments)
"delete", "export", "extends", "function", "import", "let", "super", "var", "with", "yield", "await", "debugger",
"instanceof", "implements", "package", "eval", "arguments",
};

// what a key's parameters are beside: the endpoints' other parameters and locals (db, request, environment, entity,
// problem), and the client's (request, row, and what its calls call: call, found, encodeURIComponent, undefined)
private static readonly HashSet<string> KeyNeighbours = new HashSet<string>
{
"db", "request", "environment", "entity", "problem", "routes", "group", "e",
"row", "call", "found", "query", "paged", "options", "list", "z", "undefined", "encodeURIComponent",
};

/// <summary>A table's endpoints: its DbSet's name in kebab case (LineItems: /api/line-items).</summary>
Expand All @@ -32,14 +41,88 @@ public static List<ColumnSchema> Key(TableSchema table) =>
? table.PrimaryKey.MemberColumns.Cast<MemberColumnSchema>().Select(c => table.Columns[c.Name]).ToList()
: new List<ColumnSchema>();

/// <summary>A key column's parameter, in C# and TypeScript: its property in camel case (OrderId: orderId).</summary>
public static string Parameter(ColumnSchema column)
/// <summary>A key column's parameter, in C# and TypeScript: its property in camel case (OrderId: orderId), with
/// Value after it where it's a keyword or a name the code around it has (class: classValue, db: dbValue), and a
/// number where another column's has it.</summary>
public static string Parameter(ColumnSchema column) => ParameterNames(column.Table).Parameters[column];

// A property in camel case, as the parameters have it (not JSON's: OrderID is orderID).
private static string Camel(ColumnSchema column)
{
string name = Names.Property(column);
name = char.ToLowerInvariant(name[0]) + name.Substring(1);
return Keywords.Contains(name) ? name + "Value" : name;
return char.ToLowerInvariant(name[0]) + name.Substring(1);
}

// The table's columns' parameters (Parameter) and filters (Filter), each once in the table; worked out once a table
// (a schema read again is new tables).
private static (Dictionary<ColumnSchema, string> Parameters, Dictionary<ColumnSchema, string> Filters) ParameterNames(TableSchema table) =>
TableParameters.GetValue(table, ParameterNamesOf).Names;

private sealed class TableNames
{
public (Dictionary<ColumnSchema, string>, Dictionary<ColumnSchema, string>) Names;
}

private static readonly System.Runtime.CompilerServices.ConditionalWeakTable<TableSchema, TableNames> TableParameters =
new System.Runtime.CompilerServices.ConditionalWeakTable<TableSchema, TableNames>();

private static TableNames ParameterNamesOf(TableSchema table)
{
var parameters = new Dictionary<ColumnSchema, string>();
var filters = new Dictionary<ColumnSchema, string>();
var parameterNames = new HashSet<string>();
var filterNames = new HashSet<string>(ListParameters);
string Once(string name, HashSet<string> taken)
{
string unique = name;
for (int i = 2; !taken.Add(unique); i++)
unique = name + i;
return unique;
}
foreach (ColumnSchema column in table.Columns)
{
string name = Camel(column);
parameters[column] = Once(Keywords.Contains(name) || KeyNeighbours.Contains(name) ? name + "Value" : name, parameterNames);
filters[column] = Once(ListParameters.Contains(name) ? name + "Filter" : Keywords.Contains(name) ? name + "Value" : name, filterNames);
}
return new TableNames { Names = (parameters, filters) };
}

// ---- the records' and their members' names ----

// FullStack's own names in a table's records (the response's From, the requests' ToEntity and ApplyTo, the records
// themselves): a column's property can't be one of its record's members, nor its record's name, so where one has
// it, the record's name or member gives way (From: FromEntity), as a navigation does; a number after that.
private static string Own(TableSchema table, params string[] names)
{
var taken = new HashSet<string>(Names.Columns(table).Select(Names.Property));
foreach (string name in names)
if (!taken.Contains(name))
return name;
string last = names[names.Length - 1];
for (int i = 2; ; i++)
if (!taken.Contains(last + i))
return last + i;
}

/// <summary>The record a row is returned as: ProductResponse (ProductResponseRecord where a column has that name).</summary>
public static string Response(TableSchema table) => Own(table, Names.Entity(table) + "Response", Names.Entity(table) + "ResponseRecord");

/// <summary>The record a new row is sent as: CreateProductRequest (or ...Record).</summary>
public static string CreateRequest(TableSchema table) => Own(table, "Create" + Names.Entity(table) + "Request", "Create" + Names.Entity(table) + "RequestRecord");

/// <summary>The record a row's changes are sent as: UpdateProductRequest (or ...Record).</summary>
public static string UpdateRequest(TableSchema table) => Own(table, "Update" + Names.Entity(table) + "Request", "Update" + Names.Entity(table) + "RequestRecord");

/// <summary>The response's factory from an entity: From (FromEntity where a column is named From).</summary>
public static string From(TableSchema table) => Own(table, "From", "FromEntity");

/// <summary>The new row's request's entity: ToEntity (CreateEntity where a column is named ToEntity).</summary>
public static string ToEntity(TableSchema table) => Own(table, "ToEntity", "CreateEntity");

/// <summary>What applies the changes to an entity: ApplyTo (ApplyToEntity where a column is named ApplyTo).</summary>
public static string ApplyTo(TableSchema table) => Own(table, "ApplyTo", "ApplyToEntity");

/// <summary>The key's route template: "{orderId}/{lineNum}".</summary>
public static string KeyRoute(TableSchema table) => string.Join("/", Key(table).Select(c => "{" + Parameter(c) + "}"));

Expand Down Expand Up @@ -80,8 +163,12 @@ public static string Validation(ColumnSchema column) =>
"macaddr", "interval", "bit varying", "varbit",
};

// the parameters a list has already, which a filter's name can't be
private static readonly HashSet<string> ListParameters = new HashSet<string> { "page", "pageSize", "sort", "desc", "search", "db", "rows" };
// the parameters a list has already, its locals (rows, pattern, total, items; e, its lambdas'), and the UI's list's
// own in its address (q, its search), which a filter's name can't be
private static readonly HashSet<string> ListParameters = new HashSet<string>
{
"page", "pageSize", "sort", "desc", "search", "db", "rows", "pattern", "isNumber", "number", "total", "items", "e", "q",
};

/// <summary>The column's database type, in lower case and without its size: varchar, numeric, text.</summary>
public static string Native(ColumnSchema column)
Expand Down Expand Up @@ -126,13 +213,10 @@ private static bool Referred(ColumnSchema column) =>
.Any(k => k.PrimaryKeyTable.Owner == column.Table.Owner && k.PrimaryKeyTable.Name == column.Table.Name &&
k.PrimaryKeyMemberColumns.Cast<MemberColumnSchema>().Any(m => m.Name == column.Name));

/// <summary>A filter's query parameter: the key's parameter name (productId), unless the list has one of that name
/// already (pageFilter).</summary>
public static string Filter(ColumnSchema column)
{
string name = Parameter(column);
return ListParameters.Contains(name) ? name + "Filter" : name;
}
/// <summary>A filter's query parameter: the column's property in camel case (productId), with Filter after it where
/// the list has one of that name already (pageFilter), Value where it's a keyword (classValue), and a number where
/// another column's has it.</summary>
public static string Filter(ColumnSchema column) => ParameterNames(column.Table).Filters[column];

/// <summary>Whether a column's C# type is a value type (int, not string): a nullable one is read with .Value.</summary>
public static bool IsValueType(ColumnSchema column) => Names.Type(column).TrimEnd('?') is not ("string" or "byte[]" or "object");
Expand Down
12 changes: 6 additions & 6 deletions Templates/Web/FullStack/client/src/app/kit/FormPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Value } from "./cells.tsx";
import { appName, resolve, tableNamed } from "./config.ts";
import { invalidateTable, useQuery } from "./data.ts";
import { FormField } from "./fields.tsx";
import { buildRequest, checkField, defaultFormValue, formFields, problemErrors, toFormValue } from "./form.ts";
import { buildRequest, checkField, defaultFormValue, fieldEntry, formFields, problemErrors, toFormValue } from "./form.ts";
import { keyFromParams, keyOf, keyText, rowLabel, rowPath, rowTitle } from "./format.ts";
import { Icon } from "./icons.tsx";
import { deleteRow, errorText } from "./ListPage.tsx";
Expand Down Expand Up @@ -44,7 +44,7 @@ function Form({ table, row }: { table: Table; row?: Row }) {

const dirty = fields.some((field) => values[field.name] !== initial[field.name]);
const checks = useMemo(() => Object.fromEntries(fields.map((field) => [field.name, checkField(field, values[field.name] ?? null)])), [fields, values]);
const errorOf = (field: Field) => server[field.name] ?? (tried || touched[field.name] ? checks[field.name] : undefined);
const errorOf = (field: Field) => fieldEntry(server, field.name) ?? (tried || fieldEntry(touched, field.name) ? checks[field.name] : undefined);
const wrong = fields.filter((field) => errorOf(field)).length;
const required = fields.filter((field) => field.required);
const filled = required.filter((field) => {
Expand All @@ -66,7 +66,7 @@ function Form({ table, row }: { table: Table; row?: Row }) {

const change = (field: Field, value: FormValue) => {
setValues((current) => ({ ...current, [field.name]: value }));
if (server[field.name]) setServer(({ [field.name]: _, ...rest }) => rest);
if (fieldEntry(server, field.name)) setServer(({ [field.name]: _, ...rest }) => rest);
};

const back = row ? rowPath(table, row) : `/${table.name}`;
Expand All @@ -78,7 +78,7 @@ function Form({ table, row }: { table: Table; row?: Row }) {
setProblem(undefined);
const built = buildRequest(table, editing, values);
if (!built.request) {
const first = fields.find((field) => built.errors[field.name]);
const first = fields.find((field) => fieldEntry(built.errors, field.name));
if (first) document.getElementById(`field-${table.name}-${first.name}`)?.focus();
return;
}
Expand All @@ -103,7 +103,7 @@ function Form({ table, row }: { table: Table; row?: Row }) {
// a row that isn't there), and above the form
const mapped = problemErrors(table, details.errors);
setServer(mapped.fields);
const first = fields.find((field) => mapped.fields[field.name]);
const first = fields.find((field) => fieldEntry(mapped.fields, field.name));
if (first) document.getElementById(`field-${table.name}-${first.name}`)?.focus();
setProblem({ title: details.title ?? "The database refused the change.", detail: details.detail, database: details.database });
} else if (details?.errors) {
Expand Down Expand Up @@ -161,7 +161,7 @@ function Form({ table, row }: { table: Table; row?: Row }) {
<div className="form-layout">
<form className="form" onSubmit={submit} noValidate onBlur={(event) => {
const name = (event.target as HTMLElement).id?.replace(`field-${table.name}-`, "");
if (name && fields.some((field) => field.name === name)) setTouched((current) => (current[name] ? current : { ...current, [name]: true }));
if (name && fields.some((field) => field.name === name)) setTouched((current) => (fieldEntry(current, name) ? current : { ...current, [name]: true }));
}}>
{keyFields.length > 0 && (
<Card title="Key" icon="key" className="form-section">
Expand Down
Loading