prismic-ts-codegen 0.1.11 → 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 +18 -17
  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,28 +1,26 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const BLANK_LINE_IDENTIFIER = "// ___BLANK_LINE_TO_BE_REPLACED___";
4
- const CUSTOM_TYPES_DOCUMENTATION_URL = "https://prismic.io/docs/core-concepts/custom-types";
5
- const SHARED_SLICES_DOCUMENTATION_URL = "https://prismic.io/docs/core-concepts/reusing-slices";
3
+ const CUSTOM_TYPES_DOCUMENTATION_URL = "https://prismic.io/docs/custom-types";
4
+ const SHARED_SLICES_DOCUMENTATION_URL = "https://prismic.io/docs/slice";
6
5
  const FIELD_DOCUMENTATION_URLS = {
7
- UID: "https://prismic.io/docs/core-concepts/uid",
8
- Boolean: "https://prismic.io/docs/core-concepts/boolean",
9
- Color: "https://prismic.io/docs/core-concepts/color",
10
- Date: "https://prismic.io/docs/core-concepts/date",
11
- Timestamp: "https://prismic.io/docs/core-concepts/timestamp",
12
- Number: "https://prismic.io/docs/core-concepts/number",
13
- Text: "https://prismic.io/docs/core-concepts/key-text",
14
- Select: "https://prismic.io/docs/core-concepts/select",
15
- StructuredText: "https://prismic.io/docs/core-concepts/rich-text-title",
16
- Image: "https://prismic.io/docs/core-concepts/image",
17
- Link: "https://prismic.io/docs/core-concepts/link-content-relationship",
18
- Embed: "https://prismic.io/docs/core-concepts/embed",
19
- GeoPoint: "https://prismic.io/docs/core-concepts/geopoint",
20
- Group: "https://prismic.io/docs/core-concepts/group",
21
- IntegrationFields: "https://prismic.io/docs/core-concepts/integration-fields",
22
- Slices: "https://prismic.io/docs/core-concepts/slices",
23
- Choice: "https://prismic.io/docs/core-concepts/slices"
6
+ UID: "https://prismic.io/docs/field#uid",
7
+ Boolean: "https://prismic.io/docs/field#boolean",
8
+ Color: "https://prismic.io/docs/field#color",
9
+ Date: "https://prismic.io/docs/field#date",
10
+ Timestamp: "https://prismic.io/docs/field#timestamp",
11
+ Number: "https://prismic.io/docs/field#number",
12
+ Text: "https://prismic.io/docs/field#key-text",
13
+ Select: "https://prismic.io/docs/field#select",
14
+ StructuredText: "https://prismic.io/docs/field#rich-text-title",
15
+ Image: "https://prismic.io/docs/field#image",
16
+ Link: "https://prismic.io/docs/field#link-content-relationship",
17
+ Embed: "https://prismic.io/docs/field#embed",
18
+ GeoPoint: "https://prismic.io/docs/field#geopoint",
19
+ Group: "https://prismic.io/docs/field#group",
20
+ IntegrationFields: "https://prismic.io/docs/field#integration",
21
+ Slices: "https://prismic.io/docs/field#slices",
22
+ Choice: "https://prismic.io/docs/field#slices"
24
23
  };
25
- exports.BLANK_LINE_IDENTIFIER = BLANK_LINE_IDENTIFIER;
26
24
  exports.CUSTOM_TYPES_DOCUMENTATION_URL = CUSTOM_TYPES_DOCUMENTATION_URL;
27
25
  exports.FIELD_DOCUMENTATION_URLS = FIELD_DOCUMENTATION_URLS;
28
26
  exports.SHARED_SLICES_DOCUMENTATION_URL = SHARED_SLICES_DOCUMENTATION_URL;
@@ -1 +1 @@
1
- {"version":3,"file":"constants.cjs","sources":["../../src/constants.ts"],"sourcesContent":["import type { CustomTypeModelFieldType } from \"@prismicio/client\";\n\nexport const BLANK_LINE_IDENTIFIER = \"// ___BLANK_LINE_TO_BE_REPLACED___\";\n\nexport const CUSTOM_TYPES_DOCUMENTATION_URL =\n\t\"https://prismic.io/docs/core-concepts/custom-types\";\n\nexport const SHARED_SLICES_DOCUMENTATION_URL =\n\t\"https://prismic.io/docs/core-concepts/reusing-slices\";\n\nexport const FIELD_DOCUMENTATION_URLS: Record<\n\tExclude<\n\t\t(typeof CustomTypeModelFieldType)[keyof typeof CustomTypeModelFieldType],\n\t\t\"Range\" | \"Separator\"\n\t>,\n\tstring\n> = {\n\tUID: \"https://prismic.io/docs/core-concepts/uid\",\n\tBoolean: \"https://prismic.io/docs/core-concepts/boolean\",\n\tColor: \"https://prismic.io/docs/core-concepts/color\",\n\tDate: \"https://prismic.io/docs/core-concepts/date\",\n\tTimestamp: \"https://prismic.io/docs/core-concepts/timestamp\",\n\tNumber: \"https://prismic.io/docs/core-concepts/number\",\n\tText: \"https://prismic.io/docs/core-concepts/key-text\",\n\tSelect: \"https://prismic.io/docs/core-concepts/select\",\n\tStructuredText: \"https://prismic.io/docs/core-concepts/rich-text-title\",\n\tImage: \"https://prismic.io/docs/core-concepts/image\",\n\tLink: \"https://prismic.io/docs/core-concepts/link-content-relationship\",\n\tEmbed: \"https://prismic.io/docs/core-concepts/embed\",\n\tGeoPoint: \"https://prismic.io/docs/core-concepts/geopoint\",\n\tGroup: \"https://prismic.io/docs/core-concepts/group\",\n\tIntegrationFields: \"https://prismic.io/docs/core-concepts/integration-fields\",\n\tSlices: \"https://prismic.io/docs/core-concepts/slices\",\n\tChoice: \"https://prismic.io/docs/core-concepts/slices\",\n};\n"],"names":[],"mappings":";;AAEO,MAAM,wBAAwB;AAE9B,MAAM,iCACZ;AAEM,MAAM,kCACZ;AAEM,MAAM,2BAMT;AAAA,EACH,KAAK;AAAA,EACL,SAAS;AAAA,EACT,OAAO;AAAA,EACP,MAAM;AAAA,EACN,WAAW;AAAA,EACX,QAAQ;AAAA,EACR,MAAM;AAAA,EACN,QAAQ;AAAA,EACR,gBAAgB;AAAA,EAChB,OAAO;AAAA,EACP,MAAM;AAAA,EACN,OAAO;AAAA,EACP,UAAU;AAAA,EACV,OAAO;AAAA,EACP,mBAAmB;AAAA,EACnB,QAAQ;AAAA,EACR,QAAQ;;;;;;"}
1
+ {"version":3,"file":"constants.cjs","sources":["../../src/constants.ts"],"sourcesContent":["import type { CustomTypeModelFieldType } from \"@prismicio/client\";\n\nexport const CUSTOM_TYPES_DOCUMENTATION_URL =\n\t\"https://prismic.io/docs/custom-types\";\n\nexport const SHARED_SLICES_DOCUMENTATION_URL = \"https://prismic.io/docs/slice\";\n\nexport const FIELD_DOCUMENTATION_URLS: Record<\n\tExclude<\n\t\t(typeof CustomTypeModelFieldType)[keyof typeof CustomTypeModelFieldType],\n\t\t\"Range\" | \"Separator\"\n\t>,\n\tstring\n> = {\n\tUID: \"https://prismic.io/docs/field#uid\",\n\tBoolean: \"https://prismic.io/docs/field#boolean\",\n\tColor: \"https://prismic.io/docs/field#color\",\n\tDate: \"https://prismic.io/docs/field#date\",\n\tTimestamp: \"https://prismic.io/docs/field#timestamp\",\n\tNumber: \"https://prismic.io/docs/field#number\",\n\tText: \"https://prismic.io/docs/field#key-text\",\n\tSelect: \"https://prismic.io/docs/field#select\",\n\tStructuredText: \"https://prismic.io/docs/field#rich-text-title\",\n\tImage: \"https://prismic.io/docs/field#image\",\n\tLink: \"https://prismic.io/docs/field#link-content-relationship\",\n\tEmbed: \"https://prismic.io/docs/field#embed\",\n\tGeoPoint: \"https://prismic.io/docs/field#geopoint\",\n\tGroup: \"https://prismic.io/docs/field#group\",\n\tIntegrationFields: \"https://prismic.io/docs/field#integration\",\n\tSlices: \"https://prismic.io/docs/field#slices\",\n\tChoice: \"https://prismic.io/docs/field#slices\",\n};\n"],"names":[],"mappings":";;AAEO,MAAM,iCACZ;AAEM,MAAM,kCAAkC;AAExC,MAAM,2BAMT;AAAA,EACH,KAAK;AAAA,EACL,SAAS;AAAA,EACT,OAAO;AAAA,EACP,MAAM;AAAA,EACN,WAAW;AAAA,EACX,QAAQ;AAAA,EACR,MAAM;AAAA,EACN,QAAQ;AAAA,EACR,gBAAgB;AAAA,EAChB,OAAO;AAAA,EACP,MAAM;AAAA,EACN,OAAO;AAAA,EACP,UAAU;AAAA,EACV,OAAO;AAAA,EACP,mBAAmB;AAAA,EACnB,QAAQ;AAAA,EACR,QAAQ;;;;;"}
@@ -1,5 +1,4 @@
1
1
  import type { CustomTypeModelFieldType } from "@prismicio/client";
2
- export declare const BLANK_LINE_IDENTIFIER = "// ___BLANK_LINE_TO_BE_REPLACED___";
3
- export declare const CUSTOM_TYPES_DOCUMENTATION_URL = "https://prismic.io/docs/core-concepts/custom-types";
4
- export declare const SHARED_SLICES_DOCUMENTATION_URL = "https://prismic.io/docs/core-concepts/reusing-slices";
2
+ export declare const CUSTOM_TYPES_DOCUMENTATION_URL = "https://prismic.io/docs/custom-types";
3
+ export declare const SHARED_SLICES_DOCUMENTATION_URL = "https://prismic.io/docs/slice";
5
4
  export declare const FIELD_DOCUMENTATION_URLS: Record<Exclude<(typeof CustomTypeModelFieldType)[keyof typeof CustomTypeModelFieldType], "Range" | "Separator">, string>;
package/dist/constants.js CHANGED
@@ -1,27 +1,25 @@
1
- const BLANK_LINE_IDENTIFIER = "// ___BLANK_LINE_TO_BE_REPLACED___";
2
- const CUSTOM_TYPES_DOCUMENTATION_URL = "https://prismic.io/docs/core-concepts/custom-types";
3
- const SHARED_SLICES_DOCUMENTATION_URL = "https://prismic.io/docs/core-concepts/reusing-slices";
1
+ const CUSTOM_TYPES_DOCUMENTATION_URL = "https://prismic.io/docs/custom-types";
2
+ const SHARED_SLICES_DOCUMENTATION_URL = "https://prismic.io/docs/slice";
4
3
  const FIELD_DOCUMENTATION_URLS = {
5
- UID: "https://prismic.io/docs/core-concepts/uid",
6
- Boolean: "https://prismic.io/docs/core-concepts/boolean",
7
- Color: "https://prismic.io/docs/core-concepts/color",
8
- Date: "https://prismic.io/docs/core-concepts/date",
9
- Timestamp: "https://prismic.io/docs/core-concepts/timestamp",
10
- Number: "https://prismic.io/docs/core-concepts/number",
11
- Text: "https://prismic.io/docs/core-concepts/key-text",
12
- Select: "https://prismic.io/docs/core-concepts/select",
13
- StructuredText: "https://prismic.io/docs/core-concepts/rich-text-title",
14
- Image: "https://prismic.io/docs/core-concepts/image",
15
- Link: "https://prismic.io/docs/core-concepts/link-content-relationship",
16
- Embed: "https://prismic.io/docs/core-concepts/embed",
17
- GeoPoint: "https://prismic.io/docs/core-concepts/geopoint",
18
- Group: "https://prismic.io/docs/core-concepts/group",
19
- IntegrationFields: "https://prismic.io/docs/core-concepts/integration-fields",
20
- Slices: "https://prismic.io/docs/core-concepts/slices",
21
- Choice: "https://prismic.io/docs/core-concepts/slices"
4
+ UID: "https://prismic.io/docs/field#uid",
5
+ Boolean: "https://prismic.io/docs/field#boolean",
6
+ Color: "https://prismic.io/docs/field#color",
7
+ Date: "https://prismic.io/docs/field#date",
8
+ Timestamp: "https://prismic.io/docs/field#timestamp",
9
+ Number: "https://prismic.io/docs/field#number",
10
+ Text: "https://prismic.io/docs/field#key-text",
11
+ Select: "https://prismic.io/docs/field#select",
12
+ StructuredText: "https://prismic.io/docs/field#rich-text-title",
13
+ Image: "https://prismic.io/docs/field#image",
14
+ Link: "https://prismic.io/docs/field#link-content-relationship",
15
+ Embed: "https://prismic.io/docs/field#embed",
16
+ GeoPoint: "https://prismic.io/docs/field#geopoint",
17
+ Group: "https://prismic.io/docs/field#group",
18
+ IntegrationFields: "https://prismic.io/docs/field#integration",
19
+ Slices: "https://prismic.io/docs/field#slices",
20
+ Choice: "https://prismic.io/docs/field#slices"
22
21
  };
23
22
  export {
24
- BLANK_LINE_IDENTIFIER,
25
23
  CUSTOM_TYPES_DOCUMENTATION_URL,
26
24
  FIELD_DOCUMENTATION_URLS,
27
25
  SHARED_SLICES_DOCUMENTATION_URL
@@ -1 +1 @@
1
- {"version":3,"file":"constants.js","sources":["../../src/constants.ts"],"sourcesContent":["import type { CustomTypeModelFieldType } from \"@prismicio/client\";\n\nexport const BLANK_LINE_IDENTIFIER = \"// ___BLANK_LINE_TO_BE_REPLACED___\";\n\nexport const CUSTOM_TYPES_DOCUMENTATION_URL =\n\t\"https://prismic.io/docs/core-concepts/custom-types\";\n\nexport const SHARED_SLICES_DOCUMENTATION_URL =\n\t\"https://prismic.io/docs/core-concepts/reusing-slices\";\n\nexport const FIELD_DOCUMENTATION_URLS: Record<\n\tExclude<\n\t\t(typeof CustomTypeModelFieldType)[keyof typeof CustomTypeModelFieldType],\n\t\t\"Range\" | \"Separator\"\n\t>,\n\tstring\n> = {\n\tUID: \"https://prismic.io/docs/core-concepts/uid\",\n\tBoolean: \"https://prismic.io/docs/core-concepts/boolean\",\n\tColor: \"https://prismic.io/docs/core-concepts/color\",\n\tDate: \"https://prismic.io/docs/core-concepts/date\",\n\tTimestamp: \"https://prismic.io/docs/core-concepts/timestamp\",\n\tNumber: \"https://prismic.io/docs/core-concepts/number\",\n\tText: \"https://prismic.io/docs/core-concepts/key-text\",\n\tSelect: \"https://prismic.io/docs/core-concepts/select\",\n\tStructuredText: \"https://prismic.io/docs/core-concepts/rich-text-title\",\n\tImage: \"https://prismic.io/docs/core-concepts/image\",\n\tLink: \"https://prismic.io/docs/core-concepts/link-content-relationship\",\n\tEmbed: \"https://prismic.io/docs/core-concepts/embed\",\n\tGeoPoint: \"https://prismic.io/docs/core-concepts/geopoint\",\n\tGroup: \"https://prismic.io/docs/core-concepts/group\",\n\tIntegrationFields: \"https://prismic.io/docs/core-concepts/integration-fields\",\n\tSlices: \"https://prismic.io/docs/core-concepts/slices\",\n\tChoice: \"https://prismic.io/docs/core-concepts/slices\",\n};\n"],"names":[],"mappings":"AAEO,MAAM,wBAAwB;AAE9B,MAAM,iCACZ;AAEM,MAAM,kCACZ;AAEM,MAAM,2BAMT;AAAA,EACH,KAAK;AAAA,EACL,SAAS;AAAA,EACT,OAAO;AAAA,EACP,MAAM;AAAA,EACN,WAAW;AAAA,EACX,QAAQ;AAAA,EACR,MAAM;AAAA,EACN,QAAQ;AAAA,EACR,gBAAgB;AAAA,EAChB,OAAO;AAAA,EACP,MAAM;AAAA,EACN,OAAO;AAAA,EACP,UAAU;AAAA,EACV,OAAO;AAAA,EACP,mBAAmB;AAAA,EACnB,QAAQ;AAAA,EACR,QAAQ;;"}
1
+ {"version":3,"file":"constants.js","sources":["../../src/constants.ts"],"sourcesContent":["import type { CustomTypeModelFieldType } from \"@prismicio/client\";\n\nexport const CUSTOM_TYPES_DOCUMENTATION_URL =\n\t\"https://prismic.io/docs/custom-types\";\n\nexport const SHARED_SLICES_DOCUMENTATION_URL = \"https://prismic.io/docs/slice\";\n\nexport const FIELD_DOCUMENTATION_URLS: Record<\n\tExclude<\n\t\t(typeof CustomTypeModelFieldType)[keyof typeof CustomTypeModelFieldType],\n\t\t\"Range\" | \"Separator\"\n\t>,\n\tstring\n> = {\n\tUID: \"https://prismic.io/docs/field#uid\",\n\tBoolean: \"https://prismic.io/docs/field#boolean\",\n\tColor: \"https://prismic.io/docs/field#color\",\n\tDate: \"https://prismic.io/docs/field#date\",\n\tTimestamp: \"https://prismic.io/docs/field#timestamp\",\n\tNumber: \"https://prismic.io/docs/field#number\",\n\tText: \"https://prismic.io/docs/field#key-text\",\n\tSelect: \"https://prismic.io/docs/field#select\",\n\tStructuredText: \"https://prismic.io/docs/field#rich-text-title\",\n\tImage: \"https://prismic.io/docs/field#image\",\n\tLink: \"https://prismic.io/docs/field#link-content-relationship\",\n\tEmbed: \"https://prismic.io/docs/field#embed\",\n\tGeoPoint: \"https://prismic.io/docs/field#geopoint\",\n\tGroup: \"https://prismic.io/docs/field#group\",\n\tIntegrationFields: \"https://prismic.io/docs/field#integration\",\n\tSlices: \"https://prismic.io/docs/field#slices\",\n\tChoice: \"https://prismic.io/docs/field#slices\",\n};\n"],"names":[],"mappings":"AAEO,MAAM,iCACZ;AAEM,MAAM,kCAAkC;AAExC,MAAM,2BAMT;AAAA,EACH,KAAK;AAAA,EACL,SAAS;AAAA,EACT,OAAO;AAAA,EACP,MAAM;AAAA,EACN,WAAW;AAAA,EACX,QAAQ;AAAA,EACR,MAAM;AAAA,EACN,QAAQ;AAAA,EACR,gBAAgB;AAAA,EAChB,OAAO;AAAA,EACP,MAAM;AAAA,EACN,OAAO;AAAA,EACP,UAAU;AAAA,EACV,OAAO;AAAA,EACP,mBAAmB;AAAA,EACnB,QAAQ;AAAA,EACR,QAAQ;;"}
@@ -1,114 +1,95 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const tsMorph = require("ts-morph");
4
- const addTypeAliasForCustomType = require("./lib/addTypeAliasForCustomType.cjs");
5
- const addTypeAliasForSharedSlice = require("./lib/addTypeAliasForSharedSlice.cjs");
6
- const buildTypeName = require("./lib/buildTypeName.cjs");
7
- const getSourceFileText = require("./lib/getSourceFileText.cjs");
8
- const constants = require("./constants.cjs");
9
- const generateTypes = (config = {}) => {
10
- var _a, _b, _c;
11
- const project = new tsMorph.Project({
12
- useInMemoryFileSystem: true
13
- });
14
- const sourceFile = project.createSourceFile("types.d.ts");
3
+ const commonTags = require("common-tags");
4
+ const QuickLRU = require("quick-lru");
5
+ const addLine = require("./lib/addLine.cjs");
6
+ const addSection = require("./lib/addSection.cjs");
7
+ const buildCustomTypeType = require("./lib/buildCustomTypeType.cjs");
8
+ const buildSharedSliceType = require("./lib/buildSharedSliceType.cjs");
9
+ const buildUnion = require("./lib/buildUnion.cjs");
10
+ const cache = new QuickLRU({ maxSize: 1e3 });
11
+ function generateTypes(config = {}) {
12
+ var _a, _b, _c, _d, _e;
13
+ const fieldConfigs = config.fieldConfigs || {};
14
+ const shouldUseCache = config.cache ?? true;
15
+ let code = "";
15
16
  const typesProvider = config.typesProvider || "@prismicio/types";
16
- sourceFile.addImportDeclaration({
17
- moduleSpecifier: typesProvider,
18
- namespaceImport: "prismic",
19
- isTypeOnly: true
20
- });
21
- sourceFile.addStatements(constants.BLANK_LINE_IDENTIFIER);
22
- const simplifyTypeAlias = sourceFile.addTypeAlias({
23
- name: "Simplify",
24
- typeParameters: [
25
- {
26
- name: "T"
27
- }
28
- ],
29
- type: `{ [KeyType in keyof T]: T[KeyType] }`
30
- });
17
+ let clientImportName = "prismic";
18
+ code = addLine.addLine(`import type * as prismic from "${typesProvider}";`, code);
19
+ if (((_a = config.clientIntegration) == null ? void 0 : _a.includeCreateClientInterface) || ((_b = config.clientIntegration) == null ? void 0 : _b.includeContentNamespace)) {
20
+ if (typesProvider !== "@prismicio/client") {
21
+ clientImportName = "prismicClient";
22
+ code = addLine.addLine(`import type * as ${clientImportName} from "@prismicio/client";`, code);
23
+ }
24
+ }
25
+ code = addSection.addSection(`type Simplify<T> = { [KeyType in keyof T]: T[KeyType] };`, code);
26
+ const contentTypeNames = [];
31
27
  if (config.customTypeModels) {
28
+ const allDocumentTypesTypeNames = [];
32
29
  for (const model of config.customTypeModels) {
33
- addTypeAliasForCustomType.addTypeAliasForCustomType({
30
+ const customTypeType = buildCustomTypeType.buildCustomTypeType({
34
31
  model,
35
- sourceFile,
36
- localeIDs: config.localeIDs || [],
37
- fieldConfigs: config.fieldConfigs || {}
32
+ localeIDs: config.localeIDs,
33
+ fieldConfigs,
34
+ cache: shouldUseCache ? cache : void 0
38
35
  });
36
+ for (const auxiliaryType of customTypeType.auxiliaryTypes) {
37
+ code = addSection.addSection(auxiliaryType.code, code);
38
+ }
39
+ code = addSection.addSection(customTypeType.code, code);
40
+ allDocumentTypesTypeNames.push(customTypeType.name);
41
+ contentTypeNames.push(customTypeType.name);
42
+ contentTypeNames.push(customTypeType.dataName);
39
43
  }
40
44
  if (config.customTypeModels.length > 0) {
41
- sourceFile.addTypeAlias({
42
- name: "AllDocumentTypes",
43
- type: config.customTypeModels.map((customTypeModel) => buildTypeName.buildTypeName(customTypeModel.id, "Document")).join(" | "),
44
- isExported: true
45
- });
45
+ const allDocumentTypesUnionName = "AllDocumentTypes";
46
+ const allDocumentTypesUnion = buildUnion.buildUnion(allDocumentTypesTypeNames);
47
+ code = addSection.addSection(`export type ${allDocumentTypesUnionName} = ${allDocumentTypesUnion};`, code);
48
+ contentTypeNames.push(allDocumentTypesUnionName);
46
49
  }
47
50
  }
48
51
  if (config.sharedSliceModels) {
49
52
  for (const model of config.sharedSliceModels) {
50
- addTypeAliasForSharedSlice.addTypeAliasForSharedSlice({
53
+ const sharedSliceType = buildSharedSliceType.buildSharedSliceType({
51
54
  model,
52
- sourceFile,
53
- fieldConfigs: config.fieldConfigs || {}
55
+ fieldConfigs,
56
+ cache: shouldUseCache ? cache : void 0
54
57
  });
58
+ code = addSection.addSection(sharedSliceType.code, code);
59
+ contentTypeNames.push(sharedSliceType.name);
60
+ contentTypeNames.push(sharedSliceType.variationUnionName);
61
+ contentTypeNames.push(...sharedSliceType.variationNames);
55
62
  }
56
63
  }
57
- if (((_a = config.clientIntegration) == null ? void 0 : _a.includeCreateClientInterface) || ((_b = config.clientIntegration) == null ? void 0 : _b.includeContentNamespace)) {
58
- let clientNamespaceImportName = "prismic";
59
- if (typesProvider !== "@prismicio/client") {
60
- clientNamespaceImportName = "prismicClient";
61
- sourceFile.addImportDeclaration({
62
- moduleSpecifier: "@prismicio/client",
63
- namespaceImport: clientNamespaceImportName,
64
- isTypeOnly: true
65
- });
66
- }
67
- const clientModuleDeclaration = sourceFile.addModule({
68
- name: '"@prismicio/client"',
69
- hasDeclareKeyword: true,
70
- declarationKind: tsMorph.ModuleDeclarationKind.Module
71
- });
64
+ if (((_c = config.clientIntegration) == null ? void 0 : _c.includeCreateClientInterface) || ((_d = config.clientIntegration) == null ? void 0 : _d.includeContentNamespace)) {
65
+ let clientModuleCode = "";
72
66
  if (config.clientIntegration.includeCreateClientInterface) {
73
- clientModuleDeclaration.addInterface({
74
- name: "CreateClient",
75
- callSignatures: [
76
- {
77
- parameters: [
78
- {
79
- name: "repositoryNameOrEndpoint",
80
- type: "string"
81
- },
82
- {
83
- name: "options",
84
- type: `${clientNamespaceImportName}.ClientConfig`,
85
- hasQuestionToken: true
86
- }
87
- ],
88
- returnType: (((_c = config.customTypeModels) == null ? void 0 : _c.length) || 0) > 0 ? `${clientNamespaceImportName}.Client<AllDocumentTypes>` : `${clientNamespaceImportName}.Client`
89
- }
90
- ]
91
- });
67
+ if ((((_e = config.customTypeModels) == null ? void 0 : _e.length) || 0) > 0) {
68
+ clientModuleCode = addSection.addSection(`interface CreateClient {
69
+ (repositoryNameOrEndpoint: string, options?: ${clientImportName}.ClientConfig): ${clientImportName}.Client<AllDocumentTypes>;
70
+ }`, clientModuleCode);
71
+ } else {
72
+ clientModuleCode = addSection.addSection(`interface CreateClient {
73
+ (repositoryNameOrEndpoint: string, options?: ${clientImportName}.ClientConfig): ${clientImportName}.Client;
74
+ }`, clientModuleCode);
75
+ }
92
76
  }
93
77
  if (config.clientIntegration.includeContentNamespace) {
94
- const contentNamespaceDeclaration = clientModuleDeclaration.addModule({
95
- name: "Content",
96
- declarationKind: tsMorph.ModuleDeclarationKind.Namespace
97
- });
98
- const exportSymbols = sourceFile.getExportSymbols().filter((exportSymbol) => {
99
- return exportSymbol.getName() !== simplifyTypeAlias.getName();
100
- });
101
- contentNamespaceDeclaration.addExportDeclaration({
102
- isTypeOnly: true,
103
- namedExports: exportSymbols.map((exportSymbol) => {
104
- return {
105
- name: exportSymbol.getName()
106
- };
107
- })
108
- });
78
+ clientModuleCode = addSection.addSection(commonTags.source`
79
+ namespace Content {
80
+ export type {
81
+ ${contentTypeNames.join(",\n")}
82
+ }
83
+ }
84
+ `, clientModuleCode);
109
85
  }
86
+ code = addSection.addSection(commonTags.source`
87
+ declare module "@prismicio/client" {
88
+ ${clientModuleCode}
89
+ }
90
+ `, code);
110
91
  }
111
- return getSourceFileText.getSourceFileText(sourceFile);
112
- };
92
+ return code;
93
+ }
113
94
  exports.generateTypes = generateTypes;
114
95
  //# sourceMappingURL=generateTypes.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"generateTypes.cjs","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":["Project","BLANK_LINE_IDENTIFIER","addTypeAliasForCustomType","buildTypeName","addTypeAliasForSharedSlice","ModuleDeclarationKind","getSourceFileText"],"mappings":";;;;;;;;AA0BO,MAAM,gBAAgB,CAAC,SAA8B,OAAM;;AAC3D,QAAA,UAAU,IAAIA,gBAAQ;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,cAAcC,UAAAA,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;AAClBC,0DAAA;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,oBACLC,cAAAA,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;AAClBC,4DAAA;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,iBAAiBC,QAAsB,sBAAA;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,iBAAiBA,QAAsB,sBAAA;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,SAAOC,kBAAAA,kBAAkB,UAAU;AACpC;;"}
1
+ {"version":3,"file":"generateTypes.cjs","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":["addLine","addSection","buildCustomTypeType","buildUnion","buildSharedSliceType","source"],"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,SAAAA,QAAA,QAAQ,kCAAkC,mBAAmB,IAAI;AAExE,QACC,YAAO,sBAAP,mBAA0B,mCAC1B,YAAO,sBAAP,mBAA0B,0BACzB;AACD,QAAI,kBAAkB,qBAAqB;AACvB,yBAAA;AAIZ,aAAAA,QAAA,QACN,oBAAoB,8CACpB,IAAI;AAAA,IAEL;AAAA,EACD;AAEM,SAAAC,WAAAA,WACN,4DACA,IAAI;AAGL,QAAM,mBAA6B,CAAA;AAEnC,MAAI,OAAO,kBAAkB;AAC5B,UAAM,4BAAsC,CAAA;AAEjC,eAAA,SAAS,OAAO,kBAAkB;AAC5C,YAAM,iBAAiBC,oBAAAA,oBAAoB;AAAA,QAC1C;AAAA,QACA,WAAW,OAAO;AAAA,QAClB;AAAA,QACA,OAAO,iBAAiB,QAAQ;AAAA,MAAA,CAChC;AAEU,iBAAA,iBAAiB,eAAe,gBAAgB;AACnD,eAAAD,WAAAA,WAAW,cAAc,MAAM,IAAI;AAAA,MAC1C;AAEM,aAAAA,WAAAA,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,wBAAwBE,sBAAW,yBAAyB;AAElE,aAAOF,WAAAA,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,kBAAkBG,qBAAAA,qBAAqB;AAAA,QAC5C;AAAA,QACA;AAAA,QACA,OAAO,iBAAiB,QAAQ;AAAA,MAAA,CAChC;AAEM,aAAAH,WAAAA,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,2BAAmBA,WAClB,WAAA;AAAA,gDAC2C,mCAAmC;AAAA,IAE9E,gBAAgB;AAAA,MAAA,OAEX;AACN,2BAAmBA,WAClB,WAAA;AAAA,gDAC2C,mCAAmC;AAAA,IAE9E,gBAAgB;AAAA,MAEjB;AAAA,IACD;AAEG,QAAA,OAAO,kBAAkB,yBAAyB;AACrD,yBAAmBA,WAClB,WAAAI;;;SAGK,iBAAiB,KAAK,KAAK;AAAA;AAAA;AAAA,OAIhC,gBAAgB;AAAA,IAEjB;AAED,WAAOJ,WACN,WAAAI;;OAEI;AAAA;AAAA,MAGJ,IAAI;AAAA,EAEL;AAEM,SAAA;AACR;;"}
@@ -11,5 +11,6 @@ export type GenerateTypesConfig = {
11
11
  includeCreateClientInterface?: boolean;
12
12
  includeContentNamespace?: boolean;
13
13
  };
14
+ cache?: boolean;
14
15
  };
15
- export declare const generateTypes: (config?: GenerateTypesConfig) => string;
16
+ export declare function generateTypes(config?: GenerateTypesConfig): string;
@@ -1,113 +1,94 @@
1
- import { Project, ModuleDeclarationKind } from "ts-morph";
2
- import { addTypeAliasForCustomType } from "./lib/addTypeAliasForCustomType.js";
3
- import { addTypeAliasForSharedSlice } from "./lib/addTypeAliasForSharedSlice.js";
4
- import { buildTypeName } from "./lib/buildTypeName.js";
5
- import { getSourceFileText } from "./lib/getSourceFileText.js";
6
- import { BLANK_LINE_IDENTIFIER } from "./constants.js";
7
- const generateTypes = (config = {}) => {
8
- var _a, _b, _c;
9
- const project = new Project({
10
- useInMemoryFileSystem: true
11
- });
12
- const sourceFile = project.createSourceFile("types.d.ts");
1
+ import { source } from "common-tags";
2
+ import QuickLRU from "quick-lru";
3
+ import { addLine } from "./lib/addLine.js";
4
+ import { addSection } from "./lib/addSection.js";
5
+ import { buildCustomTypeType } from "./lib/buildCustomTypeType.js";
6
+ import { buildSharedSliceType } from "./lib/buildSharedSliceType.js";
7
+ import { buildUnion } from "./lib/buildUnion.js";
8
+ const cache = new QuickLRU({ maxSize: 1e3 });
9
+ function generateTypes(config = {}) {
10
+ var _a, _b, _c, _d, _e;
11
+ const fieldConfigs = config.fieldConfigs || {};
12
+ const shouldUseCache = config.cache ?? true;
13
+ let code = "";
13
14
  const typesProvider = config.typesProvider || "@prismicio/types";
14
- sourceFile.addImportDeclaration({
15
- moduleSpecifier: typesProvider,
16
- namespaceImport: "prismic",
17
- isTypeOnly: true
18
- });
19
- sourceFile.addStatements(BLANK_LINE_IDENTIFIER);
20
- const simplifyTypeAlias = sourceFile.addTypeAlias({
21
- name: "Simplify",
22
- typeParameters: [
23
- {
24
- name: "T"
25
- }
26
- ],
27
- type: `{ [KeyType in keyof T]: T[KeyType] }`
28
- });
15
+ let clientImportName = "prismic";
16
+ code = addLine(`import type * as prismic from "${typesProvider}";`, code);
17
+ if (((_a = config.clientIntegration) == null ? void 0 : _a.includeCreateClientInterface) || ((_b = config.clientIntegration) == null ? void 0 : _b.includeContentNamespace)) {
18
+ if (typesProvider !== "@prismicio/client") {
19
+ clientImportName = "prismicClient";
20
+ code = addLine(`import type * as ${clientImportName} from "@prismicio/client";`, code);
21
+ }
22
+ }
23
+ code = addSection(`type Simplify<T> = { [KeyType in keyof T]: T[KeyType] };`, code);
24
+ const contentTypeNames = [];
29
25
  if (config.customTypeModels) {
26
+ const allDocumentTypesTypeNames = [];
30
27
  for (const model of config.customTypeModels) {
31
- addTypeAliasForCustomType({
28
+ const customTypeType = buildCustomTypeType({
32
29
  model,
33
- sourceFile,
34
- localeIDs: config.localeIDs || [],
35
- fieldConfigs: config.fieldConfigs || {}
30
+ localeIDs: config.localeIDs,
31
+ fieldConfigs,
32
+ cache: shouldUseCache ? cache : void 0
36
33
  });
34
+ for (const auxiliaryType of customTypeType.auxiliaryTypes) {
35
+ code = addSection(auxiliaryType.code, code);
36
+ }
37
+ code = addSection(customTypeType.code, code);
38
+ allDocumentTypesTypeNames.push(customTypeType.name);
39
+ contentTypeNames.push(customTypeType.name);
40
+ contentTypeNames.push(customTypeType.dataName);
37
41
  }
38
42
  if (config.customTypeModels.length > 0) {
39
- sourceFile.addTypeAlias({
40
- name: "AllDocumentTypes",
41
- type: config.customTypeModels.map((customTypeModel) => buildTypeName(customTypeModel.id, "Document")).join(" | "),
42
- isExported: true
43
- });
43
+ const allDocumentTypesUnionName = "AllDocumentTypes";
44
+ const allDocumentTypesUnion = buildUnion(allDocumentTypesTypeNames);
45
+ code = addSection(`export type ${allDocumentTypesUnionName} = ${allDocumentTypesUnion};`, code);
46
+ contentTypeNames.push(allDocumentTypesUnionName);
44
47
  }
45
48
  }
46
49
  if (config.sharedSliceModels) {
47
50
  for (const model of config.sharedSliceModels) {
48
- addTypeAliasForSharedSlice({
51
+ const sharedSliceType = buildSharedSliceType({
49
52
  model,
50
- sourceFile,
51
- fieldConfigs: config.fieldConfigs || {}
53
+ fieldConfigs,
54
+ cache: shouldUseCache ? cache : void 0
52
55
  });
56
+ code = addSection(sharedSliceType.code, code);
57
+ contentTypeNames.push(sharedSliceType.name);
58
+ contentTypeNames.push(sharedSliceType.variationUnionName);
59
+ contentTypeNames.push(...sharedSliceType.variationNames);
53
60
  }
54
61
  }
55
- if (((_a = config.clientIntegration) == null ? void 0 : _a.includeCreateClientInterface) || ((_b = config.clientIntegration) == null ? void 0 : _b.includeContentNamespace)) {
56
- let clientNamespaceImportName = "prismic";
57
- if (typesProvider !== "@prismicio/client") {
58
- clientNamespaceImportName = "prismicClient";
59
- sourceFile.addImportDeclaration({
60
- moduleSpecifier: "@prismicio/client",
61
- namespaceImport: clientNamespaceImportName,
62
- isTypeOnly: true
63
- });
64
- }
65
- const clientModuleDeclaration = sourceFile.addModule({
66
- name: '"@prismicio/client"',
67
- hasDeclareKeyword: true,
68
- declarationKind: ModuleDeclarationKind.Module
69
- });
62
+ if (((_c = config.clientIntegration) == null ? void 0 : _c.includeCreateClientInterface) || ((_d = config.clientIntegration) == null ? void 0 : _d.includeContentNamespace)) {
63
+ let clientModuleCode = "";
70
64
  if (config.clientIntegration.includeCreateClientInterface) {
71
- clientModuleDeclaration.addInterface({
72
- name: "CreateClient",
73
- callSignatures: [
74
- {
75
- parameters: [
76
- {
77
- name: "repositoryNameOrEndpoint",
78
- type: "string"
79
- },
80
- {
81
- name: "options",
82
- type: `${clientNamespaceImportName}.ClientConfig`,
83
- hasQuestionToken: true
84
- }
85
- ],
86
- returnType: (((_c = config.customTypeModels) == null ? void 0 : _c.length) || 0) > 0 ? `${clientNamespaceImportName}.Client<AllDocumentTypes>` : `${clientNamespaceImportName}.Client`
87
- }
88
- ]
89
- });
65
+ if ((((_e = config.customTypeModels) == null ? void 0 : _e.length) || 0) > 0) {
66
+ clientModuleCode = addSection(`interface CreateClient {
67
+ (repositoryNameOrEndpoint: string, options?: ${clientImportName}.ClientConfig): ${clientImportName}.Client<AllDocumentTypes>;
68
+ }`, clientModuleCode);
69
+ } else {
70
+ clientModuleCode = addSection(`interface CreateClient {
71
+ (repositoryNameOrEndpoint: string, options?: ${clientImportName}.ClientConfig): ${clientImportName}.Client;
72
+ }`, clientModuleCode);
73
+ }
90
74
  }
91
75
  if (config.clientIntegration.includeContentNamespace) {
92
- const contentNamespaceDeclaration = clientModuleDeclaration.addModule({
93
- name: "Content",
94
- declarationKind: ModuleDeclarationKind.Namespace
95
- });
96
- const exportSymbols = sourceFile.getExportSymbols().filter((exportSymbol) => {
97
- return exportSymbol.getName() !== simplifyTypeAlias.getName();
98
- });
99
- contentNamespaceDeclaration.addExportDeclaration({
100
- isTypeOnly: true,
101
- namedExports: exportSymbols.map((exportSymbol) => {
102
- return {
103
- name: exportSymbol.getName()
104
- };
105
- })
106
- });
76
+ clientModuleCode = addSection(source`
77
+ namespace Content {
78
+ export type {
79
+ ${contentTypeNames.join(",\n")}
80
+ }
81
+ }
82
+ `, clientModuleCode);
107
83
  }
84
+ code = addSection(source`
85
+ declare module "@prismicio/client" {
86
+ ${clientModuleCode}
87
+ }
88
+ `, code);
108
89
  }
109
- return getSourceFileText(sourceFile);
110
- };
90
+ return code;
91
+ }
111
92
  export {
112
93
  generateTypes
113
94
  };