From d706bb7c8da11e0641aa1b16dc8872086ca1c428 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Wed, 12 Nov 2025 10:20:16 +0100 Subject: [PATCH] :bug: Fix validation issues with dtcg-node schema --- common/src/app/common/types/tokens_lib.cljc | 21 ++++++++++++--------- library/CHANGES.md | 7 ++++++- library/package.json | 2 +- library/test/_tokens-2.json | 21 +++++++++++++++++++++ library/test/builder.test.js | 21 +++++++++++++++++++++ 5 files changed, 61 insertions(+), 11 deletions(-) create mode 100644 library/test/_tokens-2.json diff --git a/common/src/app/common/types/tokens_lib.cljc b/common/src/app/common/types/tokens_lib.cljc index 48ba6b8a5b..aa698d323e 100644 --- a/common/src/app/common/types/tokens_lib.cljc +++ b/common/src/app/common/types/tokens_lib.cljc @@ -1460,16 +1460,19 @@ Will return a value that matches this schema: ["type" :string]]])) (def ^:private schema:dtcg-node - [:or + [:schema {:registry + {::simple-value + [:or :string :int :double] + ::value + [:or + [:ref ::simple-value] + [:vector ::simple-value] + [:map-of :string [:or + [:ref ::simple-value] + [:vector ::simple-value]]]]}} [:map - ["$value" :string] - ["$type" :string]] - [:map - ["$value" [:sequential [:map ["$type" :string]]]] - ["$type" :string]] - [:map - ["$value" :map] - ["$type" :string]]]) + ["$type" :string] + ["$value" [:ref ::value]]]]) (def ^:private dtcg-node? (sm/validator schema:dtcg-node)) diff --git a/library/CHANGES.md b/library/CHANGES.md index 97e4212855..78a3bc23d3 100644 --- a/library/CHANGES.md +++ b/library/CHANGES.md @@ -1,6 +1,11 @@ # CHANGELOG -## 1.1.0-RC1 +## 1.1.0-RC2 + +- Fix validation issue with several token nodes + + +## 1.1.0-RC2 - Add experimental addTokensLib method diff --git a/library/package.json b/library/package.json index 8ceb1725b6..33e8014809 100644 --- a/library/package.json +++ b/library/package.json @@ -1,6 +1,6 @@ { "name": "@penpot/library", - "version": "1.1.0-RC1", + "version": "1.1.0-RC2", "license": "MPL-2.0", "author": "Kaleidos INC", "packageManager": "yarn@4.10.3+sha512.c38cafb5c7bb273f3926d04e55e1d8c9dfa7d9c3ea1f36a4868fa028b9e5f72298f0b7f401ad5eb921749eb012eb1c3bb74bf7503df3ee43fd600d14a018266f", diff --git a/library/test/_tokens-2.json b/library/test/_tokens-2.json new file mode 100644 index 0000000000..7446608710 --- /dev/null +++ b/library/test/_tokens-2.json @@ -0,0 +1,21 @@ +{ + "Global": { + "font-1": { + "$value": [ + "Abel" + ], + "$type": "fontFamilies", + "$description": "" + } + }, + "$themes": [], + "$metadata": { + "tokenSetOrder": [ + "Global" + ], + "activeThemes": [], + "activeSets": [ + "Global" + ] + } +} \ No newline at end of file diff --git a/library/test/builder.test.js b/library/test/builder.test.js index 0e1b0270ec..207f863e35 100644 --- a/library/test/builder.test.js +++ b/library/test/builder.test.js @@ -149,6 +149,27 @@ test("create context with tokens lib as json", () => { assert.ok(file.data.tokensLib) }); +test("create context with tokens lib as json 2", () => { + const context = penpot.createBuildContext(); + + const fileId = context.addFile({name: "file 1"}); + const pageId = context.addPage({name: "page 1"}); + + + const tokensFilePath = path.join(__dirname, "_tokens-2.json"); + const tokens = fs.readFileSync(tokensFilePath, "utf8"); + + context.addTokensLib(tokens); + + const internalState = context.getInternalState(); + const file = internalState.files[fileId]; + + assert.ok(file, "file should exist"); + + assert.ok(file.data); + assert.ok(file.data.tokensLib) +}); + test("create context with tokens lib as obj", () => { const context = penpot.createBuildContext();