@prismicio/types-internal 4.2.0-pr.13.ce54183 → 4.2.0-pr.13.d30a344
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/model/customType.d.ts.map +1 -1
- package/dist/model/customType.js +5 -5
- package/dist/model/customType.js.map +1 -1
- package/dist/model/slice.d.ts.map +1 -1
- package/dist/model/slice.js +15 -1
- package/dist/model/slice.js.map +1 -1
- package/dist/model/widget.d.ts +6 -6
- package/package.json +1 -1
- package/src/model/customType.ts +8 -6
- package/src/model/slice.ts +20 -2
|
@@ -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,
|
|
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,cA+D1C,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"}
|
package/dist/model/customType.js
CHANGED
|
@@ -14,15 +14,14 @@ const createCustomTypeSchema = (sectionSchema) => z.object({
|
|
|
14
14
|
format: z._default(CustomTypeFormatSchema, "custom")
|
|
15
15
|
}).check(z.superRefine((model, ctx) => {
|
|
16
16
|
const { json } = model;
|
|
17
|
-
const existingKeys = /* @__PURE__ */ new Map();
|
|
18
17
|
const tabEntries = Object.entries(json);
|
|
19
18
|
if (tabEntries.length === 0) ctx.addIssue({
|
|
20
19
|
code: "custom",
|
|
21
20
|
message: `Custom type "${model.id}" must have at least one tab`,
|
|
22
21
|
path: ["json"]
|
|
23
22
|
});
|
|
23
|
+
const existingWidgetKeys = /* @__PURE__ */ new Map();
|
|
24
24
|
for (const [tabID, tab] of tabEntries) for (const [widgetID, widget] of Object.entries(tab)) {
|
|
25
|
-
const maybeTabID = existingKeys.get(widgetID);
|
|
26
25
|
if (widget.type === "UID" && widgetID !== "uid") ctx.addIssue({
|
|
27
26
|
code: "custom",
|
|
28
27
|
message: `The UID widget ID must be set to "uid"`,
|
|
@@ -32,10 +31,11 @@ const createCustomTypeSchema = (sectionSchema) => z.object({
|
|
|
32
31
|
widgetID
|
|
33
32
|
]
|
|
34
33
|
});
|
|
35
|
-
|
|
34
|
+
const maybeTabID = existingWidgetKeys.get(widgetID);
|
|
35
|
+
if (typeof maybeTabID === "string") {
|
|
36
36
|
ctx.addIssue({
|
|
37
37
|
code: "custom",
|
|
38
|
-
message: `${widgetID} already exists in the ${maybeTabID} tab`,
|
|
38
|
+
message: `${widgetID} already exists in the "${maybeTabID}" tab`,
|
|
39
39
|
path: [
|
|
40
40
|
"json",
|
|
41
41
|
tabID,
|
|
@@ -44,7 +44,7 @@ const createCustomTypeSchema = (sectionSchema) => z.object({
|
|
|
44
44
|
});
|
|
45
45
|
continue;
|
|
46
46
|
}
|
|
47
|
-
|
|
47
|
+
existingWidgetKeys.set(widgetID, tabID);
|
|
48
48
|
}
|
|
49
49
|
}));
|
|
50
50
|
const StaticCustomTypeModelSchema = createCustomTypeSchema(StaticCustomTypeModelTabSchema);
|
|
@@ -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 = <\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
|
|
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\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\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 = D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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"}
|
package/dist/model/slice.js
CHANGED
|
@@ -36,11 +36,25 @@ const SharedSliceModelSchema = z.object({
|
|
|
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 (
|
|
39
|
+
if (model.variations.length === 0) ctx.addIssue({
|
|
40
40
|
code: "custom",
|
|
41
41
|
message: `Shared slice "${model.id}" must have at least one variation`,
|
|
42
42
|
path: ["variations"]
|
|
43
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
|
+
}
|
|
44
58
|
}));
|
|
45
59
|
const SharedSliceRefModelSchema = z.object({ type: z.literal(SharedSliceType) });
|
|
46
60
|
const SharedSliceVariationContentModelSchema = z.object({
|
package/dist/model/slice.js.map
CHANGED
|
@@ -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\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\
|
|
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,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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"}
|
package/dist/model/widget.d.ts
CHANGED
|
@@ -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";
|
|
24
22
|
StructuredText: "StructuredText";
|
|
25
23
|
Separator: "Separator";
|
|
26
24
|
Table: "Table";
|
|
27
|
-
|
|
25
|
+
Image: "Image";
|
|
26
|
+
IntegrationFields: "IntegrationFields";
|
|
28
27
|
UID: "UID";
|
|
28
|
+
Group: "Group";
|
|
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";
|
|
47
45
|
StructuredText: "StructuredText";
|
|
48
46
|
Separator: "Separator";
|
|
49
47
|
Table: "Table";
|
|
50
|
-
|
|
48
|
+
Image: "Image";
|
|
49
|
+
IntegrationFields: "IntegrationFields";
|
|
51
50
|
UID: "UID";
|
|
51
|
+
Group: "Group";
|
|
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
package/src/model/customType.ts
CHANGED
|
@@ -33,7 +33,6 @@ const createCustomTypeSchema = <
|
|
|
33
33
|
z.superRefine((model, ctx) => {
|
|
34
34
|
const { json } = model
|
|
35
35
|
|
|
36
|
-
const existingKeys = new Map<string, string>()
|
|
37
36
|
const tabEntries = Object.entries(json)
|
|
38
37
|
if (tabEntries.length === 0) {
|
|
39
38
|
ctx.addIssue({
|
|
@@ -43,10 +42,11 @@ const createCustomTypeSchema = <
|
|
|
43
42
|
})
|
|
44
43
|
}
|
|
45
44
|
|
|
45
|
+
// A map of widget IDs to the tab they belong to
|
|
46
|
+
// to check for ID uniqueness across all tabs.
|
|
47
|
+
const existingWidgetKeys = new Map<string, string>()
|
|
46
48
|
for (const [tabID, tab] of tabEntries) {
|
|
47
49
|
for (const [widgetID, widget] of Object.entries(tab)) {
|
|
48
|
-
const maybeTabID = existingKeys.get(widgetID)
|
|
49
|
-
|
|
50
50
|
if (widget.type === "UID" && widgetID !== "uid") {
|
|
51
51
|
ctx.addIssue({
|
|
52
52
|
code: "custom",
|
|
@@ -55,15 +55,17 @@ const createCustomTypeSchema = <
|
|
|
55
55
|
})
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
|
|
58
|
+
const maybeTabID = existingWidgetKeys.get(widgetID)
|
|
59
|
+
if (typeof maybeTabID === "string") {
|
|
59
60
|
ctx.addIssue({
|
|
60
61
|
code: "custom",
|
|
61
|
-
message: `${widgetID} already exists in the ${maybeTabID} tab`,
|
|
62
|
+
message: `${widgetID} already exists in the "${maybeTabID}" tab`,
|
|
62
63
|
path: ["json", tabID, widgetID],
|
|
63
64
|
})
|
|
64
65
|
continue
|
|
65
66
|
}
|
|
66
|
-
|
|
67
|
+
|
|
68
|
+
existingWidgetKeys.set(widgetID, tabID)
|
|
67
69
|
}
|
|
68
70
|
}
|
|
69
71
|
}),
|
package/src/model/slice.ts
CHANGED
|
@@ -72,14 +72,32 @@ export const SharedSliceModelSchema = z
|
|
|
72
72
|
})
|
|
73
73
|
.check(
|
|
74
74
|
z.superRefine((model, ctx) => {
|
|
75
|
-
|
|
76
|
-
if (variationIDs.length === 0) {
|
|
75
|
+
if (model.variations.length === 0) {
|
|
77
76
|
ctx.addIssue({
|
|
78
77
|
code: "custom",
|
|
79
78
|
message: `Shared slice "${model.id}" must have at least one variation`,
|
|
80
79
|
path: ["variations"],
|
|
81
80
|
})
|
|
82
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
|
+
}
|
|
83
101
|
}),
|
|
84
102
|
)
|
|
85
103
|
|