prismic-ts-codegen 0.1.6 → 0.1.7

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 (175) hide show
  1. package/README.md +5 -5
  2. package/bin/prismic-ts-codegen.mjs +3 -0
  3. package/dist/cli/configSchema.cjs +38 -0
  4. package/dist/cli/configSchema.cjs.map +1 -0
  5. package/dist/cli/configSchema.d.ts +3 -0
  6. package/dist/cli/configSchema.js +38 -0
  7. package/dist/cli/configSchema.js.map +1 -0
  8. package/dist/cli/constants.cjs +5 -0
  9. package/dist/cli/constants.cjs.map +1 -0
  10. package/dist/cli/constants.d.ts +1 -0
  11. package/dist/cli/constants.js +5 -0
  12. package/dist/cli/constants.js.map +1 -0
  13. package/dist/cli/index.d.ts +1 -0
  14. package/dist/cli/loadConfig.cjs +32 -0
  15. package/dist/cli/loadConfig.cjs.map +1 -0
  16. package/dist/cli/loadConfig.d.ts +6 -0
  17. package/dist/cli/loadConfig.js +32 -0
  18. package/dist/cli/loadConfig.js.map +1 -0
  19. package/dist/cli/loadLocaleIDs.cjs +37 -0
  20. package/dist/cli/loadLocaleIDs.cjs.map +1 -0
  21. package/dist/cli/loadLocaleIDs.d.ts +10 -0
  22. package/dist/cli/loadLocaleIDs.js +20 -0
  23. package/dist/cli/loadLocaleIDs.js.map +1 -0
  24. package/dist/cli/loadModels.cjs +79 -0
  25. package/dist/cli/loadModels.cjs.map +1 -0
  26. package/dist/cli/loadModels.d.ts +15 -0
  27. package/dist/cli/loadModels.js +62 -0
  28. package/dist/cli/loadModels.js.map +1 -0
  29. package/dist/cli/types.d.ts +175 -0
  30. package/dist/cli.cjs +119 -0
  31. package/dist/cli.cjs.map +1 -0
  32. package/dist/cli.js +118 -0
  33. package/dist/cli.js.map +1 -0
  34. package/dist/constants.cjs +29 -0
  35. package/dist/constants.cjs.map +1 -0
  36. package/dist/constants.d.ts +5 -0
  37. package/dist/constants.js +29 -0
  38. package/dist/constants.js.map +1 -0
  39. package/dist/detectTypesProvider.cjs +16 -0
  40. package/dist/detectTypesProvider.cjs.map +1 -0
  41. package/dist/detectTypesProvider.d.ts +13 -0
  42. package/dist/detectTypesProvider.js +16 -0
  43. package/dist/detectTypesProvider.js.map +1 -0
  44. package/dist/generateTypes.cjs +109 -0
  45. package/dist/generateTypes.cjs.map +1 -0
  46. package/dist/generateTypes.d.ts +15 -0
  47. package/dist/generateTypes.js +109 -0
  48. package/dist/generateTypes.js.map +1 -0
  49. package/dist/index.cjs +6 -1086
  50. package/dist/index.cjs.map +1 -1
  51. package/dist/index.d.ts +5 -192
  52. package/dist/index.js +5 -1081
  53. package/dist/index.js.map +1 -1
  54. package/dist/lib/addInterfacePropertiesForFields.cjs +490 -0
  55. package/dist/lib/addInterfacePropertiesForFields.cjs.map +1 -0
  56. package/dist/lib/addInterfacePropertiesForFields.d.ts +21 -0
  57. package/dist/lib/addInterfacePropertiesForFields.js +490 -0
  58. package/dist/lib/addInterfacePropertiesForFields.js.map +1 -0
  59. package/dist/lib/addTypeAliasForCustomType.cjs +81 -0
  60. package/dist/lib/addTypeAliasForCustomType.cjs.map +1 -0
  61. package/dist/lib/addTypeAliasForCustomType.d.ts +11 -0
  62. package/dist/lib/addTypeAliasForCustomType.js +81 -0
  63. package/dist/lib/addTypeAliasForCustomType.js.map +1 -0
  64. package/dist/lib/addTypeAliasForSharedSlice.cjs +149 -0
  65. package/dist/lib/addTypeAliasForSharedSlice.cjs.map +1 -0
  66. package/dist/lib/addTypeAliasForSharedSlice.d.ts +10 -0
  67. package/dist/lib/addTypeAliasForSharedSlice.js +149 -0
  68. package/dist/lib/addTypeAliasForSharedSlice.js.map +1 -0
  69. package/dist/lib/buildFieldDocs.cjs +43 -0
  70. package/dist/lib/buildFieldDocs.cjs.map +1 -0
  71. package/dist/lib/buildFieldDocs.d.ts +14 -0
  72. package/dist/lib/buildFieldDocs.js +43 -0
  73. package/dist/lib/buildFieldDocs.js.map +1 -0
  74. package/dist/lib/buildSharedSliceInterfaceNamePart.cjs +8 -0
  75. package/dist/lib/buildSharedSliceInterfaceNamePart.cjs.map +1 -0
  76. package/dist/lib/buildSharedSliceInterfaceNamePart.d.ts +5 -0
  77. package/dist/lib/buildSharedSliceInterfaceNamePart.js +8 -0
  78. package/dist/lib/buildSharedSliceInterfaceNamePart.js.map +1 -0
  79. package/dist/lib/buildTypeName.cjs +12 -0
  80. package/dist/lib/buildTypeName.cjs.map +1 -0
  81. package/dist/lib/buildTypeName.d.ts +1 -0
  82. package/dist/lib/buildTypeName.js +12 -0
  83. package/dist/lib/buildTypeName.js.map +1 -0
  84. package/dist/lib/getAPIIDPath.cjs +23 -0
  85. package/dist/lib/getAPIIDPath.cjs.map +1 -0
  86. package/dist/lib/getAPIIDPath.d.ts +10 -0
  87. package/dist/lib/getAPIIDPath.js +23 -0
  88. package/dist/lib/getAPIIDPath.js.map +1 -0
  89. package/dist/lib/getFieldDocumentationURL.cjs +8 -0
  90. package/dist/lib/getFieldDocumentationURL.cjs.map +1 -0
  91. package/dist/lib/getFieldDocumentationURL.d.ts +6 -0
  92. package/dist/lib/getFieldDocumentationURL.js +8 -0
  93. package/dist/lib/getFieldDocumentationURL.js.map +1 -0
  94. package/dist/lib/getHumanReadableFieldPath.cjs +19 -0
  95. package/dist/lib/getHumanReadableFieldPath.cjs.map +1 -0
  96. package/dist/lib/getHumanReadableFieldPath.d.ts +10 -0
  97. package/dist/lib/getHumanReadableFieldPath.js +19 -0
  98. package/dist/lib/getHumanReadableFieldPath.js.map +1 -0
  99. package/dist/lib/getHumanReadableFieldType.cjs +37 -0
  100. package/dist/lib/getHumanReadableFieldType.cjs.map +1 -0
  101. package/dist/lib/getHumanReadableFieldType.d.ts +6 -0
  102. package/dist/lib/getHumanReadableFieldType.js +37 -0
  103. package/dist/lib/getHumanReadableFieldType.js.map +1 -0
  104. package/dist/lib/getHumanReadableModelName.cjs +24 -0
  105. package/dist/lib/getHumanReadableModelName.cjs.map +1 -0
  106. package/dist/lib/getHumanReadableModelName.d.ts +7 -0
  107. package/dist/lib/getHumanReadableModelName.js +24 -0
  108. package/dist/lib/getHumanReadableModelName.js.map +1 -0
  109. package/dist/lib/getSourceFileText.cjs +9 -0
  110. package/dist/lib/getSourceFileText.cjs.map +1 -0
  111. package/dist/lib/getSourceFileText.d.ts +2 -0
  112. package/dist/lib/getSourceFileText.js +9 -0
  113. package/dist/lib/getSourceFileText.js.map +1 -0
  114. package/dist/lib/hasOwnProperty.cjs +7 -0
  115. package/dist/lib/hasOwnProperty.cjs.map +1 -0
  116. package/dist/lib/hasOwnProperty.d.ts +10 -0
  117. package/dist/lib/hasOwnProperty.js +7 -0
  118. package/dist/lib/hasOwnProperty.js.map +1 -0
  119. package/dist/lib/isCustomTypeModel.cjs +7 -0
  120. package/dist/lib/isCustomTypeModel.cjs.map +1 -0
  121. package/dist/lib/isCustomTypeModel.d.ts +2 -0
  122. package/dist/lib/isCustomTypeModel.js +7 -0
  123. package/dist/lib/isCustomTypeModel.js.map +1 -0
  124. package/dist/lib/isCustomTypeModelField.cjs +7 -0
  125. package/dist/lib/isCustomTypeModelField.cjs.map +1 -0
  126. package/dist/lib/isCustomTypeModelField.d.ts +2 -0
  127. package/dist/lib/isCustomTypeModelField.js +7 -0
  128. package/dist/lib/isCustomTypeModelField.js.map +1 -0
  129. package/dist/lib/isCustomTypeModelSlice.cjs +9 -0
  130. package/dist/lib/isCustomTypeModelSlice.cjs.map +1 -0
  131. package/dist/lib/isCustomTypeModelSlice.d.ts +2 -0
  132. package/dist/lib/isCustomTypeModelSlice.js +9 -0
  133. package/dist/lib/isCustomTypeModelSlice.js.map +1 -0
  134. package/dist/lib/isSharedSliceModel.cjs +9 -0
  135. package/dist/lib/isSharedSliceModel.cjs.map +1 -0
  136. package/dist/lib/isSharedSliceModel.d.ts +2 -0
  137. package/dist/lib/isSharedSliceModel.js +9 -0
  138. package/dist/lib/isSharedSliceModel.js.map +1 -0
  139. package/dist/lib/pascalCase.cjs +8 -0
  140. package/dist/lib/pascalCase.cjs.map +1 -0
  141. package/dist/lib/pascalCase.d.ts +1 -0
  142. package/dist/lib/pascalCase.js +8 -0
  143. package/dist/lib/pascalCase.js.map +1 -0
  144. package/dist/lib/writeFieldDocsDescription.cjs +29 -0
  145. package/dist/lib/writeFieldDocsDescription.cjs.map +1 -0
  146. package/dist/lib/writeFieldDocsDescription.d.ts +13 -0
  147. package/dist/lib/writeFieldDocsDescription.js +29 -0
  148. package/dist/lib/writeFieldDocsDescription.js.map +1 -0
  149. package/dist/types.d.ts +14 -0
  150. package/package.json +45 -36
  151. package/src/cli/configSchema.ts +2 -0
  152. package/src/cli/index.ts +9 -5
  153. package/src/cli/loadConfig.ts +4 -2
  154. package/src/cli/loadModels.ts +3 -3
  155. package/src/cli/types.ts +10 -0
  156. package/src/constants.ts +6 -3
  157. package/src/detectTypesProvider.ts +32 -0
  158. package/src/generateTypes.ts +11 -6
  159. package/src/index.ts +4 -1
  160. package/src/lib/addInterfacePropertiesForFields.ts +27 -27
  161. package/src/lib/addTypeAliasForCustomType.ts +7 -5
  162. package/src/lib/addTypeAliasForSharedSlice.ts +5 -4
  163. package/src/lib/buildFieldDocs.ts +2 -1
  164. package/src/lib/getAPIIDPath.ts +3 -2
  165. package/src/lib/getFieldDocumentationURL.ts +1 -1
  166. package/src/lib/getHumanReadableFieldPath.ts +2 -1
  167. package/src/lib/getHumanReadableFieldType.ts +2 -2
  168. package/src/lib/getHumanReadableModelName.ts +1 -1
  169. package/src/lib/getSourceFileText.ts +1 -1
  170. package/src/lib/isCustomTypeModel.ts +1 -1
  171. package/src/lib/isCustomTypeModelField.ts +1 -1
  172. package/src/lib/isCustomTypeModelSlice.ts +1 -1
  173. package/src/lib/isSharedSliceModel.ts +1 -1
  174. package/src/types.ts +1 -1
  175. package/bin/cli.mjs +0 -1342
@@ -0,0 +1,81 @@
1
+ import { CUSTOM_TYPES_DOCUMENTATION_URL } from "../constants.js";
2
+ import { addInterfacePropertiesForFields } from "./addInterfacePropertiesForFields.js";
3
+ import { buildTypeName } from "./buildTypeName.js";
4
+ const collectCustomTypeFields = (model) => {
5
+ return Object.assign({}, ...Object.values(model.json));
6
+ };
7
+ const addTypeAliasForCustomType = ({ model, sourceFile, localeIDs, fieldConfigs }) => {
8
+ const { uid: uidField, ...fields } = collectCustomTypeFields(model);
9
+ const hasDataFields = Object.keys(fields).length > 0;
10
+ const hasUIDField = Boolean(uidField);
11
+ let dataInterface;
12
+ if (hasDataFields) {
13
+ dataInterface = sourceFile.addInterface({
14
+ name: buildTypeName(model.id, "Document", "Data"),
15
+ docs: [
16
+ {
17
+ description: `Content for ${model.label} documents`
18
+ }
19
+ ]
20
+ });
21
+ for (const tabName in model.json) {
22
+ const { uid: _uidField, ...tabFields } = model.json[tabName];
23
+ addInterfacePropertiesForFields({
24
+ fields: tabFields,
25
+ interface: dataInterface,
26
+ sourceFile,
27
+ path: [
28
+ {
29
+ id: model.id,
30
+ model
31
+ }
32
+ ],
33
+ fieldConfigs,
34
+ tabName
35
+ });
36
+ }
37
+ } else {
38
+ dataInterface = sourceFile.addTypeAlias({
39
+ name: buildTypeName(model.id, "Document", "Data"),
40
+ type: `Record<string, never>`,
41
+ docs: [
42
+ {
43
+ description: `Content for ${model.label} documents`
44
+ }
45
+ ]
46
+ });
47
+ }
48
+ return sourceFile.addTypeAlias({
49
+ name: buildTypeName(model.id, "Document"),
50
+ typeParameters: [
51
+ {
52
+ name: "Lang",
53
+ constraint: "string",
54
+ default: localeIDs.length > 0 ? localeIDs.map((localeID) => `"${localeID}"`).join(" | ") : "string"
55
+ }
56
+ ],
57
+ type: hasUIDField ? `prismic.PrismicDocumentWithUID<Simplify<${dataInterface.getName()}>, "${model.id}", Lang>` : `prismic.PrismicDocumentWithoutUID<Simplify<${dataInterface.getName()}>, "${model.id}", Lang>`,
58
+ docs: [
59
+ {
60
+ description: (writer) => {
61
+ writer.writeLine(`${model.label} document from Prismic`);
62
+ writer.blankLine();
63
+ writer.writeLine(`- **API ID**: \`${model.id}\``);
64
+ writer.writeLine(`- **Repeatable**: \`${model.repeatable}\``);
65
+ writer.writeLine(`- **Documentation**: ${CUSTOM_TYPES_DOCUMENTATION_URL}`);
66
+ },
67
+ tags: [
68
+ {
69
+ tagName: "typeParam",
70
+ text: "Lang - Language API ID of the document."
71
+ }
72
+ ]
73
+ }
74
+ ],
75
+ isExported: true
76
+ });
77
+ };
78
+ export {
79
+ addTypeAliasForCustomType
80
+ };
81
+ //# sourceMappingURL=addTypeAliasForCustomType.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"addTypeAliasForCustomType.js","sources":["../../../src/lib/addTypeAliasForCustomType.ts"],"sourcesContent":["import type { CustomTypeModel, CustomTypeModelField } from \"@prismicio/client\";\nimport type {\n\tInterfaceDeclaration,\n\tSourceFile,\n\tTypeAliasDeclaration,\n} from \"ts-morph\";\n\nimport { FieldConfigs } from \"../types\";\n\nimport { CUSTOM_TYPES_DOCUMENTATION_URL } from \"../constants\";\n\nimport { addInterfacePropertiesForFields } from \"./addInterfacePropertiesForFields\";\nimport { buildTypeName } from \"./buildTypeName\";\n\nconst collectCustomTypeFields = (\n\tmodel: CustomTypeModel,\n): Record<string, CustomTypeModelField> => {\n\treturn Object.assign({}, ...Object.values(model.json));\n};\n\ntype AddTypeAliasForCustomTypeConfig = {\n\tmodel: CustomTypeModel;\n\tsourceFile: SourceFile;\n\tlocaleIDs: string[];\n\tfieldConfigs: FieldConfigs;\n};\n\nexport const addTypeAliasForCustomType = ({\n\tmodel,\n\tsourceFile,\n\tlocaleIDs,\n\tfieldConfigs,\n}: AddTypeAliasForCustomTypeConfig): TypeAliasDeclaration => {\n\tconst { uid: uidField, ...fields } = collectCustomTypeFields(model);\n\tconst hasDataFields = Object.keys(fields).length > 0;\n\tconst hasUIDField = Boolean(uidField);\n\n\tlet dataInterface: InterfaceDeclaration | TypeAliasDeclaration;\n\tif (hasDataFields) {\n\t\tdataInterface = sourceFile.addInterface({\n\t\t\tname: buildTypeName(model.id, \"Document\", \"Data\"),\n\t\t\tdocs: [\n\t\t\t\t{\n\t\t\t\t\tdescription: `Content for ${model.label} documents`,\n\t\t\t\t},\n\t\t\t],\n\t\t});\n\n\t\tfor (const tabName in model.json) {\n\t\t\t// This is destructured to ensure the UID field is\n\t\t\t// ignored.\n\t\t\tconst { uid: _uidField, ...tabFields } = model.json[tabName];\n\n\t\t\taddInterfacePropertiesForFields({\n\t\t\t\tfields: tabFields,\n\t\t\t\tinterface: dataInterface,\n\t\t\t\tsourceFile: sourceFile,\n\t\t\t\tpath: [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: model.id,\n\t\t\t\t\t\tmodel: model,\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t\tfieldConfigs,\n\t\t\t\ttabName,\n\t\t\t});\n\t\t}\n\t} else {\n\t\tdataInterface = sourceFile.addTypeAlias({\n\t\t\tname: buildTypeName(model.id, \"Document\", \"Data\"),\n\t\t\ttype: `Record<string, never>`,\n\t\t\tdocs: [\n\t\t\t\t{\n\t\t\t\t\tdescription: `Content for ${model.label} documents`,\n\t\t\t\t},\n\t\t\t],\n\t\t});\n\t}\n\n\treturn sourceFile.addTypeAlias({\n\t\tname: buildTypeName(model.id, \"Document\"),\n\t\ttypeParameters: [\n\t\t\t{\n\t\t\t\tname: \"Lang\",\n\t\t\t\tconstraint: \"string\",\n\t\t\t\tdefault:\n\t\t\t\t\tlocaleIDs.length > 0\n\t\t\t\t\t\t? localeIDs.map((localeID) => `\"${localeID}\"`).join(\" | \")\n\t\t\t\t\t\t: \"string\",\n\t\t\t},\n\t\t],\n\t\ttype: hasUIDField\n\t\t\t? `prismic.PrismicDocumentWithUID<Simplify<${dataInterface.getName()}>, \"${\n\t\t\t\t\tmodel.id\n\t\t\t }\", Lang>`\n\t\t\t: `prismic.PrismicDocumentWithoutUID<Simplify<${dataInterface.getName()}>, \"${\n\t\t\t\t\tmodel.id\n\t\t\t }\", Lang>`,\n\t\tdocs: [\n\t\t\t{\n\t\t\t\tdescription: (writer) => {\n\t\t\t\t\twriter.writeLine(`${model.label} document from Prismic`);\n\t\t\t\t\twriter.blankLine();\n\t\t\t\t\twriter.writeLine(`- **API ID**: \\`${model.id}\\``);\n\t\t\t\t\twriter.writeLine(`- **Repeatable**: \\`${model.repeatable}\\``);\n\t\t\t\t\twriter.writeLine(\n\t\t\t\t\t\t`- **Documentation**: ${CUSTOM_TYPES_DOCUMENTATION_URL}`,\n\t\t\t\t\t);\n\t\t\t\t},\n\t\t\t\ttags: [\n\t\t\t\t\t{\n\t\t\t\t\t\ttagName: \"typeParam\",\n\t\t\t\t\t\ttext: \"Lang - Language API ID of the document.\",\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t],\n\t\tisExported: true,\n\t});\n};\n"],"names":[],"mappings":";;;AAcA,MAAM,0BAA0B,CAC/B,UACyC;AAClC,SAAA,OAAO,OAAO,IAAI,GAAG,OAAO,OAAO,MAAM,IAAI,CAAC;AACtD;AASO,MAAM,4BAA4B,CAAC,EACzC,OACA,YACA,WACA,mBAC2D;AAC3D,QAAM,EAAE,KAAK,UAAU,GAAG,OAAM,IAAK,wBAAwB,KAAK;AAClE,QAAM,gBAAgB,OAAO,KAAK,MAAM,EAAE,SAAS;AAC7C,QAAA,cAAc,QAAQ,QAAQ;AAEhC,MAAA;AACJ,MAAI,eAAe;AAClB,oBAAgB,WAAW,aAAa;AAAA,MACvC,MAAM,cAAc,MAAM,IAAI,YAAY,MAAM;AAAA,MAChD,MAAM;AAAA,QACL;AAAA,UACC,aAAa,eAAe,MAAM;AAAA,QAClC;AAAA,MACD;AAAA,IAAA,CACD;AAEU,eAAA,WAAW,MAAM,MAAM;AAG3B,YAAA,EAAE,KAAK,WAAW,GAAG,UAAc,IAAA,MAAM,KAAK,OAAO;AAE3B,sCAAA;AAAA,QAC/B,QAAQ;AAAA,QACR,WAAW;AAAA,QACX;AAAA,QACA,MAAM;AAAA,UACL;AAAA,YACC,IAAI,MAAM;AAAA,YACV;AAAA,UACA;AAAA,QACD;AAAA,QACD;AAAA,QACA;AAAA,MAAA,CACA;AAAA,IACD;AAAA,EAAA,OACK;AACN,oBAAgB,WAAW,aAAa;AAAA,MACvC,MAAM,cAAc,MAAM,IAAI,YAAY,MAAM;AAAA,MAChD,MAAM;AAAA,MACN,MAAM;AAAA,QACL;AAAA,UACC,aAAa,eAAe,MAAM;AAAA,QAClC;AAAA,MACD;AAAA,IAAA,CACD;AAAA,EACD;AAED,SAAO,WAAW,aAAa;AAAA,IAC9B,MAAM,cAAc,MAAM,IAAI,UAAU;AAAA,IACxC,gBAAgB;AAAA,MACf;AAAA,QACC,MAAM;AAAA,QACN,YAAY;AAAA,QACZ,SACC,UAAU,SAAS,IAChB,UAAU,IAAI,CAAC,aAAa,IAAI,WAAW,EAAE,KAAK,KAAK,IACvD;AAAA,MACJ;AAAA,IACD;AAAA,IACD,MAAM,cACH,2CAA2C,cAAc,gBACzD,MAAM,eAEN,8CAA8C,cAAc,gBAC5D,MAAM;AAAA,IAET,MAAM;AAAA,MACL;AAAA,QACC,aAAa,CAAC,WAAU;AAChB,iBAAA,UAAU,GAAG,MAAM,6BAA6B;AACvD,iBAAO,UAAS;AACT,iBAAA,UAAU,mBAAmB,MAAM,MAAM;AACzC,iBAAA,UAAU,uBAAuB,MAAM,cAAc;AACrD,iBAAA,UACN,wBAAwB,gCAAgC;AAAA,QAE1D;AAAA,QACA,MAAM;AAAA,UACL;AAAA,YACC,SAAS;AAAA,YACT,MAAM;AAAA,UACN;AAAA,QACD;AAAA,MACD;AAAA,IACD;AAAA,IACD,YAAY;AAAA,EAAA,CACZ;AACF;"}
@@ -0,0 +1,149 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const constants = require("../constants.cjs");
4
+ const addInterfacePropertiesForFields = require("./addInterfacePropertiesForFields.cjs");
5
+ const buildSharedSliceInterfaceNamePart = require("./buildSharedSliceInterfaceNamePart.cjs");
6
+ const buildTypeName = require("./buildTypeName.cjs");
7
+ const getHumanReadableFieldPath = require("./getHumanReadableFieldPath.cjs");
8
+ const addTypeAliasForSharedSlice = (config) => {
9
+ const variationTypeNames = [];
10
+ for (const variation of config.model.variations) {
11
+ let primaryInterface;
12
+ if (variation.primary && Object.keys(variation.primary).length > 0) {
13
+ primaryInterface = config.sourceFile.addInterface({
14
+ name: buildTypeName.buildTypeName(buildSharedSliceInterfaceNamePart.buildSharedSliceInterfaceNamePart({ id: config.model.id }), variation.id, "Primary"),
15
+ docs: [
16
+ {
17
+ description: (writer) => {
18
+ const humanReadablePath = getHumanReadableFieldPath.getHumanReadableFieldPath({
19
+ path: [
20
+ {
21
+ id: config.model.id,
22
+ model: config.model
23
+ },
24
+ {
25
+ id: "primary",
26
+ label: "Primary"
27
+ }
28
+ ]
29
+ });
30
+ writer.writeLine(`Primary content in ${humanReadablePath}`);
31
+ }
32
+ }
33
+ ]
34
+ });
35
+ addInterfacePropertiesForFields.addInterfacePropertiesForFields({
36
+ interface: primaryInterface,
37
+ sourceFile: config.sourceFile,
38
+ fields: variation.primary,
39
+ path: [
40
+ {
41
+ id: config.model.id,
42
+ model: config.model
43
+ },
44
+ {
45
+ id: "primary",
46
+ label: "Primary"
47
+ }
48
+ ],
49
+ fieldConfigs: config.fieldConfigs
50
+ });
51
+ }
52
+ let itemInterface;
53
+ if (variation.items && Object.keys(variation.items).length > 0) {
54
+ itemInterface = config.sourceFile.addInterface({
55
+ name: buildTypeName.buildTypeName(buildSharedSliceInterfaceNamePart.buildSharedSliceInterfaceNamePart({ id: config.model.id }), variation.id, "Item"),
56
+ docs: [
57
+ {
58
+ description: (writer) => {
59
+ const humanReadablePath = getHumanReadableFieldPath.getHumanReadableFieldPath({
60
+ path: [
61
+ {
62
+ id: config.model.id,
63
+ model: config.model
64
+ },
65
+ {
66
+ id: "items",
67
+ label: "Items"
68
+ }
69
+ ]
70
+ });
71
+ writer.writeLine(`Item in ${humanReadablePath}`);
72
+ }
73
+ }
74
+ ],
75
+ isExported: true
76
+ });
77
+ addInterfacePropertiesForFields.addInterfacePropertiesForFields({
78
+ interface: itemInterface,
79
+ sourceFile: config.sourceFile,
80
+ fields: variation.items,
81
+ path: [
82
+ {
83
+ id: config.model.id,
84
+ model: config.model
85
+ },
86
+ {
87
+ id: "items",
88
+ label: "Items"
89
+ }
90
+ ],
91
+ fieldConfigs: config.fieldConfigs
92
+ });
93
+ }
94
+ const variationType = config.sourceFile.addTypeAlias({
95
+ name: buildTypeName.buildTypeName(buildSharedSliceInterfaceNamePart.buildSharedSliceInterfaceNamePart({ id: config.model.id }), variation.id),
96
+ type: `prismic.SharedSliceVariation<"${variation.id}", ${primaryInterface ? `Simplify<${primaryInterface.getName()}>` : "Record<string, never>"}, ${itemInterface ? `Simplify<${itemInterface.getName()}>` : "never"}>`,
97
+ docs: [
98
+ {
99
+ description: (writer) => {
100
+ writer.writeLine(`${variation.name} variation for ${config.model.name} Slice`);
101
+ writer.blankLine();
102
+ writer.writeLine(`- **API ID**: \`${variation.id}\``);
103
+ writer.writeLine(`- **Description**: \`${variation.description}\``);
104
+ writer.writeLine(`- **Documentation**: ${constants.SHARED_SLICES_DOCUMENTATION_URL}`);
105
+ }
106
+ }
107
+ ],
108
+ isExported: true
109
+ });
110
+ variationTypeNames.push(variationType.getName());
111
+ }
112
+ const variationsType = config.sourceFile.addTypeAlias({
113
+ name: buildTypeName.buildTypeName(config.model.id, "Slice", "Variation"),
114
+ type: variationTypeNames.length > 0 ? variationTypeNames.join(" | ") : "never",
115
+ docs: [
116
+ {
117
+ description: (writer) => {
118
+ const humanReadablePath = getHumanReadableFieldPath.getHumanReadableFieldPath({
119
+ path: [
120
+ {
121
+ id: config.model.id,
122
+ model: config.model
123
+ }
124
+ ]
125
+ });
126
+ writer.writeLine(`Slice variation for *${humanReadablePath}*`);
127
+ }
128
+ }
129
+ ]
130
+ });
131
+ return config.sourceFile.addTypeAlias({
132
+ name: buildTypeName.buildTypeName(buildSharedSliceInterfaceNamePart.buildSharedSliceInterfaceNamePart({ id: config.model.id })),
133
+ type: `prismic.SharedSlice<"${config.model.id}", ${variationsType.getName()}>`,
134
+ docs: [
135
+ {
136
+ description: (writer) => {
137
+ writer.writeLine(`${config.model.name} Shared Slice`);
138
+ writer.blankLine();
139
+ writer.writeLine(`- **API ID**: \`${config.model.id}\``);
140
+ writer.writeLine(`- **Description**: \`${config.model.description}\``);
141
+ writer.writeLine(`- **Documentation**: ${constants.SHARED_SLICES_DOCUMENTATION_URL}`);
142
+ }
143
+ }
144
+ ],
145
+ isExported: true
146
+ });
147
+ };
148
+ exports.addTypeAliasForSharedSlice = addTypeAliasForSharedSlice;
149
+ //# sourceMappingURL=addTypeAliasForSharedSlice.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"addTypeAliasForSharedSlice.cjs","sources":["../../../src/lib/addTypeAliasForSharedSlice.ts"],"sourcesContent":["import type { SharedSliceModel } from \"@prismicio/client\";\nimport type {\n\tInterfaceDeclaration,\n\tSourceFile,\n\tTypeAliasDeclaration,\n} from \"ts-morph\";\n\nimport { FieldConfigs } from \"../types\";\n\nimport { SHARED_SLICES_DOCUMENTATION_URL } from \"../constants\";\n\nimport { addInterfacePropertiesForFields } from \"./addInterfacePropertiesForFields\";\nimport { buildSharedSliceInterfaceNamePart } from \"./buildSharedSliceInterfaceNamePart\";\nimport { buildTypeName } from \"./buildTypeName\";\nimport { getHumanReadableFieldPath } from \"./getHumanReadableFieldPath\";\n\ntype AddTypeAliasForSharedSliceConfig = {\n\tmodel: SharedSliceModel;\n\tsourceFile: SourceFile;\n\tfieldConfigs: FieldConfigs;\n};\n\nexport const addTypeAliasForSharedSlice = (\n\tconfig: AddTypeAliasForSharedSliceConfig,\n): TypeAliasDeclaration => {\n\tconst variationTypeNames: string[] = [];\n\n\tfor (const variation of config.model.variations) {\n\t\tlet primaryInterface: InterfaceDeclaration | undefined;\n\t\tif (variation.primary && Object.keys(variation.primary).length > 0) {\n\t\t\tprimaryInterface = config.sourceFile.addInterface({\n\t\t\t\tname: buildTypeName(\n\t\t\t\t\tbuildSharedSliceInterfaceNamePart({ id: config.model.id }),\n\t\t\t\t\tvariation.id,\n\t\t\t\t\t\"Primary\",\n\t\t\t\t),\n\t\t\t\tdocs: [\n\t\t\t\t\t{\n\t\t\t\t\t\tdescription: (writer) => {\n\t\t\t\t\t\t\tconst humanReadablePath = getHumanReadableFieldPath({\n\t\t\t\t\t\t\t\tpath: [\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\tid: config.model.id,\n\t\t\t\t\t\t\t\t\t\tmodel: config.model,\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\tid: \"primary\",\n\t\t\t\t\t\t\t\t\t\tlabel: \"Primary\",\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\twriter.writeLine(`Primary content in ${humanReadablePath}`);\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t});\n\t\t\taddInterfacePropertiesForFields({\n\t\t\t\tinterface: primaryInterface,\n\t\t\t\tsourceFile: config.sourceFile,\n\t\t\t\tfields: variation.primary,\n\t\t\t\tpath: [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: config.model.id,\n\t\t\t\t\t\tmodel: config.model,\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tid: \"primary\",\n\t\t\t\t\t\tlabel: \"Primary\",\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t\tfieldConfigs: config.fieldConfigs,\n\t\t\t});\n\t\t}\n\n\t\tlet itemInterface: InterfaceDeclaration | undefined;\n\t\tif (variation.items && Object.keys(variation.items).length > 0) {\n\t\t\titemInterface = config.sourceFile.addInterface({\n\t\t\t\tname: buildTypeName(\n\t\t\t\t\tbuildSharedSliceInterfaceNamePart({ id: config.model.id }),\n\t\t\t\t\tvariation.id,\n\t\t\t\t\t\"Item\",\n\t\t\t\t),\n\t\t\t\tdocs: [\n\t\t\t\t\t{\n\t\t\t\t\t\tdescription: (writer) => {\n\t\t\t\t\t\t\tconst humanReadablePath = getHumanReadableFieldPath({\n\t\t\t\t\t\t\t\tpath: [\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\tid: config.model.id,\n\t\t\t\t\t\t\t\t\t\tmodel: config.model,\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\tid: \"items\",\n\t\t\t\t\t\t\t\t\t\tlabel: \"Items\",\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\twriter.writeLine(`Item in ${humanReadablePath}`);\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t\tisExported: true,\n\t\t\t});\n\t\t\taddInterfacePropertiesForFields({\n\t\t\t\tinterface: itemInterface,\n\t\t\t\tsourceFile: config.sourceFile,\n\t\t\t\tfields: variation.items,\n\t\t\t\tpath: [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: config.model.id,\n\t\t\t\t\t\tmodel: config.model,\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tid: \"items\",\n\t\t\t\t\t\tlabel: \"Items\",\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t\tfieldConfigs: config.fieldConfigs,\n\t\t\t});\n\t\t}\n\n\t\tconst variationType = config.sourceFile.addTypeAlias({\n\t\t\tname: buildTypeName(\n\t\t\t\tbuildSharedSliceInterfaceNamePart({ id: config.model.id }),\n\t\t\t\tvariation.id,\n\t\t\t),\n\t\t\ttype: `prismic.SharedSliceVariation<\"${variation.id}\", ${\n\t\t\t\tprimaryInterface\n\t\t\t\t\t? `Simplify<${primaryInterface.getName()}>`\n\t\t\t\t\t: \"Record<string, never>\"\n\t\t\t}, ${itemInterface ? `Simplify<${itemInterface.getName()}>` : \"never\"}>`,\n\t\t\tdocs: [\n\t\t\t\t{\n\t\t\t\t\tdescription: (writer) => {\n\t\t\t\t\t\twriter.writeLine(\n\t\t\t\t\t\t\t`${variation.name} variation for ${config.model.name} Slice`,\n\t\t\t\t\t\t);\n\t\t\t\t\t\twriter.blankLine();\n\t\t\t\t\t\twriter.writeLine(`- **API ID**: \\`${variation.id}\\``);\n\t\t\t\t\t\twriter.writeLine(`- **Description**: \\`${variation.description}\\``);\n\t\t\t\t\t\twriter.writeLine(\n\t\t\t\t\t\t\t`- **Documentation**: ${SHARED_SLICES_DOCUMENTATION_URL}`,\n\t\t\t\t\t\t);\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t],\n\t\t\tisExported: true,\n\t\t});\n\n\t\tvariationTypeNames.push(variationType.getName());\n\t}\n\n\tconst variationsType = config.sourceFile.addTypeAlias({\n\t\tname: buildTypeName(config.model.id, \"Slice\", \"Variation\"),\n\t\ttype:\n\t\t\tvariationTypeNames.length > 0 ? variationTypeNames.join(\" | \") : \"never\",\n\t\tdocs: [\n\t\t\t{\n\t\t\t\tdescription: (writer) => {\n\t\t\t\t\tconst humanReadablePath = getHumanReadableFieldPath({\n\t\t\t\t\t\tpath: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tid: config.model.id,\n\t\t\t\t\t\t\t\tmodel: config.model,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t});\n\n\t\t\t\t\twriter.writeLine(`Slice variation for *${humanReadablePath}*`);\n\t\t\t\t},\n\t\t\t},\n\t\t],\n\t});\n\n\treturn config.sourceFile.addTypeAlias({\n\t\tname: buildTypeName(\n\t\t\tbuildSharedSliceInterfaceNamePart({ id: config.model.id }),\n\t\t),\n\t\ttype: `prismic.SharedSlice<\"${\n\t\t\tconfig.model.id\n\t\t}\", ${variationsType.getName()}>`,\n\t\tdocs: [\n\t\t\t{\n\t\t\t\tdescription: (writer) => {\n\t\t\t\t\twriter.writeLine(`${config.model.name} Shared Slice`);\n\t\t\t\t\twriter.blankLine();\n\t\t\t\t\twriter.writeLine(`- **API ID**: \\`${config.model.id}\\``);\n\t\t\t\t\twriter.writeLine(\n\t\t\t\t\t\t`- **Description**: \\`${config.model.description}\\``,\n\t\t\t\t\t);\n\t\t\t\t\twriter.writeLine(\n\t\t\t\t\t\t`- **Documentation**: ${SHARED_SLICES_DOCUMENTATION_URL}`,\n\t\t\t\t\t);\n\t\t\t\t},\n\t\t\t},\n\t\t],\n\t\tisExported: true,\n\t});\n};\n"],"names":["buildTypeName","buildSharedSliceInterfaceNamePart","getHumanReadableFieldPath","addInterfacePropertiesForFields","SHARED_SLICES_DOCUMENTATION_URL"],"mappings":";;;;;;;AAsBa,MAAA,6BAA6B,CACzC,WACyB;AACzB,QAAM,qBAA+B,CAAA;AAE1B,aAAA,aAAa,OAAO,MAAM,YAAY;AAC5C,QAAA;AACA,QAAA,UAAU,WAAW,OAAO,KAAK,UAAU,OAAO,EAAE,SAAS,GAAG;AAChD,yBAAA,OAAO,WAAW,aAAa;AAAA,QACjD,MAAMA,cAAA,cACLC,oEAAkC,EAAE,IAAI,OAAO,MAAM,IAAI,GACzD,UAAU,IACV,SAAS;AAAA,QAEV,MAAM;AAAA,UACL;AAAA,YACC,aAAa,CAAC,WAAU;AACvB,oBAAM,oBAAoBC,0BAAAA,0BAA0B;AAAA,gBACnD,MAAM;AAAA,kBACL;AAAA,oBACC,IAAI,OAAO,MAAM;AAAA,oBACjB,OAAO,OAAO;AAAA,kBACd;AAAA,kBACD;AAAA,oBACC,IAAI;AAAA,oBACJ,OAAO;AAAA,kBACP;AAAA,gBACD;AAAA,cAAA,CACD;AAEM,qBAAA,UAAU,sBAAsB,mBAAmB;AAAA,YAC3D;AAAA,UACA;AAAA,QACD;AAAA,MAAA,CACD;AAC+BC,sEAAA;AAAA,QAC/B,WAAW;AAAA,QACX,YAAY,OAAO;AAAA,QACnB,QAAQ,UAAU;AAAA,QAClB,MAAM;AAAA,UACL;AAAA,YACC,IAA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B,OAAO,MAAM,MAAM;AACvD,iBAAO,UACN,wBAAwB,OAAO,MAAM,eAAe;AAE9C,iBAAA,UACN,wBAAwBG,UAAiC,iCAAA;AAAA,QAE3D;AAAA,MACA;AAAA,IACD;AAAA,IACD,YAAY;AAAA,EAAA,CACZ;AACF;;"}
@@ -0,0 +1,10 @@
1
+ import type { SharedSliceModel } from "@prismicio/client";
2
+ import type { SourceFile, TypeAliasDeclaration } from "ts-morph";
3
+ import { FieldConfigs } from "../types";
4
+ type AddTypeAliasForSharedSliceConfig = {
5
+ model: SharedSliceModel;
6
+ sourceFile: SourceFile;
7
+ fieldConfigs: FieldConfigs;
8
+ };
9
+ export declare const addTypeAliasForSharedSlice: (config: AddTypeAliasForSharedSliceConfig) => TypeAliasDeclaration;
10
+ export {};
@@ -0,0 +1,149 @@
1
+ import { SHARED_SLICES_DOCUMENTATION_URL } from "../constants.js";
2
+ import { addInterfacePropertiesForFields } from "./addInterfacePropertiesForFields.js";
3
+ import { buildSharedSliceInterfaceNamePart } from "./buildSharedSliceInterfaceNamePart.js";
4
+ import { buildTypeName } from "./buildTypeName.js";
5
+ import { getHumanReadableFieldPath } from "./getHumanReadableFieldPath.js";
6
+ const addTypeAliasForSharedSlice = (config) => {
7
+ const variationTypeNames = [];
8
+ for (const variation of config.model.variations) {
9
+ let primaryInterface;
10
+ if (variation.primary && Object.keys(variation.primary).length > 0) {
11
+ primaryInterface = config.sourceFile.addInterface({
12
+ name: buildTypeName(buildSharedSliceInterfaceNamePart({ id: config.model.id }), variation.id, "Primary"),
13
+ docs: [
14
+ {
15
+ description: (writer) => {
16
+ const humanReadablePath = getHumanReadableFieldPath({
17
+ path: [
18
+ {
19
+ id: config.model.id,
20
+ model: config.model
21
+ },
22
+ {
23
+ id: "primary",
24
+ label: "Primary"
25
+ }
26
+ ]
27
+ });
28
+ writer.writeLine(`Primary content in ${humanReadablePath}`);
29
+ }
30
+ }
31
+ ]
32
+ });
33
+ addInterfacePropertiesForFields({
34
+ interface: primaryInterface,
35
+ sourceFile: config.sourceFile,
36
+ fields: variation.primary,
37
+ path: [
38
+ {
39
+ id: config.model.id,
40
+ model: config.model
41
+ },
42
+ {
43
+ id: "primary",
44
+ label: "Primary"
45
+ }
46
+ ],
47
+ fieldConfigs: config.fieldConfigs
48
+ });
49
+ }
50
+ let itemInterface;
51
+ if (variation.items && Object.keys(variation.items).length > 0) {
52
+ itemInterface = config.sourceFile.addInterface({
53
+ name: buildTypeName(buildSharedSliceInterfaceNamePart({ id: config.model.id }), variation.id, "Item"),
54
+ docs: [
55
+ {
56
+ description: (writer) => {
57
+ const humanReadablePath = getHumanReadableFieldPath({
58
+ path: [
59
+ {
60
+ id: config.model.id,
61
+ model: config.model
62
+ },
63
+ {
64
+ id: "items",
65
+ label: "Items"
66
+ }
67
+ ]
68
+ });
69
+ writer.writeLine(`Item in ${humanReadablePath}`);
70
+ }
71
+ }
72
+ ],
73
+ isExported: true
74
+ });
75
+ addInterfacePropertiesForFields({
76
+ interface: itemInterface,
77
+ sourceFile: config.sourceFile,
78
+ fields: variation.items,
79
+ path: [
80
+ {
81
+ id: config.model.id,
82
+ model: config.model
83
+ },
84
+ {
85
+ id: "items",
86
+ label: "Items"
87
+ }
88
+ ],
89
+ fieldConfigs: config.fieldConfigs
90
+ });
91
+ }
92
+ const variationType = config.sourceFile.addTypeAlias({
93
+ name: buildTypeName(buildSharedSliceInterfaceNamePart({ id: config.model.id }), variation.id),
94
+ type: `prismic.SharedSliceVariation<"${variation.id}", ${primaryInterface ? `Simplify<${primaryInterface.getName()}>` : "Record<string, never>"}, ${itemInterface ? `Simplify<${itemInterface.getName()}>` : "never"}>`,
95
+ docs: [
96
+ {
97
+ description: (writer) => {
98
+ writer.writeLine(`${variation.name} variation for ${config.model.name} Slice`);
99
+ writer.blankLine();
100
+ writer.writeLine(`- **API ID**: \`${variation.id}\``);
101
+ writer.writeLine(`- **Description**: \`${variation.description}\``);
102
+ writer.writeLine(`- **Documentation**: ${SHARED_SLICES_DOCUMENTATION_URL}`);
103
+ }
104
+ }
105
+ ],
106
+ isExported: true
107
+ });
108
+ variationTypeNames.push(variationType.getName());
109
+ }
110
+ const variationsType = config.sourceFile.addTypeAlias({
111
+ name: buildTypeName(config.model.id, "Slice", "Variation"),
112
+ type: variationTypeNames.length > 0 ? variationTypeNames.join(" | ") : "never",
113
+ docs: [
114
+ {
115
+ description: (writer) => {
116
+ const humanReadablePath = getHumanReadableFieldPath({
117
+ path: [
118
+ {
119
+ id: config.model.id,
120
+ model: config.model
121
+ }
122
+ ]
123
+ });
124
+ writer.writeLine(`Slice variation for *${humanReadablePath}*`);
125
+ }
126
+ }
127
+ ]
128
+ });
129
+ return config.sourceFile.addTypeAlias({
130
+ name: buildTypeName(buildSharedSliceInterfaceNamePart({ id: config.model.id })),
131
+ type: `prismic.SharedSlice<"${config.model.id}", ${variationsType.getName()}>`,
132
+ docs: [
133
+ {
134
+ description: (writer) => {
135
+ writer.writeLine(`${config.model.name} Shared Slice`);
136
+ writer.blankLine();
137
+ writer.writeLine(`- **API ID**: \`${config.model.id}\``);
138
+ writer.writeLine(`- **Description**: \`${config.model.description}\``);
139
+ writer.writeLine(`- **Documentation**: ${SHARED_SLICES_DOCUMENTATION_URL}`);
140
+ }
141
+ }
142
+ ],
143
+ isExported: true
144
+ });
145
+ };
146
+ export {
147
+ addTypeAliasForSharedSlice
148
+ };
149
+ //# sourceMappingURL=addTypeAliasForSharedSlice.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"addTypeAliasForSharedSlice.js","sources":["../../../src/lib/addTypeAliasForSharedSlice.ts"],"sourcesContent":["import type { SharedSliceModel } from \"@prismicio/client\";\nimport type {\n\tInterfaceDeclaration,\n\tSourceFile,\n\tTypeAliasDeclaration,\n} from \"ts-morph\";\n\nimport { FieldConfigs } from \"../types\";\n\nimport { SHARED_SLICES_DOCUMENTATION_URL } from \"../constants\";\n\nimport { addInterfacePropertiesForFields } from \"./addInterfacePropertiesForFields\";\nimport { buildSharedSliceInterfaceNamePart } from \"./buildSharedSliceInterfaceNamePart\";\nimport { buildTypeName } from \"./buildTypeName\";\nimport { getHumanReadableFieldPath } from \"./getHumanReadableFieldPath\";\n\ntype AddTypeAliasForSharedSliceConfig = {\n\tmodel: SharedSliceModel;\n\tsourceFile: SourceFile;\n\tfieldConfigs: FieldConfigs;\n};\n\nexport const addTypeAliasForSharedSlice = (\n\tconfig: AddTypeAliasForSharedSliceConfig,\n): TypeAliasDeclaration => {\n\tconst variationTypeNames: string[] = [];\n\n\tfor (const variation of config.model.variations) {\n\t\tlet primaryInterface: InterfaceDeclaration | undefined;\n\t\tif (variation.primary && Object.keys(variation.primary).length > 0) {\n\t\t\tprimaryInterface = config.sourceFile.addInterface({\n\t\t\t\tname: buildTypeName(\n\t\t\t\t\tbuildSharedSliceInterfaceNamePart({ id: config.model.id }),\n\t\t\t\t\tvariation.id,\n\t\t\t\t\t\"Primary\",\n\t\t\t\t),\n\t\t\t\tdocs: [\n\t\t\t\t\t{\n\t\t\t\t\t\tdescription: (writer) => {\n\t\t\t\t\t\t\tconst humanReadablePath = getHumanReadableFieldPath({\n\t\t\t\t\t\t\t\tpath: [\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\tid: config.model.id,\n\t\t\t\t\t\t\t\t\t\tmodel: config.model,\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\tid: \"primary\",\n\t\t\t\t\t\t\t\t\t\tlabel: \"Primary\",\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\twriter.writeLine(`Primary content in ${humanReadablePath}`);\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t});\n\t\t\taddInterfacePropertiesForFields({\n\t\t\t\tinterface: primaryInterface,\n\t\t\t\tsourceFile: config.sourceFile,\n\t\t\t\tfields: variation.primary,\n\t\t\t\tpath: [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: config.model.id,\n\t\t\t\t\t\tmodel: config.model,\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tid: \"primary\",\n\t\t\t\t\t\tlabel: \"Primary\",\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t\tfieldConfigs: config.fieldConfigs,\n\t\t\t});\n\t\t}\n\n\t\tlet itemInterface: InterfaceDeclaration | undefined;\n\t\tif (variation.items && Object.keys(variation.items).length > 0) {\n\t\t\titemInterface = config.sourceFile.addInterface({\n\t\t\t\tname: buildTypeName(\n\t\t\t\t\tbuildSharedSliceInterfaceNamePart({ id: config.model.id }),\n\t\t\t\t\tvariation.id,\n\t\t\t\t\t\"Item\",\n\t\t\t\t),\n\t\t\t\tdocs: [\n\t\t\t\t\t{\n\t\t\t\t\t\tdescription: (writer) => {\n\t\t\t\t\t\t\tconst humanReadablePath = getHumanReadableFieldPath({\n\t\t\t\t\t\t\t\tpath: [\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\tid: config.model.id,\n\t\t\t\t\t\t\t\t\t\tmodel: config.model,\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\tid: \"items\",\n\t\t\t\t\t\t\t\t\t\tlabel: \"Items\",\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\twriter.writeLine(`Item in ${humanReadablePath}`);\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t\tisExported: true,\n\t\t\t});\n\t\t\taddInterfacePropertiesForFields({\n\t\t\t\tinterface: itemInterface,\n\t\t\t\tsourceFile: config.sourceFile,\n\t\t\t\tfields: variation.items,\n\t\t\t\tpath: [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: config.model.id,\n\t\t\t\t\t\tmodel: config.model,\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tid: \"items\",\n\t\t\t\t\t\tlabel: \"Items\",\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t\tfieldConfigs: config.fieldConfigs,\n\t\t\t});\n\t\t}\n\n\t\tconst variationType = config.sourceFile.addTypeAlias({\n\t\t\tname: buildTypeName(\n\t\t\t\tbuildSharedSliceInterfaceNamePart({ id: config.model.id }),\n\t\t\t\tvariation.id,\n\t\t\t),\n\t\t\ttype: `prismic.SharedSliceVariation<\"${variation.id}\", ${\n\t\t\t\tprimaryInterface\n\t\t\t\t\t? `Simplify<${primaryInterface.getName()}>`\n\t\t\t\t\t: \"Record<string, never>\"\n\t\t\t}, ${itemInterface ? `Simplify<${itemInterface.getName()}>` : \"never\"}>`,\n\t\t\tdocs: [\n\t\t\t\t{\n\t\t\t\t\tdescription: (writer) => {\n\t\t\t\t\t\twriter.writeLine(\n\t\t\t\t\t\t\t`${variation.name} variation for ${config.model.name} Slice`,\n\t\t\t\t\t\t);\n\t\t\t\t\t\twriter.blankLine();\n\t\t\t\t\t\twriter.writeLine(`- **API ID**: \\`${variation.id}\\``);\n\t\t\t\t\t\twriter.writeLine(`- **Description**: \\`${variation.description}\\``);\n\t\t\t\t\t\twriter.writeLine(\n\t\t\t\t\t\t\t`- **Documentation**: ${SHARED_SLICES_DOCUMENTATION_URL}`,\n\t\t\t\t\t\t);\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t],\n\t\t\tisExported: true,\n\t\t});\n\n\t\tvariationTypeNames.push(variationType.getName());\n\t}\n\n\tconst variationsType = config.sourceFile.addTypeAlias({\n\t\tname: buildTypeName(config.model.id, \"Slice\", \"Variation\"),\n\t\ttype:\n\t\t\tvariationTypeNames.length > 0 ? variationTypeNames.join(\" | \") : \"never\",\n\t\tdocs: [\n\t\t\t{\n\t\t\t\tdescription: (writer) => {\n\t\t\t\t\tconst humanReadablePath = getHumanReadableFieldPath({\n\t\t\t\t\t\tpath: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tid: config.model.id,\n\t\t\t\t\t\t\t\tmodel: config.model,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t});\n\n\t\t\t\t\twriter.writeLine(`Slice variation for *${humanReadablePath}*`);\n\t\t\t\t},\n\t\t\t},\n\t\t],\n\t});\n\n\treturn config.sourceFile.addTypeAlias({\n\t\tname: buildTypeName(\n\t\t\tbuildSharedSliceInterfaceNamePart({ id: config.model.id }),\n\t\t),\n\t\ttype: `prismic.SharedSlice<\"${\n\t\t\tconfig.model.id\n\t\t}\", ${variationsType.getName()}>`,\n\t\tdocs: [\n\t\t\t{\n\t\t\t\tdescription: (writer) => {\n\t\t\t\t\twriter.writeLine(`${config.model.name} Shared Slice`);\n\t\t\t\t\twriter.blankLine();\n\t\t\t\t\twriter.writeLine(`- **API ID**: \\`${config.model.id}\\``);\n\t\t\t\t\twriter.writeLine(\n\t\t\t\t\t\t`- **Description**: \\`${config.model.description}\\``,\n\t\t\t\t\t);\n\t\t\t\t\twriter.writeLine(\n\t\t\t\t\t\t`- **Documentation**: ${SHARED_SLICES_DOCUMENTATION_URL}`,\n\t\t\t\t\t);\n\t\t\t\t},\n\t\t\t},\n\t\t],\n\t\tisExported: true,\n\t});\n};\n"],"names":[],"mappings":";;;;;AAsBa,MAAA,6BAA6B,CACzC,WACyB;AACzB,QAAM,qBAA+B,CAAA;AAE1B,aAAA,aAAa,OAAO,MAAM,YAAY;AAC5C,QAAA;AACA,QAAA,UAAU,WAAW,OAAO,KAAK,UAAU,OAAO,EAAE,SAAS,GAAG;AAChD,yBAAA,OAAO,WAAW,aAAa;AAAA,QACjD,MAAM,cACL,kCAAkC,EAAE,IAAI,OAAO,MAAM,IAAI,GACzD,UAAU,IACV,SAAS;AAAA,QAEV,MAAM;AAAA,UACL;AAAA,YACC,aAAa,CAAC,WAAU;AACvB,oBAAM,oBAAoB,0BAA0B;AAAA,gBACnD,MAAM;AAAA,kBACL;AAAA,oBACC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WAAW,aAAa;AAAA,IACrC,MAAM,cACL,kCAAkC,EAAE,IAAI,OAAO,MAAM,GAAE,CAAE,CAAC;AAAA,IAE3D,MAAM,wBACL,OAAO,MAAM,QACR,eAAe,QAAO;AAAA,IAC5B,MAAM;AAAA,MACL;AAAA,QACC,aAAa,CAAC,WAAU;AACvB,iBAAO,UAAU,GAAG,OAAO,MAAM,mBAAmB;AACpD,iBAAO,UAAS;AAChB,iBAAO,UAAU,mBAAmB,OAAO,MAAM,MAAM;AACvD,iBAAO,UACN,wBAAwB,OAAO,MAAM,eAAe;AAE9C,iBAAA,UACN,wBAAwB,iCAAiC;AAAA,QAE3D;AAAA,MACA;AAAA,IACD;AAAA,IACD,YAAY;AAAA,EAAA,CACZ;AACF;"}
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const getAPIIDPath = require("./getAPIIDPath.cjs");
4
+ const getFieldDocumentationURL = require("./getFieldDocumentationURL.cjs");
5
+ const getHumanReadableFieldPath = require("./getHumanReadableFieldPath.cjs");
6
+ const getHumanReadableFieldType = require("./getHumanReadableFieldType.cjs");
7
+ 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
+ });
38
+ }
39
+ }
40
+ ];
41
+ };
42
+ exports.buildFieldDocs = buildFieldDocs;
43
+ //# sourceMappingURL=buildFieldDocs.cjs.map
@@ -0,0 +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;;"}
@@ -0,0 +1,14 @@
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
+ ];
11
+ tabName?: string;
12
+ };
13
+ export declare const buildFieldDocs: (config: BuildFieldDocsConfig) => NonNullable<JSDocableNodeStructure["docs"]>;
14
+ export {};
@@ -0,0 +1,43 @@
1
+ import { getAPIIDPath } from "./getAPIIDPath.js";
2
+ import { getFieldDocumentationURL } from "./getFieldDocumentationURL.js";
3
+ import { getHumanReadableFieldPath } from "./getHumanReadableFieldPath.js";
4
+ import { getHumanReadableFieldType } from "./getHumanReadableFieldType.js";
5
+ 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
+ });
36
+ }
37
+ }
38
+ ];
39
+ };
40
+ export {
41
+ buildFieldDocs
42
+ };
43
+ //# sourceMappingURL=buildFieldDocs.js.map
@@ -0,0 +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;"}
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const pascalCase = require("./pascalCase.cjs");
4
+ const buildSharedSliceInterfaceNamePart = (config) => {
5
+ return pascalCase.pascalCase(`${config.id} Slice`);
6
+ };
7
+ exports.buildSharedSliceInterfaceNamePart = buildSharedSliceInterfaceNamePart;
8
+ //# sourceMappingURL=buildSharedSliceInterfaceNamePart.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"buildSharedSliceInterfaceNamePart.cjs","sources":["../../../src/lib/buildSharedSliceInterfaceNamePart.ts"],"sourcesContent":["import { pascalCase } from \"./pascalCase\";\n\ntype BuildSharedSliceInterfaceNamePartConfig = {\n\tid: string;\n};\n\nexport const buildSharedSliceInterfaceNamePart = (\n\tconfig: BuildSharedSliceInterfaceNamePartConfig,\n): string => {\n\treturn pascalCase(`${config.id} Slice`);\n};\n"],"names":["pascalCase"],"mappings":";;;AAMa,MAAA,oCAAoC,CAChD,WACW;AACJ,SAAAA,WAAAA,WAAW,GAAG,OAAO,UAAU;AACvC;;"}
@@ -0,0 +1,5 @@
1
+ type BuildSharedSliceInterfaceNamePartConfig = {
2
+ id: string;
3
+ };
4
+ export declare const buildSharedSliceInterfaceNamePart: (config: BuildSharedSliceInterfaceNamePartConfig) => string;
5
+ export {};
@@ -0,0 +1,8 @@
1
+ import { pascalCase } from "./pascalCase.js";
2
+ const buildSharedSliceInterfaceNamePart = (config) => {
3
+ return pascalCase(`${config.id} Slice`);
4
+ };
5
+ export {
6
+ buildSharedSliceInterfaceNamePart
7
+ };
8
+ //# sourceMappingURL=buildSharedSliceInterfaceNamePart.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"buildSharedSliceInterfaceNamePart.js","sources":["../../../src/lib/buildSharedSliceInterfaceNamePart.ts"],"sourcesContent":["import { pascalCase } from \"./pascalCase\";\n\ntype BuildSharedSliceInterfaceNamePartConfig = {\n\tid: string;\n};\n\nexport const buildSharedSliceInterfaceNamePart = (\n\tconfig: BuildSharedSliceInterfaceNamePartConfig,\n): string => {\n\treturn pascalCase(`${config.id} Slice`);\n};\n"],"names":[],"mappings":";AAMa,MAAA,oCAAoC,CAChD,WACW;AACJ,SAAA,WAAW,GAAG,OAAO,UAAU;AACvC;"}
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const pascalCase = require("./pascalCase.cjs");
4
+ const buildTypeName = (...parts) => {
5
+ let name = pascalCase.pascalCase(parts.filter(Boolean).join(" "));
6
+ if (/^[0-9]/.test(name) ? "_" : "") {
7
+ name = `_${name}`;
8
+ }
9
+ return name;
10
+ };
11
+ exports.buildTypeName = buildTypeName;
12
+ //# sourceMappingURL=buildTypeName.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"buildTypeName.cjs","sources":["../../../src/lib/buildTypeName.ts"],"sourcesContent":["import { pascalCase } from \"./pascalCase\";\n\nexport const buildTypeName = (...parts: string[]) => {\n\tlet name = pascalCase(parts.filter(Boolean).join(\" \"));\n\n\tif (/^[0-9]/.test(name) ? \"_\" : \"\") {\n\t\tname = `_${name}`;\n\t}\n\n\treturn name;\n};\n"],"names":["pascalCase"],"mappings":";;;AAEa,MAAA,gBAAgB,IAAI,UAAmB;AAC/C,MAAA,OAAOA,sBAAW,MAAM,OAAO,OAAO,EAAE,KAAK,GAAG,CAAC;AAErD,MAAI,SAAS,KAAK,IAAI,IAAI,MAAM,IAAI;AACnC,WAAO,IAAI;AAAA,EACX;AAEM,SAAA;AACR;;"}
@@ -0,0 +1 @@
1
+ export declare const buildTypeName: (...parts: string[]) => string;
@@ -0,0 +1,12 @@
1
+ import { pascalCase } from "./pascalCase.js";
2
+ const buildTypeName = (...parts) => {
3
+ let name = pascalCase(parts.filter(Boolean).join(" "));
4
+ if (/^[0-9]/.test(name) ? "_" : "") {
5
+ name = `_${name}`;
6
+ }
7
+ return name;
8
+ };
9
+ export {
10
+ buildTypeName
11
+ };
12
+ //# sourceMappingURL=buildTypeName.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"buildTypeName.js","sources":["../../../src/lib/buildTypeName.ts"],"sourcesContent":["import { pascalCase } from \"./pascalCase\";\n\nexport const buildTypeName = (...parts: string[]) => {\n\tlet name = pascalCase(parts.filter(Boolean).join(\" \"));\n\n\tif (/^[0-9]/.test(name) ? \"_\" : \"\") {\n\t\tname = `_${name}`;\n\t}\n\n\treturn name;\n};\n"],"names":[],"mappings":";AAEa,MAAA,gBAAgB,IAAI,UAAmB;AAC/C,MAAA,OAAO,WAAW,MAAM,OAAO,OAAO,EAAE,KAAK,GAAG,CAAC;AAErD,MAAI,SAAS,KAAK,IAAI,IAAI,MAAM,IAAI;AACnC,WAAO,IAAI;AAAA,EACX;AAEM,SAAA;AACR;"}