@nordhavnhq/beacon 0.0.0-stage → 0.4.0

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 CHANGED
@@ -1,3 +1,336 @@
1
- # Temporary Holding Version
1
+ # @nordhavnhq/beacon
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Typed client for the Nordhavn OS **content API**. Read and write a project's
4
+ node datasets from any website or app: headless-CMS style, and beyond.
5
+
6
+ Your site talks to project **nodes** over a small, key-authenticated REST
7
+ surface (`/api/content/*`). A **project API key** (`slk_...`) grants read and/or
8
+ write access to specific nodes and datasets. This package wraps that surface in
9
+ a fully typed client with built-in read caching.
10
+
11
+ - Zero dependencies, works in Node 18+ and the browser (the API sends permissive CORS).
12
+ - Dual ESM / CommonJS build, full TypeScript types.
13
+ - Read caching with TTL, automatic invalidation on writes, and a `clearCache()` method.
14
+
15
+ ## Install
16
+
17
+ Published on npmjs:
18
+
19
+ ```bash
20
+ npm install @nordhavnhq/beacon
21
+ ```
22
+
23
+ ## Quick start
24
+
25
+ ```ts
26
+ import { createClient } from '@nordhavnhq/beacon'
27
+
28
+ const studio = createClient({
29
+ apiKey: process.env.HAVEN_API_KEY!, // slk_...
30
+ // baseUrl defaults to https://beacon.nordhavn.ai;
31
+ // set it only for a self-hosted server:
32
+ // baseUrl: 'https://studio.example.com',
33
+ })
34
+
35
+ // Discover what this key can reach.
36
+ const { nodes } = await studio.schema()
37
+
38
+ // List records from a dataset.
39
+ const posts = await studio.listRecords('blog', 'posts')
40
+
41
+ // Or use the fluent, typed handle.
42
+ interface Post { title: string, slug: string, body: string, published: boolean }
43
+ const blog = studio.dataset<Post>('blog', 'posts')
44
+
45
+ const all = await blog.list()
46
+ const one = await blog.get('rec_abc123')
47
+ const created = await blog.create({ title: 'Hello', slug: 'hello', body: '...', published: true })
48
+ const updated = await blog.update('rec_abc123', { published: false })
49
+ ```
50
+
51
+ Each record is `{ uid, data, createdAt, updatedAt }`, where `data` is keyed by
52
+ field slug with references (files, referenced records) already inflated.
53
+
54
+ ## Authentication & scopes
55
+
56
+ Pass the project API key as `apiKey`. A key's reach is the union of its per-node
57
+ scopes (read and/or write, optionally narrowed to specific datasets). Calls
58
+ outside the key's scope throw a `HavenError` with `status` 403; an
59
+ unknown node/dataset/record throws 404.
60
+
61
+ ```ts
62
+ import { HavenError } from '@nordhavnhq/beacon'
63
+
64
+ try {
65
+ await studio.getRecord('blog', 'posts', 'nope')
66
+ } catch (err) {
67
+ if (err instanceof HavenError && err.isNotFound) {
68
+ // handle missing record
69
+ }
70
+ }
71
+ ```
72
+
73
+ ## Introspection
74
+
75
+ `schema()` returns every node the key can reach, the datasets within, each
76
+ dataset's field schema, and `canRead` / `canWrite` flags so a site can adapt to
77
+ its access without hardcoding slugs.
78
+
79
+ ```ts
80
+ for (const node of await studio.nodes()) {
81
+ for (const ds of node.datasets) {
82
+ console.log(node.slug, ds.slug, ds.canWrite ? '(writable)' : '(read-only)')
83
+ }
84
+ }
85
+ ```
86
+
87
+ ## Localisation
88
+
89
+ If the project has multiple languages, request one on reads. Untranslated fields
90
+ fall back to the project's default (source) language automatically, so a
91
+ partly-translated site never shows blanks.
92
+
93
+ ```ts
94
+ // List the languages the project offers (default first).
95
+ const locales = await studio.locales()
96
+ // [{ code: 'nl-BE', label: 'Dutch (Belgium)', isDefault: true, isFallback: false },
97
+ // { code: 'en-US', label: 'English (US)', isDefault: false, isFallback: true }]
98
+
99
+ // A client-wide default locale for every read:
100
+ const en = createClient({ apiKey: 'slk_...', locale: 'en-US' })
101
+ const posts = await en.dataset('blog', 'posts').list()
102
+
103
+ // ...or per call, overriding the client locale:
104
+ const fr = await studio.listRecords('blog', 'posts', { locale: 'fr-BE' })
105
+ const one = await studio.getRecord('blog', 'posts', 'R12AB34C', { locale: 'nl-BE' })
106
+ ```
107
+
108
+ Each locale is cached separately, so switching languages never serves the wrong
109
+ one. Pass `locale: ''` on a call to force the project default even when a
110
+ client-level `locale` is set.
111
+
112
+ ### How a requested locale resolves
113
+
114
+ You can pass the visitor's **detected** locale verbatim (e.g. from
115
+ `Accept-Language`); the studio resolves it server-side, so you never have to map
116
+ it to a configured code yourself:
117
+
118
+ 1. **Exact match** first (`nl-BE` -> `nl-BE`).
119
+ 2. **Base-language match**: `nl` and `nl-NL` resolve to a configured `nl-BE`;
120
+ `en`, `en-GB`, `en-AU` resolve to `en-US`. So the project only needs one
121
+ regional variant per language.
122
+ 3. **No match** (a language the project doesn't offer, e.g. a German visitor):
123
+ the project's **fallback** locale is served if one is set (the entry with
124
+ `isFallback: true`), otherwise the default. This lets a Dutch-authored site
125
+ (default `nl-BE`) show English to unknown languages while Dutch visitors still
126
+ get the source.
127
+ 4. **No locale sent** (you omit it): the default/source language.
128
+
129
+ Within the chosen language, any field that isn't translated yet falls back to
130
+ the default language for that field, never a blank.
131
+
132
+ ```ts
133
+ // Framework example: forward whatever the visitor asked for.
134
+ const accept = request.headers.get('accept-language')?.split(',')[0] // e.g. 'de-DE'
135
+ const posts = await studio.listRecords('blog', 'posts', { locale: accept })
136
+ // German isn't offered -> the project's fallback (say en-US) comes back.
137
+ ```
138
+
139
+ ## Saved queries
140
+
141
+ Run a server-defined query (`queries.<slug>`) and get its result. The `shape`
142
+ tells you whether `value` is a `collection`, a `single` record, or a scalar
143
+ `value`.
144
+
145
+ ```ts
146
+ const result = await studio.query('featured-posts')
147
+ if (result.shape === 'collection') {
148
+ // result.value is an array of records
149
+ }
150
+ ```
151
+
152
+ ## Caching
153
+
154
+ Reads (`schema`, `listRecords`, `getRecord`, `query`) are cached in memory and
155
+ kept fresh by **conditional revalidation** - the site stays in sync with the
156
+ studio without you doing anything, and without a "publish" step.
157
+
158
+ How it stays fresh, cheaply:
159
+
160
+ - The studio publishes a tiny per-project **stamp** (`GET /api/content/version`)
161
+ that changes on every content edit. The client checks it at most once every
162
+ minute (one small request, no matter how many reads).
163
+ - While the stamp is unchanged, reads are served straight from cache - zero
164
+ network.
165
+ - When the stamp moves, the affected read is **revalidated** with its `ETag`
166
+ (`If-None-Match`): the studio answers `304 Not Modified` (keep the cached
167
+ value, no transfer) or `200` with the new content. So a change to one dataset
168
+ only refetches that dataset; everything else stays cached on a `304`.
169
+
170
+ What this buys you:
171
+
172
+ - **Edits go live on their own, within about a minute** for public visitors
173
+ (instantly in a surface preview) - a safe promise to a client is "live within
174
+ 10 minutes". No button, no
175
+ webhook, no cache to clear.
176
+ - **Resilient:** if the studio is unreachable, the last good value keeps being
177
+ served (a definitive `404`/`403`, e.g. a deleted record, is surfaced as an
178
+ error rather than masked).
179
+ - The **TTL (7 days default)** is the outage window, not the refresh interval:
180
+ how long the site keeps serving the last-known content while the studio is
181
+ unreachable. An entry that keeps revalidating stays alive, so in practice an
182
+ entry only expires ~`ttl` after the studio goes down.
183
+
184
+ Every knob is overridable:
185
+
186
+ ```ts
187
+ const studio = createClient({
188
+ apiKey, baseUrl,
189
+ // defaults: ttl 7d (outage window), revalidate 60s (stamp check), maxEntries 500
190
+ cache: { ttl: 604_800_000, revalidate: 60_000, maxEntries: 1000 },
191
+ })
192
+
193
+ // Survive an outage of any length - serve last-known until the studio returns:
194
+ createClient({ apiKey, baseUrl, cache: { ttl: 0 } })
195
+
196
+ // Pure TTL, never check the stamp (content can be up to `ttl` stale):
197
+ createClient({ apiKey, baseUrl, cache: { revalidate: false } })
198
+
199
+ // Disable caching entirely (every read hits the studio live):
200
+ createClient({ apiKey, baseUrl, cache: false })
201
+
202
+ // Bypass the cache for a single call (the fresh value still refreshes it):
203
+ await studio.listRecords('blog', 'posts', { cache: false })
204
+ ```
205
+
206
+ > Caching is safe to leave on everywhere, including local/dev frontends: because
207
+ > every read revalidates against the stamp, a cached dev site is still always in
208
+ > sync. There is no "dev bypasses, production caches" split to manage.
209
+
210
+ ### Preview requests
211
+
212
+ When the studio loads your site inside a surface preview it appends
213
+ `?sl-preview=…` to the URL. Pass the request through `forRequest()` and those
214
+ loads skip the cache completely, so an editor always sees their change
215
+ immediately:
216
+
217
+ ```ts
218
+ // Next.js app router
219
+ export default async function Page({ searchParams }) {
220
+ const studioForThisRequest = studio.forRequest(await searchParams)
221
+ const posts = await studioForThisRequest.dataset('blog', 'posts').list()
222
+ }
223
+
224
+ // Anything with a Request object
225
+ const posts = await studio.forRequest(request).dataset('blog', 'posts').list()
226
+ ```
227
+
228
+ `forRequest()` accepts a `Request`, a URL string or `URL`, `URLSearchParams`, or
229
+ a plain searchParams object, and returns this same client unchanged when the
230
+ marker is absent - so it is safe to call on every request. Preview reads share
231
+ the normal cache and refresh it, they do not maintain a second copy.
232
+
233
+ One caveat: this only bypasses **this client's** cache. If your page also sits
234
+ behind a CDN or a framework data cache, that layer needs the same treatment or
235
+ the editor still sees a stale page. In Next.js:
236
+
237
+ ```ts
238
+ import { isPreviewRequest } from '@nordhavnhq/beacon'
239
+
240
+ export const dynamic = 'force-dynamic' // or, per fetch: cache: 'no-store'
241
+ ```
242
+
243
+ ### Clearing the cache
244
+
245
+ ```ts
246
+ studio.clearCache() // everything
247
+ studio.clearCache('blog') // one node
248
+ studio.clearCache({ node: 'blog', dataset: 'posts' }) // one dataset
249
+ studio.dataset('blog', 'posts').clearCache() // same, fluent
250
+ ```
251
+
252
+ Bring your own store (share a cache across instances, or persist it) by
253
+ implementing `CacheStore` and passing it as `cache.store`.
254
+
255
+ ## API
256
+
257
+ | Method | Description |
258
+ | --- | --- |
259
+ | `schema(opts?)` | Full reachable content shape (`{ nodes }`). |
260
+ | `nodes(opts?)` | Shortcut for `schema().nodes`. |
261
+ | `listRecords<T>(node, dataset, opts?)` | All records in a dataset. |
262
+ | `getRecord<T>(node, dataset, uid, opts?)` | One record by uid. |
263
+ | `createRecord<T>(node, dataset, data)` | Create a record (needs write scope). |
264
+ | `updateRecord<T>(node, dataset, uid, data)` | Merge-patch a record (needs write scope). |
265
+ | `query<V>(slug, opts?)` | Run a saved query. |
266
+ | `dataset<T>(node, dataset)` | Fluent handle: `.list() .get() .create() .update() .clearCache()`. |
267
+ | `clearCache(scope?)` | Clear all, one node, or one dataset. |
268
+ | `forRequest(req)` | Cache-bypassing view of this client for studio preview requests. |
269
+ | `isPreview` | Whether this client came from a preview request. |
270
+
271
+ `opts` is `{ cache?: boolean }`. All read methods accept a row type parameter
272
+ `<T>` for `record.data`.
273
+
274
+ ## Chart contract
275
+
276
+ The shape of a chart block is part of the contract, so a site can render the
277
+ same charts the studio shows. Types and constants come from the main entry,
278
+ with no runtime dependencies:
279
+
280
+ ```ts
281
+ import type { ChartSpec, ChartData } from '@nordhavnhq/beacon'
282
+ import { CHART_TYPES, PALETTE_KEYS, AGGREGATIONS } from '@nordhavnhq/beacon'
283
+ ```
284
+
285
+ - `ChartSpec`: what a chart block stores (type, source, category field, series,
286
+ date bucket, sort, limit, gap filling, stacking, legend).
287
+ - `ChartData`: the consolidated result a renderer draws (categories plus one
288
+ value list per series).
289
+ - `PALETTE_KEYS`: the eight colour keys a series can use. A spec never holds a
290
+ raw colour; the renderer maps each key to a colour of its own theme.
291
+
292
+ To validate or fill in defaults, use the zod schema from a separate entry
293
+ (`zod` ^4 is an optional peer dependency, only needed for this entry):
294
+
295
+ ```ts
296
+ import { chartSpecSchema, DEFAULT_CHART_SPEC } from '@nordhavnhq/beacon/schema'
297
+
298
+ const spec = chartSpecSchema.parse(block.props)
299
+ ```
300
+
301
+ Two more shapes, plain types with no schema, for the roadmap and the
302
+ forecast chart of `@nordhavnhq/ui`:
303
+
304
+ - `RoadmapData`: a plan on a timeline (lanes with phases, milestones, what
305
+ waits on the viewer, tasks, repeats, happenings, events), with the tooltip
306
+ content (`RoadmapTip`) written by the host. All dates are ISO days.
307
+ - `ForecastSeries`: measured values per step, a forecast band
308
+ (`{ x, low, mid, high }`) and a target.
309
+
310
+ ## Node < 18
311
+
312
+ Global `fetch` is required. On older runtimes, pass one:
313
+
314
+ ```ts
315
+ import fetch from 'node-fetch'
316
+ createClient({ apiKey, baseUrl, fetch: fetch as unknown as typeof globalThis.fetch })
317
+ ```
318
+
319
+ ## Coming from `@justmade/client`
320
+
321
+ This package used to be published as `@justmade/client`. Those versions stay on
322
+ npm and keep working. To switch, install `@nordhavnhq/beacon` and change the import:
323
+
324
+ ```ts
325
+ import { createClient, HavenError } from '@nordhavnhq/beacon'
326
+ ```
327
+
328
+ `JustmadeClient`, `JustmadeClientOptions` and `JustmadeError` are still exported
329
+ as deprecated aliases of `HavenClient`, `HavenClientOptions` and `HavenError`,
330
+ and go in the next breaking release. One difference: an error's `name` is now
331
+ `'HavenError'`, so code that compares `err.name` must use the new name (or
332
+ `instanceof`).
333
+
334
+ ## License
335
+
336
+ MIT
@@ -0,0 +1,119 @@
1
+ /**
2
+ * The chart contract: what a chart block is (`ChartSpec`, as authored and
3
+ * stored) and what a renderer draws (`ChartData`, the resolved categories and
4
+ * series). Shared by the Nordhavn OS server, the client and every renderer, so a
5
+ * chart means the same thing wherever it is read. Pure data: no dependencies.
6
+ * The zod schemas for these shapes live in `@nordhavnhq/beacon/schema`.
7
+ */
8
+ /**
9
+ * The palette a series colour may pick from. A renderer maps a key to a colour
10
+ * of the theme it runs in; a spec never carries a raw hex.
11
+ */
12
+ declare const PALETTE_KEYS: readonly ["ember", "aurora", "crimson", "dusk", "jade", "cobalt", "iris", "nebula"];
13
+ type PaletteKey = typeof PALETTE_KEYS[number];
14
+ declare const CHART_TYPES: readonly ["bar", "bar-horizontal", "line", "area", "pie", "donut", "share", "heatmap"];
15
+ type ChartType = typeof CHART_TYPES[number];
16
+ /**
17
+ * How a chart reads its data: `cartesian` plots each series over the
18
+ * categories, `part` cuts one series into its categories (one whole), `matrix`
19
+ * is a grid of the categories (columns) by the series (rows).
20
+ */
21
+ type ChartFamily = 'cartesian' | 'part' | 'matrix';
22
+ /** What a chart type is and takes: every editor, parser and renderer reads it from here. */
23
+ interface ChartTypeInfo {
24
+ value: ChartType;
25
+ label: string;
26
+ /** One line on what the type is for (editor hint, agent docs). */
27
+ purpose: string;
28
+ /** A lucide icon name (kebab-case); the host maps it to its icon set. */
29
+ icon: string;
30
+ family: ChartFamily;
31
+ /** Exactly one series (the parts are the categories). */
32
+ singleSeries: boolean;
33
+ /** Series may sit on a left or right value axis. */
34
+ axes: boolean;
35
+ /** Series may stack. */
36
+ stacked: boolean;
37
+ /** Each series wears its own colour (else one hue in tints). */
38
+ seriesColors: boolean;
39
+ /** Value labels on the marks are possible. */
40
+ valueLabels: boolean;
41
+ /** Drawn as HTML that sizes to its content, not into a fixed canvas box. */
42
+ html: boolean;
43
+ /** Default box height in px. */
44
+ height: number;
45
+ }
46
+ declare const CHART_TYPE_INFO: Record<ChartType, ChartTypeInfo>;
47
+ declare function chartTypeInfo(type: ChartType): ChartTypeInfo;
48
+ /** Pie, donut and share: one series cut into its categories. */
49
+ declare function isPartChart(type: ChartType): boolean;
50
+ /** Bar in either direction. */
51
+ declare function isBarChart(type: ChartType): boolean;
52
+ /** Which Y axis a series scales against. Only for the types with `axes`. */
53
+ declare const CHART_AXES: readonly ["left", "right"];
54
+ type ChartAxis = typeof CHART_AXES[number];
55
+ /** Periods a date category can be grouped into. */
56
+ declare const DATE_BUCKET_VALUES: readonly ["day", "week", "month", "quarter", "year"];
57
+ type DateBucket = typeof DATE_BUCKET_VALUES[number];
58
+ /** `auto` picks the period from the date range. */
59
+ declare const BUCKET_MODES: readonly ["auto", "day", "week", "month", "quarter", "year"];
60
+ type BucketMode = typeof BUCKET_MODES[number];
61
+ /** How the records that fall in one category combine into one point. */
62
+ declare const AGGREGATIONS: readonly ["sum", "avg", "count", "min", "max", "first", "last"];
63
+ type Aggregation = typeof AGGREGATIONS[number];
64
+ /** Category order. `default` is chronological for dates, source order otherwise. */
65
+ declare const CHART_SORTS: readonly ["default", "category-asc", "category-desc", "value-desc", "value-asc"];
66
+ type ChartSort = typeof CHART_SORTS[number];
67
+ interface ChartSeriesSpec {
68
+ /** Field slug whose numeric value is the Y value. */
69
+ field: string;
70
+ label?: string;
71
+ /** Omitted: the next colour of the renderer's default rotation. */
72
+ color?: PaletteKey;
73
+ axis: ChartAxis;
74
+ aggregate: Aggregation;
75
+ }
76
+ /** A chart as authored and stored: where its data comes from and how it is shaped. */
77
+ interface ChartSpec {
78
+ title: string;
79
+ chartType: ChartType;
80
+ /** A dataset (`node.dataset`) or a saved query (`queries.<slug>`). */
81
+ source: string;
82
+ /** Field slug for the X axis or the slice labels. */
83
+ categoryField: string;
84
+ /**
85
+ * Field slug to split the first series by: one series per distinct value of
86
+ * this field (top 12 by record count, the rest as "Other"). The rows of a
87
+ * heatmap, the stacks of a bar. Empty: the series are the value fields.
88
+ */
89
+ splitField: string;
90
+ series: ChartSeriesSpec[];
91
+ /** Date categories only. */
92
+ bucket: BucketMode;
93
+ sort: ChartSort;
94
+ /** Keep the top N categories, the rest becomes "Other". 0 is no limit. Non-date only. */
95
+ limit: number;
96
+ /** Date buckets only: emit empty periods so a line stays continuous. */
97
+ fillGaps: boolean;
98
+ stacked: boolean;
99
+ legend: boolean;
100
+ }
101
+ interface ChartSeriesData {
102
+ name: string;
103
+ /** One value per category; null is a gap (nothing measured there). */
104
+ data: Array<number | null>;
105
+ /** A palette key or any CSS colour the host resolved. */
106
+ color?: string;
107
+ axis?: ChartAxis;
108
+ }
109
+ /** A chart as a renderer draws it: the data already resolved and consolidated. */
110
+ interface ChartData {
111
+ type: ChartType;
112
+ categories: string[];
113
+ series: ChartSeriesData[];
114
+ stacked?: boolean;
115
+ legend?: boolean;
116
+ }
117
+
118
+ export { AGGREGATIONS as A, BUCKET_MODES as B, DATE_BUCKET_VALUES as D, PALETTE_KEYS as P, CHART_AXES as c, CHART_SORTS as d, CHART_TYPES as e, CHART_TYPE_INFO as f, chartTypeInfo as q, isBarChart as r, isPartChart as s };
119
+ export type { ChartData as C, Aggregation as a, BucketMode as b, ChartAxis as g, ChartFamily as h, ChartSeriesData as i, ChartSeriesSpec as j, ChartSort as k, ChartSpec as l, ChartType as m, ChartTypeInfo as n, DateBucket as o, PaletteKey as p };
@@ -0,0 +1,119 @@
1
+ /**
2
+ * The chart contract: what a chart block is (`ChartSpec`, as authored and
3
+ * stored) and what a renderer draws (`ChartData`, the resolved categories and
4
+ * series). Shared by the Nordhavn OS server, the client and every renderer, so a
5
+ * chart means the same thing wherever it is read. Pure data: no dependencies.
6
+ * The zod schemas for these shapes live in `@nordhavnhq/beacon/schema`.
7
+ */
8
+ /**
9
+ * The palette a series colour may pick from. A renderer maps a key to a colour
10
+ * of the theme it runs in; a spec never carries a raw hex.
11
+ */
12
+ declare const PALETTE_KEYS: readonly ["ember", "aurora", "crimson", "dusk", "jade", "cobalt", "iris", "nebula"];
13
+ type PaletteKey = typeof PALETTE_KEYS[number];
14
+ declare const CHART_TYPES: readonly ["bar", "bar-horizontal", "line", "area", "pie", "donut", "share", "heatmap"];
15
+ type ChartType = typeof CHART_TYPES[number];
16
+ /**
17
+ * How a chart reads its data: `cartesian` plots each series over the
18
+ * categories, `part` cuts one series into its categories (one whole), `matrix`
19
+ * is a grid of the categories (columns) by the series (rows).
20
+ */
21
+ type ChartFamily = 'cartesian' | 'part' | 'matrix';
22
+ /** What a chart type is and takes: every editor, parser and renderer reads it from here. */
23
+ interface ChartTypeInfo {
24
+ value: ChartType;
25
+ label: string;
26
+ /** One line on what the type is for (editor hint, agent docs). */
27
+ purpose: string;
28
+ /** A lucide icon name (kebab-case); the host maps it to its icon set. */
29
+ icon: string;
30
+ family: ChartFamily;
31
+ /** Exactly one series (the parts are the categories). */
32
+ singleSeries: boolean;
33
+ /** Series may sit on a left or right value axis. */
34
+ axes: boolean;
35
+ /** Series may stack. */
36
+ stacked: boolean;
37
+ /** Each series wears its own colour (else one hue in tints). */
38
+ seriesColors: boolean;
39
+ /** Value labels on the marks are possible. */
40
+ valueLabels: boolean;
41
+ /** Drawn as HTML that sizes to its content, not into a fixed canvas box. */
42
+ html: boolean;
43
+ /** Default box height in px. */
44
+ height: number;
45
+ }
46
+ declare const CHART_TYPE_INFO: Record<ChartType, ChartTypeInfo>;
47
+ declare function chartTypeInfo(type: ChartType): ChartTypeInfo;
48
+ /** Pie, donut and share: one series cut into its categories. */
49
+ declare function isPartChart(type: ChartType): boolean;
50
+ /** Bar in either direction. */
51
+ declare function isBarChart(type: ChartType): boolean;
52
+ /** Which Y axis a series scales against. Only for the types with `axes`. */
53
+ declare const CHART_AXES: readonly ["left", "right"];
54
+ type ChartAxis = typeof CHART_AXES[number];
55
+ /** Periods a date category can be grouped into. */
56
+ declare const DATE_BUCKET_VALUES: readonly ["day", "week", "month", "quarter", "year"];
57
+ type DateBucket = typeof DATE_BUCKET_VALUES[number];
58
+ /** `auto` picks the period from the date range. */
59
+ declare const BUCKET_MODES: readonly ["auto", "day", "week", "month", "quarter", "year"];
60
+ type BucketMode = typeof BUCKET_MODES[number];
61
+ /** How the records that fall in one category combine into one point. */
62
+ declare const AGGREGATIONS: readonly ["sum", "avg", "count", "min", "max", "first", "last"];
63
+ type Aggregation = typeof AGGREGATIONS[number];
64
+ /** Category order. `default` is chronological for dates, source order otherwise. */
65
+ declare const CHART_SORTS: readonly ["default", "category-asc", "category-desc", "value-desc", "value-asc"];
66
+ type ChartSort = typeof CHART_SORTS[number];
67
+ interface ChartSeriesSpec {
68
+ /** Field slug whose numeric value is the Y value. */
69
+ field: string;
70
+ label?: string;
71
+ /** Omitted: the next colour of the renderer's default rotation. */
72
+ color?: PaletteKey;
73
+ axis: ChartAxis;
74
+ aggregate: Aggregation;
75
+ }
76
+ /** A chart as authored and stored: where its data comes from and how it is shaped. */
77
+ interface ChartSpec {
78
+ title: string;
79
+ chartType: ChartType;
80
+ /** A dataset (`node.dataset`) or a saved query (`queries.<slug>`). */
81
+ source: string;
82
+ /** Field slug for the X axis or the slice labels. */
83
+ categoryField: string;
84
+ /**
85
+ * Field slug to split the first series by: one series per distinct value of
86
+ * this field (top 12 by record count, the rest as "Other"). The rows of a
87
+ * heatmap, the stacks of a bar. Empty: the series are the value fields.
88
+ */
89
+ splitField: string;
90
+ series: ChartSeriesSpec[];
91
+ /** Date categories only. */
92
+ bucket: BucketMode;
93
+ sort: ChartSort;
94
+ /** Keep the top N categories, the rest becomes "Other". 0 is no limit. Non-date only. */
95
+ limit: number;
96
+ /** Date buckets only: emit empty periods so a line stays continuous. */
97
+ fillGaps: boolean;
98
+ stacked: boolean;
99
+ legend: boolean;
100
+ }
101
+ interface ChartSeriesData {
102
+ name: string;
103
+ /** One value per category; null is a gap (nothing measured there). */
104
+ data: Array<number | null>;
105
+ /** A palette key or any CSS colour the host resolved. */
106
+ color?: string;
107
+ axis?: ChartAxis;
108
+ }
109
+ /** A chart as a renderer draws it: the data already resolved and consolidated. */
110
+ interface ChartData {
111
+ type: ChartType;
112
+ categories: string[];
113
+ series: ChartSeriesData[];
114
+ stacked?: boolean;
115
+ legend?: boolean;
116
+ }
117
+
118
+ export { AGGREGATIONS as A, BUCKET_MODES as B, DATE_BUCKET_VALUES as D, PALETTE_KEYS as P, CHART_AXES as c, CHART_SORTS as d, CHART_TYPES as e, CHART_TYPE_INFO as f, chartTypeInfo as q, isBarChart as r, isPartChart as s };
119
+ export type { ChartData as C, Aggregation as a, BucketMode as b, ChartAxis as g, ChartFamily as h, ChartSeriesData as i, ChartSeriesSpec as j, ChartSort as k, ChartSpec as l, ChartType as m, ChartTypeInfo as n, DateBucket as o, PaletteKey as p };