reactive/data-client / .agents/skills/data-client-schema
data-client-schema
VerifiedModel the app's data with @data-client schemas, which normalize responses into one shared cache so an update shows everywhere. Use it whenever an endpoint returning data is added or its response changes (resource, RestEndpoint, GraphQL, Endpoint), when the data's shape changes, when data from different endpoints must be joined or related, when deriving views from loaded data, or when one item looks different in two places. Covers Entity, GQLEntity, Collection, Union and Query.
references/_ScalarDemo.md
View on GitHub<!-- Generated by `yarn build:skills` from docs/rest/shared/_ScalarDemo.mdx (react). Edit the source doc, not this file. -->
```ts title="api/Company" {11-20,26-28,34-36}
import { Collection, Entity, RestEndpoint, Scalar } from '@data-client/rest';
export class Company extends Entity {
id = '';
name = '';
price = 0;
pct_equity = 0;
shares = 0;
}
const PortfolioScalar = new Scalar({
lens: args => args[0]?.portfolio,
key: 'portfolio',
entity: Company,
});
Company.schema = {
pct_equity: PortfolioScalar,
shares: PortfolioScalar,
};
export const getCompanies = new RestEndpoint({
path: '/companies',
searchParams: {} as { portfolio: string },
// `portfolio` is a lens, not a filter — the returned Company list is the same
// regardless of lens. Dropping it from `argsKey` collapses every portfolio to
// one Collection pk, so `Collection.queryKey()` finds the list on every
// switch and `useSuspense` reuses it without refetching.
schema: new Collection([Company], { argsKey: () => ({}) }),
});
export const getPortfolioColumns = new RestEndpoint({
path: '/companies/columns',
searchParams: {} as { portfolio: string },
schema: new Collection([PortfolioScalar], {
argsKey: ({ portfolio }: { portfolio: string }) => ({ portfolio }),
}),
});
```
```tsx title="CompanyGrid"
import { type Company } from './api/Company';
export default function CompanyGrid({ companies }: { companies: Company[] }) {
return (
<table>
<thead>
<tr>
<th>Name</th>
<th className="value">Price</th>
<th className="value">% Equity</th>
<th className="value">Shares</th>
</tr>
</thead>
<tbody>
{companies.map(c => (
<tr key={c.pk()}>
<td>{c.name}</td>
<td className="value">${c.price.toFixed(2)}</td>
<td className="value">
{c.pct_equity === undefined ?
<span className="skeleton" />
: formatPercent(c.pct_equity)}
</td>
<td className="value">
{c.shares === undefined ?
<span className="skeleton" />
: c.shares.toLocaleString()}
</td>
</tr>
))}
</tbody>
</table>
);
}
function formatPercent(value: number) {
return `${(value * 100).toFixed(1)}%`;
}
```
```tsx title="PortfolioGrid"
import React from 'react';
import { useSuspense, useFetch } from '@data-client/react';
import { getCompanies, getPortfolioColumns } from './api/Company';
import CompanyGrid from './CompanyGrid';
function PortfolioGrid() {
const [portfolio, setPortfolio] = React.useState('A');
// Fetches on first render, then re-denormalizes from cache on every
// portfolio switch. The Collection's `queryKey()` ignores `portfolio`,
// so there is no endpoint refetch on switch.
const companies = useSuspense(getCompanies, { portfolio });
// The first render's `useSuspense` already populated `Scalar(portfolio)`
// for `firstPortfolio`, so we only fetch columns when the user switches
// away. `useFetch` then dedupes later revisits via its endpoint cache.
const firstPortfolio = React.useRef(portfolio).current;
useFetch(
getPortfolioColumns,
portfolio === firstPortfolio ? null : { portfolio },
);
return (
<div>
<label>
Portfolio:{' '}
<select
value={portfolio}
onChange={e => setPortfolio(e.currentTarget.value)}
>
<option value="A">Portfolio A</option>
<option value="B">Portfolio B</option>
</select>
</label>
<CompanyGrid companies={companies} />
</div>
);
}
render(<PortfolioGrid />);
```
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| slack-gif-creatoranthropics/skillsKnowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request animated GIFs for Slack like "make me a GIF of X doing Y for Slack." | Stars: 197k | Updated | Claude CodeCodex | Verified | Install |
| ponytailDietrichGebert/ponytailLazy senior dev mode for any coding task: the smallest change that fully solves it, and a reply a busy human understands in one read. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-debtDietrichGebert/ponytailList every `shortcut:` comment (and older `ponytail:` ones) as a debt ledger. One-shot report, changes nothing. Use for "ponytail debt", "what did ponytail defer", "list the shortcuts", /ponytail-debt. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |