@prismicio/types-internal 4.0.0-pr.6.0ddf815 → 4.0.0-pr.6.7b0b0be
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.
|
@@ -33,7 +33,7 @@ function fromLegacy(legacy) {
|
|
|
33
33
|
const parsed = z.uuidv4().safeParse(value);
|
|
34
34
|
if (parsed.success) keys.set(key.substring(0, key.length - 4), parsed.data);
|
|
35
35
|
} else if (!key.endsWith("_POSITION")) widgets[key] = value;
|
|
36
|
-
const result = DocumentLegacyCodec(defaultCtx("", types, keys)).toContent(
|
|
36
|
+
const result = DocumentLegacyCodec(defaultCtx("", types, keys)).toContent(widgets);
|
|
37
37
|
if (!result.success) return;
|
|
38
38
|
return result.data;
|
|
39
39
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"documentContent.js","names":["contentPath.serialize"],"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 type { WidgetContent } from \"../content/widget\"\nimport type { FieldOrSliceType } from \"../model/widget\"\nimport { FieldOrSliceTypeSchema } from \"../model/widget\"\nimport * as contentPath from \"./contentPath\"\nimport { traverseDocumentContent } from \"./traverseContent\"\n\nexport function collectWidgets<TWidgetContent extends WidgetContent>(\n\tdocument: DocumentContent,\n\ttest: (args: {\n\t\tpath: contentPath.Path\n\t\tkey: string\n\t\tapiID: string\n\t\tcontent: WidgetContent\n\t}) => args is {\n\t\tpath: contentPath.Path\n\t\tkey: string\n\t\tapiID: string\n\t\tcontent: TWidgetContent\n\t},\n): Record<string, TWidgetContent> {\n\tconst collected: Record<string, TWidgetContent> = {}\n\n\ttraverseDocumentContent(document, {\n\t\ttransformWidget: (args) => {\n\t\t\tif (test(args)) {\n\t\t\t\tcollected[contentPath.serialize(args.path)] = args.content\n\t\t\t}\n\n\t\t\treturn args.content\n\t\t},\n\t})\n\n\treturn collected\n}\n\nexport function fromLegacy(legacy: DocumentLegacy): 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(
|
|
1
|
+
{"version":3,"file":"documentContent.js","names":["contentPath.serialize"],"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 type { WidgetContent } from \"../content/widget\"\nimport type { FieldOrSliceType } from \"../model/widget\"\nimport { FieldOrSliceTypeSchema } from \"../model/widget\"\nimport * as contentPath from \"./contentPath\"\nimport { traverseDocumentContent } from \"./traverseContent\"\n\nexport function collectWidgets<TWidgetContent extends WidgetContent>(\n\tdocument: DocumentContent,\n\ttest: (args: {\n\t\tpath: contentPath.Path\n\t\tkey: string\n\t\tapiID: string\n\t\tcontent: WidgetContent\n\t}) => args is {\n\t\tpath: contentPath.Path\n\t\tkey: string\n\t\tapiID: string\n\t\tcontent: TWidgetContent\n\t},\n): Record<string, TWidgetContent> {\n\tconst collected: Record<string, TWidgetContent> = {}\n\n\ttraverseDocumentContent(document, {\n\t\ttransformWidget: (args) => {\n\t\t\tif (test(args)) {\n\t\t\t\tcollected[contentPath.serialize(args.path)] = args.content\n\t\t\t}\n\n\t\t\treturn args.content\n\t\t},\n\t})\n\n\treturn collected\n}\n\nexport function fromLegacy(legacy: DocumentLegacy): 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\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"],"mappings":";;;;;;;;;;;;;;AAaA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
66
|
}
|
|
67
67
|
|
|
68
|
-
const result = DocumentLegacyCodec(defaultCtx("", types, keys)).toContent(
|
|
68
|
+
const result = DocumentLegacyCodec(defaultCtx("", types, keys)).toContent(widgets)
|
|
69
69
|
if (!result.success) {
|
|
70
70
|
return
|
|
71
71
|
}
|