prismic-ts-codegen 0.1.11 → 0.1.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/constants.cjs +19 -21
- package/dist/constants.cjs.map +1 -1
- package/dist/constants.d.ts +2 -3
- package/dist/constants.js +19 -21
- package/dist/constants.js.map +1 -1
- package/dist/generateTypes.cjs +71 -90
- package/dist/generateTypes.cjs.map +1 -1
- package/dist/generateTypes.d.ts +2 -1
- package/dist/generateTypes.js +71 -90
- package/dist/generateTypes.js.map +1 -1
- package/dist/lib/addBlankLine.cjs +12 -0
- package/dist/lib/addBlankLine.cjs.map +1 -0
- package/dist/lib/addBlankLine.d.ts +5 -0
- package/dist/lib/addBlankLine.js +12 -0
- package/dist/lib/addBlankLine.js.map +1 -0
- package/dist/lib/addLine.cjs +8 -0
- package/dist/lib/addLine.cjs.map +1 -0
- package/dist/lib/addLine.d.ts +1 -0
- package/dist/lib/addLine.js +8 -0
- package/dist/lib/addLine.js.map +1 -0
- package/dist/lib/addSection.cjs +8 -0
- package/dist/lib/addSection.cjs.map +1 -0
- package/dist/lib/addSection.d.ts +1 -0
- package/dist/lib/addSection.js +8 -0
- package/dist/lib/addSection.js.map +1 -0
- package/dist/lib/addTrailingNewLine.cjs +11 -0
- package/dist/lib/addTrailingNewLine.cjs.map +1 -0
- package/dist/lib/addTrailingNewLine.d.ts +5 -0
- package/dist/lib/addTrailingNewLine.js +11 -0
- package/dist/lib/addTrailingNewLine.js.map +1 -0
- package/dist/lib/buildCustomTypeDataType.cjs +51 -0
- package/dist/lib/buildCustomTypeDataType.cjs.map +1 -0
- package/dist/lib/buildCustomTypeDataType.d.ts +13 -0
- package/dist/lib/buildCustomTypeDataType.js +51 -0
- package/dist/lib/buildCustomTypeDataType.js.map +1 -0
- package/dist/lib/buildCustomTypeType.cjs +60 -0
- package/dist/lib/buildCustomTypeType.cjs.map +1 -0
- package/dist/lib/buildCustomTypeType.d.ts +17 -0
- package/dist/lib/buildCustomTypeType.js +60 -0
- package/dist/lib/buildCustomTypeType.js.map +1 -0
- package/dist/lib/buildFieldDocs.cjs +67 -35
- package/dist/lib/buildFieldDocs.cjs.map +1 -1
- package/dist/lib/buildFieldDocs.d.ts +7 -11
- package/dist/lib/buildFieldDocs.js +67 -35
- package/dist/lib/buildFieldDocs.js.map +1 -1
- package/dist/lib/buildFieldProperties.cjs +300 -0
- package/dist/lib/buildFieldProperties.cjs.map +1 -0
- package/dist/lib/buildFieldProperties.d.ts +14 -0
- package/dist/lib/buildFieldProperties.js +300 -0
- package/dist/lib/buildFieldProperties.js.map +1 -0
- package/dist/lib/buildSharedSliceType.cjs +140 -0
- package/dist/lib/buildSharedSliceType.cjs.map +1 -0
- package/dist/lib/buildSharedSliceType.d.ts +16 -0
- package/dist/lib/buildSharedSliceType.js +140 -0
- package/dist/lib/buildSharedSliceType.js.map +1 -0
- package/dist/lib/buildTypeName.cjs +4 -2
- package/dist/lib/buildTypeName.cjs.map +1 -1
- package/dist/lib/buildTypeName.js +4 -2
- package/dist/lib/buildTypeName.js.map +1 -1
- package/dist/lib/buildUnion.cjs +7 -0
- package/dist/lib/buildUnion.cjs.map +1 -0
- package/dist/lib/buildUnion.d.ts +1 -0
- package/dist/lib/buildUnion.js +7 -0
- package/dist/lib/buildUnion.js.map +1 -0
- package/dist/lib/checkHasUIDFIeld.cjs +7 -0
- package/dist/lib/checkHasUIDFIeld.cjs.map +1 -0
- package/dist/lib/checkHasUIDFIeld.d.ts +2 -0
- package/dist/lib/checkHasUIDFIeld.js +7 -0
- package/dist/lib/checkHasUIDFIeld.js.map +1 -0
- package/dist/lib/getAPIIDPath.cjs +18 -14
- package/dist/lib/getAPIIDPath.cjs.map +1 -1
- package/dist/lib/getAPIIDPath.d.ts +4 -8
- package/dist/lib/getAPIIDPath.js +18 -14
- package/dist/lib/getAPIIDPath.js.map +1 -1
- package/dist/lib/getCacheKey.cjs +25 -0
- package/dist/lib/getCacheKey.cjs.map +1 -0
- package/dist/lib/getCacheKey.d.ts +9 -0
- package/dist/lib/getCacheKey.js +8 -0
- package/dist/lib/getCacheKey.js.map +1 -0
- package/dist/lib/getHumanReadableModelName.cjs +13 -17
- package/dist/lib/getHumanReadableModelName.cjs.map +1 -1
- package/dist/lib/getHumanReadableModelName.d.ts +3 -3
- package/dist/lib/getHumanReadableModelName.js +13 -17
- package/dist/lib/getHumanReadableModelName.js.map +1 -1
- package/dist/lib/{getHumanReadableFieldPath.cjs → getHumanReadablePath.cjs} +8 -8
- package/dist/lib/getHumanReadablePath.cjs.map +1 -0
- package/dist/lib/getHumanReadablePath.d.ts +6 -0
- package/dist/lib/{getHumanReadableFieldPath.js → getHumanReadablePath.js} +8 -8
- package/dist/lib/getHumanReadablePath.js.map +1 -0
- package/dist/types.d.ts +9 -1
- package/package.json +18 -17
- package/src/constants.ts +19 -22
- package/src/generateTypes.ts +109 -108
- package/src/lib/addBlankLine.ts +13 -0
- package/src/lib/addLine.ts +5 -0
- package/src/lib/addSection.ts +5 -0
- package/src/lib/addTrailingNewLine.ts +14 -0
- package/src/lib/buildCustomTypeDataType.ts +74 -0
- package/src/lib/buildCustomTypeType.ts +101 -0
- package/src/lib/buildFieldDocs.ts +128 -68
- package/src/lib/buildFieldProperties.ts +513 -0
- package/src/lib/buildSharedSliceType.ts +213 -0
- package/src/lib/buildTypeName.ts +4 -2
- package/src/lib/buildUnion.ts +3 -0
- package/src/lib/checkHasUIDFIeld.ts +5 -0
- package/src/lib/getAPIIDPath.ts +40 -41
- package/src/lib/getCacheKey.ts +13 -0
- package/src/lib/getHumanReadableModelName.ts +23 -20
- package/src/lib/getHumanReadablePath.ts +24 -0
- package/src/types.ts +11 -1
- package/dist/lib/addInterfacePropertiesForFields.cjs +0 -489
- package/dist/lib/addInterfacePropertiesForFields.cjs.map +0 -1
- package/dist/lib/addInterfacePropertiesForFields.d.ts +0 -21
- package/dist/lib/addInterfacePropertiesForFields.js +0 -489
- package/dist/lib/addInterfacePropertiesForFields.js.map +0 -1
- package/dist/lib/addTypeAliasForCustomType.cjs +0 -81
- package/dist/lib/addTypeAliasForCustomType.cjs.map +0 -1
- package/dist/lib/addTypeAliasForCustomType.d.ts +0 -11
- package/dist/lib/addTypeAliasForCustomType.js +0 -81
- package/dist/lib/addTypeAliasForCustomType.js.map +0 -1
- package/dist/lib/addTypeAliasForSharedSlice.cjs +0 -149
- package/dist/lib/addTypeAliasForSharedSlice.cjs.map +0 -1
- package/dist/lib/addTypeAliasForSharedSlice.d.ts +0 -10
- package/dist/lib/addTypeAliasForSharedSlice.js +0 -149
- package/dist/lib/addTypeAliasForSharedSlice.js.map +0 -1
- package/dist/lib/buildSharedSliceInterfaceNamePart.cjs +0 -8
- package/dist/lib/buildSharedSliceInterfaceNamePart.cjs.map +0 -1
- package/dist/lib/buildSharedSliceInterfaceNamePart.d.ts +0 -5
- package/dist/lib/buildSharedSliceInterfaceNamePart.js +0 -8
- package/dist/lib/buildSharedSliceInterfaceNamePart.js.map +0 -1
- package/dist/lib/getFieldDocumentationURL.cjs +0 -8
- package/dist/lib/getFieldDocumentationURL.cjs.map +0 -1
- package/dist/lib/getFieldDocumentationURL.d.ts +0 -6
- package/dist/lib/getFieldDocumentationURL.js +0 -8
- package/dist/lib/getFieldDocumentationURL.js.map +0 -1
- package/dist/lib/getHumanReadableFieldPath.cjs.map +0 -1
- package/dist/lib/getHumanReadableFieldPath.d.ts +0 -10
- package/dist/lib/getHumanReadableFieldPath.js.map +0 -1
- package/dist/lib/getHumanReadableFieldType.cjs +0 -36
- package/dist/lib/getHumanReadableFieldType.cjs.map +0 -1
- package/dist/lib/getHumanReadableFieldType.d.ts +0 -6
- package/dist/lib/getHumanReadableFieldType.js +0 -36
- package/dist/lib/getHumanReadableFieldType.js.map +0 -1
- package/dist/lib/getSourceFileText.cjs +0 -9
- package/dist/lib/getSourceFileText.cjs.map +0 -1
- package/dist/lib/getSourceFileText.d.ts +0 -2
- package/dist/lib/getSourceFileText.js +0 -9
- package/dist/lib/getSourceFileText.js.map +0 -1
- package/dist/lib/hasOwnProperty.cjs +0 -7
- package/dist/lib/hasOwnProperty.cjs.map +0 -1
- package/dist/lib/hasOwnProperty.d.ts +0 -10
- package/dist/lib/hasOwnProperty.js +0 -7
- package/dist/lib/hasOwnProperty.js.map +0 -1
- package/dist/lib/isCustomTypeModel.cjs +0 -7
- package/dist/lib/isCustomTypeModel.cjs.map +0 -1
- package/dist/lib/isCustomTypeModel.d.ts +0 -2
- package/dist/lib/isCustomTypeModel.js +0 -7
- package/dist/lib/isCustomTypeModel.js.map +0 -1
- package/dist/lib/isCustomTypeModelField.cjs +0 -7
- package/dist/lib/isCustomTypeModelField.cjs.map +0 -1
- package/dist/lib/isCustomTypeModelField.d.ts +0 -2
- package/dist/lib/isCustomTypeModelField.js +0 -7
- package/dist/lib/isCustomTypeModelField.js.map +0 -1
- package/dist/lib/isCustomTypeModelSlice.cjs +0 -8
- package/dist/lib/isCustomTypeModelSlice.cjs.map +0 -1
- package/dist/lib/isCustomTypeModelSlice.d.ts +0 -2
- package/dist/lib/isCustomTypeModelSlice.js +0 -8
- package/dist/lib/isCustomTypeModelSlice.js.map +0 -1
- package/dist/lib/isSharedSliceModel.cjs +0 -8
- package/dist/lib/isSharedSliceModel.cjs.map +0 -1
- package/dist/lib/isSharedSliceModel.d.ts +0 -2
- package/dist/lib/isSharedSliceModel.js +0 -8
- package/dist/lib/isSharedSliceModel.js.map +0 -1
- package/dist/lib/pascalCase.cjs +0 -8
- package/dist/lib/pascalCase.cjs.map +0 -1
- package/dist/lib/pascalCase.d.ts +0 -1
- package/dist/lib/pascalCase.js +0 -8
- package/dist/lib/pascalCase.js.map +0 -1
- package/dist/lib/writeFieldDocsDescription.cjs +0 -29
- package/dist/lib/writeFieldDocsDescription.cjs.map +0 -1
- package/dist/lib/writeFieldDocsDescription.d.ts +0 -13
- package/dist/lib/writeFieldDocsDescription.js +0 -29
- package/dist/lib/writeFieldDocsDescription.js.map +0 -1
- package/src/lib/addInterfacePropertiesForFields.ts +0 -665
- package/src/lib/addTypeAliasForCustomType.ts +0 -120
- package/src/lib/addTypeAliasForSharedSlice.ts +0 -201
- package/src/lib/buildSharedSliceInterfaceNamePart.ts +0 -11
- package/src/lib/getFieldDocumentationURL.ts +0 -15
- package/src/lib/getHumanReadableFieldPath.ts +0 -36
- package/src/lib/getHumanReadableFieldType.ts +0 -55
- package/src/lib/getSourceFileText.ts +0 -14
- package/src/lib/hasOwnProperty.ts +0 -15
- package/src/lib/isCustomTypeModel.ts +0 -5
- package/src/lib/isCustomTypeModelField.ts +0 -7
- package/src/lib/isCustomTypeModelSlice.ts +0 -14
- package/src/lib/isSharedSliceModel.ts +0 -14
- package/src/lib/pascalCase.ts +0 -9
- package/src/lib/writeFieldDocsDescription.ts +0 -51
package/dist/constants.cjs
CHANGED
|
@@ -1,28 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
const SHARED_SLICES_DOCUMENTATION_URL = "https://prismic.io/docs/core-concepts/reusing-slices";
|
|
3
|
+
const CUSTOM_TYPES_DOCUMENTATION_URL = "https://prismic.io/docs/custom-types";
|
|
4
|
+
const SHARED_SLICES_DOCUMENTATION_URL = "https://prismic.io/docs/slice";
|
|
6
5
|
const FIELD_DOCUMENTATION_URLS = {
|
|
7
|
-
UID: "https://prismic.io/docs/
|
|
8
|
-
Boolean: "https://prismic.io/docs/
|
|
9
|
-
Color: "https://prismic.io/docs/
|
|
10
|
-
Date: "https://prismic.io/docs/
|
|
11
|
-
Timestamp: "https://prismic.io/docs/
|
|
12
|
-
Number: "https://prismic.io/docs/
|
|
13
|
-
Text: "https://prismic.io/docs/
|
|
14
|
-
Select: "https://prismic.io/docs/
|
|
15
|
-
StructuredText: "https://prismic.io/docs/
|
|
16
|
-
Image: "https://prismic.io/docs/
|
|
17
|
-
Link: "https://prismic.io/docs/
|
|
18
|
-
Embed: "https://prismic.io/docs/
|
|
19
|
-
GeoPoint: "https://prismic.io/docs/
|
|
20
|
-
Group: "https://prismic.io/docs/
|
|
21
|
-
IntegrationFields: "https://prismic.io/docs/
|
|
22
|
-
Slices: "https://prismic.io/docs/
|
|
23
|
-
Choice: "https://prismic.io/docs/
|
|
6
|
+
UID: "https://prismic.io/docs/field#uid",
|
|
7
|
+
Boolean: "https://prismic.io/docs/field#boolean",
|
|
8
|
+
Color: "https://prismic.io/docs/field#color",
|
|
9
|
+
Date: "https://prismic.io/docs/field#date",
|
|
10
|
+
Timestamp: "https://prismic.io/docs/field#timestamp",
|
|
11
|
+
Number: "https://prismic.io/docs/field#number",
|
|
12
|
+
Text: "https://prismic.io/docs/field#key-text",
|
|
13
|
+
Select: "https://prismic.io/docs/field#select",
|
|
14
|
+
StructuredText: "https://prismic.io/docs/field#rich-text-title",
|
|
15
|
+
Image: "https://prismic.io/docs/field#image",
|
|
16
|
+
Link: "https://prismic.io/docs/field#link-content-relationship",
|
|
17
|
+
Embed: "https://prismic.io/docs/field#embed",
|
|
18
|
+
GeoPoint: "https://prismic.io/docs/field#geopoint",
|
|
19
|
+
Group: "https://prismic.io/docs/field#group",
|
|
20
|
+
IntegrationFields: "https://prismic.io/docs/field#integration",
|
|
21
|
+
Slices: "https://prismic.io/docs/field#slices",
|
|
22
|
+
Choice: "https://prismic.io/docs/field#slices"
|
|
24
23
|
};
|
|
25
|
-
exports.BLANK_LINE_IDENTIFIER = BLANK_LINE_IDENTIFIER;
|
|
26
24
|
exports.CUSTOM_TYPES_DOCUMENTATION_URL = CUSTOM_TYPES_DOCUMENTATION_URL;
|
|
27
25
|
exports.FIELD_DOCUMENTATION_URLS = FIELD_DOCUMENTATION_URLS;
|
|
28
26
|
exports.SHARED_SLICES_DOCUMENTATION_URL = SHARED_SLICES_DOCUMENTATION_URL;
|
package/dist/constants.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.cjs","sources":["../../src/constants.ts"],"sourcesContent":["import type { CustomTypeModelFieldType } from \"@prismicio/client\";\n\nexport const
|
|
1
|
+
{"version":3,"file":"constants.cjs","sources":["../../src/constants.ts"],"sourcesContent":["import type { CustomTypeModelFieldType } from \"@prismicio/client\";\n\nexport const CUSTOM_TYPES_DOCUMENTATION_URL =\n\t\"https://prismic.io/docs/custom-types\";\n\nexport const SHARED_SLICES_DOCUMENTATION_URL = \"https://prismic.io/docs/slice\";\n\nexport const FIELD_DOCUMENTATION_URLS: Record<\n\tExclude<\n\t\t(typeof CustomTypeModelFieldType)[keyof typeof CustomTypeModelFieldType],\n\t\t\"Range\" | \"Separator\"\n\t>,\n\tstring\n> = {\n\tUID: \"https://prismic.io/docs/field#uid\",\n\tBoolean: \"https://prismic.io/docs/field#boolean\",\n\tColor: \"https://prismic.io/docs/field#color\",\n\tDate: \"https://prismic.io/docs/field#date\",\n\tTimestamp: \"https://prismic.io/docs/field#timestamp\",\n\tNumber: \"https://prismic.io/docs/field#number\",\n\tText: \"https://prismic.io/docs/field#key-text\",\n\tSelect: \"https://prismic.io/docs/field#select\",\n\tStructuredText: \"https://prismic.io/docs/field#rich-text-title\",\n\tImage: \"https://prismic.io/docs/field#image\",\n\tLink: \"https://prismic.io/docs/field#link-content-relationship\",\n\tEmbed: \"https://prismic.io/docs/field#embed\",\n\tGeoPoint: \"https://prismic.io/docs/field#geopoint\",\n\tGroup: \"https://prismic.io/docs/field#group\",\n\tIntegrationFields: \"https://prismic.io/docs/field#integration\",\n\tSlices: \"https://prismic.io/docs/field#slices\",\n\tChoice: \"https://prismic.io/docs/field#slices\",\n};\n"],"names":[],"mappings":";;AAEO,MAAM,iCACZ;AAEM,MAAM,kCAAkC;AAExC,MAAM,2BAMT;AAAA,EACH,KAAK;AAAA,EACL,SAAS;AAAA,EACT,OAAO;AAAA,EACP,MAAM;AAAA,EACN,WAAW;AAAA,EACX,QAAQ;AAAA,EACR,MAAM;AAAA,EACN,QAAQ;AAAA,EACR,gBAAgB;AAAA,EAChB,OAAO;AAAA,EACP,MAAM;AAAA,EACN,OAAO;AAAA,EACP,UAAU;AAAA,EACV,OAAO;AAAA,EACP,mBAAmB;AAAA,EACnB,QAAQ;AAAA,EACR,QAAQ;;;;;"}
|
package/dist/constants.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { CustomTypeModelFieldType } from "@prismicio/client";
|
|
2
|
-
export declare const
|
|
3
|
-
export declare const
|
|
4
|
-
export declare const SHARED_SLICES_DOCUMENTATION_URL = "https://prismic.io/docs/core-concepts/reusing-slices";
|
|
2
|
+
export declare const CUSTOM_TYPES_DOCUMENTATION_URL = "https://prismic.io/docs/custom-types";
|
|
3
|
+
export declare const SHARED_SLICES_DOCUMENTATION_URL = "https://prismic.io/docs/slice";
|
|
5
4
|
export declare const FIELD_DOCUMENTATION_URLS: Record<Exclude<(typeof CustomTypeModelFieldType)[keyof typeof CustomTypeModelFieldType], "Range" | "Separator">, string>;
|
package/dist/constants.js
CHANGED
|
@@ -1,27 +1,25 @@
|
|
|
1
|
-
const
|
|
2
|
-
const
|
|
3
|
-
const SHARED_SLICES_DOCUMENTATION_URL = "https://prismic.io/docs/core-concepts/reusing-slices";
|
|
1
|
+
const CUSTOM_TYPES_DOCUMENTATION_URL = "https://prismic.io/docs/custom-types";
|
|
2
|
+
const SHARED_SLICES_DOCUMENTATION_URL = "https://prismic.io/docs/slice";
|
|
4
3
|
const FIELD_DOCUMENTATION_URLS = {
|
|
5
|
-
UID: "https://prismic.io/docs/
|
|
6
|
-
Boolean: "https://prismic.io/docs/
|
|
7
|
-
Color: "https://prismic.io/docs/
|
|
8
|
-
Date: "https://prismic.io/docs/
|
|
9
|
-
Timestamp: "https://prismic.io/docs/
|
|
10
|
-
Number: "https://prismic.io/docs/
|
|
11
|
-
Text: "https://prismic.io/docs/
|
|
12
|
-
Select: "https://prismic.io/docs/
|
|
13
|
-
StructuredText: "https://prismic.io/docs/
|
|
14
|
-
Image: "https://prismic.io/docs/
|
|
15
|
-
Link: "https://prismic.io/docs/
|
|
16
|
-
Embed: "https://prismic.io/docs/
|
|
17
|
-
GeoPoint: "https://prismic.io/docs/
|
|
18
|
-
Group: "https://prismic.io/docs/
|
|
19
|
-
IntegrationFields: "https://prismic.io/docs/
|
|
20
|
-
Slices: "https://prismic.io/docs/
|
|
21
|
-
Choice: "https://prismic.io/docs/
|
|
4
|
+
UID: "https://prismic.io/docs/field#uid",
|
|
5
|
+
Boolean: "https://prismic.io/docs/field#boolean",
|
|
6
|
+
Color: "https://prismic.io/docs/field#color",
|
|
7
|
+
Date: "https://prismic.io/docs/field#date",
|
|
8
|
+
Timestamp: "https://prismic.io/docs/field#timestamp",
|
|
9
|
+
Number: "https://prismic.io/docs/field#number",
|
|
10
|
+
Text: "https://prismic.io/docs/field#key-text",
|
|
11
|
+
Select: "https://prismic.io/docs/field#select",
|
|
12
|
+
StructuredText: "https://prismic.io/docs/field#rich-text-title",
|
|
13
|
+
Image: "https://prismic.io/docs/field#image",
|
|
14
|
+
Link: "https://prismic.io/docs/field#link-content-relationship",
|
|
15
|
+
Embed: "https://prismic.io/docs/field#embed",
|
|
16
|
+
GeoPoint: "https://prismic.io/docs/field#geopoint",
|
|
17
|
+
Group: "https://prismic.io/docs/field#group",
|
|
18
|
+
IntegrationFields: "https://prismic.io/docs/field#integration",
|
|
19
|
+
Slices: "https://prismic.io/docs/field#slices",
|
|
20
|
+
Choice: "https://prismic.io/docs/field#slices"
|
|
22
21
|
};
|
|
23
22
|
export {
|
|
24
|
-
BLANK_LINE_IDENTIFIER,
|
|
25
23
|
CUSTOM_TYPES_DOCUMENTATION_URL,
|
|
26
24
|
FIELD_DOCUMENTATION_URLS,
|
|
27
25
|
SHARED_SLICES_DOCUMENTATION_URL
|
package/dist/constants.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sources":["../../src/constants.ts"],"sourcesContent":["import type { CustomTypeModelFieldType } from \"@prismicio/client\";\n\nexport const
|
|
1
|
+
{"version":3,"file":"constants.js","sources":["../../src/constants.ts"],"sourcesContent":["import type { CustomTypeModelFieldType } from \"@prismicio/client\";\n\nexport const CUSTOM_TYPES_DOCUMENTATION_URL =\n\t\"https://prismic.io/docs/custom-types\";\n\nexport const SHARED_SLICES_DOCUMENTATION_URL = \"https://prismic.io/docs/slice\";\n\nexport const FIELD_DOCUMENTATION_URLS: Record<\n\tExclude<\n\t\t(typeof CustomTypeModelFieldType)[keyof typeof CustomTypeModelFieldType],\n\t\t\"Range\" | \"Separator\"\n\t>,\n\tstring\n> = {\n\tUID: \"https://prismic.io/docs/field#uid\",\n\tBoolean: \"https://prismic.io/docs/field#boolean\",\n\tColor: \"https://prismic.io/docs/field#color\",\n\tDate: \"https://prismic.io/docs/field#date\",\n\tTimestamp: \"https://prismic.io/docs/field#timestamp\",\n\tNumber: \"https://prismic.io/docs/field#number\",\n\tText: \"https://prismic.io/docs/field#key-text\",\n\tSelect: \"https://prismic.io/docs/field#select\",\n\tStructuredText: \"https://prismic.io/docs/field#rich-text-title\",\n\tImage: \"https://prismic.io/docs/field#image\",\n\tLink: \"https://prismic.io/docs/field#link-content-relationship\",\n\tEmbed: \"https://prismic.io/docs/field#embed\",\n\tGeoPoint: \"https://prismic.io/docs/field#geopoint\",\n\tGroup: \"https://prismic.io/docs/field#group\",\n\tIntegrationFields: \"https://prismic.io/docs/field#integration\",\n\tSlices: \"https://prismic.io/docs/field#slices\",\n\tChoice: \"https://prismic.io/docs/field#slices\",\n};\n"],"names":[],"mappings":"AAEO,MAAM,iCACZ;AAEM,MAAM,kCAAkC;AAExC,MAAM,2BAMT;AAAA,EACH,KAAK;AAAA,EACL,SAAS;AAAA,EACT,OAAO;AAAA,EACP,MAAM;AAAA,EACN,WAAW;AAAA,EACX,QAAQ;AAAA,EACR,MAAM;AAAA,EACN,QAAQ;AAAA,EACR,gBAAgB;AAAA,EAChB,OAAO;AAAA,EACP,MAAM;AAAA,EACN,OAAO;AAAA,EACP,UAAU;AAAA,EACV,OAAO;AAAA,EACP,mBAAmB;AAAA,EACnB,QAAQ;AAAA,EACR,QAAQ;;"}
|
package/dist/generateTypes.cjs
CHANGED
|
@@ -1,114 +1,95 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
const
|
|
3
|
+
const commonTags = require("common-tags");
|
|
4
|
+
const QuickLRU = require("quick-lru");
|
|
5
|
+
const addLine = require("./lib/addLine.cjs");
|
|
6
|
+
const addSection = require("./lib/addSection.cjs");
|
|
7
|
+
const buildCustomTypeType = require("./lib/buildCustomTypeType.cjs");
|
|
8
|
+
const buildSharedSliceType = require("./lib/buildSharedSliceType.cjs");
|
|
9
|
+
const buildUnion = require("./lib/buildUnion.cjs");
|
|
10
|
+
const cache = new QuickLRU({ maxSize: 1e3 });
|
|
11
|
+
function generateTypes(config = {}) {
|
|
12
|
+
var _a, _b, _c, _d, _e;
|
|
13
|
+
const fieldConfigs = config.fieldConfigs || {};
|
|
14
|
+
const shouldUseCache = config.cache ?? true;
|
|
15
|
+
let code = "";
|
|
15
16
|
const typesProvider = config.typesProvider || "@prismicio/types";
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
name: "T"
|
|
27
|
-
}
|
|
28
|
-
],
|
|
29
|
-
type: `{ [KeyType in keyof T]: T[KeyType] }`
|
|
30
|
-
});
|
|
17
|
+
let clientImportName = "prismic";
|
|
18
|
+
code = addLine.addLine(`import type * as prismic from "${typesProvider}";`, code);
|
|
19
|
+
if (((_a = config.clientIntegration) == null ? void 0 : _a.includeCreateClientInterface) || ((_b = config.clientIntegration) == null ? void 0 : _b.includeContentNamespace)) {
|
|
20
|
+
if (typesProvider !== "@prismicio/client") {
|
|
21
|
+
clientImportName = "prismicClient";
|
|
22
|
+
code = addLine.addLine(`import type * as ${clientImportName} from "@prismicio/client";`, code);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
code = addSection.addSection(`type Simplify<T> = { [KeyType in keyof T]: T[KeyType] };`, code);
|
|
26
|
+
const contentTypeNames = [];
|
|
31
27
|
if (config.customTypeModels) {
|
|
28
|
+
const allDocumentTypesTypeNames = [];
|
|
32
29
|
for (const model of config.customTypeModels) {
|
|
33
|
-
|
|
30
|
+
const customTypeType = buildCustomTypeType.buildCustomTypeType({
|
|
34
31
|
model,
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
32
|
+
localeIDs: config.localeIDs,
|
|
33
|
+
fieldConfigs,
|
|
34
|
+
cache: shouldUseCache ? cache : void 0
|
|
38
35
|
});
|
|
36
|
+
for (const auxiliaryType of customTypeType.auxiliaryTypes) {
|
|
37
|
+
code = addSection.addSection(auxiliaryType.code, code);
|
|
38
|
+
}
|
|
39
|
+
code = addSection.addSection(customTypeType.code, code);
|
|
40
|
+
allDocumentTypesTypeNames.push(customTypeType.name);
|
|
41
|
+
contentTypeNames.push(customTypeType.name);
|
|
42
|
+
contentTypeNames.push(customTypeType.dataName);
|
|
39
43
|
}
|
|
40
44
|
if (config.customTypeModels.length > 0) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
});
|
|
45
|
+
const allDocumentTypesUnionName = "AllDocumentTypes";
|
|
46
|
+
const allDocumentTypesUnion = buildUnion.buildUnion(allDocumentTypesTypeNames);
|
|
47
|
+
code = addSection.addSection(`export type ${allDocumentTypesUnionName} = ${allDocumentTypesUnion};`, code);
|
|
48
|
+
contentTypeNames.push(allDocumentTypesUnionName);
|
|
46
49
|
}
|
|
47
50
|
}
|
|
48
51
|
if (config.sharedSliceModels) {
|
|
49
52
|
for (const model of config.sharedSliceModels) {
|
|
50
|
-
|
|
53
|
+
const sharedSliceType = buildSharedSliceType.buildSharedSliceType({
|
|
51
54
|
model,
|
|
52
|
-
|
|
53
|
-
|
|
55
|
+
fieldConfigs,
|
|
56
|
+
cache: shouldUseCache ? cache : void 0
|
|
54
57
|
});
|
|
58
|
+
code = addSection.addSection(sharedSliceType.code, code);
|
|
59
|
+
contentTypeNames.push(sharedSliceType.name);
|
|
60
|
+
contentTypeNames.push(sharedSliceType.variationUnionName);
|
|
61
|
+
contentTypeNames.push(...sharedSliceType.variationNames);
|
|
55
62
|
}
|
|
56
63
|
}
|
|
57
|
-
if (((
|
|
58
|
-
let
|
|
59
|
-
if (typesProvider !== "@prismicio/client") {
|
|
60
|
-
clientNamespaceImportName = "prismicClient";
|
|
61
|
-
sourceFile.addImportDeclaration({
|
|
62
|
-
moduleSpecifier: "@prismicio/client",
|
|
63
|
-
namespaceImport: clientNamespaceImportName,
|
|
64
|
-
isTypeOnly: true
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
const clientModuleDeclaration = sourceFile.addModule({
|
|
68
|
-
name: '"@prismicio/client"',
|
|
69
|
-
hasDeclareKeyword: true,
|
|
70
|
-
declarationKind: tsMorph.ModuleDeclarationKind.Module
|
|
71
|
-
});
|
|
64
|
+
if (((_c = config.clientIntegration) == null ? void 0 : _c.includeCreateClientInterface) || ((_d = config.clientIntegration) == null ? void 0 : _d.includeContentNamespace)) {
|
|
65
|
+
let clientModuleCode = "";
|
|
72
66
|
if (config.clientIntegration.includeCreateClientInterface) {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
{
|
|
83
|
-
name: "options",
|
|
84
|
-
type: `${clientNamespaceImportName}.ClientConfig`,
|
|
85
|
-
hasQuestionToken: true
|
|
86
|
-
}
|
|
87
|
-
],
|
|
88
|
-
returnType: (((_c = config.customTypeModels) == null ? void 0 : _c.length) || 0) > 0 ? `${clientNamespaceImportName}.Client<AllDocumentTypes>` : `${clientNamespaceImportName}.Client`
|
|
89
|
-
}
|
|
90
|
-
]
|
|
91
|
-
});
|
|
67
|
+
if ((((_e = config.customTypeModels) == null ? void 0 : _e.length) || 0) > 0) {
|
|
68
|
+
clientModuleCode = addSection.addSection(`interface CreateClient {
|
|
69
|
+
(repositoryNameOrEndpoint: string, options?: ${clientImportName}.ClientConfig): ${clientImportName}.Client<AllDocumentTypes>;
|
|
70
|
+
}`, clientModuleCode);
|
|
71
|
+
} else {
|
|
72
|
+
clientModuleCode = addSection.addSection(`interface CreateClient {
|
|
73
|
+
(repositoryNameOrEndpoint: string, options?: ${clientImportName}.ClientConfig): ${clientImportName}.Client;
|
|
74
|
+
}`, clientModuleCode);
|
|
75
|
+
}
|
|
92
76
|
}
|
|
93
77
|
if (config.clientIntegration.includeContentNamespace) {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
contentNamespaceDeclaration.addExportDeclaration({
|
|
102
|
-
isTypeOnly: true,
|
|
103
|
-
namedExports: exportSymbols.map((exportSymbol) => {
|
|
104
|
-
return {
|
|
105
|
-
name: exportSymbol.getName()
|
|
106
|
-
};
|
|
107
|
-
})
|
|
108
|
-
});
|
|
78
|
+
clientModuleCode = addSection.addSection(commonTags.source`
|
|
79
|
+
namespace Content {
|
|
80
|
+
export type {
|
|
81
|
+
${contentTypeNames.join(",\n")}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
`, clientModuleCode);
|
|
109
85
|
}
|
|
86
|
+
code = addSection.addSection(commonTags.source`
|
|
87
|
+
declare module "@prismicio/client" {
|
|
88
|
+
${clientModuleCode}
|
|
89
|
+
}
|
|
90
|
+
`, code);
|
|
110
91
|
}
|
|
111
|
-
return
|
|
112
|
-
}
|
|
92
|
+
return code;
|
|
93
|
+
}
|
|
113
94
|
exports.generateTypes = generateTypes;
|
|
114
95
|
//# sourceMappingURL=generateTypes.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateTypes.cjs","sources":["../../src/generateTypes.ts"],"sourcesContent":["import type { CustomTypeModel, SharedSliceModel } from \"@prismicio/client\";\nimport {
|
|
1
|
+
{"version":3,"file":"generateTypes.cjs","sources":["../../src/generateTypes.ts"],"sourcesContent":["import type { CustomTypeModel, SharedSliceModel } from \"@prismicio/client\";\nimport { source } from \"common-tags\";\nimport QuickLRU from \"quick-lru\";\n\nimport { addLine } from \"./lib/addLine\";\nimport { addSection } from \"./lib/addSection\";\nimport { buildCustomTypeType } from \"./lib/buildCustomTypeType\";\nimport { buildSharedSliceType } from \"./lib/buildSharedSliceType\";\nimport { buildUnion } from \"./lib/buildUnion\";\n\nimport { FieldConfigs } from \"./types\";\n\nexport type TypesProvider = \"@prismicio/client\" | \"@prismicio/types\";\n\nconst cache = new QuickLRU<string, unknown>({ maxSize: 1000 });\n\nexport type GenerateTypesConfig = {\n\tcustomTypeModels?: CustomTypeModel[];\n\tsharedSliceModels?: SharedSliceModel[];\n\tlocaleIDs?: string[];\n\tfieldConfigs?: FieldConfigs;\n\ttypesProvider?: TypesProvider;\n\tclientIntegration?: {\n\t\tincludeCreateClientInterface?: boolean;\n\t\tincludeContentNamespace?: boolean;\n\t};\n\tcache?: boolean;\n};\n\nexport function generateTypes(config: GenerateTypesConfig = {}): string {\n\tconst fieldConfigs = config.fieldConfigs || {};\n\tconst shouldUseCache = config.cache ?? true;\n\n\tlet code = \"\";\n\n\tconst typesProvider = config.typesProvider || \"@prismicio/types\";\n\tlet clientImportName = \"prismic\";\n\n\tcode = addLine(`import type * as prismic from \"${typesProvider}\";`, code);\n\n\tif (\n\t\tconfig.clientIntegration?.includeCreateClientInterface ||\n\t\tconfig.clientIntegration?.includeContentNamespace\n\t) {\n\t\tif (typesProvider !== \"@prismicio/client\") {\n\t\t\tclientImportName = \"prismicClient\";\n\n\t\t\t// This import declaration would be a duplicate if the types\n\t\t\t// provider is @prismicio/client.\n\t\t\tcode = addLine(\n\t\t\t\t`import type * as ${clientImportName} from \"@prismicio/client\";`,\n\t\t\t\tcode,\n\t\t\t);\n\t\t}\n\t}\n\n\tcode = addSection(\n\t\t`type Simplify<T> = { [KeyType in keyof T]: T[KeyType] };`,\n\t\tcode,\n\t);\n\n\tconst contentTypeNames: string[] = [];\n\n\tif (config.customTypeModels) {\n\t\tconst allDocumentTypesTypeNames: string[] = [];\n\n\t\tfor (const model of config.customTypeModels) {\n\t\t\tconst customTypeType = buildCustomTypeType({\n\t\t\t\tmodel,\n\t\t\t\tlocaleIDs: config.localeIDs,\n\t\t\t\tfieldConfigs,\n\t\t\t\tcache: shouldUseCache ? cache : undefined,\n\t\t\t});\n\n\t\t\tfor (const auxiliaryType of customTypeType.auxiliaryTypes) {\n\t\t\t\tcode = addSection(auxiliaryType.code, code);\n\t\t\t}\n\n\t\t\tcode = addSection(customTypeType.code, code);\n\n\t\t\tallDocumentTypesTypeNames.push(customTypeType.name);\n\n\t\t\tcontentTypeNames.push(customTypeType.name);\n\t\t\tcontentTypeNames.push(customTypeType.dataName);\n\t\t}\n\n\t\tif (config.customTypeModels.length > 0) {\n\t\t\tconst allDocumentTypesUnionName = \"AllDocumentTypes\";\n\t\t\tconst allDocumentTypesUnion = buildUnion(allDocumentTypesTypeNames);\n\n\t\t\tcode = addSection(\n\t\t\t\t`export type ${allDocumentTypesUnionName} = ${allDocumentTypesUnion};`,\n\t\t\t\tcode,\n\t\t\t);\n\n\t\t\tcontentTypeNames.push(allDocumentTypesUnionName);\n\t\t}\n\t}\n\n\tif (config.sharedSliceModels) {\n\t\tfor (const model of config.sharedSliceModels) {\n\t\t\tconst sharedSliceType = buildSharedSliceType({\n\t\t\t\tmodel,\n\t\t\t\tfieldConfigs,\n\t\t\t\tcache: shouldUseCache ? cache : undefined,\n\t\t\t});\n\n\t\t\tcode = addSection(sharedSliceType.code, code);\n\n\t\t\tcontentTypeNames.push(sharedSliceType.name);\n\t\t\tcontentTypeNames.push(sharedSliceType.variationUnionName);\n\t\t\tcontentTypeNames.push(...sharedSliceType.variationNames);\n\t\t}\n\t}\n\n\tif (\n\t\tconfig.clientIntegration?.includeCreateClientInterface ||\n\t\tconfig.clientIntegration?.includeContentNamespace\n\t) {\n\t\tlet clientModuleCode = \"\";\n\n\t\tif (config.clientIntegration.includeCreateClientInterface) {\n\t\t\tif ((config.customTypeModels?.length || 0) > 0) {\n\t\t\t\tclientModuleCode = addSection(\n\t\t\t\t\t`interface CreateClient {\n\t(repositoryNameOrEndpoint: string, options?: ${clientImportName}.ClientConfig): ${clientImportName}.Client<AllDocumentTypes>;\n}`,\n\t\t\t\t\tclientModuleCode,\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tclientModuleCode = addSection(\n\t\t\t\t\t`interface CreateClient {\n\t(repositoryNameOrEndpoint: string, options?: ${clientImportName}.ClientConfig): ${clientImportName}.Client;\n}`,\n\t\t\t\t\tclientModuleCode,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\tif (config.clientIntegration.includeContentNamespace) {\n\t\t\tclientModuleCode = addSection(\n\t\t\t\tsource`\n\t\t\t\t\tnamespace Content {\n\t\t\t\t\t\texport type {\n\t\t\t\t\t\t\t${contentTypeNames.join(\",\\n\")}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t`,\n\t\t\t\tclientModuleCode,\n\t\t\t);\n\t\t}\n\n\t\tcode = addSection(\n\t\t\tsource`\n\t\t\t\tdeclare module \"@prismicio/client\" {\n\t\t\t\t\t${clientModuleCode}\n\t\t\t\t}\n\t\t\t`,\n\t\t\tcode,\n\t\t);\n\t}\n\n\treturn code;\n}\n"],"names":["addLine","addSection","buildCustomTypeType","buildUnion","buildSharedSliceType","source"],"mappings":";;;;;;;;;AAcA,MAAM,QAAQ,IAAI,SAA0B,EAAE,SAAS,IAAM,CAAA;AAe7C,SAAA,cAAc,SAA8B,IAAE;;AACvD,QAAA,eAAe,OAAO,gBAAgB;AACtC,QAAA,iBAAiB,OAAO,SAAS;AAEvC,MAAI,OAAO;AAEL,QAAA,gBAAgB,OAAO,iBAAiB;AAC9C,MAAI,mBAAmB;AAEhB,SAAAA,QAAA,QAAQ,kCAAkC,mBAAmB,IAAI;AAExE,QACC,YAAO,sBAAP,mBAA0B,mCAC1B,YAAO,sBAAP,mBAA0B,0BACzB;AACD,QAAI,kBAAkB,qBAAqB;AACvB,yBAAA;AAIZ,aAAAA,QAAA,QACN,oBAAoB,8CACpB,IAAI;AAAA,IAEL;AAAA,EACD;AAEM,SAAAC,WAAAA,WACN,4DACA,IAAI;AAGL,QAAM,mBAA6B,CAAA;AAEnC,MAAI,OAAO,kBAAkB;AAC5B,UAAM,4BAAsC,CAAA;AAEjC,eAAA,SAAS,OAAO,kBAAkB;AAC5C,YAAM,iBAAiBC,oBAAAA,oBAAoB;AAAA,QAC1C;AAAA,QACA,WAAW,OAAO;AAAA,QAClB;AAAA,QACA,OAAO,iBAAiB,QAAQ;AAAA,MAAA,CAChC;AAEU,iBAAA,iBAAiB,eAAe,gBAAgB;AACnD,eAAAD,WAAAA,WAAW,cAAc,MAAM,IAAI;AAAA,MAC1C;AAEM,aAAAA,WAAAA,WAAW,eAAe,MAAM,IAAI;AAEjB,gCAAA,KAAK,eAAe,IAAI;AAEjC,uBAAA,KAAK,eAAe,IAAI;AACxB,uBAAA,KAAK,eAAe,QAAQ;AAAA,IAC7C;AAEG,QAAA,OAAO,iBAAiB,SAAS,GAAG;AACvC,YAAM,4BAA4B;AAC5B,YAAA,wBAAwBE,sBAAW,yBAAyB;AAElE,aAAOF,WAAAA,WACN,eAAe,+BAA+B,0BAC9C,IAAI;AAGL,uBAAiB,KAAK,yBAAyB;AAAA,IAC/C;AAAA,EACD;AAED,MAAI,OAAO,mBAAmB;AAClB,eAAA,SAAS,OAAO,mBAAmB;AAC7C,YAAM,kBAAkBG,qBAAAA,qBAAqB;AAAA,QAC5C;AAAA,QACA;AAAA,QACA,OAAO,iBAAiB,QAAQ;AAAA,MAAA,CAChC;AAEM,aAAAH,WAAAA,WAAW,gBAAgB,MAAM,IAAI;AAE3B,uBAAA,KAAK,gBAAgB,IAAI;AACzB,uBAAA,KAAK,gBAAgB,kBAAkB;AACvC,uBAAA,KAAK,GAAG,gBAAgB,cAAc;AAAA,IACvD;AAAA,EACD;AAED,QACC,YAAO,sBAAP,mBAA0B,mCAC1B,YAAO,sBAAP,mBAA0B,0BACzB;AACD,QAAI,mBAAmB;AAEnB,QAAA,OAAO,kBAAkB,8BAA8B;AAC1D,aAAK,YAAO,qBAAP,mBAAyB,WAAU,KAAK,GAAG;AAC/C,2BAAmBA,WAClB,WAAA;AAAA,gDAC2C,mCAAmC;AAAA,IAE9E,gBAAgB;AAAA,MAAA,OAEX;AACN,2BAAmBA,WAClB,WAAA;AAAA,gDAC2C,mCAAmC;AAAA,IAE9E,gBAAgB;AAAA,MAEjB;AAAA,IACD;AAEG,QAAA,OAAO,kBAAkB,yBAAyB;AACrD,yBAAmBA,WAClB,WAAAI;;;SAGK,iBAAiB,KAAK,KAAK;AAAA;AAAA;AAAA,OAIhC,gBAAgB;AAAA,IAEjB;AAED,WAAOJ,WACN,WAAAI;;OAEI;AAAA;AAAA,MAGJ,IAAI;AAAA,EAEL;AAEM,SAAA;AACR;;"}
|
package/dist/generateTypes.d.ts
CHANGED
|
@@ -11,5 +11,6 @@ export type GenerateTypesConfig = {
|
|
|
11
11
|
includeCreateClientInterface?: boolean;
|
|
12
12
|
includeContentNamespace?: boolean;
|
|
13
13
|
};
|
|
14
|
+
cache?: boolean;
|
|
14
15
|
};
|
|
15
|
-
export declare
|
|
16
|
+
export declare function generateTypes(config?: GenerateTypesConfig): string;
|
package/dist/generateTypes.js
CHANGED
|
@@ -1,113 +1,94 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
const
|
|
1
|
+
import { source } from "common-tags";
|
|
2
|
+
import QuickLRU from "quick-lru";
|
|
3
|
+
import { addLine } from "./lib/addLine.js";
|
|
4
|
+
import { addSection } from "./lib/addSection.js";
|
|
5
|
+
import { buildCustomTypeType } from "./lib/buildCustomTypeType.js";
|
|
6
|
+
import { buildSharedSliceType } from "./lib/buildSharedSliceType.js";
|
|
7
|
+
import { buildUnion } from "./lib/buildUnion.js";
|
|
8
|
+
const cache = new QuickLRU({ maxSize: 1e3 });
|
|
9
|
+
function generateTypes(config = {}) {
|
|
10
|
+
var _a, _b, _c, _d, _e;
|
|
11
|
+
const fieldConfigs = config.fieldConfigs || {};
|
|
12
|
+
const shouldUseCache = config.cache ?? true;
|
|
13
|
+
let code = "";
|
|
13
14
|
const typesProvider = config.typesProvider || "@prismicio/types";
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
name: "T"
|
|
25
|
-
}
|
|
26
|
-
],
|
|
27
|
-
type: `{ [KeyType in keyof T]: T[KeyType] }`
|
|
28
|
-
});
|
|
15
|
+
let clientImportName = "prismic";
|
|
16
|
+
code = addLine(`import type * as prismic from "${typesProvider}";`, code);
|
|
17
|
+
if (((_a = config.clientIntegration) == null ? void 0 : _a.includeCreateClientInterface) || ((_b = config.clientIntegration) == null ? void 0 : _b.includeContentNamespace)) {
|
|
18
|
+
if (typesProvider !== "@prismicio/client") {
|
|
19
|
+
clientImportName = "prismicClient";
|
|
20
|
+
code = addLine(`import type * as ${clientImportName} from "@prismicio/client";`, code);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
code = addSection(`type Simplify<T> = { [KeyType in keyof T]: T[KeyType] };`, code);
|
|
24
|
+
const contentTypeNames = [];
|
|
29
25
|
if (config.customTypeModels) {
|
|
26
|
+
const allDocumentTypesTypeNames = [];
|
|
30
27
|
for (const model of config.customTypeModels) {
|
|
31
|
-
|
|
28
|
+
const customTypeType = buildCustomTypeType({
|
|
32
29
|
model,
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
30
|
+
localeIDs: config.localeIDs,
|
|
31
|
+
fieldConfigs,
|
|
32
|
+
cache: shouldUseCache ? cache : void 0
|
|
36
33
|
});
|
|
34
|
+
for (const auxiliaryType of customTypeType.auxiliaryTypes) {
|
|
35
|
+
code = addSection(auxiliaryType.code, code);
|
|
36
|
+
}
|
|
37
|
+
code = addSection(customTypeType.code, code);
|
|
38
|
+
allDocumentTypesTypeNames.push(customTypeType.name);
|
|
39
|
+
contentTypeNames.push(customTypeType.name);
|
|
40
|
+
contentTypeNames.push(customTypeType.dataName);
|
|
37
41
|
}
|
|
38
42
|
if (config.customTypeModels.length > 0) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
});
|
|
43
|
+
const allDocumentTypesUnionName = "AllDocumentTypes";
|
|
44
|
+
const allDocumentTypesUnion = buildUnion(allDocumentTypesTypeNames);
|
|
45
|
+
code = addSection(`export type ${allDocumentTypesUnionName} = ${allDocumentTypesUnion};`, code);
|
|
46
|
+
contentTypeNames.push(allDocumentTypesUnionName);
|
|
44
47
|
}
|
|
45
48
|
}
|
|
46
49
|
if (config.sharedSliceModels) {
|
|
47
50
|
for (const model of config.sharedSliceModels) {
|
|
48
|
-
|
|
51
|
+
const sharedSliceType = buildSharedSliceType({
|
|
49
52
|
model,
|
|
50
|
-
|
|
51
|
-
|
|
53
|
+
fieldConfigs,
|
|
54
|
+
cache: shouldUseCache ? cache : void 0
|
|
52
55
|
});
|
|
56
|
+
code = addSection(sharedSliceType.code, code);
|
|
57
|
+
contentTypeNames.push(sharedSliceType.name);
|
|
58
|
+
contentTypeNames.push(sharedSliceType.variationUnionName);
|
|
59
|
+
contentTypeNames.push(...sharedSliceType.variationNames);
|
|
53
60
|
}
|
|
54
61
|
}
|
|
55
|
-
if (((
|
|
56
|
-
let
|
|
57
|
-
if (typesProvider !== "@prismicio/client") {
|
|
58
|
-
clientNamespaceImportName = "prismicClient";
|
|
59
|
-
sourceFile.addImportDeclaration({
|
|
60
|
-
moduleSpecifier: "@prismicio/client",
|
|
61
|
-
namespaceImport: clientNamespaceImportName,
|
|
62
|
-
isTypeOnly: true
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
const clientModuleDeclaration = sourceFile.addModule({
|
|
66
|
-
name: '"@prismicio/client"',
|
|
67
|
-
hasDeclareKeyword: true,
|
|
68
|
-
declarationKind: ModuleDeclarationKind.Module
|
|
69
|
-
});
|
|
62
|
+
if (((_c = config.clientIntegration) == null ? void 0 : _c.includeCreateClientInterface) || ((_d = config.clientIntegration) == null ? void 0 : _d.includeContentNamespace)) {
|
|
63
|
+
let clientModuleCode = "";
|
|
70
64
|
if (config.clientIntegration.includeCreateClientInterface) {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
{
|
|
81
|
-
name: "options",
|
|
82
|
-
type: `${clientNamespaceImportName}.ClientConfig`,
|
|
83
|
-
hasQuestionToken: true
|
|
84
|
-
}
|
|
85
|
-
],
|
|
86
|
-
returnType: (((_c = config.customTypeModels) == null ? void 0 : _c.length) || 0) > 0 ? `${clientNamespaceImportName}.Client<AllDocumentTypes>` : `${clientNamespaceImportName}.Client`
|
|
87
|
-
}
|
|
88
|
-
]
|
|
89
|
-
});
|
|
65
|
+
if ((((_e = config.customTypeModels) == null ? void 0 : _e.length) || 0) > 0) {
|
|
66
|
+
clientModuleCode = addSection(`interface CreateClient {
|
|
67
|
+
(repositoryNameOrEndpoint: string, options?: ${clientImportName}.ClientConfig): ${clientImportName}.Client<AllDocumentTypes>;
|
|
68
|
+
}`, clientModuleCode);
|
|
69
|
+
} else {
|
|
70
|
+
clientModuleCode = addSection(`interface CreateClient {
|
|
71
|
+
(repositoryNameOrEndpoint: string, options?: ${clientImportName}.ClientConfig): ${clientImportName}.Client;
|
|
72
|
+
}`, clientModuleCode);
|
|
73
|
+
}
|
|
90
74
|
}
|
|
91
75
|
if (config.clientIntegration.includeContentNamespace) {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
contentNamespaceDeclaration.addExportDeclaration({
|
|
100
|
-
isTypeOnly: true,
|
|
101
|
-
namedExports: exportSymbols.map((exportSymbol) => {
|
|
102
|
-
return {
|
|
103
|
-
name: exportSymbol.getName()
|
|
104
|
-
};
|
|
105
|
-
})
|
|
106
|
-
});
|
|
76
|
+
clientModuleCode = addSection(source`
|
|
77
|
+
namespace Content {
|
|
78
|
+
export type {
|
|
79
|
+
${contentTypeNames.join(",\n")}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
`, clientModuleCode);
|
|
107
83
|
}
|
|
84
|
+
code = addSection(source`
|
|
85
|
+
declare module "@prismicio/client" {
|
|
86
|
+
${clientModuleCode}
|
|
87
|
+
}
|
|
88
|
+
`, code);
|
|
108
89
|
}
|
|
109
|
-
return
|
|
110
|
-
}
|
|
90
|
+
return code;
|
|
91
|
+
}
|
|
111
92
|
export {
|
|
112
93
|
generateTypes
|
|
113
94
|
};
|