@adobe/design-data 2.0.0 → 2.0.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/design-data",
3
- "version": "2.0.0",
3
+ "version": "2.0.1",
4
4
  "description": "Node.js helpers for @adobe/design-data-wasm: filesystem dataset loading, token write operations, and authoring-session management",
5
5
  "type": "module",
6
6
  "main": "./src/index.js",
@@ -43,7 +43,7 @@
43
43
  "dependencies": {
44
44
  "ajv": "^8.17.1",
45
45
  "ajv-formats": "^3.0.1",
46
- "@adobe/design-data-wasm": "0.1.0"
46
+ "@adobe/design-data-wasm": "0.2.0"
47
47
  },
48
48
  "devDependencies": {
49
49
  "ava": "^6.1.2"
package/src/load.js CHANGED
@@ -86,6 +86,19 @@ export async function loadDataset(dirPath) {
86
86
  return Dataset.fromTokens(tokens);
87
87
  }
88
88
 
89
+ /**
90
+ * Build a Dataset directly from an already-parsed token array.
91
+ * Use this when the caller has already read and parsed the token files to avoid
92
+ * a second filesystem pass.
93
+ *
94
+ * @param {object[]} tokens - Flat array of cascade-format token objects.
95
+ * @returns {Promise<import('@adobe/design-data-wasm').Dataset>}
96
+ */
97
+ export async function buildDataset(tokens) {
98
+ const { Dataset } = await getWasm();
99
+ return Dataset.fromTokens(tokens);
100
+ }
101
+
89
102
  /**
90
103
  * Synchronous variant using the already-loaded wasm module.
91
104
  * The caller is responsible for ensuring the module is initialised first.
package/src/validate.js CHANGED
@@ -26,7 +26,7 @@ import { readFileSync, readdirSync, existsSync } from "node:fs";
26
26
  import { join, dirname } from "node:path";
27
27
  import Ajv from "ajv/dist/2020.js";
28
28
  import addFormats from "ajv-formats";
29
- import { loadDataset, walkTokenFiles } from "./load.js";
29
+ import { buildDataset, walkTokenFiles } from "./load.js";
30
30
 
31
31
  // ---------------------------------------------------------------------------
32
32
  // Schema directory resolution
@@ -220,8 +220,10 @@ export async function validateDataset(
220
220
  const ajv = loadSchemaValidator(resolvedSchemaDir);
221
221
  const layer1Errors = [];
222
222
 
223
- // Walk token files and validate each token's $schema.
223
+ // Walk token files, validate each token's $schema, and accumulate parsed tokens
224
+ // so Layer-2 can reuse the same data without a second filesystem pass.
224
225
  const tokenFiles = walkTokenFiles(datasetPath);
226
+ const allTokens = [];
225
227
  for (const file of tokenFiles) {
226
228
  let parsed;
227
229
  try {
@@ -234,15 +236,15 @@ export async function validateDataset(
234
236
  continue;
235
237
  }
236
238
  if (!Array.isArray(parsed)) continue; // Legacy object-map format — loadDataset (Layer-2) warns and skips these.
237
- const tokens = parsed;
238
- for (const token of tokens) {
239
+ allTokens.push(...parsed);
240
+ for (const token of parsed) {
239
241
  const diags = validateTokenSchema(token, ajv, file);
240
242
  layer1Errors.push(...diags);
241
243
  }
242
244
  }
243
245
 
244
- // Layer-2: relational rules via wasm.
245
- const ds = await loadDataset(datasetPath);
246
+ // Layer-2: relational rules via wasm — built from already-parsed tokens.
247
+ const ds = await buildDataset(allTokens);
246
248
  const layer2Result = ds.validate();
247
249
 
248
250
  const allErrors = [