Skip to content
Open
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
9 changes: 9 additions & 0 deletions .changeset/nav-platform-object-requires-object.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"@objectstack/spec": patch
"@objectstack/platform-objects": patch
---

Clause-②: no
Metadata-protocol: none

An app menu entry naming a platform object the stack does not declare (`sys_task`, `sys_note`, or any `sys_`/`cloud_`/`ai_` name) is still refused by `defineStack` / `os validate`, but the refusal now names the fix: add `requiresObject: '<name>'` to the entry (the menu hides it wherever the object is not registered) and do not declare a copy of the object in the package. A name without a platform prefix keeps the old message. The `sys_task` and `sys_note` docblocks now teach the menu entry with `requiresObject`.
7 changes: 7 additions & 0 deletions packages/platform-objects/src/work/sys-note.object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ import { ObjectSchema, Field } from '@objectstack/spec/data';
* customizable object — an organization adds fields and views — and comments
* and attachments work on it as on any record.
*
* Every environment carries it, so an app puts notes in its menu with a
* navigation entry naming it instead of declaring its own note object:
* `{ type: 'object', objectName: 'sys_note', requiresObject: 'sys_note' }`.
* The entry needs `requiresObject` — `defineStack` refuses a menu entry for an
* object the stack does not declare unless the entry says the object comes
* from elsewhere.
*
* ## The heading a list shows
*
* The title is optional. A list and a record header show `heading`, which the
Expand Down
6 changes: 5 additions & 1 deletion packages/platform-objects/src/work/sys-task.object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ export const TASK_DONE_STATUS = 'done';
*
* Every environment carries it, whichever application is installed, so an app
* puts tasks in its menu with a `type: 'object'` navigation entry naming
* `sys_task` instead of declaring its own task object. It is an ordinary
* `sys_task` instead of declaring its own task object:
* `{ type: 'object', objectName: 'sys_task', requiresObject: 'sys_task' }`.
* The entry needs `requiresObject` — `defineStack` refuses a menu entry for an
* object the stack does not declare unless the entry says the object comes
* from elsewhere. It is an ordinary
* customizable object: an organization adds fields and views to it, and
* comments and attachments work on it as on any record (`enable.files` is on;
* the comment feed is on by default).
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.

/**
* An app menu entry naming a platform object (`sys_task`, `sys_note`) that the
* stack does not declare.
*
* The refusal stays: the platform-prefix test cannot tell an object every
* environment carries from one a plugin contributes, so exempting the prefix
* would let a menu point at an absent object. What changes is the message: for
* a platform-prefixed name it names the fix, `requiresObject`, and warns
* against declaring a package copy, which "not defined in objects" alone
* invites. A name without the prefix keeps the old message.
*/

import { describe, it, expect } from 'vitest';
import { defineStack } from './stack.zod';

type Envelope = Error & { code?: string; status?: number; issues?: readonly string[] };

function refusalOf(run: () => unknown): Envelope | null {
try {
run();
return null;
} catch (e) {
return e as Envelope;
}
}

const manifest = {
id: 'app.example.starter',
name: 'Starter',
version: '1.0.0',
type: 'app' as const,
namespace: 'starter',
};

const company = { name: 'starter_company', label: 'Company', fields: { title: { type: 'text' as const } } };

const stackWithEntry = (entry: Record<string, unknown>) =>
({
manifest,
objects: [company],
apps: [
{
name: 'starter',
label: 'Starter',
navigation: [
{ id: 'nav_companies', type: 'object', label: 'Companies', objectName: 'starter_company' },
{ id: 'nav_entry', type: 'object', label: 'Entry', ...entry },
],
},
],
}) as unknown as Parameters<typeof defineStack>[0];

const base = (name: string) =>
`App 'starter' navigation references object '${name}' which is not defined in objects.`;

describe('app navigation naming a platform object the stack does not declare', () => {
it.each(['sys_task', 'sys_note'])('refuses %s without requiresObject, and the message names requiresObject', (name) => {
const refused = refusalOf(() => defineStack(stackWithEntry({ objectName: name })));
expect(refused?.code).toBe('STACK_CROSS_REFERENCE_INVALID');
expect(refused?.status).toBe(422);
const issue = refused?.issues?.find((i) => i.startsWith(base(name)));
expect(issue).toBeDefined();
expect(issue).toContain(`requiresObject: '${name}'`);
expect(issue).toContain('do not declare a copy');
});

it.each(['sys_task', 'sys_note'])('accepts %s with requiresObject naming it', (name) => {
expect(refusalOf(() => defineStack(stackWithEntry({ objectName: name, requiresObject: name })))).toBeNull();
});

it('keeps the old message, with no requiresObject hint, for an unknown name without the platform prefix', () => {
const refused = refusalOf(() => defineStack(stackWithEntry({ objectName: 'starter_missing' })));
expect(refused?.code).toBe('STACK_CROSS_REFERENCE_INVALID');
expect(refused?.status).toBe(422);
expect(refused?.issues).toContain(base('starter_missing'));
expect(refused?.issues?.some((i) => i.includes('requiresObject'))).toBe(false);
});
});
13 changes: 12 additions & 1 deletion packages/spec/src/stack.zod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6587,8 +6587,19 @@ function validateCrossReferences(
// hides the entry when the object isn't in the SchemaRegistry,
// and stack-level cross-ref validation must skip it.
if (!nav.requiresObject) {
// A platform-prefixed name is still refused: the prefix test
// cannot tell an object every environment carries from one a
// plugin contributes, so exempting it would let a menu point at
// an object that is absent. The message names the fix instead —
// `requiresObject` — because "not defined in objects" alone
// invites declaring a package copy of a platform object.
const base = `App '${appName}' navigation references object '${nav.objectName}' which is not defined in objects.`;
errors.push(
`App '${appName}' navigation references object '${nav.objectName}' which is not defined in objects.`,
isPlatformObjectName(nav.objectName)
? `${base} '${nav.objectName}' is provided by the platform or a plugin, not by this stack: `
+ `add requiresObject: '${nav.objectName}' to the entry (the menu then hides it wherever the object `
+ `is not registered), and do not declare a copy of the object in this package.`
: base,
);
}
}
Expand Down
Loading