@reqvire-org/ads 0.3.18 → 0.3.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/dist/behaviors.mjs +19 -9
- package/dist/bootstrap-ds/ADS.md +2 -2
- package/dist/bootstrap-ds/README.md +2 -2
- package/dist/bootstrap-ds/design-system/index.ts +0 -1
- package/dist/bootstrap-ds/design-system/review/index.ts +1 -0
- package/dist/bootstrap-ds/design-system/tokens/{Foundation.scenario.tsx → Foundation.ads.scenario.tsx} +2 -2
- package/dist/bootstrap-ds/ds.config.json +1 -1
- package/dist/bootstrap-ds/tsconfig.build.json +9 -2
- package/dist/bootstrap-ds/tsconfig.json +18 -3
- package/dist/bootstrap-ds/vite.config.ts +1 -1
- package/dist/boundaries.mjs +6 -2
- package/dist/check.mjs +44 -17
- package/dist/config.mjs +33 -5
- package/dist/contract-migration.mjs +110 -0
- package/dist/contracts.d.mts +22 -0
- package/dist/evidence.mjs +1 -1
- package/dist/index.mjs +1 -0
- package/dist/init.mjs +18 -15
- package/dist/layers.mjs +288 -0
- package/dist/lint-config.mjs +1 -1
- package/dist/mcp/catalog.mjs +9 -2
- package/dist/mcp/context.mjs +2 -1
- package/dist/mcp/edit-preparation.mjs +9 -6
- package/dist/mcp/mutations.mjs +1 -1
- package/dist/mcp/preview-widget.bundle.js +41 -39
- package/dist/mcp/prompts.mjs +1 -1
- package/dist/mcp/server.mjs +9 -3
- package/dist/mcp/widget.bundle.js +1 -1
- package/dist/oxlint.mjs +3 -1
- package/dist/paint-contracts.mjs +124 -0
- package/dist/preview-resources.mjs +12 -2
- package/dist/public-api.mjs +13 -6
- package/dist/public-props.mjs +2 -2
- package/dist/runtime-contracts.mjs +225 -0
- package/dist/scenario-trace.mjs +37 -9
- package/dist/scenarios-vite.mjs +3 -2
- package/dist/scenarios.mjs +89 -30
- package/dist/scoped-tokens.mjs +9 -4
- package/dist/showcase/client.bundle.js +1 -1
- package/dist/showcase/sandbox.bundle.js +1 -1
- package/dist/skills/ads-break-ui/SKILL.md +25 -6
- package/dist/skills/ads-break-ui/references/contracts.md +250 -0
- package/dist/skills/ads-break-ui/references/guarded-editing.md +1 -1
- package/dist/skills/ads-break-ui/references/layers.md +123 -0
- package/dist/skills/ads-break-ui/references/review.md +96 -0
- package/dist/skills/ads-break-ui/references/scenarios.md +24 -3
- package/dist/skills/ads-designer/SKILL.md +26 -7
- package/dist/skills/ads-designer/assets/bootstrap-ds/ADS.md +2 -2
- package/dist/skills/ads-designer/assets/bootstrap-ds/README.md +2 -2
- package/dist/skills/ads-designer/assets/bootstrap-ds/design-system/index.ts +0 -1
- package/dist/skills/ads-designer/assets/bootstrap-ds/design-system/review/index.ts +1 -0
- package/dist/skills/ads-designer/assets/bootstrap-ds/design-system/tokens/{Foundation.scenario.tsx → Foundation.ads.scenario.tsx} +2 -2
- package/dist/skills/ads-designer/assets/bootstrap-ds/ds.config.json +1 -1
- package/dist/skills/ads-designer/assets/bootstrap-ds/tsconfig.build.json +9 -2
- package/dist/skills/ads-designer/assets/bootstrap-ds/tsconfig.json +18 -3
- package/dist/skills/ads-designer/assets/bootstrap-ds/vite.config.ts +1 -1
- package/dist/skills/ads-designer/references/contracts.md +250 -0
- package/dist/skills/ads-designer/references/guarded-editing.md +1 -1
- package/dist/skills/ads-designer/references/layers.md +123 -0
- package/dist/skills/ads-designer/references/review.md +96 -0
- package/dist/skills/ads-designer/references/scenarios.md +24 -3
- package/dist/skills/ads-import/SKILL.md +25 -6
- package/dist/skills/ads-import/references/contracts.md +250 -0
- package/dist/skills/ads-import/references/guarded-editing.md +1 -1
- package/dist/skills/ads-import/references/layers.md +123 -0
- package/dist/skills/ads-import/references/review.md +96 -0
- package/dist/skills/ads-import/references/scenarios.md +24 -3
- package/dist/skills/ads-migrate/SKILL.md +25 -6
- package/dist/skills/ads-migrate/references/contracts.md +250 -0
- package/dist/skills/ads-migrate/references/guarded-editing.md +1 -1
- package/dist/skills/ads-migrate/references/layers.md +123 -0
- package/dist/skills/ads-migrate/references/review.md +96 -0
- package/dist/skills/ads-migrate/references/scenarios.md +24 -3
- package/dist/skills/ads-motion/SKILL.md +26 -7
- package/dist/skills/ads-motion/references/audit.md +1 -1
- package/dist/skills/ads-motion/references/contracts.md +250 -0
- package/dist/skills/ads-motion/references/guarded-editing.md +1 -1
- package/dist/skills/ads-motion/references/layers.md +123 -0
- package/dist/skills/ads-motion/references/motion-review.md +35 -0
- package/dist/skills/ads-motion/references/review.md +96 -35
- package/dist/skills/ads-motion/references/scenarios.md +24 -3
- package/dist/token-origins.mjs +24 -0
- package/dist/tokens.mjs +4 -3
- package/dist/unit-contracts.mjs +203 -0
- package/dist/units.mjs +26 -17
- package/dist/verification/browser.mjs +156 -26
- package/dist/verification/playwright-reporter.cjs +13 -3
- package/docs/ADS.md +40 -6
- package/docs/ARCHITECTURE.md +73 -4
- package/docs/BEHAVIORS.md +15 -0
- package/docs/CHANGELOG.md +42 -0
- package/docs/CONTRACTS.md +250 -0
- package/docs/GUIDE.md +29 -3
- package/docs/MCP.md +42 -6
- package/package.json +4 -1
- package/dist/bootstrap-ds/design-system/patterns/token-preview/Scenario.tsx +0 -4
- package/dist/bootstrap-ds/design-system/patterns/token-preview/fixture.ts +0 -8
- package/dist/skills/ads-designer/assets/bootstrap-ds/design-system/patterns/token-preview/Scenario.tsx +0 -4
- package/dist/skills/ads-designer/assets/bootstrap-ds/design-system/patterns/token-preview/fixture.ts +0 -8
- /package/dist/bootstrap-ds/design-system/{patterns → review}/token-preview/TokenPreview.tsx +0 -0
- /package/dist/bootstrap-ds/design-system/tokens/{Foundation.fixture.ts → Foundation.ads.fixture.ts} +0 -0
- /package/dist/skills/ads-designer/assets/bootstrap-ds/design-system/{patterns → review}/token-preview/TokenPreview.tsx +0 -0
- /package/dist/skills/ads-designer/assets/bootstrap-ds/design-system/tokens/{Foundation.fixture.ts → Foundation.ads.fixture.ts} +0 -0
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
# Components, patterns and application adapters
|
|
2
|
+
|
|
3
|
+
Read this when choosing an owner, moving UI between layers, or resolving
|
|
4
|
+
`component-dependency`, `component-contract`, `component-style`, `no-app-import`
|
|
5
|
+
or `showcase-import`. MCP also serves this guide as `ads://guides/layers`.
|
|
6
|
+
|
|
7
|
+
## Choose by responsibility
|
|
8
|
+
|
|
9
|
+
A **component** provides one cohesive UI capability: semantics, input handling,
|
|
10
|
+
focus, accessibility, states and appearance. It may compose other components and
|
|
11
|
+
controllers. A notification using an icon, action button and spinner can still
|
|
12
|
+
be one component.
|
|
13
|
+
|
|
14
|
+
A **pattern** arranges capabilities and content slots into a reusable structure
|
|
15
|
+
or workflow, such as navigation with search/account controls or a report screen.
|
|
16
|
+
Layout parts may arrange `children` without importing several components.
|
|
17
|
+
Patterns may compose other patterns. A native wrapper or a large implementation
|
|
18
|
+
does not decide the layer.
|
|
19
|
+
|
|
20
|
+
An **application adapter** supplies domain data, store access, route state and
|
|
21
|
+
navigation/service callbacks. Domain-shaped inputs are valid in project-owned
|
|
22
|
+
patterns; importing a particular application store/router is not.
|
|
23
|
+
|
|
24
|
+
A **scenario** supplies demonstration inputs, local state and simulated services.
|
|
25
|
+
A component scenario may compose several public components and development review helpers
|
|
26
|
+
to demonstrate its subject. That does not turn its fixture or variant selectors
|
|
27
|
+
into production API. Keep `covers` aligned with the scenario's subject layer.
|
|
28
|
+
|
|
29
|
+
Do not classify by import count, JSX element count, names or file length. Review
|
|
30
|
+
the capability and its consumer contract. Preserve valid APIs when tracing is
|
|
31
|
+
inconclusive; do not make an export private or add a product prop just to pass.
|
|
32
|
+
|
|
33
|
+
## Demonstrate the production implementation
|
|
34
|
+
|
|
35
|
+
Product patterns are reusable application UI, not showcase replicas. A scenario
|
|
36
|
+
imports the same production owner and supplies fixtures through its public API;
|
|
37
|
+
the application supplies live data and callbacks to that API. Keep mock records,
|
|
38
|
+
demo selections and simulated services in development files. Legitimate defaults,
|
|
39
|
+
control labels and the pattern's own interaction logic remain with their owner.
|
|
40
|
+
|
|
41
|
+
Demo framing must not replace a product pattern's styling or behavior. Browser
|
|
42
|
+
checks should exercise both the demonstrated contract and relevant application
|
|
43
|
+
integration; a successful showcase does not establish production parity. A new
|
|
44
|
+
pattern need not already have an application consumer, and import counts cannot
|
|
45
|
+
detect a duplicated implementation. Existing import guards prevent fixture/test
|
|
46
|
+
dependencies; review and browser checks must assess hardcoded mock data and
|
|
47
|
+
unrepresentative rendering that source ownership alone cannot prove.
|
|
48
|
+
|
|
49
|
+
Review framing belongs in development-only `review/`, not production patterns.
|
|
50
|
+
Use the separate review entry and [review.md](review.md) for the migration and
|
|
51
|
+
build contract.
|
|
52
|
+
|
|
53
|
+
## Dependency contracts (blocking)
|
|
54
|
+
|
|
55
|
+
- Component runtime may depend on components, shared controllers and lower-level
|
|
56
|
+
helpers. It cannot depend on patterns or composition, including indirectly
|
|
57
|
+
through aliases, forwarding exports, helpers or literal dynamic imports.
|
|
58
|
+
Type-only pattern references do not introduce runtime dependencies.
|
|
59
|
+
- Patterns consume component symbols published by the configured public entry,
|
|
60
|
+
including intentional public types. A relative import of a public symbol is
|
|
61
|
+
allowed inside the ADS; requiring a self-import through the barrel can create
|
|
62
|
+
cycles. Private state, class blocks and implementation helpers stay internal.
|
|
63
|
+
A public component may use its own private implementation dependencies.
|
|
64
|
+
- Runtime code cannot import review implementations/types/styles, scenarios, fixtures or checks, including through
|
|
65
|
+
forwarding exports. Scenarios also cannot import application source.
|
|
66
|
+
- ADS implementations receive application data/effects through inputs and
|
|
67
|
+
callbacks. Re-exporting application stores, routers or services from a helper
|
|
68
|
+
does not make them part of the ADS.
|
|
69
|
+
|
|
70
|
+
For example, `components/Control → shared/helper → patterns/Navigation` fails
|
|
71
|
+
`component-dependency`. Extract a lower-level capability/controller, or move the
|
|
72
|
+
arrangement to a pattern. `patterns/Navigation → components/Control` is valid
|
|
73
|
+
when `Control` is public. Replacing that import with its private state helper
|
|
74
|
+
fails `component-contract` even through a forwarding module.
|
|
75
|
+
|
|
76
|
+
## Styling contracts (blocking when ownership is established)
|
|
77
|
+
|
|
78
|
+
Components own their control states and appearance. Patterns own arrangement,
|
|
79
|
+
spacing and their own presentation. Use typed component props/variants, an
|
|
80
|
+
intentional public class helper/hook, or registered non-state customization
|
|
81
|
+
variables. Registration does not authorize overriding interaction policy.
|
|
82
|
+
|
|
83
|
+
```tsx
|
|
84
|
+
// Component-owned implementation; the marker is not a consumer styling API.
|
|
85
|
+
function Control() {
|
|
86
|
+
return <button><span className="control-private-label">Label</span></button>;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// Pattern: rejected because it styles the component's private rendered part.
|
|
90
|
+
const wrong = css`
|
|
91
|
+
& .control-private-label { color: var(--text-muted); }
|
|
92
|
+
`;
|
|
93
|
+
|
|
94
|
+
// Pattern: its own arrangement remains valid.
|
|
95
|
+
const layout = css`
|
|
96
|
+
display: flex;
|
|
97
|
+
gap: var(--space-4);
|
|
98
|
+
`;
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
The source guard matches component-emitted class names and unambiguous literal
|
|
102
|
+
data markers to the selector's styled subject, including `:is()`/`:where()`.
|
|
103
|
+
It also rejects reads of known private component variables. It does not treat
|
|
104
|
+
an ancestor predicate or `:has()` query as styling that ancestor/descendant:
|
|
105
|
+
`[data-layout="expanded"] > & { gap: var(--space-4); }` changes the pattern's
|
|
106
|
+
own arrangement. Public hooks and registered non-state variables remain valid.
|
|
107
|
+
Token definitions, namespaces and writes retain their existing guards.
|
|
108
|
+
|
|
109
|
+
Opaque/computed imports, generated selectors, ambiguous shared markers, forwarded
|
|
110
|
+
consumer classes and arbitrary service abstractions are not a complete static
|
|
111
|
+
proof. Passing source checks does not prove that every visual override is safe.
|
|
112
|
+
Review the real rendered states, computed styles, keyboard interactions and
|
|
113
|
+
responsive layouts; use registered browser checks for promised behavior.
|
|
114
|
+
|
|
115
|
+
## Refactoring an owner
|
|
116
|
+
|
|
117
|
+
Move runtime source, its scenarios/fixtures and guides together; update public
|
|
118
|
+
exports, dependent imports and documented scenario IDs. Keep callers on the
|
|
119
|
+
same intentional public API. Navigation stays in an application callback or a
|
|
120
|
+
normal link supplied by the consumer, rather than a hidden router mutation in
|
|
121
|
+
the pattern. Validate the complete migration with project checks, product and
|
|
122
|
+
preview builds, and behavior tests. An existing guard rejection is not permission
|
|
123
|
+
to write around the guarded editing workflow.
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# Review motion
|
|
2
|
+
|
|
3
|
+
Read the item's local README before treating a choice as accidental. Compare
|
|
4
|
+
the source state machine with actual rendered behavior when a browser is
|
|
5
|
+
available. Mark source-only conclusions and untested performance hypotheses.
|
|
6
|
+
|
|
7
|
+
Assess the following where applicable:
|
|
8
|
+
|
|
9
|
+
| Area | Look for |
|
|
10
|
+
|------|----------|
|
|
11
|
+
| Purpose/frequency | A clear relationship to the action; repeated work is not slowed |
|
|
12
|
+
| Easing | Entry decelerates naturally; continuous movement and elapsed-time motion use suitable curves |
|
|
13
|
+
| Timing | Feedback starts promptly; total choreography fits its distance and task |
|
|
14
|
+
| Origin/distance | Placement and scale point to the real trigger without excessive travel |
|
|
15
|
+
| Continuity | Reversal and repeated updates retarget without snapping or restarting |
|
|
16
|
+
| Lifecycle | Exit, cancellation, unmount, and zero-duration states clean up correctly |
|
|
17
|
+
| Accessibility | Motion preference, focus, hidden content, and keyboard behavior remain correct |
|
|
18
|
+
| Ownership | Motion uses tokens and owner styles; consumers do not override internals |
|
|
19
|
+
| Cost | Measured rendering work matches the problem; no per-frame work is assumed harmless |
|
|
20
|
+
|
|
21
|
+
The upstream guidance favors short transitions, restrained scale, and transform/
|
|
22
|
+
opacity. Apply those as defaults with context. A documented 400 ms stack,
|
|
23
|
+
measured height transition, or necessary loading loop is not inherently broken.
|
|
24
|
+
Likewise, a transition below 300 ms is not automatically good. Verify whether an
|
|
25
|
+
exception preserves the intended experience and has acceptable observed cost.
|
|
26
|
+
|
|
27
|
+
Present only actionable findings. Include file/line, trigger, observed behavior,
|
|
28
|
+
expected behavior, why the difference matters, and a concrete owner-level fix.
|
|
29
|
+
For timing/easing proposals, name the current and proposed token policy and its
|
|
30
|
+
scope. If a token is shared, identify affected neighbors before changing values.
|
|
31
|
+
|
|
32
|
+
Use a before/after/why comparison for implemented fixes. Separate behavior
|
|
33
|
+
defects, visual refinements, and profiling questions so a suspicion is not
|
|
34
|
+
reported as a proved performance failure. If no defect is found, say what was
|
|
35
|
+
checked and what remains unverified. Do not invent findings to fill a checklist.
|
|
@@ -1,35 +1,96 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
Read
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
1
|
+
# Development-only review UI
|
|
2
|
+
|
|
3
|
+
Read this when creating or migrating demo frames, preview sizing helpers, token
|
|
4
|
+
renderers or demonstration controls. MCP serves it as `ads://guides/review`.
|
|
5
|
+
|
|
6
|
+
## Responsibilities and boundaries
|
|
7
|
+
|
|
8
|
+
Components provide cohesive production capabilities. Patterns provide reusable
|
|
9
|
+
application structures/workflows. Both receive variable application data and
|
|
10
|
+
callbacks through their APIs. Their scenarios import the same implementation
|
|
11
|
+
used by the application and supply fixtures; do not create a second implementation
|
|
12
|
+
that only looks correct in the showcase.
|
|
13
|
+
|
|
14
|
+
`design-system/review/` owns development-only presentation: example frames,
|
|
15
|
+
arrangement, demonstration controls, token sample renderers and their styles.
|
|
16
|
+
It remains project-owned. The MCP host shell stays generic; review code executes
|
|
17
|
+
inside the preview App with the project's framework, foundation, fonts and styles.
|
|
18
|
+
Nothing depends on particular helper names or an imported component library.
|
|
19
|
+
|
|
20
|
+
The development entry defaults to `review/index.ts` relative to `dsDir`; configure
|
|
21
|
+
`reviewEntry` for another script inside `review/`. Its import alias is the
|
|
22
|
+
configured `publicAlias` plus `/review`, normally `@ds/review`. Discover the actual
|
|
23
|
+
entry/alias through `ads_status.project.review`. Export helpers there, never from
|
|
24
|
+
the production public barrel. Review implementations, types and styles must not
|
|
25
|
+
enter application, component, pattern or controller dependencies. Tests, fixtures,
|
|
26
|
+
scenarios and preview mounts can consume review code.
|
|
27
|
+
|
|
28
|
+
Review helpers can own Linaria presentation, local state and demo controls. Normal
|
|
29
|
+
style-token, variable ownership, measured-style-write and application separation
|
|
30
|
+
gates still apply. They consume deliberate public component/pattern/controller
|
|
31
|
+
contracts and may reuse local foundation helpers. They cannot target private
|
|
32
|
+
component styles or replace real product behavior. Keep one-off fixture data in
|
|
33
|
+
the scenario; a helper need not become a product API to frame an example.
|
|
34
|
+
|
|
35
|
+
## Scenario and token contracts
|
|
36
|
+
|
|
37
|
+
```tsx
|
|
38
|
+
import { Panel } from "@ds";
|
|
39
|
+
import { ReviewFrame } from "@ds/review";
|
|
40
|
+
import { fixture } from "./Panel.fixture";
|
|
41
|
+
|
|
42
|
+
export const scenario = { title: "Panel", covers: ["Panel"] };
|
|
43
|
+
export default function Scenario() {
|
|
44
|
+
return <ReviewFrame><Panel {...fixture} /></ReviewFrame>;
|
|
45
|
+
}
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
The names above are illustrative. `covers` names the production subjects actually
|
|
49
|
+
demonstrated, not every review wrapper. A review export has no product catalogue
|
|
50
|
+
entry and needs no standalone catalogue scenario. Keep review unit tests/specs
|
|
51
|
+
beside their owner; optional behavior contracts can verify review guarantees
|
|
52
|
+
through an existing real scenario. They establish no production coverage.
|
|
53
|
+
|
|
54
|
+
A token scenario may name its real review renderer in `covers`, import it from
|
|
55
|
+
the development entry, declare `samples: fixture.samples`, and pass those samples
|
|
56
|
+
into the renderer. Existing real product patterns may also serve as token UI.
|
|
57
|
+
Empty covers, unused samples, fabricated tokens and plain value lists remain
|
|
58
|
+
invalid. The rendered App must still pass token-binding checks. See
|
|
59
|
+
[scenarios.md](scenarios.md) for the full token/render contract.
|
|
60
|
+
|
|
61
|
+
Review class helpers can supply source-proven Linaria classes to a scenario.
|
|
62
|
+
Arbitrary scenario classes/styles remain forbidden. A review wrapper's own native
|
|
63
|
+
controls do not authorize arbitrary native controls in its consuming scenario;
|
|
64
|
+
slot/selector exceptions still need actual production-owner evidence. Keep
|
|
65
|
+
production and review export names distinct where `covers` would be ambiguous.
|
|
66
|
+
|
|
67
|
+
## Build and guarded edits
|
|
68
|
+
|
|
69
|
+
The normal preview plugin registers the exact review alias before broader product
|
|
70
|
+
aliases. Configure the same alias in project TypeScript and any independent
|
|
71
|
+
preview/dev harness. In an ordered bundler alias map, put `@ds/review` before
|
|
72
|
+
`@ds`; the broad `@ds` mapping must not resolve it as `index.ts/review`.
|
|
73
|
+
Production entrypoints never import the development entry. Inspect the product
|
|
74
|
+
bundle for review modules/CSS; passing static checks does not prove bundle parity.
|
|
75
|
+
|
|
76
|
+
Use `ads_units` for `review/<Owner>` units. Scenarios, local specs and helper files
|
|
77
|
+
follow ordinary flat/directory ownership. A review patch may update only its own
|
|
78
|
+
re-exports in the development entry and its own documented style boundaries.
|
|
79
|
+
Product owners retain the separate production entry companion. Use prepared
|
|
80
|
+
patches/dry runs and coupled transactions as described in
|
|
81
|
+
[guarded-editing.md](guarded-editing.md); do not bypass a rejected mutation.
|
|
82
|
+
|
|
83
|
+
For an existing project, identify helpers by responsibility and actual consumers,
|
|
84
|
+
not names or the number of imported components. Preserve real application patterns.
|
|
85
|
+
Move only demo helpers, their styles and relevant guides to `review/`; update
|
|
86
|
+
scenario/preview imports, style-boundary paths, TypeScript/bundler aliases and
|
|
87
|
+
links. Remove their production exports and obsolete standalone product scenarios.
|
|
88
|
+
Do not copy old example fixtures or export demonstration controls as product UI.
|
|
89
|
+
|
|
90
|
+
Upgrade ADS before migrating a consuming project: older versions do not know the
|
|
91
|
+
separate review entry. For staged guarded edits, first add distinctly named review
|
|
92
|
+
exports, migrate consumers in passing owner patches, then remove the old pattern
|
|
93
|
+
exports/owners once unused. Required coupled changes use a transaction. Check
|
|
94
|
+
source gates, typecheck, preview and production builds, real browser rendering,
|
|
95
|
+
registered behaviors and token bindings. A source move alone establishes none
|
|
96
|
+
of those rendered guarantees.
|
|
@@ -34,10 +34,31 @@ do not add scenario `preventDefault` handlers merely to hide it. Explicit App
|
|
|
34
34
|
bases retain their declared behavior and CSP requirements; external hosts own
|
|
35
35
|
their document-loading policy. Verify link activation as well as rendering.
|
|
36
36
|
|
|
37
|
+
## Forms inside Apps
|
|
38
|
+
|
|
39
|
+
Use real form semantics and the runtime owner's intended submit handler. ADS's
|
|
40
|
+
showcase and diagnostic explorer permit `allow-forms` at every iframe layer,
|
|
41
|
+
including legacy widgets. Browser constraint validation, Submit clicks, Enter and
|
|
42
|
+
`requestSubmit()` can reach the normal submit path. Client-side forms call
|
|
43
|
+
`preventDefault()` in their submit handlers; the host does not synthesize clicks
|
|
44
|
+
or submit events. Native action requests are blocked by CSP `form-action 'none'`.
|
|
45
|
+
Submit effects that use tools or resources still follow the MCP bridge.
|
|
46
|
+
|
|
47
|
+
If a click fires but the `submit` handler never runs, inspect the browser's sandbox
|
|
48
|
+
diagnostic and every ancestor iframe's permissions. Distinguish that host problem
|
|
49
|
+
from native constraint validation legitimately preventing submission. Do not add
|
|
50
|
+
scenario click interception to disguise a missing sandbox permission. External
|
|
51
|
+
MCP hosts control their own sandbox/CSP policy.
|
|
52
|
+
|
|
53
|
+
Verify an invalid submit, a valid submit, implicit Enter submission and the promised
|
|
54
|
+
state effects. A working Next button is not evidence that form submission works.
|
|
55
|
+
Keep native action navigation separate from client-side submission behavior;
|
|
56
|
+
`allow-forms` does not grant host DOM access or top-level navigation.
|
|
57
|
+
|
|
37
58
|
## Owner-local token previews load their own definitions
|
|
38
59
|
|
|
39
60
|
Keep the registered token sheet imported by its runtime owner for product use.
|
|
40
|
-
A colocated `kind: "tokens"` scenario may render only the
|
|
61
|
+
A colocated `kind: "tokens"` scenario may render only the development-only review renderer
|
|
41
62
|
with its fixture samples. Discovery adds the registered owner sheet to the
|
|
42
63
|
generated record's `stylesheets`; `previewEntriesPlugin` imports those paths
|
|
43
64
|
into the token preview independently of the runtime component. Custom builders
|
|
@@ -91,7 +112,7 @@ These examples describe verification mistakes, not component-specific rules:
|
|
|
91
112
|
|
|
92
113
|
| Situation | Do not | Do instead |
|
|
93
114
|
|-----------|--------|------------|
|
|
94
|
-
| A reference example sets `width: 15rem`, while the native popup uses its default width. | Remove the reference width and claim the original example now matches. | Keep the baseline intact. Reproduce demo sizing through the project's
|
|
115
|
+
| A reference example sets `width: 15rem`, while the native popup uses its default width. | Remove the reference width and claim the original example now matches. | Keep the baseline intact. Reproduce demo sizing through the project's development-only review helper or supported style helper. If a different native size is intentional, document it. Label any additional normalized comparison separately. |
|
|
95
116
|
| Static tracing cannot prove that a public clear control renders when a value is selected. | Remove its export, drop its required coverage, or change runtime behavior merely to pass the gate. | Preserve the intended public API. Try a meaningful selected-state fixture or another real scenario. If valid rendering remains untraceable, report the tooling limitation with a small reproduction. |
|
|
96
117
|
| A screenshot shows the clear control in a selected state. | Treat its presence as evidence that clearing works. | Add a browser check: start selected, activate Clear, assert the value and selection are empty, verify the control's resulting visibility and documented focus behavior, then select again. |
|
|
97
118
|
|
|
@@ -207,6 +228,6 @@ An `exercises` entry records behavioral use; it never grants styling permission.
|
|
|
207
228
|
Keep helper signatures compatible with the product API. Fix ownership/provenance
|
|
208
229
|
in the runtime owner when genuinely wrong; retain intentional public APIs when
|
|
209
230
|
reporting an unsupported trace. Demo-only sizing, framing and arrangement still
|
|
210
|
-
belong in
|
|
231
|
+
belong in development-only review helpers. A style helper is not permission to
|
|
211
232
|
author a second design in the scenario. For cascade risks and extraction issues,
|
|
212
233
|
read [atomic-styles.md](atomic-styles.md).
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import valueParser from "postcss-value-parser";
|
|
2
|
+
|
|
3
|
+
/** Read-only provenance for project policies. No token-name or design semantics
|
|
4
|
+
* are inferred. stopAt is an explicit project-selected vocabulary. */
|
|
5
|
+
export function inspectTokenOrigins(inventory, name, { stopAt = [] } = {}) {
|
|
6
|
+
const allowed=new Set(stopAt),tokens=new Map(inventory.tokens.map(token=>[token.name,token]));
|
|
7
|
+
const origins=new Set(),literals=[],diagnostics=[];let steps=0;
|
|
8
|
+
function visit(name,seen=new Set()) {
|
|
9
|
+
if(++steps>256){diagnostics.push("Token provenance exceeded 256 branches.");return;}
|
|
10
|
+
const token=tokens.get(name);
|
|
11
|
+
if(!token){diagnostics.push(`Undefined token ${name}.`);return;}
|
|
12
|
+
if(allowed.has(name)){origins.add(name);return;}
|
|
13
|
+
if(seen.has(name)){diagnostics.push(`Cyclic alias through ${name}.`);return;}
|
|
14
|
+
seen=new Set([...seen,name]);
|
|
15
|
+
for(const definition of token.definitions) {
|
|
16
|
+
const nodes=valueParser(definition.value).nodes.filter(node=>!["space","comment"].includes(node.type));
|
|
17
|
+
const ref=nodes.length===1&&nodes[0].type==="function"&&nodes[0].value==="var"&&nodes[0].nodes.filter(node=>!["space","comment"].includes(node.type));
|
|
18
|
+
if(ref&&ref.length===1&&ref[0].type==="word"&&/^--[\w-]+$/.test(ref[0].value))visit(ref[0].value,seen);
|
|
19
|
+
else literals.push({token:name,...definition});
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
visit(name);
|
|
23
|
+
return {token:name,origins:[...origins].sort(),literals,diagnostics,aliasOnly:origins.size>0&&!literals.length&&!diagnostics.length};
|
|
24
|
+
}
|
package/dist/tokens.mjs
CHANGED
|
@@ -45,8 +45,9 @@ function matchesType(value, type) {
|
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
export function inspectTokens(directory) {
|
|
49
|
-
const options = loadConfig(directory);
|
|
48
|
+
export function inspectTokens(directory, suppliedOptions) {
|
|
49
|
+
const options = suppliedOptions ?? loadConfig(directory);
|
|
50
|
+
if(options.tokenInventory)return options.tokenInventory;
|
|
50
51
|
const { root, dsRoot, config } = options;
|
|
51
52
|
const definitions = new Map();
|
|
52
53
|
const diagnostics = [];
|
|
@@ -141,7 +142,7 @@ export function inspectTokens(directory) {
|
|
|
141
142
|
if (type && resolved !== undefined && !matchesType(resolved, type)) report("token-type", name, entry, `${name} expects ${type}; found ${resolved}.`);
|
|
142
143
|
}
|
|
143
144
|
}
|
|
144
|
-
return {
|
|
145
|
+
return options.tokenInventory = {
|
|
145
146
|
contractVersion: tokenContract.version,
|
|
146
147
|
tokens: [...definitions].sort(([a], [b]) => a.localeCompare(b)).map(([name, entries]) => ({ name, ...tokenContract.tokens[name], ...(scopedTokenOwner(options, name) ? {owner:scopedTokenOwner(options, name).unit, namespace:scopedTokenOwner(options, name).namespace} : {owner:"tokens"}), definitions: entries })),
|
|
147
148
|
diagnostics,
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import { existsSync, realpathSync, statSync } from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import ts from "typescript";
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
import { isContractFile, isDevelopmentFile, isInside, isReviewFile, sourceFiles } from "./config.mjs";
|
|
6
|
+
import { projectCompilerOptions } from "./boundaries.mjs";
|
|
7
|
+
import { inspectUnits } from "./units.mjs";
|
|
8
|
+
import { publicApi, reviewApi } from "./public-api.mjs";
|
|
9
|
+
|
|
10
|
+
const identities = new WeakSet();
|
|
11
|
+
const ref = z.custom(value => value && typeof value === "object" && identities.has(value), "Use a resolved implementation symbol, not its name or an object describing it.");
|
|
12
|
+
const id = z.string().regex(/^[A-Za-z0-9][\w.-]{0,99}$/);
|
|
13
|
+
const checks = z.array(id).min(1).max(100);
|
|
14
|
+
const field = z.string().regex(/^[A-Za-z_$][\w$]*(?:\.(?:[A-Za-z_$][\w$]*|\*))*$/).max(200);
|
|
15
|
+
const paint = z.object({ api: ref, property: field, kind: z.literal("paint-reference"), bindings: z.array(id).max(20).optional() }).strict();
|
|
16
|
+
const binding = z.object({ input: z.object({ api: ref, property: field }).strict(), producer: ref, valueFrom: field,
|
|
17
|
+
variable: z.string().regex(/^--[a-z][\w-]*\$\{key\}[\w-]*$/), scope: z.object({ api: ref, selector: z.string().min(1).max(200) }).strict(), checks }).strict();
|
|
18
|
+
const part = z.object({ api: ref, parent: ref, consumer: ref, checks }).strict();
|
|
19
|
+
const schema = z.object({ schemaVersion: z.literal(1),
|
|
20
|
+
tokens: z.object({ namespace: z.string(), stylesheet: z.string().min(1).max(256) }).strict().optional(),
|
|
21
|
+
paintInputs: z.array(paint).max(100).optional(), bindings: z.record(id, binding).optional(),
|
|
22
|
+
declarativeParts: z.array(part).max(100).optional(), behavior: z.record(z.string(), z.unknown()).optional(),
|
|
23
|
+
}).strict();
|
|
24
|
+
|
|
25
|
+
const slash = file => file.replaceAll("\\", "/");
|
|
26
|
+
export function implementationIdentity(declaration, root) {
|
|
27
|
+
return `${slash(path.relative(root, declaration.getSourceFile().fileName))}:${declaration.pos}`;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function implementationNode(program, reference, root) {
|
|
31
|
+
const source = program.getSourceFile(path.resolve(root, reference.source));
|
|
32
|
+
let found;
|
|
33
|
+
function visit(node) {
|
|
34
|
+
if (node.pos === reference.position && (ts.isFunctionDeclaration(node) || ts.isVariableDeclaration(node) || ts.isClassDeclaration(node))) found = node;
|
|
35
|
+
else if (!found) ts.forEachChild(node, visit);
|
|
36
|
+
}
|
|
37
|
+
if (source) visit(source);
|
|
38
|
+
return found;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** Pure AST evaluation. Functions are opaque identities; project code never runs. */
|
|
42
|
+
export function staticContractValue(expression, checker, options, locations = new Map()) {
|
|
43
|
+
let visits = 0;
|
|
44
|
+
function read(node, key = "", seen = new Set()) {
|
|
45
|
+
if (++visits > 12000 || seen.size > 60) throw new Error("Static contract expansion exceeded its bounded limit.");
|
|
46
|
+
while (node && (ts.isAsExpression(node) || ts.isSatisfiesExpression(node) || ts.isParenthesizedExpression(node))) node = node.expression;
|
|
47
|
+
if (!node || seen.has(node)) throw new Error(`Unresolved or cyclic contract value at ${key || "default export"}.`);
|
|
48
|
+
locations.set(key, node);
|
|
49
|
+
seen = new Set([...seen, node]);
|
|
50
|
+
if (ts.isStringLiteralLike(node) || ts.isNumericLiteral(node)) return ts.isNumericLiteral(node) ? Number(node.text) : node.text;
|
|
51
|
+
if (node.kind === ts.SyntaxKind.TrueKeyword) return true;
|
|
52
|
+
if (node.kind === ts.SyntaxKind.FalseKeyword) return false;
|
|
53
|
+
if (node.kind === ts.SyntaxKind.NullKeyword) return null;
|
|
54
|
+
if (ts.isPrefixUnaryExpression(node) && node.operator === ts.SyntaxKind.MinusToken && ts.isNumericLiteral(node.operand)) return -Number(node.operand.text);
|
|
55
|
+
if (ts.isArrayLiteralExpression(node)) {
|
|
56
|
+
const result = [];
|
|
57
|
+
for (const item of node.elements) {
|
|
58
|
+
if (ts.isSpreadElement(item)) { const values = read(item.expression, key, seen); if (!Array.isArray(values)) throw new Error("Contract array spreads require a static array."); result.push(...values); }
|
|
59
|
+
else result.push(read(item, `${key}.${result.length}`, seen));
|
|
60
|
+
}
|
|
61
|
+
return result;
|
|
62
|
+
}
|
|
63
|
+
if (ts.isObjectLiteralExpression(node)) {
|
|
64
|
+
const result = Object.create(null);
|
|
65
|
+
for (const item of node.properties) {
|
|
66
|
+
if (ts.isSpreadAssignment(item)) {
|
|
67
|
+
const value = read(item.expression, key, seen);
|
|
68
|
+
if (!value || Array.isArray(value) || typeof value !== "object" || identities.has(value)) throw new Error("Contract object spreads require a plain static object.");
|
|
69
|
+
for (const [name, valueItem] of Object.entries(value)) { if (Object.hasOwn(result, name)) throw new Error(`Duplicate contract field ${key}.${name}.`); result[name] = valueItem; }
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
if (!ts.isPropertyAssignment(item) && !ts.isShorthandPropertyAssignment(item)) throw new Error("Contracts contain data fields, not getters, methods or executable expressions.");
|
|
73
|
+
if (!ts.isIdentifier(item.name) && !ts.isStringLiteralLike(item.name)) throw new Error("Contract property keys must be literal names.");
|
|
74
|
+
const name = item.name.text;
|
|
75
|
+
if (["__proto__", "prototype", "constructor"].includes(name) || Object.hasOwn(result, name)) throw new Error(`Invalid or duplicate contract field ${key}.${name}.`);
|
|
76
|
+
const input = ts.isShorthandPropertyAssignment(item) ? checker.getShorthandAssignmentValueSymbol(item)?.valueDeclaration : null;
|
|
77
|
+
result[name] = read(input?.initializer ?? (ts.isPropertyAssignment(item) ? item.initializer : item.name), key ? `${key}.${name}` : name, seen);
|
|
78
|
+
}
|
|
79
|
+
return result;
|
|
80
|
+
}
|
|
81
|
+
if (ts.isIdentifier(node) || ts.isPropertyAccessExpression(node)) {
|
|
82
|
+
let symbol = checker.getSymbolAtLocation(ts.isPropertyAccessExpression(node) ? node.name : node);
|
|
83
|
+
if (symbol?.flags & ts.SymbolFlags.Alias) symbol = checker.getAliasedSymbol(symbol);
|
|
84
|
+
const declaration = symbol?.valueDeclaration;
|
|
85
|
+
if (!declaration) throw new Error(`Cannot resolve contract symbol ${node.getText()}.`);
|
|
86
|
+
const runtime = !isDevelopmentFile(declaration.getSourceFile().fileName, options)||isReviewFile(declaration.getSourceFile().fileName,options);
|
|
87
|
+
const initializer = ts.isVariableDeclaration(declaration) ? declaration.initializer : ts.isPropertyAssignment(declaration) ? declaration.initializer : null;
|
|
88
|
+
const callable = ts.isFunctionDeclaration(declaration) || ts.isClassDeclaration(declaration) || initializer && (ts.isArrowFunction(initializer) || ts.isFunctionExpression(initializer) || ts.isCallExpression(initializer));
|
|
89
|
+
if (runtime && callable) {
|
|
90
|
+
const value = { source: slash(path.relative(options.root, declaration.getSourceFile().fileName)), symbol: symbol.name, position: declaration.pos, identity: implementationIdentity(declaration, options.root) };
|
|
91
|
+
identities.add(value); return value;
|
|
92
|
+
}
|
|
93
|
+
if (initializer && (!ts.isVariableDeclaration(declaration) || declaration.parent.flags & ts.NodeFlags.Const)) return read(initializer, key, seen);
|
|
94
|
+
}
|
|
95
|
+
throw new Error(`Unsupported static contract expression at ${key || "default export"}: ${ts.SyntaxKind[node.kind]}. Calls, getters and environment-dependent code are not evaluated.`);
|
|
96
|
+
}
|
|
97
|
+
return read(expression);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export function inspectUnitContracts(options) {
|
|
101
|
+
if (options.unitContracts) return options.unitContracts;
|
|
102
|
+
const files = sourceFiles(options.dsRoot).filter(isContractFile);
|
|
103
|
+
const result = { contracts: [], diagnostics: [], program: null };
|
|
104
|
+
options.unitContracts = result;
|
|
105
|
+
if (!files.length) return result;
|
|
106
|
+
const inventory = inspectUnits(options);
|
|
107
|
+
const program = ts.createProgram(sourceFiles(options.dsRoot).filter(file => /\.[cm]?[jt]sx?$/.test(file)), { ...projectCompilerOptions(options), allowJs: true });
|
|
108
|
+
result.program = program;
|
|
109
|
+
const checker = program.getTypeChecker();
|
|
110
|
+
const publicItems = [...publicApi(program, options), ...reviewApi(program, options)];
|
|
111
|
+
const publicByIdentity = new Map(publicItems.map(api => [implementationIdentity(api.declaration, options.root), api]));
|
|
112
|
+
const seen = new Set();
|
|
113
|
+
for (const file of files) {
|
|
114
|
+
const relative = slash(path.relative(options.root, file));
|
|
115
|
+
const unit = inventory.owner(inventory.relative(relative));
|
|
116
|
+
const source = program.getSourceFile(file), locations = new Map();
|
|
117
|
+
function report(message, fieldName = "") {
|
|
118
|
+
const node = locations.get(fieldName) ?? source;
|
|
119
|
+
const position = node?.getSourceFile().getLineAndCharacterOfPosition(node.getStart());
|
|
120
|
+
result.diagnostics.push({ file: relative, rule: "unit-contract", message, line: (position?.line ?? 0) + 1, column: (position?.character ?? 0) + 1, ...(fieldName ? { entry: fieldName } : {}) });
|
|
121
|
+
}
|
|
122
|
+
try {
|
|
123
|
+
if (!source || statSync(file).size > 128 * 1024 || realpathSync(file) !== file) throw new Error("Contracts must be real owner-local files of at most 128 KiB.");
|
|
124
|
+
if (!/^(?:components|patterns|controllers|review)\//.test(unit ?? "")) throw new Error("Contracts belong to a component, pattern, controller or review owner.");
|
|
125
|
+
if (seen.has(unit)) throw new Error(`Only one TypeScript contract may describe ${unit}.`);
|
|
126
|
+
seen.add(unit);
|
|
127
|
+
for (const statement of source.statements) {
|
|
128
|
+
if (ts.isImportDeclaration(statement) || ts.isInterfaceDeclaration(statement) || ts.isTypeAliasDeclaration(statement) || ts.isExportAssignment(statement) || ts.isEmptyStatement(statement)) continue;
|
|
129
|
+
if (ts.isVariableStatement(statement) && statement.declarationList.flags & ts.NodeFlags.Const) continue;
|
|
130
|
+
throw new Error("Contract modules contain imports, types, static constants and one default data export; executable statements are forbidden.");
|
|
131
|
+
}
|
|
132
|
+
const exports = source.statements.filter(ts.isExportAssignment);
|
|
133
|
+
if (exports.length !== 1 || exports[0].isExportEquals) throw new Error("Export one default contract data object.");
|
|
134
|
+
const value = staticContractValue(exports[0].expression, checker, options, locations);
|
|
135
|
+
for(const statement of source.statements.filter(ts.isVariableStatement))for(const declaration of statement.declarationList.declarations)staticContractValue(declaration.initializer,checker,options);
|
|
136
|
+
const parsed = schema.safeParse(value);
|
|
137
|
+
if (!parsed.success) { for (const issue of parsed.error.issues.slice(0, 12)) report(`${issue.path.join(".")}: ${issue.message}`, issue.path.join(".")); continue; }
|
|
138
|
+
const data = parsed.data;
|
|
139
|
+
const apiName = (reference, fieldName) => {
|
|
140
|
+
const owner = inventory.owner(inventory.relative(reference.source));
|
|
141
|
+
const api = publicByIdentity.get(reference.identity);
|
|
142
|
+
if (owner !== unit || !api) { report(`${fieldName} must reference a real public API owned by ${unit}.`, fieldName); return null; }
|
|
143
|
+
return api.name;
|
|
144
|
+
};
|
|
145
|
+
function implementation(reference, fieldName) {
|
|
146
|
+
const absolute = path.resolve(options.root, reference.source);
|
|
147
|
+
if (!isInside(options.dsRoot, absolute) || inventory.owner(inventory.relative(reference.source)) !== unit || isDevelopmentFile(absolute, options)&&!isReviewFile(absolute,options)) report(`${fieldName} must reference runtime or review implementation inside ${unit}, not a contract, fixture or spec.`, fieldName);
|
|
148
|
+
}
|
|
149
|
+
if (data.tokens) {
|
|
150
|
+
if(!/^(?:components|patterns)\//.test(unit))report("Owner-local design token namespaces belong to components or patterns. Controllers remain headless; review uses the shared vocabulary and its own presentation state.","tokens");
|
|
151
|
+
const absolute = path.resolve(path.dirname(file), data.tokens.stylesheet);
|
|
152
|
+
if (!isInside(options.dsRoot, absolute) || inventory.owner(inventory.relative(slash(path.relative(options.root, absolute)))) !== unit || !absolute.endsWith(".css") || !existsSync(absolute)) report("Token stylesheet must be a real CSS file in this owner.", "tokens.stylesheet");
|
|
153
|
+
data.tokens.file = slash(path.relative(options.root, absolute));
|
|
154
|
+
}
|
|
155
|
+
for (const [index, input] of (data.paintInputs ?? []).entries()) {
|
|
156
|
+
if(data.paintInputs.slice(0,index).some(prior=>prior.api.identity===input.api.identity&&prior.property===input.property))report("Duplicate paint-input registration is ambiguous.",`paintInputs.${index}`);
|
|
157
|
+
input.apiName = apiName(input.api, `paintInputs.${index}.api`);
|
|
158
|
+
for (const name of input.bindings ?? []) if (!Object.hasOwn(data.bindings ?? {}, name)) report(`Unknown binding ${name}.`, `paintInputs.${index}.bindings`);
|
|
159
|
+
}
|
|
160
|
+
for (const [name, entry] of Object.entries(data.bindings ?? {})) {
|
|
161
|
+
entry.apiName = apiName(entry.input.api, `bindings.${name}.input.api`);
|
|
162
|
+
entry.scope.apiName = apiName(entry.scope.api, `bindings.${name}.scope.api`);
|
|
163
|
+
if(!publicByIdentity.get(entry.scope.api.identity)?.renderable)report("Binding scopes require a real public rendering API.",`bindings.${name}.scope.api`);
|
|
164
|
+
implementation(entry.producer, `bindings.${name}.producer`);
|
|
165
|
+
if (entry.apiName !== entry.scope.apiName) report("The binding input and attachment scope must belong to the same public API.", `bindings.${name}`);
|
|
166
|
+
}
|
|
167
|
+
for (const [index, entry] of (data.declarativeParts ?? []).entries()) {
|
|
168
|
+
if(data.declarativeParts.slice(0,index).some(prior=>prior.api.identity===entry.api.identity))report("A declarative API needs one unambiguous parent/consumer relationship.",`declarativeParts.${index}`);
|
|
169
|
+
entry.apiName = apiName(entry.api, `declarativeParts.${index}.api`);
|
|
170
|
+
entry.parentName = apiName(entry.parent, `declarativeParts.${index}.parent`);
|
|
171
|
+
if(!publicByIdentity.get(entry.parent.identity)?.renderable)report("Declarative parents require a real public rendering API.",`declarativeParts.${index}.parent`);
|
|
172
|
+
implementation(entry.consumer, `declarativeParts.${index}.consumer`);
|
|
173
|
+
}
|
|
174
|
+
let behavior;
|
|
175
|
+
if (data.behavior) {
|
|
176
|
+
if(Object.hasOwn(data.behavior,"schemaVersion"))report("Behavior inherits the owner contract's schemaVersion; remove the competing nested version.","behavior.schemaVersion");
|
|
177
|
+
behavior = { ...data.behavior, schemaVersion: 1 };
|
|
178
|
+
behavior.subjects = Object.fromEntries(Object.entries(behavior.subjects ?? {}).map(([name, subject]) => {
|
|
179
|
+
if (subject?.api && identities.has(subject.api)) return [name, { api: apiName(subject.api, `behavior.subjects.${name}.api`) ?? "" }];
|
|
180
|
+
if (subject?.implementation && identities.has(subject.implementation)) {
|
|
181
|
+
implementation(subject.implementation, `behavior.subjects.${name}.implementation`);
|
|
182
|
+
return [name, { source: `./${slash(path.relative(path.dirname(file), path.resolve(options.root, subject.implementation.source)))}`, symbol: subject.implementation.symbol }];
|
|
183
|
+
}
|
|
184
|
+
report("Behavior subjects must use an actual public api or owner-local implementation symbol.", `behavior.subjects.${name}`);
|
|
185
|
+
return [name, subject];
|
|
186
|
+
}));
|
|
187
|
+
}
|
|
188
|
+
for (const entry of [...Object.values(data.bindings ?? {}), ...(data.declarativeParts ?? [])]) for (const check of entry.checks) if (!behavior?.checks?.[check]) report(`Required check ${check} is not registered in this contract's behavior checks.`);
|
|
189
|
+
result.contracts.push({ ...data, ...(behavior ? { behavior } : {}), unit, file: relative });
|
|
190
|
+
} catch (error) { report(error.message); }
|
|
191
|
+
}
|
|
192
|
+
return result;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/** An ownership lookup, not source/browser certification of the declaration. */
|
|
196
|
+
export function runtimeBindingOwner(options, name) {
|
|
197
|
+
for (const contract of inspectUnitContracts(options).contracts) for (const [id, binding] of Object.entries(contract.bindings ?? {})) {
|
|
198
|
+
const [prefix, suffix] = binding.variable.split("${key}");
|
|
199
|
+
const key = name.slice(prefix.length, suffix ? -suffix.length : undefined);
|
|
200
|
+
if (name.startsWith(prefix) && name.endsWith(suffix) && /^[A-Za-z0-9_-]+$/.test(key)) return { ...binding, id, unit: contract.unit };
|
|
201
|
+
}
|
|
202
|
+
return null;
|
|
203
|
+
}
|