@prismicio/client 7.0.0-alpha.5 → 7.0.0
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/buildQueryURL.cjs.map +1 -1
- package/dist/buildQueryURL.d.ts +4 -4
- package/dist/buildQueryURL.js.map +1 -1
- package/dist/createClient.cjs +24 -24
- package/dist/createClient.cjs.map +1 -1
- package/dist/createClient.d.ts +28 -28
- package/dist/createClient.js +24 -24
- package/dist/createClient.js.map +1 -1
- package/dist/filter.cjs +1 -1
- package/dist/filter.cjs.map +1 -1
- package/dist/filter.d.ts +1 -1
- package/dist/filter.js +1 -1
- package/dist/filter.js.map +1 -1
- package/dist/helpers/asDate.cjs.map +1 -1
- package/dist/helpers/asDate.d.ts +2 -2
- package/dist/helpers/asDate.js.map +1 -1
- package/dist/helpers/asHTML.cjs.map +1 -1
- package/dist/helpers/asHTML.d.ts +17 -17
- package/dist/helpers/asHTML.js.map +1 -1
- package/dist/helpers/asImagePixelDensitySrcSet.cjs.map +1 -1
- package/dist/helpers/asImagePixelDensitySrcSet.d.ts +5 -5
- package/dist/helpers/asImagePixelDensitySrcSet.js.map +1 -1
- package/dist/helpers/asImageSrc.cjs.map +1 -1
- package/dist/helpers/asImageSrc.d.ts +3 -3
- package/dist/helpers/asImageSrc.js.map +1 -1
- package/dist/helpers/asImageWidthSrcSet.cjs.map +1 -1
- package/dist/helpers/asImageWidthSrcSet.d.ts +6 -6
- package/dist/helpers/asImageWidthSrcSet.js.map +1 -1
- package/dist/helpers/asLink.cjs.map +1 -1
- package/dist/helpers/asLink.d.ts +14 -14
- package/dist/helpers/asLink.js.map +1 -1
- package/dist/helpers/asLinkAttrs.cjs.map +1 -1
- package/dist/helpers/asLinkAttrs.d.ts +5 -5
- package/dist/helpers/asLinkAttrs.js.map +1 -1
- package/dist/helpers/asText.cjs.map +1 -1
- package/dist/helpers/asText.d.ts +8 -8
- package/dist/helpers/asText.js.map +1 -1
- package/dist/helpers/documentToLinkField.cjs.map +1 -1
- package/dist/helpers/documentToLinkField.js.map +1 -1
- package/dist/helpers/isFilled.cjs +3 -1
- package/dist/helpers/isFilled.cjs.map +1 -1
- package/dist/helpers/isFilled.d.ts +24 -20
- package/dist/helpers/isFilled.js +3 -1
- package/dist/helpers/isFilled.js.map +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +12 -2
- package/dist/index.js.map +1 -1
- package/dist/package.json.cjs +1 -1
- package/dist/package.json.js +1 -1
- package/dist/types/api/repository.d.ts +2 -2
- package/dist/types/model/boolean.d.ts +1 -1
- package/dist/types/model/color.d.ts +1 -1
- package/dist/types/model/contentRelationship.d.ts +1 -1
- package/dist/types/model/customType.d.ts +11 -11
- package/dist/types/model/date.d.ts +1 -1
- package/dist/types/model/embed.d.ts +1 -1
- package/dist/types/model/geoPoint.d.ts +1 -1
- package/dist/types/model/group.d.ts +1 -1
- package/dist/types/model/image.d.ts +3 -3
- package/dist/types/model/{integrationFields.d.ts → integration.d.ts} +3 -3
- package/dist/types/model/keyText.d.ts +1 -1
- package/dist/types/model/link.cjs.map +1 -1
- package/dist/types/model/link.d.ts +2 -2
- package/dist/types/model/link.js.map +1 -1
- package/dist/types/model/linkToMedia.d.ts +1 -1
- package/dist/types/model/number.d.ts +1 -1
- package/dist/types/model/richText.d.ts +3 -3
- package/dist/types/model/select.d.ts +1 -1
- package/dist/types/model/sharedSlice.d.ts +2 -2
- package/dist/types/model/sharedSliceVariation.d.ts +1 -1
- package/dist/types/model/slice.cjs.map +1 -1
- package/dist/types/model/slice.d.ts +1 -1
- package/dist/types/model/slice.js.map +1 -1
- package/dist/types/model/sliceZone.cjs.map +1 -1
- package/dist/types/model/sliceZone.d.ts +2 -2
- package/dist/types/model/sliceZone.js.map +1 -1
- package/dist/types/model/timestamp.d.ts +1 -1
- package/dist/types/model/title.d.ts +1 -1
- package/dist/types/model/types.cjs +5 -1
- package/dist/types/model/types.cjs.map +1 -1
- package/dist/types/model/types.d.ts +10 -6
- package/dist/types/model/types.js +5 -1
- package/dist/types/model/types.js.map +1 -1
- package/dist/types/model/uid.d.ts +1 -1
- package/dist/types/value/boolean.d.ts +1 -1
- package/dist/types/value/color.d.ts +1 -1
- package/dist/types/value/contentRelationship.d.ts +1 -1
- package/dist/types/value/date.d.ts +1 -1
- package/dist/types/value/document.d.ts +4 -4
- package/dist/types/value/embed.cjs.map +1 -1
- package/dist/types/value/embed.d.ts +1 -1
- package/dist/types/value/embed.js.map +1 -1
- package/dist/types/value/geoPoint.d.ts +1 -1
- package/dist/types/value/group.d.ts +1 -1
- package/dist/types/value/image.d.ts +3 -3
- package/dist/types/value/{integrationFields.d.ts → integration.d.ts} +2 -2
- package/dist/types/value/keyText.d.ts +1 -1
- package/dist/types/value/link.cjs.map +1 -1
- package/dist/types/value/link.d.ts +2 -2
- package/dist/types/value/link.js.map +1 -1
- package/dist/types/value/linkToMedia.d.ts +2 -2
- package/dist/types/value/number.d.ts +1 -1
- package/dist/types/value/richText.cjs.map +1 -1
- package/dist/types/value/richText.d.ts +26 -26
- package/dist/types/value/richText.js.map +1 -1
- package/dist/types/value/select.d.ts +1 -1
- package/dist/types/value/sharedSlice.d.ts +1 -1
- package/dist/types/value/sharedSliceVariation.d.ts +3 -0
- package/dist/types/value/slice.d.ts +1 -1
- package/dist/types/value/timestamp.d.ts +1 -1
- package/dist/types/value/title.d.ts +1 -1
- package/dist/types/value/types.d.ts +2 -2
- package/dist/types/webhook/apiUpdate.d.ts +1 -1
- package/package.json +2 -2
- package/src/buildQueryURL.ts +4 -4
- package/src/createClient.ts +28 -28
- package/src/filter.ts +1 -1
- package/src/helpers/asDate.ts +2 -2
- package/src/helpers/asHTML.ts +18 -18
- package/src/helpers/asImagePixelDensitySrcSet.ts +5 -5
- package/src/helpers/asImageSrc.ts +3 -3
- package/src/helpers/asImageWidthSrcSet.ts +6 -6
- package/src/helpers/asLink.ts +18 -18
- package/src/helpers/asLinkAttrs.ts +5 -5
- package/src/helpers/asText.ts +8 -8
- package/src/helpers/documentToLinkField.ts +1 -1
- package/src/helpers/isFilled.ts +27 -22
- package/src/index.ts +19 -3
- package/src/types/api/repository.ts +2 -2
- package/src/types/model/boolean.ts +1 -1
- package/src/types/model/color.ts +1 -1
- package/src/types/model/contentRelationship.ts +1 -1
- package/src/types/model/customType.ts +11 -11
- package/src/types/model/date.ts +1 -1
- package/src/types/model/embed.ts +1 -1
- package/src/types/model/geoPoint.ts +1 -1
- package/src/types/model/group.ts +1 -1
- package/src/types/model/image.ts +3 -3
- package/src/types/model/{integrationFields.ts → integration.ts} +3 -3
- package/src/types/model/keyText.ts +1 -1
- package/src/types/model/link.ts +2 -2
- package/src/types/model/linkToMedia.ts +1 -1
- package/src/types/model/number.ts +1 -1
- package/src/types/model/richText.ts +3 -3
- package/src/types/model/select.ts +1 -1
- package/src/types/model/sharedSlice.ts +2 -2
- package/src/types/model/sharedSliceVariation.ts +1 -1
- package/src/types/model/slice.ts +1 -1
- package/src/types/model/sliceZone.ts +2 -2
- package/src/types/model/timestamp.ts +1 -1
- package/src/types/model/title.ts +1 -1
- package/src/types/model/types.ts +10 -6
- package/src/types/model/uid.ts +1 -1
- package/src/types/value/boolean.ts +1 -1
- package/src/types/value/color.ts +1 -1
- package/src/types/value/contentRelationship.ts +1 -1
- package/src/types/value/date.ts +1 -1
- package/src/types/value/document.ts +4 -4
- package/src/types/value/embed.ts +1 -1
- package/src/types/value/geoPoint.ts +1 -1
- package/src/types/value/group.ts +1 -1
- package/src/types/value/image.ts +4 -4
- package/src/types/value/{integrationFields.ts → integration.ts} +2 -2
- package/src/types/value/keyText.ts +1 -1
- package/src/types/value/link.ts +2 -2
- package/src/types/value/linkToMedia.ts +2 -2
- package/src/types/value/number.ts +1 -1
- package/src/types/value/richText.ts +26 -26
- package/src/types/value/select.ts +1 -1
- package/src/types/value/sharedSlice.ts +1 -1
- package/src/types/value/sharedSliceVariation.ts +3 -0
- package/src/types/value/slice.ts +1 -1
- package/src/types/value/timestamp.ts +1 -1
- package/src/types/value/title.ts +1 -1
- package/src/types/value/types.ts +2 -2
- package/src/types/webhook/apiUpdate.ts +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildQueryURL.cjs","sources":["../../src/buildQueryURL.ts"],"sourcesContent":["import { castArray } from \"./lib/castArray\";\nimport { devMsg } from \"./lib/devMsg\";\n\n/**\n * Create a union of the given object's values, and optionally specify which\n * keys to get the values from.\n *\n * Taken from the `type-fest` package.\n *\n * See:\n * https://github.com/sindresorhus/type-fest/blob/61c35052f09caa23de5eef96d95196375d8ed498/source/value-of.d.ts\n */\ntype ValueOf<\n\tObjectType,\n\tValueType extends keyof ObjectType = keyof ObjectType,\n> = ObjectType[ValueType];\n\n/**\n * An `orderings` parameter that orders the results by the specified field.\n *\n * {@link https://prismic.io/docs/rest-api-technical-reference#orderings}\n */\nexport interface Ordering {\n\tfield: string;\n\tdirection?: \"asc\" | \"desc\";\n}\n\n/**\n * A `routes` parameter that determines how a document's URL field is resolved.\n *\n * {@link https://prismic.io/docs/route-resolver}\n *\n * @example With a document's UID field.\n *\n * ```ts\n * {\n * \t\"type\": \"page\",\n * \t\"path\": \"/:uid\"\n * }\n * ```\n *\n * @example With a Content Relationship `parent` field.\n *\n * ```ts\n * {\n * \t\"type\": \"page\",\n * \t\"path\": \"/:parent?/:uid\",\n * \t\"resolvers\": {\n * \t\t\"parent\": \"parent\"\n * \t}\n * }\n * ```\n */\nexport interface Route {\n\t/**\n\t * The Custom Type of the document.\n\t */\n\ttype: string;\n\n\t/**\n\t * A specific UID to which this route definition is scoped. The route is only\n\t * defined for the document whose UID matches the given UID.\n\t */\n\tuid?: string;\n\n\t/**\n\t * A specific language to which this route definition is scoped. The route is\n\t * only defined for documents whose language matches the given language.\n\t */\n\tlang?: string;\n\n\t/**\n\t * The resolved path of the document with optional placeholders.\n\t */\n\tpath: string;\n\n\t/**\n\t * An object that lists the API IDs of the Content Relationships in the route.\n\t */\n\tresolvers?: Record<string, string>;\n}\n\n/**\n * Parameters for the Prismic REST API V2.\n *\n * {@link https://prismic.io/docs/api}\n */\nexport interface QueryParams {\n\t/**\n\t * The secure token for accessing the API (only needed if your repository is\n\t * set to private).\n\t *\n\t * {@link https://prismic.io/docs/access-token}\n\t */\n\taccessToken?: string;\n\n\t/**\n\t * The `pageSize` parameter defines the maximum number of documents that the\n\t * API will return for your query.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#pagesize}\n\t */\n\tpageSize?: number;\n\n\t/**\n\t * The `page` parameter defines the pagination for the result of your query.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#page}\n\t */\n\tpage?: number;\n\n\t/**\n\t * The `after` parameter can be used along with the orderings option. It will\n\t * remove all the documents except for those after the specified document in\n\t * the list.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#after}\n\t */\n\tafter?: string;\n\n\t/**\n\t * The `fetch` parameter is used to make queries faster by only retrieving the\n\t * specified field(s).\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#fetch}\n\t */\n\tfetch?: string | string[];\n\n\t/**\n\t * The `fetchLinks` parameter allows you to retrieve a specific content field\n\t * from a linked document and add it to the document response object.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#fetchlinks}\n\t */\n\tfetchLinks?: string | string[];\n\n\t/**\n\t * The `graphQuery` parameter allows you to specify which fields to retrieve\n\t * and what content to retrieve from Linked Documents / Content\n\t * Relationships.\n\t *\n\t * {@link https://prismic.io/docs/graphquery-rest-api}\n\t */\n\tgraphQuery?: string;\n\n\t/**\n\t * The `lang` option defines the language code for the results of your query.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#lang}\n\t */\n\tlang?: string;\n\n\t/**\n\t * The `orderings` parameter orders the results by the specified field(s). You\n\t * can specify as many fields as you want.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#orderings}\n\t *\n\t * @remarks Strings and arrays of strings are deprecated as of\n\t * `@prismicio/client@7.0.0`. Please migrate to the more explicit\n\t * array of objects.\n\t *\n\t * @example\n\t *\n\t * ```typescript\n\t * buildQueryURL(endpoint,{\n\t * orderings: [\n\t * { field: \"my.product.price\", direction: \"desc\" },\n\t * { field: \"my.product.title\" },\n\t * ],\n\t * });\n\t * ```\n\t */\n\t// TODO: Update TSDoc with deprecated API removal in v8\n\torderings?: string | Ordering | (string | Ordering)[];\n\n\t/**\n\t * The `routes` option allows you to define how a document's `url` field is\n\t * resolved.\n\t *\n\t * {@link https://prismic.io/docs/route-resolver}\n\t */\n\troutes?: Route | string | (Route | string)[];\n\n\t/**\n\t * The `brokenRoute` option allows you to define the route populated in the\n\t * `url` property for broken Link or Content Relationship fields. A broken\n\t * link is a Link or Content Relationship field whose linked document has been\n\t * unpublished or deleted.\n\t *\n\t * {@link https://prismic.io/docs/route-resolver}\n\t */\n\tbrokenRoute?: string;\n}\n\n/**\n * Arguments for `buildQueryURL` to construct a Query URL.\n */\ntype BuildQueryURLParams = {\n\t/**\n\t * Ref used to query documents.\n\t *\n\t * {@link https://prismic.io/docs/api#refs-and-the-entry-api}\n\t */\n\tref: string;\n\n\t/**\n\t * Ref used to populate Integration Fields with the latest content.\n\t *\n\t * {@link https://prismic.io/docs/integration-fields}\n\t */\n\tintegrationFieldsRef?: string;\n\n\t/**\n\t * One or more filters to filter documents for the query.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#q}\n\t */\n\tfilters?: string | string[];\n\n\t/**\n\t * @deprecated Renamed to `filters`. Ensure the value is an array of filters, not a single, non-array filter.\n\t */\n\tpredicates?: string | string[];\n};\n\n/**\n * Parameters in this map have been renamed from the official Prismic REST API\n * V2 specification for better developer ergonomics.\n *\n * These parameters are renamed to their mapped value.\n */\nconst RENAMED_PARAMS = {\n\taccessToken: \"access_token\",\n} as const;\n\n/**\n * A valid parameter name for the Prismic REST API V2.\n */\ntype ValidParamName =\n\t| Exclude<\n\t\t\tkeyof QueryParams,\n\t\t\tkeyof typeof RENAMED_PARAMS | keyof BuildQueryURLParams\n\t >\n\t| ValueOf<typeof RENAMED_PARAMS>;\n\n/**\n * Converts an Ordering to a string that is compatible with Prismic's REST API.\n * If the value provided is already a string, no conversion is performed.\n *\n * @param ordering - Ordering to convert.\n *\n * @returns String representation of the Ordering.\n */\nconst castOrderingToString = (ordering: Ordering | string): string => {\n\t// TODO: Remove the following when `orderings` strings are no longer supported.\n\tif (typeof ordering === \"string\") {\n\t\tif (process.env.NODE_ENV === \"development\") {\n\t\t\tconst [field, direction] = ordering.split(\" \");\n\n\t\t\tconst objectForm =\n\t\t\t\tdirection === \"desc\"\n\t\t\t\t\t? `{ field: \"${field}\", direction: \"desc\" }`\n\t\t\t\t\t: `{ field: \"${field}\" }`;\n\n\t\t\tconsole.warn(\n\t\t\t\t`[@prismicio/client] A string value was provided to the \\`orderings\\` query parameter. Strings are deprecated. Please convert it to the object form: ${objectForm}. For more details, see ${devMsg(\n\t\t\t\t\t\"orderings-must-be-an-array-of-objects\",\n\t\t\t\t)}`,\n\t\t\t);\n\t\t}\n\n\t\treturn ordering;\n\t}\n\n\treturn ordering.direction === \"desc\"\n\t\t? `${ordering.field} desc`\n\t\t: ordering.field;\n};\n\nexport type BuildQueryURLArgs = QueryParams & BuildQueryURLParams;\n\n/**\n * Build a Prismic REST API V2 URL to request documents from a repository. The\n * paginated response for this URL includes documents matching the parameters.\n *\n * A ref is required to make a request. Request the `endpoint` URL to retrieve a\n * list of available refs.\n *\n * Type the JSON response with `Query`.\n *\n * {@link https://prismic.io/docs/api#refs-and-the-entry-api}\n * {@link https://prismic.io/docs/rest-api-technical-reference}\n *\n * @param endpoint - URL to the repository's REST API V2.\n * @param args - Arguments to filter and scope the query.\n *\n * @returns URL that can be used to request documents from the repository.\n */\nexport const buildQueryURL = (\n\tendpoint: string,\n\targs: BuildQueryURLArgs,\n): string => {\n\tconst { filters, predicates, ...params } = args;\n\n\tconst url = new URL(`documents/search`, `${endpoint}/`);\n\n\tif (filters) {\n\t\t// TODO: Remove warning when we remove support for string `filters` values.\n\t\tif (process.env.NODE_ENV === \"development\" && !Array.isArray(filters)) {\n\t\t\tconsole.warn(\n\t\t\t\t`[@prismicio/client] A non-array value was provided to the \\`filters\\` query parameter (\\`${filters}\\`). Non-array values are deprecated. Please convert it to an array. For more details, see ${devMsg(\n\t\t\t\t\t\"filters-must-be-an-array\",\n\t\t\t\t)}`,\n\t\t\t);\n\t\t}\n\n\t\t// TODO: Remove `castArray` when we remove support for string `filters` values.\n\t\tfor (const filter of castArray(filters)) {\n\t\t\turl.searchParams.append(\"q\", `[${filter}]`);\n\t\t}\n\t}\n\n\t// TODO: Remove when we remove support for deprecated `predicates` argument.\n\tif (predicates) {\n\t\tfor (const predicate of castArray(predicates)) {\n\t\t\turl.searchParams.append(\"q\", `[${predicate}]`);\n\t\t}\n\t}\n\n\t// Iterate over each parameter and add it to the URL. In some cases, the\n\t// parameter value needs to be transformed to fit the REST API.\n\tfor (const k in params) {\n\t\tconst name = (RENAMED_PARAMS[k as keyof typeof RENAMED_PARAMS] ||\n\t\t\tk) as ValidParamName;\n\n\t\tlet value = params[k as keyof typeof params];\n\n\t\tif (name === \"orderings\") {\n\t\t\tconst scopedValue = params[name];\n\n\t\t\tif (scopedValue != null) {\n\t\t\t\t// TODO: Remove the following warning when `orderings` strings are no longer supported.\n\t\t\t\tif (\n\t\t\t\t\tprocess.env.NODE_ENV === \"development\" &&\n\t\t\t\t\ttypeof scopedValue === \"string\"\n\t\t\t\t) {\n\t\t\t\t\tconsole.warn(\n\t\t\t\t\t\t`[@prismicio/client] A string value was provided to the \\`orderings\\` query parameter. Strings are deprecated. Please convert it to an array of objects. For more details, see ${devMsg(\n\t\t\t\t\t\t\t\"orderings-must-be-an-array-of-objects\",\n\t\t\t\t\t\t)}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tconst v = castArray(scopedValue)\n\t\t\t\t\t.map((ordering) => castOrderingToString(ordering))\n\t\t\t\t\t.join(\",\");\n\n\t\t\t\tvalue = `[${v}]`;\n\t\t\t}\n\t\t} else if (name === \"routes\") {\n\t\t\tif (typeof params[name] === \"object\") {\n\t\t\t\tvalue = JSON.stringify(castArray(params[name]));\n\t\t\t}\n\t\t}\n\n\t\tif (value != null) {\n\t\t\turl.searchParams.set(\n\t\t\t\tname,\n\t\t\t\tcastArray<string | number | Route | Ordering>(value).join(\",\"),\n\t\t\t);\n\t\t}\n\t}\n\n\treturn url.toString();\n};\n"],"names":["devMsg","castArray"],"mappings":";;;;AAwOA,MAAM,iBAAiB;AAAA,EACtB,aAAa;;AAqBd,MAAM,uBAAuB,CAAC,aAAuC;AAEhE,MAAA,OAAO,aAAa,UAAU;AAC7B,QAAA,QAAQ,IAAI,aAAa,eAAe;AAC3C,YAAM,CAAC,OAAO,SAAS,IAAI,SAAS,MAAM,GAAG;AAE7C,YAAM,aACL,cAAc,SACX,aAAa,gCACb,aAAa;AAEjB,cAAQ,KACP,uJAAuJ,qCAAqCA,cAC3L,uCAAuC,GACrC;AAAA,IAEJ;AAEM,WAAA;AAAA,EACP;AAED,SAAO,SAAS,cAAc,SAC3B,GAAG,SAAS,eACZ,SAAS;AACb;AAqBa,MAAA,gBAAgB,CAC5B,UACA,SACW;AACX,QAAM,EAAE,SAAS,YAAY,GAAG,WAAW;AAE3C,QAAM,MAAM,IAAI,IAAI,oBAAoB,GAAG,WAAW;AAEtD,MAAI,SAAS;AAER,QAAA,QAAQ,IAAI,aAAa,iBAAiB,CAAC,MAAM,QAAQ,OAAO,GAAG;AACtE,cAAQ,KACP,4FAA4F,qGAAqGA,cAChM,0BAA0B,GACxB;AAAA,IAEJ;AAGU,eAAA,UAAUC,oBAAU,OAAO,GAAG;AACxC,UAAI,aAAa,OAAO,KAAK,IAAI,SAAS;AAAA,IAC1C;AAAA,EACD;AAGD,MAAI,YAAY;AACJ,eAAA,aAAaA,oBAAU,UAAU,GAAG;AAC9C,UAAI,aAAa,OAAO,KAAK,IAAI,YAAY;AAAA,IAC7C;AAAA,EACD;AAID,aAAW,KAAK,QAAQ;AACjB,UAAA,OAAQ,eAAe,CAAgC,KAC5D;AAEG,QAAA,QAAQ,OAAO,CAAwB;AAE3C,QAAI,SAAS,aAAa;AACnB,YAAA,cAAc,OAAO,IAAI;AAE/B,UAAI,eAAe,MAAM;AAExB,YACC,QAAQ,IAAI,aAAa,iBACzB,OAAO,gBAAgB,UACtB;AACD,kBAAQ,KACP,iLAAiLD,OAChL,OAAA,uCAAuC,GACrC;AAAA,QAEJ;AAED,cAAM,IAAIC,UAAAA,UAAU,WAAW,EAC7B,IAAI,CAAC,aAAa,qBAAqB,QAAQ,CAAC,EAChD,KAAK,GAAG;AAEV,gBAAQ,IAAI;AAAA,MACZ;AAAA,IAAA,WACS,SAAS,UAAU;AAC7B,UAAI,OAAO,OAAO,IAAI,MAAM,UAAU;AACrC,gBAAQ,KAAK,UAAUA,UAAAA,UAAU,OAAO,IAAI,CAAC,CAAC;AAAA,MAC9C;AAAA,IACD;AAED,QAAI,SAAS,MAAM;AACd,UAAA,aAAa,IAChB,MACAA,UAAAA,UAA8C,KAAK,EAAE,KAAK,GAAG,CAAC;AAAA,IAE/D;AAAA,EACD;AAED,SAAO,IAAI;AACZ;;"}
|
|
1
|
+
{"version":3,"file":"buildQueryURL.cjs","sources":["../../src/buildQueryURL.ts"],"sourcesContent":["import { castArray } from \"./lib/castArray\";\nimport { devMsg } from \"./lib/devMsg\";\n\n/**\n * Create a union of the given object's values, and optionally specify which\n * keys to get the values from.\n *\n * Taken from the `type-fest` package.\n *\n * See:\n * https://github.com/sindresorhus/type-fest/blob/61c35052f09caa23de5eef96d95196375d8ed498/source/value-of.d.ts\n */\ntype ValueOf<\n\tObjectType,\n\tValueType extends keyof ObjectType = keyof ObjectType,\n> = ObjectType[ValueType];\n\n/**\n * An `orderings` parameter that orders the results by the specified field.\n *\n * {@link https://prismic.io/docs/rest-api-technical-reference#orderings}\n */\nexport interface Ordering {\n\tfield: string;\n\tdirection?: \"asc\" | \"desc\";\n}\n\n/**\n * A `routes` parameter that determines how a document's URL field is resolved.\n *\n * {@link https://prismic.io/docs/route-resolver}\n *\n * @example With a document's UID field.\n *\n * ```ts\n * {\n * \t\"type\": \"page\",\n * \t\"path\": \"/:uid\"\n * }\n * ```\n *\n * @example With a Content Relationship `parent` field.\n *\n * ```ts\n * {\n * \t\"type\": \"page\",\n * \t\"path\": \"/:parent?/:uid\",\n * \t\"resolvers\": {\n * \t\t\"parent\": \"parent\"\n * \t}\n * }\n * ```\n */\nexport interface Route {\n\t/**\n\t * The custom type of the document.\n\t */\n\ttype: string;\n\n\t/**\n\t * A specific UID to which this route definition is scoped. The route is only\n\t * defined for the document whose UID matches the given UID.\n\t */\n\tuid?: string;\n\n\t/**\n\t * A specific language to which this route definition is scoped. The route is\n\t * only defined for documents whose language matches the given language.\n\t */\n\tlang?: string;\n\n\t/**\n\t * The resolved path of the document with optional placeholders.\n\t */\n\tpath: string;\n\n\t/**\n\t * An object that lists the API IDs of the Content Relationships in the route.\n\t */\n\tresolvers?: Record<string, string>;\n}\n\n/**\n * Parameters for the Prismic REST API V2.\n *\n * {@link https://prismic.io/docs/api}\n */\nexport interface QueryParams {\n\t/**\n\t * The secure token for accessing the API (only needed if your repository is\n\t * set to private).\n\t *\n\t * {@link https://prismic.io/docs/access-token}\n\t */\n\taccessToken?: string;\n\n\t/**\n\t * The `pageSize` parameter defines the maximum number of documents that the\n\t * API will return for your query.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#pagesize}\n\t */\n\tpageSize?: number;\n\n\t/**\n\t * The `page` parameter defines the pagination for the result of your query.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#page}\n\t */\n\tpage?: number;\n\n\t/**\n\t * The `after` parameter can be used along with the orderings option. It will\n\t * remove all the documents except for those after the specified document in\n\t * the list.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#after}\n\t */\n\tafter?: string;\n\n\t/**\n\t * The `fetch` parameter is used to make queries faster by only retrieving the\n\t * specified field(s).\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#fetch}\n\t */\n\tfetch?: string | string[];\n\n\t/**\n\t * The `fetchLinks` parameter allows you to retrieve a specific content field\n\t * from a linked document and add it to the document response object.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#fetchlinks}\n\t */\n\tfetchLinks?: string | string[];\n\n\t/**\n\t * The `graphQuery` parameter allows you to specify which fields to retrieve\n\t * and what content to retrieve from Linked Documents / Content\n\t * Relationships.\n\t *\n\t * {@link https://prismic.io/docs/graphquery-rest-api}\n\t */\n\tgraphQuery?: string;\n\n\t/**\n\t * The `lang` option defines the language code for the results of your query.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#lang}\n\t */\n\tlang?: string;\n\n\t/**\n\t * The `orderings` parameter orders the results by the specified field(s). You\n\t * can specify as many fields as you want.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#orderings}\n\t *\n\t * @remarks Strings and arrays of strings are deprecated as of\n\t * `@prismicio/client@7.0.0`. Please migrate to the more explicit\n\t * array of objects.\n\t *\n\t * @example\n\t *\n\t * ```typescript\n\t * buildQueryURL(endpoint,{\n\t * orderings: [\n\t * { field: \"my.product.price\", direction: \"desc\" },\n\t * { field: \"my.product.title\" },\n\t * ],\n\t * });\n\t * ```\n\t */\n\t// TODO: Update TSDoc with deprecated API removal in v8\n\torderings?: string | Ordering | (string | Ordering)[];\n\n\t/**\n\t * The `routes` option allows you to define how a document's `url` field is\n\t * resolved.\n\t *\n\t * {@link https://prismic.io/docs/route-resolver}\n\t */\n\troutes?: Route | string | (Route | string)[];\n\n\t/**\n\t * The `brokenRoute` option allows you to define the route populated in the\n\t * `url` property for broken link or content relationship fields. A broken\n\t * link is a link or content relationship field whose linked document has been\n\t * unpublished or deleted.\n\t *\n\t * {@link https://prismic.io/docs/route-resolver}\n\t */\n\tbrokenRoute?: string;\n}\n\n/**\n * Arguments for `buildQueryURL` to construct a Query URL.\n */\ntype BuildQueryURLParams = {\n\t/**\n\t * Ref used to query documents.\n\t *\n\t * {@link https://prismic.io/docs/api#refs-and-the-entry-api}\n\t */\n\tref: string;\n\n\t/**\n\t * Ref used to populate integration fields with the latest content.\n\t *\n\t * {@link https://prismic.io/docs/integration-fields}\n\t */\n\tintegrationFieldsRef?: string;\n\n\t/**\n\t * One or more filters to filter documents for the query.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#q}\n\t */\n\tfilters?: string | string[];\n\n\t/**\n\t * @deprecated Renamed to `filters`. Ensure the value is an array of filters, not a single, non-array filter.\n\t */\n\tpredicates?: string | string[];\n};\n\n/**\n * Parameters in this map have been renamed from the official Prismic REST API\n * V2 specification for better developer ergonomics.\n *\n * These parameters are renamed to their mapped value.\n */\nconst RENAMED_PARAMS = {\n\taccessToken: \"access_token\",\n} as const;\n\n/**\n * A valid parameter name for the Prismic REST API V2.\n */\ntype ValidParamName =\n\t| Exclude<\n\t\t\tkeyof QueryParams,\n\t\t\tkeyof typeof RENAMED_PARAMS | keyof BuildQueryURLParams\n\t >\n\t| ValueOf<typeof RENAMED_PARAMS>;\n\n/**\n * Converts an Ordering to a string that is compatible with Prismic's REST API.\n * If the value provided is already a string, no conversion is performed.\n *\n * @param ordering - Ordering to convert.\n *\n * @returns String representation of the Ordering.\n */\nconst castOrderingToString = (ordering: Ordering | string): string => {\n\t// TODO: Remove the following when `orderings` strings are no longer supported.\n\tif (typeof ordering === \"string\") {\n\t\tif (process.env.NODE_ENV === \"development\") {\n\t\t\tconst [field, direction] = ordering.split(\" \");\n\n\t\t\tconst objectForm =\n\t\t\t\tdirection === \"desc\"\n\t\t\t\t\t? `{ field: \"${field}\", direction: \"desc\" }`\n\t\t\t\t\t: `{ field: \"${field}\" }`;\n\n\t\t\tconsole.warn(\n\t\t\t\t`[@prismicio/client] A string value was provided to the \\`orderings\\` query parameter. Strings are deprecated. Please convert it to the object form: ${objectForm}. For more details, see ${devMsg(\n\t\t\t\t\t\"orderings-must-be-an-array-of-objects\",\n\t\t\t\t)}`,\n\t\t\t);\n\t\t}\n\n\t\treturn ordering;\n\t}\n\n\treturn ordering.direction === \"desc\"\n\t\t? `${ordering.field} desc`\n\t\t: ordering.field;\n};\n\nexport type BuildQueryURLArgs = QueryParams & BuildQueryURLParams;\n\n/**\n * Build a Prismic REST API V2 URL to request documents from a repository. The\n * paginated response for this URL includes documents matching the parameters.\n *\n * A ref is required to make a request. Request the `endpoint` URL to retrieve a\n * list of available refs.\n *\n * Type the JSON response with `Query`.\n *\n * {@link https://prismic.io/docs/api#refs-and-the-entry-api}\n * {@link https://prismic.io/docs/rest-api-technical-reference}\n *\n * @param endpoint - URL to the repository's REST API V2.\n * @param args - Arguments to filter and scope the query.\n *\n * @returns URL that can be used to request documents from the repository.\n */\nexport const buildQueryURL = (\n\tendpoint: string,\n\targs: BuildQueryURLArgs,\n): string => {\n\tconst { filters, predicates, ...params } = args;\n\n\tconst url = new URL(`documents/search`, `${endpoint}/`);\n\n\tif (filters) {\n\t\t// TODO: Remove warning when we remove support for string `filters` values.\n\t\tif (process.env.NODE_ENV === \"development\" && !Array.isArray(filters)) {\n\t\t\tconsole.warn(\n\t\t\t\t`[@prismicio/client] A non-array value was provided to the \\`filters\\` query parameter (\\`${filters}\\`). Non-array values are deprecated. Please convert it to an array. For more details, see ${devMsg(\n\t\t\t\t\t\"filters-must-be-an-array\",\n\t\t\t\t)}`,\n\t\t\t);\n\t\t}\n\n\t\t// TODO: Remove `castArray` when we remove support for string `filters` values.\n\t\tfor (const filter of castArray(filters)) {\n\t\t\turl.searchParams.append(\"q\", `[${filter}]`);\n\t\t}\n\t}\n\n\t// TODO: Remove when we remove support for deprecated `predicates` argument.\n\tif (predicates) {\n\t\tfor (const predicate of castArray(predicates)) {\n\t\t\turl.searchParams.append(\"q\", `[${predicate}]`);\n\t\t}\n\t}\n\n\t// Iterate over each parameter and add it to the URL. In some cases, the\n\t// parameter value needs to be transformed to fit the REST API.\n\tfor (const k in params) {\n\t\tconst name = (RENAMED_PARAMS[k as keyof typeof RENAMED_PARAMS] ||\n\t\t\tk) as ValidParamName;\n\n\t\tlet value = params[k as keyof typeof params];\n\n\t\tif (name === \"orderings\") {\n\t\t\tconst scopedValue = params[name];\n\n\t\t\tif (scopedValue != null) {\n\t\t\t\t// TODO: Remove the following warning when `orderings` strings are no longer supported.\n\t\t\t\tif (\n\t\t\t\t\tprocess.env.NODE_ENV === \"development\" &&\n\t\t\t\t\ttypeof scopedValue === \"string\"\n\t\t\t\t) {\n\t\t\t\t\tconsole.warn(\n\t\t\t\t\t\t`[@prismicio/client] A string value was provided to the \\`orderings\\` query parameter. Strings are deprecated. Please convert it to an array of objects. For more details, see ${devMsg(\n\t\t\t\t\t\t\t\"orderings-must-be-an-array-of-objects\",\n\t\t\t\t\t\t)}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tconst v = castArray(scopedValue)\n\t\t\t\t\t.map((ordering) => castOrderingToString(ordering))\n\t\t\t\t\t.join(\",\");\n\n\t\t\t\tvalue = `[${v}]`;\n\t\t\t}\n\t\t} else if (name === \"routes\") {\n\t\t\tif (typeof params[name] === \"object\") {\n\t\t\t\tvalue = JSON.stringify(castArray(params[name]));\n\t\t\t}\n\t\t}\n\n\t\tif (value != null) {\n\t\t\turl.searchParams.set(\n\t\t\t\tname,\n\t\t\t\tcastArray<string | number | Route | Ordering>(value).join(\",\"),\n\t\t\t);\n\t\t}\n\t}\n\n\treturn url.toString();\n};\n"],"names":["devMsg","castArray"],"mappings":";;;;AAwOA,MAAM,iBAAiB;AAAA,EACtB,aAAa;;AAqBd,MAAM,uBAAuB,CAAC,aAAuC;AAEhE,MAAA,OAAO,aAAa,UAAU;AAC7B,QAAA,QAAQ,IAAI,aAAa,eAAe;AAC3C,YAAM,CAAC,OAAO,SAAS,IAAI,SAAS,MAAM,GAAG;AAE7C,YAAM,aACL,cAAc,SACX,aAAa,gCACb,aAAa;AAEjB,cAAQ,KACP,uJAAuJ,qCAAqCA,cAC3L,uCAAuC,GACrC;AAAA,IAEJ;AAEM,WAAA;AAAA,EACP;AAED,SAAO,SAAS,cAAc,SAC3B,GAAG,SAAS,eACZ,SAAS;AACb;AAqBa,MAAA,gBAAgB,CAC5B,UACA,SACW;AACX,QAAM,EAAE,SAAS,YAAY,GAAG,WAAW;AAE3C,QAAM,MAAM,IAAI,IAAI,oBAAoB,GAAG,WAAW;AAEtD,MAAI,SAAS;AAER,QAAA,QAAQ,IAAI,aAAa,iBAAiB,CAAC,MAAM,QAAQ,OAAO,GAAG;AACtE,cAAQ,KACP,4FAA4F,qGAAqGA,cAChM,0BAA0B,GACxB;AAAA,IAEJ;AAGU,eAAA,UAAUC,oBAAU,OAAO,GAAG;AACxC,UAAI,aAAa,OAAO,KAAK,IAAI,SAAS;AAAA,IAC1C;AAAA,EACD;AAGD,MAAI,YAAY;AACJ,eAAA,aAAaA,oBAAU,UAAU,GAAG;AAC9C,UAAI,aAAa,OAAO,KAAK,IAAI,YAAY;AAAA,IAC7C;AAAA,EACD;AAID,aAAW,KAAK,QAAQ;AACjB,UAAA,OAAQ,eAAe,CAAgC,KAC5D;AAEG,QAAA,QAAQ,OAAO,CAAwB;AAE3C,QAAI,SAAS,aAAa;AACnB,YAAA,cAAc,OAAO,IAAI;AAE/B,UAAI,eAAe,MAAM;AAExB,YACC,QAAQ,IAAI,aAAa,iBACzB,OAAO,gBAAgB,UACtB;AACD,kBAAQ,KACP,iLAAiLD,OAChL,OAAA,uCAAuC,GACrC;AAAA,QAEJ;AAED,cAAM,IAAIC,UAAAA,UAAU,WAAW,EAC7B,IAAI,CAAC,aAAa,qBAAqB,QAAQ,CAAC,EAChD,KAAK,GAAG;AAEV,gBAAQ,IAAI;AAAA,MACZ;AAAA,IAAA,WACS,SAAS,UAAU;AAC7B,UAAI,OAAO,OAAO,IAAI,MAAM,UAAU;AACrC,gBAAQ,KAAK,UAAUA,UAAAA,UAAU,OAAO,IAAI,CAAC,CAAC;AAAA,MAC9C;AAAA,IACD;AAED,QAAI,SAAS,MAAM;AACd,UAAA,aAAa,IAChB,MACAA,UAAAA,UAA8C,KAAK,EAAE,KAAK,GAAG,CAAC;AAAA,IAE/D;AAAA,EACD;AAED,SAAO,IAAI;AACZ;;"}
|
package/dist/buildQueryURL.d.ts
CHANGED
|
@@ -35,7 +35,7 @@ export interface Ordering {
|
|
|
35
35
|
*/
|
|
36
36
|
export interface Route {
|
|
37
37
|
/**
|
|
38
|
-
* The
|
|
38
|
+
* The custom type of the document.
|
|
39
39
|
*/
|
|
40
40
|
type: string;
|
|
41
41
|
/**
|
|
@@ -150,8 +150,8 @@ export interface QueryParams {
|
|
|
150
150
|
routes?: Route | string | (Route | string)[];
|
|
151
151
|
/**
|
|
152
152
|
* The `brokenRoute` option allows you to define the route populated in the
|
|
153
|
-
* `url` property for broken
|
|
154
|
-
* link is a
|
|
153
|
+
* `url` property for broken link or content relationship fields. A broken
|
|
154
|
+
* link is a link or content relationship field whose linked document has been
|
|
155
155
|
* unpublished or deleted.
|
|
156
156
|
*
|
|
157
157
|
* {@link https://prismic.io/docs/route-resolver}
|
|
@@ -169,7 +169,7 @@ type BuildQueryURLParams = {
|
|
|
169
169
|
*/
|
|
170
170
|
ref: string;
|
|
171
171
|
/**
|
|
172
|
-
* Ref used to populate
|
|
172
|
+
* Ref used to populate integration fields with the latest content.
|
|
173
173
|
*
|
|
174
174
|
* {@link https://prismic.io/docs/integration-fields}
|
|
175
175
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildQueryURL.js","sources":["../../src/buildQueryURL.ts"],"sourcesContent":["import { castArray } from \"./lib/castArray\";\nimport { devMsg } from \"./lib/devMsg\";\n\n/**\n * Create a union of the given object's values, and optionally specify which\n * keys to get the values from.\n *\n * Taken from the `type-fest` package.\n *\n * See:\n * https://github.com/sindresorhus/type-fest/blob/61c35052f09caa23de5eef96d95196375d8ed498/source/value-of.d.ts\n */\ntype ValueOf<\n\tObjectType,\n\tValueType extends keyof ObjectType = keyof ObjectType,\n> = ObjectType[ValueType];\n\n/**\n * An `orderings` parameter that orders the results by the specified field.\n *\n * {@link https://prismic.io/docs/rest-api-technical-reference#orderings}\n */\nexport interface Ordering {\n\tfield: string;\n\tdirection?: \"asc\" | \"desc\";\n}\n\n/**\n * A `routes` parameter that determines how a document's URL field is resolved.\n *\n * {@link https://prismic.io/docs/route-resolver}\n *\n * @example With a document's UID field.\n *\n * ```ts\n * {\n * \t\"type\": \"page\",\n * \t\"path\": \"/:uid\"\n * }\n * ```\n *\n * @example With a Content Relationship `parent` field.\n *\n * ```ts\n * {\n * \t\"type\": \"page\",\n * \t\"path\": \"/:parent?/:uid\",\n * \t\"resolvers\": {\n * \t\t\"parent\": \"parent\"\n * \t}\n * }\n * ```\n */\nexport interface Route {\n\t/**\n\t * The Custom Type of the document.\n\t */\n\ttype: string;\n\n\t/**\n\t * A specific UID to which this route definition is scoped. The route is only\n\t * defined for the document whose UID matches the given UID.\n\t */\n\tuid?: string;\n\n\t/**\n\t * A specific language to which this route definition is scoped. The route is\n\t * only defined for documents whose language matches the given language.\n\t */\n\tlang?: string;\n\n\t/**\n\t * The resolved path of the document with optional placeholders.\n\t */\n\tpath: string;\n\n\t/**\n\t * An object that lists the API IDs of the Content Relationships in the route.\n\t */\n\tresolvers?: Record<string, string>;\n}\n\n/**\n * Parameters for the Prismic REST API V2.\n *\n * {@link https://prismic.io/docs/api}\n */\nexport interface QueryParams {\n\t/**\n\t * The secure token for accessing the API (only needed if your repository is\n\t * set to private).\n\t *\n\t * {@link https://prismic.io/docs/access-token}\n\t */\n\taccessToken?: string;\n\n\t/**\n\t * The `pageSize` parameter defines the maximum number of documents that the\n\t * API will return for your query.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#pagesize}\n\t */\n\tpageSize?: number;\n\n\t/**\n\t * The `page` parameter defines the pagination for the result of your query.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#page}\n\t */\n\tpage?: number;\n\n\t/**\n\t * The `after` parameter can be used along with the orderings option. It will\n\t * remove all the documents except for those after the specified document in\n\t * the list.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#after}\n\t */\n\tafter?: string;\n\n\t/**\n\t * The `fetch` parameter is used to make queries faster by only retrieving the\n\t * specified field(s).\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#fetch}\n\t */\n\tfetch?: string | string[];\n\n\t/**\n\t * The `fetchLinks` parameter allows you to retrieve a specific content field\n\t * from a linked document and add it to the document response object.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#fetchlinks}\n\t */\n\tfetchLinks?: string | string[];\n\n\t/**\n\t * The `graphQuery` parameter allows you to specify which fields to retrieve\n\t * and what content to retrieve from Linked Documents / Content\n\t * Relationships.\n\t *\n\t * {@link https://prismic.io/docs/graphquery-rest-api}\n\t */\n\tgraphQuery?: string;\n\n\t/**\n\t * The `lang` option defines the language code for the results of your query.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#lang}\n\t */\n\tlang?: string;\n\n\t/**\n\t * The `orderings` parameter orders the results by the specified field(s). You\n\t * can specify as many fields as you want.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#orderings}\n\t *\n\t * @remarks Strings and arrays of strings are deprecated as of\n\t * `@prismicio/client@7.0.0`. Please migrate to the more explicit\n\t * array of objects.\n\t *\n\t * @example\n\t *\n\t * ```typescript\n\t * buildQueryURL(endpoint,{\n\t * orderings: [\n\t * { field: \"my.product.price\", direction: \"desc\" },\n\t * { field: \"my.product.title\" },\n\t * ],\n\t * });\n\t * ```\n\t */\n\t// TODO: Update TSDoc with deprecated API removal in v8\n\torderings?: string | Ordering | (string | Ordering)[];\n\n\t/**\n\t * The `routes` option allows you to define how a document's `url` field is\n\t * resolved.\n\t *\n\t * {@link https://prismic.io/docs/route-resolver}\n\t */\n\troutes?: Route | string | (Route | string)[];\n\n\t/**\n\t * The `brokenRoute` option allows you to define the route populated in the\n\t * `url` property for broken Link or Content Relationship fields. A broken\n\t * link is a Link or Content Relationship field whose linked document has been\n\t * unpublished or deleted.\n\t *\n\t * {@link https://prismic.io/docs/route-resolver}\n\t */\n\tbrokenRoute?: string;\n}\n\n/**\n * Arguments for `buildQueryURL` to construct a Query URL.\n */\ntype BuildQueryURLParams = {\n\t/**\n\t * Ref used to query documents.\n\t *\n\t * {@link https://prismic.io/docs/api#refs-and-the-entry-api}\n\t */\n\tref: string;\n\n\t/**\n\t * Ref used to populate Integration Fields with the latest content.\n\t *\n\t * {@link https://prismic.io/docs/integration-fields}\n\t */\n\tintegrationFieldsRef?: string;\n\n\t/**\n\t * One or more filters to filter documents for the query.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#q}\n\t */\n\tfilters?: string | string[];\n\n\t/**\n\t * @deprecated Renamed to `filters`. Ensure the value is an array of filters, not a single, non-array filter.\n\t */\n\tpredicates?: string | string[];\n};\n\n/**\n * Parameters in this map have been renamed from the official Prismic REST API\n * V2 specification for better developer ergonomics.\n *\n * These parameters are renamed to their mapped value.\n */\nconst RENAMED_PARAMS = {\n\taccessToken: \"access_token\",\n} as const;\n\n/**\n * A valid parameter name for the Prismic REST API V2.\n */\ntype ValidParamName =\n\t| Exclude<\n\t\t\tkeyof QueryParams,\n\t\t\tkeyof typeof RENAMED_PARAMS | keyof BuildQueryURLParams\n\t >\n\t| ValueOf<typeof RENAMED_PARAMS>;\n\n/**\n * Converts an Ordering to a string that is compatible with Prismic's REST API.\n * If the value provided is already a string, no conversion is performed.\n *\n * @param ordering - Ordering to convert.\n *\n * @returns String representation of the Ordering.\n */\nconst castOrderingToString = (ordering: Ordering | string): string => {\n\t// TODO: Remove the following when `orderings` strings are no longer supported.\n\tif (typeof ordering === \"string\") {\n\t\tif (process.env.NODE_ENV === \"development\") {\n\t\t\tconst [field, direction] = ordering.split(\" \");\n\n\t\t\tconst objectForm =\n\t\t\t\tdirection === \"desc\"\n\t\t\t\t\t? `{ field: \"${field}\", direction: \"desc\" }`\n\t\t\t\t\t: `{ field: \"${field}\" }`;\n\n\t\t\tconsole.warn(\n\t\t\t\t`[@prismicio/client] A string value was provided to the \\`orderings\\` query parameter. Strings are deprecated. Please convert it to the object form: ${objectForm}. For more details, see ${devMsg(\n\t\t\t\t\t\"orderings-must-be-an-array-of-objects\",\n\t\t\t\t)}`,\n\t\t\t);\n\t\t}\n\n\t\treturn ordering;\n\t}\n\n\treturn ordering.direction === \"desc\"\n\t\t? `${ordering.field} desc`\n\t\t: ordering.field;\n};\n\nexport type BuildQueryURLArgs = QueryParams & BuildQueryURLParams;\n\n/**\n * Build a Prismic REST API V2 URL to request documents from a repository. The\n * paginated response for this URL includes documents matching the parameters.\n *\n * A ref is required to make a request. Request the `endpoint` URL to retrieve a\n * list of available refs.\n *\n * Type the JSON response with `Query`.\n *\n * {@link https://prismic.io/docs/api#refs-and-the-entry-api}\n * {@link https://prismic.io/docs/rest-api-technical-reference}\n *\n * @param endpoint - URL to the repository's REST API V2.\n * @param args - Arguments to filter and scope the query.\n *\n * @returns URL that can be used to request documents from the repository.\n */\nexport const buildQueryURL = (\n\tendpoint: string,\n\targs: BuildQueryURLArgs,\n): string => {\n\tconst { filters, predicates, ...params } = args;\n\n\tconst url = new URL(`documents/search`, `${endpoint}/`);\n\n\tif (filters) {\n\t\t// TODO: Remove warning when we remove support for string `filters` values.\n\t\tif (process.env.NODE_ENV === \"development\" && !Array.isArray(filters)) {\n\t\t\tconsole.warn(\n\t\t\t\t`[@prismicio/client] A non-array value was provided to the \\`filters\\` query parameter (\\`${filters}\\`). Non-array values are deprecated. Please convert it to an array. For more details, see ${devMsg(\n\t\t\t\t\t\"filters-must-be-an-array\",\n\t\t\t\t)}`,\n\t\t\t);\n\t\t}\n\n\t\t// TODO: Remove `castArray` when we remove support for string `filters` values.\n\t\tfor (const filter of castArray(filters)) {\n\t\t\turl.searchParams.append(\"q\", `[${filter}]`);\n\t\t}\n\t}\n\n\t// TODO: Remove when we remove support for deprecated `predicates` argument.\n\tif (predicates) {\n\t\tfor (const predicate of castArray(predicates)) {\n\t\t\turl.searchParams.append(\"q\", `[${predicate}]`);\n\t\t}\n\t}\n\n\t// Iterate over each parameter and add it to the URL. In some cases, the\n\t// parameter value needs to be transformed to fit the REST API.\n\tfor (const k in params) {\n\t\tconst name = (RENAMED_PARAMS[k as keyof typeof RENAMED_PARAMS] ||\n\t\t\tk) as ValidParamName;\n\n\t\tlet value = params[k as keyof typeof params];\n\n\t\tif (name === \"orderings\") {\n\t\t\tconst scopedValue = params[name];\n\n\t\t\tif (scopedValue != null) {\n\t\t\t\t// TODO: Remove the following warning when `orderings` strings are no longer supported.\n\t\t\t\tif (\n\t\t\t\t\tprocess.env.NODE_ENV === \"development\" &&\n\t\t\t\t\ttypeof scopedValue === \"string\"\n\t\t\t\t) {\n\t\t\t\t\tconsole.warn(\n\t\t\t\t\t\t`[@prismicio/client] A string value was provided to the \\`orderings\\` query parameter. Strings are deprecated. Please convert it to an array of objects. For more details, see ${devMsg(\n\t\t\t\t\t\t\t\"orderings-must-be-an-array-of-objects\",\n\t\t\t\t\t\t)}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tconst v = castArray(scopedValue)\n\t\t\t\t\t.map((ordering) => castOrderingToString(ordering))\n\t\t\t\t\t.join(\",\");\n\n\t\t\t\tvalue = `[${v}]`;\n\t\t\t}\n\t\t} else if (name === \"routes\") {\n\t\t\tif (typeof params[name] === \"object\") {\n\t\t\t\tvalue = JSON.stringify(castArray(params[name]));\n\t\t\t}\n\t\t}\n\n\t\tif (value != null) {\n\t\t\turl.searchParams.set(\n\t\t\t\tname,\n\t\t\t\tcastArray<string | number | Route | Ordering>(value).join(\",\"),\n\t\t\t);\n\t\t}\n\t}\n\n\treturn url.toString();\n};\n"],"names":[],"mappings":";;AAwOA,MAAM,iBAAiB;AAAA,EACtB,aAAa;;AAqBd,MAAM,uBAAuB,CAAC,aAAuC;AAEhE,MAAA,OAAO,aAAa,UAAU;AAC7B,QAAA,QAAQ,IAAI,aAAa,eAAe;AAC3C,YAAM,CAAC,OAAO,SAAS,IAAI,SAAS,MAAM,GAAG;AAE7C,YAAM,aACL,cAAc,SACX,aAAa,gCACb,aAAa;AAEjB,cAAQ,KACP,uJAAuJ,qCAAqC,OAC3L,uCAAuC,GACrC;AAAA,IAEJ;AAEM,WAAA;AAAA,EACP;AAED,SAAO,SAAS,cAAc,SAC3B,GAAG,SAAS,eACZ,SAAS;AACb;AAqBa,MAAA,gBAAgB,CAC5B,UACA,SACW;AACX,QAAM,EAAE,SAAS,YAAY,GAAG,WAAW;AAE3C,QAAM,MAAM,IAAI,IAAI,oBAAoB,GAAG,WAAW;AAEtD,MAAI,SAAS;AAER,QAAA,QAAQ,IAAI,aAAa,iBAAiB,CAAC,MAAM,QAAQ,OAAO,GAAG;AACtE,cAAQ,KACP,4FAA4F,qGAAqG,OAChM,0BAA0B,GACxB;AAAA,IAEJ;AAGU,eAAA,UAAU,UAAU,OAAO,GAAG;AACxC,UAAI,aAAa,OAAO,KAAK,IAAI,SAAS;AAAA,IAC1C;AAAA,EACD;AAGD,MAAI,YAAY;AACJ,eAAA,aAAa,UAAU,UAAU,GAAG;AAC9C,UAAI,aAAa,OAAO,KAAK,IAAI,YAAY;AAAA,IAC7C;AAAA,EACD;AAID,aAAW,KAAK,QAAQ;AACjB,UAAA,OAAQ,eAAe,CAAgC,KAC5D;AAEG,QAAA,QAAQ,OAAO,CAAwB;AAE3C,QAAI,SAAS,aAAa;AACnB,YAAA,cAAc,OAAO,IAAI;AAE/B,UAAI,eAAe,MAAM;AAExB,YACC,QAAQ,IAAI,aAAa,iBACzB,OAAO,gBAAgB,UACtB;AACD,kBAAQ,KACP,iLAAiL,OAChL,uCAAuC,GACrC;AAAA,QAEJ;AAED,cAAM,IAAI,UAAU,WAAW,EAC7B,IAAI,CAAC,aAAa,qBAAqB,QAAQ,CAAC,EAChD,KAAK,GAAG;AAEV,gBAAQ,IAAI;AAAA,MACZ;AAAA,IAAA,WACS,SAAS,UAAU;AAC7B,UAAI,OAAO,OAAO,IAAI,MAAM,UAAU;AACrC,gBAAQ,KAAK,UAAU,UAAU,OAAO,IAAI,CAAC,CAAC;AAAA,MAC9C;AAAA,IACD;AAED,QAAI,SAAS,MAAM;AACd,UAAA,aAAa,IAChB,MACA,UAA8C,KAAK,EAAE,KAAK,GAAG,CAAC;AAAA,IAE/D;AAAA,EACD;AAED,SAAO,IAAI;AACZ;"}
|
|
1
|
+
{"version":3,"file":"buildQueryURL.js","sources":["../../src/buildQueryURL.ts"],"sourcesContent":["import { castArray } from \"./lib/castArray\";\nimport { devMsg } from \"./lib/devMsg\";\n\n/**\n * Create a union of the given object's values, and optionally specify which\n * keys to get the values from.\n *\n * Taken from the `type-fest` package.\n *\n * See:\n * https://github.com/sindresorhus/type-fest/blob/61c35052f09caa23de5eef96d95196375d8ed498/source/value-of.d.ts\n */\ntype ValueOf<\n\tObjectType,\n\tValueType extends keyof ObjectType = keyof ObjectType,\n> = ObjectType[ValueType];\n\n/**\n * An `orderings` parameter that orders the results by the specified field.\n *\n * {@link https://prismic.io/docs/rest-api-technical-reference#orderings}\n */\nexport interface Ordering {\n\tfield: string;\n\tdirection?: \"asc\" | \"desc\";\n}\n\n/**\n * A `routes` parameter that determines how a document's URL field is resolved.\n *\n * {@link https://prismic.io/docs/route-resolver}\n *\n * @example With a document's UID field.\n *\n * ```ts\n * {\n * \t\"type\": \"page\",\n * \t\"path\": \"/:uid\"\n * }\n * ```\n *\n * @example With a Content Relationship `parent` field.\n *\n * ```ts\n * {\n * \t\"type\": \"page\",\n * \t\"path\": \"/:parent?/:uid\",\n * \t\"resolvers\": {\n * \t\t\"parent\": \"parent\"\n * \t}\n * }\n * ```\n */\nexport interface Route {\n\t/**\n\t * The custom type of the document.\n\t */\n\ttype: string;\n\n\t/**\n\t * A specific UID to which this route definition is scoped. The route is only\n\t * defined for the document whose UID matches the given UID.\n\t */\n\tuid?: string;\n\n\t/**\n\t * A specific language to which this route definition is scoped. The route is\n\t * only defined for documents whose language matches the given language.\n\t */\n\tlang?: string;\n\n\t/**\n\t * The resolved path of the document with optional placeholders.\n\t */\n\tpath: string;\n\n\t/**\n\t * An object that lists the API IDs of the Content Relationships in the route.\n\t */\n\tresolvers?: Record<string, string>;\n}\n\n/**\n * Parameters for the Prismic REST API V2.\n *\n * {@link https://prismic.io/docs/api}\n */\nexport interface QueryParams {\n\t/**\n\t * The secure token for accessing the API (only needed if your repository is\n\t * set to private).\n\t *\n\t * {@link https://prismic.io/docs/access-token}\n\t */\n\taccessToken?: string;\n\n\t/**\n\t * The `pageSize` parameter defines the maximum number of documents that the\n\t * API will return for your query.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#pagesize}\n\t */\n\tpageSize?: number;\n\n\t/**\n\t * The `page` parameter defines the pagination for the result of your query.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#page}\n\t */\n\tpage?: number;\n\n\t/**\n\t * The `after` parameter can be used along with the orderings option. It will\n\t * remove all the documents except for those after the specified document in\n\t * the list.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#after}\n\t */\n\tafter?: string;\n\n\t/**\n\t * The `fetch` parameter is used to make queries faster by only retrieving the\n\t * specified field(s).\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#fetch}\n\t */\n\tfetch?: string | string[];\n\n\t/**\n\t * The `fetchLinks` parameter allows you to retrieve a specific content field\n\t * from a linked document and add it to the document response object.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#fetchlinks}\n\t */\n\tfetchLinks?: string | string[];\n\n\t/**\n\t * The `graphQuery` parameter allows you to specify which fields to retrieve\n\t * and what content to retrieve from Linked Documents / Content\n\t * Relationships.\n\t *\n\t * {@link https://prismic.io/docs/graphquery-rest-api}\n\t */\n\tgraphQuery?: string;\n\n\t/**\n\t * The `lang` option defines the language code for the results of your query.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#lang}\n\t */\n\tlang?: string;\n\n\t/**\n\t * The `orderings` parameter orders the results by the specified field(s). You\n\t * can specify as many fields as you want.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#orderings}\n\t *\n\t * @remarks Strings and arrays of strings are deprecated as of\n\t * `@prismicio/client@7.0.0`. Please migrate to the more explicit\n\t * array of objects.\n\t *\n\t * @example\n\t *\n\t * ```typescript\n\t * buildQueryURL(endpoint,{\n\t * orderings: [\n\t * { field: \"my.product.price\", direction: \"desc\" },\n\t * { field: \"my.product.title\" },\n\t * ],\n\t * });\n\t * ```\n\t */\n\t// TODO: Update TSDoc with deprecated API removal in v8\n\torderings?: string | Ordering | (string | Ordering)[];\n\n\t/**\n\t * The `routes` option allows you to define how a document's `url` field is\n\t * resolved.\n\t *\n\t * {@link https://prismic.io/docs/route-resolver}\n\t */\n\troutes?: Route | string | (Route | string)[];\n\n\t/**\n\t * The `brokenRoute` option allows you to define the route populated in the\n\t * `url` property for broken link or content relationship fields. A broken\n\t * link is a link or content relationship field whose linked document has been\n\t * unpublished or deleted.\n\t *\n\t * {@link https://prismic.io/docs/route-resolver}\n\t */\n\tbrokenRoute?: string;\n}\n\n/**\n * Arguments for `buildQueryURL` to construct a Query URL.\n */\ntype BuildQueryURLParams = {\n\t/**\n\t * Ref used to query documents.\n\t *\n\t * {@link https://prismic.io/docs/api#refs-and-the-entry-api}\n\t */\n\tref: string;\n\n\t/**\n\t * Ref used to populate integration fields with the latest content.\n\t *\n\t * {@link https://prismic.io/docs/integration-fields}\n\t */\n\tintegrationFieldsRef?: string;\n\n\t/**\n\t * One or more filters to filter documents for the query.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#q}\n\t */\n\tfilters?: string | string[];\n\n\t/**\n\t * @deprecated Renamed to `filters`. Ensure the value is an array of filters, not a single, non-array filter.\n\t */\n\tpredicates?: string | string[];\n};\n\n/**\n * Parameters in this map have been renamed from the official Prismic REST API\n * V2 specification for better developer ergonomics.\n *\n * These parameters are renamed to their mapped value.\n */\nconst RENAMED_PARAMS = {\n\taccessToken: \"access_token\",\n} as const;\n\n/**\n * A valid parameter name for the Prismic REST API V2.\n */\ntype ValidParamName =\n\t| Exclude<\n\t\t\tkeyof QueryParams,\n\t\t\tkeyof typeof RENAMED_PARAMS | keyof BuildQueryURLParams\n\t >\n\t| ValueOf<typeof RENAMED_PARAMS>;\n\n/**\n * Converts an Ordering to a string that is compatible with Prismic's REST API.\n * If the value provided is already a string, no conversion is performed.\n *\n * @param ordering - Ordering to convert.\n *\n * @returns String representation of the Ordering.\n */\nconst castOrderingToString = (ordering: Ordering | string): string => {\n\t// TODO: Remove the following when `orderings` strings are no longer supported.\n\tif (typeof ordering === \"string\") {\n\t\tif (process.env.NODE_ENV === \"development\") {\n\t\t\tconst [field, direction] = ordering.split(\" \");\n\n\t\t\tconst objectForm =\n\t\t\t\tdirection === \"desc\"\n\t\t\t\t\t? `{ field: \"${field}\", direction: \"desc\" }`\n\t\t\t\t\t: `{ field: \"${field}\" }`;\n\n\t\t\tconsole.warn(\n\t\t\t\t`[@prismicio/client] A string value was provided to the \\`orderings\\` query parameter. Strings are deprecated. Please convert it to the object form: ${objectForm}. For more details, see ${devMsg(\n\t\t\t\t\t\"orderings-must-be-an-array-of-objects\",\n\t\t\t\t)}`,\n\t\t\t);\n\t\t}\n\n\t\treturn ordering;\n\t}\n\n\treturn ordering.direction === \"desc\"\n\t\t? `${ordering.field} desc`\n\t\t: ordering.field;\n};\n\nexport type BuildQueryURLArgs = QueryParams & BuildQueryURLParams;\n\n/**\n * Build a Prismic REST API V2 URL to request documents from a repository. The\n * paginated response for this URL includes documents matching the parameters.\n *\n * A ref is required to make a request. Request the `endpoint` URL to retrieve a\n * list of available refs.\n *\n * Type the JSON response with `Query`.\n *\n * {@link https://prismic.io/docs/api#refs-and-the-entry-api}\n * {@link https://prismic.io/docs/rest-api-technical-reference}\n *\n * @param endpoint - URL to the repository's REST API V2.\n * @param args - Arguments to filter and scope the query.\n *\n * @returns URL that can be used to request documents from the repository.\n */\nexport const buildQueryURL = (\n\tendpoint: string,\n\targs: BuildQueryURLArgs,\n): string => {\n\tconst { filters, predicates, ...params } = args;\n\n\tconst url = new URL(`documents/search`, `${endpoint}/`);\n\n\tif (filters) {\n\t\t// TODO: Remove warning when we remove support for string `filters` values.\n\t\tif (process.env.NODE_ENV === \"development\" && !Array.isArray(filters)) {\n\t\t\tconsole.warn(\n\t\t\t\t`[@prismicio/client] A non-array value was provided to the \\`filters\\` query parameter (\\`${filters}\\`). Non-array values are deprecated. Please convert it to an array. For more details, see ${devMsg(\n\t\t\t\t\t\"filters-must-be-an-array\",\n\t\t\t\t)}`,\n\t\t\t);\n\t\t}\n\n\t\t// TODO: Remove `castArray` when we remove support for string `filters` values.\n\t\tfor (const filter of castArray(filters)) {\n\t\t\turl.searchParams.append(\"q\", `[${filter}]`);\n\t\t}\n\t}\n\n\t// TODO: Remove when we remove support for deprecated `predicates` argument.\n\tif (predicates) {\n\t\tfor (const predicate of castArray(predicates)) {\n\t\t\turl.searchParams.append(\"q\", `[${predicate}]`);\n\t\t}\n\t}\n\n\t// Iterate over each parameter and add it to the URL. In some cases, the\n\t// parameter value needs to be transformed to fit the REST API.\n\tfor (const k in params) {\n\t\tconst name = (RENAMED_PARAMS[k as keyof typeof RENAMED_PARAMS] ||\n\t\t\tk) as ValidParamName;\n\n\t\tlet value = params[k as keyof typeof params];\n\n\t\tif (name === \"orderings\") {\n\t\t\tconst scopedValue = params[name];\n\n\t\t\tif (scopedValue != null) {\n\t\t\t\t// TODO: Remove the following warning when `orderings` strings are no longer supported.\n\t\t\t\tif (\n\t\t\t\t\tprocess.env.NODE_ENV === \"development\" &&\n\t\t\t\t\ttypeof scopedValue === \"string\"\n\t\t\t\t) {\n\t\t\t\t\tconsole.warn(\n\t\t\t\t\t\t`[@prismicio/client] A string value was provided to the \\`orderings\\` query parameter. Strings are deprecated. Please convert it to an array of objects. For more details, see ${devMsg(\n\t\t\t\t\t\t\t\"orderings-must-be-an-array-of-objects\",\n\t\t\t\t\t\t)}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tconst v = castArray(scopedValue)\n\t\t\t\t\t.map((ordering) => castOrderingToString(ordering))\n\t\t\t\t\t.join(\",\");\n\n\t\t\t\tvalue = `[${v}]`;\n\t\t\t}\n\t\t} else if (name === \"routes\") {\n\t\t\tif (typeof params[name] === \"object\") {\n\t\t\t\tvalue = JSON.stringify(castArray(params[name]));\n\t\t\t}\n\t\t}\n\n\t\tif (value != null) {\n\t\t\turl.searchParams.set(\n\t\t\t\tname,\n\t\t\t\tcastArray<string | number | Route | Ordering>(value).join(\",\"),\n\t\t\t);\n\t\t}\n\t}\n\n\treturn url.toString();\n};\n"],"names":[],"mappings":";;AAwOA,MAAM,iBAAiB;AAAA,EACtB,aAAa;;AAqBd,MAAM,uBAAuB,CAAC,aAAuC;AAEhE,MAAA,OAAO,aAAa,UAAU;AAC7B,QAAA,QAAQ,IAAI,aAAa,eAAe;AAC3C,YAAM,CAAC,OAAO,SAAS,IAAI,SAAS,MAAM,GAAG;AAE7C,YAAM,aACL,cAAc,SACX,aAAa,gCACb,aAAa;AAEjB,cAAQ,KACP,uJAAuJ,qCAAqC,OAC3L,uCAAuC,GACrC;AAAA,IAEJ;AAEM,WAAA;AAAA,EACP;AAED,SAAO,SAAS,cAAc,SAC3B,GAAG,SAAS,eACZ,SAAS;AACb;AAqBa,MAAA,gBAAgB,CAC5B,UACA,SACW;AACX,QAAM,EAAE,SAAS,YAAY,GAAG,WAAW;AAE3C,QAAM,MAAM,IAAI,IAAI,oBAAoB,GAAG,WAAW;AAEtD,MAAI,SAAS;AAER,QAAA,QAAQ,IAAI,aAAa,iBAAiB,CAAC,MAAM,QAAQ,OAAO,GAAG;AACtE,cAAQ,KACP,4FAA4F,qGAAqG,OAChM,0BAA0B,GACxB;AAAA,IAEJ;AAGU,eAAA,UAAU,UAAU,OAAO,GAAG;AACxC,UAAI,aAAa,OAAO,KAAK,IAAI,SAAS;AAAA,IAC1C;AAAA,EACD;AAGD,MAAI,YAAY;AACJ,eAAA,aAAa,UAAU,UAAU,GAAG;AAC9C,UAAI,aAAa,OAAO,KAAK,IAAI,YAAY;AAAA,IAC7C;AAAA,EACD;AAID,aAAW,KAAK,QAAQ;AACjB,UAAA,OAAQ,eAAe,CAAgC,KAC5D;AAEG,QAAA,QAAQ,OAAO,CAAwB;AAE3C,QAAI,SAAS,aAAa;AACnB,YAAA,cAAc,OAAO,IAAI;AAE/B,UAAI,eAAe,MAAM;AAExB,YACC,QAAQ,IAAI,aAAa,iBACzB,OAAO,gBAAgB,UACtB;AACD,kBAAQ,KACP,iLAAiL,OAChL,uCAAuC,GACrC;AAAA,QAEJ;AAED,cAAM,IAAI,UAAU,WAAW,EAC7B,IAAI,CAAC,aAAa,qBAAqB,QAAQ,CAAC,EAChD,KAAK,GAAG;AAEV,gBAAQ,IAAI;AAAA,MACZ;AAAA,IAAA,WACS,SAAS,UAAU;AAC7B,UAAI,OAAO,OAAO,IAAI,MAAM,UAAU;AACrC,gBAAQ,KAAK,UAAU,UAAU,OAAO,IAAI,CAAC,CAAC;AAAA,MAC9C;AAAA,IACD;AAED,QAAI,SAAS,MAAM;AACd,UAAA,aAAa,IAChB,MACA,UAA8C,KAAK,EAAE,KAAK,GAAG,CAAC;AAAA,IAE/D;AAAA,EACD;AAED,SAAO,IAAI;AACZ;"}
|
package/dist/createClient.cjs
CHANGED
|
@@ -67,7 +67,7 @@ class Client {
|
|
|
67
67
|
*/
|
|
68
68
|
__publicField(this, "accessToken");
|
|
69
69
|
/**
|
|
70
|
-
* A list of
|
|
70
|
+
* A list of route resolver objects that define how a document's `url` field
|
|
71
71
|
* is resolved.
|
|
72
72
|
*
|
|
73
73
|
* {@link https://prismic.io/docs/route-resolver}
|
|
@@ -75,8 +75,8 @@ class Client {
|
|
|
75
75
|
__publicField(this, "routes");
|
|
76
76
|
/**
|
|
77
77
|
* The `brokenRoute` option allows you to define the route populated in the
|
|
78
|
-
* `url` property for broken
|
|
79
|
-
* link is a
|
|
78
|
+
* `url` property for broken link or content relationship fields. A broken
|
|
79
|
+
* link is a link or content relationship field whose linked document has been
|
|
80
80
|
* unpublished or deleted.
|
|
81
81
|
*
|
|
82
82
|
* {@link https://prismic.io/docs/route-resolver}
|
|
@@ -301,7 +301,7 @@ class Client {
|
|
|
301
301
|
* A document's UID is different from its ID. An ID is automatically generated
|
|
302
302
|
* for all documents and is made available on its `id` property. A UID is
|
|
303
303
|
* provided in the Prismic editor and is unique among all documents of its
|
|
304
|
-
*
|
|
304
|
+
* custom type.
|
|
305
305
|
* @example
|
|
306
306
|
*
|
|
307
307
|
* ```ts
|
|
@@ -325,7 +325,7 @@ class Client {
|
|
|
325
325
|
* A document's UID is different from its ID. An ID is automatically generated
|
|
326
326
|
* for all documents and is made available on its `id` property. A UID is
|
|
327
327
|
* provided in the Prismic editor and is unique among all documents of its
|
|
328
|
-
*
|
|
328
|
+
* custom type.
|
|
329
329
|
* @example
|
|
330
330
|
*
|
|
331
331
|
* ```ts
|
|
@@ -355,7 +355,7 @@ class Client {
|
|
|
355
355
|
* A document's UID is different from its ID. An ID is automatically generated
|
|
356
356
|
* for all documents and is made available on its `id` property. A UID is
|
|
357
357
|
* provided in the Prismic editor and is unique among all documents of its
|
|
358
|
-
*
|
|
358
|
+
* custom type.
|
|
359
359
|
* @example
|
|
360
360
|
*
|
|
361
361
|
* ```ts
|
|
@@ -376,13 +376,13 @@ class Client {
|
|
|
376
376
|
}
|
|
377
377
|
/**
|
|
378
378
|
* Queries a document from the Prismic repository with a specific UID and
|
|
379
|
-
*
|
|
379
|
+
* custom type.
|
|
380
380
|
*
|
|
381
381
|
* @remarks
|
|
382
382
|
* A document's UID is different from its ID. An ID is automatically generated
|
|
383
383
|
* for all documents and is made available on its `id` property. A UID is
|
|
384
384
|
* provided in the Prismic editor and is unique among all documents of its
|
|
385
|
-
*
|
|
385
|
+
* custom type.
|
|
386
386
|
* @example
|
|
387
387
|
*
|
|
388
388
|
* ```ts
|
|
@@ -390,7 +390,7 @@ class Client {
|
|
|
390
390
|
* ```
|
|
391
391
|
*
|
|
392
392
|
* @typeParam TDocument - Type of the Prismic document returned.
|
|
393
|
-
* @param documentType - The API ID of the document's
|
|
393
|
+
* @param documentType - The API ID of the document's custom type.
|
|
394
394
|
* @param uid - UID of the document.
|
|
395
395
|
* @param params - Parameters to filter, sort, and paginate the results.
|
|
396
396
|
*
|
|
@@ -411,7 +411,7 @@ class Client {
|
|
|
411
411
|
* A document's UID is different from its ID. An ID is automatically generated
|
|
412
412
|
* for all documents and is made available on its `id` property. A UID is
|
|
413
413
|
* provided in the Prismic editor and is unique among all documents of its
|
|
414
|
-
*
|
|
414
|
+
* custom type.
|
|
415
415
|
* @example
|
|
416
416
|
*
|
|
417
417
|
* ```ts
|
|
@@ -422,7 +422,7 @@ class Client {
|
|
|
422
422
|
* ```
|
|
423
423
|
*
|
|
424
424
|
* @typeParam TDocument - Type of the Prismic document returned.
|
|
425
|
-
* @param documentType - The API ID of the document's
|
|
425
|
+
* @param documentType - The API ID of the document's custom type.
|
|
426
426
|
* @param uids - A list of document UIDs.
|
|
427
427
|
* @param params - Parameters to filter, sort, and paginate the results.
|
|
428
428
|
*
|
|
@@ -437,7 +437,7 @@ class Client {
|
|
|
437
437
|
}
|
|
438
438
|
/**
|
|
439
439
|
* Queries all documents from the Prismic repository with specific UIDs and
|
|
440
|
-
*
|
|
440
|
+
* custom type.
|
|
441
441
|
*
|
|
442
442
|
* This method may make multiple network requests to query all matching
|
|
443
443
|
* content.
|
|
@@ -446,7 +446,7 @@ class Client {
|
|
|
446
446
|
* A document's UID is different from its ID. An ID is automatically generated
|
|
447
447
|
* for all documents and is made available on its `id` property. A UID is
|
|
448
448
|
* provided in the Prismic editor and is unique among all documents of its
|
|
449
|
-
*
|
|
449
|
+
* custom type.
|
|
450
450
|
* @example
|
|
451
451
|
*
|
|
452
452
|
* ```ts
|
|
@@ -457,7 +457,7 @@ class Client {
|
|
|
457
457
|
* ```
|
|
458
458
|
*
|
|
459
459
|
* @typeParam TDocument - Type of Prismic documents returned.
|
|
460
|
-
* @param documentType - The API ID of the document's
|
|
460
|
+
* @param documentType - The API ID of the document's custom type.
|
|
461
461
|
* @param uids - A list of document UIDs.
|
|
462
462
|
* @param params - Parameters to filter, sort, and paginate the results.
|
|
463
463
|
*
|
|
@@ -471,12 +471,12 @@ class Client {
|
|
|
471
471
|
}
|
|
472
472
|
/**
|
|
473
473
|
* Queries a singleton document from the Prismic repository for a specific
|
|
474
|
-
*
|
|
474
|
+
* custom type.
|
|
475
475
|
*
|
|
476
476
|
* @remarks
|
|
477
477
|
* A singleton document is one that is configured in Prismic to only allow one
|
|
478
478
|
* instance. For example, a repository may be configured to contain just one
|
|
479
|
-
* Settings document. This is in contrast to a repeatable
|
|
479
|
+
* Settings document. This is in contrast to a repeatable custom type which
|
|
480
480
|
* allows multiple instances of itself.
|
|
481
481
|
* @example
|
|
482
482
|
*
|
|
@@ -485,20 +485,20 @@ class Client {
|
|
|
485
485
|
* ```
|
|
486
486
|
*
|
|
487
487
|
* @typeParam TDocument - Type of the Prismic document returned.
|
|
488
|
-
* @param documentType - The API ID of the singleton
|
|
488
|
+
* @param documentType - The API ID of the singleton custom type.
|
|
489
489
|
* @param params - Parameters to filter, sort, and paginate the results.
|
|
490
490
|
*
|
|
491
|
-
* @returns The singleton document for the
|
|
491
|
+
* @returns The singleton document for the custom type, if a matching document
|
|
492
492
|
* exists.
|
|
493
493
|
*/
|
|
494
494
|
async getSingle(documentType, params) {
|
|
495
495
|
return await this.getFirst(appendFilters.appendFilters(params, typeFilter.typeFilter(documentType)));
|
|
496
496
|
}
|
|
497
497
|
/**
|
|
498
|
-
* Queries documents from the Prismic repository for a specific
|
|
498
|
+
* Queries documents from the Prismic repository for a specific custom type.
|
|
499
499
|
*
|
|
500
500
|
* Use `getAllByType` instead if you need to query all documents for a
|
|
501
|
-
* specific
|
|
501
|
+
* specific custom type.
|
|
502
502
|
*
|
|
503
503
|
* @example
|
|
504
504
|
*
|
|
@@ -507,10 +507,10 @@ class Client {
|
|
|
507
507
|
* ```
|
|
508
508
|
*
|
|
509
509
|
* @typeParam TDocument - Type of Prismic documents returned.
|
|
510
|
-
* @param documentType - The API ID of the
|
|
510
|
+
* @param documentType - The API ID of the custom type.
|
|
511
511
|
* @param params - Parameters to filter, sort, and paginate the results.
|
|
512
512
|
*
|
|
513
|
-
* @returns A paginated response containing documents of the
|
|
513
|
+
* @returns A paginated response containing documents of the custom type.
|
|
514
514
|
*/
|
|
515
515
|
async getByType(documentType, params) {
|
|
516
516
|
return await this.get(appendFilters.appendFilters(params, typeFilter.typeFilter(documentType)));
|
|
@@ -529,10 +529,10 @@ class Client {
|
|
|
529
529
|
* ```
|
|
530
530
|
*
|
|
531
531
|
* @typeParam TDocument - Type of Prismic documents returned.
|
|
532
|
-
* @param documentType - The API ID of the
|
|
532
|
+
* @param documentType - The API ID of the custom type.
|
|
533
533
|
* @param params - Parameters to filter, sort, and paginate the results.
|
|
534
534
|
*
|
|
535
|
-
* @returns A list of all documents of the
|
|
535
|
+
* @returns A list of all documents of the custom type.
|
|
536
536
|
*/
|
|
537
537
|
async getAllByType(documentType, params) {
|
|
538
538
|
return await this.dangerouslyGetAll(appendFilters.appendFilters(params, typeFilter.typeFilter(documentType)));
|