prismic-ts-codegen 0.1.11 → 0.1.13

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 (202) hide show
  1. package/dist/_node_modules/quick-lru/index.cjs +234 -0
  2. package/dist/_node_modules/quick-lru/index.cjs.map +1 -0
  3. package/dist/_node_modules/quick-lru/index.js +235 -0
  4. package/dist/_node_modules/quick-lru/index.js.map +1 -0
  5. package/dist/constants.cjs +19 -21
  6. package/dist/constants.cjs.map +1 -1
  7. package/dist/constants.d.ts +2 -3
  8. package/dist/constants.js +19 -21
  9. package/dist/constants.js.map +1 -1
  10. package/dist/generateTypes.cjs +71 -90
  11. package/dist/generateTypes.cjs.map +1 -1
  12. package/dist/generateTypes.d.ts +2 -1
  13. package/dist/generateTypes.js +71 -90
  14. package/dist/generateTypes.js.map +1 -1
  15. package/dist/lib/addBlankLine.cjs +12 -0
  16. package/dist/lib/addBlankLine.cjs.map +1 -0
  17. package/dist/lib/addBlankLine.d.ts +5 -0
  18. package/dist/lib/addBlankLine.js +12 -0
  19. package/dist/lib/addBlankLine.js.map +1 -0
  20. package/dist/lib/addLine.cjs +8 -0
  21. package/dist/lib/addLine.cjs.map +1 -0
  22. package/dist/lib/addLine.d.ts +1 -0
  23. package/dist/lib/addLine.js +8 -0
  24. package/dist/lib/addLine.js.map +1 -0
  25. package/dist/lib/addSection.cjs +8 -0
  26. package/dist/lib/addSection.cjs.map +1 -0
  27. package/dist/lib/addSection.d.ts +1 -0
  28. package/dist/lib/addSection.js +8 -0
  29. package/dist/lib/addSection.js.map +1 -0
  30. package/dist/lib/addTrailingNewLine.cjs +11 -0
  31. package/dist/lib/addTrailingNewLine.cjs.map +1 -0
  32. package/dist/lib/addTrailingNewLine.d.ts +5 -0
  33. package/dist/lib/addTrailingNewLine.js +11 -0
  34. package/dist/lib/addTrailingNewLine.js.map +1 -0
  35. package/dist/lib/buildCustomTypeDataType.cjs +51 -0
  36. package/dist/lib/buildCustomTypeDataType.cjs.map +1 -0
  37. package/dist/lib/buildCustomTypeDataType.d.ts +13 -0
  38. package/dist/lib/buildCustomTypeDataType.js +51 -0
  39. package/dist/lib/buildCustomTypeDataType.js.map +1 -0
  40. package/dist/lib/buildCustomTypeType.cjs +60 -0
  41. package/dist/lib/buildCustomTypeType.cjs.map +1 -0
  42. package/dist/lib/buildCustomTypeType.d.ts +17 -0
  43. package/dist/lib/buildCustomTypeType.js +60 -0
  44. package/dist/lib/buildCustomTypeType.js.map +1 -0
  45. package/dist/lib/buildFieldDocs.cjs +67 -35
  46. package/dist/lib/buildFieldDocs.cjs.map +1 -1
  47. package/dist/lib/buildFieldDocs.d.ts +7 -11
  48. package/dist/lib/buildFieldDocs.js +67 -35
  49. package/dist/lib/buildFieldDocs.js.map +1 -1
  50. package/dist/lib/buildFieldProperties.cjs +300 -0
  51. package/dist/lib/buildFieldProperties.cjs.map +1 -0
  52. package/dist/lib/buildFieldProperties.d.ts +14 -0
  53. package/dist/lib/buildFieldProperties.js +300 -0
  54. package/dist/lib/buildFieldProperties.js.map +1 -0
  55. package/dist/lib/buildSharedSliceType.cjs +140 -0
  56. package/dist/lib/buildSharedSliceType.cjs.map +1 -0
  57. package/dist/lib/buildSharedSliceType.d.ts +16 -0
  58. package/dist/lib/buildSharedSliceType.js +140 -0
  59. package/dist/lib/buildSharedSliceType.js.map +1 -0
  60. package/dist/lib/buildTypeName.cjs +4 -2
  61. package/dist/lib/buildTypeName.cjs.map +1 -1
  62. package/dist/lib/buildTypeName.js +4 -2
  63. package/dist/lib/buildTypeName.js.map +1 -1
  64. package/dist/lib/buildUnion.cjs +7 -0
  65. package/dist/lib/buildUnion.cjs.map +1 -0
  66. package/dist/lib/buildUnion.d.ts +1 -0
  67. package/dist/lib/buildUnion.js +7 -0
  68. package/dist/lib/buildUnion.js.map +1 -0
  69. package/dist/lib/checkHasUIDFIeld.cjs +7 -0
  70. package/dist/lib/checkHasUIDFIeld.cjs.map +1 -0
  71. package/dist/lib/checkHasUIDFIeld.d.ts +2 -0
  72. package/dist/lib/checkHasUIDFIeld.js +7 -0
  73. package/dist/lib/checkHasUIDFIeld.js.map +1 -0
  74. package/dist/lib/getAPIIDPath.cjs +18 -14
  75. package/dist/lib/getAPIIDPath.cjs.map +1 -1
  76. package/dist/lib/getAPIIDPath.d.ts +4 -8
  77. package/dist/lib/getAPIIDPath.js +18 -14
  78. package/dist/lib/getAPIIDPath.js.map +1 -1
  79. package/dist/lib/getCacheKey.cjs +25 -0
  80. package/dist/lib/getCacheKey.cjs.map +1 -0
  81. package/dist/lib/getCacheKey.d.ts +9 -0
  82. package/dist/lib/getCacheKey.js +8 -0
  83. package/dist/lib/getCacheKey.js.map +1 -0
  84. package/dist/lib/getHumanReadableModelName.cjs +13 -17
  85. package/dist/lib/getHumanReadableModelName.cjs.map +1 -1
  86. package/dist/lib/getHumanReadableModelName.d.ts +3 -3
  87. package/dist/lib/getHumanReadableModelName.js +13 -17
  88. package/dist/lib/getHumanReadableModelName.js.map +1 -1
  89. package/dist/lib/{getHumanReadableFieldPath.cjs → getHumanReadablePath.cjs} +8 -8
  90. package/dist/lib/getHumanReadablePath.cjs.map +1 -0
  91. package/dist/lib/getHumanReadablePath.d.ts +6 -0
  92. package/dist/lib/{getHumanReadableFieldPath.js → getHumanReadablePath.js} +8 -8
  93. package/dist/lib/getHumanReadablePath.js.map +1 -0
  94. package/dist/types.d.ts +9 -1
  95. package/package.json +18 -17
  96. package/src/constants.ts +19 -22
  97. package/src/generateTypes.ts +109 -108
  98. package/src/lib/addBlankLine.ts +13 -0
  99. package/src/lib/addLine.ts +5 -0
  100. package/src/lib/addSection.ts +5 -0
  101. package/src/lib/addTrailingNewLine.ts +14 -0
  102. package/src/lib/buildCustomTypeDataType.ts +74 -0
  103. package/src/lib/buildCustomTypeType.ts +101 -0
  104. package/src/lib/buildFieldDocs.ts +128 -68
  105. package/src/lib/buildFieldProperties.ts +513 -0
  106. package/src/lib/buildSharedSliceType.ts +213 -0
  107. package/src/lib/buildTypeName.ts +4 -2
  108. package/src/lib/buildUnion.ts +3 -0
  109. package/src/lib/checkHasUIDFIeld.ts +5 -0
  110. package/src/lib/getAPIIDPath.ts +40 -41
  111. package/src/lib/getCacheKey.ts +13 -0
  112. package/src/lib/getHumanReadableModelName.ts +23 -20
  113. package/src/lib/getHumanReadablePath.ts +24 -0
  114. package/src/types.ts +11 -1
  115. package/dist/lib/addInterfacePropertiesForFields.cjs +0 -489
  116. package/dist/lib/addInterfacePropertiesForFields.cjs.map +0 -1
  117. package/dist/lib/addInterfacePropertiesForFields.d.ts +0 -21
  118. package/dist/lib/addInterfacePropertiesForFields.js +0 -489
  119. package/dist/lib/addInterfacePropertiesForFields.js.map +0 -1
  120. package/dist/lib/addTypeAliasForCustomType.cjs +0 -81
  121. package/dist/lib/addTypeAliasForCustomType.cjs.map +0 -1
  122. package/dist/lib/addTypeAliasForCustomType.d.ts +0 -11
  123. package/dist/lib/addTypeAliasForCustomType.js +0 -81
  124. package/dist/lib/addTypeAliasForCustomType.js.map +0 -1
  125. package/dist/lib/addTypeAliasForSharedSlice.cjs +0 -149
  126. package/dist/lib/addTypeAliasForSharedSlice.cjs.map +0 -1
  127. package/dist/lib/addTypeAliasForSharedSlice.d.ts +0 -10
  128. package/dist/lib/addTypeAliasForSharedSlice.js +0 -149
  129. package/dist/lib/addTypeAliasForSharedSlice.js.map +0 -1
  130. package/dist/lib/buildSharedSliceInterfaceNamePart.cjs +0 -8
  131. package/dist/lib/buildSharedSliceInterfaceNamePart.cjs.map +0 -1
  132. package/dist/lib/buildSharedSliceInterfaceNamePart.d.ts +0 -5
  133. package/dist/lib/buildSharedSliceInterfaceNamePart.js +0 -8
  134. package/dist/lib/buildSharedSliceInterfaceNamePart.js.map +0 -1
  135. package/dist/lib/getFieldDocumentationURL.cjs +0 -8
  136. package/dist/lib/getFieldDocumentationURL.cjs.map +0 -1
  137. package/dist/lib/getFieldDocumentationURL.d.ts +0 -6
  138. package/dist/lib/getFieldDocumentationURL.js +0 -8
  139. package/dist/lib/getFieldDocumentationURL.js.map +0 -1
  140. package/dist/lib/getHumanReadableFieldPath.cjs.map +0 -1
  141. package/dist/lib/getHumanReadableFieldPath.d.ts +0 -10
  142. package/dist/lib/getHumanReadableFieldPath.js.map +0 -1
  143. package/dist/lib/getHumanReadableFieldType.cjs +0 -36
  144. package/dist/lib/getHumanReadableFieldType.cjs.map +0 -1
  145. package/dist/lib/getHumanReadableFieldType.d.ts +0 -6
  146. package/dist/lib/getHumanReadableFieldType.js +0 -36
  147. package/dist/lib/getHumanReadableFieldType.js.map +0 -1
  148. package/dist/lib/getSourceFileText.cjs +0 -9
  149. package/dist/lib/getSourceFileText.cjs.map +0 -1
  150. package/dist/lib/getSourceFileText.d.ts +0 -2
  151. package/dist/lib/getSourceFileText.js +0 -9
  152. package/dist/lib/getSourceFileText.js.map +0 -1
  153. package/dist/lib/hasOwnProperty.cjs +0 -7
  154. package/dist/lib/hasOwnProperty.cjs.map +0 -1
  155. package/dist/lib/hasOwnProperty.d.ts +0 -10
  156. package/dist/lib/hasOwnProperty.js +0 -7
  157. package/dist/lib/hasOwnProperty.js.map +0 -1
  158. package/dist/lib/isCustomTypeModel.cjs +0 -7
  159. package/dist/lib/isCustomTypeModel.cjs.map +0 -1
  160. package/dist/lib/isCustomTypeModel.d.ts +0 -2
  161. package/dist/lib/isCustomTypeModel.js +0 -7
  162. package/dist/lib/isCustomTypeModel.js.map +0 -1
  163. package/dist/lib/isCustomTypeModelField.cjs +0 -7
  164. package/dist/lib/isCustomTypeModelField.cjs.map +0 -1
  165. package/dist/lib/isCustomTypeModelField.d.ts +0 -2
  166. package/dist/lib/isCustomTypeModelField.js +0 -7
  167. package/dist/lib/isCustomTypeModelField.js.map +0 -1
  168. package/dist/lib/isCustomTypeModelSlice.cjs +0 -8
  169. package/dist/lib/isCustomTypeModelSlice.cjs.map +0 -1
  170. package/dist/lib/isCustomTypeModelSlice.d.ts +0 -2
  171. package/dist/lib/isCustomTypeModelSlice.js +0 -8
  172. package/dist/lib/isCustomTypeModelSlice.js.map +0 -1
  173. package/dist/lib/isSharedSliceModel.cjs +0 -8
  174. package/dist/lib/isSharedSliceModel.cjs.map +0 -1
  175. package/dist/lib/isSharedSliceModel.d.ts +0 -2
  176. package/dist/lib/isSharedSliceModel.js +0 -8
  177. package/dist/lib/isSharedSliceModel.js.map +0 -1
  178. package/dist/lib/pascalCase.cjs +0 -8
  179. package/dist/lib/pascalCase.cjs.map +0 -1
  180. package/dist/lib/pascalCase.d.ts +0 -1
  181. package/dist/lib/pascalCase.js +0 -8
  182. package/dist/lib/pascalCase.js.map +0 -1
  183. package/dist/lib/writeFieldDocsDescription.cjs +0 -29
  184. package/dist/lib/writeFieldDocsDescription.cjs.map +0 -1
  185. package/dist/lib/writeFieldDocsDescription.d.ts +0 -13
  186. package/dist/lib/writeFieldDocsDescription.js +0 -29
  187. package/dist/lib/writeFieldDocsDescription.js.map +0 -1
  188. package/src/lib/addInterfacePropertiesForFields.ts +0 -665
  189. package/src/lib/addTypeAliasForCustomType.ts +0 -120
  190. package/src/lib/addTypeAliasForSharedSlice.ts +0 -201
  191. package/src/lib/buildSharedSliceInterfaceNamePart.ts +0 -11
  192. package/src/lib/getFieldDocumentationURL.ts +0 -15
  193. package/src/lib/getHumanReadableFieldPath.ts +0 -36
  194. package/src/lib/getHumanReadableFieldType.ts +0 -55
  195. package/src/lib/getSourceFileText.ts +0 -14
  196. package/src/lib/hasOwnProperty.ts +0 -15
  197. package/src/lib/isCustomTypeModel.ts +0 -5
  198. package/src/lib/isCustomTypeModelField.ts +0 -7
  199. package/src/lib/isCustomTypeModelSlice.ts +0 -14
  200. package/src/lib/isSharedSliceModel.ts +0 -14
  201. package/src/lib/pascalCase.ts +0 -9
  202. package/src/lib/writeFieldDocsDescription.ts +0 -51
@@ -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
@@ -1 +1 @@
1
- {"version":3,"file":"buildFieldDocs.cjs","sources":["../../../src/lib/buildFieldDocs.ts"],"sourcesContent":["import type {\n\tCustomTypeModel,\n\tCustomTypeModelField,\n\tCustomTypeModelSlice,\n\tSharedSliceModel,\n} from \"@prismicio/client\";\nimport type { JSDocableNodeStructure } from \"ts-morph\";\n\nimport { PathElement } from \"../types\";\n\nimport { getAPIIDPath } from \"./getAPIIDPath\";\nimport { getFieldDocumentationURL } from \"./getFieldDocumentationURL\";\nimport { getHumanReadableFieldPath } from \"./getHumanReadableFieldPath\";\nimport { getHumanReadableFieldType } from \"./getHumanReadableFieldType\";\nimport { getHumanReadableModelName } from \"./getHumanReadableModelName\";\nimport { writeFieldDocsDescription } from \"./writeFieldDocsDescription\";\n\ntype BuildFieldDocsConfig = {\n\tid: string;\n\tmodel: CustomTypeModelField;\n\tpath: [\n\t\tPathElement<CustomTypeModel | SharedSliceModel>,\n\t\t...PathElement<CustomTypeModelField | CustomTypeModelSlice>[],\n\t];\n\ttabName?: string;\n};\n\nexport const buildFieldDocs = (\n\tconfig: BuildFieldDocsConfig,\n): NonNullable<JSDocableNodeStructure[\"docs\"]> => {\n\treturn [\n\t\t{\n\t\t\tdescription: (writer) => {\n\t\t\t\tconst name = getHumanReadableModelName({\n\t\t\t\t\tid: config.id,\n\t\t\t\t\tmodel: config.model,\n\t\t\t\t});\n\t\t\t\tconst humanReadablePath = getHumanReadableFieldPath({\n\t\t\t\t\tpath: config.path,\n\t\t\t\t});\n\n\t\t\t\tconst fieldType = getHumanReadableFieldType({\n\t\t\t\t\tmodel: config.model,\n\t\t\t\t});\n\n\t\t\t\tconst placeholder =\n\t\t\t\t\tconfig.model.config &&\n\t\t\t\t\t\"placeholder\" in config.model.config &&\n\t\t\t\t\tconfig.model.config.placeholder\n\t\t\t\t\t\t? config.model.config.placeholder\n\t\t\t\t\t\t: `*None*`;\n\n\t\t\t\tconst defaultValue =\n\t\t\t\t\tconfig.model.config && \"default_value\" in config.model.config\n\t\t\t\t\t\t? config.model.config.default_value\n\t\t\t\t\t\t: undefined;\n\n\t\t\t\tconst apiIDPath = getAPIIDPath({\n\t\t\t\t\tpath: [...config.path, { id: config.id, model: config.model }],\n\t\t\t\t});\n\n\t\t\t\twriteFieldDocsDescription({\n\t\t\t\t\twriter,\n\t\t\t\t\tdescription: `${name} field in *${humanReadablePath}*`,\n\t\t\t\t\tfieldType,\n\t\t\t\t\tplaceholder,\n\t\t\t\t\tdefaultValue,\n\t\t\t\t\tapiIDPath,\n\t\t\t\t\ttabName: config.tabName,\n\t\t\t\t\tdocumentationURL: getFieldDocumentationURL({ model: config.model }),\n\t\t\t\t});\n\t\t\t},\n\t\t},\n\t];\n};\n"],"names":["getHumanReadableModelName","getHumanReadableFieldPath","getHumanReadableFieldType","getAPIIDPath","writeFieldDocsDescription","getFieldDocumentationURL"],"mappings":";;;;;;;;AA2Ba,MAAA,iBAAiB,CAC7B,WACgD;AACzC,SAAA;AAAA,IACN;AAAA,MACC,aAAa,CAAC,WAAU;AACvB,cAAM,OAAOA,0BAAAA,0BAA0B;AAAA,UACtC,IAAI,OAAO;AAAA,UACX,OAAO,OAAO;AAAA,QAAA,CACd;AACD,cAAM,oBAAoBC,0BAAAA,0BAA0B;AAAA,UACnD,MAAM,OAAO;AAAA,QAAA,CACb;AAED,cAAM,YAAYC,0BAAAA,0BAA0B;AAAA,UAC3C,OAAO,OAAO;AAAA,QAAA,CACd;AAED,cAAM,cACL,OAAO,MAAM,UACb,iBAAiB,OAAO,MAAM,UAC9B,OAAO,MAAM,OAAO,cACjB,OAAO,MAAM,OAAO,cACpB;AAEE,cAAA,eACL,OAAO,MAAM,UAAU,mBAAmB,OAAO,MAAM,SACpD,OAAO,MAAM,OAAO,gBACpB;AAEJ,cAAM,YAAYC,aAAAA,aAAa;AAAA,UAC9B,MAAM,CAAC,GAAG,OAAO,MAAM,EAAE,IAAI,OAAO,IAAI,OAAO,OAAO,MAAA,CAAO;AAAA,QAAA,CAC7D;AAEyBC,4DAAA;AAAA,UACzB;AAAA,UACA,aAAa,GAAG,kBAAkB;AAAA,UAClC;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA,SAAS,OAAO;AAAA,UAChB,kBAAkBC,yBAAAA,yBAAyB,EAAE,OAAO,OAAO,OAAO;AAAA,QAAA,CAClE;AAAA,MACF;AAAA,IACA;AAAA,EAAA;AAEH;;"}
1
+ {"version":3,"file":"buildFieldDocs.cjs","sources":["../../../src/lib/buildFieldDocs.ts"],"sourcesContent":["import { CustomTypeModelField } from \"@prismicio/client\";\n\nimport { FieldPath } from \"../types\";\n\nimport { FIELD_DOCUMENTATION_URLS } from \"../constants\";\n\nimport { addLine } from \"./addLine\";\nimport { getAPIIDPath } from \"./getAPIIDPath\";\nimport { getHumanReadableModelName } from \"./getHumanReadableModelName\";\nimport { getHumanReadablePath } from \"./getHumanReadablePath\";\n\ntype GetFieldHumanReadableTypeArgs = {\n\tfield: CustomTypeModelField;\n};\n\nfunction getHumanReadableFieldType(\n\targs: GetFieldHumanReadableTypeArgs,\n): string {\n\tswitch (args.field.type) {\n\t\tcase \"StructuredText\": {\n\t\t\tconst isTitleField =\n\t\t\t\targs.field.config &&\n\t\t\t\t\"single\" in args.field.config &&\n\t\t\t\targs.field.config.single &&\n\t\t\t\targs.field.config.single\n\t\t\t\t\t.split(\",\")\n\t\t\t\t\t.every((blockType) => /heading/.test(blockType));\n\n\t\t\treturn isTitleField ? \"Title\" : \"Rich Text\";\n\t\t}\n\n\t\tcase \"IntegrationFields\": {\n\t\t\tconst catalog = args.field.config?.catalog;\n\n\t\t\treturn `Integration Fields (Catalog: ${\n\t\t\t\tcatalog ? `\\`${catalog}\\`` : \"*unknown*\"\n\t\t\t})`;\n\t\t}\n\n\t\tcase \"Link\": {\n\t\t\tswitch (args.field.config?.select) {\n\t\t\t\tcase \"document\": {\n\t\t\t\t\treturn \"Content Relationship\";\n\t\t\t\t}\n\n\t\t\t\tcase \"media\": {\n\t\t\t\t\treturn \"Link to Media\";\n\t\t\t\t}\n\n\t\t\t\tdefault: {\n\t\t\t\t\treturn \"Link\";\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tcase \"Slices\": {\n\t\t\treturn \"Slice Zone\";\n\t\t}\n\n\t\tdefault: {\n\t\t\treturn args.field.type;\n\t\t}\n\t}\n}\n\ntype BuildFieldDocsArgs = {\n\tname: string;\n\tfield: CustomTypeModelField;\n\tpath: FieldPath;\n\ttabName?: string;\n};\n\nexport function buildFieldDocs(args: BuildFieldDocsArgs): string {\n\tlet result = \"/**\";\n\n\tconst humanReadableName = getHumanReadableModelName({\n\t\tmodel: args.field,\n\t\tname: args.name,\n\t});\n\tconst humanReadablePath = getHumanReadablePath({ path: args.path });\n\tconst humanReadableFieldType = getHumanReadableFieldType({\n\t\tfield: args.field,\n\t});\n\n\tresult = addLine(\n\t\t` * ${humanReadableName} field in *${humanReadablePath}*`,\n\t\tresult,\n\t);\n\n\tresult = addLine(\" *\", result);\n\n\tresult = addLine(` * - **Field Type**: ${humanReadableFieldType}`, result);\n\n\tconst placeholder =\n\t\t(args.field.config &&\n\t\t\t\"placeholder\" in args.field.config &&\n\t\t\targs.field.config.placeholder) ||\n\t\t`*None*`;\n\tresult = addLine(` * - **Placeholder**: ${placeholder}`, result);\n\n\tconst defaultValue =\n\t\targs.field.config && \"default_value\" in args.field.config\n\t\t\t? args.field.config.default_value\n\t\t\t: undefined;\n\tif (defaultValue !== undefined) {\n\t\tconst stringifiedDefaultValue =\n\t\t\ttypeof defaultValue === \"boolean\" ? `${defaultValue}` : defaultValue;\n\n\t\tresult = addLine(\n\t\t\t` * - **Default Value**: ${stringifiedDefaultValue}`,\n\t\t\tresult,\n\t\t);\n\t}\n\n\tconst apiIDPath = getAPIIDPath({\n\t\tpath: [...args.path, { name: args.name, model: args.field }],\n\t});\n\tresult = addLine(` * - **API ID Path**: ${apiIDPath}`, result);\n\n\tif (args.tabName) {\n\t\tresult = addLine(` * - **Tab**: ${args.tabName}`, result);\n\t}\n\n\tconst documentationURL =\n\t\tFIELD_DOCUMENTATION_URLS[\n\t\t\targs.field.type as keyof typeof FIELD_DOCUMENTATION_URLS\n\t\t];\n\tif (documentationURL) {\n\t\tresult = addLine(` * - **Documentation**: ${documentationURL}`, result);\n\t}\n\n\tresult = addLine(\" */\", result);\n\n\treturn result;\n}\n"],"names":["getHumanReadableModelName","getHumanReadablePath","addLine","getAPIIDPath","FIELD_DOCUMENTATION_URLS"],"mappings":";;;;;;;AAeA,SAAS,0BACR,MAAmC;;AAE3B,UAAA,KAAK,MAAM,MAAM;AAAA,IACxB,KAAK,kBAAkB;AAChB,YAAA,eACL,KAAK,MAAM,UACX,YAAY,KAAK,MAAM,UACvB,KAAK,MAAM,OAAO,UAClB,KAAK,MAAM,OAAO,OAChB,MAAM,GAAG,EACT,MAAM,CAAC,cAAc,UAAU,KAAK,SAAS,CAAC;AAEjD,aAAO,eAAe,UAAU;AAAA,IAChC;AAAA,IAED,KAAK,qBAAqB;AACnB,YAAA,WAAU,UAAK,MAAM,WAAX,mBAAmB;AAE5B,aAAA,gCACN,UAAU,KAAK,cAAc;AAAA,IAE9B;AAAA,IAED,KAAK,QAAQ;AACJ,eAAA,UAAK,MAAM,WAAX,mBAAmB,QAAQ;AAAA,QAClC,KAAK,YAAY;AACT,iBAAA;AAAA,QACP;AAAA,QAED,KAAK,SAAS;AACN,iBAAA;AAAA,QACP;AAAA,QAED,SAAS;AACD,iBAAA;AAAA,QACP;AAAA,MACD;AAAA,IACD;AAAA,IAED,KAAK,UAAU;AACP,aAAA;AAAA,IACP;AAAA,IAED,SAAS;AACR,aAAO,KAAK,MAAM;AAAA,IAClB;AAAA,EACD;AACF;AASM,SAAU,eAAe,MAAwB;AACtD,MAAI,SAAS;AAEb,QAAM,oBAAoBA,0BAAAA,0BAA0B;AAAA,IACnD,OAAO,KAAK;AAAA,IACZ,MAAM,KAAK;AAAA,EAAA,CACX;AACD,QAAM,oBAAoBC,qBAAAA,qBAAqB,EAAE,MAAM,KAAK,MAAM;AAClE,QAAM,yBAAyB,0BAA0B;AAAA,IACxD,OAAO,KAAK;AAAA,EAAA,CACZ;AAED,WAASC,QAAAA,QACR,MAAM,+BAA+B,sBACrC,MAAM;AAGE,WAAAA,QAAA,QAAQ,MAAM,MAAM;AAEpB,WAAAA,QAAA,QAAQ,wBAAwB,0BAA0B,MAAM;AAEnE,QAAA,cACJ,KAAK,MAAM,UACX,iBAAiB,KAAK,MAAM,UAC5B,KAAK,MAAM,OAAO,eACnB;AACQ,WAAAA,QAAA,QAAQ,yBAAyB,eAAe,MAAM;AAEzD,QAAA,eACL,KAAK,MAAM,UAAU,mBAAmB,KAAK,MAAM,SAChD,KAAK,MAAM,OAAO,gBAClB;AACJ,MAAI,iBAAiB,QAAW;AAC/B,UAAM,0BACL,OAAO,iBAAiB,YAAY,GAAG,iBAAiB;AAEhD,aAAAA,QAAA,QACR,2BAA2B,2BAC3B,MAAM;AAAA,EAEP;AAED,QAAM,YAAYC,aAAAA,aAAa;AAAA,IAC9B,MAAM,CAAC,GAAG,KAAK,MAAM,EAAE,MAAM,KAAK,MAAM,OAAO,KAAK,MAAA,CAAO;AAAA,EAAA,CAC3D;AACQ,WAAAD,QAAA,QAAQ,yBAAyB,aAAa,MAAM;AAE7D,MAAI,KAAK,SAAS;AACjB,aAASA,QAAQ,QAAA,iBAAiB,KAAK,WAAW,MAAM;AAAA,EACxD;AAED,QAAM,mBACLE,UAAA,yBACC,KAAK,MAAM,IAA6C;AAE1D,MAAI,kBAAkB;AACZ,aAAAF,QAAA,QAAQ,2BAA2B,oBAAoB,MAAM;AAAA,EACtE;AAEQ,WAAAA,QAAA,QAAQ,OAAO,MAAM;AAEvB,SAAA;AACR;;"}
@@ -1,14 +1,10 @@
1
- import type { CustomTypeModel, CustomTypeModelField, CustomTypeModelSlice, SharedSliceModel } from "@prismicio/client";
2
- import type { JSDocableNodeStructure } from "ts-morph";
3
- import { PathElement } from "../types";
4
- type BuildFieldDocsConfig = {
5
- id: string;
6
- model: CustomTypeModelField;
7
- path: [
8
- PathElement<CustomTypeModel | SharedSliceModel>,
9
- ...PathElement<CustomTypeModelField | CustomTypeModelSlice>[]
10
- ];
1
+ import { CustomTypeModelField } from "@prismicio/client";
2
+ import { FieldPath } from "../types";
3
+ type BuildFieldDocsArgs = {
4
+ name: string;
5
+ field: CustomTypeModelField;
6
+ path: FieldPath;
11
7
  tabName?: string;
12
8
  };
13
- export declare const buildFieldDocs: (config: BuildFieldDocsConfig) => NonNullable<JSDocableNodeStructure["docs"]>;
9
+ export declare function buildFieldDocs(args: BuildFieldDocsArgs): string;
14
10
  export {};
@@ -1,42 +1,74 @@
1
+ import { FIELD_DOCUMENTATION_URLS } from "../constants.js";
2
+ import { addLine } from "./addLine.js";
1
3
  import { getAPIIDPath } from "./getAPIIDPath.js";
2
- import { getFieldDocumentationURL } from "./getFieldDocumentationURL.js";
3
- import { getHumanReadableFieldPath } from "./getHumanReadableFieldPath.js";
4
- import { getHumanReadableFieldType } from "./getHumanReadableFieldType.js";
5
4
  import { getHumanReadableModelName } from "./getHumanReadableModelName.js";
6
- import { writeFieldDocsDescription } from "./writeFieldDocsDescription.js";
7
- const buildFieldDocs = (config) => {
8
- return [
9
- {
10
- description: (writer) => {
11
- const name = getHumanReadableModelName({
12
- id: config.id,
13
- model: config.model
14
- });
15
- const humanReadablePath = getHumanReadableFieldPath({
16
- path: config.path
17
- });
18
- const fieldType = getHumanReadableFieldType({
19
- model: config.model
20
- });
21
- const placeholder = config.model.config && "placeholder" in config.model.config && config.model.config.placeholder ? config.model.config.placeholder : `*None*`;
22
- const defaultValue = config.model.config && "default_value" in config.model.config ? config.model.config.default_value : void 0;
23
- const apiIDPath = getAPIIDPath({
24
- path: [...config.path, { id: config.id, model: config.model }]
25
- });
26
- writeFieldDocsDescription({
27
- writer,
28
- description: `${name} field in *${humanReadablePath}*`,
29
- fieldType,
30
- placeholder,
31
- defaultValue,
32
- apiIDPath,
33
- tabName: config.tabName,
34
- documentationURL: getFieldDocumentationURL({ model: config.model })
35
- });
5
+ import { getHumanReadablePath } from "./getHumanReadablePath.js";
6
+ function getHumanReadableFieldType(args) {
7
+ var _a, _b;
8
+ switch (args.field.type) {
9
+ case "StructuredText": {
10
+ const isTitleField = args.field.config && "single" in args.field.config && args.field.config.single && args.field.config.single.split(",").every((blockType) => /heading/.test(blockType));
11
+ return isTitleField ? "Title" : "Rich Text";
12
+ }
13
+ case "IntegrationFields": {
14
+ const catalog = (_a = args.field.config) == null ? void 0 : _a.catalog;
15
+ return `Integration Fields (Catalog: ${catalog ? `\`${catalog}\`` : "*unknown*"})`;
16
+ }
17
+ case "Link": {
18
+ switch ((_b = args.field.config) == null ? void 0 : _b.select) {
19
+ case "document": {
20
+ return "Content Relationship";
21
+ }
22
+ case "media": {
23
+ return "Link to Media";
24
+ }
25
+ default: {
26
+ return "Link";
27
+ }
36
28
  }
37
29
  }
38
- ];
39
- };
30
+ case "Slices": {
31
+ return "Slice Zone";
32
+ }
33
+ default: {
34
+ return args.field.type;
35
+ }
36
+ }
37
+ }
38
+ function buildFieldDocs(args) {
39
+ let result = "/**";
40
+ const humanReadableName = getHumanReadableModelName({
41
+ model: args.field,
42
+ name: args.name
43
+ });
44
+ const humanReadablePath = getHumanReadablePath({ path: args.path });
45
+ const humanReadableFieldType = getHumanReadableFieldType({
46
+ field: args.field
47
+ });
48
+ result = addLine(` * ${humanReadableName} field in *${humanReadablePath}*`, result);
49
+ result = addLine(" *", result);
50
+ result = addLine(` * - **Field Type**: ${humanReadableFieldType}`, result);
51
+ const placeholder = args.field.config && "placeholder" in args.field.config && args.field.config.placeholder || `*None*`;
52
+ result = addLine(` * - **Placeholder**: ${placeholder}`, result);
53
+ const defaultValue = args.field.config && "default_value" in args.field.config ? args.field.config.default_value : void 0;
54
+ if (defaultValue !== void 0) {
55
+ const stringifiedDefaultValue = typeof defaultValue === "boolean" ? `${defaultValue}` : defaultValue;
56
+ result = addLine(` * - **Default Value**: ${stringifiedDefaultValue}`, result);
57
+ }
58
+ const apiIDPath = getAPIIDPath({
59
+ path: [...args.path, { name: args.name, model: args.field }]
60
+ });
61
+ result = addLine(` * - **API ID Path**: ${apiIDPath}`, result);
62
+ if (args.tabName) {
63
+ result = addLine(` * - **Tab**: ${args.tabName}`, result);
64
+ }
65
+ const documentationURL = FIELD_DOCUMENTATION_URLS[args.field.type];
66
+ if (documentationURL) {
67
+ result = addLine(` * - **Documentation**: ${documentationURL}`, result);
68
+ }
69
+ result = addLine(" */", result);
70
+ return result;
71
+ }
40
72
  export {
41
73
  buildFieldDocs
42
74
  };
@@ -1 +1 @@
1
- {"version":3,"file":"buildFieldDocs.js","sources":["../../../src/lib/buildFieldDocs.ts"],"sourcesContent":["import type {\n\tCustomTypeModel,\n\tCustomTypeModelField,\n\tCustomTypeModelSlice,\n\tSharedSliceModel,\n} from \"@prismicio/client\";\nimport type { JSDocableNodeStructure } from \"ts-morph\";\n\nimport { PathElement } from \"../types\";\n\nimport { getAPIIDPath } from \"./getAPIIDPath\";\nimport { getFieldDocumentationURL } from \"./getFieldDocumentationURL\";\nimport { getHumanReadableFieldPath } from \"./getHumanReadableFieldPath\";\nimport { getHumanReadableFieldType } from \"./getHumanReadableFieldType\";\nimport { getHumanReadableModelName } from \"./getHumanReadableModelName\";\nimport { writeFieldDocsDescription } from \"./writeFieldDocsDescription\";\n\ntype BuildFieldDocsConfig = {\n\tid: string;\n\tmodel: CustomTypeModelField;\n\tpath: [\n\t\tPathElement<CustomTypeModel | SharedSliceModel>,\n\t\t...PathElement<CustomTypeModelField | CustomTypeModelSlice>[],\n\t];\n\ttabName?: string;\n};\n\nexport const buildFieldDocs = (\n\tconfig: BuildFieldDocsConfig,\n): NonNullable<JSDocableNodeStructure[\"docs\"]> => {\n\treturn [\n\t\t{\n\t\t\tdescription: (writer) => {\n\t\t\t\tconst name = getHumanReadableModelName({\n\t\t\t\t\tid: config.id,\n\t\t\t\t\tmodel: config.model,\n\t\t\t\t});\n\t\t\t\tconst humanReadablePath = getHumanReadableFieldPath({\n\t\t\t\t\tpath: config.path,\n\t\t\t\t});\n\n\t\t\t\tconst fieldType = getHumanReadableFieldType({\n\t\t\t\t\tmodel: config.model,\n\t\t\t\t});\n\n\t\t\t\tconst placeholder =\n\t\t\t\t\tconfig.model.config &&\n\t\t\t\t\t\"placeholder\" in config.model.config &&\n\t\t\t\t\tconfig.model.config.placeholder\n\t\t\t\t\t\t? config.model.config.placeholder\n\t\t\t\t\t\t: `*None*`;\n\n\t\t\t\tconst defaultValue =\n\t\t\t\t\tconfig.model.config && \"default_value\" in config.model.config\n\t\t\t\t\t\t? config.model.config.default_value\n\t\t\t\t\t\t: undefined;\n\n\t\t\t\tconst apiIDPath = getAPIIDPath({\n\t\t\t\t\tpath: [...config.path, { id: config.id, model: config.model }],\n\t\t\t\t});\n\n\t\t\t\twriteFieldDocsDescription({\n\t\t\t\t\twriter,\n\t\t\t\t\tdescription: `${name} field in *${humanReadablePath}*`,\n\t\t\t\t\tfieldType,\n\t\t\t\t\tplaceholder,\n\t\t\t\t\tdefaultValue,\n\t\t\t\t\tapiIDPath,\n\t\t\t\t\ttabName: config.tabName,\n\t\t\t\t\tdocumentationURL: getFieldDocumentationURL({ model: config.model }),\n\t\t\t\t});\n\t\t\t},\n\t\t},\n\t];\n};\n"],"names":[],"mappings":";;;;;;AA2Ba,MAAA,iBAAiB,CAC7B,WACgD;AACzC,SAAA;AAAA,IACN;AAAA,MACC,aAAa,CAAC,WAAU;AACvB,cAAM,OAAO,0BAA0B;AAAA,UACtC,IAAI,OAAO;AAAA,UACX,OAAO,OAAO;AAAA,QAAA,CACd;AACD,cAAM,oBAAoB,0BAA0B;AAAA,UACnD,MAAM,OAAO;AAAA,QAAA,CACb;AAED,cAAM,YAAY,0BAA0B;AAAA,UAC3C,OAAO,OAAO;AAAA,QAAA,CACd;AAED,cAAM,cACL,OAAO,MAAM,UACb,iBAAiB,OAAO,MAAM,UAC9B,OAAO,MAAM,OAAO,cACjB,OAAO,MAAM,OAAO,cACpB;AAEE,cAAA,eACL,OAAO,MAAM,UAAU,mBAAmB,OAAO,MAAM,SACpD,OAAO,MAAM,OAAO,gBACpB;AAEJ,cAAM,YAAY,aAAa;AAAA,UAC9B,MAAM,CAAC,GAAG,OAAO,MAAM,EAAE,IAAI,OAAO,IAAI,OAAO,OAAO,MAAA,CAAO;AAAA,QAAA,CAC7D;AAEyB,kCAAA;AAAA,UACzB;AAAA,UACA,aAAa,GAAG,kBAAkB;AAAA,UAClC;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA,SAAS,OAAO;AAAA,UAChB,kBAAkB,yBAAyB,EAAE,OAAO,OAAO,OAAO;AAAA,QAAA,CAClE;AAAA,MACF;AAAA,IACA;AAAA,EAAA;AAEH;"}
1
+ {"version":3,"file":"buildFieldDocs.js","sources":["../../../src/lib/buildFieldDocs.ts"],"sourcesContent":["import { CustomTypeModelField } from \"@prismicio/client\";\n\nimport { FieldPath } from \"../types\";\n\nimport { FIELD_DOCUMENTATION_URLS } from \"../constants\";\n\nimport { addLine } from \"./addLine\";\nimport { getAPIIDPath } from \"./getAPIIDPath\";\nimport { getHumanReadableModelName } from \"./getHumanReadableModelName\";\nimport { getHumanReadablePath } from \"./getHumanReadablePath\";\n\ntype GetFieldHumanReadableTypeArgs = {\n\tfield: CustomTypeModelField;\n};\n\nfunction getHumanReadableFieldType(\n\targs: GetFieldHumanReadableTypeArgs,\n): string {\n\tswitch (args.field.type) {\n\t\tcase \"StructuredText\": {\n\t\t\tconst isTitleField =\n\t\t\t\targs.field.config &&\n\t\t\t\t\"single\" in args.field.config &&\n\t\t\t\targs.field.config.single &&\n\t\t\t\targs.field.config.single\n\t\t\t\t\t.split(\",\")\n\t\t\t\t\t.every((blockType) => /heading/.test(blockType));\n\n\t\t\treturn isTitleField ? \"Title\" : \"Rich Text\";\n\t\t}\n\n\t\tcase \"IntegrationFields\": {\n\t\t\tconst catalog = args.field.config?.catalog;\n\n\t\t\treturn `Integration Fields (Catalog: ${\n\t\t\t\tcatalog ? `\\`${catalog}\\`` : \"*unknown*\"\n\t\t\t})`;\n\t\t}\n\n\t\tcase \"Link\": {\n\t\t\tswitch (args.field.config?.select) {\n\t\t\t\tcase \"document\": {\n\t\t\t\t\treturn \"Content Relationship\";\n\t\t\t\t}\n\n\t\t\t\tcase \"media\": {\n\t\t\t\t\treturn \"Link to Media\";\n\t\t\t\t}\n\n\t\t\t\tdefault: {\n\t\t\t\t\treturn \"Link\";\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tcase \"Slices\": {\n\t\t\treturn \"Slice Zone\";\n\t\t}\n\n\t\tdefault: {\n\t\t\treturn args.field.type;\n\t\t}\n\t}\n}\n\ntype BuildFieldDocsArgs = {\n\tname: string;\n\tfield: CustomTypeModelField;\n\tpath: FieldPath;\n\ttabName?: string;\n};\n\nexport function buildFieldDocs(args: BuildFieldDocsArgs): string {\n\tlet result = \"/**\";\n\n\tconst humanReadableName = getHumanReadableModelName({\n\t\tmodel: args.field,\n\t\tname: args.name,\n\t});\n\tconst humanReadablePath = getHumanReadablePath({ path: args.path });\n\tconst humanReadableFieldType = getHumanReadableFieldType({\n\t\tfield: args.field,\n\t});\n\n\tresult = addLine(\n\t\t` * ${humanReadableName} field in *${humanReadablePath}*`,\n\t\tresult,\n\t);\n\n\tresult = addLine(\" *\", result);\n\n\tresult = addLine(` * - **Field Type**: ${humanReadableFieldType}`, result);\n\n\tconst placeholder =\n\t\t(args.field.config &&\n\t\t\t\"placeholder\" in args.field.config &&\n\t\t\targs.field.config.placeholder) ||\n\t\t`*None*`;\n\tresult = addLine(` * - **Placeholder**: ${placeholder}`, result);\n\n\tconst defaultValue =\n\t\targs.field.config && \"default_value\" in args.field.config\n\t\t\t? args.field.config.default_value\n\t\t\t: undefined;\n\tif (defaultValue !== undefined) {\n\t\tconst stringifiedDefaultValue =\n\t\t\ttypeof defaultValue === \"boolean\" ? `${defaultValue}` : defaultValue;\n\n\t\tresult = addLine(\n\t\t\t` * - **Default Value**: ${stringifiedDefaultValue}`,\n\t\t\tresult,\n\t\t);\n\t}\n\n\tconst apiIDPath = getAPIIDPath({\n\t\tpath: [...args.path, { name: args.name, model: args.field }],\n\t});\n\tresult = addLine(` * - **API ID Path**: ${apiIDPath}`, result);\n\n\tif (args.tabName) {\n\t\tresult = addLine(` * - **Tab**: ${args.tabName}`, result);\n\t}\n\n\tconst documentationURL =\n\t\tFIELD_DOCUMENTATION_URLS[\n\t\t\targs.field.type as keyof typeof FIELD_DOCUMENTATION_URLS\n\t\t];\n\tif (documentationURL) {\n\t\tresult = addLine(` * - **Documentation**: ${documentationURL}`, result);\n\t}\n\n\tresult = addLine(\" */\", result);\n\n\treturn result;\n}\n"],"names":[],"mappings":";;;;;AAeA,SAAS,0BACR,MAAmC;;AAE3B,UAAA,KAAK,MAAM,MAAM;AAAA,IACxB,KAAK,kBAAkB;AAChB,YAAA,eACL,KAAK,MAAM,UACX,YAAY,KAAK,MAAM,UACvB,KAAK,MAAM,OAAO,UAClB,KAAK,MAAM,OAAO,OAChB,MAAM,GAAG,EACT,MAAM,CAAC,cAAc,UAAU,KAAK,SAAS,CAAC;AAEjD,aAAO,eAAe,UAAU;AAAA,IAChC;AAAA,IAED,KAAK,qBAAqB;AACnB,YAAA,WAAU,UAAK,MAAM,WAAX,mBAAmB;AAE5B,aAAA,gCACN,UAAU,KAAK,cAAc;AAAA,IAE9B;AAAA,IAED,KAAK,QAAQ;AACJ,eAAA,UAAK,MAAM,WAAX,mBAAmB,QAAQ;AAAA,QAClC,KAAK,YAAY;AACT,iBAAA;AAAA,QACP;AAAA,QAED,KAAK,SAAS;AACN,iBAAA;AAAA,QACP;AAAA,QAED,SAAS;AACD,iBAAA;AAAA,QACP;AAAA,MACD;AAAA,IACD;AAAA,IAED,KAAK,UAAU;AACP,aAAA;AAAA,IACP;AAAA,IAED,SAAS;AACR,aAAO,KAAK,MAAM;AAAA,IAClB;AAAA,EACD;AACF;AASM,SAAU,eAAe,MAAwB;AACtD,MAAI,SAAS;AAEb,QAAM,oBAAoB,0BAA0B;AAAA,IACnD,OAAO,KAAK;AAAA,IACZ,MAAM,KAAK;AAAA,EAAA,CACX;AACD,QAAM,oBAAoB,qBAAqB,EAAE,MAAM,KAAK,MAAM;AAClE,QAAM,yBAAyB,0BAA0B;AAAA,IACxD,OAAO,KAAK;AAAA,EAAA,CACZ;AAED,WAAS,QACR,MAAM,+BAA+B,sBACrC,MAAM;AAGE,WAAA,QAAQ,MAAM,MAAM;AAEpB,WAAA,QAAQ,wBAAwB,0BAA0B,MAAM;AAEnE,QAAA,cACJ,KAAK,MAAM,UACX,iBAAiB,KAAK,MAAM,UAC5B,KAAK,MAAM,OAAO,eACnB;AACQ,WAAA,QAAQ,yBAAyB,eAAe,MAAM;AAEzD,QAAA,eACL,KAAK,MAAM,UAAU,mBAAmB,KAAK,MAAM,SAChD,KAAK,MAAM,OAAO,gBAClB;AACJ,MAAI,iBAAiB,QAAW;AAC/B,UAAM,0BACL,OAAO,iBAAiB,YAAY,GAAG,iBAAiB;AAEhD,aAAA,QACR,2BAA2B,2BAC3B,MAAM;AAAA,EAEP;AAED,QAAM,YAAY,aAAa;AAAA,IAC9B,MAAM,CAAC,GAAG,KAAK,MAAM,EAAE,MAAM,KAAK,MAAM,OAAO,KAAK,MAAA,CAAO;AAAA,EAAA,CAC3D;AACQ,WAAA,QAAQ,yBAAyB,aAAa,MAAM;AAE7D,MAAI,KAAK,SAAS;AACjB,aAAS,QAAQ,iBAAiB,KAAK,WAAW,MAAM;AAAA,EACxD;AAED,QAAM,mBACL,yBACC,KAAK,MAAM,IAA6C;AAE1D,MAAI,kBAAkB;AACZ,aAAA,QAAQ,2BAA2B,oBAAoB,MAAM;AAAA,EACtE;AAEQ,WAAA,QAAQ,OAAO,MAAM;AAEvB,SAAA;AACR;"}