UNPKG

gatsby-source-prismic

Version:

Gatsby source plugin for building websites using Prismic as a data source

1 lines 3.81 kB
{"version":3,"file":"buildImgixURLParamsInputObjectType.cjs","sources":["../../../src/lib/buildImgixURLParamsInputObjectType.ts"],"sourcesContent":["import { camelCase } from \"camel-case\";\nimport type { GatsbyGraphQLInputObjectType, NodePluginSchema } from \"gatsby\";\nimport { parameters as imgixParamSpecs } from \"imgix-url-params/dist/parameters.json\";\n\nexport type BuildImgixParamsInputObjectTypeConfig = {\n\tschema: NodePluginSchema;\n};\n\nexport const buildImgixURLParamsInputObjectType = (\n\tconfig: BuildImgixParamsInputObjectTypeConfig,\n): GatsbyGraphQLInputObjectType => {\n\tconst fields: GatsbyGraphQLInputObjectType[\"config\"][\"fields\"] = {};\n\n\tfor (const paramKey in imgixParamSpecs) {\n\t\tconst paramSpec = imgixParamSpecs[paramKey as keyof typeof imgixParamSpecs];\n\n\t\tconst normalizedName = camelCase(paramKey);\n\n\t\tconst expects = paramSpec.expects;\n\t\tconst expectsTypes = Array.from(\n\t\t\tnew Set(expects.map((expect) => expect.type)),\n\t\t);\n\n\t\tconst type = expectsTypes.every(\n\t\t\t(type) => type === \"integer\" || type === \"unit_scalar\",\n\t\t)\n\t\t\t? \"Int\"\n\t\t\t: expectsTypes.every(\n\t\t\t\t\t(type) =>\n\t\t\t\t\t\ttype === \"integer\" || type === \"unit_scalar\" || type === \"number\",\n\t\t\t )\n\t\t\t? \"Float\"\n\t\t\t: expectsTypes.every((type) => type === \"boolean\")\n\t\t\t? \"Boolean\"\n\t\t\t: \"String\";\n\n\t\tconst description =\n\t\t\t\"short_description\" in paramSpec\n\t\t\t\t? paramSpec.short_description +\n\t\t\t\t // Ensure the description ends with a period.\n\t\t\t\t (paramSpec.short_description.slice(-1) === \".\" ? \"\" : \".\")\n\t\t\t\t: undefined;\n\n\t\tconst fieldDefinition: (typeof fields)[string] = {\n\t\t\ttype,\n\t\t\tdescription,\n\t\t};\n\n\t\t// Add the default value as part of the description. Setting it as a\n\t\t// GraphQL default value will automatically assign it in the final URL.\n\t\t// Doing so would result in a huge number of unwanted params.\n\t\tif (\"default\" in paramSpec) {\n\t\t\tfieldDefinition.description =\n\t\t\t\tfieldDefinition.description + ` Default: \\`${paramSpec.default}\\`.`;\n\t\t}\n\n\t\t// Add Imgix documentation URL as part of the description.\n\t\tif (\"url\" in paramSpec) {\n\t\t\tfieldDefinition.description =\n\t\t\t\tfieldDefinition.description + ` [See docs](${paramSpec.url}).`;\n\t\t}\n\n\t\tfields[normalizedName] = fieldDefinition;\n\n\t\t// Create aliased fields.\n\t\tif (\"aliases\" in paramSpec) {\n\t\t\tfor (const alias of paramSpec.aliases) {\n\t\t\t\tfields[camelCase(alias)] = {\n\t\t\t\t\t...fieldDefinition,\n\t\t\t\t\tdescription: `Alias for \\`${normalizedName}\\`.`,\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\t}\n\n\treturn config.schema.buildInputObjectType({\n\t\tname: \"PrismicImgixURLParams\",\n\t\tfields,\n\t});\n};\n"],"names":["imgixParamSpecs","camelCase","type"],"mappings":";;;;AAQa,MAAA,qCAAqC,CACjD,WACiC;AACjC,QAAM,SAA2D,CAAA;AAEjE,aAAW,YAAYA,4BAAiB;AACjC,UAAA,YAAYA,2BAAgB,QAAwC;AAEpE,UAAA,iBAAiBC,oBAAU,QAAQ;AAEzC,UAAM,UAAU,UAAU;AAC1B,UAAM,eAAe,MAAM,KAC1B,IAAI,IAAI,QAAQ,IAAI,CAAC,WAAW,OAAO,IAAI,CAAC,CAAC;AAG9C,UAAM,OAAO,aAAa,MACzB,CAACC,UAASA,UAAS,aAAaA,UAAS,aAAa,IAEpD,QACA,aAAa,MACb,CAACA,UACAA,UAAS,aAAaA,UAAS,iBAAiBA,UAAS,QAAQ,IAElE,UACA,aAAa,MAAM,CAACA,UAASA,UAAS,SAAS,IAC/C,YACA;AAEG,UAAA,cACL,uBAAuB,YACpB,UAAU;AAAA,KAET,UAAU,kBAAkB,MAAM,EAAE,MAAM,MAAM,KAAK,OACtD;AAEJ,UAAM,kBAA2C;AAAA,MAChD;AAAA,MACA;AAAA,IAAA;AAMD,QAAI,aAAa,WAAW;AAC3B,sBAAgB,cACf,gBAAgB,cAAc,eAAe,UAAU;AAAA,IACxD;AAGD,QAAI,SAAS,WAAW;AACvB,sBAAgB,cACf,gBAAgB,cAAc,eAAe,UAAU;AAAA,IACxD;AAED,WAAO,cAAc,IAAI;AAGzB,QAAI,aAAa,WAAW;AAChB,iBAAA,SAAS,UAAU,SAAS;AAC/B,eAAAD,UAAAA,UAAU,KAAK,CAAC,IAAI;AAAA,UAC1B,GAAG;AAAA,UACH,aAAa,eAAe;AAAA,QAAA;AAAA,MAE7B;AAAA,IACD;AAAA,EACD;AAEM,SAAA,OAAO,OAAO,qBAAqB;AAAA,IACzC,MAAM;AAAA,IACN;AAAA,EAAA,CACA;AACF;;"}