prismic-ts-codegen 0.1.29 → 0.1.30
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/bin/prismic-ts-codegen.js +1 -1
- package/dist/cli/{configSchema.d.cts → configSchema.d.mts} +1 -1
- package/dist/cli/{configSchema.d.cts.map → configSchema.d.mts.map} +1 -1
- package/dist/cli/{configSchema.js → configSchema.mjs} +1 -1
- package/dist/cli/configSchema.mjs.map +1 -0
- package/dist/cli/{constants.d.cts → constants.d.mts} +1 -1
- package/dist/cli/constants.d.mts.map +1 -0
- package/dist/cli/{constants.js → constants.mjs} +1 -1
- package/dist/cli/{constants.cjs.map → constants.mjs.map} +1 -1
- package/dist/cli/{loadConfig.js → loadConfig.mjs} +1 -1
- package/dist/cli/loadConfig.mjs.map +1 -0
- package/dist/cli/{loadLocaleIDs.js → loadLocaleIDs.mjs} +1 -1
- package/dist/cli/loadLocaleIDs.mjs.map +1 -0
- package/dist/cli/{loadModels.js → loadModels.mjs} +1 -1
- package/dist/cli/loadModels.mjs.map +1 -0
- package/dist/{cli.js → cli.mjs} +10 -9
- package/dist/cli.mjs.map +1 -0
- package/dist/{constants.js → constants.mjs} +1 -1
- package/dist/{constants.cjs.map → constants.mjs.map} +1 -1
- package/dist/{detectTypesProvider.d.cts → detectTypesProvider.d.mts} +2 -2
- package/dist/{detectTypesProvider.d.cts.map → detectTypesProvider.d.mts.map} +1 -1
- package/dist/{detectTypesProvider.js → detectTypesProvider.mjs} +1 -1
- package/dist/{detectTypesProvider.cjs.map → detectTypesProvider.mjs.map} +1 -1
- package/dist/{generateTypes.d.ts → generateTypes.d.mts} +2 -2
- package/dist/{generateTypes.d.cts.map → generateTypes.d.mts.map} +1 -1
- package/dist/{generateTypes.js → generateTypes.mjs} +6 -6
- package/dist/generateTypes.mjs.map +1 -0
- package/dist/{index.d.cts → index.d.mts} +4 -4
- package/dist/index.mjs +4 -0
- package/dist/lib/{addBlankLine.js → addBlankLine.mjs} +2 -2
- package/dist/lib/addBlankLine.mjs.map +1 -0
- package/dist/lib/{addLine.js → addLine.mjs} +2 -2
- package/dist/lib/addLine.mjs.map +1 -0
- package/dist/lib/{addSection.js → addSection.mjs} +2 -2
- package/dist/lib/addSection.mjs.map +1 -0
- package/dist/lib/{addTrailingNewLine.js → addTrailingNewLine.mjs} +1 -1
- package/dist/lib/{addTrailingNewLine.cjs.map → addTrailingNewLine.mjs.map} +1 -1
- package/dist/lib/{buildCustomTypeDataType.js → buildCustomTypeDataType.mjs} +4 -4
- package/dist/lib/buildCustomTypeDataType.mjs.map +1 -0
- package/dist/lib/{buildCustomTypeType.js → buildCustomTypeType.mjs} +9 -9
- package/dist/lib/buildCustomTypeType.mjs.map +1 -0
- package/dist/lib/{buildFieldDocs.js → buildFieldDocs.mjs} +6 -6
- package/dist/lib/buildFieldDocs.mjs.map +1 -0
- package/dist/lib/{buildFieldProperties.js → buildFieldProperties.mjs} +7 -7
- package/dist/lib/buildFieldProperties.mjs.map +1 -0
- package/dist/lib/{buildSharedSliceType.js → buildSharedSliceType.mjs} +9 -9
- package/dist/lib/buildSharedSliceType.mjs.map +1 -0
- package/dist/lib/{buildTypeName.js → buildTypeName.mjs} +1 -1
- package/dist/lib/buildTypeName.mjs.map +1 -0
- package/dist/lib/{buildUnion.js → buildUnion.mjs} +1 -1
- package/dist/lib/{buildUnion.cjs.map → buildUnion.mjs.map} +1 -1
- package/dist/lib/{checkHasUIDFIeld.js → checkHasUIDFIeld.mjs} +1 -1
- package/dist/lib/{checkHasUIDFIeld.cjs.map → checkHasUIDFIeld.mjs.map} +1 -1
- package/dist/lib/{getAPIIDPath.js → getAPIIDPath.mjs} +1 -1
- package/dist/lib/{getAPIIDPath.cjs.map → getAPIIDPath.mjs.map} +1 -1
- package/dist/lib/{getCacheKey.js → getCacheKey.mjs} +1 -1
- package/dist/lib/getCacheKey.mjs.map +1 -0
- package/dist/lib/{getHumanReadableModelName.js → getHumanReadableModelName.mjs} +1 -1
- package/dist/lib/{getHumanReadableModelName.cjs.map → getHumanReadableModelName.mjs.map} +1 -1
- package/dist/lib/{getHumanReadablePath.js → getHumanReadablePath.mjs} +2 -2
- package/dist/lib/getHumanReadablePath.mjs.map +1 -0
- package/dist/{types.d.cts → types.d.mts} +1 -1
- package/dist/types.d.mts.map +1 -0
- package/package.json +2 -8
- package/dist/_virtual/_rolldown/runtime.cjs +0 -23
- package/dist/cli/configSchema.cjs +0 -31
- package/dist/cli/configSchema.cjs.map +0 -1
- package/dist/cli/configSchema.d.ts +0 -39
- package/dist/cli/configSchema.d.ts.map +0 -1
- package/dist/cli/configSchema.js.map +0 -1
- package/dist/cli/constants.cjs +0 -6
- package/dist/cli/constants.d.cts.map +0 -1
- package/dist/cli/constants.d.ts +0 -5
- package/dist/cli/constants.d.ts.map +0 -1
- package/dist/cli/constants.js.map +0 -1
- package/dist/cli/loadConfig.cjs +0 -22
- package/dist/cli/loadConfig.cjs.map +0 -1
- package/dist/cli/loadConfig.js.map +0 -1
- package/dist/cli/loadLocaleIDs.cjs +0 -21
- package/dist/cli/loadLocaleIDs.cjs.map +0 -1
- package/dist/cli/loadLocaleIDs.js.map +0 -1
- package/dist/cli/loadModels.cjs +0 -54
- package/dist/cli/loadModels.cjs.map +0 -1
- package/dist/cli/loadModels.js.map +0 -1
- package/dist/cli.cjs +0 -110
- package/dist/cli.cjs.map +0 -1
- package/dist/cli.d.ts +0 -1
- package/dist/cli.js.map +0 -1
- package/dist/constants.cjs +0 -33
- package/dist/constants.js.map +0 -1
- package/dist/detectTypesProvider.cjs +0 -25
- package/dist/detectTypesProvider.d.ts +0 -17
- package/dist/detectTypesProvider.d.ts.map +0 -1
- package/dist/detectTypesProvider.js.map +0 -1
- package/dist/generateTypes.cjs +0 -144
- package/dist/generateTypes.cjs.map +0 -1
- package/dist/generateTypes.d.cts +0 -21
- package/dist/generateTypes.d.ts.map +0 -1
- package/dist/generateTypes.js.map +0 -1
- package/dist/index.cjs +0 -7
- package/dist/index.d.ts +0 -5
- package/dist/index.js +0 -4
- package/dist/lib/addBlankLine.cjs +0 -10
- package/dist/lib/addBlankLine.cjs.map +0 -1
- package/dist/lib/addBlankLine.js.map +0 -1
- package/dist/lib/addLine.cjs +0 -9
- package/dist/lib/addLine.cjs.map +0 -1
- package/dist/lib/addLine.js.map +0 -1
- package/dist/lib/addSection.cjs +0 -9
- package/dist/lib/addSection.cjs.map +0 -1
- package/dist/lib/addSection.js.map +0 -1
- package/dist/lib/addTrailingNewLine.cjs +0 -9
- package/dist/lib/addTrailingNewLine.js.map +0 -1
- package/dist/lib/buildCustomTypeDataType.cjs +0 -51
- package/dist/lib/buildCustomTypeDataType.cjs.map +0 -1
- package/dist/lib/buildCustomTypeDataType.js.map +0 -1
- package/dist/lib/buildCustomTypeType.cjs +0 -63
- package/dist/lib/buildCustomTypeType.cjs.map +0 -1
- package/dist/lib/buildCustomTypeType.js.map +0 -1
- package/dist/lib/buildFieldDocs.cjs +0 -66
- package/dist/lib/buildFieldDocs.cjs.map +0 -1
- package/dist/lib/buildFieldDocs.js.map +0 -1
- package/dist/lib/buildFieldProperties.cjs +0 -285
- package/dist/lib/buildFieldProperties.cjs.map +0 -1
- package/dist/lib/buildFieldProperties.js.map +0 -1
- package/dist/lib/buildSharedSliceType.cjs +0 -152
- package/dist/lib/buildSharedSliceType.cjs.map +0 -1
- package/dist/lib/buildSharedSliceType.js.map +0 -1
- package/dist/lib/buildTypeName.cjs +0 -12
- package/dist/lib/buildTypeName.cjs.map +0 -1
- package/dist/lib/buildTypeName.js.map +0 -1
- package/dist/lib/buildUnion.cjs +0 -8
- package/dist/lib/buildUnion.js.map +0 -1
- package/dist/lib/checkHasUIDFIeld.cjs +0 -8
- package/dist/lib/checkHasUIDFIeld.js.map +0 -1
- package/dist/lib/getAPIIDPath.cjs +0 -24
- package/dist/lib/getAPIIDPath.js.map +0 -1
- package/dist/lib/getCacheKey.cjs +0 -17
- package/dist/lib/getCacheKey.cjs.map +0 -1
- package/dist/lib/getCacheKey.js.map +0 -1
- package/dist/lib/getHumanReadableModelName.cjs +0 -15
- package/dist/lib/getHumanReadableModelName.js.map +0 -1
- package/dist/lib/getHumanReadablePath.cjs +0 -16
- package/dist/lib/getHumanReadablePath.cjs.map +0 -1
- package/dist/lib/getHumanReadablePath.js.map +0 -1
- package/dist/types.d.cts.map +0 -1
- package/dist/types.d.ts +0 -14
- package/dist/types.d.ts.map +0 -1
- /package/dist/{cli.d.cts → cli.d.mts} +0 -0
package/dist/cli.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","names":["resolvePath"],"sources":["../src/cli/index.ts"],"sourcesContent":["import { existsSync, writeFileSync } from \"fs\";\nimport { resolve as resolvePath } from \"path\";\n\nimport { stripIndent } from \"common-tags\";\nimport meow from \"meow\";\n\nimport { detectTypesProvider, generateTypes } from \"../index\";\nimport { configSchema } from \"./configSchema\";\nimport { NON_EDITABLE_FILE_HEADER } from \"./constants\";\nimport { loadConfig } from \"./loadConfig\";\nimport { loadLocaleIDs } from \"./loadLocaleIDs\";\nimport { loadModels } from \"./loadModels\";\n\nconst cli = meow(\n\t`\n\tUsage:\n\t prismic-ts-codegen [options...]\n\t prismic-ts-codegen init [options...]\n\n\tCommands:\n\t init [options]\n\n\tOptions:\n\t -c, --config <path> Path to a prismic-ts-codegen configuration file.\n\t`,\n\t{\n\t\timportMeta: import.meta,\n\t\tflags: {\n\t\t\tconfig: {\n\t\t\t\ttype: \"string\",\n\t\t\t\tshortFlag: \"c\",\n\t\t\t\tisRequired: false,\n\t\t\t},\n\t\t},\n\t},\n);\n\nconst main = async () => {\n\tif (cli.input[0] === \"init\") {\n\t\tconst configPath = cli.flags.config || \"prismicCodegen.config.ts\";\n\n\t\tif (existsSync(configPath)) {\n\t\t\tconsole.info(`\\n${configPath} already exists.`);\n\t\t} else {\n\t\t\tlet contents = \"\";\n\n\t\t\tif (existsSync(\"slicemachine.config.json\") || existsSync(\"sm.json\")) {\n\t\t\t\tcontents = stripIndent`\n\t\t\t\t\timport type { Config } from \"prismic-ts-codegen\";\n\n\t\t\t\t\tconst config: Config = {\n\t\t\t\t\t output: \"./types.generated.ts\",\n\t\t\t\t\t models: [\"./customtypes/**/index.json\", \"./slices/**/model.json\"],\n\t\t\t\t\t};\n\n\t\t\t\t\texport default config;\n\t\t\t\t`;\n\t\t\t} else {\n\t\t\t\tcontents = stripIndent`\n\t\t\t\t\timport type { Config } from \"prismic-ts-codegen\";\n\n\t\t\t\t\tconst config: Config = {\n\t\t\t\t\t output: \"./types.generated.ts\",\n\t\t\t\t\t};\n\n\t\t\t\t\texport default config;\n\t\t\t\t`;\n\t\t\t}\n\n\t\t\twriteFileSync(configPath, contents);\n\n\t\t\tconsole.info(`\\nCreated prismic-ts-codegen config file: ${configPath}`);\n\t\t}\n\t} else {\n\t\tconst unvalidatedConfig = loadConfig({ path: cli.flags.config });\n\n\t\tconst result = configSchema.safeParse(unvalidatedConfig);\n\n\t\tif (result.success) {\n\t\t\tconst config = result.data;\n\t\t\tconst { customTypeModels, sharedSliceModels } = await loadModels({\n\t\t\t\tlocalPaths: Array.isArray(config.models) ? config.models : config.models?.files,\n\t\t\t\trepositoryName: config.repositoryName,\n\t\t\t\tcustomTypesAPIToken: config.customTypesAPIToken,\n\t\t\t\tfetchFromRepository:\n\t\t\t\t\tconfig.models &&\n\t\t\t\t\t\"fetchFromRepository\" in config.models &&\n\t\t\t\t\tconfig.models.fetchFromRepository,\n\t\t\t});\n\n\t\t\tconst localeIDs = await loadLocaleIDs({\n\t\t\t\tlocaleIDs: Array.isArray(config.locales) ? config.locales : config.locales?.ids,\n\t\t\t\trepositoryName: config.repositoryName,\n\t\t\t\taccessToken: config.accessToken,\n\t\t\t\tfetchFromRepository:\n\t\t\t\t\tconfig.locales &&\n\t\t\t\t\t\"fetchFromRepository\" in config.locales &&\n\t\t\t\t\tconfig.locales.fetchFromRepository,\n\t\t\t});\n\n\t\t\tconst typesProvider = config.typesProvider || (await detectTypesProvider());\n\n\t\t\tconst hasCustomTypeModels = customTypeModels.length > 0;\n\n\t\t\tif (config.clientIntegration?.includeCreateClientInterface && !hasCustomTypeModels) {\n\t\t\t\tconsole.info(\n\t\t\t\t\t\"[INFO]: prismic-ts-codegen was configured to automatically integrate with `@prismicio/client`, but the integration was not generated because no Custom Type models were found. Automatic integration requires at least one Custom Type model.\",\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst types = generateTypes({\n\t\t\t\tcustomTypeModels,\n\t\t\t\tsharedSliceModels,\n\t\t\t\tlocaleIDs,\n\t\t\t\tfieldConfigs: config.fields,\n\t\t\t\tclientIntegration: {\n\t\t\t\t\tincludeCreateClientInterface: hasCustomTypeModels\n\t\t\t\t\t\t? (config.clientIntegration?.includeCreateClientInterface ?? true)\n\t\t\t\t\t\t: false,\n\t\t\t\t\tincludeContentNamespace: config.clientIntegration?.includeContentNamespace ?? true,\n\t\t\t\t},\n\t\t\t\ttypesProvider,\n\t\t\t});\n\n\t\t\tconst fileContents = `${NON_EDITABLE_FILE_HEADER}\\n\\n${types}`;\n\n\t\t\tif (config.output) {\n\t\t\t\twriteFileSync(resolvePath(config.output), fileContents);\n\n\t\t\t\tconsole.info(`\\nGenerated types in: ${config.output}`);\n\t\t\t} else {\n\t\t\t\tprocess.stdout.write(types + \"\\n\");\n\t\t\t}\n\t\t} else {\n\t\t\tconsole.error(result.error.message);\n\t\t\tprocess.exit(1);\n\t\t}\n\t}\n};\n\nmain().catch((error) => {\n\tconsole.error(error);\n\tprocess.exit(1);\n});\n"],"mappings":";;;;;;;;;;;;;AAaA,MAAM,MAAM,KACX;;;;;;;;;;IAWA;CACC,YAAY,OAAO;CACnB,OAAO,EACN,QAAQ;EACP,MAAM;EACN,WAAW;EACX,YAAY;EACZ,EACD;CACD,CACD;AAED,MAAM,OAAO,YAAY;AACxB,KAAI,IAAI,MAAM,OAAO,QAAQ;EAC5B,MAAM,aAAa,IAAI,MAAM,UAAU;AAEvC,MAAI,WAAW,WAAW,CACzB,SA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OAAO,OAAO,EAAE,aAAa;AAEvD,YAAQ,KAAK,yBAAyB,OAAO,SAAS;SAEtD,SAAQ,OAAO,MAAM,QAAQ,KAAK;SAE7B;AACN,WAAQ,MAAM,OAAO,MAAM,QAAQ;AACnC,WAAQ,KAAK,EAAE;;;;AAKlB,MAAM,CAAC,OAAO,UAAU;AACvB,SAAQ,MAAM,MAAM;AACpB,SAAQ,KAAK,EAAE;EACd"}
|
package/dist/constants.cjs
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
//#region src/constants.ts
|
|
2
|
-
const CUSTOM_TYPES_DOCUMENTATION_URL = "https://prismic.io/docs/content-modeling";
|
|
3
|
-
const SHARED_SLICES_DOCUMENTATION_URL = "https://prismic.io/docs/slices";
|
|
4
|
-
const FIELD_DOCUMENTATION_URLS = {
|
|
5
|
-
UID: "https://prismic.io/docs/fields/uid",
|
|
6
|
-
Boolean: "https://prismic.io/docs/fields/boolean",
|
|
7
|
-
Color: "https://prismic.io/docs/fields/color",
|
|
8
|
-
Date: "https://prismic.io/docs/fields/date",
|
|
9
|
-
Timestamp: "https://prismic.io/docs/fields/timestamp",
|
|
10
|
-
Number: "https://prismic.io/docs/fields/number",
|
|
11
|
-
Text: "https://prismic.io/docs/fields/text",
|
|
12
|
-
Select: "https://prismic.io/docs/fields/select",
|
|
13
|
-
StructuredText: "https://prismic.io/docs/fields/rich-text",
|
|
14
|
-
Image: "https://prismic.io/docs/fields/image",
|
|
15
|
-
Link: {
|
|
16
|
-
contentRelationship: "https://prismic.io/docs/fields/content-relationship",
|
|
17
|
-
link: "https://prismic.io/docs/fields/link",
|
|
18
|
-
linkToMedia: "https://prismic.io/docs/fields/link-to-media"
|
|
19
|
-
},
|
|
20
|
-
Embed: "https://prismic.io/docs/fields/embed",
|
|
21
|
-
GeoPoint: "https://prismic.io/docs/fields/geopoint",
|
|
22
|
-
Table: "https://prismic.io/docs/fields/table",
|
|
23
|
-
Group: "https://prismic.io/docs/fields/repeatable-group",
|
|
24
|
-
IntegrationFields: "https://prismic.io/docs/fields/integration",
|
|
25
|
-
Slices: "https://prismic.io/docs/slices",
|
|
26
|
-
Choice: "https://prismic.io/docs/slices"
|
|
27
|
-
};
|
|
28
|
-
//#endregion
|
|
29
|
-
exports.CUSTOM_TYPES_DOCUMENTATION_URL = CUSTOM_TYPES_DOCUMENTATION_URL;
|
|
30
|
-
exports.FIELD_DOCUMENTATION_URLS = FIELD_DOCUMENTATION_URLS;
|
|
31
|
-
exports.SHARED_SLICES_DOCUMENTATION_URL = SHARED_SLICES_DOCUMENTATION_URL;
|
|
32
|
-
|
|
33
|
-
//# sourceMappingURL=constants.cjs.map
|
package/dist/constants.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","names":[],"sources":["../src/constants.ts"],"sourcesContent":["import type { CustomTypeModelFieldType } from \"@prismicio/client\";\n\nexport const CUSTOM_TYPES_DOCUMENTATION_URL = \"https://prismic.io/docs/content-modeling\";\n\nexport const SHARED_SLICES_DOCUMENTATION_URL = \"https://prismic.io/docs/slices\";\n\nexport const FIELD_DOCUMENTATION_URLS = {\n\tUID: \"https://prismic.io/docs/fields/uid\",\n\tBoolean: \"https://prismic.io/docs/fields/boolean\",\n\tColor: \"https://prismic.io/docs/fields/color\",\n\tDate: \"https://prismic.io/docs/fields/date\",\n\tTimestamp: \"https://prismic.io/docs/fields/timestamp\",\n\tNumber: \"https://prismic.io/docs/fields/number\",\n\tText: \"https://prismic.io/docs/fields/text\",\n\tSelect: \"https://prismic.io/docs/fields/select\",\n\tStructuredText: \"https://prismic.io/docs/fields/rich-text\",\n\tImage: \"https://prismic.io/docs/fields/image\",\n\tLink: {\n\t\tcontentRelationship: \"https://prismic.io/docs/fields/content-relationship\",\n\t\tlink: \"https://prismic.io/docs/fields/link\",\n\t\tlinkToMedia: \"https://prismic.io/docs/fields/link-to-media\",\n\t},\n\tEmbed: \"https://prismic.io/docs/fields/embed\",\n\tGeoPoint: \"https://prismic.io/docs/fields/geopoint\",\n\tTable: \"https://prismic.io/docs/fields/table\",\n\tGroup: \"https://prismic.io/docs/fields/repeatable-group\",\n\tIntegrationFields: \"https://prismic.io/docs/fields/integration\",\n\tSlices: \"https://prismic.io/docs/slices\",\n\tChoice: \"https://prismic.io/docs/slices\",\n} satisfies Record<\n\tExclude<\n\t\t(typeof CustomTypeModelFieldType)[keyof typeof CustomTypeModelFieldType],\n\t\t\"Range\" | \"Separator\"\n\t>,\n\tstring | Record<string, string>\n>;\n"],"mappings":";AAEA,MAAa,iCAAiC;AAE9C,MAAa,kCAAkC;AAE/C,MAAa,2BAA2B;CACvC,KAAK;CACL,SAAS;CACT,OAAO;CACP,MAAM;CACN,WAAW;CACX,QAAQ;CACR,MAAM;CACN,QAAQ;CACR,gBAAgB;CAChB,OAAO;CACP,MAAM;EACL,qBAAqB;EACrB,MAAM;EACN,aAAa;EACb;CACD,OAAO;CACP,UAAU;CACV,OAAO;CACP,OAAO;CACP,mBAAmB;CACnB,QAAQ;CACR,QAAQ;CACR"}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
require("./_virtual/_rolldown/runtime.cjs");
|
|
2
|
-
let node_module = require("node:module");
|
|
3
|
-
//#region src/detectTypesProvider.ts
|
|
4
|
-
/**
|
|
5
|
-
* Detects which types provider should be used for a project.
|
|
6
|
-
*
|
|
7
|
-
* @param config - Configures the detection.
|
|
8
|
-
* @returns The types provider identifier to use, or `undefined` if on cannot be
|
|
9
|
-
* determined.
|
|
10
|
-
*/
|
|
11
|
-
const detectTypesProvider = async (config = {}) => {
|
|
12
|
-
const cwd = config.cwd || process.cwd();
|
|
13
|
-
const require = (0, node_module.createRequire)(cwd.endsWith("/") ? cwd : cwd + "/");
|
|
14
|
-
try {
|
|
15
|
-
if (Number.parseInt(require("@prismicio/client/package.json").version.split(".")[0]) >= 7) return "@prismicio/client";
|
|
16
|
-
} catch {}
|
|
17
|
-
try {
|
|
18
|
-
require.resolve("@prismicio/types");
|
|
19
|
-
return "@prismicio/types";
|
|
20
|
-
} catch {}
|
|
21
|
-
};
|
|
22
|
-
//#endregion
|
|
23
|
-
exports.detectTypesProvider = detectTypesProvider;
|
|
24
|
-
|
|
25
|
-
//# sourceMappingURL=detectTypesProvider.cjs.map
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { TypesProvider } from "./generateTypes.js";
|
|
2
|
-
|
|
3
|
-
//#region src/detectTypesProvider.d.ts
|
|
4
|
-
type DetectTypesProviderConfig = {
|
|
5
|
-
cwd?: string;
|
|
6
|
-
};
|
|
7
|
-
/**
|
|
8
|
-
* Detects which types provider should be used for a project.
|
|
9
|
-
*
|
|
10
|
-
* @param config - Configures the detection.
|
|
11
|
-
* @returns The types provider identifier to use, or `undefined` if on cannot be
|
|
12
|
-
* determined.
|
|
13
|
-
*/
|
|
14
|
-
declare const detectTypesProvider: (config?: DetectTypesProviderConfig) => Promise<TypesProvider | undefined>;
|
|
15
|
-
//#endregion
|
|
16
|
-
export { DetectTypesProviderConfig, detectTypesProvider };
|
|
17
|
-
//# sourceMappingURL=detectTypesProvider.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"detectTypesProvider.d.ts","names":[],"sources":["../src/detectTypesProvider.ts"],"mappings":";;;KAIY,yBAAA;EACX,GAAA;AAAA;;;;;AAUD;;;cAAa,mBAAA,GACZ,MAAA,GAAQ,yBAAA,KACN,OAAA,CAAQ,aAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"detectTypesProvider.js","names":[],"sources":["../src/detectTypesProvider.ts"],"sourcesContent":["import { createRequire } from \"node:module\";\n\nimport type { TypesProvider } from \"./generateTypes\";\n\nexport type DetectTypesProviderConfig = {\n\tcwd?: string;\n};\n\n/**\n * Detects which types provider should be used for a project.\n *\n * @param config - Configures the detection.\n * @returns The types provider identifier to use, or `undefined` if on cannot be\n * determined.\n */\nexport const detectTypesProvider = async (\n\tconfig: DetectTypesProviderConfig = {},\n): Promise<TypesProvider | undefined> => {\n\tconst cwd = config.cwd || process.cwd();\n\n\tconst require = createRequire(cwd.endsWith(\"/\") ? cwd : cwd + \"/\");\n\n\ttry {\n\t\tif (Number.parseInt(require(\"@prismicio/client/package.json\").version.split(\".\")[0]) >= 7) {\n\t\t\treturn \"@prismicio/client\";\n\t\t}\n\t} catch {\n\t\t// noop\n\t}\n\n\ttry {\n\t\trequire.resolve(\"@prismicio/types\");\n\n\t\treturn \"@prismicio/types\";\n\t} catch {\n\t\t// noop\n\t}\n};\n"],"mappings":";;;;;;;;;AAeA,MAAa,sBAAsB,OAClC,SAAoC,EAAE,KACE;CACxC,MAAM,MAAM,OAAO,OAAO,QAAQ,KAAK;CAEvC,MAAM,UAAU,cAAc,IAAI,SAAS,IAAI,GAAG,MAAM,MAAM,IAAI;AAElE,KAAI;AACH,MAAI,OAAO,SAAS,QAAQ,iCAAiC,CAAC,QAAQ,MAAM,IAAI,CAAC,GAAG,IAAI,EACvF,QAAO;SAED;AAIR,KAAI;AACH,UAAQ,QAAQ,mBAAmB;AAEnC,SAAO;SACA"}
|
package/dist/generateTypes.cjs
DELETED
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
const require_runtime = require("./_virtual/_rolldown/runtime.cjs");
|
|
2
|
-
const require_addLine = require("./lib/addLine.cjs");
|
|
3
|
-
const require_addSection = require("./lib/addSection.cjs");
|
|
4
|
-
const require_buildUnion = require("./lib/buildUnion.cjs");
|
|
5
|
-
const require_buildCustomTypeType = require("./lib/buildCustomTypeType.cjs");
|
|
6
|
-
const require_buildSharedSliceType = require("./lib/buildSharedSliceType.cjs");
|
|
7
|
-
let common_tags = require("common-tags");
|
|
8
|
-
let quick_lru = require("quick-lru");
|
|
9
|
-
quick_lru = require_runtime.__toESM(quick_lru);
|
|
10
|
-
//#region src/generateTypes.ts
|
|
11
|
-
const cache = new quick_lru.default({ maxSize: 1e3 });
|
|
12
|
-
function generateTypes(config = {}) {
|
|
13
|
-
const fieldConfigs = config.fieldConfigs || {};
|
|
14
|
-
const shouldUseCache = config.cache ?? true;
|
|
15
|
-
let code = "";
|
|
16
|
-
const typesProvider = config.typesProvider || "@prismicio/types";
|
|
17
|
-
let clientImportName = "prismic";
|
|
18
|
-
code = require_addLine.addLine(`import type * as prismic from "${typesProvider}";`, code);
|
|
19
|
-
if (config.clientIntegration?.includeCreateClientInterface || config.clientIntegration?.includeContentNamespace) {
|
|
20
|
-
if (typesProvider !== "@prismicio/client") {
|
|
21
|
-
clientImportName = "prismicClient";
|
|
22
|
-
code = require_addLine.addLine(`import type * as ${clientImportName} from "@prismicio/client";`, code);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
code = require_addSection.addSection(`type Simplify<T> = { [KeyType in keyof T]: T[KeyType] };`, code);
|
|
26
|
-
code = require_addSection.addSection(`
|
|
27
|
-
type PickContentRelationshipFieldData<
|
|
28
|
-
TRelationship extends prismic.CustomTypeModelFetchCustomTypeLevel1 | prismic.CustomTypeModelFetchCustomTypeLevel2 | prismic.CustomTypeModelFetchGroupLevel1 | prismic.CustomTypeModelFetchGroupLevel2,
|
|
29
|
-
TData extends Record<string, prismic.AnyRegularField | prismic.GroupField | prismic.NestedGroupField | prismic.SliceZone>,
|
|
30
|
-
TLang extends string
|
|
31
|
-
> = |
|
|
32
|
-
// Content relationship fields
|
|
33
|
-
{
|
|
34
|
-
[TSubRelationship in Extract<
|
|
35
|
-
TRelationship["fields"][number], prismic.CustomTypeModelFetchContentRelationshipLevel1
|
|
36
|
-
> as TSubRelationship["id"]]:
|
|
37
|
-
ContentRelationshipFieldWithData<TSubRelationship["customtypes"], TLang>;
|
|
38
|
-
} &
|
|
39
|
-
// Group
|
|
40
|
-
{
|
|
41
|
-
[TGroup in Extract<
|
|
42
|
-
TRelationship["fields"][number], prismic.CustomTypeModelFetchGroupLevel1 | prismic.CustomTypeModelFetchGroupLevel2
|
|
43
|
-
> as TGroup["id"]]:
|
|
44
|
-
TData[TGroup["id"]] extends prismic.GroupField<infer TGroupData>
|
|
45
|
-
? prismic.GroupField<PickContentRelationshipFieldData<TGroup, TGroupData, TLang>>
|
|
46
|
-
: never
|
|
47
|
-
} &
|
|
48
|
-
// Other fields
|
|
49
|
-
{
|
|
50
|
-
[TFieldKey in Extract<TRelationship["fields"][number], string>]:
|
|
51
|
-
TFieldKey extends keyof TData ? TData[TFieldKey] : never;
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
type ContentRelationshipFieldWithData<
|
|
55
|
-
TCustomType extends readonly (prismic.CustomTypeModelFetchCustomTypeLevel1 | string)[] | readonly (prismic.CustomTypeModelFetchCustomTypeLevel2 | string)[],
|
|
56
|
-
TLang extends string = string
|
|
57
|
-
> = {
|
|
58
|
-
[ID in Exclude<TCustomType[number], string>["id"]]:
|
|
59
|
-
prismic.ContentRelationshipField<
|
|
60
|
-
ID,
|
|
61
|
-
TLang,
|
|
62
|
-
PickContentRelationshipFieldData<
|
|
63
|
-
Extract<TCustomType[number], { id: ID }>,
|
|
64
|
-
Extract<prismic.Content.AllDocumentTypes, { type: ID }>["data"],
|
|
65
|
-
TLang
|
|
66
|
-
>
|
|
67
|
-
>
|
|
68
|
-
}[Exclude<TCustomType[number], string>["id"]];
|
|
69
|
-
`, code);
|
|
70
|
-
const contentTypeNames = [];
|
|
71
|
-
if (config.customTypeModels) {
|
|
72
|
-
const allDocumentTypesTypeNames = [];
|
|
73
|
-
for (const model of config.customTypeModels) {
|
|
74
|
-
const customTypeType = require_buildCustomTypeType.buildCustomTypeType({
|
|
75
|
-
model,
|
|
76
|
-
localeIDs: config.localeIDs,
|
|
77
|
-
fieldConfigs,
|
|
78
|
-
cache: shouldUseCache ? cache : void 0
|
|
79
|
-
});
|
|
80
|
-
for (const auxiliaryType of customTypeType.auxiliaryTypes) code = require_addSection.addSection(auxiliaryType.code, code);
|
|
81
|
-
code = require_addSection.addSection(customTypeType.code, code);
|
|
82
|
-
allDocumentTypesTypeNames.push(customTypeType.name);
|
|
83
|
-
contentTypeNames.push(customTypeType.name);
|
|
84
|
-
contentTypeNames.push(...customTypeType.contentTypeNames);
|
|
85
|
-
}
|
|
86
|
-
if (config.customTypeModels.length > 0) {
|
|
87
|
-
const allDocumentTypesUnionName = "AllDocumentTypes";
|
|
88
|
-
code = require_addSection.addSection(`export type ${allDocumentTypesUnionName} = ${require_buildUnion.buildUnion(allDocumentTypesTypeNames)};`, code);
|
|
89
|
-
contentTypeNames.push(allDocumentTypesUnionName);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
if (config.sharedSliceModels) for (const model of config.sharedSliceModels) {
|
|
93
|
-
const sharedSliceType = require_buildSharedSliceType.buildSharedSliceType({
|
|
94
|
-
model,
|
|
95
|
-
fieldConfigs,
|
|
96
|
-
cache: shouldUseCache ? cache : void 0
|
|
97
|
-
});
|
|
98
|
-
for (const auxiliaryType of sharedSliceType.auxiliaryTypes) code = require_addSection.addSection(auxiliaryType.code, code);
|
|
99
|
-
code = require_addSection.addSection(sharedSliceType.code, code);
|
|
100
|
-
contentTypeNames.push(sharedSliceType.name);
|
|
101
|
-
contentTypeNames.push(...sharedSliceType.contentTypeNames);
|
|
102
|
-
}
|
|
103
|
-
if (config.clientIntegration?.includeCreateClientInterface || config.clientIntegration?.includeContentNamespace) {
|
|
104
|
-
let clientModuleCode = "";
|
|
105
|
-
if (config.clientIntegration.includeCreateClientInterface) if ((config.customTypeModels?.length || 0) > 0) {
|
|
106
|
-
clientModuleCode = require_addSection.addSection(`interface CreateClient {
|
|
107
|
-
(repositoryNameOrEndpoint: string, options?: ${clientImportName}.ClientConfig): ${clientImportName}.Client<AllDocumentTypes>;
|
|
108
|
-
}`, clientModuleCode);
|
|
109
|
-
clientModuleCode = require_addSection.addSection(`interface CreateWriteClient {
|
|
110
|
-
(repositoryNameOrEndpoint: string, options: ${clientImportName}.WriteClientConfig): ${clientImportName}.WriteClient<AllDocumentTypes>;
|
|
111
|
-
}`, clientModuleCode);
|
|
112
|
-
clientModuleCode = require_addSection.addSection(`interface CreateMigration {
|
|
113
|
-
(): ${clientImportName}.Migration<AllDocumentTypes>;
|
|
114
|
-
}`, clientModuleCode);
|
|
115
|
-
} else {
|
|
116
|
-
clientModuleCode = require_addSection.addSection(`interface CreateClient {
|
|
117
|
-
(repositoryNameOrEndpoint: string, options?: ${clientImportName}.ClientConfig): ${clientImportName}.Client;
|
|
118
|
-
}`, clientModuleCode);
|
|
119
|
-
clientModuleCode = require_addSection.addSection(`interface CreateWriteClient {
|
|
120
|
-
(repositoryNameOrEndpoint: string, options?: ${clientImportName}.WriteClientConfig): ${clientImportName}.WriteClient;
|
|
121
|
-
}`, clientModuleCode);
|
|
122
|
-
clientModuleCode = require_addSection.addSection(`interface CreateMigration {
|
|
123
|
-
(): ${clientImportName}.Migration;
|
|
124
|
-
}`, clientModuleCode);
|
|
125
|
-
}
|
|
126
|
-
if (config.clientIntegration.includeContentNamespace) clientModuleCode = require_addSection.addSection(common_tags.source`
|
|
127
|
-
namespace Content {
|
|
128
|
-
export type {
|
|
129
|
-
${contentTypeNames.join(",\n")}
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
`, clientModuleCode);
|
|
133
|
-
code = require_addSection.addSection(common_tags.source`
|
|
134
|
-
declare module "@prismicio/client" {
|
|
135
|
-
${clientModuleCode}
|
|
136
|
-
}
|
|
137
|
-
`, code);
|
|
138
|
-
}
|
|
139
|
-
return code;
|
|
140
|
-
}
|
|
141
|
-
//#endregion
|
|
142
|
-
exports.generateTypes = generateTypes;
|
|
143
|
-
|
|
144
|
-
//# sourceMappingURL=generateTypes.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"generateTypes.cjs","names":["QuickLRU","addLine","addSection","buildCustomTypeType","buildUnion","buildSharedSliceType"],"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\";\nimport type { 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(`import type * as ${clientImportName} from \"@prismicio/client\";`, code);\n\t\t}\n\t}\n\n\tcode = addSection(`type Simplify<T> = { [KeyType in keyof T]: T[KeyType] };`, code);\n\n\tcode = addSection(\n\t\t`\ntype PickContentRelationshipFieldData<\n\tTRelationship extends prismic.CustomTypeModelFetchCustomTypeLevel1 | prismic.CustomTypeModelFetchCustomTypeLevel2 | prismic.CustomTypeModelFetchGroupLevel1 | prismic.CustomTypeModelFetchGroupLevel2,\n\tTData extends Record<string, prismic.AnyRegularField | prismic.GroupField | prismic.NestedGroupField | prismic.SliceZone>,\n\tTLang extends string\n> = |\n\t// Content relationship fields\n\t{\n\t\t[TSubRelationship in Extract<\n\t\t\tTRelationship[\"fields\"][number], prismic.CustomTypeModelFetchContentRelationshipLevel1\n\t\t> as TSubRelationship[\"id\"]]:\n\t\t\tContentRelationshipFieldWithData<TSubRelationship[\"customtypes\"], TLang>;\n\t} &\n\t// Group\n\t{\n\t\t[TGroup in Extract<\n\t\t\tTRelationship[\"fields\"][number], prismic.CustomTypeModelFetchGroupLevel1 | prismic.CustomTypeModelFetchGroupLevel2\n\t\t> as TGroup[\"id\"]]:\n\t\t\tTData[TGroup[\"id\"]] extends prismic.GroupField<infer TGroupData>\n\t\t\t\t? prismic.GroupField<PickContentRelationshipFieldData<TGroup, TGroupData, TLang>>\n\t\t\t\t: never\n\t} &\n\t// Other fields\n\t{\n\t\t[TFieldKey in Extract<TRelationship[\"fields\"][number], string>]:\n\t\t\tTFieldKey extends keyof TData ? TData[TFieldKey] : never;\n\t};\n\ntype ContentRelationshipFieldWithData<\n\tTCustomType extends readonly (prismic.CustomTypeModelFetchCustomTypeLevel1 | string)[] | readonly (prismic.CustomTypeModelFetchCustomTypeLevel2 | string)[],\n\tTLang extends string = string\n> = {\n\t[ID in Exclude<TCustomType[number], string>[\"id\"]]:\n\t\tprismic.ContentRelationshipField<\n\t\t\tID,\n\t\t\tTLang,\n\t\t\tPickContentRelationshipFieldData<\n\t\t\t\tExtract<TCustomType[number], { id: ID }>,\n\t\t\t\tExtract<prismic.Content.AllDocumentTypes, { type: ID }>[\"data\"],\n\t\t\t\tTLang\n\t\t\t>\n\t\t>\n}[Exclude<TCustomType[number], string>[\"id\"]];\n`,\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.contentTypeNames);\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\tfor (const auxiliaryType of sharedSliceType.auxiliaryTypes) {\n\t\t\t\tcode = addSection(auxiliaryType.code, code);\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.contentTypeNames);\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\tclientModuleCode = addSection(\n\t\t\t\t\t`interface CreateWriteClient {\n\t(repositoryNameOrEndpoint: string, options: ${clientImportName}.WriteClientConfig): ${clientImportName}.WriteClient<AllDocumentTypes>;\n}`,\n\t\t\t\t\tclientModuleCode,\n\t\t\t\t);\n\t\t\t\tclientModuleCode = addSection(\n\t\t\t\t\t`interface CreateMigration {\n\t(): ${clientImportName}.Migration<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\tclientModuleCode = addSection(\n\t\t\t\t\t`interface CreateWriteClient {\n\t(repositoryNameOrEndpoint: string, options?: ${clientImportName}.WriteClientConfig): ${clientImportName}.WriteClient;\n}`,\n\t\t\t\t\tclientModuleCode,\n\t\t\t\t);\n\t\t\t\tclientModuleCode = addSection(\n\t\t\t\t\t`interface CreateMigration {\n\t(): ${clientImportName}.Migration;\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 \"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A,MAAM;;OAEF,iBAAiB;;MAGrB,KACA;;AAGF,QAAO"}
|
package/dist/generateTypes.d.cts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { FieldConfigs } from "./types.cjs";
|
|
2
|
-
import { CustomTypeModel, SharedSliceModel } from "@prismicio/client";
|
|
3
|
-
|
|
4
|
-
//#region src/generateTypes.d.ts
|
|
5
|
-
type TypesProvider = "@prismicio/client" | "@prismicio/types";
|
|
6
|
-
type GenerateTypesConfig = {
|
|
7
|
-
customTypeModels?: CustomTypeModel[];
|
|
8
|
-
sharedSliceModels?: SharedSliceModel[];
|
|
9
|
-
localeIDs?: string[];
|
|
10
|
-
fieldConfigs?: FieldConfigs;
|
|
11
|
-
typesProvider?: TypesProvider;
|
|
12
|
-
clientIntegration?: {
|
|
13
|
-
includeCreateClientInterface?: boolean;
|
|
14
|
-
includeContentNamespace?: boolean;
|
|
15
|
-
};
|
|
16
|
-
cache?: boolean;
|
|
17
|
-
};
|
|
18
|
-
declare function generateTypes(config?: GenerateTypesConfig): string;
|
|
19
|
-
//#endregion
|
|
20
|
-
export { GenerateTypesConfig, TypesProvider, generateTypes };
|
|
21
|
-
//# sourceMappingURL=generateTypes.d.cts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"generateTypes.d.ts","names":[],"sources":["../src/generateTypes.ts"],"mappings":";;;;KAWY,aAAA;AAAA,KAIA,mBAAA;EACX,gBAAA,GAAmB,eAAA;EACnB,iBAAA,GAAoB,gBAAA;EACpB,SAAA;EACA,YAAA,GAAe,YAAA;EACf,aAAA,GAAgB,aAAA;EAChB,iBAAA;IACC,4BAAA;IACA,uBAAA;EAAA;EAED,KAAA;AAAA;AAAA,iBAGe,aAAA,CAAc,MAAA,GAAQ,mBAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"generateTypes.js","names":[],"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\";\nimport type { 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(`import type * as ${clientImportName} from \"@prismicio/client\";`, code);\n\t\t}\n\t}\n\n\tcode = addSection(`type Simplify<T> = { [KeyType in keyof T]: T[KeyType] };`, code);\n\n\tcode = addSection(\n\t\t`\ntype PickContentRelationshipFieldData<\n\tTRelationship extends prismic.CustomTypeModelFetchCustomTypeLevel1 | prismic.CustomTypeModelFetchCustomTypeLevel2 | prismic.CustomTypeModelFetchGroupLevel1 | prismic.CustomTypeModelFetchGroupLevel2,\n\tTData extends Record<string, prismic.AnyRegularField | prismic.GroupField | prismic.NestedGroupField | prismic.SliceZone>,\n\tTLang extends string\n> = |\n\t// Content relationship fields\n\t{\n\t\t[TSubRelationship in Extract<\n\t\t\tTRelationship[\"fields\"][number], prismic.CustomTypeModelFetchContentRelationshipLevel1\n\t\t> as TSubRelationship[\"id\"]]:\n\t\t\tContentRelationshipFieldWithData<TSubRelationship[\"customtypes\"], TLang>;\n\t} &\n\t// Group\n\t{\n\t\t[TGroup in Extract<\n\t\t\tTRelationship[\"fields\"][number], prismic.CustomTypeModelFetchGroupLevel1 | prismic.CustomTypeModelFetchGroupLevel2\n\t\t> as TGroup[\"id\"]]:\n\t\t\tTData[TGroup[\"id\"]] extends prismic.GroupField<infer TGroupData>\n\t\t\t\t? prismic.GroupField<PickContentRelationshipFieldData<TGroup, TGroupData, TLang>>\n\t\t\t\t: never\n\t} &\n\t// Other fields\n\t{\n\t\t[TFieldKey in Extract<TRelationship[\"fields\"][number], string>]:\n\t\t\tTFieldKey extends keyof TData ? TData[TFieldKey] : never;\n\t};\n\ntype ContentRelationshipFieldWithData<\n\tTCustomType extends readonly (prismic.CustomTypeModelFetchCustomTypeLevel1 | string)[] | readonly (prismic.CustomTypeModelFetchCustomTypeLevel2 | string)[],\n\tTLang extends string = string\n> = {\n\t[ID in Exclude<TCustomType[number], string>[\"id\"]]:\n\t\tprismic.ContentRelationshipField<\n\t\t\tID,\n\t\t\tTLang,\n\t\t\tPickContentRelationshipFieldData<\n\t\t\t\tExtract<TCustomType[number], { id: ID }>,\n\t\t\t\tExtract<prismic.Content.AllDocumentTypes, { type: ID }>[\"data\"],\n\t\t\t\tTLang\n\t\t\t>\n\t\t>\n}[Exclude<TCustomType[number], string>[\"id\"]];\n`,\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.contentTypeNames);\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\tfor (const auxiliaryType of sharedSliceType.auxiliaryTypes) {\n\t\t\t\tcode = addSection(auxiliaryType.code, code);\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.contentTypeNames);\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\tclientModuleCode = addSection(\n\t\t\t\t\t`interface CreateWriteClient {\n\t(repositoryNameOrEndpoint: string, options: ${clientImportName}.WriteClientConfig): ${clientImportName}.WriteClient<AllDocumentTypes>;\n}`,\n\t\t\t\t\tclientModuleCode,\n\t\t\t\t);\n\t\t\t\tclientModuleCode = addSection(\n\t\t\t\t\t`interface CreateMigration {\n\t(): ${clientImportName}.Migration<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\tclientModuleCode = addSection(\n\t\t\t\t\t`interface CreateWriteClient {\n\t(repositoryNameOrEndpoint: string, options?: ${clientImportName}.WriteClientConfig): ${clientImportName}.WriteClient;\n}`,\n\t\t\t\t\tclientModuleCode,\n\t\t\t\t);\n\t\t\t\tclientModuleCode = addSection(\n\t\t\t\t\t`interface CreateMigration {\n\t(): ${clientImportName}.Migration;\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`,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exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_generateTypes = require("./generateTypes.cjs");
|
|
3
|
-
const require_detectTypesProvider = require("./detectTypesProvider.cjs");
|
|
4
|
-
const require_constants = require("./cli/constants.cjs");
|
|
5
|
-
exports.NON_EDITABLE_FILE_HEADER = require_constants.NON_EDITABLE_FILE_HEADER;
|
|
6
|
-
exports.detectTypesProvider = require_detectTypesProvider.detectTypesProvider;
|
|
7
|
-
exports.generateTypes = require_generateTypes.generateTypes;
|
package/dist/index.d.ts
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { GenerateTypesConfig, TypesProvider, generateTypes } from "./generateTypes.js";
|
|
2
|
-
import { DetectTypesProviderConfig, detectTypesProvider } from "./detectTypesProvider.js";
|
|
3
|
-
import { Config } from "./cli/configSchema.js";
|
|
4
|
-
import { NON_EDITABLE_FILE_HEADER } from "./cli/constants.js";
|
|
5
|
-
export { type Config, type DetectTypesProviderConfig, type GenerateTypesConfig, NON_EDITABLE_FILE_HEADER, type TypesProvider, detectTypesProvider, generateTypes };
|
package/dist/index.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
const require_addTrailingNewLine = require("./addTrailingNewLine.cjs");
|
|
2
|
-
//#region src/lib/addBlankLine.ts
|
|
3
|
-
function addBlankLine(state, config) {
|
|
4
|
-
if ((!state || state.endsWith("\n\n")) && !config?.force) return state;
|
|
5
|
-
else return require_addTrailingNewLine.addTrailingNewLine(state) + "\n";
|
|
6
|
-
}
|
|
7
|
-
//#endregion
|
|
8
|
-
exports.addBlankLine = addBlankLine;
|
|
9
|
-
|
|
10
|
-
//# sourceMappingURL=addBlankLine.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"addBlankLine.cjs","names":["addTrailingNewLine"],"sources":["../../src/lib/addBlankLine.ts"],"sourcesContent":["import { addTrailingNewLine } from \"./addTrailingNewLine\";\n\ntype AddBlankLineConfig = {\n\tforce?: boolean;\n};\n\nexport function addBlankLine(state: string, config?: AddBlankLineConfig): string {\n\tif ((!state || state.endsWith(\"\\n\\n\")) && !config?.force) {\n\t\treturn state;\n\t} else {\n\t\treturn addTrailingNewLine(state) + \"\\n\";\n\t}\n}\n"],"mappings":";;AAMA,SAAgB,aAAa,OAAe,QAAqC;AAChF,MAAK,CAAC,SAAS,MAAM,SAAS,OAAO,KAAK,CAAC,QAAQ,MAClD,QAAO;KAEP,QAAOA,2BAAAA,mBAAmB,MAAM,GAAG"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"addBlankLine.js","names":[],"sources":["../../src/lib/addBlankLine.ts"],"sourcesContent":["import { addTrailingNewLine } from \"./addTrailingNewLine\";\n\ntype AddBlankLineConfig = {\n\tforce?: boolean;\n};\n\nexport function addBlankLine(state: string, config?: AddBlankLineConfig): string {\n\tif ((!state || state.endsWith(\"\\n\\n\")) && !config?.force) {\n\t\treturn state;\n\t} else {\n\t\treturn addTrailingNewLine(state) + \"\\n\";\n\t}\n}\n"],"mappings":";;AAMA,SAAgB,aAAa,OAAe,QAAqC;AAChF,MAAK,CAAC,SAAS,MAAM,SAAS,OAAO,KAAK,CAAC,QAAQ,MAClD,QAAO;KAEP,QAAO,mBAAmB,MAAM,GAAG"}
|
package/dist/lib/addLine.cjs
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
const require_addTrailingNewLine = require("./addTrailingNewLine.cjs");
|
|
2
|
-
//#region src/lib/addLine.ts
|
|
3
|
-
function addLine(line, state) {
|
|
4
|
-
return require_addTrailingNewLine.addTrailingNewLine(state) + line;
|
|
5
|
-
}
|
|
6
|
-
//#endregion
|
|
7
|
-
exports.addLine = addLine;
|
|
8
|
-
|
|
9
|
-
//# sourceMappingURL=addLine.cjs.map
|
package/dist/lib/addLine.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"addLine.cjs","names":["addTrailingNewLine"],"sources":["../../src/lib/addLine.ts"],"sourcesContent":["import { addTrailingNewLine } from \"./addTrailingNewLine\";\n\nexport function addLine(line: string, state: string): string {\n\treturn addTrailingNewLine(state) + line;\n}\n"],"mappings":";;AAEA,SAAgB,QAAQ,MAAc,OAAuB;AAC5D,QAAOA,2BAAAA,mBAAmB,MAAM,GAAG"}
|
package/dist/lib/addLine.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"addLine.js","names":[],"sources":["../../src/lib/addLine.ts"],"sourcesContent":["import { addTrailingNewLine } from \"./addTrailingNewLine\";\n\nexport function addLine(line: string, state: string): string {\n\treturn addTrailingNewLine(state) + line;\n}\n"],"mappings":";;AAEA,SAAgB,QAAQ,MAAc,OAAuB;AAC5D,QAAO,mBAAmB,MAAM,GAAG"}
|
package/dist/lib/addSection.cjs
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
const require_addBlankLine = require("./addBlankLine.cjs");
|
|
2
|
-
//#region src/lib/addSection.ts
|
|
3
|
-
function addSection(section, state) {
|
|
4
|
-
return require_addBlankLine.addBlankLine(state) + section;
|
|
5
|
-
}
|
|
6
|
-
//#endregion
|
|
7
|
-
exports.addSection = addSection;
|
|
8
|
-
|
|
9
|
-
//# sourceMappingURL=addSection.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"addSection.cjs","names":["addBlankLine"],"sources":["../../src/lib/addSection.ts"],"sourcesContent":["import { addBlankLine } from \"./addBlankLine\";\n\nexport function addSection(section: string, state: string): string {\n\treturn addBlankLine(state) + section;\n}\n"],"mappings":";;AAEA,SAAgB,WAAW,SAAiB,OAAuB;AAClE,QAAOA,qBAAAA,aAAa,MAAM,GAAG"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"addSection.js","names":[],"sources":["../../src/lib/addSection.ts"],"sourcesContent":["import { addBlankLine } from \"./addBlankLine\";\n\nexport function addSection(section: string, state: string): string {\n\treturn addBlankLine(state) + section;\n}\n"],"mappings":";;AAEA,SAAgB,WAAW,SAAiB,OAAuB;AAClE,QAAO,aAAa,MAAM,GAAG"}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
//#region src/lib/addTrailingNewLine.ts
|
|
2
|
-
function addTrailingNewLine(state, config) {
|
|
3
|
-
if ((!state || state.endsWith("\n")) && !config?.force) return state;
|
|
4
|
-
else return state + "\n";
|
|
5
|
-
}
|
|
6
|
-
//#endregion
|
|
7
|
-
exports.addTrailingNewLine = addTrailingNewLine;
|
|
8
|
-
|
|
9
|
-
//# sourceMappingURL=addTrailingNewLine.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"addTrailingNewLine.js","names":[],"sources":["../../src/lib/addTrailingNewLine.ts"],"sourcesContent":["type AddTrailingNewLineConfig = {\n\tforce?: boolean;\n};\n\nexport function addTrailingNewLine(state: string, config?: AddTrailingNewLineConfig): string {\n\tif ((!state || state.endsWith(\"\\n\")) && !config?.force) {\n\t\treturn state;\n\t} else {\n\t\treturn state + \"\\n\";\n\t}\n}\n"],"mappings":";AAIA,SAAgB,mBAAmB,OAAe,QAA2C;AAC5F,MAAK,CAAC,SAAS,MAAM,SAAS,KAAK,KAAK,CAAC,QAAQ,MAChD,QAAO;KAEP,QAAO,QAAQ"}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
require("../_virtual/_rolldown/runtime.cjs");
|
|
2
|
-
const require_buildTypeName = require("./buildTypeName.cjs");
|
|
3
|
-
const require_getHumanReadableModelName = require("./getHumanReadableModelName.cjs");
|
|
4
|
-
const require_buildFieldProperties = require("./buildFieldProperties.cjs");
|
|
5
|
-
let common_tags = require("common-tags");
|
|
6
|
-
//#region src/lib/buildCustomTypeDataType.ts
|
|
7
|
-
function buildCustomTypeDataType(args) {
|
|
8
|
-
let code = "";
|
|
9
|
-
const auxiliaryTypes = [];
|
|
10
|
-
const contentTypeNames = [];
|
|
11
|
-
const name = require_buildTypeName.buildTypeName(args.model.id, "Document", "Data");
|
|
12
|
-
const humanReadableName = require_getHumanReadableModelName.getHumanReadableModelName({
|
|
13
|
-
name: args.model.id,
|
|
14
|
-
model: args.model
|
|
15
|
-
});
|
|
16
|
-
let fieldProperties = "";
|
|
17
|
-
for (const tabName in args.model.json) {
|
|
18
|
-
const { uid: _uid, ...fields } = args.model.json[tabName];
|
|
19
|
-
const tabFieldProperties = require_buildFieldProperties.buildFieldProperties({
|
|
20
|
-
fields,
|
|
21
|
-
fieldConfigs: args.fieldConfigs,
|
|
22
|
-
path: [{
|
|
23
|
-
name: args.model.id,
|
|
24
|
-
model: args.model
|
|
25
|
-
}],
|
|
26
|
-
tabName
|
|
27
|
-
});
|
|
28
|
-
fieldProperties += tabFieldProperties.code;
|
|
29
|
-
auxiliaryTypes.push(...tabFieldProperties.auxiliaryTypes);
|
|
30
|
-
contentTypeNames.push(...tabFieldProperties.contentTypeNames);
|
|
31
|
-
}
|
|
32
|
-
if (fieldProperties) code = common_tags.source`
|
|
33
|
-
/**
|
|
34
|
-
* Content for ${humanReadableName} documents
|
|
35
|
-
*/
|
|
36
|
-
interface ${name} {
|
|
37
|
-
${fieldProperties}
|
|
38
|
-
}
|
|
39
|
-
`;
|
|
40
|
-
else code = `interface ${name} {}`;
|
|
41
|
-
return {
|
|
42
|
-
name,
|
|
43
|
-
code,
|
|
44
|
-
auxiliaryTypes,
|
|
45
|
-
contentTypeNames
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
//#endregion
|
|
49
|
-
exports.buildCustomTypeDataType = buildCustomTypeDataType;
|
|
50
|
-
|
|
51
|
-
//# sourceMappingURL=buildCustomTypeDataType.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"buildCustomTypeDataType.cjs","names":["buildTypeName","getHumanReadableModelName","buildFieldProperties"],"sources":["../../src/lib/buildCustomTypeDataType.ts"],"sourcesContent":["import type { CustomTypeModel } from \"@prismicio/client\";\nimport { source } from \"common-tags\";\n\nimport { buildTypeName } from \"../lib/buildTypeName\";\nimport type { AuxiliaryType, FieldConfigs } from \"../types\";\nimport { buildFieldProperties } from \"./buildFieldProperties\";\nimport { getHumanReadableModelName } from \"./getHumanReadableModelName\";\n\ntype BuildCustomTypeDataTypeArgs = {\n\tmodel: CustomTypeModel;\n\tfieldConfigs: FieldConfigs;\n};\n\ntype BuildCustomTypeDataTypeReturnValue = {\n\tname: string;\n\tcode: string;\n\tauxiliaryTypes: AuxiliaryType[];\n\tcontentTypeNames: string[];\n};\n\nexport function buildCustomTypeDataType(\n\targs: BuildCustomTypeDataTypeArgs,\n): BuildCustomTypeDataTypeReturnValue {\n\tlet code = \"\";\n\tconst auxiliaryTypes: AuxiliaryType[] = [];\n\tconst contentTypeNames: string[] = [];\n\n\tconst name = buildTypeName(args.model.id, \"Document\", \"Data\");\n\tconst humanReadableName = getHumanReadableModelName({\n\t\tname: args.model.id,\n\t\tmodel: args.model,\n\t});\n\n\tlet fieldProperties = \"\";\n\n\tfor (const tabName in args.model.json) {\n\t\tconst { uid: _uid, ...fields } = args.model.json[tabName];\n\n\t\tconst tabFieldProperties = buildFieldProperties({\n\t\t\tfields,\n\t\t\tfieldConfigs: args.fieldConfigs,\n\t\t\tpath: [\n\t\t\t\t{\n\t\t\t\t\tname: args.model.id,\n\t\t\t\t\tmodel: args.model,\n\t\t\t\t},\n\t\t\t],\n\t\t\ttabName,\n\t\t});\n\n\t\tfieldProperties += tabFieldProperties.code;\n\n\t\tauxiliaryTypes.push(...tabFieldProperties.auxiliaryTypes);\n\t\tcontentTypeNames.push(...tabFieldProperties.contentTypeNames);\n\t}\n\n\tif (fieldProperties) {\n\t\tcode = source`\n\t\t\t/**\n\t\t\t * Content for ${humanReadableName} documents\n\t\t\t */\n\t\t\tinterface ${name} {\n\t\t\t\t${fieldProperties}\n\t\t\t}\n\t\t`;\n\t} else {\n\t\tcode = `interface ${name} {}`;\n\t}\n\n\treturn {\n\t\tname,\n\t\tcode,\n\t\tauxiliaryTypes,\n\t\tcontentTypeNames,\n\t};\n}\n"],"mappings":";;;;;;AAoBA,SAAgB,wBACf,MACqC;CACrC,IAAI,OAAO;CACX,MAAM,iBAAkC,EAAE;CAC1C,MAAM,mBAA6B,EAAE;CAErC,MAAM,OAAOA,sBAAAA,cAAc,KAAK,MAAM,IAAI,YAAY,OAAO;CAC7D,MAAM,oBAAoBC,kCAAAA,0BAA0B;EACnD,MAAM,KAAK,MAAM;EACjB,OAAO,KAAK;EACZ,CAAC;CAEF,IAAI,kBAAkB;AAEtB,MAAK,MAAM,WAAW,KAAK,MAAM,MAAM;EACtC,MAAM,EAAE,KAAK,MAAM,GAAG,WAAW,KAAK,MAAM,KAAK;EAEjD,MAAM,qBAAqBC,6BAAAA,qBAAqB;GAC/C;GACA,cAAc,KAAK;GACnB,MAAM,CACL;IACC,MAAM,KAAK,MAAM;IACjB,OAAO,KAAK;IACZ,CACD;GACD;GACA,CAAC;AAEF,qBAAmB,mBAAmB;AAEtC,iBAAe,KAAK,GAAG,mBAAmB,eAAe;AACzD,mBAAiB,KAAK,GAAG,mBAAmB,iBAAiB;;AAG9D,KAAI,gBACH,QAAO,YAAA,MAAM;;oBAEK,kBAAkB;;eAEvB,KAAK;MACd,gBAAgB;;;KAIpB,QAAO,aAAa,KAAK;AAG1B,QAAO;EACN;EACA;EACA;EACA;EACA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"buildCustomTypeDataType.js","names":[],"sources":["../../src/lib/buildCustomTypeDataType.ts"],"sourcesContent":["import type { CustomTypeModel } from \"@prismicio/client\";\nimport { source } from \"common-tags\";\n\nimport { buildTypeName } from \"../lib/buildTypeName\";\nimport type { AuxiliaryType, FieldConfigs } from \"../types\";\nimport { buildFieldProperties } from \"./buildFieldProperties\";\nimport { getHumanReadableModelName } from \"./getHumanReadableModelName\";\n\ntype BuildCustomTypeDataTypeArgs = {\n\tmodel: CustomTypeModel;\n\tfieldConfigs: FieldConfigs;\n};\n\ntype BuildCustomTypeDataTypeReturnValue = {\n\tname: string;\n\tcode: string;\n\tauxiliaryTypes: AuxiliaryType[];\n\tcontentTypeNames: string[];\n};\n\nexport function buildCustomTypeDataType(\n\targs: BuildCustomTypeDataTypeArgs,\n): BuildCustomTypeDataTypeReturnValue {\n\tlet code = \"\";\n\tconst auxiliaryTypes: AuxiliaryType[] = [];\n\tconst contentTypeNames: string[] = [];\n\n\tconst name = buildTypeName(args.model.id, \"Document\", \"Data\");\n\tconst humanReadableName = getHumanReadableModelName({\n\t\tname: args.model.id,\n\t\tmodel: args.model,\n\t});\n\n\tlet fieldProperties = \"\";\n\n\tfor (const tabName in args.model.json) {\n\t\tconst { uid: _uid, ...fields } = args.model.json[tabName];\n\n\t\tconst tabFieldProperties = buildFieldProperties({\n\t\t\tfields,\n\t\t\tfieldConfigs: args.fieldConfigs,\n\t\t\tpath: [\n\t\t\t\t{\n\t\t\t\t\tname: args.model.id,\n\t\t\t\t\tmodel: args.model,\n\t\t\t\t},\n\t\t\t],\n\t\t\ttabName,\n\t\t});\n\n\t\tfieldProperties += tabFieldProperties.code;\n\n\t\tauxiliaryTypes.push(...tabFieldProperties.auxiliaryTypes);\n\t\tcontentTypeNames.push(...tabFieldProperties.contentTypeNames);\n\t}\n\n\tif (fieldProperties) {\n\t\tcode = source`\n\t\t\t/**\n\t\t\t * Content for ${humanReadableName} documents\n\t\t\t */\n\t\t\tinterface ${name} {\n\t\t\t\t${fieldProperties}\n\t\t\t}\n\t\t`;\n\t} else {\n\t\tcode = `interface ${name} {}`;\n\t}\n\n\treturn {\n\t\tname,\n\t\tcode,\n\t\tauxiliaryTypes,\n\t\tcontentTypeNames,\n\t};\n}\n"],"mappings":";;;;;AAoBA,SAAgB,wBACf,MACqC;CACrC,IAAI,OAAO;CACX,MAAM,iBAAkC,EAAE;CAC1C,MAAM,mBAA6B,EAAE;CAErC,MAAM,OAAO,cAAc,KAAK,MAAM,IAAI,YAAY,OAAO;CAC7D,MAAM,oBAAoB,0BAA0B;EACnD,MAAM,KAAK,MAAM;EACjB,OAAO,KAAK;EACZ,CAAC;CAEF,IAAI,kBAAkB;AAEtB,MAAK,MAAM,WAAW,KAAK,MAAM,MAAM;EACtC,MAAM,EAAE,KAAK,MAAM,GAAG,WAAW,KAAK,MAAM,KAAK;EAEjD,MAAM,qBAAqB,qBAAqB;GAC/C;GACA,cAAc,KAAK;GACnB,MAAM,CACL;IACC,MAAM,KAAK,MAAM;IACjB,OAAO,KAAK;IACZ,CACD;GACD;GACA,CAAC;AAEF,qBAAmB,mBAAmB;AAEtC,iBAAe,KAAK,GAAG,mBAAmB,eAAe;AACzD,mBAAiB,KAAK,GAAG,mBAAmB,iBAAiB;;AAG9D,KAAI,gBACH,QAAO,MAAM;;oBAEK,kBAAkB;;eAEvB,KAAK;MACd,gBAAgB;;;KAIpB,QAAO,aAAa,KAAK;AAG1B,QAAO;EACN;EACA;EACA;EACA;EACA"}
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
require("../_virtual/_rolldown/runtime.cjs");
|
|
2
|
-
const require_addSection = require("./addSection.cjs");
|
|
3
|
-
const require_constants = require("../constants.cjs");
|
|
4
|
-
const require_buildTypeName = require("./buildTypeName.cjs");
|
|
5
|
-
const require_getHumanReadableModelName = require("./getHumanReadableModelName.cjs");
|
|
6
|
-
const require_buildUnion = require("./buildUnion.cjs");
|
|
7
|
-
const require_buildCustomTypeDataType = require("./buildCustomTypeDataType.cjs");
|
|
8
|
-
const require_checkHasUIDFIeld = require("./checkHasUIDFIeld.cjs");
|
|
9
|
-
const require_getCacheKey = require("./getCacheKey.cjs");
|
|
10
|
-
let common_tags = require("common-tags");
|
|
11
|
-
//#region src/lib/buildCustomTypeType.ts
|
|
12
|
-
function buildCustomTypeType(args) {
|
|
13
|
-
if (args.cache) {
|
|
14
|
-
const key = require_getCacheKey.getCacheKey(args.model);
|
|
15
|
-
const cached = args.cache.get(key);
|
|
16
|
-
if (cached) return cached;
|
|
17
|
-
}
|
|
18
|
-
let code = "";
|
|
19
|
-
const auxiliaryTypes = [];
|
|
20
|
-
const contentTypeNames = [];
|
|
21
|
-
const name = require_buildTypeName.buildTypeName(args.model.id, "Document");
|
|
22
|
-
const langDefault = args.localeIDs && args.localeIDs.length > 0 ? require_buildUnion.buildUnion(args.localeIDs.map((localeID) => `"${localeID}"`)) : "string";
|
|
23
|
-
const baseDocumentType = require_checkHasUIDFIeld.checkHasUIDField(args.model) ? "PrismicDocumentWithUID" : "PrismicDocumentWithoutUID";
|
|
24
|
-
const humanReadableName = require_getHumanReadableModelName.getHumanReadableModelName({
|
|
25
|
-
name: args.model.id,
|
|
26
|
-
model: args.model
|
|
27
|
-
});
|
|
28
|
-
const dataType = require_buildCustomTypeDataType.buildCustomTypeDataType({
|
|
29
|
-
model: args.model,
|
|
30
|
-
fieldConfigs: args.fieldConfigs
|
|
31
|
-
});
|
|
32
|
-
auxiliaryTypes.push(...dataType.auxiliaryTypes);
|
|
33
|
-
contentTypeNames.push(dataType.name);
|
|
34
|
-
contentTypeNames.push(...dataType.contentTypeNames);
|
|
35
|
-
code = require_addSection.addSection(dataType.code, code);
|
|
36
|
-
code = require_addSection.addSection(common_tags.source`
|
|
37
|
-
/**
|
|
38
|
-
* ${humanReadableName} document from Prismic
|
|
39
|
-
*
|
|
40
|
-
* - **API ID**: \`${args.model.id}\`
|
|
41
|
-
* - **Repeatable**: \`${args.model.repeatable.toString()}\`
|
|
42
|
-
* - **Documentation**: ${require_constants.CUSTOM_TYPES_DOCUMENTATION_URL}
|
|
43
|
-
*
|
|
44
|
-
* @typeParam Lang - Language API ID of the document.
|
|
45
|
-
*/
|
|
46
|
-
export type ${name}<Lang extends string = ${langDefault}> = prismic.${baseDocumentType}<Simplify<${dataType.name}>, "${args.model.id}", Lang>;
|
|
47
|
-
`, code);
|
|
48
|
-
const result = {
|
|
49
|
-
name,
|
|
50
|
-
code,
|
|
51
|
-
auxiliaryTypes,
|
|
52
|
-
contentTypeNames
|
|
53
|
-
};
|
|
54
|
-
if (args.cache) {
|
|
55
|
-
const key = require_getCacheKey.getCacheKey(args.model);
|
|
56
|
-
args.cache.set(key, result);
|
|
57
|
-
}
|
|
58
|
-
return result;
|
|
59
|
-
}
|
|
60
|
-
//#endregion
|
|
61
|
-
exports.buildCustomTypeType = buildCustomTypeType;
|
|
62
|
-
|
|
63
|
-
//# sourceMappingURL=buildCustomTypeType.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"buildCustomTypeType.cjs","names":["getCacheKey","buildTypeName","buildUnion","checkHasUIDField","getHumanReadableModelName","buildCustomTypeDataType","addSection","CUSTOM_TYPES_DOCUMENTATION_URL"],"sources":["../../src/lib/buildCustomTypeType.ts"],"sourcesContent":["import type { CustomTypeModel } from \"@prismicio/client\";\nimport { source } from \"common-tags\";\nimport type QuickLRU from \"quick-lru\";\n\nimport { CUSTOM_TYPES_DOCUMENTATION_URL } from \"../constants\";\nimport type { AuxiliaryType, FieldConfigs } from \"../types\";\nimport { addSection } from \"./addSection\";\nimport { buildCustomTypeDataType } from \"./buildCustomTypeDataType\";\nimport { buildTypeName } from \"./buildTypeName\";\nimport { buildUnion } from \"./buildUnion\";\nimport { checkHasUIDField } from \"./checkHasUIDFIeld\";\nimport { getCacheKey } from \"./getCacheKey\";\nimport { getHumanReadableModelName } from \"./getHumanReadableModelName\";\n\ntype BuildCustomTypeTypesArgs = {\n\tmodel: CustomTypeModel;\n\tlocaleIDs?: string[];\n\tfieldConfigs: FieldConfigs;\n\tcache?: QuickLRU<string, unknown>;\n};\n\ntype BuildCustomTypeTypeReturnValue = {\n\tname: string;\n\tcode: string;\n\tauxiliaryTypes: AuxiliaryType[];\n\tcontentTypeNames: string[];\n};\n\nexport function buildCustomTypeType(\n\targs: BuildCustomTypeTypesArgs\n): BuildCustomTypeTypeReturnValue {\n\tif (args.cache) {\n\t\tconst key = getCacheKey(args.model);\n\t\tconst cached = args.cache.get(key);\n\n\t\tif (cached) {\n\t\t\treturn cached as BuildCustomTypeTypeReturnValue;\n\t\t}\n\t}\n\n\tlet code = \"\";\n\n\tconst auxiliaryTypes: AuxiliaryType[] = [];\n\tconst contentTypeNames: string[] = [];\n\n\tconst name = buildTypeName(args.model.id, \"Document\");\n\tconst langDefault =\n\t\targs.localeIDs && args.localeIDs.length > 0\n\t\t\t? buildUnion(args.localeIDs.map((localeID) => `\"${localeID}\"`))\n\t\t\t: \"string\";\n\tconst baseDocumentType = checkHasUIDField(args.model)\n\t\t? \"PrismicDocumentWithUID\"\n\t\t: \"PrismicDocumentWithoutUID\";\n\tconst humanReadableName = getHumanReadableModelName({\n\t\tname: args.model.id,\n\t\tmodel: args.model,\n\t});\n\n\tconst dataType = buildCustomTypeDataType({\n\t\tmodel: args.model,\n\t\tfieldConfigs: args.fieldConfigs,\n\t});\n\n\tauxiliaryTypes.push(...dataType.auxiliaryTypes);\n\tcontentTypeNames.push(dataType.name);\n\tcontentTypeNames.push(...dataType.contentTypeNames);\n\n\tcode = addSection(dataType.code, code);\n\n\tcode = addSection(\n\t\tsource`\n\t\t\t/**\n\t\t\t * ${humanReadableName} document from Prismic\n\t\t\t *\n\t\t\t * - **API ID**: \\`${args.model.id}\\`\n\t\t\t * - **Repeatable**: \\`${args.model.repeatable.toString()}\\`\n\t\t\t * - **Documentation**: ${CUSTOM_TYPES_DOCUMENTATION_URL}\n\t\t\t *\n\t\t\t * @typeParam Lang - Language API ID of the document.\n\t\t\t */\n\t\t\texport type ${name}<Lang extends string = ${langDefault}> = prismic.${baseDocumentType}<Simplify<${\n\t\t\tdataType.name\n\t\t}>, \"${args.model.id}\", Lang>;\n\t\t`,\n\t\tcode\n\t);\n\n\tconst result = {\n\t\tname,\n\t\tcode,\n\t\tauxiliaryTypes,\n\t\tcontentTypeNames,\n\t};\n\n\tif (args.cache) {\n\t\tconst key = getCacheKey(args.model);\n\n\t\targs.cache.set(key, result);\n\t}\n\n\treturn result;\n}\n"],"mappings":";;;;;;;;;;;AA4BA,SAAgB,oBACf,MACiC;AACjC,KAAI,KAAK,OAAO;EACf,MAAM,MAAMA,oBAAAA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Type.ts"],"sourcesContent":["import type { CustomTypeModel } from \"@prismicio/client\";\nimport { source } from \"common-tags\";\nimport type QuickLRU from \"quick-lru\";\n\nimport { CUSTOM_TYPES_DOCUMENTATION_URL } from \"../constants\";\nimport type { AuxiliaryType, FieldConfigs } from \"../types\";\nimport { addSection } from \"./addSection\";\nimport { buildCustomTypeDataType } from \"./buildCustomTypeDataType\";\nimport { buildTypeName } from \"./buildTypeName\";\nimport { buildUnion } from \"./buildUnion\";\nimport { checkHasUIDField } from \"./checkHasUIDFIeld\";\nimport { getCacheKey } from \"./getCacheKey\";\nimport { getHumanReadableModelName } from \"./getHumanReadableModelName\";\n\ntype BuildCustomTypeTypesArgs = {\n\tmodel: CustomTypeModel;\n\tlocaleIDs?: string[];\n\tfieldConfigs: FieldConfigs;\n\tcache?: QuickLRU<string, unknown>;\n};\n\ntype BuildCustomTypeTypeReturnValue = {\n\tname: string;\n\tcode: string;\n\tauxiliaryTypes: AuxiliaryType[];\n\tcontentTypeNames: string[];\n};\n\nexport function buildCustomTypeType(\n\targs: BuildCustomTypeTypesArgs\n): BuildCustomTypeTypeReturnValue {\n\tif (args.cache) {\n\t\tconst key = getCacheKey(args.model);\n\t\tconst cached = args.cache.get(key);\n\n\t\tif (cached) {\n\t\t\treturn cached as BuildCustomTypeTypeReturnValue;\n\t\t}\n\t}\n\n\tlet code = \"\";\n\n\tconst auxiliaryTypes: AuxiliaryType[] = [];\n\tconst contentTypeNames: string[] = [];\n\n\tconst name = buildTypeName(args.model.id, \"Document\");\n\tconst langDefault =\n\t\targs.localeIDs && args.localeIDs.length > 0\n\t\t\t? buildUnion(args.localeIDs.map((localeID) => `\"${localeID}\"`))\n\t\t\t: \"string\";\n\tconst baseDocumentType = checkHasUIDField(args.model)\n\t\t? \"PrismicDocumentWithUID\"\n\t\t: \"PrismicDocumentWithoutUID\";\n\tconst humanReadableName = getHumanReadableModelName({\n\t\tname: args.model.id,\n\t\tmodel: args.model,\n\t});\n\n\tconst dataType = buildCustomTypeDataType({\n\t\tmodel: args.model,\n\t\tfieldConfigs: args.fieldConfigs,\n\t});\n\n\tauxiliaryTypes.push(...dataType.auxiliaryTypes);\n\tcontentTypeNames.push(dataType.name);\n\tcontentTypeNames.push(...dataType.contentTypeNames);\n\n\tcode = addSection(dataType.code, code);\n\n\tcode = addSection(\n\t\tsource`\n\t\t\t/**\n\t\t\t * ${humanReadableName} document from Prismic\n\t\t\t *\n\t\t\t * - **API ID**: \\`${args.model.id}\\`\n\t\t\t * - **Repeatable**: \\`${args.model.repeatable.toString()}\\`\n\t\t\t * - **Documentation**: ${CUSTOM_TYPES_DOCUMENTATION_URL}\n\t\t\t *\n\t\t\t * @typeParam Lang - Language API ID of the document.\n\t\t\t */\n\t\t\texport type ${name}<Lang extends string = ${langDefault}> = prismic.${baseDocumentType}<Simplify<${\n\t\t\tdataType.name\n\t\t}>, \"${args.model.id}\", Lang>;\n\t\t`,\n\t\tcode\n\t);\n\n\tconst result = {\n\t\tname,\n\t\tcode,\n\t\tauxiliaryTypes,\n\t\tcontentTypeNames,\n\t};\n\n\tif (args.cache) {\n\t\tconst key = getCacheKey(args.model);\n\n\t\targs.cache.set(key, result);\n\t}\n\n\treturn result;\n}\n"],"mappings":";;;;;;;;;;AA4BA,SAAgB,oBACf,MACiC;AACjC,KAAI,KAAK,OAAO;EACf,MAAM,MAAM,YAAY,KAAK,MAAM;EACnC,MAAM,SAAS,KAAK,MAAM,IAAI,IAAI;AAElC,MAAI,OACH,QAAO;;CAIT,IAAI,OAAO;CAEX,MAAM,iBAAkC,EAAE;CAC1C,MAAM,mBAA6B,EAAE;CAErC,MAAM,OAAO,cAAc,KAAK,MAAM,IAAI,WAAW;CACrD,MAAM,cACL,KAAK,aAAa,KAAK,UAAU,SAAS,IACvC,WAAW,KAAK,UAAU,KAAK,aAAa,IAAI,SAAS,GAAG,CAAC,GAC7D;CACJ,MAAM,mBAAmB,iBAAiB,KAAK,MAAM,GAClD,2BACA;CACH,MAAM,oBAAoB,0BAA0B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