From 3b72c7f9883aedd98cc7f7631d699ec1c8330857 Mon Sep 17 00:00:00 2001 From: Angelo Ashmore Date: Tue, 9 Apr 2024 12:08:01 -1000 Subject: [PATCH] feat: support `format` option in custom type models (#16) --- package-lock.json | 68 ++++-------------- package.json | 2 +- src/model/customType.ts | 4 ++ test/model-customType.test.ts | 9 +++ test/snapshots/model-customType.test.ts.md | 8 ++- test/snapshots/model-customType.test.ts.snap | Bin 388 -> 452 bytes .../value-contentRelationship.test.ts.md | 40 +++++------ .../value-contentRelationship.test.ts.snap | Bin 604 -> 549 bytes test/snapshots/value-customType.test.ts.md | 64 +++++++++-------- test/snapshots/value-customType.test.ts.snap | Bin 812 -> 874 bytes 10 files changed, 89 insertions(+), 106 deletions(-) diff --git a/package-lock.json b/package-lock.json index 6c3a05f..89bbc23 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,7 +12,7 @@ "change-case": "^4.1.2" }, "devDependencies": { - "@prismicio/client": "^7.0.1", + "@prismicio/client": "^7.4.0", "@size-limit/preset-small-lib": "^8.2.4", "@types/node": "^20.3.0", "@typescript-eslint/eslint-plugin": "^5.59.8", @@ -1097,39 +1097,17 @@ } }, "node_modules/@prismicio/client": { - "version": "7.0.1", - "resolved": "https://registry.npmjs.org/@prismicio/client/-/client-7.0.1.tgz", - "integrity": "sha512-f4SDcDwVB2T73QKJJtzXd8LsfvDgIqOQNhC78bwsKLb1BjfPZNucsyIcRI9jGZdGxcU7lA+HStkYHw6z98ofKQ==", + "version": "7.4.0", + "resolved": "https://registry.npmjs.org/@prismicio/client/-/client-7.4.0.tgz", + "integrity": "sha512-CNUSffXDcBXWb8lRko8cW/975hPFKsT0lxziXUOHfsGZ/AOYkQlW9LOO04UBPzHGqWxt0PU45k7kpT692JoKTw==", "dev": true, "dependencies": { - "@prismicio/richtext": "^2.1.5", - "imgix-url-builder": "^0.0.3" + "imgix-url-builder": "^0.0.4" }, "engines": { "node": ">=14.15.0" } }, - "node_modules/@prismicio/richtext": { - "version": "2.1.5", - "resolved": "https://registry.npmjs.org/@prismicio/richtext/-/richtext-2.1.5.tgz", - "integrity": "sha512-Sf6iCsciPmfK3uQeFmeY9RTRSuhrCVzyU39OkiJ1VJn8O0531pKapGoWS+5WGxouJtE5+jGqV8L+L2mKP7NkXQ==", - "dev": true, - "dependencies": { - "@prismicio/types": "^0.2.7" - }, - "engines": { - "node": ">=12.7.0" - } - }, - "node_modules/@prismicio/types": { - "version": "0.2.8", - "resolved": "https://registry.npmjs.org/@prismicio/types/-/types-0.2.8.tgz", - "integrity": "sha512-EmuYYil56U+UtEifMD/9TmLzpWliV+X6kypwPq47GNXmIXyFK1JsP3z872fUziXwoBjd2YILj28DNdYXlLOpXg==", - "dev": true, - "engines": { - "node": ">=12.7.0" - } - }, "node_modules/@rollup/plugin-typescript": { "version": "10.0.1", "resolved": "https://registry.npmjs.org/@rollup/plugin-typescript/-/plugin-typescript-10.0.1.tgz", @@ -3990,9 +3968,9 @@ } }, "node_modules/imgix-url-builder": { - "version": "0.0.3", - "resolved": "https://registry.npmjs.org/imgix-url-builder/-/imgix-url-builder-0.0.3.tgz", - "integrity": "sha512-8Oc2Cn4+jF06sEfJcVPlWYfD2F6RjrwIMbk1xEzux8unoB5LsvFc/GL1BQ47HPaeE12ReX2nMUcjUslGYWLxHA==", + "version": "0.0.4", + "resolved": "https://registry.npmjs.org/imgix-url-builder/-/imgix-url-builder-0.0.4.tgz", + "integrity": "sha512-JRLydfxGTTbSSOG82ewuCgnmw/CzIPzoDqpP3UYD7RE+QWS8ZZbpF87ZuRqtcbEKdxahRsExinuKRxPZVvukWA==", "dev": true, "engines": { "node": ">=12.7.0" @@ -8869,30 +8847,14 @@ } }, "@prismicio/client": { - "version": "7.0.1", - "resolved": "https://registry.npmjs.org/@prismicio/client/-/client-7.0.1.tgz", - "integrity": "sha512-f4SDcDwVB2T73QKJJtzXd8LsfvDgIqOQNhC78bwsKLb1BjfPZNucsyIcRI9jGZdGxcU7lA+HStkYHw6z98ofKQ==", + "version": "7.4.0", + "resolved": "https://registry.npmjs.org/@prismicio/client/-/client-7.4.0.tgz", + "integrity": "sha512-CNUSffXDcBXWb8lRko8cW/975hPFKsT0lxziXUOHfsGZ/AOYkQlW9LOO04UBPzHGqWxt0PU45k7kpT692JoKTw==", "dev": true, "requires": { - "@prismicio/richtext": "^2.1.5", - "imgix-url-builder": "^0.0.3" + "imgix-url-builder": "^0.0.4" } }, - "@prismicio/richtext": { - "version": "2.1.5", - "resolved": "https://registry.npmjs.org/@prismicio/richtext/-/richtext-2.1.5.tgz", - "integrity": "sha512-Sf6iCsciPmfK3uQeFmeY9RTRSuhrCVzyU39OkiJ1VJn8O0531pKapGoWS+5WGxouJtE5+jGqV8L+L2mKP7NkXQ==", - "dev": true, - "requires": { - "@prismicio/types": "^0.2.7" - } - }, - "@prismicio/types": { - "version": "0.2.8", - "resolved": "https://registry.npmjs.org/@prismicio/types/-/types-0.2.8.tgz", - "integrity": "sha512-EmuYYil56U+UtEifMD/9TmLzpWliV+X6kypwPq47GNXmIXyFK1JsP3z872fUziXwoBjd2YILj28DNdYXlLOpXg==", - "dev": true - }, "@rollup/plugin-typescript": { "version": "10.0.1", "resolved": "https://registry.npmjs.org/@rollup/plugin-typescript/-/plugin-typescript-10.0.1.tgz", @@ -10990,9 +10952,9 @@ "dev": true }, "imgix-url-builder": { - "version": "0.0.3", - "resolved": "https://registry.npmjs.org/imgix-url-builder/-/imgix-url-builder-0.0.3.tgz", - "integrity": "sha512-8Oc2Cn4+jF06sEfJcVPlWYfD2F6RjrwIMbk1xEzux8unoB5LsvFc/GL1BQ47HPaeE12ReX2nMUcjUslGYWLxHA==", + "version": "0.0.4", + "resolved": "https://registry.npmjs.org/imgix-url-builder/-/imgix-url-builder-0.0.4.tgz", + "integrity": "sha512-JRLydfxGTTbSSOG82ewuCgnmw/CzIPzoDqpP3UYD7RE+QWS8ZZbpF87ZuRqtcbEKdxahRsExinuKRxPZVvukWA==", "dev": true }, "import-fresh": { diff --git a/package.json b/package.json index 92cc79c..2b09e75 100644 --- a/package.json +++ b/package.json @@ -61,7 +61,7 @@ "change-case": "^4.1.2" }, "devDependencies": { - "@prismicio/client": "^7.0.1", + "@prismicio/client": "^7.4.0", "@size-limit/preset-small-lib": "^8.2.4", "@types/node": "^20.3.0", "@typescript-eslint/eslint-plugin": "^5.59.8", diff --git a/src/model/customType.ts b/src/model/customType.ts index da11b6c..f4de966 100644 --- a/src/model/customType.ts +++ b/src/model/customType.ts @@ -16,6 +16,7 @@ export type MockCustomTypeModelConfig< label?: string; status?: boolean; repeatable?: boolean; + format?: prismic.CustomTypeModel["format"]; } & ( | { fields?: Definition; @@ -57,6 +58,8 @@ export const customType = < id = changeCase.snakeCase(config.label); } + const format = config.format ?? faker.randomElement(["page", "custom"]); + let json = {} as MockCustomTypeModel["json"]; if ("fields" in config && config.fields) { @@ -70,6 +73,7 @@ export const customType = < label, status: config.status ?? faker.boolean(), repeatable: config.repeatable ?? faker.boolean(), + format, json, } as MockCustomTypeModel; }; diff --git a/test/model-customType.test.ts b/test/model-customType.test.ts index 8e8ec30..097d2fa 100644 --- a/test/model-customType.test.ts +++ b/test/model-customType.test.ts @@ -36,3 +36,12 @@ test("can be configured for specific tabs", (t) => { t.is(actual.json.Main.boolean.type, prismic.CustomTypeModelFieldType.Boolean); }); + +test("can be configured for a specific format", (t) => { + const actual = prismicM.model.customType({ + seed: t.title, + format: "page", + }); + + t.is(actual.format, "page"); +}); diff --git a/test/snapshots/model-customType.test.ts.md b/test/snapshots/model-customType.test.ts.md index e21a00e..89a0d97 100644 --- a/test/snapshots/model-customType.test.ts.md +++ b/test/snapshots/model-customType.test.ts.md @@ -10,18 +10,20 @@ Generated by [AVA](https://avajs.dev). [ { + format: 'page', id: 'id', json: {}, label: 'Id', repeatable: true, - status: false, + status: true, }, { + format: 'page', id: 'id', json: {}, label: 'Id', repeatable: true, - status: false, + status: true, }, ] @@ -31,6 +33,7 @@ Generated by [AVA](https://avajs.dev). [ { + format: 'custom', id: 'ut', json: {}, label: 'Ut', @@ -38,6 +41,7 @@ Generated by [AVA](https://avajs.dev). status: true, }, { + format: 'custom', id: 'ut', json: {}, label: 'Ut', diff --git a/test/snapshots/model-customType.test.ts.snap b/test/snapshots/model-customType.test.ts.snap index 75bb8cb5414004d1daf4277ca417874ad7577e3c..9fba542786deb58f1a86020e44ab5733ba8840ea 100644 GIT binary patch literal 452 zcmV;#0XzOdRzV|=3pjnb7K zp3d44a*4v^rcViTEfzBH&Fxx=>8rK)u&lP^XX(j2(uVREDx*|vn_G8Sp_-#XtKbmxWM ziKv-j_GY#2Y}>O^#9%@E7P!Pf>or;D;j%#+Q%`4fpE`OP8l#=Qllz|75akDT@DBMrW}Gl~A!vbr zn&-L?FlAvF3TOzB0yY6I#ztm?@`Q3m@W%9=@yYmR?0^tQFqs!zMqO+>kTcqBHb=HA zZnpa#)W(?k@!0UbTx<^CvVApr>}VCknFduBg*XXiUe+uFoE z`}8$Cj+`YhV+s(ZVX#w~9gziKbB)hJuy^d4kRn-5qa4^nA3^NMq>`;g|8N zh`=3Sz%%d)d;p(mqQ9`y-sRYlHw&B1=8?>@hZ1lVJOD%R2D}5Gz&8;36`9(+%(9?G zK_P0q^W+Pvuac*dY1l}w#2Ys@(n>|3>~>*#oE?4enw4}-%d9i2m2q75t;{M#i&|y9 z$8MPOtn#)&CGMswXLUK2Yv6BJh_-O1S<=alt!_B3TH_8^75#E@#F1bnQ|M`Yq3c|3 zZ?;--S=iEEZf!bpR=HpH=)cyk`)Ay)liBk-cq4LjZ3h4V^CJoT literal 604 zcmV-i0;BywRzV*3u-sO;bN9t1@%A_&VQ znRcf;nTeT+w4etC58_EL9z3lFy?F8)=)ryj^`w3f!6)6#+8wmE6tM<=Wvlb(`HE!P98 zv~uz-DOA5}*K$4SaGN1 zPAx4*8?CgROd;#|SkKzroN2dNf=e_^o#d-5%O(Hs&MwsCoSkpuDfX|+@kIE-dx>#O2oZwdvo3O}vbdJBr0(3>sh%%b-Do zE;Kj7Xx(`t$H&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