prismic-ts-codegen 0.1.10 → 0.1.12

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 (198) hide show
  1. package/dist/constants.cjs +19 -21
  2. package/dist/constants.cjs.map +1 -1
  3. package/dist/constants.d.ts +2 -3
  4. package/dist/constants.js +19 -21
  5. package/dist/constants.js.map +1 -1
  6. package/dist/generateTypes.cjs +71 -90
  7. package/dist/generateTypes.cjs.map +1 -1
  8. package/dist/generateTypes.d.ts +2 -1
  9. package/dist/generateTypes.js +71 -90
  10. package/dist/generateTypes.js.map +1 -1
  11. package/dist/lib/addBlankLine.cjs +12 -0
  12. package/dist/lib/addBlankLine.cjs.map +1 -0
  13. package/dist/lib/addBlankLine.d.ts +5 -0
  14. package/dist/lib/addBlankLine.js +12 -0
  15. package/dist/lib/addBlankLine.js.map +1 -0
  16. package/dist/lib/addLine.cjs +8 -0
  17. package/dist/lib/addLine.cjs.map +1 -0
  18. package/dist/lib/addLine.d.ts +1 -0
  19. package/dist/lib/addLine.js +8 -0
  20. package/dist/lib/addLine.js.map +1 -0
  21. package/dist/lib/addSection.cjs +8 -0
  22. package/dist/lib/addSection.cjs.map +1 -0
  23. package/dist/lib/addSection.d.ts +1 -0
  24. package/dist/lib/addSection.js +8 -0
  25. package/dist/lib/addSection.js.map +1 -0
  26. package/dist/lib/addTrailingNewLine.cjs +11 -0
  27. package/dist/lib/addTrailingNewLine.cjs.map +1 -0
  28. package/dist/lib/addTrailingNewLine.d.ts +5 -0
  29. package/dist/lib/addTrailingNewLine.js +11 -0
  30. package/dist/lib/addTrailingNewLine.js.map +1 -0
  31. package/dist/lib/buildCustomTypeDataType.cjs +51 -0
  32. package/dist/lib/buildCustomTypeDataType.cjs.map +1 -0
  33. package/dist/lib/buildCustomTypeDataType.d.ts +13 -0
  34. package/dist/lib/buildCustomTypeDataType.js +51 -0
  35. package/dist/lib/buildCustomTypeDataType.js.map +1 -0
  36. package/dist/lib/buildCustomTypeType.cjs +60 -0
  37. package/dist/lib/buildCustomTypeType.cjs.map +1 -0
  38. package/dist/lib/buildCustomTypeType.d.ts +17 -0
  39. package/dist/lib/buildCustomTypeType.js +60 -0
  40. package/dist/lib/buildCustomTypeType.js.map +1 -0
  41. package/dist/lib/buildFieldDocs.cjs +67 -35
  42. package/dist/lib/buildFieldDocs.cjs.map +1 -1
  43. package/dist/lib/buildFieldDocs.d.ts +7 -11
  44. package/dist/lib/buildFieldDocs.js +67 -35
  45. package/dist/lib/buildFieldDocs.js.map +1 -1
  46. package/dist/lib/buildFieldProperties.cjs +300 -0
  47. package/dist/lib/buildFieldProperties.cjs.map +1 -0
  48. package/dist/lib/buildFieldProperties.d.ts +14 -0
  49. package/dist/lib/buildFieldProperties.js +300 -0
  50. package/dist/lib/buildFieldProperties.js.map +1 -0
  51. package/dist/lib/buildSharedSliceType.cjs +140 -0
  52. package/dist/lib/buildSharedSliceType.cjs.map +1 -0
  53. package/dist/lib/buildSharedSliceType.d.ts +16 -0
  54. package/dist/lib/buildSharedSliceType.js +140 -0
  55. package/dist/lib/buildSharedSliceType.js.map +1 -0
  56. package/dist/lib/buildTypeName.cjs +4 -2
  57. package/dist/lib/buildTypeName.cjs.map +1 -1
  58. package/dist/lib/buildTypeName.js +4 -2
  59. package/dist/lib/buildTypeName.js.map +1 -1
  60. package/dist/lib/buildUnion.cjs +7 -0
  61. package/dist/lib/buildUnion.cjs.map +1 -0
  62. package/dist/lib/buildUnion.d.ts +1 -0
  63. package/dist/lib/buildUnion.js +7 -0
  64. package/dist/lib/buildUnion.js.map +1 -0
  65. package/dist/lib/checkHasUIDFIeld.cjs +7 -0
  66. package/dist/lib/checkHasUIDFIeld.cjs.map +1 -0
  67. package/dist/lib/checkHasUIDFIeld.d.ts +2 -0
  68. package/dist/lib/checkHasUIDFIeld.js +7 -0
  69. package/dist/lib/checkHasUIDFIeld.js.map +1 -0
  70. package/dist/lib/getAPIIDPath.cjs +18 -14
  71. package/dist/lib/getAPIIDPath.cjs.map +1 -1
  72. package/dist/lib/getAPIIDPath.d.ts +4 -8
  73. package/dist/lib/getAPIIDPath.js +18 -14
  74. package/dist/lib/getAPIIDPath.js.map +1 -1
  75. package/dist/lib/getCacheKey.cjs +25 -0
  76. package/dist/lib/getCacheKey.cjs.map +1 -0
  77. package/dist/lib/getCacheKey.d.ts +9 -0
  78. package/dist/lib/getCacheKey.js +8 -0
  79. package/dist/lib/getCacheKey.js.map +1 -0
  80. package/dist/lib/getHumanReadableModelName.cjs +13 -17
  81. package/dist/lib/getHumanReadableModelName.cjs.map +1 -1
  82. package/dist/lib/getHumanReadableModelName.d.ts +3 -3
  83. package/dist/lib/getHumanReadableModelName.js +13 -17
  84. package/dist/lib/getHumanReadableModelName.js.map +1 -1
  85. package/dist/lib/{getHumanReadableFieldPath.cjs → getHumanReadablePath.cjs} +8 -8
  86. package/dist/lib/getHumanReadablePath.cjs.map +1 -0
  87. package/dist/lib/getHumanReadablePath.d.ts +6 -0
  88. package/dist/lib/{getHumanReadableFieldPath.js → getHumanReadablePath.js} +8 -8
  89. package/dist/lib/getHumanReadablePath.js.map +1 -0
  90. package/dist/types.d.ts +9 -1
  91. package/package.json +19 -18
  92. package/src/constants.ts +19 -22
  93. package/src/generateTypes.ts +109 -108
  94. package/src/lib/addBlankLine.ts +13 -0
  95. package/src/lib/addLine.ts +5 -0
  96. package/src/lib/addSection.ts +5 -0
  97. package/src/lib/addTrailingNewLine.ts +14 -0
  98. package/src/lib/buildCustomTypeDataType.ts +74 -0
  99. package/src/lib/buildCustomTypeType.ts +101 -0
  100. package/src/lib/buildFieldDocs.ts +128 -68
  101. package/src/lib/buildFieldProperties.ts +513 -0
  102. package/src/lib/buildSharedSliceType.ts +213 -0
  103. package/src/lib/buildTypeName.ts +4 -2
  104. package/src/lib/buildUnion.ts +3 -0
  105. package/src/lib/checkHasUIDFIeld.ts +5 -0
  106. package/src/lib/getAPIIDPath.ts +40 -41
  107. package/src/lib/getCacheKey.ts +13 -0
  108. package/src/lib/getHumanReadableModelName.ts +23 -20
  109. package/src/lib/getHumanReadablePath.ts +24 -0
  110. package/src/types.ts +11 -1
  111. package/dist/lib/addInterfacePropertiesForFields.cjs +0 -489
  112. package/dist/lib/addInterfacePropertiesForFields.cjs.map +0 -1
  113. package/dist/lib/addInterfacePropertiesForFields.d.ts +0 -21
  114. package/dist/lib/addInterfacePropertiesForFields.js +0 -489
  115. package/dist/lib/addInterfacePropertiesForFields.js.map +0 -1
  116. package/dist/lib/addTypeAliasForCustomType.cjs +0 -81
  117. package/dist/lib/addTypeAliasForCustomType.cjs.map +0 -1
  118. package/dist/lib/addTypeAliasForCustomType.d.ts +0 -11
  119. package/dist/lib/addTypeAliasForCustomType.js +0 -81
  120. package/dist/lib/addTypeAliasForCustomType.js.map +0 -1
  121. package/dist/lib/addTypeAliasForSharedSlice.cjs +0 -149
  122. package/dist/lib/addTypeAliasForSharedSlice.cjs.map +0 -1
  123. package/dist/lib/addTypeAliasForSharedSlice.d.ts +0 -10
  124. package/dist/lib/addTypeAliasForSharedSlice.js +0 -149
  125. package/dist/lib/addTypeAliasForSharedSlice.js.map +0 -1
  126. package/dist/lib/buildSharedSliceInterfaceNamePart.cjs +0 -8
  127. package/dist/lib/buildSharedSliceInterfaceNamePart.cjs.map +0 -1
  128. package/dist/lib/buildSharedSliceInterfaceNamePart.d.ts +0 -5
  129. package/dist/lib/buildSharedSliceInterfaceNamePart.js +0 -8
  130. package/dist/lib/buildSharedSliceInterfaceNamePart.js.map +0 -1
  131. package/dist/lib/getFieldDocumentationURL.cjs +0 -8
  132. package/dist/lib/getFieldDocumentationURL.cjs.map +0 -1
  133. package/dist/lib/getFieldDocumentationURL.d.ts +0 -6
  134. package/dist/lib/getFieldDocumentationURL.js +0 -8
  135. package/dist/lib/getFieldDocumentationURL.js.map +0 -1
  136. package/dist/lib/getHumanReadableFieldPath.cjs.map +0 -1
  137. package/dist/lib/getHumanReadableFieldPath.d.ts +0 -10
  138. package/dist/lib/getHumanReadableFieldPath.js.map +0 -1
  139. package/dist/lib/getHumanReadableFieldType.cjs +0 -36
  140. package/dist/lib/getHumanReadableFieldType.cjs.map +0 -1
  141. package/dist/lib/getHumanReadableFieldType.d.ts +0 -6
  142. package/dist/lib/getHumanReadableFieldType.js +0 -36
  143. package/dist/lib/getHumanReadableFieldType.js.map +0 -1
  144. package/dist/lib/getSourceFileText.cjs +0 -9
  145. package/dist/lib/getSourceFileText.cjs.map +0 -1
  146. package/dist/lib/getSourceFileText.d.ts +0 -2
  147. package/dist/lib/getSourceFileText.js +0 -9
  148. package/dist/lib/getSourceFileText.js.map +0 -1
  149. package/dist/lib/hasOwnProperty.cjs +0 -7
  150. package/dist/lib/hasOwnProperty.cjs.map +0 -1
  151. package/dist/lib/hasOwnProperty.d.ts +0 -10
  152. package/dist/lib/hasOwnProperty.js +0 -7
  153. package/dist/lib/hasOwnProperty.js.map +0 -1
  154. package/dist/lib/isCustomTypeModel.cjs +0 -7
  155. package/dist/lib/isCustomTypeModel.cjs.map +0 -1
  156. package/dist/lib/isCustomTypeModel.d.ts +0 -2
  157. package/dist/lib/isCustomTypeModel.js +0 -7
  158. package/dist/lib/isCustomTypeModel.js.map +0 -1
  159. package/dist/lib/isCustomTypeModelField.cjs +0 -7
  160. package/dist/lib/isCustomTypeModelField.cjs.map +0 -1
  161. package/dist/lib/isCustomTypeModelField.d.ts +0 -2
  162. package/dist/lib/isCustomTypeModelField.js +0 -7
  163. package/dist/lib/isCustomTypeModelField.js.map +0 -1
  164. package/dist/lib/isCustomTypeModelSlice.cjs +0 -8
  165. package/dist/lib/isCustomTypeModelSlice.cjs.map +0 -1
  166. package/dist/lib/isCustomTypeModelSlice.d.ts +0 -2
  167. package/dist/lib/isCustomTypeModelSlice.js +0 -8
  168. package/dist/lib/isCustomTypeModelSlice.js.map +0 -1
  169. package/dist/lib/isSharedSliceModel.cjs +0 -8
  170. package/dist/lib/isSharedSliceModel.cjs.map +0 -1
  171. package/dist/lib/isSharedSliceModel.d.ts +0 -2
  172. package/dist/lib/isSharedSliceModel.js +0 -8
  173. package/dist/lib/isSharedSliceModel.js.map +0 -1
  174. package/dist/lib/pascalCase.cjs +0 -8
  175. package/dist/lib/pascalCase.cjs.map +0 -1
  176. package/dist/lib/pascalCase.d.ts +0 -1
  177. package/dist/lib/pascalCase.js +0 -8
  178. package/dist/lib/pascalCase.js.map +0 -1
  179. package/dist/lib/writeFieldDocsDescription.cjs +0 -29
  180. package/dist/lib/writeFieldDocsDescription.cjs.map +0 -1
  181. package/dist/lib/writeFieldDocsDescription.d.ts +0 -13
  182. package/dist/lib/writeFieldDocsDescription.js +0 -29
  183. package/dist/lib/writeFieldDocsDescription.js.map +0 -1
  184. package/src/lib/addInterfacePropertiesForFields.ts +0 -665
  185. package/src/lib/addTypeAliasForCustomType.ts +0 -120
  186. package/src/lib/addTypeAliasForSharedSlice.ts +0 -201
  187. package/src/lib/buildSharedSliceInterfaceNamePart.ts +0 -11
  188. package/src/lib/getFieldDocumentationURL.ts +0 -15
  189. package/src/lib/getHumanReadableFieldPath.ts +0 -36
  190. package/src/lib/getHumanReadableFieldType.ts +0 -55
  191. package/src/lib/getSourceFileText.ts +0 -14
  192. package/src/lib/hasOwnProperty.ts +0 -15
  193. package/src/lib/isCustomTypeModel.ts +0 -5
  194. package/src/lib/isCustomTypeModelField.ts +0 -7
  195. package/src/lib/isCustomTypeModelSlice.ts +0 -14
  196. package/src/lib/isSharedSliceModel.ts +0 -14
  197. package/src/lib/pascalCase.ts +0 -9
  198. package/src/lib/writeFieldDocsDescription.ts +0 -51
@@ -1 +1 @@
1
- {"version":3,"file":"generateTypes.js","sources":["../../src/generateTypes.ts"],"sourcesContent":["import type { CustomTypeModel, SharedSliceModel } from \"@prismicio/client\";\nimport { ModuleDeclarationKind, Project } from \"ts-morph\";\n\nimport { addTypeAliasForCustomType } from \"./lib/addTypeAliasForCustomType\";\nimport { addTypeAliasForSharedSlice } from \"./lib/addTypeAliasForSharedSlice\";\nimport { buildTypeName } from \"./lib/buildTypeName\";\nimport { getSourceFileText } from \"./lib/getSourceFileText\";\n\nimport { FieldConfigs } from \"./types\";\n\nimport { BLANK_LINE_IDENTIFIER } from \"./constants\";\n\nexport type TypesProvider = \"@prismicio/client\" | \"@prismicio/types\";\n\nexport type GenerateTypesConfig = {\n\tcustomTypeModels?: CustomTypeModel[];\n\tsharedSliceModels?: SharedSliceModel[];\n\tlocaleIDs?: string[];\n\tfieldConfigs?: FieldConfigs;\n\ttypesProvider?: TypesProvider;\n\tclientIntegration?: {\n\t\tincludeCreateClientInterface?: boolean;\n\t\tincludeContentNamespace?: boolean;\n\t};\n};\n\nexport const generateTypes = (config: GenerateTypesConfig = {}) => {\n\tconst project = new Project({\n\t\tuseInMemoryFileSystem: true,\n\t});\n\n\tconst sourceFile = project.createSourceFile(\"types.d.ts\");\n\n\tconst typesProvider = config.typesProvider || \"@prismicio/types\";\n\n\tsourceFile.addImportDeclaration({\n\t\tmoduleSpecifier: typesProvider,\n\t\tnamespaceImport: \"prismic\",\n\t\tisTypeOnly: true,\n\t});\n\n\tsourceFile.addStatements(BLANK_LINE_IDENTIFIER);\n\n\tconst simplifyTypeAlias = sourceFile.addTypeAlias({\n\t\tname: \"Simplify\",\n\t\ttypeParameters: [\n\t\t\t{\n\t\t\t\tname: \"T\",\n\t\t\t},\n\t\t],\n\t\ttype: `{ [KeyType in keyof T]: T[KeyType] }`,\n\t});\n\n\tif (config.customTypeModels) {\n\t\tfor (const model of config.customTypeModels) {\n\t\t\taddTypeAliasForCustomType({\n\t\t\t\tmodel,\n\t\t\t\tsourceFile,\n\t\t\t\tlocaleIDs: config.localeIDs || [],\n\t\t\t\tfieldConfigs: config.fieldConfigs || {},\n\t\t\t});\n\t\t}\n\n\t\tif (config.customTypeModels.length > 0) {\n\t\t\tsourceFile.addTypeAlias({\n\t\t\t\tname: \"AllDocumentTypes\",\n\t\t\t\ttype: config.customTypeModels\n\t\t\t\t\t.map((customTypeModel) =>\n\t\t\t\t\t\tbuildTypeName(customTypeModel.id, \"Document\"),\n\t\t\t\t\t)\n\t\t\t\t\t.join(\" | \"),\n\t\t\t\tisExported: true,\n\t\t\t});\n\t\t}\n\t}\n\n\tif (config.sharedSliceModels) {\n\t\tfor (const model of config.sharedSliceModels) {\n\t\t\taddTypeAliasForSharedSlice({\n\t\t\t\tmodel,\n\t\t\t\tsourceFile,\n\t\t\t\tfieldConfigs: config.fieldConfigs || {},\n\t\t\t});\n\t\t}\n\t}\n\n\tif (\n\t\tconfig.clientIntegration?.includeCreateClientInterface ||\n\t\tconfig.clientIntegration?.includeContentNamespace\n\t) {\n\t\tlet clientNamespaceImportName = \"prismic\";\n\n\t\tif (typesProvider !== \"@prismicio/client\") {\n\t\t\tclientNamespaceImportName = \"prismicClient\";\n\n\t\t\t// This import declaration would be a duplicate if the types\n\t\t\t// provider is @prismicio/client.\n\t\t\tsourceFile.addImportDeclaration({\n\t\t\t\tmoduleSpecifier: \"@prismicio/client\",\n\t\t\t\tnamespaceImport: clientNamespaceImportName,\n\t\t\t\tisTypeOnly: true,\n\t\t\t});\n\t\t}\n\n\t\tconst clientModuleDeclaration = sourceFile.addModule({\n\t\t\tname: '\"@prismicio/client\"',\n\t\t\thasDeclareKeyword: true,\n\t\t\tdeclarationKind: ModuleDeclarationKind.Module,\n\t\t});\n\n\t\tif (config.clientIntegration.includeCreateClientInterface) {\n\t\t\tclientModuleDeclaration.addInterface({\n\t\t\t\tname: \"CreateClient\",\n\t\t\t\tcallSignatures: [\n\t\t\t\t\t{\n\t\t\t\t\t\tparameters: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tname: \"repositoryNameOrEndpoint\",\n\t\t\t\t\t\t\t\ttype: \"string\",\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tname: \"options\",\n\t\t\t\t\t\t\t\ttype: `${clientNamespaceImportName}.ClientConfig`,\n\t\t\t\t\t\t\t\thasQuestionToken: true,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t\treturnType:\n\t\t\t\t\t\t\t(config.customTypeModels?.length || 0) > 0\n\t\t\t\t\t\t\t\t? `${clientNamespaceImportName}.Client<AllDocumentTypes>`\n\t\t\t\t\t\t\t\t: `${clientNamespaceImportName}.Client`,\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t});\n\t\t}\n\n\t\tif (config.clientIntegration.includeContentNamespace) {\n\t\t\tconst contentNamespaceDeclaration = clientModuleDeclaration.addModule({\n\t\t\t\tname: \"Content\",\n\t\t\t\tdeclarationKind: ModuleDeclarationKind.Namespace,\n\t\t\t});\n\n\t\t\tconst exportSymbols = sourceFile\n\t\t\t\t.getExportSymbols()\n\t\t\t\t.filter((exportSymbol) => {\n\t\t\t\t\t// The Simplify utility type should not\n\t\t\t\t\t// be exported, but it is included in\n\t\t\t\t\t// `getExportSymbols()`'s result.\n\t\t\t\t\treturn exportSymbol.getName() !== simplifyTypeAlias.getName();\n\t\t\t\t});\n\n\t\t\tcontentNamespaceDeclaration.addExportDeclaration({\n\t\t\t\tisTypeOnly: true,\n\t\t\t\tnamedExports: exportSymbols.map((exportSymbol) => {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tname: exportSymbol.getName(),\n\t\t\t\t\t};\n\t\t\t\t}),\n\t\t\t});\n\t\t}\n\t}\n\n\treturn getSourceFileText(sourceFile);\n};\n"],"names":[],"mappings":";;;;;;AA0BO,MAAM,gBAAgB,CAAC,SAA8B,OAAM;;AAC3D,QAAA,UAAU,IAAI,QAAQ;AAAA,IAC3B,uBAAuB;AAAA,EAAA,CACvB;AAEK,QAAA,aAAa,QAAQ,iBAAiB,YAAY;AAElD,QAAA,gBAAgB,OAAO,iBAAiB;AAE9C,aAAW,qBAAqB;AAAA,IAC/B,iBAAiB;AAAA,IACjB,iBAAiB;AAAA,IACjB,YAAY;AAAA,EAAA,CACZ;AAED,aAAW,cAAc,qBAAqB;AAExC,QAAA,oBAAoB,WAAW,aAAa;AAAA,IACjD,MAAM;AAAA,IACN,gBAAgB;AAAA,MACf;AAAA,QACC,MAAM;AAAA,MACN;AAAA,IACD;AAAA,IACD,MAAM;AAAA,EAAA,CACN;AAED,MAAI,OAAO,kBAAkB;AACjB,eAAA,SAAS,OAAO,kBAAkB;AAClB,gCAAA;AAAA,QACzB;AAAA,QACA;AAAA,QACA,WAAW,OAAO,aAAa,CAAE;AAAA,QACjC,cAAc,OAAO,gBAAgB,CAAE;AAAA,MAAA,CACvC;AAAA,IACD;AAEG,QAAA,OAAO,iBAAiB,SAAS,GAAG;AACvC,iBAAW,aAAa;AAAA,QACvB,MAAM;AAAA,QACN,MAAM,OAAO,iBACX,IAAI,CAAC,oBACL,cAAc,gBAAgB,IAAI,UAAU,CAAC,EAE7C,KAAK,KAAK;AAAA,QACZ,YAAY;AAAA,MAAA,CACZ;AAAA,IACD;AAAA,EACD;AAED,MAAI,OAAO,mBAAmB;AAClB,eAAA,SAAS,OAAO,mBAAmB;AAClB,iCAAA;AAAA,QAC1B;AAAA,QACA;AAAA,QACA,cAAc,OAAO,gBAAgB,CAAE;AAAA,MAAA,CACvC;AAAA,IACD;AAAA,EACD;AAED,QACC,YAAO,sBAAP,mBAA0B,mCAC1B,YAAO,sBAAP,mBAA0B,0BACzB;AACD,QAAI,4BAA4B;AAEhC,QAAI,kBAAkB,qBAAqB;AACd,kCAAA;AAI5B,iBAAW,qBAAqB;AAAA,QAC/B,iBAAiB;AAAA,QACjB,iBAAiB;AAAA,QACjB,YAAY;AAAA,MAAA,CACZ;AAAA,IACD;AAEK,UAAA,0BAA0B,WAAW,UAAU;AAAA,MACpD,MAAM;AAAA,MACN,mBAAmB;AAAA,MACnB,iBAAiB,sBAAsB;AAAA,IAAA,CACvC;AAEG,QAAA,OAAO,kBAAkB,8BAA8B;AAC1D,8BAAwB,aAAa;AAAA,QACpC,MAAM;AAAA,QACN,gBAAgB;AAAA,UACf;AAAA,YACC,YAAY;AAAA,cACX;AAAA,gBACC,MAAM;AAAA,gBACN,MAAM;AAAA,cACN;AAAA,cACD;AAAA,gBACC,MAAM;AAAA,gBACN,MAAM,GAAG;AAAA,gBACT,kBAAkB;AAAA,cAClB;AAAA,YACD;AAAA,YACD,eACE,YAAO,qBAAP,mBAAyB,WAAU,KAAK,IACtC,GAAG,uDACH,GAAG;AAAA,UACP;AAAA,QACD;AAAA,MAAA,CACD;AAAA,IACD;AAEG,QAAA,OAAO,kBAAkB,yBAAyB;AAC/C,YAAA,8BAA8B,wBAAwB,UAAU;AAAA,QACrE,MAAM;AAAA,QACN,iBAAiB,sBAAsB;AAAA,MAAA,CACvC;AAED,YAAM,gBAAgB,WACpB,iBACA,EAAA,OAAO,CAAC,iBAAgB;AAIxB,eAAO,aAAa,QAAA,MAAc,kBAAkB,QAAO;AAAA,MAAA,CAC3D;AAEF,kCAA4B,qBAAqB;AAAA,QAChD,YAAY;AAAA,QACZ,cAAc,cAAc,IAAI,CAAC,iBAAgB;AACzC,iBAAA;AAAA,YACN,MAAM,aAAa,QAAS;AAAA,UAAA;AAAA,SAE7B;AAAA,MAAA,CACD;AAAA,IACD;AAAA,EACD;AAED,SAAO,kBAAkB,UAAU;AACpC;"}
1
+ {"version":3,"file":"generateTypes.js","sources":["../../src/generateTypes.ts"],"sourcesContent":["import type { CustomTypeModel, SharedSliceModel } from \"@prismicio/client\";\nimport { source } from \"common-tags\";\nimport QuickLRU from \"quick-lru\";\n\nimport { addLine } from \"./lib/addLine\";\nimport { addSection } from \"./lib/addSection\";\nimport { buildCustomTypeType } from \"./lib/buildCustomTypeType\";\nimport { buildSharedSliceType } from \"./lib/buildSharedSliceType\";\nimport { buildUnion } from \"./lib/buildUnion\";\n\nimport { FieldConfigs } from \"./types\";\n\nexport type TypesProvider = \"@prismicio/client\" | \"@prismicio/types\";\n\nconst cache = new QuickLRU<string, unknown>({ maxSize: 1000 });\n\nexport type GenerateTypesConfig = {\n\tcustomTypeModels?: CustomTypeModel[];\n\tsharedSliceModels?: SharedSliceModel[];\n\tlocaleIDs?: string[];\n\tfieldConfigs?: FieldConfigs;\n\ttypesProvider?: TypesProvider;\n\tclientIntegration?: {\n\t\tincludeCreateClientInterface?: boolean;\n\t\tincludeContentNamespace?: boolean;\n\t};\n\tcache?: boolean;\n};\n\nexport function generateTypes(config: GenerateTypesConfig = {}): string {\n\tconst fieldConfigs = config.fieldConfigs || {};\n\tconst shouldUseCache = config.cache ?? true;\n\n\tlet code = \"\";\n\n\tconst typesProvider = config.typesProvider || \"@prismicio/types\";\n\tlet clientImportName = \"prismic\";\n\n\tcode = addLine(`import type * as prismic from \"${typesProvider}\";`, code);\n\n\tif (\n\t\tconfig.clientIntegration?.includeCreateClientInterface ||\n\t\tconfig.clientIntegration?.includeContentNamespace\n\t) {\n\t\tif (typesProvider !== \"@prismicio/client\") {\n\t\t\tclientImportName = \"prismicClient\";\n\n\t\t\t// This import declaration would be a duplicate if the types\n\t\t\t// provider is @prismicio/client.\n\t\t\tcode = addLine(\n\t\t\t\t`import type * as ${clientImportName} from \"@prismicio/client\";`,\n\t\t\t\tcode,\n\t\t\t);\n\t\t}\n\t}\n\n\tcode = addSection(\n\t\t`type Simplify<T> = { [KeyType in keyof T]: T[KeyType] };`,\n\t\tcode,\n\t);\n\n\tconst contentTypeNames: string[] = [];\n\n\tif (config.customTypeModels) {\n\t\tconst allDocumentTypesTypeNames: string[] = [];\n\n\t\tfor (const model of config.customTypeModels) {\n\t\t\tconst customTypeType = buildCustomTypeType({\n\t\t\t\tmodel,\n\t\t\t\tlocaleIDs: config.localeIDs,\n\t\t\t\tfieldConfigs,\n\t\t\t\tcache: shouldUseCache ? cache : undefined,\n\t\t\t});\n\n\t\t\tfor (const auxiliaryType of customTypeType.auxiliaryTypes) {\n\t\t\t\tcode = addSection(auxiliaryType.code, code);\n\t\t\t}\n\n\t\t\tcode = addSection(customTypeType.code, code);\n\n\t\t\tallDocumentTypesTypeNames.push(customTypeType.name);\n\n\t\t\tcontentTypeNames.push(customTypeType.name);\n\t\t\tcontentTypeNames.push(customTypeType.dataName);\n\t\t}\n\n\t\tif (config.customTypeModels.length > 0) {\n\t\t\tconst allDocumentTypesUnionName = \"AllDocumentTypes\";\n\t\t\tconst allDocumentTypesUnion = buildUnion(allDocumentTypesTypeNames);\n\n\t\t\tcode = addSection(\n\t\t\t\t`export type ${allDocumentTypesUnionName} = ${allDocumentTypesUnion};`,\n\t\t\t\tcode,\n\t\t\t);\n\n\t\t\tcontentTypeNames.push(allDocumentTypesUnionName);\n\t\t}\n\t}\n\n\tif (config.sharedSliceModels) {\n\t\tfor (const model of config.sharedSliceModels) {\n\t\t\tconst sharedSliceType = buildSharedSliceType({\n\t\t\t\tmodel,\n\t\t\t\tfieldConfigs,\n\t\t\t\tcache: shouldUseCache ? cache : undefined,\n\t\t\t});\n\n\t\t\tcode = addSection(sharedSliceType.code, code);\n\n\t\t\tcontentTypeNames.push(sharedSliceType.name);\n\t\t\tcontentTypeNames.push(sharedSliceType.variationUnionName);\n\t\t\tcontentTypeNames.push(...sharedSliceType.variationNames);\n\t\t}\n\t}\n\n\tif (\n\t\tconfig.clientIntegration?.includeCreateClientInterface ||\n\t\tconfig.clientIntegration?.includeContentNamespace\n\t) {\n\t\tlet clientModuleCode = \"\";\n\n\t\tif (config.clientIntegration.includeCreateClientInterface) {\n\t\t\tif ((config.customTypeModels?.length || 0) > 0) {\n\t\t\t\tclientModuleCode = addSection(\n\t\t\t\t\t`interface CreateClient {\n\t(repositoryNameOrEndpoint: string, options?: ${clientImportName}.ClientConfig): ${clientImportName}.Client<AllDocumentTypes>;\n}`,\n\t\t\t\t\tclientModuleCode,\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tclientModuleCode = addSection(\n\t\t\t\t\t`interface CreateClient {\n\t(repositoryNameOrEndpoint: string, options?: ${clientImportName}.ClientConfig): ${clientImportName}.Client;\n}`,\n\t\t\t\t\tclientModuleCode,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\tif (config.clientIntegration.includeContentNamespace) {\n\t\t\tclientModuleCode = addSection(\n\t\t\t\tsource`\n\t\t\t\t\tnamespace Content {\n\t\t\t\t\t\texport type {\n\t\t\t\t\t\t\t${contentTypeNames.join(\",\\n\")}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t`,\n\t\t\t\tclientModuleCode,\n\t\t\t);\n\t\t}\n\n\t\tcode = addSection(\n\t\t\tsource`\n\t\t\t\tdeclare module \"@prismicio/client\" {\n\t\t\t\t\t${clientModuleCode}\n\t\t\t\t}\n\t\t\t`,\n\t\t\tcode,\n\t\t);\n\t}\n\n\treturn code;\n}\n"],"names":[],"mappings":";;;;;;;AAcA,MAAM,QAAQ,IAAI,SAA0B,EAAE,SAAS,IAAM,CAAA;AAe7C,SAAA,cAAc,SAA8B,IAAE;;AACvD,QAAA,eAAe,OAAO,gBAAgB;AACtC,QAAA,iBAAiB,OAAO,SAAS;AAEvC,MAAI,OAAO;AAEL,QAAA,gBAAgB,OAAO,iBAAiB;AAC9C,MAAI,mBAAmB;AAEhB,SAAA,QAAQ,kCAAkC,mBAAmB,IAAI;AAExE,QACC,YAAO,sBAAP,mBAA0B,mCAC1B,YAAO,sBAAP,mBAA0B,0BACzB;AACD,QAAI,kBAAkB,qBAAqB;AACvB,yBAAA;AAIZ,aAAA,QACN,oBAAoB,8CACpB,IAAI;AAAA,IAEL;AAAA,EACD;AAEM,SAAA,WACN,4DACA,IAAI;AAGL,QAAM,mBAA6B,CAAA;AAEnC,MAAI,OAAO,kBAAkB;AAC5B,UAAM,4BAAsC,CAAA;AAEjC,eAAA,SAAS,OAAO,kBAAkB;AAC5C,YAAM,iBAAiB,oBAAoB;AAAA,QAC1C;AAAA,QACA,WAAW,OAAO;AAAA,QAClB;AAAA,QACA,OAAO,iBAAiB,QAAQ;AAAA,MAAA,CAChC;AAEU,iBAAA,iBAAiB,eAAe,gBAAgB;AACnD,eAAA,WAAW,cAAc,MAAM,IAAI;AAAA,MAC1C;AAEM,aAAA,WAAW,eAAe,MAAM,IAAI;AAEjB,gCAAA,KAAK,eAAe,IAAI;AAEjC,uBAAA,KAAK,eAAe,IAAI;AACxB,uBAAA,KAAK,eAAe,QAAQ;AAAA,IAC7C;AAEG,QAAA,OAAO,iBAAiB,SAAS,GAAG;AACvC,YAAM,4BAA4B;AAC5B,YAAA,wBAAwB,WAAW,yBAAyB;AAElE,aAAO,WACN,eAAe,+BAA+B,0BAC9C,IAAI;AAGL,uBAAiB,KAAK,yBAAyB;AAAA,IAC/C;AAAA,EACD;AAED,MAAI,OAAO,mBAAmB;AAClB,eAAA,SAAS,OAAO,mBAAmB;AAC7C,YAAM,kBAAkB,qBAAqB;AAAA,QAC5C;AAAA,QACA;AAAA,QACA,OAAO,iBAAiB,QAAQ;AAAA,MAAA,CAChC;AAEM,aAAA,WAAW,gBAAgB,MAAM,IAAI;AAE3B,uBAAA,KAAK,gBAAgB,IAAI;AACzB,uBAAA,KAAK,gBAAgB,kBAAkB;AACvC,uBAAA,KAAK,GAAG,gBAAgB,cAAc;AAAA,IACvD;AAAA,EACD;AAED,QACC,YAAO,sBAAP,mBAA0B,mCAC1B,YAAO,sBAAP,mBAA0B,0BACzB;AACD,QAAI,mBAAmB;AAEnB,QAAA,OAAO,kBAAkB,8BAA8B;AAC1D,aAAK,YAAO,qBAAP,mBAAyB,WAAU,KAAK,GAAG;AAC/C,2BAAmB,WAClB;AAAA,gDAC2C,mCAAmC;AAAA,IAE9E,gBAAgB;AAAA,MAAA,OAEX;AACN,2BAAmB,WAClB;AAAA,gDAC2C,mCAAmC;AAAA,IAE9E,gBAAgB;AAAA,MAEjB;AAAA,IACD;AAEG,QAAA,OAAO,kBAAkB,yBAAyB;AACrD,yBAAmB,WAClB;AAAA;AAAA;AAAA,SAGK,iBAAiB,KAAK,KAAK;AAAA;AAAA;AAAA,OAIhC,gBAAgB;AAAA,IAEjB;AAED,WAAO,WACN;AAAA;AAAA,OAEI;AAAA;AAAA,MAGJ,IAAI;AAAA,EAEL;AAEM,SAAA;AACR;"}
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const addTrailingNewLine = require("./addTrailingNewLine.cjs");
4
+ function addBlankLine(state, config) {
5
+ if ((!state || state.endsWith("\n\n")) && !(config == null ? void 0 : config.force)) {
6
+ return state;
7
+ } else {
8
+ return addTrailingNewLine.addTrailingNewLine(state) + "\n";
9
+ }
10
+ }
11
+ exports.addBlankLine = addBlankLine;
12
+ //# sourceMappingURL=addBlankLine.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"addBlankLine.cjs","sources":["../../../src/lib/addBlankLine.ts"],"sourcesContent":["import { addTrailingNewLine } from \"./addTrailingNewLine\";\n\ntype AddBlankLineConfig = {\n\tforce?: boolean;\n};\n\nexport function addBlankLine(state: string, config?: AddBlankLineConfig) {\n\tif ((!state || state.endsWith(\"\\n\\n\")) && !config?.force) {\n\t\treturn state;\n\t} else {\n\t\treturn addTrailingNewLine(state) + \"\\n\";\n\t}\n}\n"],"names":["addTrailingNewLine"],"mappings":";;;AAMgB,SAAA,aAAa,OAAe,QAA2B;AACjE,OAAA,CAAC,SAAS,MAAM,SAAS,MAAM,MAAM,EAAC,iCAAQ,QAAO;AAClD,WAAA;AAAA,EAAA,OACD;AACC,WAAAA,mBAAA,mBAAmB,KAAK,IAAI;AAAA,EACnC;AACF;;"}
@@ -0,0 +1,5 @@
1
+ type AddBlankLineConfig = {
2
+ force?: boolean;
3
+ };
4
+ export declare function addBlankLine(state: string, config?: AddBlankLineConfig): string;
5
+ export {};
@@ -0,0 +1,12 @@
1
+ import { addTrailingNewLine } from "./addTrailingNewLine.js";
2
+ function addBlankLine(state, config) {
3
+ if ((!state || state.endsWith("\n\n")) && !(config == null ? void 0 : config.force)) {
4
+ return state;
5
+ } else {
6
+ return addTrailingNewLine(state) + "\n";
7
+ }
8
+ }
9
+ export {
10
+ addBlankLine
11
+ };
12
+ //# sourceMappingURL=addBlankLine.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"addBlankLine.js","sources":["../../../src/lib/addBlankLine.ts"],"sourcesContent":["import { addTrailingNewLine } from \"./addTrailingNewLine\";\n\ntype AddBlankLineConfig = {\n\tforce?: boolean;\n};\n\nexport function addBlankLine(state: string, config?: AddBlankLineConfig) {\n\tif ((!state || state.endsWith(\"\\n\\n\")) && !config?.force) {\n\t\treturn state;\n\t} else {\n\t\treturn addTrailingNewLine(state) + \"\\n\";\n\t}\n}\n"],"names":[],"mappings":";AAMgB,SAAA,aAAa,OAAe,QAA2B;AACjE,OAAA,CAAC,SAAS,MAAM,SAAS,MAAM,MAAM,EAAC,iCAAQ,QAAO;AAClD,WAAA;AAAA,EAAA,OACD;AACC,WAAA,mBAAmB,KAAK,IAAI;AAAA,EACnC;AACF;"}
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const addTrailingNewLine = require("./addTrailingNewLine.cjs");
4
+ function addLine(line, state) {
5
+ return addTrailingNewLine.addTrailingNewLine(state) + line;
6
+ }
7
+ exports.addLine = addLine;
8
+ //# sourceMappingURL=addLine.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"addLine.cjs","sources":["../../../src/lib/addLine.ts"],"sourcesContent":["import { addTrailingNewLine } from \"./addTrailingNewLine\";\n\nexport function addLine(line: string, state: string) {\n\treturn addTrailingNewLine(state) + line;\n}\n"],"names":["addTrailingNewLine"],"mappings":";;;AAEgB,SAAA,QAAQ,MAAc,OAAa;AAC3C,SAAAA,mBAAA,mBAAmB,KAAK,IAAI;AACpC;;"}
@@ -0,0 +1 @@
1
+ export declare function addLine(line: string, state: string): string;
@@ -0,0 +1,8 @@
1
+ import { addTrailingNewLine } from "./addTrailingNewLine.js";
2
+ function addLine(line, state) {
3
+ return addTrailingNewLine(state) + line;
4
+ }
5
+ export {
6
+ addLine
7
+ };
8
+ //# sourceMappingURL=addLine.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"addLine.js","sources":["../../../src/lib/addLine.ts"],"sourcesContent":["import { addTrailingNewLine } from \"./addTrailingNewLine\";\n\nexport function addLine(line: string, state: string) {\n\treturn addTrailingNewLine(state) + line;\n}\n"],"names":[],"mappings":";AAEgB,SAAA,QAAQ,MAAc,OAAa;AAC3C,SAAA,mBAAmB,KAAK,IAAI;AACpC;"}
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const addBlankLine = require("./addBlankLine.cjs");
4
+ function addSection(section, state) {
5
+ return addBlankLine.addBlankLine(state) + section;
6
+ }
7
+ exports.addSection = addSection;
8
+ //# sourceMappingURL=addSection.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"addSection.cjs","sources":["../../../src/lib/addSection.ts"],"sourcesContent":["import { addBlankLine } from \"./addBlankLine\";\n\nexport function addSection(section: string, state: string) {\n\treturn addBlankLine(state) + section;\n}\n"],"names":["addBlankLine"],"mappings":";;;AAEgB,SAAA,WAAW,SAAiB,OAAa;AACjD,SAAAA,aAAA,aAAa,KAAK,IAAI;AAC9B;;"}
@@ -0,0 +1 @@
1
+ export declare function addSection(section: string, state: string): string;
@@ -0,0 +1,8 @@
1
+ import { addBlankLine } from "./addBlankLine.js";
2
+ function addSection(section, state) {
3
+ return addBlankLine(state) + section;
4
+ }
5
+ export {
6
+ addSection
7
+ };
8
+ //# sourceMappingURL=addSection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"addSection.js","sources":["../../../src/lib/addSection.ts"],"sourcesContent":["import { addBlankLine } from \"./addBlankLine\";\n\nexport function addSection(section: string, state: string) {\n\treturn addBlankLine(state) + section;\n}\n"],"names":[],"mappings":";AAEgB,SAAA,WAAW,SAAiB,OAAa;AACjD,SAAA,aAAa,KAAK,IAAI;AAC9B;"}
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ function addTrailingNewLine(state, config) {
4
+ if ((!state || state.endsWith("\n")) && !(config == null ? void 0 : config.force)) {
5
+ return state;
6
+ } else {
7
+ return state + "\n";
8
+ }
9
+ }
10
+ exports.addTrailingNewLine = addTrailingNewLine;
11
+ //# sourceMappingURL=addTrailingNewLine.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"addTrailingNewLine.cjs","sources":["../../../src/lib/addTrailingNewLine.ts"],"sourcesContent":["type AddTrailingNewLineConfig = {\n\tforce?: boolean;\n};\n\nexport function addTrailingNewLine(\n\tstate: string,\n\tconfig?: AddTrailingNewLineConfig,\n) {\n\tif ((!state || state.endsWith(\"\\n\")) && !config?.force) {\n\t\treturn state;\n\t} else {\n\t\treturn state + \"\\n\";\n\t}\n}\n"],"names":[],"mappings":";;AAIgB,SAAA,mBACf,OACA,QAAiC;AAE5B,OAAA,CAAC,SAAS,MAAM,SAAS,IAAI,MAAM,EAAC,iCAAQ,QAAO;AAChD,WAAA;AAAA,EAAA,OACD;AACN,WAAO,QAAQ;AAAA,EACf;AACF;;"}
@@ -0,0 +1,5 @@
1
+ type AddTrailingNewLineConfig = {
2
+ force?: boolean;
3
+ };
4
+ export declare function addTrailingNewLine(state: string, config?: AddTrailingNewLineConfig): string;
5
+ export {};
@@ -0,0 +1,11 @@
1
+ function addTrailingNewLine(state, config) {
2
+ if ((!state || state.endsWith("\n")) && !(config == null ? void 0 : config.force)) {
3
+ return state;
4
+ } else {
5
+ return state + "\n";
6
+ }
7
+ }
8
+ export {
9
+ addTrailingNewLine
10
+ };
11
+ //# sourceMappingURL=addTrailingNewLine.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"addTrailingNewLine.js","sources":["../../../src/lib/addTrailingNewLine.ts"],"sourcesContent":["type AddTrailingNewLineConfig = {\n\tforce?: boolean;\n};\n\nexport function addTrailingNewLine(\n\tstate: string,\n\tconfig?: AddTrailingNewLineConfig,\n) {\n\tif ((!state || state.endsWith(\"\\n\")) && !config?.force) {\n\t\treturn state;\n\t} else {\n\t\treturn state + \"\\n\";\n\t}\n}\n"],"names":[],"mappings":"AAIgB,SAAA,mBACf,OACA,QAAiC;AAE5B,OAAA,CAAC,SAAS,MAAM,SAAS,IAAI,MAAM,EAAC,iCAAQ,QAAO;AAChD,WAAA;AAAA,EAAA,OACD;AACN,WAAO,QAAQ;AAAA,EACf;AACF;"}
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const commonTags = require("common-tags");
4
+ const buildTypeName = require("./buildTypeName.cjs");
5
+ const buildFieldProperties = require("./buildFieldProperties.cjs");
6
+ const getHumanReadableModelName = require("./getHumanReadableModelName.cjs");
7
+ function buildCustomTypeDataType(args) {
8
+ let code = "";
9
+ const auxiliaryTypes = [];
10
+ const name = buildTypeName.buildTypeName(args.model.id, "Document", "Data");
11
+ const humanReadableName = getHumanReadableModelName.getHumanReadableModelName({
12
+ name: args.model.id,
13
+ model: args.model
14
+ });
15
+ let fieldProperties = "";
16
+ for (const tabName in args.model.json) {
17
+ const { uid: _uid, ...fields } = args.model.json[tabName];
18
+ const tabFieldProperties = buildFieldProperties.buildFieldProperties({
19
+ fields,
20
+ fieldConfigs: args.fieldConfigs,
21
+ path: [
22
+ {
23
+ name: args.model.id,
24
+ model: args.model
25
+ }
26
+ ],
27
+ tabName
28
+ });
29
+ fieldProperties += tabFieldProperties.code;
30
+ auxiliaryTypes.push(...tabFieldProperties.auxiliaryTypes);
31
+ }
32
+ if (fieldProperties) {
33
+ code = commonTags.source`
34
+ /**
35
+ * Content for ${humanReadableName} documents
36
+ */
37
+ interface ${name} {
38
+ ${fieldProperties}
39
+ }
40
+ `;
41
+ } else {
42
+ code = `interface ${name} {}`;
43
+ }
44
+ return {
45
+ name,
46
+ code,
47
+ auxiliaryTypes
48
+ };
49
+ }
50
+ exports.buildCustomTypeDataType = buildCustomTypeDataType;
51
+ //# sourceMappingURL=buildCustomTypeDataType.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"buildCustomTypeDataType.cjs","sources":["../../../src/lib/buildCustomTypeDataType.ts"],"sourcesContent":["import { CustomTypeModel } from \"@prismicio/client\";\nimport { source } from \"common-tags\";\n\nimport { buildTypeName } from \"../lib/buildTypeName\";\n\nimport { AuxiliaryType, FieldConfigs } from \"../types\";\n\nimport { buildFieldProperties } from \"./buildFieldProperties\";\nimport { getHumanReadableModelName } from \"./getHumanReadableModelName\";\n\ntype BuildCustomTypeDataTypeArgs = {\n\tmodel: CustomTypeModel;\n\tfieldConfigs: FieldConfigs;\n};\n\ntype BuildCustomTypeDataTypeReturnValue = {\n\tname: string;\n\tcode: string;\n\tauxiliaryTypes: AuxiliaryType[];\n};\n\nexport function buildCustomTypeDataType(\n\targs: BuildCustomTypeDataTypeArgs,\n): BuildCustomTypeDataTypeReturnValue {\n\tlet code = \"\";\n\tconst auxiliaryTypes: AuxiliaryType[] = [];\n\n\tconst name = buildTypeName(args.model.id, \"Document\", \"Data\");\n\tconst humanReadableName = getHumanReadableModelName({\n\t\tname: args.model.id,\n\t\tmodel: args.model,\n\t});\n\n\tlet fieldProperties = \"\";\n\n\tfor (const tabName in args.model.json) {\n\t\tconst { uid: _uid, ...fields } = args.model.json[tabName];\n\n\t\tconst tabFieldProperties = buildFieldProperties({\n\t\t\tfields,\n\t\t\tfieldConfigs: args.fieldConfigs,\n\t\t\tpath: [\n\t\t\t\t{\n\t\t\t\t\tname: args.model.id,\n\t\t\t\t\tmodel: args.model,\n\t\t\t\t},\n\t\t\t],\n\t\t\ttabName,\n\t\t});\n\n\t\tfieldProperties += tabFieldProperties.code;\n\n\t\tauxiliaryTypes.push(...tabFieldProperties.auxiliaryTypes);\n\t}\n\n\tif (fieldProperties) {\n\t\tcode = source`\n\t\t\t/**\n\t\t\t * Content for ${humanReadableName} documents\n\t\t\t */\n\t\t\tinterface ${name} {\n\t\t\t\t${fieldProperties}\n\t\t\t}\n\t\t`;\n\t} else {\n\t\tcode = `interface ${name} {}`;\n\t}\n\n\treturn {\n\t\tname,\n\t\tcode,\n\t\tauxiliaryTypes,\n\t};\n}\n"],"names":["buildTypeName","getHumanReadableModelName","buildFieldProperties","source"],"mappings":";;;;;;AAqBM,SAAU,wBACf,MAAiC;AAEjC,MAAI,OAAO;AACX,QAAM,iBAAkC,CAAA;AAExC,QAAM,OAAOA,cAAAA,cAAc,KAAK,MAAM,IAAI,YAAY,MAAM;AAC5D,QAAM,oBAAoBC,0BAAAA,0BAA0B;AAAA,IACnD,MAAM,KAAK,MAAM;AAAA,IACjB,OAAO,KAAK;AAAA,EAAA,CACZ;AAED,MAAI,kBAAkB;AAEX,aAAA,WAAW,KAAK,MAAM,MAAM;AAChC,UAAA,EAAE,KAAK,MAAM,GAAG,WAAW,KAAK,MAAM,KAAK,OAAO;AAExD,UAAM,qBAAqBC,qBAAAA,qBAAqB;AAAA,MAC/C;AAAA,MACA,cAAc,KAAK;AAAA,MACnB,MAAM;AAAA,QACL;AAAA,UACC,MAAM,KAAK,MAAM;AAAA,UACjB,OAAO,KAAK;AAAA,QACZ;AAAA,MACD;AAAA,MACD;AAAA,IAAA,CACA;AAED,uBAAmB,mBAAmB;AAEvB,mBAAA,KAAK,GAAG,mBAAmB,cAAc;AAAA,EACxD;AAED,MAAI,iBAAiB;AACb,WAAAC,WAAAA;AAAAA;AAAAA,oBAEW;AAAA;AAAA,eAEL;AAAA,MACT;AAAA;AAAA;AAAA,EAAA,OAGE;AACN,WAAO,aAAa;AAAA,EACpB;AAEM,SAAA;AAAA,IACN;AAAA,IACA;AAAA,IACA;AAAA,EAAA;AAEF;;"}
@@ -0,0 +1,13 @@
1
+ import { CustomTypeModel } from "@prismicio/client";
2
+ import { AuxiliaryType, FieldConfigs } from "../types";
3
+ type BuildCustomTypeDataTypeArgs = {
4
+ model: CustomTypeModel;
5
+ fieldConfigs: FieldConfigs;
6
+ };
7
+ type BuildCustomTypeDataTypeReturnValue = {
8
+ name: string;
9
+ code: string;
10
+ auxiliaryTypes: AuxiliaryType[];
11
+ };
12
+ export declare function buildCustomTypeDataType(args: BuildCustomTypeDataTypeArgs): BuildCustomTypeDataTypeReturnValue;
13
+ export {};
@@ -0,0 +1,51 @@
1
+ import { source } from "common-tags";
2
+ import { buildTypeName } from "./buildTypeName.js";
3
+ import { buildFieldProperties } from "./buildFieldProperties.js";
4
+ import { getHumanReadableModelName } from "./getHumanReadableModelName.js";
5
+ function buildCustomTypeDataType(args) {
6
+ let code = "";
7
+ const auxiliaryTypes = [];
8
+ const name = buildTypeName(args.model.id, "Document", "Data");
9
+ const humanReadableName = getHumanReadableModelName({
10
+ name: args.model.id,
11
+ model: args.model
12
+ });
13
+ let fieldProperties = "";
14
+ for (const tabName in args.model.json) {
15
+ const { uid: _uid, ...fields } = args.model.json[tabName];
16
+ const tabFieldProperties = buildFieldProperties({
17
+ fields,
18
+ fieldConfigs: args.fieldConfigs,
19
+ path: [
20
+ {
21
+ name: args.model.id,
22
+ model: args.model
23
+ }
24
+ ],
25
+ tabName
26
+ });
27
+ fieldProperties += tabFieldProperties.code;
28
+ auxiliaryTypes.push(...tabFieldProperties.auxiliaryTypes);
29
+ }
30
+ if (fieldProperties) {
31
+ code = source`
32
+ /**
33
+ * Content for ${humanReadableName} documents
34
+ */
35
+ interface ${name} {
36
+ ${fieldProperties}
37
+ }
38
+ `;
39
+ } else {
40
+ code = `interface ${name} {}`;
41
+ }
42
+ return {
43
+ name,
44
+ code,
45
+ auxiliaryTypes
46
+ };
47
+ }
48
+ export {
49
+ buildCustomTypeDataType
50
+ };
51
+ //# sourceMappingURL=buildCustomTypeDataType.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"buildCustomTypeDataType.js","sources":["../../../src/lib/buildCustomTypeDataType.ts"],"sourcesContent":["import { CustomTypeModel } from \"@prismicio/client\";\nimport { source } from \"common-tags\";\n\nimport { buildTypeName } from \"../lib/buildTypeName\";\n\nimport { AuxiliaryType, FieldConfigs } from \"../types\";\n\nimport { buildFieldProperties } from \"./buildFieldProperties\";\nimport { getHumanReadableModelName } from \"./getHumanReadableModelName\";\n\ntype BuildCustomTypeDataTypeArgs = {\n\tmodel: CustomTypeModel;\n\tfieldConfigs: FieldConfigs;\n};\n\ntype BuildCustomTypeDataTypeReturnValue = {\n\tname: string;\n\tcode: string;\n\tauxiliaryTypes: AuxiliaryType[];\n};\n\nexport function buildCustomTypeDataType(\n\targs: BuildCustomTypeDataTypeArgs,\n): BuildCustomTypeDataTypeReturnValue {\n\tlet code = \"\";\n\tconst auxiliaryTypes: AuxiliaryType[] = [];\n\n\tconst name = buildTypeName(args.model.id, \"Document\", \"Data\");\n\tconst humanReadableName = getHumanReadableModelName({\n\t\tname: args.model.id,\n\t\tmodel: args.model,\n\t});\n\n\tlet fieldProperties = \"\";\n\n\tfor (const tabName in args.model.json) {\n\t\tconst { uid: _uid, ...fields } = args.model.json[tabName];\n\n\t\tconst tabFieldProperties = buildFieldProperties({\n\t\t\tfields,\n\t\t\tfieldConfigs: args.fieldConfigs,\n\t\t\tpath: [\n\t\t\t\t{\n\t\t\t\t\tname: args.model.id,\n\t\t\t\t\tmodel: args.model,\n\t\t\t\t},\n\t\t\t],\n\t\t\ttabName,\n\t\t});\n\n\t\tfieldProperties += tabFieldProperties.code;\n\n\t\tauxiliaryTypes.push(...tabFieldProperties.auxiliaryTypes);\n\t}\n\n\tif (fieldProperties) {\n\t\tcode = source`\n\t\t\t/**\n\t\t\t * Content for ${humanReadableName} documents\n\t\t\t */\n\t\t\tinterface ${name} {\n\t\t\t\t${fieldProperties}\n\t\t\t}\n\t\t`;\n\t} else {\n\t\tcode = `interface ${name} {}`;\n\t}\n\n\treturn {\n\t\tname,\n\t\tcode,\n\t\tauxiliaryTypes,\n\t};\n}\n"],"names":[],"mappings":";;;;AAqBM,SAAU,wBACf,MAAiC;AAEjC,MAAI,OAAO;AACX,QAAM,iBAAkC,CAAA;AAExC,QAAM,OAAO,cAAc,KAAK,MAAM,IAAI,YAAY,MAAM;AAC5D,QAAM,oBAAoB,0BAA0B;AAAA,IACnD,MAAM,KAAK,MAAM;AAAA,IACjB,OAAO,KAAK;AAAA,EAAA,CACZ;AAED,MAAI,kBAAkB;AAEX,aAAA,WAAW,KAAK,MAAM,MAAM;AAChC,UAAA,EAAE,KAAK,MAAM,GAAG,WAAW,KAAK,MAAM,KAAK,OAAO;AAExD,UAAM,qBAAqB,qBAAqB;AAAA,MAC/C;AAAA,MACA,cAAc,KAAK;AAAA,MACnB,MAAM;AAAA,QACL;AAAA,UACC,MAAM,KAAK,MAAM;AAAA,UACjB,OAAO,KAAK;AAAA,QACZ;AAAA,MACD;AAAA,MACD;AAAA,IAAA,CACA;AAED,uBAAmB,mBAAmB;AAEvB,mBAAA,KAAK,GAAG,mBAAmB,cAAc;AAAA,EACxD;AAED,MAAI,iBAAiB;AACb,WAAA;AAAA;AAAA,oBAEW;AAAA;AAAA,eAEL;AAAA,MACT;AAAA;AAAA;AAAA,EAAA,OAGE;AACN,WAAO,aAAa;AAAA,EACpB;AAEM,SAAA;AAAA,IACN;AAAA,IACA;AAAA,IACA;AAAA,EAAA;AAEF;"}
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const commonTags = require("common-tags");
4
+ const constants = require("../constants.cjs");
5
+ const addSection = require("./addSection.cjs");
6
+ const buildCustomTypeDataType = require("./buildCustomTypeDataType.cjs");
7
+ const buildTypeName = require("./buildTypeName.cjs");
8
+ const buildUnion = require("./buildUnion.cjs");
9
+ const checkHasUIDFIeld = require("./checkHasUIDFIeld.cjs");
10
+ const getCacheKey = require("./getCacheKey.cjs");
11
+ const getHumanReadableModelName = require("./getHumanReadableModelName.cjs");
12
+ function buildCustomTypeType(args) {
13
+ if (args.cache) {
14
+ const key = getCacheKey.getCacheKey(args.model);
15
+ const cached = args.cache.get(key);
16
+ if (cached) {
17
+ return cached;
18
+ }
19
+ }
20
+ let code = "";
21
+ const auxiliaryTypes = [];
22
+ const name = buildTypeName.buildTypeName(args.model.id, "Document");
23
+ const langDefault = args.localeIDs && args.localeIDs.length > 0 ? buildUnion.buildUnion(args.localeIDs.map((localeID) => `"${localeID}"`)) : "string";
24
+ const baseDocumentType = checkHasUIDFIeld.checkHasUIDField(args.model) ? "PrismicDocumentWithUID" : "PrismicDocumentWithoutUID";
25
+ const humanReadableName = getHumanReadableModelName.getHumanReadableModelName({
26
+ name: args.model.id,
27
+ model: args.model
28
+ });
29
+ const dataType = buildCustomTypeDataType.buildCustomTypeDataType({
30
+ model: args.model,
31
+ fieldConfigs: args.fieldConfigs
32
+ });
33
+ auxiliaryTypes.push(...dataType.auxiliaryTypes);
34
+ code = addSection.addSection(dataType.code, code);
35
+ code = addSection.addSection(commonTags.source`
36
+ /**
37
+ * ${humanReadableName} document from Prismic
38
+ *
39
+ * - **API ID**: \`${args.model.id}\`
40
+ * - **Repeatable**: \`${args.model.repeatable.toString()}\`
41
+ * - **Documentation**: ${constants.CUSTOM_TYPES_DOCUMENTATION_URL}
42
+ *
43
+ * @typeParam Lang - Language API ID of the document.
44
+ */
45
+ export type ${name}<Lang extends string = ${langDefault}> = prismic.${baseDocumentType}<Simplify<${dataType.name}>, "${args.model.id}", Lang>;
46
+ `, code);
47
+ const result = {
48
+ name,
49
+ dataName: dataType.name,
50
+ code,
51
+ auxiliaryTypes
52
+ };
53
+ if (args.cache) {
54
+ const key = getCacheKey.getCacheKey(args.model);
55
+ args.cache.set(key, result);
56
+ }
57
+ return result;
58
+ }
59
+ exports.buildCustomTypeType = buildCustomTypeType;
60
+ //# sourceMappingURL=buildCustomTypeType.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"buildCustomTypeType.cjs","sources":["../../../src/lib/buildCustomTypeType.ts"],"sourcesContent":["import { CustomTypeModel } from \"@prismicio/client\";\nimport { source } from \"common-tags\";\nimport QuickLRU from \"quick-lru\";\n\nimport { AuxiliaryType, FieldConfigs } from \"../types\";\n\nimport { CUSTOM_TYPES_DOCUMENTATION_URL } from \"../constants\";\n\nimport { addSection } from \"./addSection\";\nimport { buildCustomTypeDataType } from \"./buildCustomTypeDataType\";\nimport { buildTypeName } from \"./buildTypeName\";\nimport { buildUnion } from \"./buildUnion\";\nimport { checkHasUIDField } from \"./checkHasUIDFIeld\";\nimport { getCacheKey } from \"./getCacheKey\";\nimport { getHumanReadableModelName } from \"./getHumanReadableModelName\";\n\ntype BuildCustomTypeTypesArgs = {\n\tmodel: CustomTypeModel;\n\tlocaleIDs?: string[];\n\tfieldConfigs: FieldConfigs;\n\tcache?: QuickLRU<string, unknown>;\n};\n\ntype BuildCustomTypeTypeReturnValue = {\n\tname: string;\n\tdataName: string;\n\tcode: string;\n\tauxiliaryTypes: AuxiliaryType[];\n};\n\nexport function buildCustomTypeType(\n\targs: BuildCustomTypeTypesArgs,\n): BuildCustomTypeTypeReturnValue {\n\tif (args.cache) {\n\t\tconst key = getCacheKey(args.model);\n\t\tconst cached = args.cache.get(key);\n\n\t\tif (cached) {\n\t\t\treturn cached as BuildCustomTypeTypeReturnValue;\n\t\t}\n\t}\n\n\tlet code = \"\";\n\n\tconst auxiliaryTypes: AuxiliaryType[] = [];\n\n\tconst name = buildTypeName(args.model.id, \"Document\");\n\tconst langDefault =\n\t\targs.localeIDs && args.localeIDs.length > 0\n\t\t\t? buildUnion(args.localeIDs.map((localeID) => `\"${localeID}\"`))\n\t\t\t: \"string\";\n\tconst baseDocumentType = checkHasUIDField(args.model)\n\t\t? \"PrismicDocumentWithUID\"\n\t\t: \"PrismicDocumentWithoutUID\";\n\tconst humanReadableName = getHumanReadableModelName({\n\t\tname: args.model.id,\n\t\tmodel: args.model,\n\t});\n\n\tconst dataType = buildCustomTypeDataType({\n\t\tmodel: args.model,\n\t\tfieldConfigs: args.fieldConfigs,\n\t});\n\n\tauxiliaryTypes.push(...dataType.auxiliaryTypes);\n\n\tcode = addSection(dataType.code, code);\n\n\tcode = addSection(\n\t\tsource`\n\t\t\t/**\n\t\t\t * ${humanReadableName} document from Prismic\n\t\t\t *\n\t\t\t * - **API ID**: \\`${args.model.id}\\`\n\t\t\t * - **Repeatable**: \\`${args.model.repeatable.toString()}\\`\n\t\t\t * - **Documentation**: ${CUSTOM_TYPES_DOCUMENTATION_URL}\n\t\t\t *\n\t\t\t * @typeParam Lang - Language API ID of the document.\n\t\t\t */\n\t\t\texport type ${name}<Lang extends string = ${langDefault}> = prismic.${baseDocumentType}<Simplify<${\n\t\t\tdataType.name\n\t\t}>, \"${args.model.id}\", Lang>;\n\t\t`,\n\t\tcode,\n\t);\n\n\tconst result = {\n\t\tname,\n\t\tdataName: dataType.name,\n\t\tcode,\n\t\tauxiliaryTypes,\n\t};\n\n\tif (args.cache) {\n\t\tconst key = getCacheKey(args.model);\n\n\t\targs.cache.set(key, result);\n\t}\n\n\treturn result;\n}\n"],"names":["getCacheKey","buildTypeName","buildUnion","checkHasUIDField","getHumanReadableModelName","buildCustomTypeDataType","addSection","source","CUSTOM_TYPES_DOCUMENTATION_URL"],"mappings":";;;;;;;;;;;AA8BM,SAAU,oBACf,MAA8B;AAE9B,MAAI,KAAK,OAAO;AACT,UAAA,MAAMA,YAAAA,YAAY,KAAK,KAAK;AAClC,UAAM,SAAS,KAAK,MAAM,IAAI,GAAG;AAEjC,QAAI,QAAQ;AACJ,aAAA;AAAA,IACP;AAAA,EACD;AAED,MAAI,OAAO;AAEX,QAAM,iBAAkC,CAAA;AAExC,QAAM,OAAOC,cAAAA,cAAc,KAAK,MAAM,IAAI,UAAU;AACpD,QAAM,cACL,KAAK,aAAa,KAAK,UAAU,SAAS,IACvCC,sBAAW,KAAK,UAAU,IAAI,CAAC,aAAa,IAAI,WAAW,CAAC,IAC5D;AACJ,QAAM,mBAAmBC,iBAAAA,iBAAiB,KAAK,KAAK,IACjD,2BACA;AACH,QAAM,oBAAoBC,0BAAAA,0BAA0B;AAAA,IACnD,MAAM,KAAK,MAAM;AAAA,IACjB,OAAO,KAAK;AAAA,EAAA,CACZ;AAED,QAAM,WAAWC,wBAAAA,wBAAwB;AAAA,IACxC,OAAO,KAAK;AAAA,IACZ,cAAc,KAAK;AAAA,EAAA,CACnB;AAEc,iBAAA,KAAK,GAAG,SAAS,cAAc;AAEvC,SAAAC,WAAAA,WAAW,SAAS,MAAM,IAAI;AAErC,SAAOA,WACN,WAAAC;;QAEM;AAAA;AAAA,wBAEgB,KAAK,MAAM;AAAA,4BACP,KAAK,MAAM,WAAW,SAAU;AAAA,6BAC/BC;;;;iBAIZ,8BAA8B,0BAA0B,6BACtE,SAAS,WACH,KAAK,MAAM;AAAA,KAElB,IAAI;AAGL,QAAM,SAAS;AAAA,IACd;AAAA,IACA,UAAU,SAAS;AAAA,IACnB;AAAA,IACA;AAAA,EAAA;AAGD,MAAI,KAAK,OAAO;AACT,UAAA,MAAMR,YAAAA,YAAY,KAAK,KAAK;AAE7B,SAAA,MAAM,IAAI,KAAK,MAAM;AAAA,EAC1B;AAEM,SAAA;AACR;;"}
@@ -0,0 +1,17 @@
1
+ import { CustomTypeModel } from "@prismicio/client";
2
+ import QuickLRU from "quick-lru";
3
+ import { AuxiliaryType, FieldConfigs } from "../types";
4
+ type BuildCustomTypeTypesArgs = {
5
+ model: CustomTypeModel;
6
+ localeIDs?: string[];
7
+ fieldConfigs: FieldConfigs;
8
+ cache?: QuickLRU<string, unknown>;
9
+ };
10
+ type BuildCustomTypeTypeReturnValue = {
11
+ name: string;
12
+ dataName: string;
13
+ code: string;
14
+ auxiliaryTypes: AuxiliaryType[];
15
+ };
16
+ export declare function buildCustomTypeType(args: BuildCustomTypeTypesArgs): BuildCustomTypeTypeReturnValue;
17
+ export {};
@@ -0,0 +1,60 @@
1
+ import { source } from "common-tags";
2
+ import { CUSTOM_TYPES_DOCUMENTATION_URL } from "../constants.js";
3
+ import { addSection } from "./addSection.js";
4
+ import { buildCustomTypeDataType } from "./buildCustomTypeDataType.js";
5
+ import { buildTypeName } from "./buildTypeName.js";
6
+ import { buildUnion } from "./buildUnion.js";
7
+ import { checkHasUIDField } from "./checkHasUIDFIeld.js";
8
+ import { getCacheKey } from "./getCacheKey.js";
9
+ import { getHumanReadableModelName } from "./getHumanReadableModelName.js";
10
+ function buildCustomTypeType(args) {
11
+ if (args.cache) {
12
+ const key = getCacheKey(args.model);
13
+ const cached = args.cache.get(key);
14
+ if (cached) {
15
+ return cached;
16
+ }
17
+ }
18
+ let code = "";
19
+ const auxiliaryTypes = [];
20
+ const name = buildTypeName(args.model.id, "Document");
21
+ const langDefault = args.localeIDs && args.localeIDs.length > 0 ? buildUnion(args.localeIDs.map((localeID) => `"${localeID}"`)) : "string";
22
+ const baseDocumentType = checkHasUIDField(args.model) ? "PrismicDocumentWithUID" : "PrismicDocumentWithoutUID";
23
+ const humanReadableName = getHumanReadableModelName({
24
+ name: args.model.id,
25
+ model: args.model
26
+ });
27
+ const dataType = buildCustomTypeDataType({
28
+ model: args.model,
29
+ fieldConfigs: args.fieldConfigs
30
+ });
31
+ auxiliaryTypes.push(...dataType.auxiliaryTypes);
32
+ code = addSection(dataType.code, code);
33
+ code = addSection(source`
34
+ /**
35
+ * ${humanReadableName} document from Prismic
36
+ *
37
+ * - **API ID**: \`${args.model.id}\`
38
+ * - **Repeatable**: \`${args.model.repeatable.toString()}\`
39
+ * - **Documentation**: ${CUSTOM_TYPES_DOCUMENTATION_URL}
40
+ *
41
+ * @typeParam Lang - Language API ID of the document.
42
+ */
43
+ export type ${name}<Lang extends string = ${langDefault}> = prismic.${baseDocumentType}<Simplify<${dataType.name}>, "${args.model.id}", Lang>;
44
+ `, code);
45
+ const result = {
46
+ name,
47
+ dataName: dataType.name,
48
+ code,
49
+ auxiliaryTypes
50
+ };
51
+ if (args.cache) {
52
+ const key = getCacheKey(args.model);
53
+ args.cache.set(key, result);
54
+ }
55
+ return result;
56
+ }
57
+ export {
58
+ buildCustomTypeType
59
+ };
60
+ //# sourceMappingURL=buildCustomTypeType.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"buildCustomTypeType.js","sources":["../../../src/lib/buildCustomTypeType.ts"],"sourcesContent":["import { CustomTypeModel } from \"@prismicio/client\";\nimport { source } from \"common-tags\";\nimport QuickLRU from \"quick-lru\";\n\nimport { AuxiliaryType, FieldConfigs } from \"../types\";\n\nimport { CUSTOM_TYPES_DOCUMENTATION_URL } from \"../constants\";\n\nimport { addSection } from \"./addSection\";\nimport { buildCustomTypeDataType } from \"./buildCustomTypeDataType\";\nimport { buildTypeName } from \"./buildTypeName\";\nimport { buildUnion } from \"./buildUnion\";\nimport { checkHasUIDField } from \"./checkHasUIDFIeld\";\nimport { getCacheKey } from \"./getCacheKey\";\nimport { getHumanReadableModelName } from \"./getHumanReadableModelName\";\n\ntype BuildCustomTypeTypesArgs = {\n\tmodel: CustomTypeModel;\n\tlocaleIDs?: string[];\n\tfieldConfigs: FieldConfigs;\n\tcache?: QuickLRU<string, unknown>;\n};\n\ntype BuildCustomTypeTypeReturnValue = {\n\tname: string;\n\tdataName: string;\n\tcode: string;\n\tauxiliaryTypes: AuxiliaryType[];\n};\n\nexport function buildCustomTypeType(\n\targs: BuildCustomTypeTypesArgs,\n): BuildCustomTypeTypeReturnValue {\n\tif (args.cache) {\n\t\tconst key = getCacheKey(args.model);\n\t\tconst cached = args.cache.get(key);\n\n\t\tif (cached) {\n\t\t\treturn cached as BuildCustomTypeTypeReturnValue;\n\t\t}\n\t}\n\n\tlet code = \"\";\n\n\tconst auxiliaryTypes: AuxiliaryType[] = [];\n\n\tconst name = buildTypeName(args.model.id, \"Document\");\n\tconst langDefault =\n\t\targs.localeIDs && args.localeIDs.length > 0\n\t\t\t? buildUnion(args.localeIDs.map((localeID) => `\"${localeID}\"`))\n\t\t\t: \"string\";\n\tconst baseDocumentType = checkHasUIDField(args.model)\n\t\t? \"PrismicDocumentWithUID\"\n\t\t: \"PrismicDocumentWithoutUID\";\n\tconst humanReadableName = getHumanReadableModelName({\n\t\tname: args.model.id,\n\t\tmodel: args.model,\n\t});\n\n\tconst dataType = buildCustomTypeDataType({\n\t\tmodel: args.model,\n\t\tfieldConfigs: args.fieldConfigs,\n\t});\n\n\tauxiliaryTypes.push(...dataType.auxiliaryTypes);\n\n\tcode = addSection(dataType.code, code);\n\n\tcode = addSection(\n\t\tsource`\n\t\t\t/**\n\t\t\t * ${humanReadableName} document from Prismic\n\t\t\t *\n\t\t\t * - **API ID**: \\`${args.model.id}\\`\n\t\t\t * - **Repeatable**: \\`${args.model.repeatable.toString()}\\`\n\t\t\t * - **Documentation**: ${CUSTOM_TYPES_DOCUMENTATION_URL}\n\t\t\t *\n\t\t\t * @typeParam Lang - Language API ID of the document.\n\t\t\t */\n\t\t\texport type ${name}<Lang extends string = ${langDefault}> = prismic.${baseDocumentType}<Simplify<${\n\t\t\tdataType.name\n\t\t}>, \"${args.model.id}\", Lang>;\n\t\t`,\n\t\tcode,\n\t);\n\n\tconst result = {\n\t\tname,\n\t\tdataName: dataType.name,\n\t\tcode,\n\t\tauxiliaryTypes,\n\t};\n\n\tif (args.cache) {\n\t\tconst key = getCacheKey(args.model);\n\n\t\targs.cache.set(key, result);\n\t}\n\n\treturn result;\n}\n"],"names":[],"mappings":";;;;;;;;;AA8BM,SAAU,oBACf,MAA8B;AAE9B,MAAI,KAAK,OAAO;AACT,UAAA,MAAM,YAAY,KAAK,KAAK;AAClC,UAAM,SAAS,KAAK,MAAM,IAAI,GAAG;AAEjC,QAAI,QAAQ;AACJ,aAAA;AAAA,IACP;AAAA,EACD;AAED,MAAI,OAAO;AAEX,QAAM,iBAAkC,CAAA;AAExC,QAAM,OAAO,cAAc,KAAK,MAAM,IAAI,UAAU;AACpD,QAAM,cACL,KAAK,aAAa,KAAK,UAAU,SAAS,IACvC,WAAW,KAAK,UAAU,IAAI,CAAC,aAAa,IAAI,WAAW,CAAC,IAC5D;AACJ,QAAM,mBAAmB,iBAAiB,KAAK,KAAK,IACjD,2BACA;AACH,QAAM,oBAAoB,0BAA0B;AAAA,IACnD,MAAM,KAAK,MAAM;AAAA,IACjB,OAAO,KAAK;AAAA,EAAA,CACZ;AAED,QAAM,WAAW,wBAAwB;AAAA,IACxC,OAAO,KAAK;AAAA,IACZ,cAAc,KAAK;AAAA,EAAA,CACnB;AAEc,iBAAA,KAAK,GAAG,SAAS,cAAc;AAEvC,SAAA,WAAW,SAAS,MAAM,IAAI;AAErC,SAAO,WACN;AAAA;AAAA,QAEM;AAAA;AAAA,wBAEgB,KAAK,MAAM;AAAA,4BACP,KAAK,MAAM,WAAW,SAAU;AAAA,6BAC/B;AAAA;AAAA;AAAA;AAAA,iBAIZ,8BAA8B,0BAA0B,6BACtE,SAAS,WACH,KAAK,MAAM;AAAA,KAElB,IAAI;AAGL,QAAM,SAAS;AAAA,IACd;AAAA,IACA,UAAU,SAAS;AAAA,IACnB;AAAA,IACA;AAAA,EAAA;AAGD,MAAI,KAAK,OAAO;AACT,UAAA,MAAM,YAAY,KAAK,KAAK;AAE7B,SAAA,MAAM,IAAI,KAAK,MAAM;AAAA,EAC1B;AAEM,SAAA;AACR;"}
@@ -1,43 +1,75 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const constants = require("../constants.cjs");
4
+ const addLine = require("./addLine.cjs");
3
5
  const getAPIIDPath = require("./getAPIIDPath.cjs");
4
- const getFieldDocumentationURL = require("./getFieldDocumentationURL.cjs");
5
- const getHumanReadableFieldPath = require("./getHumanReadableFieldPath.cjs");
6
- const getHumanReadableFieldType = require("./getHumanReadableFieldType.cjs");
7
6
  const getHumanReadableModelName = require("./getHumanReadableModelName.cjs");
8
- const writeFieldDocsDescription = require("./writeFieldDocsDescription.cjs");
9
- const buildFieldDocs = (config) => {
10
- return [
11
- {
12
- description: (writer) => {
13
- const name = getHumanReadableModelName.getHumanReadableModelName({
14
- id: config.id,
15
- model: config.model
16
- });
17
- const humanReadablePath = getHumanReadableFieldPath.getHumanReadableFieldPath({
18
- path: config.path
19
- });
20
- const fieldType = getHumanReadableFieldType.getHumanReadableFieldType({
21
- model: config.model
22
- });
23
- const placeholder = config.model.config && "placeholder" in config.model.config && config.model.config.placeholder ? config.model.config.placeholder : `*None*`;
24
- const defaultValue = config.model.config && "default_value" in config.model.config ? config.model.config.default_value : void 0;
25
- const apiIDPath = getAPIIDPath.getAPIIDPath({
26
- path: [...config.path, { id: config.id, model: config.model }]
27
- });
28
- writeFieldDocsDescription.writeFieldDocsDescription({
29
- writer,
30
- description: `${name} field in *${humanReadablePath}*`,
31
- fieldType,
32
- placeholder,
33
- defaultValue,
34
- apiIDPath,
35
- tabName: config.tabName,
36
- documentationURL: getFieldDocumentationURL.getFieldDocumentationURL({ model: config.model })
37
- });
7
+ const getHumanReadablePath = require("./getHumanReadablePath.cjs");
8
+ function getHumanReadableFieldType(args) {
9
+ var _a, _b;
10
+ switch (args.field.type) {
11
+ case "StructuredText": {
12
+ const isTitleField = args.field.config && "single" in args.field.config && args.field.config.single && args.field.config.single.split(",").every((blockType) => /heading/.test(blockType));
13
+ return isTitleField ? "Title" : "Rich Text";
14
+ }
15
+ case "IntegrationFields": {
16
+ const catalog = (_a = args.field.config) == null ? void 0 : _a.catalog;
17
+ return `Integration Fields (Catalog: ${catalog ? `\`${catalog}\`` : "*unknown*"})`;
18
+ }
19
+ case "Link": {
20
+ switch ((_b = args.field.config) == null ? void 0 : _b.select) {
21
+ case "document": {
22
+ return "Content Relationship";
23
+ }
24
+ case "media": {
25
+ return "Link to Media";
26
+ }
27
+ default: {
28
+ return "Link";
29
+ }
38
30
  }
39
31
  }
40
- ];
41
- };
32
+ case "Slices": {
33
+ return "Slice Zone";
34
+ }
35
+ default: {
36
+ return args.field.type;
37
+ }
38
+ }
39
+ }
40
+ function buildFieldDocs(args) {
41
+ let result = "/**";
42
+ const humanReadableName = getHumanReadableModelName.getHumanReadableModelName({
43
+ model: args.field,
44
+ name: args.name
45
+ });
46
+ const humanReadablePath = getHumanReadablePath.getHumanReadablePath({ path: args.path });
47
+ const humanReadableFieldType = getHumanReadableFieldType({
48
+ field: args.field
49
+ });
50
+ result = addLine.addLine(` * ${humanReadableName} field in *${humanReadablePath}*`, result);
51
+ result = addLine.addLine(" *", result);
52
+ result = addLine.addLine(` * - **Field Type**: ${humanReadableFieldType}`, result);
53
+ const placeholder = args.field.config && "placeholder" in args.field.config && args.field.config.placeholder || `*None*`;
54
+ result = addLine.addLine(` * - **Placeholder**: ${placeholder}`, result);
55
+ const defaultValue = args.field.config && "default_value" in args.field.config ? args.field.config.default_value : void 0;
56
+ if (defaultValue !== void 0) {
57
+ const stringifiedDefaultValue = typeof defaultValue === "boolean" ? `${defaultValue}` : defaultValue;
58
+ result = addLine.addLine(` * - **Default Value**: ${stringifiedDefaultValue}`, result);
59
+ }
60
+ const apiIDPath = getAPIIDPath.getAPIIDPath({
61
+ path: [...args.path, { name: args.name, model: args.field }]
62
+ });
63
+ result = addLine.addLine(` * - **API ID Path**: ${apiIDPath}`, result);
64
+ if (args.tabName) {
65
+ result = addLine.addLine(` * - **Tab**: ${args.tabName}`, result);
66
+ }
67
+ const documentationURL = constants.FIELD_DOCUMENTATION_URLS[args.field.type];
68
+ if (documentationURL) {
69
+ result = addLine.addLine(` * - **Documentation**: ${documentationURL}`, result);
70
+ }
71
+ result = addLine.addLine(" */", result);
72
+ return result;
73
+ }
42
74
  exports.buildFieldDocs = buildFieldDocs;
43
75
  //# sourceMappingURL=buildFieldDocs.cjs.map