Skip to content

Commit dc0bee0

Browse files
dmealingclaude
andcommitted
feat(#207): register projection row-scope @filter across all five ports
Register an optional @filter attribute on object.projection — a portable attr.filter object (eq/ne/gt/gte/lt/lte/like/in/isNull with and/or) that selects which rows a derived view returns, lowered to an outer SQL WHERE. Placement mirrors origin.aggregate's @filter exactly (a filter-subtype attr on the object, since the predicate is a LOGICAL derivation — it must survive non-RDB lowerings), and is registered on object.projection ONLY, so a write-through entity read-view can never carry one (a filtered replica would break read-your-writes totality; v1 scope: projections only). Registered + registry-conformance byte-matched in all five ports (TS / C# / Java / Python / Kotlin — Kotlin rides Java's registry). Each JVM/dotnet/python port registers the attr in code and (C#/Python) syncs its committed SpecMetamodel copy; strict per-subtype attr scoping then keeps @filter on projection while pruning the discriminator attrs it does not declare. A new fixtures/conformance/projection-filter corpus fixture proves the attr loads + canonical-serializes identically everywhere (and exercises it for the registry-coverage ratchet). Regenerated the embedded metamodel, the canonical registry manifest, and the metamodel docs. The TS extraction + WHERE lowering + fail-closed validation land next; this commit is the coordinated cross-port registration half. Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_01NGQ7oSuNcjhsMHWwZzhBwr
1 parent fab61cc commit dc0bee0

18 files changed

Lines changed: 251 additions & 12 deletions

File tree

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
{
2+
"metadata.root": {
3+
"package": "demo",
4+
"children": [
5+
{
6+
"object.entity": {
7+
"name": "Order",
8+
"children": [
9+
{
10+
"source.rdb": {
11+
"@table": "orders"
12+
}
13+
},
14+
{
15+
"field.uuid": {
16+
"name": "id"
17+
}
18+
},
19+
{
20+
"field.string": {
21+
"name": "status"
22+
}
23+
},
24+
{
25+
"identity.primary": {
26+
"name": "id",
27+
"@fields": [
28+
"id"
29+
]
30+
}
31+
}
32+
]
33+
}
34+
},
35+
{
36+
"object.projection": {
37+
"name": "ActiveOrders",
38+
"@filter": {
39+
"status": {
40+
"ne": "archived"
41+
}
42+
},
43+
"children": [
44+
{
45+
"source.rdb": {
46+
"@kind": "view",
47+
"@view": "v_active_orders"
48+
}
49+
},
50+
{
51+
"field.uuid": {
52+
"name": "id",
53+
"extends": "demo::Order.id",
54+
"@column": "id"
55+
}
56+
},
57+
{
58+
"field.string": {
59+
"name": "status",
60+
"extends": "demo::Order.status"
61+
}
62+
},
63+
{
64+
"identity.primary": {
65+
"name": "id",
66+
"extends": "demo::Order.id"
67+
}
68+
}
69+
]
70+
}
71+
}
72+
]
73+
}
74+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"metadata.root": {
3+
"package": "demo",
4+
"children": [
5+
{
6+
"object.entity": {
7+
"name": "Order",
8+
"children": [
9+
{ "source.rdb": { "@table": "orders" } },
10+
{ "field.uuid": { "name": "id" } },
11+
{ "field.string": { "name": "status" } },
12+
{ "identity.primary": { "name": "id", "@fields": ["id"] } }
13+
]
14+
}
15+
},
16+
{
17+
"object.projection": {
18+
"name": "ActiveOrders",
19+
"@filter": { "status": { "ne": "archived" } },
20+
"children": [
21+
{ "source.rdb": { "@kind": "view", "@view": "v_active_orders" } },
22+
{ "field.uuid": { "name": "id", "extends": "demo::Order.id", "@column": "id" } },
23+
{ "field.string": { "name": "status", "extends": "demo::Order.status" } },
24+
{ "identity.primary": { "name": "id", "extends": "demo::Order.id" } }
25+
]
26+
}
27+
}
28+
]
29+
}
30+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
["metaobjects-core-types", "metaobjects-db"]

‎fixtures/metamodel-docs/expected/providers.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ Core metaobjects metamodel types and subtypes.
2828
- `identity.reference`: `@enforce`, `@fields`, `@references`
2929
- `identity.secondary`: `@fields`
3030
- `object.entity`: `@discriminator`, `@discriminatorValue`
31+
- `object.projection`: `@filter`
3132
- `origin.aggregate`: `@agg`, `@distinct`, `@filter`, `@of`, `@orderBy`, `@via`
3233
- `origin.collection`: `@via`
3334
- `origin.computed`: `@expr`

‎fixtures/metamodel-docs/expected/types/object.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ A derived read-only representation of entities. Its fields are extends-bound / o
6969

7070
**Attributes**
7171

72-
_No subtype-specific attributes._
72+
| Attribute | Type | Required | Default | Allowed values | Provider | Description |
73+
| --- | --- | --- | --- | --- | --- | --- |
74+
| `@filter` | filter | no | | | metaobjects-core-types | Optional row-scope predicate (a portable attr.filter object: eq/ne/gt/gte/lt/lte/like/in/isNull with and/or, desugared to { field: { op: value } } at parse time) selecting which rows the view returns — lowered to an outer SQL WHERE. Resolves against the projection's own declared fields; an aggregate-derived field is not addressable (fail-closed). |
7375

7476
**Allowed children**
7577

‎fixtures/registry-conformance/expected-registry.json‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2959,7 +2959,15 @@
29592959
"description": "A derived read-only representation of entities. Its fields are extends-bound / origin-derived / self-declared-under-external-assembly, all read-only at the subtype level. Identity is optional and MUST extend an entity identity; sources are restricted to read-only @kinds. The declared field set IS the exposure (inclusive, fail-closed).",
29602960
"rules": "object.projection is a derived read-only representation: every field is extends-bound, origin-derived, or self-declared-under-external-assembly, and all are read-only at the subtype level. Identity is optional and, when present, MUST extend an entity identity. Sources are restricted to read-only @kinds. The declared field set IS the exposure — an inclusive list, fail-closed. A projection NEVER declares relationships (derivation is expressed via @via, not a relationship child) and NEVER co-locates templates — hence its child set omits both relationship and template. See ADR-0028 (object taxonomy, projection).",
29612961
"whenToUse": "You need a derived, read-only view over entities — a report, summary, or joined/aggregated read model. Declare it (with origin.* children) instead of hand-writing the SELECT/joins; it stays read-only and regenerates.",
2962-
"attrs": [],
2962+
"attrs": [
2963+
{
2964+
"name": "filter",
2965+
"valueType": "filter",
2966+
"isArray": false,
2967+
"required": false,
2968+
"description": "Optional row-scope predicate (a portable attr.filter object: eq/ne/gt/gte/lt/lte/like/in/isNull with and/or, desugared to { field: { op: value } } at parse time) selecting which rows the view returns — lowered to an outer SQL WHERE. Resolves against the projection's own declared fields; an aggregate-derived field is not addressable (fail-closed)."
2969+
}
2970+
],
29632971
"children": [
29642972
{
29652973
"childType": "field",

‎server/csharp/MetaObjects/Core/Object/ObjectConstants.cs‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,19 @@ public static class ObjectConstants
4545
/// </summary>
4646
public const string OBJECT_ATTR_DISCRIMINATOR_VALUE = "discriminatorValue";
4747

48+
// -----------------------------------------------------------------------
49+
// #207 — projection row-scope @filter (view-level WHERE)
50+
// -----------------------------------------------------------------------
51+
52+
/// <summary>
53+
/// #207: an optional row-scope predicate on an object.projection (an attr.filter
54+
/// object — the same subType origin.aggregate's @filter uses) selecting which rows
55+
/// the derived view returns; lowered to an outer SQL WHERE. Mirrors
56+
/// origin.aggregate's @filter placement (attr.filter subType), optional (min 0 /
57+
/// max 1). Mirrors TS OBJECT_PROJECTION_ATTR_FILTER.
58+
/// </summary>
59+
public const string OBJECT_PROJECTION_ATTR_FILTER = "filter";
60+
4861
public static readonly string[] OBJECT_SUBTYPES =
4962
[
5063
BaseTypes.SUBTYPE_BASE,

‎server/csharp/MetaObjects/Core/Object/ObjectSchema.cs‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,25 @@ public static class ObjectSchema
3838
"string) controls codegen + storage coercion. Required on every concrete " +
3939
"subtype of a discriminated entity."),
4040
];
41+
42+
/// <summary>
43+
/// #207 — the optional row-scope @filter on an object.projection (a portable
44+
/// attr.filter object, the same subType origin.aggregate's @filter uses). Selects
45+
/// which rows the derived view returns; lowered to an outer SQL WHERE. Registered
46+
/// ONLY on object.projection (see CoreTypes); the description is single-sourced
47+
/// from spec/metamodel/object.json via ApplySpecDescriptions, so this text is a
48+
/// fallback that already matches the canonical.
49+
/// </summary>
50+
public static readonly AttrSchema ProjectionFilterAttr =
51+
new AttrSchema(
52+
Name: ObjectConstants.OBJECT_PROJECTION_ATTR_FILTER,
53+
ValueType: AttrConstants.ATTR_SUBTYPE_FILTER,
54+
Required: false,
55+
Description:
56+
"Optional row-scope predicate (a portable attr.filter object: " +
57+
"eq/ne/gt/gte/lt/lte/like/in/isNull with and/or, desugared to " +
58+
"{ field: { op: value } } at parse time) selecting which rows the view " +
59+
"returns — lowered to an outer SQL WHERE. Resolves against the " +
60+
"projection's own declared fields; an aggregate-derived field is not " +
61+
"addressable (fail-closed).");
4162
}

‎server/csharp/MetaObjects/CoreTypes.cs‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,13 @@ private static void RegisterCoreTypeDefs(TypeRegistry registry)
254254
// mode for its enum fields' tolerant extract) is re-homed to the
255255
// metaobjects-prompt concern provider (reads prompt.json's object.value
256256
// extends), so core no longer appends it here.
257-
List<AttrSchema> objectAttrs = ObjectSchema.ObjectAttrs.ToList();
257+
// #207: object.projection additionally carries the row-scope @filter (an
258+
// attr.filter object lowered to a view-level WHERE). Strict attr scoping
259+
// (from spec object.json's projection allow-list) keeps it here and prunes
260+
// the discriminator attrs, which projection does not declare.
261+
List<AttrSchema> objectAttrs = subType == OBJECT_SUBTYPE_PROJECTION
262+
? [.. ObjectSchema.ObjectAttrs, ObjectSchema.ProjectionFilterAttr]
263+
: ObjectSchema.ObjectAttrs.ToList();
258264

259265
List<ChildRule> rules = subType == OBJECT_SUBTYPE_PROJECTION
260266
? new List<ChildRule>(projectionRules)

‎server/csharp/MetaObjects/SpecMetamodel/object.json‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@
4545
"extendsBase": true,
4646
"description": "A derived read-only representation of entities. Its fields are extends-bound / origin-derived / self-declared-under-external-assembly, all read-only at the subtype level. Identity is optional and MUST extend an entity identity; sources are restricted to read-only @kinds. The declared field set IS the exposure (inclusive, fail-closed).",
4747
"whenToUse": "You need a derived, read-only view over entities — a report, summary, or joined/aggregated read model. Declare it (with origin.* children) instead of hand-writing the SELECT/joins; it stays read-only and regenerates.",
48-
"rules": "object.projection is a derived read-only representation: every field is extends-bound, origin-derived, or self-declared-under-external-assembly, and all are read-only at the subtype level. Identity is optional and, when present, MUST extend an entity identity. Sources are restricted to read-only @kinds. The declared field set IS the exposure — an inclusive list, fail-closed. A projection NEVER declares relationships (derivation is expressed via @via, not a relationship child) and NEVER co-locates templates — hence its child set omits both relationship and template. See ADR-0028 (object taxonomy, projection)."
48+
"rules": "object.projection is a derived read-only representation: every field is extends-bound, origin-derived, or self-declared-under-external-assembly, and all are read-only at the subtype level. Identity is optional and, when present, MUST extend an entity identity. Sources are restricted to read-only @kinds. The declared field set IS the exposure — an inclusive list, fail-closed. A projection NEVER declares relationships (derivation is expressed via @via, not a relationship child) and NEVER co-locates templates — hence its child set omits both relationship and template. See ADR-0028 (object taxonomy, projection).",
49+
"children": [
50+
{ "type": "attr", "subType": "filter", "name": "filter", "min": 0, "max": 1, "description": "Optional row-scope predicate (a portable attr.filter object: eq/ne/gt/gte/lt/lte/like/in/isNull with and/or, desugared to { field: { op: value } } at parse time) selecting which rows the view returns — lowered to an outer SQL WHERE. Resolves against the projection's own declared fields; an aggregate-derived field is not addressable (fail-closed)." }
51+
]
4952
}
5053
]
5154
}

0 commit comments

Comments
 (0)