@prismicio/types-internal 4.2.0-canary.a2c9e19 → 4.2.0-pr.13.ce54183

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.
@@ -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,cA6D1C,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,41 @@ 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 existingKeys = /* @__PURE__ */ new Map();
18
+ const tabEntries = Object.entries(json);
19
+ if (tabEntries.length === 0) ctx.addIssue({
20
+ code: "custom",
21
+ message: `Custom type "${model.id}" must have at least one tab`,
22
+ path: ["json"]
23
+ });
24
+ for (const [tabID, tab] of tabEntries) for (const [widgetID, widget] of Object.entries(tab)) {
25
+ const maybeTabID = existingKeys.get(widgetID);
26
+ if (widget.type === "UID" && widgetID !== "uid") ctx.addIssue({
27
+ code: "custom",
28
+ message: `The UID widget ID must be set to "uid"`,
29
+ path: [
30
+ "json",
31
+ tabID,
32
+ widgetID
33
+ ]
34
+ });
35
+ if (maybeTabID) {
36
+ ctx.addIssue({
37
+ code: "custom",
38
+ message: `${widgetID} already exists in the ${maybeTabID} tab`,
39
+ path: [
40
+ "json",
41
+ tabID,
42
+ widgetID
43
+ ]
44
+ });
45
+ continue;
46
+ }
47
+ existingKeys.set(widgetID, tabID);
48
+ }
49
+ }));
16
50
  const StaticCustomTypeModelSchema = createCustomTypeSchema(StaticCustomTypeModelTabSchema);
17
51
  const DynamicCustomTypeModelSchema = createCustomTypeSchema(DynamicCustomTypeModelTabSchema);
18
52
  //#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 existingKeys = new Map<string, string>()\n\t\t\t\tconst tabEntries = Object.entries(json)\n\t\t\t\tif (tabEntries.length === 0) {\n\t\t\t\t\tctx.addIssue({\n\t\t\t\t\t\tcode: \"custom\",\n\t\t\t\t\t\tmessage: `Custom type \"${model.id}\" must have at least one tab`,\n\t\t\t\t\t\tpath: [\"json\"],\n\t\t\t\t\t})\n\t\t\t\t}\n\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\tconst maybeTabID = existingKeys.get(widgetID)\n\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\tif (maybeTabID) {\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\t\t\t\t\t\texistingKeys.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,+BAAe,IAAI,KAAqB;CAC9C,MAAM,aAAa,OAAO,QAAQ,KAAK;AACvC,KAAI,WAAW,WAAW,EACzB,KAAI,SAAS;EACZ,MAAM;EACN,SAAS,gBAAgB,MAAM,GAAG;EAClC,MAAM,CAAC,OAAO;EACd,CAAC;AAGH,MAAK,MAAM,CAAC,OAAO,QAAQ,WAC1B,MAAK,MAAM,CAAC,UAAU,WAAW,OAAO,QAAQ,IAAI,EAAE;EACrD,MAAM,aAAa,aAAa,IAAI,SAAS;AAE7C,MAAI,OAAO,SAAS,SAAS,aAAa,MACzC,KAAI,SAAS;GACZ,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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAOvC,gCAAA,GAAmC,CAAA,CAAE,KAAA,QACzC,sCAAA;AAAA,KAWI,iBAAA,GAAoB,mBAAA,GAAsB,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,13 @@ 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 (Object.keys(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
+ }));
39
45
  const SharedSliceRefModelSchema = z.object({ type: z.literal(SharedSliceType) });
40
46
  const SharedSliceVariationContentModelSchema = z.object({
41
47
  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])\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,EAAE,QAAQ;CAChB,aAAa,EAAE,QAAQ;CACvB,UAAU,EAAE,SAAS,EAAE,QAAQ,EAN/B,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/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\tconst variationIDs = Object.keys(model.variations)\n\t\t\tif (variationIDs.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\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,EAAE,QAAQ;CAChB,aAAa,EAAE,QA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AAwB;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"}
@@ -19,13 +19,13 @@ declare const FieldModelTypeSchema: z.ZodMiniEnum<{
19
19
  Boolean: "Boolean";
20
20
  Embed: "Embed";
21
21
  GeoPoint: "GeoPoint";
22
+ Image: "Image";
23
+ IntegrationFields: "IntegrationFields";
22
24
  StructuredText: "StructuredText";
23
25
  Separator: "Separator";
24
26
  Table: "Table";
25
- Image: "Image";
26
- IntegrationFields: "IntegrationFields";
27
- UID: "UID";
28
27
  Group: "Group";
28
+ UID: "UID";
29
29
  Slices: "Slices";
30
30
  Choice: "Choice";
31
31
  }>;
@@ -42,13 +42,13 @@ declare const FieldOrSliceTypeSchema: z.ZodMiniUnion<readonly [z.ZodMiniEnum<{
42
42
  Boolean: "Boolean";
43
43
  Embed: "Embed";
44
44
  GeoPoint: "GeoPoint";
45
+ Image: "Image";
46
+ IntegrationFields: "IntegrationFields";
45
47
  StructuredText: "StructuredText";
46
48
  Separator: "Separator";
47
49
  Table: "Table";
48
- Image: "Image";
49
- IntegrationFields: "IntegrationFields";
50
- UID: "UID";
51
50
  Group: "Group";
51
+ UID: "UID";
52
52
  Slices: "Slices";
53
53
  Choice: "Choice";
54
54
  }>, z.ZodMiniUnion<readonly [z.ZodMiniLiteral<"Slice">, z.ZodMiniLiteral<"SharedSlice">]>, z.ZodMiniLiteral<"Repeatable.Link">]>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prismicio/types-internal",
3
- "version": "4.2.0-canary.a2c9e19",
3
+ "version": "4.2.0-pr.13.ce54183",
4
4
  "description": "TypeScript types and runtime parsers for Prismic data",
5
5
  "keywords": [
6
6
  "prismic",
@@ -15,15 +15,59 @@ 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 existingKeys = new Map<string, string>()
37
+ const tabEntries = Object.entries(json)
38
+ if (tabEntries.length === 0) {
39
+ ctx.addIssue({
40
+ code: "custom",
41
+ message: `Custom type "${model.id}" must have at least one tab`,
42
+ path: ["json"],
43
+ })
44
+ }
45
+
46
+ for (const [tabID, tab] of tabEntries) {
47
+ for (const [widgetID, widget] of Object.entries(tab)) {
48
+ const maybeTabID = existingKeys.get(widgetID)
49
+
50
+ if (widget.type === "UID" && widgetID !== "uid") {
51
+ ctx.addIssue({
52
+ code: "custom",
53
+ message: `The UID widget ID must be set to "uid"`,
54
+ path: ["json", tabID, widgetID],
55
+ })
56
+ }
57
+
58
+ if (maybeTabID) {
59
+ ctx.addIssue({
60
+ code: "custom",
61
+ message: `${widgetID} already exists in the ${maybeTabID} tab`,
62
+ path: ["json", tabID, widgetID],
63
+ })
64
+ continue
65
+ }
66
+ existingKeys.set(widgetID, tabID)
67
+ }
68
+ }
69
+ }),
70
+ )
27
71
 
28
72
  export const StaticCustomTypeModelSchema = createCustomTypeSchema(StaticCustomTypeModelTabSchema)
29
73
  export type StaticCustomTypeModel = z.infer<typeof StaticCustomTypeModelSchema>
@@ -61,14 +61,27 @@ 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
+ const variationIDs = Object.keys(model.variations)
76
+ if (variationIDs.length === 0) {
77
+ ctx.addIssue({
78
+ code: "custom",
79
+ message: `Shared slice "${model.id}" must have at least one variation`,
80
+ path: ["variations"],
81
+ })
82
+ }
83
+ }),
84
+ )
72
85
 
73
86
  export type SharedSliceModel = z.infer<typeof SharedSliceModelSchema>
74
87