@adobe/design-data-wasm 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.
@@ -0,0 +1,439 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ /**
4
+ * A list of suggestion results from `Dataset.suggest()`. Typed as `SuggestResult[]` in TypeScript.
5
+ */
6
+ export type SuggestResultArray = SuggestResult[];
7
+
8
+ /**
9
+ * A list of token results from a query. Typed as `TokenResult[]` in TypeScript.
10
+ */
11
+ export type TokenResultArray = TokenResult[];
12
+
13
+ /**
14
+ * A mode-set context for token resolution.
15
+ *
16
+ * Maps mode-set names (e.g. `\"colorScheme\"`, `\"scale\"`) to their active mode
17
+ * values (e.g. `\"dark\"`, `\"medium\"`).
18
+ *
19
+ * ```ts
20
+ * const result = ds.resolve(\"background\", { colorScheme: \"dark\", scale: \"medium\" });
21
+ * ```
22
+ */
23
+ export type ResolutionContext = Map<string, string>;
24
+
25
+ /**
26
+ * A registry vocabulary object as read from `registry/*.json`.
27
+ */
28
+ export interface RegistryObject {
29
+ values: RegistryEntry[];
30
+ }
31
+
32
+ /**
33
+ * A single entry in a registry vocabulary (e.g. a size, state, or variant).
34
+ *
35
+ * Mirrors the shape of each object in `registry/*.json#values`.
36
+ */
37
+ export interface RegistryEntry {
38
+ id: string;
39
+ label?: string;
40
+ description?: string;
41
+ aliases?: string[];
42
+ default?: boolean;
43
+ deprecated?: boolean;
44
+ }
45
+
46
+ /**
47
+ * A single key→value change within a token\'s properties.
48
+ */
49
+ export interface PropertyChange {
50
+ path: string;
51
+ changeType: string;
52
+ newValue?: Value;
53
+ originalValue?: Value;
54
+ }
55
+
56
+ /**
57
+ * A single ranked suggestion result from `Dataset.suggest()`.
58
+ */
59
+ export interface SuggestResult {
60
+ tokenUuid?: string;
61
+ tokenName: string;
62
+ file: string;
63
+ layer: string;
64
+ confidence: number;
65
+ nameObject?: Value;
66
+ value?: Value;
67
+ }
68
+
69
+ /**
70
+ * A single resolved token result from `Dataset.resolve()`.
71
+ */
72
+ export interface ResolveResult {
73
+ token: TokenResult;
74
+ specificity: number;
75
+ }
76
+
77
+ /**
78
+ * A single validation diagnostic.
79
+ */
80
+ export interface Diagnostic {
81
+ severity: Severity;
82
+ message: string;
83
+ ruleId?: string;
84
+ path?: string;
85
+ }
86
+
87
+ /**
88
+ * A token record as returned by query results.
89
+ *
90
+ * Reflects `design_data_core::graph::TokenRecord` — the canonical token object
91
+ * including its `name`, `value`, `uuid`, `$schema`, etc. in `raw`.
92
+ */
93
+ export interface TokenResult {
94
+ name: string;
95
+ /**
96
+ * The token\'s full source JSON (all fields: name, value, uuid, $schema, etc.)
97
+ */
98
+ raw: Value;
99
+ uuid?: string;
100
+ schemaUrl?: string;
101
+ aliasTarget?: string;
102
+ layer: string;
103
+ }
104
+
105
+ /**
106
+ * A token that gained a `deprecated` marker.
107
+ */
108
+ export interface DeprecatedToken {
109
+ name: string;
110
+ uuid?: string;
111
+ }
112
+
113
+ /**
114
+ * A token that had its `deprecated` marker removed.
115
+ */
116
+ export interface RevertedToken {
117
+ name: string;
118
+ uuid?: string;
119
+ }
120
+
121
+ /**
122
+ * A token that had property-level changes (same name, same UUID).
123
+ */
124
+ export interface UpdatedToken {
125
+ name: string;
126
+ uuid?: string;
127
+ propertyChanges: PropertyChange[];
128
+ }
129
+
130
+ /**
131
+ * A token that was added.
132
+ */
133
+ export interface AddedToken {
134
+ name: string;
135
+ uuid?: string;
136
+ }
137
+
138
+ /**
139
+ * A token that was deleted.
140
+ */
141
+ export interface DeletedToken {
142
+ name: string;
143
+ uuid?: string;
144
+ }
145
+
146
+ /**
147
+ * A token that was renamed (same UUID, different name).
148
+ */
149
+ export interface RenamedToken {
150
+ oldName: string;
151
+ newName: string;
152
+ uuid?: string;
153
+ propertyChanges: PropertyChange[];
154
+ }
155
+
156
+ /**
157
+ * Severity level of a validation diagnostic.
158
+ */
159
+ export type Severity = "error" | "warning" | "info";
160
+
161
+ /**
162
+ * The result of `Dataset.diff()`.
163
+ *
164
+ * Mirrors `design_data_core::diff::DiffReport` with typed arrays for each change category.
165
+ */
166
+ export interface DiffResult {
167
+ renamed: RenamedToken[];
168
+ deprecated: DeprecatedToken[];
169
+ reverted: RevertedToken[];
170
+ added: AddedToken[];
171
+ deleted: DeletedToken[];
172
+ updated: UpdatedToken[];
173
+ }
174
+
175
+ /**
176
+ * The result of `Dataset.resolveReference()`.
177
+ *
178
+ * Contains the resolved terminal value and the full chain of names/references
179
+ * traversed to reach it — mirrors the `getResolutionChain()` behaviour from
180
+ * the legacy inline `TokenResolver` in `docs/s2-tokens-viewer/index.html`.
181
+ *
182
+ * ```ts
183
+ * const r = ds.resolveReference(\"{accent-color-100}\", { colorScheme: \"light\" });
184
+ * // r.chain → [\"{accent-color-100}\", \"{blue-100}\", \"rgb(245, 249, 255)\"]
185
+ * // r.value → \"rgb(245, 249, 255)\
186
+ * ```
187
+ */
188
+ export interface ReferenceChainResult {
189
+ /**
190
+ * The resolved terminal value (absent if the chain is empty or all aliases dangle).
191
+ */
192
+ value?: Value;
193
+ /**
194
+ * Ordered list from original reference → intermediate names → final value string.
195
+ */
196
+ chain: string[];
197
+ }
198
+
199
+ /**
200
+ * The result of `Dataset.validate()`.
201
+ */
202
+ export interface ValidationResult {
203
+ valid: boolean;
204
+ errors: Diagnostic[];
205
+ warnings: Diagnostic[];
206
+ }
207
+
208
+
209
+ /**
210
+ * A loaded token dataset you can query, validate, resolve, and diff.
211
+ *
212
+ * ```js
213
+ * import init, { Dataset } from "@adobe/design-data-wasm";
214
+ * await init();
215
+ *
216
+ * // Use the canonical embedded Spectrum dataset:
217
+ * const ds = Dataset.embedded();
218
+ * const results = ds.query("property=color,colorScheme=dark");
219
+ *
220
+ * // Or load your own tokens:
221
+ * const tokens = await fetch("/tokens.json").then(r => r.json());
222
+ * const ds2 = Dataset.fromTokens(tokens);
223
+ * ```
224
+ */
225
+ export class Dataset {
226
+ private constructor();
227
+ free(): void;
228
+ [Symbol.dispose](): void;
229
+ /**
230
+ * Compute the semantic diff between this dataset and another.
231
+ *
232
+ * Returns a [`DiffResult`] with arrays of renamed, deprecated, reverted, added,
233
+ * deleted, and updated tokens.
234
+ *
235
+ * ```js
236
+ * const oldDs = Dataset.fromTokens(oldTokens);
237
+ * const newDs = Dataset.fromTokens(newTokens);
238
+ * const diff = oldDs.diff(newDs);
239
+ * console.log(`${diff.added.length} tokens added`);
240
+ * ```
241
+ */
242
+ diff(other: Dataset): DiffResult;
243
+ /**
244
+ * Open the canonical embedded Spectrum dataset from the prebuilt cache.
245
+ *
246
+ * The cache is opened once and reused; subsequent calls are cheap.
247
+ *
248
+ * Throws if the embedded cache was not generated (run `moon run sdk-wasm:cache-build`).
249
+ */
250
+ static embedded(): Dataset;
251
+ /**
252
+ * Build a dataset from an array of raw token JSON objects.
253
+ *
254
+ * Accepts the same format as the cascade token JSON files — an array of token
255
+ * objects each with a `name` object (e.g. `{ "name": { "property": "..." }, "value": ... }`).
256
+ *
257
+ * ```js
258
+ * const tokens = await fetch("/spectrum-tokens.json").then(r => r.json());
259
+ * const ds = Dataset.fromTokens(tokens);
260
+ * ```
261
+ */
262
+ static fromTokens(tokens_json: any): Dataset;
263
+ /**
264
+ * Emit a structural overview of the dataset for agent session start.
265
+ *
266
+ * Returns a plain JS object with the same shape as `design-data primer --format json`:
267
+ * `{ specVersion, tokenCount, modeSets, components, taxonomyFields, manifest, provenance }`.
268
+ *
269
+ * For the embedded Spectrum dataset (`Dataset.embedded()`), `taxonomyFields` and
270
+ * `manifest` are baked into the prebuilt `.redb` blob by the `cache-build` task.
271
+ * For in-memory datasets (`Dataset.fromTokens()`), both are empty / null.
272
+ *
273
+ * `provenance.source` is:
274
+ * - `"embedded"` when created via `Dataset.embedded()` (includes `designDataVersion`)
275
+ * - `"in-memory"` when created via `Dataset.fromTokens()`
276
+ */
277
+ primer(): any;
278
+ /**
279
+ * Filter tokens using a query expression.
280
+ *
281
+ * **Syntax:** `key=value` pairs separated by `,` (AND) or `|` (OR).
282
+ * Use `!=` for negation and `*` as a wildcard suffix or prefix.
283
+ * Valid keys: `property`, `component`, `variant`, `state`, `colorScheme`,
284
+ * `scale`, `contrast`, `uuid`, `$schema`.
285
+ *
286
+ * ```js
287
+ * const results = ds.query("property=color,colorScheme=dark");
288
+ * const all = ds.query(""); // returns all tokens
289
+ * ```
290
+ */
291
+ query(filter_expr: string): TokenResultArray;
292
+ /**
293
+ * Resolve a token for a given property in a specific context.
294
+ *
295
+ * The `context` object maps mode-set names to their active mode values —
296
+ * e.g. `{ colorScheme: "dark", scale: "medium" }`.
297
+ *
298
+ * Returns the winning token record plus its specificity, or `undefined` if
299
+ * no token matches the property+context combination.
300
+ *
301
+ * ```js
302
+ * const result = ds.resolve("background", { colorScheme: "dark", scale: "medium" });
303
+ * if (result) console.log(result.token.raw.value);
304
+ * ```
305
+ */
306
+ resolve(property: string, context: ResolutionContext): ResolveResult | undefined;
307
+ /**
308
+ * Resolve a legacy token reference by slug in a given context, returning
309
+ * the terminal value and the full alias chain.
310
+ *
311
+ * Bridges the legacy *object-map* slug model used by `docs/s2-tokens-viewer`
312
+ * to the cascade dataset. The wasm `resolve()` method resolves by *property*
313
+ * name in a mode-set context; this method resolves by *legacy slug* and a flat
314
+ * context map matching name-object fields.
315
+ *
316
+ * Context keys mirror cascade name-object fields:
317
+ * - `{ colorScheme: "light" | "dark" | "wireframe" }`
318
+ * - `{ scale: "desktop" | "mobile" }`
319
+ *
320
+ * The candidate with the most matching context fields wins; tie-breaking is
321
+ * stable (secondary sort by uuid ascending). When an alias chain passes through
322
+ * a set-level UUID, the context-appropriate child is selected so that e.g.
323
+ * `{accent-color-900}` under `{ colorScheme: "dark" }` correctly resolves to
324
+ * the dark variant of `{blue-900}`.
325
+ *
326
+ * Dangling aliases (a `$ref` target absent from the embedded dataset) are
327
+ * handled gracefully: the walk stops and the partial chain is returned with
328
+ * `value: undefined`.
329
+ *
330
+ * ```js
331
+ * const r = ds.resolveReference("{accent-color-100}", { colorScheme: "light" });
332
+ * // r.chain → ["{accent-color-100}", "{blue-100}", "rgb(245, 249, 255)"]
333
+ * // r.value → "rgb(245, 249, 255)"
334
+ * ```
335
+ */
336
+ resolveReference(token_ref: string, context: ResolutionContext): ReferenceChainResult | undefined;
337
+ /**
338
+ * Rank existing tokens by similarity to a natural-language `intent` string.
339
+ *
340
+ * Uses Jaccard similarity over the bag-of-words formed from each token's
341
+ * key segments, name-object field values, and description text. Optionally
342
+ * filter to tokens matching a specific `propertyHint` (e.g. `"color"`).
343
+ *
344
+ * ```js
345
+ * const results = ds.suggest("primary button background", undefined, 5);
346
+ * ```
347
+ */
348
+ suggest(intent: string, property_hint: string | null | undefined, limit: number): SuggestResultArray;
349
+ /**
350
+ * Return the number of tokens in the dataset.
351
+ */
352
+ tokenCount(): number;
353
+ /**
354
+ * Run relational validation rules over the dataset.
355
+ *
356
+ * Returns a [`ValidationResult`] with `valid`, `errors`, and `warnings`.
357
+ * This runs the same rules as `design-data validate` but without structural
358
+ * (JSON Schema) checks — those require filesystem access unavailable in wasm.
359
+ *
360
+ * ```js
361
+ * const result = ds.validate();
362
+ * if (!result.valid) console.error(result.errors);
363
+ * ```
364
+ */
365
+ validate(): ValidationResult;
366
+ }
367
+
368
+ /**
369
+ * Find a registry entry by its ID or one of its aliases.
370
+ *
371
+ * Returns `undefined` if not found.
372
+ * Equivalent to `@adobe/design-system-registry`'s `findValue(registry, searchTerm)`.
373
+ */
374
+ export function findValue(registry: any, search_term: string): any;
375
+
376
+ /**
377
+ * Return all non-deprecated value entries.
378
+ *
379
+ * Equivalent to `@adobe/design-system-registry`'s `getActiveValues(registry)`.
380
+ */
381
+ export function getActiveValues(registry: any): any;
382
+
383
+ /**
384
+ * Return the list of advisory field names (fields whose values are informational,
385
+ * not normative — e.g. `"variant"`, `"state"`).
386
+ */
387
+ export function getAdvisoryFields(): string[];
388
+
389
+ /**
390
+ * Return the default value entry, or `undefined` if none is marked as default.
391
+ *
392
+ * Equivalent to `@adobe/design-system-registry`'s `getDefault(registry)`.
393
+ */
394
+ export function getDefault(registry: any): any;
395
+
396
+ /**
397
+ * Return all IDs (and aliases) registered for a given field name.
398
+ *
399
+ * `fieldName` should be the canonical field key as used in token `name` objects —
400
+ * e.g. `"property"`, `"component"`, `"variant"`, `"state"`.
401
+ *
402
+ * Returns `undefined` if the field is not in the embedded registry.
403
+ */
404
+ export function getFieldValues(field_name: string): string[] | undefined;
405
+
406
+ /**
407
+ * Return the list of field names that can be used as filter keys in query
408
+ * expressions (e.g. `"property"`, `"component"`, `"$schema"`).
409
+ *
410
+ * This is the canonical set maintained in `design_data_core::query::ALLOWED_KEYS`,
411
+ * exposed here so callers do not need to hard-code it.
412
+ */
413
+ export function getIndexedFields(): string[];
414
+
415
+ /**
416
+ * Return all value IDs from a registry vocabulary object.
417
+ *
418
+ * Equivalent to `@adobe/design-system-registry`'s `getValues(registry)`.
419
+ */
420
+ export function getValues(registry: any): string[];
421
+
422
+ /**
423
+ * Return `true` if `value` (an ID or alias) is registered for `fieldName`.
424
+ */
425
+ export function hasFieldValue(field_name: string, value: string): boolean;
426
+
427
+ /**
428
+ * Return `true` if `searchTerm` matches any value ID or alias in the registry.
429
+ *
430
+ * Equivalent to `@adobe/design-system-registry`'s `hasValue(registry, searchTerm)`.
431
+ */
432
+ export function hasValue(registry: any, search_term: string): boolean;
433
+
434
+ /**
435
+ * Initialise the panic hook so that Rust panics are forwarded to the browser console.
436
+ *
437
+ * Call this once when the wasm module loads. Idempotent.
438
+ */
439
+ export function init(): void;