prismic-ts-codegen 0.1.9 → 0.1.10
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/generateTypes.cjs
CHANGED
|
@@ -12,8 +12,9 @@ const generateTypes = (config = {}) => {
|
|
|
12
12
|
useInMemoryFileSystem: true
|
|
13
13
|
});
|
|
14
14
|
const sourceFile = project.createSourceFile("types.d.ts");
|
|
15
|
+
const typesProvider = config.typesProvider || "@prismicio/types";
|
|
15
16
|
sourceFile.addImportDeclaration({
|
|
16
|
-
moduleSpecifier:
|
|
17
|
+
moduleSpecifier: typesProvider,
|
|
17
18
|
namespaceImport: "prismic",
|
|
18
19
|
isTypeOnly: true
|
|
19
20
|
});
|
|
@@ -54,10 +55,12 @@ const generateTypes = (config = {}) => {
|
|
|
54
55
|
}
|
|
55
56
|
}
|
|
56
57
|
if (((_a = config.clientIntegration) == null ? void 0 : _a.includeCreateClientInterface) || ((_b = config.clientIntegration) == null ? void 0 : _b.includeContentNamespace)) {
|
|
57
|
-
|
|
58
|
+
let clientNamespaceImportName = "prismic";
|
|
59
|
+
if (typesProvider !== "@prismicio/client") {
|
|
60
|
+
clientNamespaceImportName = "prismicClient";
|
|
58
61
|
sourceFile.addImportDeclaration({
|
|
59
62
|
moduleSpecifier: "@prismicio/client",
|
|
60
|
-
namespaceImport:
|
|
63
|
+
namespaceImport: clientNamespaceImportName,
|
|
61
64
|
isTypeOnly: true
|
|
62
65
|
});
|
|
63
66
|
}
|
|
@@ -78,11 +81,11 @@ const generateTypes = (config = {}) => {
|
|
|
78
81
|
},
|
|
79
82
|
{
|
|
80
83
|
name: "options",
|
|
81
|
-
type:
|
|
84
|
+
type: `${clientNamespaceImportName}.ClientConfig`,
|
|
82
85
|
hasQuestionToken: true
|
|
83
86
|
}
|
|
84
87
|
],
|
|
85
|
-
returnType: (((_c = config.customTypeModels) == null ? void 0 : _c.length) || 0) > 0 ?
|
|
88
|
+
returnType: (((_c = config.customTypeModels) == null ? void 0 : _c.length) || 0) > 0 ? `${clientNamespaceImportName}.Client<AllDocumentTypes>` : `${clientNamespaceImportName}.Client`
|
|
86
89
|
}
|
|
87
90
|
]
|
|
88
91
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateTypes.cjs","sources":["../../src/generateTypes.ts"],"sourcesContent":["import type { CustomTypeModel, SharedSliceModel } from \"@prismicio/client\";\nimport { ModuleDeclarationKind, Project } from \"ts-morph\";\n\nimport { addTypeAliasForCustomType } from \"./lib/addTypeAliasForCustomType\";\nimport { addTypeAliasForSharedSlice } from \"./lib/addTypeAliasForSharedSlice\";\nimport { buildTypeName } from \"./lib/buildTypeName\";\nimport { getSourceFileText } from \"./lib/getSourceFileText\";\n\nimport { FieldConfigs } from \"./types\";\n\nimport { BLANK_LINE_IDENTIFIER } from \"./constants\";\n\nexport type TypesProvider = \"@prismicio/client\" | \"@prismicio/types\";\n\nexport type GenerateTypesConfig = {\n\tcustomTypeModels?: CustomTypeModel[];\n\tsharedSliceModels?: SharedSliceModel[];\n\tlocaleIDs?: string[];\n\tfieldConfigs?: FieldConfigs;\n\ttypesProvider?: TypesProvider;\n\tclientIntegration?: {\n\t\tincludeCreateClientInterface?: boolean;\n\t\tincludeContentNamespace?: boolean;\n\t};\n};\n\nexport const generateTypes = (config: GenerateTypesConfig = {}) => {\n\tconst project = new Project({\n\t\tuseInMemoryFileSystem: true,\n\t});\n\n\tconst sourceFile = project.createSourceFile(\"types.d.ts\");\n\n\
|
|
1
|
+
{"version":3,"file":"generateTypes.cjs","sources":["../../src/generateTypes.ts"],"sourcesContent":["import type { CustomTypeModel, SharedSliceModel } from \"@prismicio/client\";\nimport { ModuleDeclarationKind, Project } from \"ts-morph\";\n\nimport { addTypeAliasForCustomType } from \"./lib/addTypeAliasForCustomType\";\nimport { addTypeAliasForSharedSlice } from \"./lib/addTypeAliasForSharedSlice\";\nimport { buildTypeName } from \"./lib/buildTypeName\";\nimport { getSourceFileText } from \"./lib/getSourceFileText\";\n\nimport { FieldConfigs } from \"./types\";\n\nimport { BLANK_LINE_IDENTIFIER } from \"./constants\";\n\nexport type TypesProvider = \"@prismicio/client\" | \"@prismicio/types\";\n\nexport type GenerateTypesConfig = {\n\tcustomTypeModels?: CustomTypeModel[];\n\tsharedSliceModels?: SharedSliceModel[];\n\tlocaleIDs?: string[];\n\tfieldConfigs?: FieldConfigs;\n\ttypesProvider?: TypesProvider;\n\tclientIntegration?: {\n\t\tincludeCreateClientInterface?: boolean;\n\t\tincludeContentNamespace?: boolean;\n\t};\n};\n\nexport const generateTypes = (config: GenerateTypesConfig = {}) => {\n\tconst project = new Project({\n\t\tuseInMemoryFileSystem: true,\n\t});\n\n\tconst sourceFile = project.createSourceFile(\"types.d.ts\");\n\n\tconst typesProvider = config.typesProvider || \"@prismicio/types\";\n\n\tsourceFile.addImportDeclaration({\n\t\tmoduleSpecifier: typesProvider,\n\t\tnamespaceImport: \"prismic\",\n\t\tisTypeOnly: true,\n\t});\n\n\tsourceFile.addStatements(BLANK_LINE_IDENTIFIER);\n\n\tconst simplifyTypeAlias = sourceFile.addTypeAlias({\n\t\tname: \"Simplify\",\n\t\ttypeParameters: [\n\t\t\t{\n\t\t\t\tname: \"T\",\n\t\t\t},\n\t\t],\n\t\ttype: `{ [KeyType in keyof T]: T[KeyType] }`,\n\t});\n\n\tif (config.customTypeModels) {\n\t\tfor (const model of config.customTypeModels) {\n\t\t\taddTypeAliasForCustomType({\n\t\t\t\tmodel,\n\t\t\t\tsourceFile,\n\t\t\t\tlocaleIDs: config.localeIDs || [],\n\t\t\t\tfieldConfigs: config.fieldConfigs || {},\n\t\t\t});\n\t\t}\n\n\t\tif (config.customTypeModels.length > 0) {\n\t\t\tsourceFile.addTypeAlias({\n\t\t\t\tname: \"AllDocumentTypes\",\n\t\t\t\ttype: config.customTypeModels\n\t\t\t\t\t.map((customTypeModel) =>\n\t\t\t\t\t\tbuildTypeName(customTypeModel.id, \"Document\"),\n\t\t\t\t\t)\n\t\t\t\t\t.join(\" | \"),\n\t\t\t\tisExported: true,\n\t\t\t});\n\t\t}\n\t}\n\n\tif (config.sharedSliceModels) {\n\t\tfor (const model of config.sharedSliceModels) {\n\t\t\taddTypeAliasForSharedSlice({\n\t\t\t\tmodel,\n\t\t\t\tsourceFile,\n\t\t\t\tfieldConfigs: config.fieldConfigs || {},\n\t\t\t});\n\t\t}\n\t}\n\n\tif (\n\t\tconfig.clientIntegration?.includeCreateClientInterface ||\n\t\tconfig.clientIntegration?.includeContentNamespace\n\t) {\n\t\tlet clientNamespaceImportName = \"prismic\";\n\n\t\tif (typesProvider !== \"@prismicio/client\") {\n\t\t\tclientNamespaceImportName = \"prismicClient\";\n\n\t\t\t// This import declaration would be a duplicate if the types\n\t\t\t// provider is @prismicio/client.\n\t\t\tsourceFile.addImportDeclaration({\n\t\t\t\tmoduleSpecifier: \"@prismicio/client\",\n\t\t\t\tnamespaceImport: clientNamespaceImportName,\n\t\t\t\tisTypeOnly: true,\n\t\t\t});\n\t\t}\n\n\t\tconst clientModuleDeclaration = sourceFile.addModule({\n\t\t\tname: '\"@prismicio/client\"',\n\t\t\thasDeclareKeyword: true,\n\t\t\tdeclarationKind: ModuleDeclarationKind.Module,\n\t\t});\n\n\t\tif (config.clientIntegration.includeCreateClientInterface) {\n\t\t\tclientModuleDeclaration.addInterface({\n\t\t\t\tname: \"CreateClient\",\n\t\t\t\tcallSignatures: [\n\t\t\t\t\t{\n\t\t\t\t\t\tparameters: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tname: \"repositoryNameOrEndpoint\",\n\t\t\t\t\t\t\t\ttype: \"string\",\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tname: \"options\",\n\t\t\t\t\t\t\t\ttype: `${clientNamespaceImportName}.ClientConfig`,\n\t\t\t\t\t\t\t\thasQuestionToken: true,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t\treturnType:\n\t\t\t\t\t\t\t(config.customTypeModels?.length || 0) > 0\n\t\t\t\t\t\t\t\t? `${clientNamespaceImportName}.Client<AllDocumentTypes>`\n\t\t\t\t\t\t\t\t: `${clientNamespaceImportName}.Client`,\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t});\n\t\t}\n\n\t\tif (config.clientIntegration.includeContentNamespace) {\n\t\t\tconst contentNamespaceDeclaration = clientModuleDeclaration.addModule({\n\t\t\t\tname: \"Content\",\n\t\t\t\tdeclarationKind: ModuleDeclarationKind.Namespace,\n\t\t\t});\n\n\t\t\tconst exportSymbols = sourceFile\n\t\t\t\t.getExportSymbols()\n\t\t\t\t.filter((exportSymbol) => {\n\t\t\t\t\t// The Simplify utility type should not\n\t\t\t\t\t// be exported, but it is included in\n\t\t\t\t\t// `getExportSymbols()`'s result.\n\t\t\t\t\treturn exportSymbol.getName() !== simplifyTypeAlias.getName();\n\t\t\t\t});\n\n\t\t\tcontentNamespaceDeclaration.addExportDeclaration({\n\t\t\t\tisTypeOnly: true,\n\t\t\t\tnamedExports: exportSymbols.map((exportSymbol) => {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tname: exportSymbol.getName(),\n\t\t\t\t\t};\n\t\t\t\t}),\n\t\t\t});\n\t\t}\n\t}\n\n\treturn getSourceFileText(sourceFile);\n};\n"],"names":["Project","BLANK_LINE_IDENTIFIER","addTypeAliasForCustomType","buildTypeName","addTypeAliasForSharedSlice","ModuleDeclarationKind","getSourceFileText"],"mappings":";;;;;;;;AA0BO,MAAM,gBAAgB,CAAC,SAA8B,OAAM;;AAC3D,QAAA,UAAU,IAAIA,gBAAQ;AAAA,IAC3B,uBAAuB;AAAA,EAAA,CACvB;AAEK,QAAA,aAAa,QAAQ,iBAAiB,YAAY;AAElD,QAAA,gBAAgB,OAAO,iBAAiB;AAE9C,aAAW,qBAAqB;AAAA,IAC/B,iBAAiB;AAAA,IACjB,iBAAiB;AAAA,IACjB,YAAY;AAAA,EAAA,CACZ;AAED,aAA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AA,QACN,gBAAgB;AAAA,UACf;AAAA,YACC,YAAY;AAAA,cACX;AAAA,gBACC,MAAM;AAAA,gBACN,MAAM;AAAA,cACN;AAAA,cACD;AAAA,gBACC,MAAM;AAAA,gBACN,MAAM,GAAG;AAAA,gBACT,kBAAkB;AAAA,cAClB;AAAA,YACD;AAAA,YACD,eACE,YAAO,qBAAP,mBAAyB,WAAU,KAAK,IACtC,GAAG,uDACH,GAAG;AAAA,UACP;AAAA,QACD;AAAA,MAAA,CACD;AAAA,IACD;AAEG,QAAA,OAAO,kBAAkB,yBAAyB;AAC/C,YAAA,8BAA8B,wBAAwB,UAAU;AAAA,QACrE,MAAM;AAAA,QACN,iBAAiBA,QAAsB,sBAAA;AAAA,MAAA,CACvC;AAED,YAAM,gBAAgB,WACpB,iBACA,EAAA,OAAO,CAAC,iBAAgB;AAIxB,eAAO,aAAa,QAAA,MAAc,kBAAkB,QAAO;AAAA,MAAA,CAC3D;AAEF,kCAA4B,qBAAqB;AAAA,QAChD,YAAY;AAAA,QACZ,cAAc,cAAc,IAAI,CAAC,iBAAgB;AACzC,iBAAA;AAAA,YACN,MAAM,aAAa,QAAS;AAAA,UAAA;AAAA,SAE7B;AAAA,MAAA,CACD;AAAA,IACD;AAAA,EACD;AAED,SAAOC,kBAAAA,kBAAkB,UAAU;AACpC;;"}
|
package/dist/generateTypes.js
CHANGED
|
@@ -10,8 +10,9 @@ const generateTypes = (config = {}) => {
|
|
|
10
10
|
useInMemoryFileSystem: true
|
|
11
11
|
});
|
|
12
12
|
const sourceFile = project.createSourceFile("types.d.ts");
|
|
13
|
+
const typesProvider = config.typesProvider || "@prismicio/types";
|
|
13
14
|
sourceFile.addImportDeclaration({
|
|
14
|
-
moduleSpecifier:
|
|
15
|
+
moduleSpecifier: typesProvider,
|
|
15
16
|
namespaceImport: "prismic",
|
|
16
17
|
isTypeOnly: true
|
|
17
18
|
});
|
|
@@ -52,10 +53,12 @@ const generateTypes = (config = {}) => {
|
|
|
52
53
|
}
|
|
53
54
|
}
|
|
54
55
|
if (((_a = config.clientIntegration) == null ? void 0 : _a.includeCreateClientInterface) || ((_b = config.clientIntegration) == null ? void 0 : _b.includeContentNamespace)) {
|
|
55
|
-
|
|
56
|
+
let clientNamespaceImportName = "prismic";
|
|
57
|
+
if (typesProvider !== "@prismicio/client") {
|
|
58
|
+
clientNamespaceImportName = "prismicClient";
|
|
56
59
|
sourceFile.addImportDeclaration({
|
|
57
60
|
moduleSpecifier: "@prismicio/client",
|
|
58
|
-
namespaceImport:
|
|
61
|
+
namespaceImport: clientNamespaceImportName,
|
|
59
62
|
isTypeOnly: true
|
|
60
63
|
});
|
|
61
64
|
}
|
|
@@ -76,11 +79,11 @@ const generateTypes = (config = {}) => {
|
|
|
76
79
|
},
|
|
77
80
|
{
|
|
78
81
|
name: "options",
|
|
79
|
-
type:
|
|
82
|
+
type: `${clientNamespaceImportName}.ClientConfig`,
|
|
80
83
|
hasQuestionToken: true
|
|
81
84
|
}
|
|
82
85
|
],
|
|
83
|
-
returnType: (((_c = config.customTypeModels) == null ? void 0 : _c.length) || 0) > 0 ?
|
|
86
|
+
returnType: (((_c = config.customTypeModels) == null ? void 0 : _c.length) || 0) > 0 ? `${clientNamespaceImportName}.Client<AllDocumentTypes>` : `${clientNamespaceImportName}.Client`
|
|
84
87
|
}
|
|
85
88
|
]
|
|
86
89
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateTypes.js","sources":["../../src/generateTypes.ts"],"sourcesContent":["import type { CustomTypeModel, SharedSliceModel } from \"@prismicio/client\";\nimport { ModuleDeclarationKind, Project } from \"ts-morph\";\n\nimport { addTypeAliasForCustomType } from \"./lib/addTypeAliasForCustomType\";\nimport { addTypeAliasForSharedSlice } from \"./lib/addTypeAliasForSharedSlice\";\nimport { buildTypeName } from \"./lib/buildTypeName\";\nimport { getSourceFileText } from \"./lib/getSourceFileText\";\n\nimport { FieldConfigs } from \"./types\";\n\nimport { BLANK_LINE_IDENTIFIER } from \"./constants\";\n\nexport type TypesProvider = \"@prismicio/client\" | \"@prismicio/types\";\n\nexport type GenerateTypesConfig = {\n\tcustomTypeModels?: CustomTypeModel[];\n\tsharedSliceModels?: SharedSliceModel[];\n\tlocaleIDs?: string[];\n\tfieldConfigs?: FieldConfigs;\n\ttypesProvider?: TypesProvider;\n\tclientIntegration?: {\n\t\tincludeCreateClientInterface?: boolean;\n\t\tincludeContentNamespace?: boolean;\n\t};\n};\n\nexport const generateTypes = (config: GenerateTypesConfig = {}) => {\n\tconst project = new Project({\n\t\tuseInMemoryFileSystem: true,\n\t});\n\n\tconst sourceFile = project.createSourceFile(\"types.d.ts\");\n\n\
|
|
1
|
+
{"version":3,"file":"generateTypes.js","sources":["../../src/generateTypes.ts"],"sourcesContent":["import type { CustomTypeModel, SharedSliceModel } from \"@prismicio/client\";\nimport { ModuleDeclarationKind, Project } from \"ts-morph\";\n\nimport { addTypeAliasForCustomType } from \"./lib/addTypeAliasForCustomType\";\nimport { addTypeAliasForSharedSlice } from \"./lib/addTypeAliasForSharedSlice\";\nimport { buildTypeName } from \"./lib/buildTypeName\";\nimport { getSourceFileText } from \"./lib/getSourceFileText\";\n\nimport { FieldConfigs } from \"./types\";\n\nimport { BLANK_LINE_IDENTIFIER } from \"./constants\";\n\nexport type TypesProvider = \"@prismicio/client\" | \"@prismicio/types\";\n\nexport type GenerateTypesConfig = {\n\tcustomTypeModels?: CustomTypeModel[];\n\tsharedSliceModels?: SharedSliceModel[];\n\tlocaleIDs?: string[];\n\tfieldConfigs?: FieldConfigs;\n\ttypesProvider?: TypesProvider;\n\tclientIntegration?: {\n\t\tincludeCreateClientInterface?: boolean;\n\t\tincludeContentNamespace?: boolean;\n\t};\n};\n\nexport const generateTypes = (config: GenerateTypesConfig = {}) => {\n\tconst project = new Project({\n\t\tuseInMemoryFileSystem: true,\n\t});\n\n\tconst sourceFile = project.createSourceFile(\"types.d.ts\");\n\n\tconst typesProvider = config.typesProvider || \"@prismicio/types\";\n\n\tsourceFile.addImportDeclaration({\n\t\tmoduleSpecifier: typesProvider,\n\t\tnamespaceImport: \"prismic\",\n\t\tisTypeOnly: true,\n\t});\n\n\tsourceFile.addStatements(BLANK_LINE_IDENTIFIER);\n\n\tconst simplifyTypeAlias = sourceFile.addTypeAlias({\n\t\tname: \"Simplify\",\n\t\ttypeParameters: [\n\t\t\t{\n\t\t\t\tname: \"T\",\n\t\t\t},\n\t\t],\n\t\ttype: `{ [KeyType in keyof T]: T[KeyType] }`,\n\t});\n\n\tif (config.customTypeModels) {\n\t\tfor (const model of config.customTypeModels) {\n\t\t\taddTypeAliasForCustomType({\n\t\t\t\tmodel,\n\t\t\t\tsourceFile,\n\t\t\t\tlocaleIDs: config.localeIDs || [],\n\t\t\t\tfieldConfigs: config.fieldConfigs || {},\n\t\t\t});\n\t\t}\n\n\t\tif (config.customTypeModels.length > 0) {\n\t\t\tsourceFile.addTypeAlias({\n\t\t\t\tname: \"AllDocumentTypes\",\n\t\t\t\ttype: config.customTypeModels\n\t\t\t\t\t.map((customTypeModel) =>\n\t\t\t\t\t\tbuildTypeName(customTypeModel.id, \"Document\"),\n\t\t\t\t\t)\n\t\t\t\t\t.join(\" | \"),\n\t\t\t\tisExported: true,\n\t\t\t});\n\t\t}\n\t}\n\n\tif (config.sharedSliceModels) {\n\t\tfor (const model of config.sharedSliceModels) {\n\t\t\taddTypeAliasForSharedSlice({\n\t\t\t\tmodel,\n\t\t\t\tsourceFile,\n\t\t\t\tfieldConfigs: config.fieldConfigs || {},\n\t\t\t});\n\t\t}\n\t}\n\n\tif (\n\t\tconfig.clientIntegration?.includeCreateClientInterface ||\n\t\tconfig.clientIntegration?.includeContentNamespace\n\t) {\n\t\tlet clientNamespaceImportName = \"prismic\";\n\n\t\tif (typesProvider !== \"@prismicio/client\") {\n\t\t\tclientNamespaceImportName = \"prismicClient\";\n\n\t\t\t// This import declaration would be a duplicate if the types\n\t\t\t// provider is @prismicio/client.\n\t\t\tsourceFile.addImportDeclaration({\n\t\t\t\tmoduleSpecifier: \"@prismicio/client\",\n\t\t\t\tnamespaceImport: clientNamespaceImportName,\n\t\t\t\tisTypeOnly: true,\n\t\t\t});\n\t\t}\n\n\t\tconst clientModuleDeclaration = sourceFile.addModule({\n\t\t\tname: '\"@prismicio/client\"',\n\t\t\thasDeclareKeyword: true,\n\t\t\tdeclarationKind: ModuleDeclarationKind.Module,\n\t\t});\n\n\t\tif (config.clientIntegration.includeCreateClientInterface) {\n\t\t\tclientModuleDeclaration.addInterface({\n\t\t\t\tname: \"CreateClient\",\n\t\t\t\tcallSignatures: [\n\t\t\t\t\t{\n\t\t\t\t\t\tparameters: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tname: \"repositoryNameOrEndpoint\",\n\t\t\t\t\t\t\t\ttype: \"string\",\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tname: \"options\",\n\t\t\t\t\t\t\t\ttype: `${clientNamespaceImportName}.ClientConfig`,\n\t\t\t\t\t\t\t\thasQuestionToken: true,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t\treturnType:\n\t\t\t\t\t\t\t(config.customTypeModels?.length || 0) > 0\n\t\t\t\t\t\t\t\t? `${clientNamespaceImportName}.Client<AllDocumentTypes>`\n\t\t\t\t\t\t\t\t: `${clientNamespaceImportName}.Client`,\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t});\n\t\t}\n\n\t\tif (config.clientIntegration.includeContentNamespace) {\n\t\t\tconst contentNamespaceDeclaration = clientModuleDeclaration.addModule({\n\t\t\t\tname: \"Content\",\n\t\t\t\tdeclarationKind: ModuleDeclarationKind.Namespace,\n\t\t\t});\n\n\t\t\tconst exportSymbols = sourceFile\n\t\t\t\t.getExportSymbols()\n\t\t\t\t.filter((exportSymbol) => {\n\t\t\t\t\t// The Simplify utility type should not\n\t\t\t\t\t// be exported, but it is included in\n\t\t\t\t\t// `getExportSymbols()`'s result.\n\t\t\t\t\treturn exportSymbol.getName() !== simplifyTypeAlias.getName();\n\t\t\t\t});\n\n\t\t\tcontentNamespaceDeclaration.addExportDeclaration({\n\t\t\t\tisTypeOnly: true,\n\t\t\t\tnamedExports: exportSymbols.map((exportSymbol) => {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tname: exportSymbol.getName(),\n\t\t\t\t\t};\n\t\t\t\t}),\n\t\t\t});\n\t\t}\n\t}\n\n\treturn getSourceFileText(sourceFile);\n};\n"],"names":[],"mappings":";;;;;;AA0BO,MAAM,gBAAgB,CAAC,SAA8B,OAAM;;AAC3D,QAAA,UAAU,IAAI,QAAQ;AAAA,IAC3B,uBAAuB;AAAA,EAAA,CACvB;AAEK,QAAA,aAAa,QAAQ,iBAAiB,YAAY;AAElD,QAAA,gBAAgB,OAAO,iBAAiB;AAE9C,aAAW,qBAAqB;AAAA,IAC/B,iBAAiB;AAAA,IACjB,iBAAiB;AAAA,IACjB,YAAY;AAAA,EAAA,CACZ;AAED,aAAW,cAAc,qBAAqB;AAExC,QAAA,oBAAoB,WAAW,aAAa;AAAA,IACjD,MAAM;AAAA,IACN,gBAAgB;AAAA,MACf;AAAA,QACC,MAAM;AAAA,MACN;AAAA,IACD;AAAA,IACD,MAAM;AAAA,EAAA,CACN;AAED,MAAI,OAAO,kBAAkB;AACjB,eAAA,SAAS,OAAO,kBAAkB;AAClB,gCAAA;AAAA,QACzB;AAAA,QACA;AAAA,QACA,WAAW,OAAO,aAAa,CAAE;AAAA,QACjC,cAAc,OAAO,gBAAgB,CAAE;AAAA,MAAA,CACvC;AAAA,IACD;AAEG,QAAA,OAAO,iBAAiB,SAAS,GAAG;AACvC,iBAAW,aAAa;AAAA,QACvB,MAAM;AAAA,QACN,MAAM,OAAO,iBACX,IAAI,CAAC,oBACL,cAAc,gBAAgB,IAAI,UAAU,CAAC,EAE7C,KAAK,KAAK;AAAA,QACZ,YAAY;AAAA,MAAA,CACZ;AAAA,IACD;AAAA,EACD;AAED,MAAI,OAAO,mBAAmB;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CAAC,iBAAgB;AACzC,iBAAA;AAAA,YACN,MAAM,aAAa,QAAS;AAAA,UAAA;AAAA,SAE7B;AAAA,MAAA,CACD;AAAA,IACD;AAAA,EACD;AAED,SAAO,kBAAkB,UAAU;AACpC;"}
|
package/package.json
CHANGED
package/src/generateTypes.ts
CHANGED
|
@@ -31,8 +31,10 @@ export const generateTypes = (config: GenerateTypesConfig = {}) => {
|
|
|
31
31
|
|
|
32
32
|
const sourceFile = project.createSourceFile("types.d.ts");
|
|
33
33
|
|
|
34
|
+
const typesProvider = config.typesProvider || "@prismicio/types";
|
|
35
|
+
|
|
34
36
|
sourceFile.addImportDeclaration({
|
|
35
|
-
moduleSpecifier:
|
|
37
|
+
moduleSpecifier: typesProvider,
|
|
36
38
|
namespaceImport: "prismic",
|
|
37
39
|
isTypeOnly: true,
|
|
38
40
|
});
|
|
@@ -86,12 +88,16 @@ export const generateTypes = (config: GenerateTypesConfig = {}) => {
|
|
|
86
88
|
config.clientIntegration?.includeCreateClientInterface ||
|
|
87
89
|
config.clientIntegration?.includeContentNamespace
|
|
88
90
|
) {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
if (
|
|
91
|
+
let clientNamespaceImportName = "prismic";
|
|
92
|
+
|
|
93
|
+
if (typesProvider !== "@prismicio/client") {
|
|
94
|
+
clientNamespaceImportName = "prismicClient";
|
|
95
|
+
|
|
96
|
+
// This import declaration would be a duplicate if the types
|
|
97
|
+
// provider is @prismicio/client.
|
|
92
98
|
sourceFile.addImportDeclaration({
|
|
93
99
|
moduleSpecifier: "@prismicio/client",
|
|
94
|
-
namespaceImport:
|
|
100
|
+
namespaceImport: clientNamespaceImportName,
|
|
95
101
|
isTypeOnly: true,
|
|
96
102
|
});
|
|
97
103
|
}
|
|
@@ -114,14 +120,14 @@ export const generateTypes = (config: GenerateTypesConfig = {}) => {
|
|
|
114
120
|
},
|
|
115
121
|
{
|
|
116
122
|
name: "options",
|
|
117
|
-
type:
|
|
123
|
+
type: `${clientNamespaceImportName}.ClientConfig`,
|
|
118
124
|
hasQuestionToken: true,
|
|
119
125
|
},
|
|
120
126
|
],
|
|
121
127
|
returnType:
|
|
122
128
|
(config.customTypeModels?.length || 0) > 0
|
|
123
|
-
?
|
|
124
|
-
:
|
|
129
|
+
? `${clientNamespaceImportName}.Client<AllDocumentTypes>`
|
|
130
|
+
: `${clientNamespaceImportName}.Client`,
|
|
125
131
|
},
|
|
126
132
|
],
|
|
127
133
|
});
|