Skip to content

feat(gen): membership-scope access for AppSpec entities - #53

Merged
yyyyaaa merged 2 commits into
mainfrom
feat/scoped-access
Nov 17, 2026
Merged

yyyyaaa merged 2 commits into
mainfrom
feat/scoped-access

Conversation

@yyyyaaa

@yyyyaaa yyyyaaa commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

Lets a custom entity's rows belong to a membership scope, and fixes two gen gaps that scoped apps hit. Desktop provisions the policies (constructive-io/constructive-desktop#287); gen only renders.

"entities": [
  { "name": "vendors", "access": { "scope": "org" } },          // the active workspace's organization
  { "name": "units", "access": { "scope": "properties" },       // an entity type's entity, by its key
    "belongsTo": [{ "field": "property_id", "to": "propertys" }] }
]
  • Contract: access takes "shared", "private" or { "scope": "<scope>" } (SpecAccess in app-spec.types.ts, a oneOf in app-spec.schema.json). Desktop syncs both files and validates specs against them.
  • Entity-type tables: manage_entity_types names the table with the prefix plus "s" (propertys), and the API inflects it as properties. applySpec now also matches _meta's tableName, so the table's label, nav and panels apply instead of becoming a gap.
  • Scoped links: a link to a scoped row carries the entity a trigger copies from one side. The API takes no value for that column on create (isWritableOnCreate: false), so it no longer turns the link into an entity of its own. The link stays a junction, with the link editor on both sides.

🤖 Generated with Claude Code

https://claude.ai/code/session_017WbsGACCtSUb8SqXaydeYJ

A custom entity's access can now be { "scope": "<scope>" }: each row belongs to one entity of that membership scope, and only its members see it. "org" puts a row in an organization (the active workspace); an entity type's scope needs a key to its table, or to a table with the same access, which the row's entity is copied from. The desktop validates specs against this schema and provisions the policies; gen doesn't read a table's access.
…er-filled links as junctions

manage_entity_types names an entity type's table with the prefix plus "s" (propertys), and the API inflects it to another plural (properties). The spec names the SQL table, so applySpec now matches `_meta`'s tableName too; before, the table's label, nav and panels were dropped as a gap.

A link to a scoped row carries the entity its trigger copies from a side. The API takes no value for that column on create, so it no longer makes the link an entity of its own: it stays a junction, with the link editor on both sides.
@luxor-code-review

luxor-code-review Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Review complete. 🟡 1 medium

📍 Findings outside the diff (1) — 🟡 1 medium — defects on lines GitHub can't attach comments to

🟡 Medium — Scoped access accepted but never resolved, validated, or consumed · app-spec.ts:121–130 · unchanged line

// shared/gen/app-spec.ts
121		for (const entity of entities) {
122			const ir = findResource(entity.name);
123			if (!ir) {
124				gap(entitiesPath, entity.name, `AppSpec entity "${entity.name}" is not in _meta.`);
125				continue;
126			}
127			if (entity.label) ir.label = entity.label;
128			const path = `${entitiesPath}.${entity.name}`;
129			refineTable(ir, entity.fields, entity.belongsTo ?? [], { fields: `${path}.fields`, belongsTo: `${path}.belongsTo` });
130		}

The schema and SpecAccess type now accept access: { "scope": "<name>" } on an entity (shared/gen/app-spec.schema.json:157-166, shared/gen/app-spec.types.ts:36), declaring that only members of the scope's entity see each row — but applySpec never reads entity.access at all (shared/gen/app-spec.ts:121-130), so the form is inert. Unlike every other spec key that names something, the scope name is never checked against the model: only the schema's scopeName pattern validates its spelling, so a typo like {"scope": "orgs"} passes validation and produces no gap or warning. An app author declaring a scoped access gets no restriction from this generator and no error for an unresolvable scope, silently falling back to the shared default.

🧹 Nitpicks (1) — 🟢 1 low
  • 🟢 TS SpecAccess type omits the schema's scope name pattern (app-spec.types.ts:36) — SpecAccess = 'shared' | 'private' | { scope: string } (shared/gen/app-spec.types.ts:36) permits any string as the scope, while the schema's scopeName ref requires ^[a-z][a-z0-9]*(_[a-z0-9]+)*$ (shared/gen/app-spec.schema.json:43-48).

This PR extends the generated app-spec schema and types so access may be either a boolean or a { scope: string } object, and updates meta-ir junction classification and resource-name matching to handle non-writable-on-create columns and tableName-based lookups. Tests cover the new scoped access form.

Files Change
shared/gen/app-spec.schema.json Adds a oneOf branch for a scoped access object with a pattern-validated scope name.
shared/gen/app-spec.types.ts Widens the SpecAccess type to include the { scope } object form.
shared/gen/meta-ir.ts Classifies junctions using non-writable-on-create columns; refines resource name matching.
shared/gen/app-spec.ts findResource now matches tableName with an undefined guard.
shared/gen/__tests__/meta-ir.test.ts Adds tests for the scoped access and matching behavior.

Reviewed commit: 96c6f08

@yyyyaaa
yyyyaaa merged commit 63a06bd into main Nov 17, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant