Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
41 changes: 26 additions & 15 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,13 +184,20 @@ Each item below is described in full under Security, Added, Changed or Fixed; th
the same way under any policy. Only single-word credentials, or a host with the default
camelCase policy and no rename, were safe. 1.3.0 fixes it: the omit list and the PATCH and PUT
key lookup read the key from the serializer's own contract (`JsonSerializerOptions.GetTypeInfo`),
so a naming policy, a rename or an attribute cannot escape them. Stripping **fails closed**: when
the contract cannot be read (a custom converter for the row type, a custom type-info resolver or a
so a naming policy, a rename or an attribute cannot escape them. What is stripped, exactly: each
top-level credential property of the entity (and, on a TPH route, of every subtype), under the key
the host's serializer writes for it, from the single row of a read, create, PATCH or PUT response,
from each row of a list or M:N response, from each row under the `rows` key of a `?withCount=`
`{ rows, total }` envelope, and from each row of the JSON report export. The envelope's own
`rows` key is read from the same contract, so an upper-case policy (`ROWS`) on a host that sets
`PropertyNameCaseInsensitive = false` is stripped too. A key in those rows that spells the
credential ignoring case, `_` and `-` is also removed. Stripping **fails closed**: when the
contract cannot be read (a custom converter for the row type, a custom type-info resolver or a
modifier that leaves a property without its reflection member, a contract that lacks the
credential), the generated route mapping throws at startup, and a response that reaches
`CredentialOmittingResult` anyway is refused with an exception naming the type and the credential
property (never a value), instead of being sent unstripped. A key that spells the credential
ignoring case, `_` and `-` is also removed. A host that sets a custom `TypeInfoResolver` or a
`CredentialOmittingResult` anyway (or an envelope whose `rows` key or array cannot be found) is
refused with an exception naming the type and the credential property (never a value), instead
of being sent unstripped. A host that sets a custom `TypeInfoResolver` or a
source-generated `JsonSerializerContext` must give the entity properties their reflection member
(the default reflection resolver does), or the app will not start. The write side of the released
1.2.0, 1.2.2 and 1.2.3 was not exploitable: a PATCH or PUT body key that missed the deny list also missed
Expand Down Expand Up @@ -294,7 +301,9 @@ Each item below is described in full under Security, Added, Changed or Fixed; th
- the loaders refuse what a view cannot lower: a `now` whose value is not an ISO-8601 duration
or whose `startOf` is not day, week or month (`error-origin-computed-now-bad-duration`); a
searched `case` whose `when` is not boolean (`error-origin-computed-case-non-boolean-when`);
computed fields that refer to each other in a cycle (`error-origin-computed-cycle`); and a
computed fields that refer to each other in a cycle (`error-origin-computed-cycle`), and a
computed field that reads its own name, which loaded before and is now `ERR_INVALID_ORIGIN` at
load (it never lowered to valid SQL; `meta gen` recursed on it until the stack ran out); and a
malformed relative date in a view host's `@filter` (`error-relative-date-view-host-malformed`),
or one on a field that is not a `field.date` or `field.timestamp`, where a projection's key
names its own field and an origin's names a field of its `@of` entity or `@via` terminal
Expand Down Expand Up @@ -1396,13 +1405,14 @@ Each item below is described in full under Security, Added, Changed or Fixed; th
metadata package builds its sandbox under `$DEV_SCRATCH` (the system temp directory when unset)
and stops its test runners with it. Contributor steps are in [CONTRIBUTING.md](CONTRIBUTING.md).

- **Behaviour change, C#: with a property rename beyond case, the accepted `?sort=` key is the
resolved property name (rc.22).** The sort allowlist, `@sortableDefaultOrder` keys and the
- **Fix, C#: with a property rename beyond case, `?sort=` accepts the field name and the resolved
property name (rc.22).** The sort allowlist, `@sortableDefaultOrder` keys and the
`EF.Property` names carry the resolved name (EF matches the model's property name, so before
this any rename made a sort return 500). A project with no resolver, or one whose rename differs
only in case, is unchanged (the key is matched case-insensitively). With `ownerRef` spelled
`OwnerKey`, `?sort=ownerRef` becomes `400 invalid_sort` and `?sort=OwnerKey` is accepted.
`?filter[<field>]` keeps the field name.
this any rename made a sort return 500). With a rename beyond case the allowlist also accepts the
field name, the key `?filter[<field>]` takes, so a client built from the metadata's field names
sorts and filters with the same key. A project with no resolver, or one whose rename differs only
in case, is unchanged (the key is matched case-insensitively). With `ownerRef` spelled `OwnerKey`,
`?sort=ownerRef` and `?sort=OwnerKey` both sort by it.

- **Behaviour change, C#: a `PropertyName` hook that disagrees with `GenConfig.PropertyNaming` is
refused (rc.22).** `EntityGenerator.PropertyName` and `DbContextGenerator.PropertyName` default to
Expand Down Expand Up @@ -2188,9 +2198,10 @@ Each item below is described in full under Security, Added, Changed or Fixed; th
entry splitting the model declared all of them (`CS0101` where two outputs build together). A
narrowed entry now declares only the enums used by the objects it accepts and the value objects it
emits beyond them, and an enum several entries use is declared by one: the entry that emits its
first consumer by resolution key. Each entry reaches that answer from the model alone, in its own
run. An enum whose first consumer no entry emits is declared by none; give that object an entry,
or use an un-narrowed entry, which declares every enum as before. Placing an enum in a project of
first consumer by resolution key. Each entry reaches that answer in its own run, from the model and
the run's entry list: an entry leaves the enum to another only when another `EntityGenerator`
entry of the same run accepts that first consumer, and declares it itself otherwise, so a single
narrowed entry still builds on its own. An un-narrowed entry declares every enum, as before. Placing an enum in a project of
its own choosing is G3, not built.

- **Fix, TypeScript docs: an identity reference's target links to its page (G4).** The Identity
Expand Down
5 changes: 5 additions & 0 deletions docs/CONFORMANCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,11 @@ canonical (`fixtures/registry-conformance/expected-registry.json`).
- `view.image`, and its `@accept`, `@aspectRatio`, `@maxBytes`, `@maxEdge`, `@store`
- *Implemented in Java only* (`implementedIn: ["java"]`): `object.* @object` (ADR-0001), the
native class an object binds to. Java's runtime acts on it; Java's own behaviour is unchanged.
- *Implemented in TypeScript and C#* (`implementedIn: ["typescript", "csharp"]`): the rc.21
view vocabulary — `origin.function` and the `object.projection` attrs `@union`, `@unionAll`,
`@grain`, `@grainOrdinal`. The TypeScript view emitter lowers them; the C# loader validates
them (mirroring the TypeScript checks message for message); the other ports load them strictly
and do not act on them yet.
- *Loads strictly in every port.* Each port registers the `metaobjects-ui-web` provider
(`view.textarea @rows`, the `view.image` attrs) and `@object` / `@objectAdapter` on
`object.*`, loads all three fixtures strictly, and emits `implementedIn` in its manifest, which
Expand Down
7 changes: 5 additions & 2 deletions docs/ports/csharp.md
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,11 @@ and sits in its package's namespace. An extract-tier private mapper may carry th
member name (`FromAcmeAlphaNoteExtracted`), because it is private to its class.
Each package's shared enum is its own `<package>/<Enum>.g.cs` under the package layout, with its
`@intValueMap` integers as member values and `@description` as its XML doc; the flat layout keeps
the one `Enums.g.cs`. An entry narrowed with `Include` declares only the shared enums it uses, and
an enum several narrowed entries use is declared by exactly one of them.
the one `Enums.g.cs`. An entry narrowed with `Include` leaves a shared enum to another `entity`
entry of the same run only when that entry accepts the enum's home object (its first consumer by
resolution key), and declares the enum itself otherwise — so a single narrowed entry declares
every enum its objects use and its output builds on its own, and an enum several narrowed entries
use is still declared by exactly one of them.

With that, `dotnet meta gen` writes there, `dotnet meta verify --codegen` diffs against it, and
a plain `dotnet meta verify` in CI runs the codegen gate with no flags. `--out <dir>` still works
Expand Down
2 changes: 2 additions & 0 deletions fixtures/metamodel-docs/expected/types/origin.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ A value computed by a database function the project owns (rc.21): @function name

**Owning provider:** metaobjects-core-types

**Implemented in:** csharp, typescript so far — every port loads and type-checks it; the others do not act on it yet.

**When to use:** A view column is the result of a function the database already holds (a PL/pgSQL state machine, a legacy computation) and cannot be expressed in @expr. Declare the call instead of hand-writing the view's @sql.

**Attributes**
Expand Down
20 changes: 20 additions & 0 deletions fixtures/registry-conformance/expected-registry.json
Original file line number Diff line number Diff line change
Expand Up @@ -3607,13 +3607,21 @@
"valueType": "string",
"isArray": false,
"required": false,
"implementedIn": [
"csharp",
"typescript"
],
"description": "rc.21: the view has one row per element of this base-entity field, a field.object array stored as jsonb; a base row with no element has no row. A field whose origin.passthrough @from names the field's @objectRef value object (Address.city) reads that member of the element; the base's own fields read the parent row as usual. An origin.aggregate is refused on such a projection."
},
{
"name": "grainOrdinal",
"valueType": "string",
"isArray": false,
"required": false,
"implementedIn": [
"csharp",
"typescript"
],
"description": "rc.21: with @grain, the name of a field.int or field.long of this projection (with no origin) that holds the element's 1-based position in the array."
},
{
Expand Down Expand Up @@ -3642,13 +3650,21 @@
"valueType": "string",
"isArray": true,
"required": false,
"implementedIn": [
"csharp",
"typescript"
],
"description": "rc.21: the view is this projection's rows UNIONed with each named projection's rows. Each named projection has the same effective fields as this one, in order: names, subtypes, array-ness and physical column names (ERR_BAD_ATTR_VALUE otherwise); its own @filter, joins and base apply to its rows. Usually this projection extends one branch and names the others. A named projection may be abstract and sourceless."
},
{
"name": "unionAll",
"valueType": "boolean",
"isArray": false,
"required": false,
"implementedIn": [
"csharp",
"typescript"
],
"description": "rc.21: with @union, keep duplicate rows (UNION ALL). Absent or false: duplicates are removed (UNION), SQL's own default."
}
],
Expand Down Expand Up @@ -4052,6 +4068,10 @@
{
"type": "origin",
"subType": "function",
"implementedIn": [
"csharp",
"typescript"
],
"description": "A value computed by a database function the project owns (rc.21): @function names it, @schema its schema (absent: public), and @args the fields passed to it, in order. On an entity an argument is one of its fields; on a projection, one of its own fields (not an aggregate) or a field of its base entity. @params declares each argument's type and @returns the result's: an argument must have its parameter's type (cast it through an origin.computed field otherwise), @returns must be the carrying field's subtype, and the view casts the call to the field's full column type (the one its table column would have: length or @dbColumnType spelling, precision and scale, a local or zoned timestamp), so the call is checked, never free SQL. The signature is a declaration: meta verify --db reads the function from pg_proc and fails on a parameter or return type that differs. MetaObjects never creates the function: it is owned SQL, created before the view. Declared on an entity, it is entity-derived: a projection reaching the entity reads it like any derived field. Postgres only; the SQLite view emitter refuses it.",
"whenToUse": "A view column is the result of a function the database already holds (a PL/pgSQL state machine, a legacy computation) and cannot be expressed in @expr. Declare the call instead of hand-writing the view's @sql.",
"attrs": [
Expand Down
30 changes: 27 additions & 3 deletions server/csharp/MetaObjects.Codegen.Tests/GeneratorIncludeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,13 +187,15 @@ public void An_enum_both_narrowed_entries_use_is_declared_once()
var r = new MetaDataLoader().Load([new InMemoryStringSource(BothUse, id: "both.json")]);
Assert.Empty(r.Errors);
// One run, one claim registry, as two entries of one generator list share.
var orderEntry = new EntityGenerator { Include = o => o.Name is "Order" };
var customerEntry = new EntityGenerator { Include = o => o.Name is "Customer" };
var ctx = new GenContext
{
Entities = r.Root.Objects(), Root = r.Root,
Entities = r.Root.Objects(), Root = r.Root, Generators = [orderEntry, customerEntry],
Config = new GenConfig { OutDir = "/tmp", Namespace = "Acme.Generated", OutputLayout = OutputLayout.Package, PackageNamespacesFromMetadata = true },
};
var orders = new EntityGenerator { Include = o => o.Name is "Order" }.Generate(ctx).ToList();
var customers = new EntityGenerator { Include = o => o.Name is "Customer" }.Generate(ctx).ToList();
var orders = orderEntry.Generate(ctx).ToList();
var customers = customerEntry.Generate(ctx).ToList();
// Customer sorts first (acme::Customer < acme::Order), so its entry declares Level.
Assert.Contains(customers, f => f.Path.EndsWith("Level.g.cs", StringComparison.Ordinal));
Assert.DoesNotContain(orders, f => f.Path.EndsWith("Level.g.cs", StringComparison.Ordinal));
Expand All @@ -204,5 +206,27 @@ public void An_enum_both_narrowed_entries_use_is_declared_once()
// Un-narrowed, it is declared as before.
Assert.Single(new EntityGenerator().Generate(ctx), f => f.Path.EndsWith("Level.g.cs", StringComparison.Ordinal));
}
// B2: a single narrowed entry whose Include does not accept the enum's home (Customer) still declares
// the enum, because no other entry of the run will; its output builds on its own.
[Theory]
[InlineData(true)]
[InlineData(false)]
public void A_single_narrowed_entry_declares_a_shared_enum_whose_home_it_does_not_emit(bool listed)
{
var r = new MetaDataLoader().Load([new InMemoryStringSource(BothUse, id: "both.json")]);
Assert.Empty(r.Errors);
var orderEntry = new EntityGenerator { Include = o => o.Name is "Order" };
// Another kind of entry accepting the home does not declare entity enums, so it does not count.
var routes = new RoutesGenerator { Include = o => o.Name is "Customer" };
var ctx = new GenContext
{
Entities = r.Root.Objects(), Root = r.Root, Generators = listed ? [orderEntry, routes] : [],
Config = new GenConfig { OutDir = "/tmp", Namespace = "Acme.Generated", OutputLayout = OutputLayout.Package, PackageNamespacesFromMetadata = true },
};
var orders = orderEntry.Generate(ctx).ToList();
Assert.Single(orders, f => f.Path.EndsWith("Level.g.cs", StringComparison.Ordinal));
var errors = PackageNamespaceTests.CompileErrors(orders);
Assert.True(errors.Count == 0, "a single narrowed entry's output should build on its own, but got:\n" + string.Join("\n", errors));
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 12 additions & 7 deletions server/csharp/MetaObjects.Codegen.Tests/PackageKeyedOutputTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,18 @@ private static MetaRoot SharedEnumModel() => Load("""
public void An_enum_used_by_several_narrowed_entries_is_declared_by_exactly_one_of_them()
{
var root = SharedEnumModel();
var ctx = Ctx(root, package: false);
string[] Declared(Func<MetaObject, bool> include) =>
new EntityGenerator { Include = include }.Generate(ctx).Where(f => f.Path == "Enums.g.cs").Select(f => f.Path).ToArray();

var withAccount = Declared(o => o.Name == "Account");
var withPlan = Declared(o => o.Name == "Plan");
var withOther = Declared(o => o.Name == "Other");
// The three entries of one run: each sees the others through the run's entry list.
var account = new EntityGenerator { Include = o => o.Name == "Account" };
var plan = new EntityGenerator { Include = o => o.Name == "Plan" };
var other = new EntityGenerator { Include = o => o.Name == "Other" };
var flat = Ctx(root, package: false);
var ctx = new GenContext { Entities = flat.Entities, Root = flat.Root, Config = flat.Config, Generators = [account, plan, other] };
string[] Declared(EntityGenerator entry) =>
entry.Generate(ctx).Where(f => f.Path == "Enums.g.cs").Select(f => f.Path).ToArray();

var withAccount = Declared(account);
var withPlan = Declared(plan);
var withOther = Declared(other);

Assert.Equal(1, withAccount.Length + withPlan.Length);
Assert.Empty(withOther);
Expand Down
Loading
Loading