@prismicio/types-internal 4.2.0 → 4.3.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.
Files changed (40) hide show
  1. package/dist/helpers/customTypeModel.d.ts +2 -1
  2. package/dist/helpers/customTypeModel.d.ts.map +1 -1
  3. package/dist/helpers/customTypeModel.js +6 -0
  4. package/dist/helpers/customTypeModel.js.map +1 -1
  5. package/dist/helpers/documentContent.d.ts +2 -1
  6. package/dist/helpers/documentContent.d.ts.map +1 -1
  7. package/dist/helpers/documentContent.js +4 -0
  8. package/dist/helpers/documentContent.js.map +1 -1
  9. package/dist/helpers/fieldModel.d.ts +7 -0
  10. package/dist/helpers/fieldModel.d.ts.map +1 -0
  11. package/dist/helpers/fieldModel.js +13 -0
  12. package/dist/helpers/fieldModel.js.map +1 -0
  13. package/dist/helpers/repository.d.ts +7 -0
  14. package/dist/helpers/repository.d.ts.map +1 -0
  15. package/dist/helpers/repository.js +15 -0
  16. package/dist/helpers/repository.js.map +1 -0
  17. package/dist/helpers/sliceModel.d.ts +8 -0
  18. package/dist/helpers/sliceModel.d.ts.map +1 -0
  19. package/dist/helpers/sliceModel.js +16 -0
  20. package/dist/helpers/sliceModel.js.map +1 -0
  21. package/dist/index.d.ts +4 -1
  22. package/dist/index.js +4 -1
  23. package/dist/model/customType.d.ts.map +1 -1
  24. package/dist/model/customType.js +30 -1
  25. package/dist/model/customType.js.map +1 -1
  26. package/dist/model/image.js +1 -1
  27. package/dist/model/image.js.map +1 -1
  28. package/dist/model/slice.d.ts.map +1 -1
  29. package/dist/model/slice.js +21 -1
  30. package/dist/model/slice.js.map +1 -1
  31. package/package.json +1 -1
  32. package/src/helpers/customTypeModel.ts +16 -0
  33. package/src/helpers/documentContent.ts +10 -0
  34. package/src/helpers/fieldModel.ts +18 -0
  35. package/src/helpers/repository.ts +25 -0
  36. package/src/helpers/sliceModel.ts +18 -0
  37. package/src/index.ts +3 -0
  38. package/src/model/customType.ts +48 -9
  39. package/src/model/image.ts +1 -1
  40. package/src/model/slice.ts +39 -8
@@ -3,12 +3,13 @@ import { DynamicCustomTypeModel, StaticCustomTypeModel, StaticCustomTypeModelTab
3
3
 
4
4
  //#region src/helpers/customTypeModel.d.ts
5
5
  declare namespace customTypeModel_d_exports {
6
- export { collectSharedSlices, filterMissingSharedSlices, flatten, toStatic };
6
+ export { collectSharedSlices, filterMissingSharedSlices, flatten, serializeID, toStatic };
7
7
  }
8
8
  declare function toStatic(customType: DynamicCustomTypeModel, sharedSlices: Map<string, SharedSliceModel> | Record<string, SharedSliceModel>): StaticCustomTypeModel;
9
9
  declare function flatten(customType: StaticCustomTypeModel): StaticCustomTypeModelTab;
10
10
  declare function collectSharedSlices(customType: StaticCustomTypeModel): Record<string, SharedSliceModel>;
11
11
  declare function filterMissingSharedSlices<TCustomType extends StaticCustomTypeModel | DynamicCustomTypeModel>(customType: TCustomType, sharedSlices: Map<string, SharedSliceModel> | Record<string, SharedSliceModel>): TCustomType;
12
+ declare function serializeID(input: string): string;
12
13
  //#endregion
13
14
  export { customTypeModel_d_exports };
14
15
  //# sourceMappingURL=customTypeModel.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"customTypeModel.d.ts","names":[],"sources":["../../src/helpers/customTypeModel.ts"],"mappings":";;;;;;;iBAOgB,QAAA,CACf,UAAA,EAAY,sBAAA,EACZ,YAAA,EAAc,GAAA,SAAY,gBAAA,IAAoB,MAAA,SAAe,gBAAA,IAC3D,qBAAA;AAAA,iBAwCa,OAAA,CAAQ,UAAA,EAAY,qBAAA,GAAwB,wBAAA;AAAA,iBAI5C,mBAAA,CACf,UAAA,EAAY,qBAAA,GACV,MAAA,SAAe,gBAAA;AAAA,iBAiBF,yBAAA,qBACK,qBAAA,GAAwB,sBAAA,CAAA,CAE5C,UAAA,EAAY,WAAA,EACZ,YAAA,EAAc,GAAA,SAAY,gBAAA,IAAoB,MAAA,SAAe,gBAAA,IAC3D,WAAA"}
1
+ {"version":3,"file":"customTypeModel.d.ts","names":[],"sources":["../../src/helpers/customTypeModel.ts"],"mappings":";;;;;;;iBAOgB,QAAA,CACf,UAAA,EAAY,sBAAA,EACZ,YAAA,EAAc,GAAA,SAAY,gBAAA,IAAoB,MAAA,SAAe,gBAAA,IAC3D,qBAAA;AAAA,iBAwCa,OAAA,CAAQ,UAAA,EAAY,qBAAA,GAAwB,wBAAA;AAAA,iBAI5C,mBAAA,CACf,UAAA,EAAY,qBAAA,GACV,MAAA,SAAe,gBAAA;AAAA,iBAiBF,yBAAA,qBACK,qBAAA,GAAwB,sBAAA,CAAA,CAE5C,UAAA,EAAY,WAAA,EACZ,YAAA,EAAc,GAAA,SAAY,gBAAA,IAAoB,MAAA,SAAe,gBAAA,IAC3D,WAAA;AAAA,iBAuCa,WAAA,CAAY,KAAA"}
@@ -4,6 +4,7 @@ var customTypeModel_exports = /* @__PURE__ */ __exportAll({
4
4
  collectSharedSlices: () => collectSharedSlices,
5
5
  filterMissingSharedSlices: () => filterMissingSharedSlices,
6
6
  flatten: () => flatten,
7
+ serializeID: () => serializeID,
7
8
  toStatic: () => toStatic
8
9
  });
9
10
  function toStatic(customType, sharedSlices) {
@@ -79,6 +80,11 @@ function filterMissingSharedSlices(customType, sharedSlices) {
79
80
  json
80
81
  };
81
82
  }
83
+ function serializeID(input) {
84
+ const normalized = input.trim().normalize("NFD").replace(/\p{M}/gu, "").toLowerCase().replace(/[^a-z0-9]+/g, "_").replace(/^_+|_+$/g, "");
85
+ if (normalized.length === 0) throw new Error(`Cannot serialize "${input}": result is empty.`);
86
+ return normalized;
87
+ }
82
88
  //#endregion
83
89
  export { collectSharedSlices, customTypeModel_exports, flatten };
84
90
 
@@ -1 +1 @@
1
- {"version":3,"file":"customTypeModel.js","names":[],"sources":["../../src/helpers/customTypeModel.ts"],"sourcesContent":["import type {\n\tDynamicCustomTypeModel,\n\tStaticCustomTypeModel,\n\tStaticCustomTypeModelTab,\n} from \"../model/customType\"\nimport type { SharedSliceModel, StaticSliceModel } from \"../model/slice\"\n\nexport function toStatic(\n\tcustomType: DynamicCustomTypeModel,\n\tsharedSlices: Map<string, SharedSliceModel> | Record<string, SharedSliceModel>,\n): StaticCustomTypeModel {\n\tconst json: StaticCustomTypeModel[\"json\"] = {}\n\n\tconst sharedSlicesMap =\n\t\tsharedSlices instanceof Map ? sharedSlices : new Map(Object.entries(sharedSlices))\n\n\tfor (const [tabKey, tab] of Object.entries(customType.json)) {\n\t\tconst tabJSON: StaticCustomTypeModel[\"json\"][string] = {}\n\t\tfor (const [key, widget] of Object.entries(tab)) {\n\t\t\tswitch (widget.type) {\n\t\t\t\tcase \"Slices\":\n\t\t\t\tcase \"Choice\":\n\t\t\t\t\tconst choices: Record<string, StaticSliceModel> = {}\n\t\t\t\t\tfor (const [id, model] of Object.entries(widget.config?.choices || {})) {\n\t\t\t\t\t\tif (model.type === \"SharedSlice\") {\n\t\t\t\t\t\t\tconst sharedSlice = sharedSlicesMap.get(id)\n\t\t\t\t\t\t\tif (sharedSlice) {\n\t\t\t\t\t\t\t\tchoices[id] = sharedSlice\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tchoices[id] = model\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\ttabJSON[key] = {\n\t\t\t\t\t\t...widget,\n\t\t\t\t\t\tconfig: { ...widget.config, choices },\n\t\t\t\t\t}\n\t\t\t\t\tbreak\n\t\t\t\tdefault:\n\t\t\t\t\ttabJSON[key] = widget\n\t\t\t}\n\t\t}\n\n\t\tjson[tabKey] = tabJSON\n\t}\n\n\treturn { ...customType, json }\n}\n\nexport function flatten(customType: StaticCustomTypeModel): StaticCustomTypeModelTab {\n\treturn Object.values(customType.json).reduce((acc, fields) => ({ ...acc, ...fields }), {})\n}\n\nexport function collectSharedSlices(\n\tcustomType: StaticCustomTypeModel,\n): Record<string, SharedSliceModel> {\n\tconst sharedSlices: Record<string, SharedSliceModel> = {}\n\n\tconst flattened = flatten(customType)\n\tfor (const widget of Object.values(flattened)) {\n\t\tif (widget.type === \"Slices\" || widget.type === \"Choice\") {\n\t\t\tfor (const [id, model] of Object.entries(widget.config?.choices || {})) {\n\t\t\t\tif (model.type === \"SharedSlice\") {\n\t\t\t\t\tsharedSlices[id] = model\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\treturn sharedSlices\n}\n\nexport function filterMissingSharedSlices<\n\tTCustomType extends StaticCustomTypeModel | DynamicCustomTypeModel,\n>(\n\tcustomType: TCustomType,\n\tsharedSlices: Map<string, SharedSliceModel> | Record<string, SharedSliceModel>,\n): TCustomType {\n\tconst json: TCustomType[\"json\"] = {}\n\n\tconst sharedSlicesMap =\n\t\tsharedSlices instanceof Map ? sharedSlices : new Map(Object.entries(sharedSlices))\n\n\tfor (const [tabKey, tab] of Object.entries(customType.json)) {\n\t\tconst tabJSON: typeof tab = {}\n\t\tfor (const [key, widget] of Object.entries(tab)) {\n\t\t\tswitch (widget.type) {\n\t\t\t\tcase \"Slices\":\n\t\t\t\tcase \"Choice\":\n\t\t\t\t\tconst choices: Required<typeof widget>[\"config\"][\"choices\"] = {}\n\t\t\t\t\tfor (const [id, model] of Object.entries(widget.config?.choices || {})) {\n\t\t\t\t\t\tif (model.type === \"SharedSlice\") {\n\t\t\t\t\t\t\tif (sharedSlicesMap.get(id)) {\n\t\t\t\t\t\t\t\tchoices[id] = model\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tchoices[id] = model\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\ttabJSON[key] = {\n\t\t\t\t\t\t...widget,\n\t\t\t\t\t\tconfig: { ...widget.config, choices },\n\t\t\t\t\t}\n\t\t\t\t\tbreak\n\t\t\t\tdefault:\n\t\t\t\t\ttabJSON[key] = widget\n\t\t\t}\n\t\t}\n\n\t\tjson[tabKey] = tabJSON\n\t}\n\n\treturn { ...customType, json }\n}\n"],"mappings":";;;;;;;;AAOA,SAAg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wBAAwB,MAAM,eAAe,IAAI,IAAI,OAAO,QAAQ,aAAa,CAAC;AAEnF,MAAK,MAAM,CAAC,QAAQ,QAAQ,OAAO,QAAQ,WAAW,KAAK,EAAE;EAC5D,MAAM,UAAsB,EAAE;AAC9B,OAAK,MAAM,CAAC,KAAK,WAAW,OAAO,QAAQ,IAAI,CAC9C,SAAQ,OAAO,MAAf;GACC,KAAK;GACL,KAAK;IACJ,MAAM,UAAwD,EAAE;AAChE,SAAK,MAAM,CAAC,IAAI,UAAU,OAAO,QAAQ,OAAO,QAAQ,WAAW,EAAE,CAAC,CACrE,KAAI,MAAM,SAAS;SACd,gBAAgB,IAAI,GAAG,CAC1B,SAAQ,MAAM;UAGf,SAAQ,MAAM;AAIhB,YAAQ,OAAO;KACd,GAAG;KACH,QAAQ;MAAE,GAAG,OAAO;MAAQ;MAAS;KACrC;AACD;GACD,QACC,SAAQ,OAAO;;AAIlB,OAAK,UAAU;;AAGhB,QAAO;EAAE,GAAG;EAAY;EAAM"}
1
+ {"version":3,"file":"customTypeModel.js","names":[],"sources":["../../src/helpers/customTypeModel.ts"],"sourcesContent":["import type {\n\tDynamicCustomTypeModel,\n\tStaticCustomTypeModel,\n\tStaticCustomTypeModelTab,\n} from \"../model/customType\"\nimport type { SharedSliceModel, StaticSliceModel } from \"../model/slice\"\n\nexport function toStatic(\n\tcustomType: DynamicCustomTypeModel,\n\tsharedSlices: Map<string, SharedSliceModel> | Record<string, SharedSliceModel>,\n): StaticCustomTypeModel {\n\tconst json: StaticCustomTypeModel[\"json\"] = {}\n\n\tconst sharedSlicesMap =\n\t\tsharedSlices instanceof Map ? sharedSlices : new Map(Object.entries(sharedSlices))\n\n\tfor (const [tabKey, tab] of Object.entries(customType.json)) {\n\t\tconst tabJSON: StaticCustomTypeModel[\"json\"][string] = {}\n\t\tfor (const [key, widget] of Object.entries(tab)) {\n\t\t\tswitch (widget.type) {\n\t\t\t\tcase \"Slices\":\n\t\t\t\tcase \"Choice\":\n\t\t\t\t\tconst choices: Record<string, StaticSliceModel> = {}\n\t\t\t\t\tfor (const [id, model] of Object.entries(widget.config?.choices || {})) {\n\t\t\t\t\t\tif (model.type === \"SharedSlice\") {\n\t\t\t\t\t\t\tconst sharedSlice = sharedSlicesMap.get(id)\n\t\t\t\t\t\t\tif (sharedSlice) {\n\t\t\t\t\t\t\t\tchoices[id] = sharedSlice\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tchoices[id] = model\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\ttabJSON[key] = {\n\t\t\t\t\t\t...widget,\n\t\t\t\t\t\tconfig: { ...widget.config, choices },\n\t\t\t\t\t}\n\t\t\t\t\tbreak\n\t\t\t\tdefault:\n\t\t\t\t\ttabJSON[key] = widget\n\t\t\t}\n\t\t}\n\n\t\tjson[tabKey] = tabJSON\n\t}\n\n\treturn { ...customType, json }\n}\n\nexport function flatten(customType: StaticCustomTypeModel): StaticCustomTypeModelTab {\n\treturn Object.values(customType.json).reduce((acc, fields) => ({ ...acc, ...fields }), {})\n}\n\nexport function collectSharedSlices(\n\tcustomType: StaticCustomTypeModel,\n): Record<string, SharedSliceModel> {\n\tconst sharedSlices: Record<string, SharedSliceModel> = {}\n\n\tconst flattened = flatten(customType)\n\tfor (const widget of Object.values(flattened)) {\n\t\tif (widget.type === \"Slices\" || widget.type === \"Choice\") {\n\t\t\tfor (const [id, model] of Object.entries(widget.config?.choices || {})) {\n\t\t\t\tif (model.type === \"SharedSlice\") {\n\t\t\t\t\tsharedSlices[id] = model\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\treturn sharedSlices\n}\n\nexport function filterMissingSharedSlices<\n\tTCustomType extends StaticCustomTypeModel | DynamicCustomTypeModel,\n>(\n\tcustomType: TCustomType,\n\tsharedSlices: Map<string, SharedSliceModel> | Record<string, SharedSliceModel>,\n): TCustomType {\n\tconst json: TCustomType[\"json\"] = {}\n\n\tconst sharedSlicesMap =\n\t\tsharedSlices instanceof Map ? sharedSlices : new Map(Object.entries(sharedSlices))\n\n\tfor (const [tabKey, tab] of Object.entries(customType.json)) {\n\t\tconst tabJSON: typeof tab = {}\n\t\tfor (const [key, widget] of Object.entries(tab)) {\n\t\t\tswitch (widget.type) {\n\t\t\t\tcase \"Slices\":\n\t\t\t\tcase \"Choice\":\n\t\t\t\t\tconst choices: Required<typeof widget>[\"config\"][\"choices\"] = {}\n\t\t\t\t\tfor (const [id, model] of Object.entries(widget.config?.choices || {})) {\n\t\t\t\t\t\tif (model.type === \"SharedSlice\") {\n\t\t\t\t\t\t\tif (sharedSlicesMap.get(id)) {\n\t\t\t\t\t\t\t\tchoices[id] = model\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tchoices[id] = model\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\ttabJSON[key] = {\n\t\t\t\t\t\t...widget,\n\t\t\t\t\t\tconfig: { ...widget.config, choices },\n\t\t\t\t\t}\n\t\t\t\t\tbreak\n\t\t\t\tdefault:\n\t\t\t\t\ttabJSON[key] = widget\n\t\t\t}\n\t\t}\n\n\t\tjson[tabKey] = tabJSON\n\t}\n\n\treturn { ...customType, json }\n}\n\nexport function serializeID(input: string): string {\n\tconst normalized = input\n\t\t.trim()\n\t\t.normalize(\"NFD\")\n\t\t.replace(/\\p{M}/gu, \"\")\n\t\t.toLowerCase()\n\t\t.replace(/[^a-z0-9]+/g, \"_\")\n\t\t.replace(/^_+|_+$/g, \"\")\n\n\tif (normalized.length === 0) {\n\t\tthrow new Error(`Cannot serialize \"${input}\": result is empty.`)\n\t}\n\n\treturn normalized\n}\n"],"mappings":";;;;;;;;;AAOA,SAAgB,SACf,YACA,cACwB;CACxB,MAAM,OAAsC,EAAE;CAE9C,MAAM,kBACL,wBAAwB,MAAM,eAAe,IAAI,IAAI,OAAO,QAAQ,aAAa,CAAC;AAEnF,MAAK,MAAM,CAAC,QAAQ,QAAQ,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B,OAAK,MAAM,CAAC,KAAK,WAAW,OAAO,QAAQ,IAAI,CAC9C,SAAQ,OAAO,MAAf;GACC,KAAK;GACL,KAAK;IACJ,MAAM,UAAwD,EAAE;AAChE,SAAK,MAAM,CAAC,IAAI,UAAU,OAAO,QAAQ,OAAO,QAAQ,WAAW,EAAE,CAAC,CACrE,KAAI,MAAM,SAAS;SACd,gBAAgB,IAAI,GAAG,CAC1B,SAAQ,MAAM;UAGf,SAAQ,MAAM;AAIhB,YAAQ,OAAO;KACd,GAAG;KACH,QAAQ;MAAE,GAAG,OAAO;MAAQ;MAAS;KACrC;AACD;GACD,QACC,SAAQ,OAAO;;AAIlB,OAAK,UAAU;;AAGhB,QAAO;EAAE,GAAG;EAAY;EAAM;;AAG/B,SAAgB,YAAY,OAAuB;CAClD,MAAM,aAAa,MACjB,MAAM,CACN,UAAU,MAAM,CAChB,QAAQ,WAAW,GAAG,CACtB,aAAa,CACb,QAAQ,eAAe,IAAI,CAC3B,QAAQ,YAAY,GAAG;AAEzB,KAAI,WAAW,WAAW,EACzB,OAAM,IAAI,MAAM,qBAAqB,MAAM,qBAAqB;AAGjE,QAAO"}
@@ -6,7 +6,7 @@ import { DocumentLegacy } from "../content/legacy/document.js";
6
6
 
7
7
  //#region src/helpers/documentContent.d.ts
8
8
  declare namespace documentContent_d_exports {
9
- export { collectWidgets, fromLegacy, toLegacy };
9
+ export { collectWidgets, fromLegacy, serializeUID, toLegacy };
10
10
  }
11
11
  declare function collectWidgets<TWidgetContent extends WidgetContent>(document: DocumentContent, test: (content: WidgetContent, args: {
12
12
  path: Path;
@@ -15,6 +15,7 @@ declare function collectWidgets<TWidgetContent extends WidgetContent>(document:
15
15
  }) => content is TWidgetContent): Record<string, TWidgetContent>;
16
16
  declare function fromLegacy(legacy: DocumentLegacy, model: StaticCustomTypeModel): DocumentContent | undefined;
17
17
  declare function toLegacy(document: DocumentContent): DocumentLegacy;
18
+ declare function serializeUID(input: string): string;
18
19
  //#endregion
19
20
  export { documentContent_d_exports };
20
21
  //# sourceMappingURL=documentContent.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"documentContent.d.ts","names":[],"sources":["../../src/helpers/documentContent.ts"],"mappings":";;;;;;;;;;iBAkBgB,cAAA,wBAAsC,aAAA,CAAA,CACrD,QAAA,EAAU,eAAA,EACV,IAAA,GACC,OAAA,EAAS,aAAA,EACT,IAAA;EACC,IAAA,EAAM,IAAA;EACN,GAAA;EACA,KAAA;AAAA,MAEG,OAAA,IAAW,cAAA,GACd,MAAA,SAAe,cAAA;AAAA,iBAgBF,UAAA,CACf,MAAA,EAAQ,cAAA,EACR,KAAA,EAAO,qBAAA,GACL,eAAA;AAAA,iBAwDa,QAAA,CAAS,QAAA,EAAU,eAAA,GAAkB,cAAA"}
1
+ {"version":3,"file":"documentContent.d.ts","names":[],"sources":["../../src/helpers/documentContent.ts"],"mappings":";;;;;;;;;;iBAkBgB,cAAA,wBAAsC,aAAA,CAAA,CACrD,QAAA,EAAU,eAAA,EACV,IAAA,GACC,OAAA,EAAS,aAAA,EACT,IAAA;EACC,IAAA,EAAM,IAAA;EACN,GAAA;EACA,KAAA;AAAA,MAEG,OAAA,IAAW,cAAA,GACd,MAAA,SAAe,cAAA;AAAA,iBAgBF,UAAA,CACf,MAAA,EAAQ,cAAA,EACR,KAAA,EAAO,qBAAA,GACL,eAAA;AAAA,iBAwDa,QAAA,CAAS,QAAA,EAAU,eAAA,GAAkB,cAAA;AAAA,iBAMrC,YAAA,CAAa,KAAA"}
@@ -13,6 +13,7 @@ import { z } from "zod/mini";
13
13
  var documentContent_exports = /* @__PURE__ */ __exportAll({
14
14
  collectWidgets: () => collectWidgets,
15
15
  fromLegacy: () => fromLegacy,
16
+ serializeUID: () => serializeUID,
16
17
  toLegacy: () => toLegacy
17
18
  });
18
19
  function collectWidgets(document, test) {
@@ -58,6 +59,9 @@ function toLegacy(document) {
58
59
  ...keys
59
60
  };
60
61
  }
62
+ function serializeUID(input) {
63
+ return input.replace(/ /g, "-").normalize("NFD").replace(/\p{M}/gu, "").replace(/[^\p{L}\d_.-]/gu, "").toLowerCase();
64
+ }
61
65
  //#endregion
62
66
  export { documentContent_exports };
63
67
 
@@ -1 +1 @@
1
- {"version":3,"file":"documentContent.js","names":["contentPath.serialize","customTypeModel.collectSharedSlices","sliceContent.compositeToShared","sliceContent.legacyToShared"],"sources":["../../src/helpers/documentContent.ts"],"sourcesContent":["import { z } from \"zod/mini\"\n\nimport { DocumentLegacyCodec } from \"../content/codec/document\"\nimport { defaultCtx } from \"../content/codec/legacyContentCtx\"\nimport type { DocumentContent } from \"../content/document\"\nimport type { DocumentLegacy } from \"../content/legacy/document\"\nimport { DocumentLegacySchema } from \"../content/legacy/document\"\nimport { isNestableContent } from \"../content/nestable\"\nimport type { CompositeSliceItemContent, LegacySliceItemContent } from \"../content/slices\"\nimport type { WidgetContent } from \"../content/widget\"\nimport type { StaticCustomTypeModel } from \"../model/customType\"\nimport type { FieldOrSliceType } from \"../model/widget\"\nimport { FieldOrSliceTypeSchema } from \"../model/widget\"\nimport * as contentPath from \"./contentPath\"\nimport * as customTypeModel from \"./customTypeModel\"\nimport * as sliceContent from \"./sliceContent\"\nimport { traverseDocumentContent } from \"./traverseContent\"\n\nexport function collectWidgets<TWidgetContent extends WidgetContent>(\n\tdocument: DocumentContent,\n\ttest: (\n\t\tcontent: WidgetContent,\n\t\targs: {\n\t\t\tpath: contentPath.Path\n\t\t\tkey: string\n\t\t\tapiID: string\n\t\t},\n\t) => content is TWidgetContent,\n): Record<string, TWidgetContent> {\n\tconst collected: Record<string, TWidgetContent> = {}\n\n\ttraverseDocumentContent(document, {\n\t\ttransformWidget: ({ content, ...args }) => {\n\t\t\tif (test(content, args)) {\n\t\t\t\tcollected[contentPath.serialize(args.path)] = content\n\t\t\t}\n\n\t\t\treturn content\n\t\t},\n\t})\n\n\treturn collected\n}\n\nexport function fromLegacy(\n\tlegacy: DocumentLegacy,\n\tmodel: StaticCustomTypeModel,\n): DocumentContent | undefined {\n\tconst parsed = DocumentLegacySchema.safeParse(legacy)\n\tif (!parsed.success) {\n\t\treturn\n\t}\n\n\tconst types = new Map<string, FieldOrSliceType>()\n\tconst keys = new Map<string, string>()\n\tconst widgets: DocumentLegacy = {}\n\tfor (const [key, value] of Object.entries(parsed.data)) {\n\t\tif (key.endsWith(\"_TYPE\")) {\n\t\t\tconst parsed = FieldOrSliceTypeSchema.safeParse(value)\n\t\t\tif (parsed.success) {\n\t\t\t\ttypes.set(key.substring(0, key.length - 5), parsed.data)\n\t\t\t}\n\t\t} else if (key.endsWith(\"_KEY\")) {\n\t\t\tconst parsed = z.uuidv4().safeParse(value)\n\t\t\tif (parsed.success) {\n\t\t\t\tkeys.set(key.substring(0, key.length - 4), parsed.data)\n\t\t\t}\n\t\t} else if (!key.endsWith(\"_POSITION\")) {\n\t\t\twidgets[key] = value\n\t\t}\n\t}\n\n\tconst result = DocumentLegacyCodec(defaultCtx(\"\", types, keys)).toContent(widgets)\n\tif (!result.success) {\n\t\treturn\n\t}\n\n\tconst needsMigration = Object.values(customTypeModel.collectSharedSlices(model)).some((slice) =>\n\t\tBoolean(slice.legacyPaths),\n\t)\n\n\tif (needsMigration) {\n\t\treturn traverseDocumentContent(result.data, {\n\t\t\tmodel,\n\t\t\ttransformSlice: ({ content, model }) => {\n\t\t\t\tif (model?.type === \"SharedSlice\") {\n\t\t\t\t\tif (content.widget.__TYPE__ === \"CompositeSliceContent\") {\n\t\t\t\t\t\treturn sliceContent.compositeToShared(content as CompositeSliceItemContent, model)\n\t\t\t\t\t} else if (\n\t\t\t\t\t\tcontent.widget.__TYPE__ === \"GroupContentType\" ||\n\t\t\t\t\t\tisNestableContent(content.widget)\n\t\t\t\t\t) {\n\t\t\t\t\t\treturn sliceContent.legacyToShared(content as LegacySliceItemContent, model)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn content\n\t\t\t},\n\t\t})\n\t}\n\n\treturn result.data\n}\n\nexport function toLegacy(document: DocumentContent): DocumentLegac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EAAE,SAAS,YAAY;AACvC,OAAI,OAAO,SAAS;QACf,QAAQ,OAAO,aAAa,wBAC/B,QAAOC,kBAA+B,SAAsC,MAAM;aAElF,QAAQ,OAAO,aAAa,sBAC5B,kBAAkB,QAAQ,OAAO,CAEjC,QAAOC,eAA4B,SAAmC,MAAM;;AAG9E,UAAO;;EAER,CAAC;AAGH,QAAO,OAAO;;AAGf,SAAgB,SAAS,UAA2C;CACnE,MAAM,EAAE,SAAS,OAAO,SAAS,oBAAoB,WAAW,GAAG,CAAC,CAAC,YAAY,SAAS;AAE1F,QAAO;EAAE,GAAG;EAAS,GAAG;EAAO,GAAG;EAAM"}
1
+ {"version":3,"file":"documentContent.js","names":["contentPath.serialize","customTypeModel.collectSharedSlices","sliceContent.compositeToShared","sliceContent.legacyToShared"],"sources":["../../src/helpers/documentContent.ts"],"sourcesContent":["import { z } from \"zod/mini\"\n\nimport { DocumentLegacyCodec } from \"../content/codec/document\"\nimport { defaultCtx } from \"../content/codec/legacyContentCtx\"\nimport type { DocumentContent } from \"../content/document\"\nimport type { DocumentLegacy } from \"../content/legacy/document\"\nimport { DocumentLegacySchema } from \"../content/legacy/document\"\nimport { isNestableContent } from \"../content/nestable\"\nimport type { CompositeSliceItemContent, LegacySliceItemContent } from \"../content/slices\"\nimport type { WidgetContent } from \"../content/widget\"\nimport type { StaticCustomTypeModel } from \"../model/customType\"\nimport type { FieldOrSliceType } from \"../model/widget\"\nimport { FieldOrSliceTypeSchema } from \"../model/widget\"\nimport * as contentPath from \"./contentPath\"\nimport * as customTypeModel from \"./customTypeModel\"\nimport * as sliceContent from \"./sliceContent\"\nimport { traverseDocumentContent } from \"./traverseContent\"\n\nexport function collectWidgets<TWidgetContent extends WidgetContent>(\n\tdocument: DocumentContent,\n\ttest: (\n\t\tcontent: WidgetContent,\n\t\targs: {\n\t\t\tpath: contentPath.Path\n\t\t\tkey: string\n\t\t\tapiID: string\n\t\t},\n\t) => content is TWidgetContent,\n): Record<string, TWidgetContent> {\n\tconst collected: Record<string, TWidgetContent> = {}\n\n\ttraverseDocumentContent(document, {\n\t\ttransformWidget: ({ content, ...args }) => {\n\t\t\tif (test(content, args)) {\n\t\t\t\tcollected[contentPath.serialize(args.path)] = content\n\t\t\t}\n\n\t\t\treturn content\n\t\t},\n\t})\n\n\treturn collected\n}\n\nexport function fromLegacy(\n\tlegacy: DocumentLegacy,\n\tmodel: StaticCustomTypeModel,\n): DocumentContent | undefined {\n\tconst parsed = DocumentLegacySchema.safeParse(legacy)\n\tif (!parsed.success) {\n\t\treturn\n\t}\n\n\tconst types = new Map<string, FieldOrSliceType>()\n\tconst keys = new Map<string, string>()\n\tconst widgets: DocumentLegacy = {}\n\tfor (const [key, value] of Object.entries(parsed.data)) {\n\t\tif (key.endsWith(\"_TYPE\")) {\n\t\t\tconst parsed = FieldOrSliceTypeSchema.safeParse(value)\n\t\t\tif (parsed.success) {\n\t\t\t\ttypes.set(key.substring(0, key.length - 5), parsed.data)\n\t\t\t}\n\t\t} else if (key.endsWith(\"_KEY\")) {\n\t\t\tconst parsed = z.uuidv4().safeParse(value)\n\t\t\tif (parsed.success) {\n\t\t\t\tkeys.set(key.substring(0, key.length - 4), parsed.data)\n\t\t\t}\n\t\t} else if (!key.endsWith(\"_POSITION\")) {\n\t\t\twidgets[key] = value\n\t\t}\n\t}\n\n\tconst result = DocumentLegacyCodec(defaultCtx(\"\", types, keys)).toContent(widgets)\n\tif (!result.success) {\n\t\treturn\n\t}\n\n\tconst needsMigration = Object.values(customTypeModel.collectSharedSlices(model)).some((slice) =>\n\t\tBoolean(slice.legacyPaths),\n\t)\n\n\tif (needsMigration) {\n\t\treturn traverseDocumentContent(result.data, {\n\t\t\tmodel,\n\t\t\ttransformSlice: ({ content, model }) => {\n\t\t\t\tif (model?.type === \"SharedSlice\") {\n\t\t\t\t\tif (content.widget.__TYPE__ === \"CompositeSliceContent\") {\n\t\t\t\t\t\treturn sliceContent.compositeToShared(content as CompositeSliceItemContent, model)\n\t\t\t\t\t} else if (\n\t\t\t\t\t\tcontent.widget.__TYPE__ === \"GroupContentType\" ||\n\t\t\t\t\t\tisNestableContent(content.widget)\n\t\t\t\t\t) {\n\t\t\t\t\t\treturn sliceContent.legacyToShared(content as LegacySliceItemContent, model)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn content\n\t\t\t},\n\t\t})\n\t}\n\n\treturn result.data\n}\n\nexport function toLegacy(document: DocumentContent): DocumentLegacy {\n\tconst { content, types, keys } = DocumentLegacyCodec(defaultCtx(\"\")).fromContent(document)\n\n\treturn { ...content, ...types, ...keys }\n}\n\nexport function serializeUID(input: string): string {\n\tconst nowhitespace = input.replace(/ /g, \"-\")\n\n\tconst normalized = nowhitespace.normalize(\"NFD\").replace(/\\p{M}/gu, \"\")\n\n\tconst slug = normalized.replace(/[^\\p{L}\\d_.-]/gu, \"\")\n\n\treturn slug.toLowerCase()\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAkBA,SAAgB,eACf,UACA,MAQiC;CACjC,MAAM,YAA4C,EAAE;AAEpD,yBAAwB,UAAU,EACjC,kBAAkB,EAAE,SAAS,GAAG,WAAW;AAC1C,MAAI,KAAK,SAAS,KAAK,CACtB,WAAUA,UAAsB,KAAK,KAAK,IAAI;AAG/C,SAAO;IAER,CAAC;AAEF,QAAO;;AAGR,SAAgB,WACf,QACA,OAC8B;CAC9B,MAAM,SAAS,qBAAqB,UAAU,OAAO;AACrD,KAAI,CAAC,OAAO,QACX;CAGD,MAAM,wBAAQ,IAAI,KAA+B;CACjD,MAAM,uBAAO,IAAI,KAAqB;CACtC,MAAM,UAA0B,EAAE;AAClC,MAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,OAAO,KAAK,CACrD,KAAI,IAAI,SAAS,QAAQ,EAAE;EAC1B,MAAM,SAAS,uBAAuB,UAAU,MAAM;AACtD,MAAI,OAAO,QACV,OAAM,IAAI,IAAI,UAAU,GAAG,IAAI,SAAS,EAAE,EAAE,OAAO,KAAK;YAE/C,IAAI,SAAS,OAAO,EAAE;EAChC,MAAM,SAAS,EAAE,QAAQ,CAAC,UAAU,MAAM;AAC1C,MAAI,OAAO,QACV,MAAK,IAAI,IAAI,UAAU,GAAG,IAAI,SAAS,EAAE,EAAE,OAAO,KAAK;YAE9C,CAAC,IAAI,SAAS,YAAY,CACpC,SAAQ,OAAO;CAIjB,MAAM,SAAS,oBAAoB,WAAW,IAAI,OAAO,KAAK,CAAC,CAAC,UAAU,QAAQ;AAClF,KAAI,CAAC,OAAO,QACX;AAOD,KAJuB,OAAO,OAAOC,oBAAoC,MAAM,CAAC,CAAC,MAAM,UACtF,QAAQ,MAAM,YAAY,CAC1B,CAGA,QAAO,wBAAwB,OAAO,MAAM;EAC3C;EACA,iBAAiB,EAAE,SAAS,YAAY;AACvC,OAAI,OAAO,SAAS;QACf,QAAQ,OAAO,aAAa,wBAC/B,QAAOC,kBAA+B,SAAsC,MAAM;aAElF,QAAQ,OAAO,aAAa,sBAC5B,kBAAkB,QAAQ,OAAO,CAEjC,QAAOC,eAA4B,SAAmC,MAAM;;AAG9E,UAAO;;EAER,CAAC;AAGH,QAAO,OAAO;;AAGf,SAAgB,SAAS,UAA2C;CACnE,MAAM,EAAE,SAAS,OAAO,SAAS,oBAAoB,WAAW,GAAG,CAAC,CAAC,YAAY,SAAS;AAE1F,QAAO;EAAE,GAAG;EAAS,GAAG;EAAO,GAAG;EAAM;;AAGzC,SAAgB,aAAa,OAAuB;AAOnD,QANqB,MAAM,QAAQ,MAAM,IAAI,CAEb,UAAU,MAAM,CAAC,QAAQ,WAAW,GAAG,CAE/C,QAAQ,mBAAmB,GAAG,CAE1C,aAAa"}
@@ -0,0 +1,7 @@
1
+ declare namespace fieldModel_d_exports {
2
+ export { serializeID };
3
+ }
4
+ declare function serializeID(input: string): string;
5
+ //#endregion
6
+ export { fieldModel_d_exports };
7
+ //# sourceMappingURL=fieldModel.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fieldModel.d.ts","names":[],"sources":["../../src/helpers/fieldModel.ts"],"mappings":";;;iBAAgB,WAAA,CAAY,KAAA"}
@@ -0,0 +1,13 @@
1
+ import { __exportAll } from "../_virtual/_rolldown/runtime.js";
2
+ //#region src/helpers/fieldModel.ts
3
+ var fieldModel_exports = /* @__PURE__ */ __exportAll({ serializeID: () => serializeID });
4
+ function serializeID(input) {
5
+ const tokens = input.trim().normalize("NFD").replace(/\p{M}/gu, "").split(/[^A-Za-z0-9]+/).filter(Boolean);
6
+ if (tokens.length === 0) throw new Error(`Cannot serialize "${input}": result is empty.`);
7
+ const [first, ...rest] = tokens;
8
+ return first.toLowerCase() + rest.map((token) => token.charAt(0).toUpperCase() + token.slice(1).toLowerCase()).join("");
9
+ }
10
+ //#endregion
11
+ export { fieldModel_exports };
12
+
13
+ //# sourceMappingURL=fieldModel.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fieldModel.js","names":[],"sources":["../../src/helpers/fieldModel.ts"],"sourcesContent":["export function serializeID(input: string): string {\n\tconst tokens = input\n\t\t.trim()\n\t\t.normalize(\"NFD\")\n\t\t.replace(/\\p{M}/gu, \"\")\n\t\t.split(/[^A-Za-z0-9]+/)\n\t\t.filter(Boolean)\n\n\tif (tokens.length === 0) {\n\t\tthrow new Error(`Cannot serialize \"${input}\": result is empty.`)\n\t}\n\n\tconst [first, ...rest] = tokens\n\treturn (\n\t\tfirst.toLowerCase() +\n\t\trest.map((token) => token.charAt(0).toUpperCase() + token.slice(1).toLowerCase()).join(\"\")\n\t)\n}\n"],"mappings":";;;AAAA,SAAgB,YAAY,OAAuB;CAClD,MAAM,SAAS,MACb,MAAM,CACN,UAAU,MAAM,CAChB,QAAQ,WAAW,GAAG,CACtB,MAAM,gBAAgB,CACtB,OAAO,QAAQ;AAEjB,KAAI,OAAO,WAAW,EACrB,OAAM,IAAI,MAAM,qBAAqB,MAAM,qBAAqB;CAGjE,MAAM,CAAC,OAAO,GAAG,QAAQ;AACzB,QACC,MAAM,aAAa,GACnB,KAAK,KAAK,UAAU,MAAM,OAAO,EAAE,CAAC,aAAa,GAAG,MAAM,MAAM,EAAE,CAAC,aAAa,CAAC,CAAC,KAAK,GAAG"}
@@ -0,0 +1,7 @@
1
+ declare namespace repository_d_exports {
2
+ export { serializeID };
3
+ }
4
+ declare function serializeID(input: string): string;
5
+ //#endregion
6
+ export { repository_d_exports };
7
+ //# sourceMappingURL=repository.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"repository.d.ts","names":[],"sources":["../../src/helpers/repository.ts"],"mappings":";;;iBAGgB,WAAA,CAAY,KAAA"}
@@ -0,0 +1,15 @@
1
+ import { __exportAll } from "../_virtual/_rolldown/runtime.js";
2
+ //#region src/helpers/repository.ts
3
+ var repository_exports = /* @__PURE__ */ __exportAll({ serializeID: () => serializeID });
4
+ const MIN_LENGTH = 4;
5
+ const MAX_LENGTH = 63;
6
+ function serializeID(input) {
7
+ const normalized = input.trim().normalize("NFD").replace(/\p{M}/gu, "").toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
8
+ const truncated = normalized.length > MAX_LENGTH ? normalized.slice(0, MAX_LENGTH).replace(/-+$/, "") : normalized;
9
+ if (truncated.length < MIN_LENGTH) throw new Error(`Cannot serialize "${input}" to a repository ID: result must be between ${MIN_LENGTH} and ${MAX_LENGTH} characters.`);
10
+ return truncated;
11
+ }
12
+ //#endregion
13
+ export { repository_exports };
14
+
15
+ //# sourceMappingURL=repository.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"repository.js","names":[],"sources":["../../src/helpers/repository.ts"],"sourcesContent":["const MIN_LENGTH = 4\nconst MAX_LENGTH = 63\n\nexport function serializeID(input: string): string {\n\tconst normalized = input\n\t\t.trim()\n\t\t.normalize(\"NFD\")\n\t\t.replace(/\\p{M}/gu, \"\")\n\t\t.toLowerCase()\n\t\t.replace(/[^a-z0-9]+/g, \"-\")\n\t\t.replace(/^-+|-+$/g, \"\")\n\n\tconst truncated =\n\t\tnormalized.length > MAX_LENGTH\n\t\t\t? normalized.slice(0, MAX_LENGTH).replace(/-+$/, \"\")\n\t\t\t: normalized\n\n\tif (truncated.length < MIN_LENGTH) {\n\t\tthrow new Error(\n\t\t\t`Cannot serialize \"${input}\" to a repository ID: result must be between ${MIN_LENGTH} and ${MAX_LENGTH} characters.`,\n\t\t)\n\t}\n\n\treturn truncated\n}\n"],"mappings":";;;AAAA,MAAM,aAAa;AACnB,MAAM,aAAa;AAEnB,SAAgB,YAAY,OAAuB;CAClD,MAAM,aAAa,MACjB,MAAM,CACN,UAAU,MAAM,CAChB,QAAQ,WAAW,GAAG,CACtB,aAAa,CACb,QAAQ,eAAe,IAAI,CAC3B,QAAQ,YAAY,GAAG;CAEzB,MAAM,YACL,WAAW,SAAS,aACjB,WAAW,MAAM,GAAG,WAAW,CAAC,QAAQ,OAAO,GAAG,GAClD;AAEJ,KAAI,UAAU,SAAS,WACtB,OAAM,IAAI,MACT,qBAAqB,MAAM,+CAA+C,WAAW,OAAO,WAAW,cACvG;AAGF,QAAO"}
@@ -0,0 +1,8 @@
1
+ declare namespace sliceModel_d_exports {
2
+ export { serializeID, serializeVariationID };
3
+ }
4
+ declare function serializeID(input: string): string;
5
+ declare const serializeVariationID: typeof serializeID;
6
+ //#endregion
7
+ export { sliceModel_d_exports };
8
+ //# sourceMappingURL=sliceModel.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sliceModel.d.ts","names":[],"sources":["../../src/helpers/sliceModel.ts"],"mappings":";;;iBAAgB,WAAA,CAAY,KAAA;AAAA,cAiBf,oBAAA,SAAoB,WAAA"}
@@ -0,0 +1,16 @@
1
+ import { __exportAll } from "../_virtual/_rolldown/runtime.js";
2
+ //#region src/helpers/sliceModel.ts
3
+ var sliceModel_exports = /* @__PURE__ */ __exportAll({
4
+ serializeID: () => serializeID,
5
+ serializeVariationID: () => serializeVariationID
6
+ });
7
+ function serializeID(input) {
8
+ const tokens = input.trim().normalize("NFD").replace(/\p{M}/gu, "").split(/[^A-Za-z0-9]+/).filter(Boolean);
9
+ if (tokens.length === 0) throw new Error(`Cannot serialize "${input}": result is empty.`);
10
+ return tokens.map((token) => token.charAt(0).toUpperCase() + token.slice(1).toLowerCase()).join("");
11
+ }
12
+ const serializeVariationID = serializeID;
13
+ //#endregion
14
+ export { sliceModel_exports };
15
+
16
+ //# sourceMappingURL=sliceModel.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sliceModel.js","names":[],"sources":["../../src/helpers/sliceModel.ts"],"sourcesContent":["export function serializeID(input: string): string {\n\tconst tokens = input\n\t\t.trim()\n\t\t.normalize(\"NFD\")\n\t\t.replace(/\\p{M}/gu, \"\")\n\t\t.split(/[^A-Za-z0-9]+/)\n\t\t.filter(Boolean)\n\n\tif (tokens.length === 0) {\n\t\tthrow new Error(`Cannot serialize \"${input}\": result is empty.`)\n\t}\n\n\treturn tokens\n\t\t.map((token) => token.charAt(0).toUpperCase() + token.slice(1).toLowerCase())\n\t\t.join(\"\")\n}\n\nexport const serializeVariationID = serializeID\n"],"mappings":";;;;;;AAAA,SAAgB,YAAY,OAAuB;CAClD,MAAM,SAAS,MACb,MAAM,CACN,UAAU,MAAM,CAChB,QAAQ,WAAW,GAAG,CACtB,MAAM,gBAAgB,CACtB,OAAO,QAAQ;AAEjB,KAAI,OAAO,WAAW,EACrB,OAAM,IAAI,MAAM,qBAAqB,MAAM,qBAAqB;AAGjE,QAAO,OACL,KAAK,UAAU,MAAM,OAAO,EAAE,CAAC,aAAa,GAAG,MAAM,MAAM,EAAE,CAAC,aAAa,CAAC,CAC5E,KAAK,GAAG;;AAGX,MAAa,uBAAuB"}
package/dist/index.d.ts CHANGED
@@ -50,9 +50,12 @@ import { LegacyContentCtx, defaultCtx, getFieldCtx } from "./content/codec/legac
50
50
  import { contentPath_d_exports } from "./helpers/contentPath.js";
51
51
  import { customTypeModel_d_exports } from "./helpers/customTypeModel.js";
52
52
  import { documentContent_d_exports } from "./helpers/documentContent.js";
53
+ import { fieldModel_d_exports } from "./helpers/fieldModel.js";
54
+ import { repository_d_exports } from "./helpers/repository.js";
53
55
  import { sliceContent_d_exports } from "./helpers/sliceContent.js";
56
+ import { sliceModel_d_exports } from "./helpers/sliceModel.js";
54
57
  import { withDefaultContent_d_exports } from "./helpers/withDefaultContent.js";
55
58
  import { imageContent_d_exports } from "./helpers/imageContent.js";
56
59
  import { TraverseSliceContentFunction, TraverseWidgetContentFunction, traverseCompositeSliceContent, traverseDocumentContent, traverseGroupContent, traverseGroupItemsContent, traverseLegacySliceContent, traverseRepeatableContent, traverseSharedSliceContent, traverseSlicesContent, traverseTableContent } from "./helpers/traverseContent.js";
57
60
  import { TraverseSliceContentWithModelFunction, TraverseWidgetContentWithModelFunction, traverseCompositeSliceContentWithModel, traverseDocumentContentWithModel, traverseGroupContentWithModel, traverseGroupItemsContentWithModel, traverseLegacySliceContentWithModel, traverseRepeatableContentWithModel, traverseSharedSliceContentWithModel, traverseSlicesContentWithModel, traverseTableContentWithModel } from "./helpers/traverseContentWithModel.js";
58
- export { type Asset, type BooleanContent, type BooleanModel, type ColorContent, type ColorModel, type CompositeSliceContent, type CompositeSliceItemContent, type CompositeSliceModel, type CustomTypeModel, type DateContent, type DateModel, type DocumentContent, type DynamicCustomTypeModel, type DynamicCustomTypeModelTab, type DynamicSliceModel, type DynamicSlicesModel, type DynamicWidgetModel, type Embed, type EmbedContent, type EmbedModel, type EmptyContent, type EmptyLinkContent, type FieldContent, type FieldModelType, type FilledLinkContent, type GeoPointContent, type GeoPointModel, type GroupContent, type GroupItemContent, type GroupModel, type HexaColorCode, type ImageContent, type ImageContentView, type ImageModel, type IntegrationFieldContent, type IntegrationFieldModel, LegacyContentCtx, type LegacySliceContent, type LegacySliceItemContent, type LegacySliceModel, type LinkContent, type LinkModel, type NestableContent, type NestableModel, type NestedGroupModel, type NonEmptyString, type NumberContent, type NumberModel, type RangeContent, type RangeModel, type RepeatableContent, type RichTextContent, type RichTextContentBlock, type RichTextContentEmbedBlock, type RichTextContentImageBlock, type RichTextContentSpan, type RichTextContentTextBlock, type RichTextModel, RichTextModelNodeType, type RichTextModelNodeTypes, RichTextNodeType, type RichTextNodeTypes, type SelectContent, type SelectModel, type SeparatorContent, type SeparatorModel, type SharedSliceContent, type SharedSliceItemContent, type SharedSliceModel, type SharedSliceModelVariation, type SharedSliceRefModel, type SharedSliceVariationContentModel, type SliceContent, type SliceContentModel, type SliceItemContent, type SliceModelType, type SlicesContent, type StaticCustomTypeModel, type StaticCustomTypeModelTab, type StaticSliceModel, type StaticSlicesModel, type StaticWidgetModel, TableCellModelNodeTypes, type TableContent, type TableModel, type TextContent, type TextModel, type TimestampContent, type TimestampModel, type TraverseSliceContentFunction, type TraverseSliceContentWithModelFunction, type TraverseWidgetContentFunction, type TraverseWidgetContentWithModelFunction, type UIDContent, type UIDModel, type WidgetContent, type WidgetKey, contentPath_d_exports as contentPath, customTypeModel_d_exports as customTypeModel, defaultCtx, documentContent_d_exports as documentContent, getFieldCtx, imageContent_d_exports as imageContent, sliceContent_d_exports as sliceContent, traverseCompositeSliceContent, traverseCompositeSliceContentWithModel, traverseDocumentContent, traverseDocumentContentWithModel, traverseGroupContent, traverseGroupContentWithModel, traverseGroupItemsContent, traverseGroupItemsContentWithModel, traverseLegacySliceContent, traverseLegacySliceContentWithModel, traverseRepeatableContent, traverseRepeatableContentWithModel, traverseSharedSliceContent, traverseSharedSliceContentWithModel, traverseSlicesContent, traverseSlicesContentWithModel, traverseTableContent, traverseTableContentWithModel, withDefaultContent_d_exports as withDefaultContent };
61
+ export { type Asset, type BooleanContent, type BooleanModel, type ColorContent, type ColorModel, type CompositeSliceContent, type CompositeSliceItemContent, type CompositeSliceModel, type CustomTypeModel, type DateContent, type DateModel, type DocumentContent, type DynamicCustomTypeModel, type DynamicCustomTypeModelTab, type DynamicSliceModel, type DynamicSlicesModel, type DynamicWidgetModel, type Embed, type EmbedContent, type EmbedModel, type EmptyContent, type EmptyLinkContent, type FieldContent, type FieldModelType, type FilledLinkContent, type GeoPointContent, type GeoPointModel, type GroupContent, type GroupItemContent, type GroupModel, type HexaColorCode, type ImageContent, type ImageContentView, type ImageModel, type IntegrationFieldContent, type IntegrationFieldModel, LegacyContentCtx, type LegacySliceContent, type LegacySliceItemContent, type LegacySliceModel, type LinkContent, type LinkModel, type NestableContent, type NestableModel, type NestedGroupModel, type NonEmptyString, type NumberContent, type NumberModel, type RangeContent, type RangeModel, type RepeatableContent, type RichTextContent, type RichTextContentBlock, type RichTextContentEmbedBlock, type RichTextContentImageBlock, type RichTextContentSpan, type RichTextContentTextBlock, type RichTextModel, RichTextModelNodeType, type RichTextModelNodeTypes, RichTextNodeType, type RichTextNodeTypes, type SelectContent, type SelectModel, type SeparatorContent, type SeparatorModel, type SharedSliceContent, type SharedSliceItemContent, type SharedSliceModel, type SharedSliceModelVariation, type SharedSliceRefModel, type SharedSliceVariationContentModel, type SliceContent, type SliceContentModel, type SliceItemContent, type SliceModelType, type SlicesContent, type StaticCustomTypeModel, type StaticCustomTypeModelTab, type StaticSliceModel, type StaticSlicesModel, type StaticWidgetModel, TableCellModelNodeTypes, type TableContent, type TableModel, type TextContent, type TextModel, type TimestampContent, type TimestampModel, type TraverseSliceContentFunction, type TraverseSliceContentWithModelFunction, type TraverseWidgetContentFunction, type TraverseWidgetContentWithModelFunction, type UIDContent, type UIDModel, type WidgetContent, type WidgetKey, contentPath_d_exports as contentPath, customTypeModel_d_exports as customTypeModel, defaultCtx, documentContent_d_exports as documentContent, fieldModel_d_exports as fieldModel, getFieldCtx, imageContent_d_exports as imageContent, repository_d_exports as repository, sliceContent_d_exports as sliceContent, sliceModel_d_exports as sliceModel, traverseCompositeSliceContent, traverseCompositeSliceContentWithModel, traverseDocumentContent, traverseDocumentContentWithModel, traverseGroupContent, traverseGroupContentWithModel, traverseGroupItemsContent, traverseGroupItemsContentWithModel, traverseLegacySliceContent, traverseLegacySliceContentWithModel, traverseRepeatableContent, traverseRepeatableContentWithModel, traverseSharedSliceContent, traverseSharedSliceContentWithModel, traverseSlicesContent, traverseSlicesContentWithModel, traverseTableContent, traverseTableContentWithModel, withDefaultContent_d_exports as withDefaultContent };
package/dist/index.js CHANGED
@@ -8,7 +8,10 @@ import { customTypeModel_exports } from "./helpers/customTypeModel.js";
8
8
  import { sliceContent_exports } from "./helpers/sliceContent.js";
9
9
  import { traverseCompositeSliceContent, traverseDocumentContent, traverseGroupContent, traverseGroupItemsContent, traverseLegacySliceContent, traverseRepeatableContent, traverseSharedSliceContent, traverseSlicesContent, traverseTableContent } from "./helpers/traverseContent.js";
10
10
  import { documentContent_exports } from "./helpers/documentContent.js";
11
+ import { fieldModel_exports } from "./helpers/fieldModel.js";
12
+ import { repository_exports } from "./helpers/repository.js";
13
+ import { sliceModel_exports } from "./helpers/sliceModel.js";
11
14
  import { withDefaultContent_exports } from "./helpers/withDefaultContent.js";
12
15
  import { imageContent_exports } from "./helpers/imageContent.js";
13
16
  import { traverseCompositeSliceContentWithModel, traverseDocumentContentWithModel, traverseGroupContentWithModel, traverseGroupItemsContentWithModel, traverseLegacySliceContentWithModel, traverseRepeatableContentWithModel, traverseSharedSliceContentWithModel, traverseSlicesContentWithModel, traverseTableContentWithModel } from "./helpers/traverseContentWithModel.js";
14
- export { LegacyContentCtx, RichTextModelNodeType, RichTextNodeType, TableCellModelNodeTypes, contentPath_exports as contentPath, customTypeModel_exports as customTypeModel, defaultCtx, documentContent_exports as documentContent, getFieldCtx, imageContent_exports as imageContent, sliceContent_exports as sliceContent, traverseCompositeSliceContent, traverseCompositeSliceContentWithModel, traverseDocumentContent, traverseDocumentContentWithModel, traverseGroupContent, traverseGroupContentWithModel, traverseGroupItemsContent, traverseGroupItemsContentWithModel, traverseLegacySliceContent, traverseLegacySliceContentWithModel, traverseRepeatableContent, traverseRepeatableContentWithModel, traverseSharedSliceContent, traverseSharedSliceContentWithModel, traverseSlicesContent, traverseSlicesContentWithModel, traverseTableContent, traverseTableContentWithModel, withDefaultContent_exports as withDefaultContent };
17
+ export { LegacyContentCtx, RichTextModelNodeType, RichTextNodeType, TableCellModelNodeTypes, contentPath_exports as contentPath, customTypeModel_exports as customTypeModel, defaultCtx, documentContent_exports as documentContent, fieldModel_exports as fieldModel, getFieldCtx, imageContent_exports as imageContent, repository_exports as repository, sliceContent_exports as sliceContent, sliceModel_exports as sliceModel, traverseCompositeSliceContent, traverseCompositeSliceContentWithModel, traverseDocumentContent, traverseDocumentContentWithModel, traverseGroupContent, traverseGroupContentWithModel, traverseGroupItemsContent, traverseGroupItemsContentWithModel, traverseLegacySliceContent, traverseLegacySliceContentWithModel, traverseRepeatableContent, traverseRepeatableContentWithModel, traverseSharedSliceContent, traverseSharedSliceContentWithModel, traverseSlicesContent, traverseSlicesContentWithModel, traverseTableContent, traverseTableContentWithModel, withDefaultContent_exports as withDefaultContent };
@@ -1 +1 @@
1
- {"version":3,"file":"customType.d.ts","names":[],"sources":["../../src/model/customType.ts"],"mappings":";;;;cAMa,8BAAA,EAA8B,CAAA,CAAA,aAAA,CAAA,CAAA,CAAA,aAAA,UAAA,CAAA,CAAA,WAAA,CAAA,iBAAA,WAAA,CAAA,CAAA,IAAA,CAAA,iBAAA,CAAA,iBAAA;AAAA,KAC/B,wBAAA,GAA2B,CAAA,CAAE,KAAA,QAAa,8BAAA;AAAA,cAEzC,+BAAA,EAA+B,CAAA,CAAA,aAAA,CAAA,CAAA,CAAA,aAAA,UAAA,CAAA,CAAA,WAAA,CAAA,kBAAA,WAAA,CAAA,CAAA,IAAA,CAAA,iBAAA,CAAA,kBAAA;AAAA,KAChC,yBAAA,GAA4B,CAAA,CAAE,KAAA,QAAa,+BAAA;AAAA,cAiB1C,2BAAA,EAA2B,CAAA,CAAA,aAAA;;;;;;;;;;;KAC5B,qBAAA,GAAwB,CAAA,CAAE,KAAA,QAAa,2BAAA;AAAA,cAEtC,4BAAA,EAA4B,CAAA,CAAA,aAAA;;;;;;;;;;;KAC7B,sBAAA,GAAyB,CAAA,CAAE,KAAA,QAAa,4BAAA;;KAKxC,eAAA,GAAkB,sBAAA"}
1
+ {"version":3,"file":"customType.d.ts","names":[],"sources":["../../src/model/customType.ts"],"mappings":";;;;cAMa,8BAAA,EAA8B,CAAA,CAAA,aAAA,CAAA,CAAA,CAAA,aAAA,UAAA,CAAA,CAAA,WAAA,CAAA,iBAAA,WAAA,CAAA,CAAA,IAAA,CAAA,iBAAA,CAAA,iBAAA;AAAA,KAC/B,wBAAA,GAA2B,CAAA,CAAE,KAAA,QAAa,8BAAA;AAAA,cAEzC,+BAAA,EAA+B,CAAA,CAAA,aAAA,CAAA,CAAA,CAAA,aAAA,UAAA,CAAA,CAAA,WAAA,CAAA,kBAAA,WAAA,CAAA,CAAA,IAAA,CAAA,iBAAA,CAAA,kBAAA;AAAA,KAChC,yBAAA,GAA4B,CAAA,CAAE,KAAA,QAAa,+BAAA;AAAA,cAwD1C,2BAAA,EAA2B,CAAA,CAAA,aAAA;;;;;;;;;;;KAC5B,qBAAA,GAAwB,CAAA,CAAE,KAAA,QAAa,2BAAA;AAAA,cAEtC,4BAAA,EAA4B,CAAA,CAAA,aAAA;;;;;;;;;;;KAC7B,sBAAA,GAAyB,CAAA,CAAE,KAAA,QAAa,4BAAA;;KAKxC,eAAA,GAAkB,sBAAA"}
@@ -12,7 +12,36 @@ const createCustomTypeSchema = (sectionSchema) => z.object({
12
12
  json: z.record(z.string(), sectionSchema),
13
13
  status: z._default(z.boolean(), true),
14
14
  format: z._default(CustomTypeFormatSchema, "custom")
15
- });
15
+ }).check(z.superRefine((model, ctx) => {
16
+ const { json } = model;
17
+ const tabEntries = Object.entries(json);
18
+ const existingWidgetKeys = /* @__PURE__ */ new Map();
19
+ for (const [tabID, tab] of tabEntries) for (const [widgetID, widget] of Object.entries(tab)) {
20
+ if (widget.type === "UID" && widgetID !== "uid") ctx.addIssue({
21
+ code: "custom",
22
+ message: `The UID widget ID must be set to "uid"`,
23
+ path: [
24
+ "json",
25
+ tabID,
26
+ widgetID
27
+ ]
28
+ });
29
+ const maybeTabID = existingWidgetKeys.get(widgetID);
30
+ if (typeof maybeTabID === "string") {
31
+ ctx.addIssue({
32
+ code: "custom",
33
+ message: `${widgetID} already exists in the "${maybeTabID}" tab`,
34
+ path: [
35
+ "json",
36
+ tabID,
37
+ widgetID
38
+ ]
39
+ });
40
+ continue;
41
+ }
42
+ existingWidgetKeys.set(widgetID, tabID);
43
+ }
44
+ }));
16
45
  const StaticCustomTypeModelSchema = createCustomTypeSchema(StaticCustomTypeModelTabSchema);
17
46
  const DynamicCustomTypeModelSchema = createCustomTypeSchema(DynamicCustomTypeModelTabSchema);
18
47
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"customType.js","names":[],"sources":["../../src/model/customType.ts"],"sourcesContent":["import { z } from \"zod/mini\"\n\nimport { WidgetKeySchema } from \"../common/widgetKey\"\nimport { DynamicWidgetModelSchema, StaticWidgetModelSchema } from \"./widget\"\n\n// Tab\nexport const StaticCustomTypeModelTabSchema = z.record(WidgetKeySchema, StaticWidgetModelSchema)\nexport type StaticCustomTypeModelTab = z.infer<typeof StaticCustomTypeModelTabSchema>\n\nexport const DynamicCustomTypeModelTabSchema = z.record(WidgetKeySchema, DynamicWidgetModelSchema)\nexport type DynamicCustomTypeModelTab = z.infer<typeof DynamicCustomTypeModelTabSchema>\n\n// Custom types\nexport const CustomTypeFormatSchema = z.enum([\"page\", \"custom\"])\nexport type CustomTypeFormat = z.infer<typeof CustomTypeFormatSchema>\n\n// Factory to create CustomType schema with configurable section type\nconst createCustomTypeSchema = <T extends z.ZodMiniType>(sectionSchema: T) =>\n\tz.object({\n\t\tid: z.string(),\n\t\tlabel: z.nullish(z.string()),\n\t\trepeatable: z._default(z.boolean(), true),\n\t\tjson: z.record(z.string(), sectionSchema),\n\t\tstatus: z._default(z.boolean(), true),\n\t\tformat: z._default(CustomTypeFormatSchema, \"custom\"),\n\t})\n\nexport const StaticCustomTypeModelSchema = createCustomTypeSchema(StaticCustomTypeModelTabSchema)\nexport type StaticCustomTypeModel = z.infer<typeof StaticCustomTypeModelSchema>\n\nexport const DynamicCustomTypeModelSchema = createCustomTypeSchema(DynamicCustomTypeModelTabSchema)\nexport type DynamicCustomTypeModel = z.infer<typeof DynamicCustomTypeModelSchema>\n\n/** @deprecated Use DynamicCustomTypeModelSchema instead */\nexport const CustomTypeModelSchema = DynamicCustomTypeModelSchema\n/** @deprecated Use DynamicCustomTypeModel instead */\nexport type CustomTypeModel = DynamicCustomTypeModel\n"],"mappings":";;;;AAMA,MAAa,iCAAiC,EAAE,OAAO,iBAAiB,wBAAwB;AAGhG,MAAa,kCAAkC,EAAE,OAAO,iBAAiB,yBAAyB;AAIlG,MAAa,yBAAyB,EAAE,KAAK,CAAC,QAAQ,SAAS,CAAC;AAIhE,MAAM,0BAAmD,kBACxD,EAAE,OAAO;CACR,IAAI,EAAE,QAAQ;CACd,OAAO,EAAE,QAAQ,EAAE,QAAQ,CAAC;CAC5B,YAAY,EAAE,SAAS,EAAE,SAAS,EAAE,KAAK;CACzC,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,cAAc;CACzC,QAAQ,EAAE,SAAS,EAAE,SAAS,EAAE,KAAK;CACrC,QAAQ,EAAE,SAAS,wBAAwB,SAAS;CACpD,CAAC;AAEH,MAAa,8BAA8B,uBAAuB,+BAA+B;AAGjG,MAAa,+BAA+B,uBAAuB,gCAAgC"}
1
+ {"version":3,"file":"customType.js","names":[],"sources":["../../src/model/customType.ts"],"sourcesContent":["import { z } from \"zod/mini\"\n\nimport { WidgetKeySchema } from \"../common/widgetKey\"\nimport { DynamicWidgetModelSchema, StaticWidgetModelSchema } from \"./widget\"\n\n// Tab\nexport const StaticCustomTypeModelTabSchema = z.record(WidgetKeySchema, StaticWidgetModelSchema)\nexport type StaticCustomTypeModelTab = z.infer<typeof StaticCustomTypeModelTabSchema>\n\nexport const DynamicCustomTypeModelTabSchema = z.record(WidgetKeySchema, DynamicWidgetModelSchema)\nexport type DynamicCustomTypeModelTab = z.infer<typeof DynamicCustomTypeModelTabSchema>\n\n// Custom types\nexport const CustomTypeFormatSchema = z.enum([\"page\", \"custom\"])\nexport type CustomTypeFormat = z.infer<typeof CustomTypeFormatSchema>\n\n// Factory to create CustomType schema with configurable section type\nconst createCustomTypeSchema = <\n\tT extends typeof StaticCustomTypeModelTabSchema | typeof DynamicCustomTypeModelTabSchema,\n>(\n\tsectionSchema: T,\n) =>\n\tz\n\t\t.object({\n\t\t\tid: z.string(),\n\t\t\tlabel: z.nullish(z.string()),\n\t\t\trepeatable: z._default(z.boolean(), true),\n\t\t\tjson: z.record(z.string(), sectionSchema),\n\t\t\tstatus: z._default(z.boolean(), true),\n\t\t\tformat: z._default(CustomTypeFormatSchema, \"custom\"),\n\t\t})\n\t\t.check(\n\t\t\tz.superRefine((model, ctx) => {\n\t\t\t\tconst { json } = model\n\n\t\t\t\tconst tabEntries = Object.entries(json)\n\n\t\t\t\t// A map of widget IDs to the tab they belong to\n\t\t\t\t// to check for ID uniqueness across all tabs.\n\t\t\t\tconst existingWidgetKeys = new Map<string, string>()\n\t\t\t\tfor (const [tabID, tab] of tabEntries) {\n\t\t\t\t\tfor (const [widgetID, widget] of Object.entries(tab)) {\n\t\t\t\t\t\tif (widget.type === \"UID\" && widgetID !== \"uid\") {\n\t\t\t\t\t\t\tctx.addIssue({\n\t\t\t\t\t\t\t\tcode: \"custom\",\n\t\t\t\t\t\t\t\tmessage: `The UID widget ID must be set to \"uid\"`,\n\t\t\t\t\t\t\t\tpath: [\"json\", tabID, widgetID],\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tconst maybeTabID = existingWidgetKeys.get(widgetID)\n\t\t\t\t\t\tif (typeof maybeTabID === \"string\") {\n\t\t\t\t\t\t\tctx.addIssue({\n\t\t\t\t\t\t\t\tcode: \"custom\",\n\t\t\t\t\t\t\t\tmessage: `${widgetID} already exists in the \"${maybeTabID}\" tab`,\n\t\t\t\t\t\t\t\tpath: [\"json\", tabID, widgetID],\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\texistingWidgetKeys.set(widgetID, tabID)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}),\n\t\t)\n\nexport const StaticCustomTypeModelSchema = createCustomTypeSchema(StaticCustomTypeModelTabSchema)\nexport type StaticCustomTypeModel = z.infer<typeof StaticCustomTypeModelSchema>\n\nexport const DynamicCustomTypeModelSchema = createCustomTypeSchema(DynamicCustomTypeModelTabSchema)\nexport type DynamicCustomTypeModel = z.infer<typeof DynamicCustomTypeModelSchema>\n\n/** @deprecated Use DynamicCustomTypeModelSchema instead */\nexport const CustomTypeModelSchema = DynamicCustomTypeModelSchema\n/** @deprecated Use DynamicCustomTypeModel instead */\nexport type CustomTypeModel = DynamicCustomTypeModel\n"],"mappings":";;;;AAMA,MAAa,iCAAiC,EAAE,OAAO,iBAAiB,wBAAwB;AAGhG,MAAa,kCAAkC,EAAE,OAAO,iBAAiB,yBAAyB;AAIlG,MAAa,yBAAyB,EAAE,KAAK,CAAC,QAAQ,SAAS,CAAC;AAIhE,MAAM,0BAGL,kBAEA,EACE,OAAO;CACP,IAAI,EAAE,QAAQ;CACd,OAAO,EAAE,QAAQ,EAAE,QAAQ,CAAC;CAC5B,YAAY,EAAE,SAAS,EAAE,SAAS,EAAE,KAAK;CACzC,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,cAAc;CACzC,QAAQ,EAAE,SAAS,EAAE,SAAS,EAAE,KAAK;CACrC,QAAQ,EAAE,SAAS,wBAAwB,SAAS;CACpD,CAAC,CACD,MACA,EAAE,aAAa,OAAO,QAAQ;CAC7B,MAAM,EAAE,SAAS;CAEjB,MAAM,aAAa,OAAO,QAAQ,KAAK;CAIvC,MAAM,qCAAqB,IAAI,KAAqB;AACpD,MAAK,MAAM,CAAC,OAAO,QAAQ,WAC1B,MAAK,MAAM,CAAC,UAAU,WAAW,OAAO,QAAQ,IAAI,EAAE;AACrD,MAAI,OAAO,SAAS,SAAS,aAAa,MACzC,KAAI,SAAS;GACZ,MAAM;GACN,SAAS;GACT,MAAM;IAAC;IAAQ;IAAO;IAAS;GAC/B,CAAC;EAGH,MAAM,aAAa,mBAAmB,IAAI,SAAS;AACnD,MAAI,OAAO,eAAe,UAAU;AACnC,OAAI,SAAS;IACZ,MAAM;IACN,SAAS,GAAG,SAAS,0BAA0B,WAAW;IAC1D,MAAM;KAAC;KAAQ;KAAO;KAAS;IAC/B,CAAC;AACF;;AAGD,qBAAmB,IAAI,UAAU,MAAM;;EAGxC,CACF;AAEH,MAAa,8BAA8B,uBAAuB,+BAA+B;AAGjG,MAAa,+BAA+B,uBAAuB,gCAAgC"}
@@ -12,7 +12,7 @@ const SideConstraintSchema = z.union([
12
12
  z.pipe(z.literal("auto"), z.transform(() => null)),
13
13
  z.pipe(z.literal(""), z.transform(() => null)),
14
14
  z.null(),
15
- z.number().check(z.int()),
15
+ z.int(),
16
16
  z.pipe(z.string(), z.transform((s) => parseInt(s.replace("px", ""), 10)))
17
17
  ]);
18
18
  const ImageConstraintSchema = z.object({
@@ -1 +1 @@
1
- {"version":3,"file":"image.js","names":[],"sources":["../../src/model/image.ts"],"sourcesContent":["import { z } from \"zod/mini\"\n\n/**\n * SideConstraint accepts multiple input formats and normalizes to number | null:\n * - Integer values\n * - String integers (e.g., \"100\")\n * - Pixel strings (e.g., \"100px\")\n * - \"auto\" or \"\" → null\n * - null\n */\nexport const SideConstraintSchema: z.ZodMiniType<number | null> = z.union([\n\tz.pipe(\n\t\tz.literal(\"auto\"),\n\t\tz.transform(() => null),\n\t),\n\tz.pipe(\n\t\tz.literal(\"\"),\n\t\tz.transform(() => null),\n\t),\n\tz.null(),\n\tz.number().check(z.int()),\n\tz.pipe(\n\t\tz.string(),\n\t\tz.transform((s: string) => parseInt(s.replace(\"px\", \"\"), 10)),\n\t),\n])\n\nexport const ImageConstraintSchema = z.object({\n\twidth: z.optional(SideConstraintSchema),\n\theight: z.optional(SideConstraintSchema),\n})\n\nexport type ImageConstraint = z.infer<typeof ImageConstraintSchema>\n\nconst ThumbnailSchema = z.object({\n\tname: z.string(),\n\twidth: z.optional(SideConstraintSchema),\n\theight: z.optional(SideConstraintSchema),\n})\n\nconst ImageConfigSchema = z.object({\n\tlabel: z.nullish(z.string()),\n\tplaceholder: z.optional(z.string()),\n\tconstraint: z.optional(ImageConstraintSchema),\n\tthumbnails: z.optional(z.array(ThumbnailSchema)),\n})\n\nexport const ImageModelSchema = z.object({\n\ttype: z.literal(\"Image\"),\n\tfieldset: z.nullish(z.string()),\n\tconfig: z.optional(ImageConfigSchema),\n})\n\nexport type ImageModel = z.infer<typeof ImageModelSchema>\n"],"mappings":";;;;;;;;;;AAUA,MAAa,uBAAqD,EAAE,MAAM;CACzE,EAAE,KACD,EAAE,QAAQ,OAAO,EACjB,EAAE,gBAAgB,KAAK,CACvB;CACD,EAAE,KACD,EAAE,QAAQ,GAAG,EACb,EAAE,gBAAgB,KAAK,CACvB;CACD,EAAE,MAAM;CACR,EAAE,QAAQ,CAAC,MAAM,EAAE,KAAK,CAAC;CACzB,EAAE,KACD,EAAE,QAAQ,EACV,EAAE,WAAW,MAAc,SAAS,EAAE,QAAQ,MAAM,GAAG,EAAE,GAAG,CAAC,CAC7D;CACD,CAAC;AAEF,MAAa,wBAAwB,EAAE,OAAO;CAC7C,OAAO,EAAE,SAAS,qBAAqB;CACvC,QAAQ,EAAE,SAAS,qBAAqB;CACxC,CAAC;AAIF,MAAM,kBAAkB,EAAE,OAAO;CAChC,MAAM,EAAE,QAAQ;CAChB,OAAO,EAAE,SAAS,qBAAqB;CACvC,QAAQ,EAAE,SAAS,qBAAqB;CACxC,CAAC;AAEF,MAAM,oBAAoB,EAAE,OAAO;CAClC,OAAO,EAAE,QAAQ,EAAE,QAAQ,CAAC;CAC5B,aAAa,EAAE,SAAS,EAAE,QAAQ,CAAC;CACnC,YAAY,EAAE,SAAS,sBAAsB;CAC7C,YAAY,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;CAChD,CAAC;AAEF,MAAa,mBAAmB,EAAE,OAAO;CACxC,MAAM,EAAE,QAAQ,QAAQ;CACxB,UAAU,EAAE,QAAQ,EAAE,QAAQ,CAAC;CAC/B,QAAQ,EAAE,SAAS,kBAAkB;CACrC,CAAC"}
1
+ {"version":3,"file":"image.js","names":[],"sources":["../../src/model/image.ts"],"sourcesContent":["import { z } from \"zod/mini\"\n\n/**\n * SideConstraint accepts multiple input formats and normalizes to number | null:\n * - Integer values\n * - String integers (e.g., \"100\")\n * - Pixel strings (e.g., \"100px\")\n * - \"auto\" or \"\" → null\n * - null\n */\nexport const SideConstraintSchema: z.ZodMiniType<number | null> = z.union([\n\tz.pipe(\n\t\tz.literal(\"auto\"),\n\t\tz.transform(() => null),\n\t),\n\tz.pipe(\n\t\tz.literal(\"\"),\n\t\tz.transform(() => null),\n\t),\n\tz.null(),\n\tz.int(),\n\tz.pipe(\n\t\tz.string(),\n\t\tz.transform((s: string) => parseInt(s.replace(\"px\", \"\"), 10)),\n\t),\n])\n\nexport const ImageConstraintSchema = z.object({\n\twidth: z.optional(SideConstraintSchema),\n\theight: z.optional(SideConstraintSchema),\n})\n\nexport type ImageConstraint = z.infer<typeof ImageConstraintSchema>\n\nconst ThumbnailSchema = z.object({\n\tname: z.string(),\n\twidth: z.optional(SideConstraintSchema),\n\theight: z.optional(SideConstraintSchema),\n})\n\nconst ImageConfigSchema = z.object({\n\tlabel: z.nullish(z.string()),\n\tplaceholder: z.optional(z.string()),\n\tconstraint: z.optional(ImageConstraintSchema),\n\tthumbnails: z.optional(z.array(ThumbnailSchema)),\n})\n\nexport const ImageModelSchema = z.object({\n\ttype: z.literal(\"Image\"),\n\tfieldset: z.nullish(z.string()),\n\tconfig: z.optional(ImageConfigSchema),\n})\n\nexport type ImageModel = z.infer<typeof ImageModelSchema>\n"],"mappings":";;;;;;;;;;AAUA,MAAa,uBAAqD,EAAE,MAAM;CACzE,EAAE,KACD,EAAE,QAAQ,OAAO,EACjB,EAAE,gBAAgB,KAAK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AsB,gBAAA,GAAmB,mBAAA;AAAA,KAQ7D,gBAAA,GAAmB,mBAAA,GAAsB,gBAAA,GAAmB,gBAAA;AAAA,KAS5D,iBAAA,GACT,mBAAA,GACA,gBAAA,GACA,gCAAA;AAAA,cAGU,oBAAA,EAAoB,CAAA,CAAA,YAAA,WAAA,CAAA,CAAA,cAAA,WAAA,CAAA,CAAA,cAAA;AAAA,KAKrB,cAAA,GAAiB,CAAA,CAAE,KAAA,QAAa,oBAAA"}
@@ -35,7 +35,27 @@ const SharedSliceModelSchema = z.object({
35
35
  variations: z.array(SharedSliceModelVariationSchema),
36
36
  description: z.optional(z.string()),
37
37
  legacyPaths: z.optional(z.record(z.string(), z.string()))
38
- });
38
+ }).check(z.superRefine((model, ctx) => {
39
+ if (model.variations.length === 0) ctx.addIssue({
40
+ code: "custom",
41
+ message: `Shared slice "${model.id}" must have at least one variation`,
42
+ path: ["variations"]
43
+ });
44
+ const existingVariationIDs = /* @__PURE__ */ new Map();
45
+ for (let index = 0; index < model.variations.length; index++) {
46
+ const variation = model.variations[index];
47
+ const maybeIndex = existingVariationIDs.get(variation.id);
48
+ if (Number.isInteger(maybeIndex)) {
49
+ ctx.addIssue({
50
+ code: "custom",
51
+ message: `Variation ID "${variation.id}" already exists at index "${maybeIndex}"`,
52
+ path: ["variations", index]
53
+ });
54
+ continue;
55
+ }
56
+ existingVariationIDs.set(variation.id, index);
57
+ }
58
+ }));
39
59
  const SharedSliceRefModelSchema = z.object({ type: z.literal(SharedSliceType) });
40
60
  const SharedSliceVariationContentModelSchema = z.object({
41
61
  type: z.literal(SharedSliceType),
@@ -1 +1 @@
1
- {"version":3,"file":"slice.js","names":[],"sources":["../../src/model/slice.ts"],"sourcesContent":["import { z } from \"zod/mini\"\n\nimport { WidgetKeySchema } from \"../common/widgetKey\"\nimport type { GroupModel, NestedGroupModel } from \"./group\"\nimport { GroupModelSchema, NestedGroupModelSchema } from \"./group\"\nimport type { NestableModel } from \"./nestable\"\nimport { NestableModelSchema } from \"./nestable\"\n\n// Simple (before 2020)\nexport const LegacySliceModelSchema = z.discriminatedUnion(\"type\", [\n\tNestableModelSchema,\n\tNestedGroupModelSchema,\n])\n\nexport type LegacySliceModel = NestableModel | NestedGroupModel\n\n// Composite (2020 to 2021)\nexport const CompositeSliceType = \"Slice\" as const\n\nconst CompositeSliceConfigSchema = z.object({\n\tlabel: z.nullish(z.string()),\n})\n\nexport const CompositeSliceModelSchema = z.object({\n\ttype: z.literal(CompositeSliceType),\n\tfieldset: z.nullish(z.string()),\n\tdescription: z.optional(z.string()),\n\ticon: z.optional(z.string()),\n\tdisplay: z.optional(z.string()),\n\t\"non-repeat\": z.optional(z.record(WidgetKeySchema, NestableModelSchema)),\n\trepeat: z.optional(z.record(WidgetKeySchema, NestableModelSchema)),\n\tconfig: z.optional(CompositeSliceConfigSchema),\n})\n\nexport type CompositeSliceModel = z.infer<typeof CompositeSliceModelSchema>\n\n// Shared (2021 to present)\nexport const SharedSliceType = \"SharedSlice\" as const\n\nconst IMAGE_PLACEHOLDER_URL =\n\t\"https://images.prismic.io/slice-machine/621a5ec4-0387-4bc5-9860-2dd46cbc07cd_default_ss.png?auto=compress,format\"\n\nexport const SharedSliceModelVariationSchema = z.object({\n\tid: z.string(),\n\tname: z.string(),\n\tdescription: z.string(),\n\timageUrl: z._default(z.string(), IMAGE_PLACEHOLDER_URL),\n\tdocURL: z.string(),\n\tversion: z.string(),\n\tdisplay: z.optional(z.string()),\n\tprimary: z.optional(\n\t\tz.record(\n\t\t\tz.string(),\n\t\t\tz.discriminatedUnion(\"type\", [NestableModelSchema, GroupModelSchema]) as z.ZodMiniType<\n\t\t\t\tNestableModel | GroupModel\n\t\t\t>,\n\t\t),\n\t),\n\titems: z.optional(z.record(z.string(), NestableModelSchema)),\n})\n\nexport type SharedSliceModelVariation = z.infer<typeof SharedSliceModelVariationSchema>\n\nexport const SharedSliceModelSchema = z.object({\n\tid: z.string(),\n\ttype: z.literal(SharedSliceType),\n\tname: z.string(),\n\tvariations: z.array(SharedSliceModelVariationSchema),\n\tdescription: z.optional(z.string()),\n\tlegacyPaths: z.optional(z.record(z.string(), z.string())),\n})\n\nexport type SharedSliceModel = z.infer<typeof SharedSliceModelSchema>\n\nexport const SharedSliceRefModelSchema = z.object({\n\ttype: z.literal(SharedSliceType),\n})\n\nexport type SharedSliceRefModel = z.infer<typeof SharedSliceRefModelSchema>\n\n// Used to represent a shared slice content which can only be\n// of a given shared slice variation type.\nexport const SharedSliceVariationContentModelSchema = z.object({\n\ttype: z.literal(SharedSliceType),\n\tsliceName: z.string(),\n\tvariationID: z.string(),\n\tfields: z.pick(SharedSliceModelVariationSchema, { primary: true, items: true }),\n})\n\nexport type SharedSliceVariationContentModel = z.infer<\n\ttypeof SharedSliceVariationContentModelSchema\n>\n\n// All\n\n// Used when slices reference SharedSlice by ref (not full definition)\nexport const DynamicSliceModelSchema: z.ZodMiniType<DynamicSliceModel> = z.discriminatedUnion(\n\t\"type\",\n\t[CompositeSliceModelSchema, LegacySliceModelSchema, SharedSliceRefModelSchema],\n)\n\nexport type DynamicSliceModel = CompositeSliceModel | LegacySliceModel | SharedSliceRefModel\n\n// Used when slices include full SharedSlice definition\nexport const StaticSliceModelSchema: z.ZodMiniType<StaticSliceModel> = z.discriminatedUnion(\n\t\"type\",\n\t[CompositeSliceModelSchema, LegacySliceModelSchema, SharedSliceModelSchema],\n)\n\nexport type StaticSliceModel = CompositeSliceModel | LegacySliceModel | SharedSliceModel\n\n// Used to represent a slice content model as shared slice variations\n// can only be of a given shared slice variation type.\nexport const SliceContentModelSchema: z.ZodMiniType<SliceContentModel> = z.discriminatedUnion(\n\t\"type\",\n\t[CompositeSliceModelSchema, LegacySliceModelSchema, SharedSliceVariationContentModelSchema],\n)\n\nexport type SliceContentModel =\n\t| CompositeSliceModel\n\t| LegacySliceModel\n\t| SharedSliceVariationContentModel\n\n// Model types\nexport const SliceModelTypeSchema = z.union([\n\tz.literal(CompositeSliceType),\n\tz.literal(SharedSliceType),\n])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Q;CAChB,YAAY,EAAE,MAAM,gCAAgC;CACpD,aAAa,EAAE,SAAS,EAAE,QAAQ,CAAC;CACnC,aAAa,EAAE,SAAS,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,QAAQ,CAAC,CAAC;CACzD,CAAC;AAIF,MAAa,4BAA4B,EAAE,OAAO,EACjD,MAAM,EAAE,QAAQ,gBAAgB,EAChC,CAAC;AAMF,MAAa,yCAAyC,EAAE,OAAO;CAC9D,MAAM,EAAE,QAAQ,gBAAgB;CAChC,WAAW,EAAE,QAAQ;CACrB,aAAa,EAAE,QAAQ;CACvB,QAAQ,EAAE,KAAK,iCAAiC;EAAE,SAAS;EAAM,OAAO;EAAM,CAAC;CAC/E,CAAC;AASF,MAAa,0BAA4D,EAAE,mBAC1E,QACA;CAAC;CAA2B;CAAwB;CAA0B,CAC9E;AAKD,MAAa,yBAA0D,EAAE,mBACxE,QACA;CAAC;CAA2B;CAAwB;CAAuB,CAC3E;AAMD,MAAa,0BAA4D,EAAE,mBAC1E,QACA;CAAC;CAA2B;CAAwB;CAAuC,CAC3F;AAQD,MAAa,uBAAuB,EAAE,MAAM,CAC3C,EAAE,QAAQ,mBAAmB,EAC7B,EAAE,QAAQ,gBAAgB,CAC1B,CAAC"}
1
+ {"version":3,"file":"slice.js","names":[],"sources":["../../src/model/slice.ts"],"sourcesContent":["import { z } from \"zod/mini\"\n\nimport { WidgetKeySchema } from \"../common/widgetKey\"\nimport type { GroupModel, NestedGroupModel } from \"./group\"\nimport { GroupModelSchema, NestedGroupModelSchema } from \"./group\"\nimport type { NestableModel } from \"./nestable\"\nimport { NestableModelSchema } from \"./nestable\"\n\n// Simple (before 2020)\nexport const LegacySliceModelSchema = z.discriminatedUnion(\"type\", [\n\tNestableModelSchema,\n\tNestedGroupModelSchema,\n])\n\nexport type LegacySliceModel = NestableModel | NestedGroupModel\n\n// Composite (2020 to 2021)\nexport const CompositeSliceType = \"Slice\" as const\n\nconst CompositeSliceConfigSchema = z.object({\n\tlabel: z.nullish(z.string()),\n})\n\nexport const CompositeSliceModelSchema = z.object({\n\ttype: z.literal(CompositeSliceType),\n\tfieldset: z.nullish(z.string()),\n\tdescription: z.optional(z.string()),\n\ticon: z.optional(z.string()),\n\tdisplay: z.optional(z.string()),\n\t\"non-repeat\": z.optional(z.record(WidgetKeySchema, NestableModelSchema)),\n\trepeat: z.optional(z.record(WidgetKeySchema, NestableModelSchema)),\n\tconfig: z.optional(CompositeSliceConfigSchema),\n})\n\nexport type CompositeSliceModel = z.infer<typeof CompositeSliceModelSchema>\n\n// Shared (2021 to present)\nexport const SharedSliceType = \"SharedSlice\" as const\n\nconst IMAGE_PLACEHOLDER_URL =\n\t\"https://images.prismic.io/slice-machine/621a5ec4-0387-4bc5-9860-2dd46cbc07cd_default_ss.png?auto=compress,format\"\n\nexport const SharedSliceModelVariationSchema = z.object({\n\tid: z.string(),\n\tname: z.string(),\n\tdescription: z.string(),\n\timageUrl: z._default(z.string(), IMAGE_PLACEHOLDER_URL),\n\tdocURL: z.string(),\n\tversion: z.string(),\n\tdisplay: z.optional(z.string()),\n\tprimary: z.optional(\n\t\tz.record(\n\t\t\tz.string(),\n\t\t\tz.discriminatedUnion(\"type\", [NestableModelSchema, GroupModelSchema]) as z.ZodMiniType<\n\t\t\t\tNestableModel | GroupModel\n\t\t\t>,\n\t\t),\n\t),\n\titems: z.optional(z.record(z.string(), NestableModelSchema)),\n})\n\nexport type SharedSliceModelVariation = z.infer<typeof SharedSliceModelVariationSchema>\n\nexport const SharedSliceModelSchema = z\n\t.object({\n\t\tid: z.string(),\n\t\ttype: z.literal(SharedSliceType),\n\t\tname: z.string(),\n\t\tvariations: z.array(SharedSliceModelVariationSchema),\n\t\tdescription: z.optional(z.string()),\n\t\tlegacyPaths: z.optional(z.record(z.string(), z.string())),\n\t})\n\t.check(\n\t\tz.superRefine((model, ctx) => {\n\t\t\tif (model.variations.length === 0) {\n\t\t\t\tctx.addIssue({\n\t\t\t\t\tcode: \"custom\",\n\t\t\t\t\tmessage: `Shared slice \"${model.id}\" must have at least one variation`,\n\t\t\t\t\tpath: [\"variations\"],\n\t\t\t\t})\n\t\t\t}\n\n\t\t\t// A map of variation IDs to the index they belong to\n\t\t\t// to check for ID uniqueness across all variations.\n\t\t\tconst existingVariationIDs = new Map<string, number>()\n\t\t\tfor (let index = 0; index < model.variations.length; index++) {\n\t\t\t\tconst variation = model.variations[index]\n\n\t\t\t\tconst maybeIndex = existingVariationIDs.get(variation.id)\n\t\t\t\tif (Number.isInteger(maybeIndex)) {\n\t\t\t\t\tctx.addIssue({\n\t\t\t\t\t\tcode: \"custom\",\n\t\t\t\t\t\tmessage: `Variation ID \"${variation.id}\" already exists at index \"${maybeIndex}\"`,\n\t\t\t\t\t\tpath: [\"variations\", index],\n\t\t\t\t\t})\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\n\t\t\t\texistingVariationIDs.set(variation.id, index)\n\t\t\t}\n\t\t}),\n\t)\n\nexport type SharedSliceModel = z.infer<typeof SharedSliceModelSchema>\n\nexport const SharedSliceRefModelSchema = z.object({\n\ttype: z.literal(SharedSliceType),\n})\n\nexport type SharedSliceRefModel = z.infer<typeof SharedSliceRefModelSchema>\n\n// Used to represent a shared slice content which can only be\n// of a given shared slice variation type.\nexport const SharedSliceVariationContentModelSchema = z.object({\n\ttype: z.literal(SharedSliceType),\n\tsliceName: z.string(),\n\tvariationID: z.string(),\n\tfields: z.pick(SharedSliceModelVariationSchema, { primary: true, items: true }),\n})\n\nexport type SharedSliceVariationContentModel = z.infer<\n\ttypeof SharedSliceVariationContentModelSchema\n>\n\n// All\n\n// Used when slices reference SharedSlice by ref (not full definition)\nexport const DynamicSliceModelSchema: z.ZodMiniType<DynamicSliceModel> = z.discriminatedUnion(\n\t\"type\",\n\t[CompositeSliceModelSchema, LegacySliceModelSchema, SharedSliceRefModelSchema],\n)\n\nexport type DynamicSliceModel = CompositeSliceModel | LegacySliceModel | SharedSliceRefModel\n\n// Used when slices include full SharedSlice definition\nexport const StaticSliceModelSchema: z.ZodMiniType<StaticSliceModel> = z.discriminatedUnion(\n\t\"type\",\n\t[CompositeSliceModelSchema, LegacySliceModelSchema, SharedSliceModelSchema],\n)\n\nexport type StaticSliceModel = CompositeSliceModel | LegacySliceModel | SharedSliceModel\n\n// Used to represent a slice content model as shared slice variations\n// can only be of a given shared slice variation type.\nexport const SliceContentModelSchema: z.ZodMiniType<SliceContentModel> = z.discriminatedUnion(\n\t\"type\",\n\t[CompositeSliceModelSchema, LegacySliceModelSchema, SharedSliceVariationContentModelSchema],\n)\n\nexport type SliceContentModel =\n\t| CompositeSliceModel\n\t| LegacySliceModel\n\t| SharedSliceVariationContentModel\n\n// Model types\nexport const SliceModelTypeSchema = z.union([\n\tz.literal(CompositeSliceType),\n\tz.literal(SharedSliceType),\n])\n\nexport type SliceModelType = z.infer<typeof SliceModelTypeSchema>\n"],"mappings":";;;;;AASA,MAAa,yBAAyB,EAAE,mBAAmB,QAAQ,CAClE,qBACA,uBACA,CAAC;AAKF,MAAa,qBAAqB;AAElC,MAAM,6BAA6B,EAAE,OAAO,EAC3C,OAAO,EAAE,QAAQ,EAAE,QAAQ,CAAC,EAC5B,CAAC;AAEF,MAAa,4BAA4B,EAAE,OAAO;CACjD,MAAM,EAAE,QAAQ,mBAAmB;CACnC,UAAU,EAAE,QAAQ,EAAE,QAAQ,CAAC;CAC/B,aAAa,EAAE,SAAS,EAAE,QAAQ,CAAC;CACnC,MAAM,EAAE,SAAS,EAAE,QAAQ,CAAC;CAC5B,SAAS,EAAE,SAAS,EAAE,QAAQ,CAAC;CAC/B,cAAc,EAAE,SAAS,EAAE,OAAO,iBAAiB,oBAAoB,CAAC;CACxE,QAAQ,EAAE,SAAS,EAAE,OAAO,iBAAiB,oBAAoB,CAAC;CAClE,QAAQ,EAAE,SAAS,2BAA2B;CAC9C,CAAC;AAKF,MAAa,kBAAkB;AAK/B,MAAa,kCAAkC,EAAE,OAAO;CACvD,IAAI,EAAE,QAAQ;CACd,MAAM,EAA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A4B,EAAE,OAAO,EACjD,MAAM,EAAE,QAAQ,gBAAgB,EAChC,CAAC;AAMF,MAAa,yCAAyC,EAAE,OAAO;CAC9D,MAAM,EAAE,QAAQ,gBAAgB;CAChC,WAAW,EAAE,QAAQ;CACrB,aAAa,EAAE,QAAQ;CACvB,QAAQ,EAAE,KAAK,iCAAiC;EAAE,SAAS;EAAM,OAAO;EAAM,CAAC;CAC/E,CAAC;AASF,MAAa,0BAA4D,EAAE,mBAC1E,QACA;CAAC;CAA2B;CAAwB;CAA0B,CAC9E;AAKD,MAAa,yBAA0D,EAAE,mBACxE,QACA;CAAC;CAA2B;CAAwB;CAAuB,CAC3E;AAMD,MAAa,0BAA4D,EAAE,mBAC1E,QACA;CAAC;CAA2B;CAAwB;CAAuC,CAC3F;AAQD,MAAa,uBAAuB,EAAE,MAAM,CAC3C,EAAE,QAAQ,mBAAmB,EAC7B,EAAE,QAAQ,gBAAgB,CAC1B,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prismicio/types-internal",
3
- "version": "4.2.0",
3
+ "version": "4.3.0",
4
4
  "description": "TypeScript types and runtime parsers for Prismic data",
5
5
  "keywords": [
6
6
  "prismic",
@@ -114,3 +114,19 @@ export function filterMissingSharedSlices<
114
114
 
115
115
  return { ...customType, json }
116
116
  }
117
+
118
+ export function serializeID(input: string): string {
119
+ const normalized = input
120
+ .trim()
121
+ .normalize("NFD")
122
+ .replace(/\p{M}/gu, "")
123
+ .toLowerCase()
124
+ .replace(/[^a-z0-9]+/g, "_")
125
+ .replace(/^_+|_+$/g, "")
126
+
127
+ if (normalized.length === 0) {
128
+ throw new Error(`Cannot serialize "${input}": result is empty.`)
129
+ }
130
+
131
+ return normalized
132
+ }
@@ -106,3 +106,13 @@ export function toLegacy(document: DocumentContent): DocumentLegacy {
106
106
 
107
107
  return { ...content, ...types, ...keys }
108
108
  }
109
+
110
+ export function serializeUID(input: string): string {
111
+ const nowhitespace = input.replace(/ /g, "-")
112
+
113
+ const normalized = nowhitespace.normalize("NFD").replace(/\p{M}/gu, "")
114
+
115
+ const slug = normalized.replace(/[^\p{L}\d_.-]/gu, "")
116
+
117
+ return slug.toLowerCase()
118
+ }
@@ -0,0 +1,18 @@
1
+ export function serializeID(input: string): string {
2
+ const tokens = input
3
+ .trim()
4
+ .normalize("NFD")
5
+ .replace(/\p{M}/gu, "")
6
+ .split(/[^A-Za-z0-9]+/)
7
+ .filter(Boolean)
8
+
9
+ if (tokens.length === 0) {
10
+ throw new Error(`Cannot serialize "${input}": result is empty.`)
11
+ }
12
+
13
+ const [first, ...rest] = tokens
14
+ return (
15
+ first.toLowerCase() +
16
+ rest.map((token) => token.charAt(0).toUpperCase() + token.slice(1).toLowerCase()).join("")
17
+ )
18
+ }
@@ -0,0 +1,25 @@
1
+ const MIN_LENGTH = 4
2
+ const MAX_LENGTH = 63
3
+
4
+ export function serializeID(input: string): string {
5
+ const normalized = input
6
+ .trim()
7
+ .normalize("NFD")
8
+ .replace(/\p{M}/gu, "")
9
+ .toLowerCase()
10
+ .replace(/[^a-z0-9]+/g, "-")
11
+ .replace(/^-+|-+$/g, "")
12
+
13
+ const truncated =
14
+ normalized.length > MAX_LENGTH
15
+ ? normalized.slice(0, MAX_LENGTH).replace(/-+$/, "")
16
+ : normalized
17
+
18
+ if (truncated.length < MIN_LENGTH) {
19
+ throw new Error(
20
+ `Cannot serialize "${input}" to a repository ID: result must be between ${MIN_LENGTH} and ${MAX_LENGTH} characters.`,
21
+ )
22
+ }
23
+
24
+ return truncated
25
+ }
@@ -0,0 +1,18 @@
1
+ export function serializeID(input: string): string {
2
+ const tokens = input
3
+ .trim()
4
+ .normalize("NFD")
5
+ .replace(/\p{M}/gu, "")
6
+ .split(/[^A-Za-z0-9]+/)
7
+ .filter(Boolean)
8
+
9
+ if (tokens.length === 0) {
10
+ throw new Error(`Cannot serialize "${input}": result is empty.`)
11
+ }
12
+
13
+ return tokens
14
+ .map((token) => token.charAt(0).toUpperCase() + token.slice(1).toLowerCase())
15
+ .join("")
16
+ }
17
+
18
+ export const serializeVariationID = serializeID
package/src/index.ts CHANGED
@@ -106,7 +106,10 @@ export { LegacyContentCtx, getFieldCtx, defaultCtx } from "./content/codec/legac
106
106
  export * as contentPath from "./helpers/contentPath"
107
107
  export * as customTypeModel from "./helpers/customTypeModel"
108
108
  export * as documentContent from "./helpers/documentContent"
109
+ export * as fieldModel from "./helpers/fieldModel"
110
+ export * as repository from "./helpers/repository"
109
111
  export * as sliceContent from "./helpers/sliceContent"
112
+ export * as sliceModel from "./helpers/sliceModel"
110
113
  export * as withDefaultContent from "./helpers/withDefaultContent"
111
114
  export * as imageContent from "./helpers/imageContent"
112
115
  export {
@@ -15,15 +15,54 @@ export const CustomTypeFormatSchema = z.enum(["page", "custom"])
15
15
  export type CustomTypeFormat = z.infer<typeof CustomTypeFormatSchema>
16
16
 
17
17
  // Factory to create CustomType schema with configurable section type
18
- const createCustomTypeSchema = <T extends z.ZodMiniType>(sectionSchema: T) =>
19
- z.object({
20
- id: z.string(),
21
- label: z.nullish(z.string()),
22
- repeatable: z._default(z.boolean(), true),
23
- json: z.record(z.string(), sectionSchema),
24
- status: z._default(z.boolean(), true),
25
- format: z._default(CustomTypeFormatSchema, "custom"),
26
- })
18
+ const createCustomTypeSchema = <
19
+ T extends typeof StaticCustomTypeModelTabSchema | typeof DynamicCustomTypeModelTabSchema,
20
+ >(
21
+ sectionSchema: T,
22
+ ) =>
23
+ z
24
+ .object({
25
+ id: z.string(),
26
+ label: z.nullish(z.string()),
27
+ repeatable: z._default(z.boolean(), true),
28
+ json: z.record(z.string(), sectionSchema),
29
+ status: z._default(z.boolean(), true),
30
+ format: z._default(CustomTypeFormatSchema, "custom"),
31
+ })
32
+ .check(
33
+ z.superRefine((model, ctx) => {
34
+ const { json } = model
35
+
36
+ const tabEntries = Object.entries(json)
37
+
38
+ // A map of widget IDs to the tab they belong to
39
+ // to check for ID uniqueness across all tabs.
40
+ const existingWidgetKeys = new Map<string, string>()
41
+ for (const [tabID, tab] of tabEntries) {
42
+ for (const [widgetID, widget] of Object.entries(tab)) {
43
+ if (widget.type === "UID" && widgetID !== "uid") {
44
+ ctx.addIssue({
45
+ code: "custom",
46
+ message: `The UID widget ID must be set to "uid"`,
47
+ path: ["json", tabID, widgetID],
48
+ })
49
+ }
50
+
51
+ const maybeTabID = existingWidgetKeys.get(widgetID)
52
+ if (typeof maybeTabID === "string") {
53
+ ctx.addIssue({
54
+ code: "custom",
55
+ message: `${widgetID} already exists in the "${maybeTabID}" tab`,
56
+ path: ["json", tabID, widgetID],
57
+ })
58
+ continue
59
+ }
60
+
61
+ existingWidgetKeys.set(widgetID, tabID)
62
+ }
63
+ }
64
+ }),
65
+ )
27
66
 
28
67
  export const StaticCustomTypeModelSchema = createCustomTypeSchema(StaticCustomTypeModelTabSchema)
29
68
  export type StaticCustomTypeModel = z.infer<typeof StaticCustomTypeModelSchema>
@@ -18,7 +18,7 @@ export const SideConstraintSchema: z.ZodMiniType<number | null> = z.union([
18
18
  z.transform(() => null),
19
19
  ),
20
20
  z.null(),
21
- z.number().check(z.int()),
21
+ z.int(),
22
22
  z.pipe(
23
23
  z.string(),
24
24
  z.transform((s: string) => parseInt(s.replace("px", ""), 10)),
@@ -61,14 +61,45 @@ export const SharedSliceModelVariationSchema = z.object({
61
61
 
62
62
  export type SharedSliceModelVariation = z.infer<typeof SharedSliceModelVariationSchema>
63
63
 
64
- export const SharedSliceModelSchema = z.object({
65
- id: z.string(),
66
- type: z.literal(SharedSliceType),
67
- name: z.string(),
68
- variations: z.array(SharedSliceModelVariationSchema),
69
- description: z.optional(z.string()),
70
- legacyPaths: z.optional(z.record(z.string(), z.string())),
71
- })
64
+ export const SharedSliceModelSchema = z
65
+ .object({
66
+ id: z.string(),
67
+ type: z.literal(SharedSliceType),
68
+ name: z.string(),
69
+ variations: z.array(SharedSliceModelVariationSchema),
70
+ description: z.optional(z.string()),
71
+ legacyPaths: z.optional(z.record(z.string(), z.string())),
72
+ })
73
+ .check(
74
+ z.superRefine((model, ctx) => {
75
+ if (model.variations.length === 0) {
76
+ ctx.addIssue({
77
+ code: "custom",
78
+ message: `Shared slice "${model.id}" must have at least one variation`,
79
+ path: ["variations"],
80
+ })
81
+ }
82
+
83
+ // A map of variation IDs to the index they belong to
84
+ // to check for ID uniqueness across all variations.
85
+ const existingVariationIDs = new Map<string, number>()
86
+ for (let index = 0; index < model.variations.length; index++) {
87
+ const variation = model.variations[index]
88
+
89
+ const maybeIndex = existingVariationIDs.get(variation.id)
90
+ if (Number.isInteger(maybeIndex)) {
91
+ ctx.addIssue({
92
+ code: "custom",
93
+ message: `Variation ID "${variation.id}" already exists at index "${maybeIndex}"`,
94
+ path: ["variations", index],
95
+ })
96
+ continue
97
+ }
98
+
99
+ existingVariationIDs.set(variation.id, index)
100
+ }
101
+ }),
102
+ )
72
103
 
73
104
  export type SharedSliceModel = z.infer<typeof SharedSliceModelSchema>
74
105