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.vue.md
View on GitHub<!-- Generated by `yarn build:skills` from docs/rest/shared/_ScalarDemo.mdx (vue). 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 }),
}),
});
```
```html title="CompanyGrid.vue"
<script setup lang="ts">
import { type Company } from './api/Company';
defineProps<{ companies: readonly Company[] }>();
function formatPercent(value: number) {
return `${(value * 100).toFixed(1)}%`;
}
</script>
<template>
<table>
<thead>
<tr>
<th>Name</th>
<th class="value">Price</th>
<th class="value">% Equity</th>
<th class="value">Shares</th>
</tr>
</thead>
<tbody>
<tr v-for="c in companies" :key="c.pk()">
<td>{{ c.name }}</td>
<td class="value">${{ c.price.toFixed(2) }}</td>
<td class="value">
<span v-if="c.pct_equity === undefined" class="skeleton" />
<template v-else>{{ formatPercent(c.pct_equity) }}</template>
</td>
<td class="value">
<span v-if="c.shares === undefined" class="skeleton" />
<template v-else>{{ c.shares.toLocaleString() }}</template>
</td>
</tr>
</tbody>
</table>
</template>
```
```html title="PortfolioGrid.vue"
<script setup lang="ts">
import { ref } from 'vue';
import { useSuspense, useFetch } from '@data-client/vue';
import { getCompanies, getPortfolioColumns } from './api/Company';
import CompanyGrid from './CompanyGrid.vue';
const portfolio = ref('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 = await useSuspense(getCompanies, () => ({
portfolio: portfolio.value,
}));
// The first `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 = portfolio.value;
useFetch(getPortfolioColumns, () =>
portfolio.value === firstPortfolio ? null : { portfolio: portfolio.value },
);
</script>
<template>
<div>
<label>
Portfolio:
<select v-model="portfolio">
<option value="A">Portfolio A</option>
<option value="B">Portfolio B</option>
</select>
</label>
<CompanyGrid :companies="companies" />
</div>
</template>
```
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 |