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
14 changes: 14 additions & 0 deletions .changeset/39661-pair-rule-suffix-app-shell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
'@object-ui/app-shell': minor
---

feat(studio)!: a customer rule on an installed object is named with the `__c` suffix

Clause-②: yes (narrowing)
Metadata-protocol: narrowed

<!-- adr-0087: registered pair-validation-rule-suffix -->

**BREAKING** for a Studio user adding a validation rule to an installed object: the name Studio mints (`validation_3`) or reads off the message (`too_big`) now ends in `__c` (`validation_3__c`, `too_big__c`), the spelling the extension door requires; a package rule's name stays refused. A rule saved before with an unsuffixed name keeps running, and its extension's next save is refused until it is renamed. A rule saved before under a package rule's name does not run: the Validations tab lists the package's rule as the package's and the customer's copy beside it, named as taken, until it is renamed or deleted.

**Migration (FROM → TO):** a validation rule a `.custom` package's object extension adds, FROM `NAME` TO `NAME__c` (`credit_check` → `credit_check__c`); a rule already ending in `__c` that a package also ships takes another name of its own ending in `__c`; a rule whose only purpose was to switch off or reword a package rule is deleted (a customer rule never replaces or switches off a package rule). Rename it in Studio's Validations tab or through `PUT /api/v1/meta/object_extension/OBJECT?package=BASE.custom`, then publish. The upgrade notice is `pair-validation-rule-suffix` (`os migrate meta`).
14 changes: 14 additions & 0 deletions .changeset/39661-pair-rule-suffix-cli.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
'@objectstack/cli': minor
---

feat(cli)!: `os validate` and `os build` refuse a `.custom` package's validation rule under another package's rule name, or without the `__c` suffix

Clause-②: yes (narrowing)
Metadata-protocol: narrowed

<!-- adr-0087: registered pair-validation-rule-suffix -->

**BREAKING** for a project whose `.custom` package's `objectExtensions[].validations` name a rule without the `__c` suffix, or with the name of a rule another package of the artifact ships for the object: `os validate` and `os build` passed it; they now exit 1 with the save door's own sentence, located at `objectExtensions[N].validations[M].name` (prefixed `packages[J].manifest.` in a multi-package artifact), and `os build` writes no artifact.

**Migration (FROM → TO):** a validation rule a `.custom` package's object extension adds, FROM `NAME` TO `NAME__c` (`credit_check` → `credit_check__c`); a rule already ending in `__c` that a package also ships takes another name of its own ending in `__c`; a rule whose only purpose was to switch off or reword a package rule is deleted (a customer rule never replaces or switches off a package rule). Rename it in Studio's Validations tab or through `PUT /api/v1/meta/object_extension/OBJECT?package=BASE.custom`, then publish. The upgrade notice is `pair-validation-rule-suffix` (`os migrate meta`).
14 changes: 14 additions & 0 deletions .changeset/39661-pair-rule-suffix-metadata-protocol.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
'@objectstack/metadata-protocol': minor
---

feat(metadata-protocol)!: the `object_extension` save door refuses a `.custom` package's validation rule under a package rule's name, or without the `__c` suffix

Clause-②: yes (narrowing)
Metadata-protocol: narrowed

<!-- adr-0087: registered pair-validation-rule-suffix -->

**BREAKING** for a caller saving, publishing or restoring an `object_extension` item into a `.custom` package (Studio, `PUT /api/v1/meta/object_extension/OBJECT?package=BASE.custom`, the MCP and AI draft doors): a validation rule whose name is the name of a rule another package ships for the target, or does not end in `__c`, answered 200; it now answers `400 VALIDATION_ERROR`, one issue per rule at `validations[N].name`, the sentence naming the rule and the fix. An extension of the `.custom` package's own object, and any package that is not `.custom`, are not judged. The judge is exported as `judgePairValidationRuleNames` (with `pairValidationRuleNameRefusalError`), the one `os validate` and `os build` ask.

**Migration (FROM → TO):** a validation rule a `.custom` package's object extension adds, FROM `NAME` TO `NAME__c` (`credit_check` → `credit_check__c`); a rule already ending in `__c` that a package also ships takes another name of its own ending in `__c`; a rule whose only purpose was to switch off or reword a package rule is deleted (a customer rule never replaces or switches off a package rule). Rename it in Studio's Validations tab or through `PUT /api/v1/meta/object_extension/OBJECT?package=BASE.custom`, then publish. The upgrade notice is `pair-validation-rule-suffix` (`os migrate meta`).
14 changes: 14 additions & 0 deletions .changeset/39661-pair-rule-suffix-objectql.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
'@objectstack/objectql': minor
---

feat(objectql)!: a `.custom` package's validation rule never replaces or switches off a package rule in the registry fold

Clause-②: yes (narrowing)
Metadata-protocol: narrowed

<!-- adr-0087: registered pair-validation-rule-suffix -->

**BREAKING** for a deployment that stored a `.custom` extension rule under a package rule's name: the fold merged it by name as it merges two vendor packages, so it replaced the package's rule, condition included, and `active: false` switched it off; a package version that later shipped a rule under a name the customer had used was replaced the same way. Now the stored copy is left out, the package's rule is enforced, and the boot log names the copy once at `error` (`[pair_validation_rule_name_held]`) with the rename; nothing throws. Between two vendor packages a later package's same-named rule still replaces the earlier one (ADR-0029 D9.2a, unchanged).

**Migration (FROM → TO):** a validation rule a `.custom` package's object extension adds, FROM `NAME` TO `NAME__c` (`credit_check` → `credit_check__c`); a rule already ending in `__c` that a package also ships takes another name of its own ending in `__c`; a rule whose only purpose was to switch off or reword a package rule is deleted (a customer rule never replaces or switches off a package rule). Rename it in Studio's Validations tab or through `PUT /api/v1/meta/object_extension/OBJECT?package=BASE.custom`, then publish. The upgrade notice is `pair-validation-rule-suffix` (`os migrate meta`).
14 changes: 14 additions & 0 deletions .changeset/39661-pair-rule-suffix-spec.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
'@objectstack/spec': minor
---

feat(spec)!: `EXTENSION_FIELD_SUFFIX` (`__c`) is the one customer suffix for a validation rule a `.custom` package adds too, and the `pair-validation-rule-suffix` upgrade notice is registered

Clause-②: yes (narrowing)
Metadata-protocol: narrowed

<!-- adr-0087: registered pair-validation-rule-suffix -->

**BREAKING** for a customer whose `.custom` package's object extension adds validation rules to another package's object: each rule name now ends in `__c` and may not be the name of a rule a package ships for that object (ruling 7411414171). `EXTENSION_FIELD_SUFFIX` and `isExtensionFieldName` (`@objectstack/spec/data`) are the one spelling of that suffix for extension fields, picklist extension values and these rules; no second constant. The protocol-19 upgrade notice `pair-validation-rule-suffix` lists the change for `os migrate meta`.

**Migration (FROM → TO):** a validation rule a `.custom` package's object extension adds, FROM `NAME` TO `NAME__c` (`credit_check` → `credit_check__c`); a rule already ending in `__c` that a package also ships takes another name of its own ending in `__c`; a rule whose only purpose was to switch off or reword a package rule is deleted (a customer rule never replaces or switches off a package rule). Rename it in Studio's Validations tab or through `PUT /api/v1/meta/object_extension/OBJECT?package=BASE.custom`, then publish. The upgrade notice is `pair-validation-rule-suffix` (`os migrate meta`).
4 changes: 2 additions & 2 deletions content/docs/data-modeling/object-extensions.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ check that spelling first.
|:---|:---|
| `fields` | **Additive.** Merged into the target's field map. A name the target already has is **replaced**, not merged — never in a `.custom` package, whose added fields all end in `__c`. |
| `fieldPatches` | **Applied, field by field.** Changes the *display* of one of the target's own fields — never one an extension adds — without replacing it — [below](#relabelling-a-vendor-field). |
| `validations` | **Concatenated.** Your rules run alongside the owner's; neither replaces the other. |
| `indexes` | **Concatenated**, same as validations. |
| `validations` | **Added by name.** Your rules run beside the owner's. Between two vendor packages, a later package's rule replaces an earlier rule of the same name. In a `.custom` package, the rules you add run beside the package's rules: each name ends in `__c` and may not be the name of a package's rule. Save and `os validate` refuse either mistake, and a stored rule under a package rule's name does not run: the package's rule does. |
| `indexes` | **Concatenated.** Your indexes are added to the owner's. |
| `label` | Replaces the target's label — with one exception, [below](#extensions-and-tenant-customization). A new `label` with no `pluralLabel` beside it also takes the target's plural off, since that plural names the old label: the object is served as one that declares no plural, and lists title it by its label. Set `pluralLabel` too to serve one. A plural the tenant set stays. |
| `pluralLabel` | Same as `label`. |
| `description` | Same as `label`. |
Expand Down
23 changes: 22 additions & 1 deletion packages/cli/src/commands/compile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ import { findExtensionFieldSuffixRefusals } from '../utils/extension-field-suffi
// [ADR-0146 D10] …and the arrangement of an extended object, the paired
// `.custom` package's alone: the same walk and the same doors' judge
// (`judgeExtensionArrangement`).
import { findExtensionArrangementRefusals } from '../utils/extension-arrangement.js';
import { findExtensionArrangementRefusals, findPairValidationRuleNameRefusals } from '../utils/extension-arrangement.js';

// [#29051] An undeclared top-level flow cycle — the walk `os validate` step
// 3a-vii runs, over the automation engine's own judge.
Expand Down Expand Up @@ -1039,6 +1039,27 @@ export default class Compile extends Command {
this.exit(1);
}

// 3b-iii-bis-3. [ruling 7411414171 (B)] A validation rule a `.custom`
// package's extension adds ends in `__c` and carries no rule name
// another package of the artifact ships for the object — the SAME
// call `os validate` makes at its step 3a-iv-ter, the save door's own
// judge (`judgePairValidationRuleNames`); no artifact is written.
const pairRuleRefusals = findPairValidationRuleNameRefusals(result.data as Record<string, unknown>);
if (pairRuleRefusals.length > 0) {
if (flags.json) {
await emitJson({ success: false, errors: pairRuleRefusals, warnings: warningsSoFar(), conversions: conversionNotices }, 0, { compact: true });
this.exit(1);
}
const n = pairRuleRefusals.length;
console.log('');
printError(`${n} validation rule${n > 1 ? 's' : ''} a \`.custom\` package adds ${n > 1 ? 'are' : 'is'} named against the customer rule naming (\`__c\`, no package rule's name)`);
printBulletList(
pairRuleRefusals.map((r) => `${r.path} [${r.code}] ${r.message}`),
{ noun: 'validation-rule name refusal(s)', remedy: JSON_FULL_LIST_REMEDY },
);
this.exit(1);
}

// 3b-iii-ter. [#28893] Flow region shape (ADR-0031) is judged by the
// rule table at step 3b since #29049 (`flow-region-shape-invalid`),
// the same verdict `os validate` and `os lint` give.
Expand Down
30 changes: 29 additions & 1 deletion packages/cli/src/commands/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ import { findNamespaceAddressLiteralRefusals } from '../utils/namespace-address-
// door's own judge, walked over the artifact's packages.
import { findOverrideDeclarationRefusals, overrideRefusalLine } from '../utils/override-declarations.js';
import { findExtensionFieldSuffixRefusals } from '../utils/extension-field-suffix.js';
import { findExtensionArrangementRefusals } from '../utils/extension-arrangement.js';
import { findExtensionArrangementRefusals, findPairValidationRuleNameRefusals } from '../utils/extension-arrangement.js';
// [ADR-0146 D10, second rule] The field-patch target check's walk; the verdict
// is the marketplace install door's own judge.
import { findFieldPatchTargetRefusals } from '../utils/field-patch-targets.js';
Expand Down Expand Up @@ -986,6 +986,34 @@ export default class Validate extends Command {
this.exit(1);
}

// 3a-iv-ter. [ruling 7411414171 (B)] A validation rule a `.custom`
// package's extension adds ends in `__c` and carries no rule name
// another package of the artifact ships for the object. The verdict
// is the `object_extension` save door's own
// (`judgePairValidationRuleNames`), so the sentence is the door's; see
// `utils/extension-arrangement.ts`.
const pairRuleRefusals = findPairValidationRuleNameRefusals(result.data as Record<string, unknown>);
if (pairRuleRefusals.length > 0) {
if (flags.json) {
await emitJson({
valid: false,
errors: pairRuleRefusals,
warnings: warningsSoFar(),
conversions: conversionNotices,
duration: timer.elapsed(),
});
this.exit(1);
}
const n = pairRuleRefusals.length;
console.log('');
printError(`${n} validation rule${n > 1 ? 's' : ''} a \`.custom\` package adds ${n > 1 ? 'are' : 'is'} named against the customer rule naming (\`__c\`, no package rule's name)`);
printBulletList(
pairRuleRefusals.map((r) => `${r.path} [${r.code}] ${r.message}`),
{ noun: 'validation-rule name refusal(s)', remedy: JSON_FULL_LIST_REMEDY },
);
this.exit(1);
}

// 3a-v. [ADR-0146 D10, second rule] The field-patch target check, at
// author time: an object extension's `fieldPatches` naming a field
// its target does not have, or an option value the field does not
Expand Down
50 changes: 48 additions & 2 deletions packages/cli/src/utils/extension-arrangement.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
*/

import { describe, expect, it } from 'vitest';
import { judgeExtensionArrangement } from '@objectstack/metadata-protocol';
import { findExtensionArrangementRefusals } from './extension-arrangement.js';
import { judgeExtensionArrangement, judgePairValidationRuleNames } from '@objectstack/metadata-protocol';
import { findExtensionArrangementRefusals, findPairValidationRuleNameRefusals } from './extension-arrangement.js';

const VENDOR = 'com.acme.partner';
const PAIR = 'com.acme.crm.custom';
Expand Down Expand Up @@ -61,3 +61,49 @@ describe('ADR-0146 D10 — the walk os validate and os build hand the arrangemen
expect(findExtensionArrangementRefusals({ objectExtensions: extensions })).toEqual([]);
});
});

/**
* [ruling 7411414171 (B)] `findPairValidationRuleNameRefusals` — the packages
* `os validate` and `os build` hand the save door's rule-name judge, and the
* package rules it reads off the artifact. Every row's message is the judge's.
*/
describe('ruling 7411414171 — the walk os validate and os build hand the rule-name judge', () => {
const BASE = 'com.acme.crm';
const rule = (name: string) => ({ type: 'script', name, message: 'No.', condition: 'record.amount > 1' });
const account = { name: 'crm_account', fields: {}, validations: [rule('credit_cap')] };

it('a `.custom` stack: an unsuffixed rule is refused under the stack\'s id, the message the judge\'s', () => {
const ext = [{ extend: 'crm_account', validations: [rule('big_deal'), rule('big_deal__c')] }];
const rows = findPairValidationRuleNameRefusals({ manifest: { id: PAIR }, objectExtensions: ext });
const judged = judgePairValidationRuleNames({ packageId: PAIR, objectExtensions: ext });
expect(rows).toEqual([{
path: 'objectExtensions[0].validations[0].name', code: 'VALIDATION_ERROR', rule: 'unsuffixed_in_pair',
packageId: PAIR, message: judged[0]!.message,
}]);
});

it('a `packages[]` artifact: a pair rule named like another package\'s rule for the object is refused, naming it', () => {
const rows = findPairValidationRuleNameRefusals({
manifest: { id: BASE },
packages: [
{ manifest: { id: BASE, objects: [account] } },
{ manifest: { id: PAIR, objectExtensions: [{ extend: 'crm_account', validations: [rule('credit_cap')] }] } },
],
});
expect(rows.map((r) => [r.path, r.rule, r.packageId])).toEqual([
['packages[1].manifest.objectExtensions[0].validations[0].name', 'held_by_package', PAIR],
]);
expect(rows[0]!.message).toContain(`package '${BASE}'`);
});

it('CONTROL: a plain package, and a `.custom` package\'s own object, are not judged', () => {
expect(findPairValidationRuleNameRefusals({
manifest: { id: VENDOR }, objectExtensions: [{ extend: 'crm_account', validations: [rule('big_deal')] }],
})).toEqual([]);
expect(findPairValidationRuleNameRefusals({
manifest: { id: PAIR },
objects: [{ name: 'crm_note', fields: {} }],
objectExtensions: [{ extend: 'crm_note', validations: [rule('big_deal')] }],
})).toEqual([]);
});
});
Loading
Loading