prismic-ts-codegen 0.1.13 → 0.1.14
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/_node_modules/@prismicio/client/dist/buildQueryURL.cjs +59 -0
- package/dist/_node_modules/@prismicio/client/dist/buildQueryURL.cjs.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/buildQueryURL.js +59 -0
- package/dist/_node_modules/@prismicio/client/dist/buildQueryURL.js.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/cookie.cjs +5 -0
- package/dist/_node_modules/@prismicio/client/dist/cookie.cjs.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/cookie.js +5 -0
- package/dist/_node_modules/@prismicio/client/dist/cookie.js.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/createClient.cjs +1138 -0
- package/dist/_node_modules/@prismicio/client/dist/createClient.cjs.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/createClient.js +1138 -0
- package/dist/_node_modules/@prismicio/client/dist/createClient.js.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/errors/ForbiddenError.cjs +7 -0
- package/dist/_node_modules/@prismicio/client/dist/errors/ForbiddenError.cjs.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/errors/ForbiddenError.js +7 -0
- package/dist/_node_modules/@prismicio/client/dist/errors/ForbiddenError.js.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/errors/NotFoundError.cjs +7 -0
- package/dist/_node_modules/@prismicio/client/dist/errors/NotFoundError.cjs.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/errors/NotFoundError.js +7 -0
- package/dist/_node_modules/@prismicio/client/dist/errors/NotFoundError.js.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/errors/ParsingError.cjs +7 -0
- package/dist/_node_modules/@prismicio/client/dist/errors/ParsingError.cjs.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/errors/ParsingError.js +7 -0
- package/dist/_node_modules/@prismicio/client/dist/errors/ParsingError.js.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/errors/PrismicError.cjs +19 -0
- package/dist/_node_modules/@prismicio/client/dist/errors/PrismicError.cjs.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/errors/PrismicError.js +19 -0
- package/dist/_node_modules/@prismicio/client/dist/errors/PrismicError.js.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/filter.cjs +247 -0
- package/dist/_node_modules/@prismicio/client/dist/filter.cjs.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/filter.js +247 -0
- package/dist/_node_modules/@prismicio/client/dist/filter.js.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/getRepositoryEndpoint.cjs +13 -0
- package/dist/_node_modules/@prismicio/client/dist/getRepositoryEndpoint.cjs.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/getRepositoryEndpoint.js +13 -0
- package/dist/_node_modules/@prismicio/client/dist/getRepositoryEndpoint.js.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/getRepositoryName.cjs +12 -0
- package/dist/_node_modules/@prismicio/client/dist/getRepositoryName.cjs.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/getRepositoryName.js +12 -0
- package/dist/_node_modules/@prismicio/client/dist/getRepositoryName.js.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/helpers/asLink.cjs +47 -0
- package/dist/_node_modules/@prismicio/client/dist/helpers/asLink.cjs.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/helpers/asLink.js +47 -0
- package/dist/_node_modules/@prismicio/client/dist/helpers/asLink.js.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/helpers/documentToLinkField.cjs +26 -0
- package/dist/_node_modules/@prismicio/client/dist/helpers/documentToLinkField.cjs.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/helpers/documentToLinkField.js +26 -0
- package/dist/_node_modules/@prismicio/client/dist/helpers/documentToLinkField.js.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/isRepositoryEndpoint.cjs +12 -0
- package/dist/_node_modules/@prismicio/client/dist/isRepositoryEndpoint.cjs.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/isRepositoryEndpoint.js +12 -0
- package/dist/_node_modules/@prismicio/client/dist/isRepositoryEndpoint.js.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/isRepositoryName.cjs +7 -0
- package/dist/_node_modules/@prismicio/client/dist/isRepositoryName.cjs.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/isRepositoryName.js +7 -0
- package/dist/_node_modules/@prismicio/client/dist/isRepositoryName.js.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/lib/appendFilters.cjs +11 -0
- package/dist/_node_modules/@prismicio/client/dist/lib/appendFilters.cjs.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/lib/appendFilters.js +11 -0
- package/dist/_node_modules/@prismicio/client/dist/lib/appendFilters.js.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/lib/castArray.cjs +7 -0
- package/dist/_node_modules/@prismicio/client/dist/lib/castArray.cjs.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/lib/castArray.js +7 -0
- package/dist/_node_modules/@prismicio/client/dist/lib/castArray.js.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/lib/castThunk.cjs +7 -0
- package/dist/_node_modules/@prismicio/client/dist/lib/castThunk.cjs.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/lib/castThunk.js +7 -0
- package/dist/_node_modules/@prismicio/client/dist/lib/castThunk.js.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/lib/devMsg.cjs +8 -0
- package/dist/_node_modules/@prismicio/client/dist/lib/devMsg.cjs.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/lib/devMsg.js +8 -0
- package/dist/_node_modules/@prismicio/client/dist/lib/devMsg.js.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/lib/everyTagFilter.cjs +9 -0
- package/dist/_node_modules/@prismicio/client/dist/lib/everyTagFilter.cjs.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/lib/everyTagFilter.js +9 -0
- package/dist/_node_modules/@prismicio/client/dist/lib/everyTagFilter.js.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/lib/findMasterRef.cjs +8 -0
- package/dist/_node_modules/@prismicio/client/dist/lib/findMasterRef.cjs.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/lib/findMasterRef.js +8 -0
- package/dist/_node_modules/@prismicio/client/dist/lib/findMasterRef.js.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/lib/findRef.cjs +12 -0
- package/dist/_node_modules/@prismicio/client/dist/lib/findRef.cjs.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/lib/findRef.js +12 -0
- package/dist/_node_modules/@prismicio/client/dist/lib/findRef.js.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/lib/findRefByID.cjs +8 -0
- package/dist/_node_modules/@prismicio/client/dist/lib/findRefByID.cjs.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/lib/findRefByID.js +8 -0
- package/dist/_node_modules/@prismicio/client/dist/lib/findRefByID.js.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/lib/findRefByLabel.cjs +8 -0
- package/dist/_node_modules/@prismicio/client/dist/lib/findRefByLabel.cjs.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/lib/findRefByLabel.js +8 -0
- package/dist/_node_modules/@prismicio/client/dist/lib/findRefByLabel.js.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/lib/getPreviewCookie.cjs +21 -0
- package/dist/_node_modules/@prismicio/client/dist/lib/getPreviewCookie.cjs.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/lib/getPreviewCookie.js +21 -0
- package/dist/_node_modules/@prismicio/client/dist/lib/getPreviewCookie.js.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/lib/minifyGraphQLQuery.cjs +7 -0
- package/dist/_node_modules/@prismicio/client/dist/lib/minifyGraphQLQuery.cjs.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/lib/minifyGraphQLQuery.js +7 -0
- package/dist/_node_modules/@prismicio/client/dist/lib/minifyGraphQLQuery.js.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/lib/someTagsFilter.cjs +9 -0
- package/dist/_node_modules/@prismicio/client/dist/lib/someTagsFilter.cjs.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/lib/someTagsFilter.js +9 -0
- package/dist/_node_modules/@prismicio/client/dist/lib/someTagsFilter.js.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/lib/typeFilter.cjs +8 -0
- package/dist/_node_modules/@prismicio/client/dist/lib/typeFilter.cjs.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/lib/typeFilter.js +8 -0
- package/dist/_node_modules/@prismicio/client/dist/lib/typeFilter.js.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/package.json.cjs +5 -0
- package/dist/_node_modules/@prismicio/client/dist/package.json.cjs.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/package.json.js +5 -0
- package/dist/_node_modules/@prismicio/client/dist/package.json.js.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/types/value/link.cjs +10 -0
- package/dist/_node_modules/@prismicio/client/dist/types/value/link.cjs.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/types/value/link.js +10 -0
- package/dist/_node_modules/@prismicio/client/dist/types/value/link.js.map +1 -0
- package/dist/cli/loadLocaleIDs.cjs +2 -19
- package/dist/cli/loadLocaleIDs.cjs.map +1 -1
- package/dist/cli/loadLocaleIDs.js +2 -2
- package/dist/cli/loadLocaleIDs.js.map +1 -1
- package/dist/lib/buildCustomTypeDataType.cjs.map +1 -1
- package/dist/lib/buildCustomTypeDataType.d.ts +1 -1
- package/dist/lib/buildCustomTypeDataType.js.map +1 -1
- package/dist/lib/buildCustomTypeType.cjs.map +1 -1
- package/dist/lib/buildCustomTypeType.d.ts +1 -1
- package/dist/lib/buildCustomTypeType.js.map +1 -1
- package/dist/lib/buildFieldDocs.cjs.map +1 -1
- package/dist/lib/buildFieldDocs.d.ts +1 -1
- package/dist/lib/buildFieldDocs.js.map +1 -1
- package/dist/lib/buildFieldProperties.cjs +18 -19
- package/dist/lib/buildFieldProperties.cjs.map +1 -1
- package/dist/lib/buildFieldProperties.d.ts +1 -1
- package/dist/lib/buildFieldProperties.js +18 -19
- package/dist/lib/buildFieldProperties.js.map +1 -1
- package/dist/lib/buildSharedSliceType.cjs.map +1 -1
- package/dist/lib/buildSharedSliceType.d.ts +1 -1
- package/dist/lib/buildSharedSliceType.js.map +1 -1
- package/dist/lib/checkHasUIDFIeld.cjs.map +1 -1
- package/dist/lib/checkHasUIDFIeld.d.ts +1 -1
- package/dist/lib/checkHasUIDFIeld.js.map +1 -1
- package/package.json +1 -1
- package/src/lib/buildCustomTypeDataType.ts +1 -1
- package/src/lib/buildCustomTypeType.ts +1 -1
- package/src/lib/buildFieldDocs.ts +1 -1
- package/src/lib/buildFieldProperties.ts +19 -23
- package/src/lib/buildSharedSliceType.ts +1 -1
- package/src/lib/checkHasUIDFIeld.ts +1 -1
|
@@ -0,0 +1,1138 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const appendFilters = require("./lib/appendFilters.cjs");
|
|
4
|
+
const castThunk = require("./lib/castThunk.cjs");
|
|
5
|
+
const devMsg = require("./lib/devMsg.cjs");
|
|
6
|
+
const everyTagFilter = require("./lib/everyTagFilter.cjs");
|
|
7
|
+
const findMasterRef = require("./lib/findMasterRef.cjs");
|
|
8
|
+
const findRefByID = require("./lib/findRefByID.cjs");
|
|
9
|
+
const findRefByLabel = require("./lib/findRefByLabel.cjs");
|
|
10
|
+
const getPreviewCookie = require("./lib/getPreviewCookie.cjs");
|
|
11
|
+
const minifyGraphQLQuery = require("./lib/minifyGraphQLQuery.cjs");
|
|
12
|
+
const someTagsFilter = require("./lib/someTagsFilter.cjs");
|
|
13
|
+
const typeFilter = require("./lib/typeFilter.cjs");
|
|
14
|
+
const ForbiddenError = require("./errors/ForbiddenError.cjs");
|
|
15
|
+
const NotFoundError = require("./errors/NotFoundError.cjs");
|
|
16
|
+
const ParsingError = require("./errors/ParsingError.cjs");
|
|
17
|
+
const PrismicError = require("./errors/PrismicError.cjs");
|
|
18
|
+
const asLink = require("./helpers/asLink.cjs");
|
|
19
|
+
const buildQueryURL = require("./buildQueryURL.cjs");
|
|
20
|
+
const filter = require("./filter.cjs");
|
|
21
|
+
const getRepositoryEndpoint = require("./getRepositoryEndpoint.cjs");
|
|
22
|
+
const getRepositoryName = require("./getRepositoryName.cjs");
|
|
23
|
+
const isRepositoryEndpoint = require("./isRepositoryEndpoint.cjs");
|
|
24
|
+
var __defProp = Object.defineProperty;
|
|
25
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
26
|
+
var __publicField = (obj, key, value) => {
|
|
27
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
28
|
+
return value;
|
|
29
|
+
};
|
|
30
|
+
const MAX_PAGE_SIZE = 100;
|
|
31
|
+
const REPOSITORY_CACHE_TTL = 5e3;
|
|
32
|
+
const GET_ALL_QUERY_DELAY = 500;
|
|
33
|
+
var RefStateMode;
|
|
34
|
+
(function(RefStateMode2) {
|
|
35
|
+
RefStateMode2["Master"] = "Master";
|
|
36
|
+
RefStateMode2["ReleaseID"] = "ReleaseID";
|
|
37
|
+
RefStateMode2["ReleaseLabel"] = "ReleaseLabel";
|
|
38
|
+
RefStateMode2["Manual"] = "Manual";
|
|
39
|
+
})(RefStateMode || (RefStateMode = {}));
|
|
40
|
+
const createClient = (repositoryNameOrEndpoint, options) => new Client(repositoryNameOrEndpoint, options);
|
|
41
|
+
class Client {
|
|
42
|
+
/**
|
|
43
|
+
* Creates a Prismic client that can be used to query a repository.
|
|
44
|
+
*
|
|
45
|
+
* If used in an environment where a global `fetch` function is unavailable,
|
|
46
|
+
* such as Node.js, the `fetch` option must be provided as part of the
|
|
47
|
+
* `options` parameter.
|
|
48
|
+
*
|
|
49
|
+
* @param repositoryNameOrEndpoint - The Prismic repository name or full Rest
|
|
50
|
+
* API V2 endpoint for the repository.
|
|
51
|
+
* @param options - Configuration that determines how content will be queried
|
|
52
|
+
* from the Prismic repository.
|
|
53
|
+
*
|
|
54
|
+
* @returns A client that can query content from the repository.
|
|
55
|
+
*/
|
|
56
|
+
constructor(repositoryNameOrEndpoint, options = {}) {
|
|
57
|
+
__publicField(this, "endpoint");
|
|
58
|
+
__publicField(this, "accessToken");
|
|
59
|
+
__publicField(this, "routes");
|
|
60
|
+
__publicField(this, "brokenRoute");
|
|
61
|
+
__publicField(this, "fetchFn");
|
|
62
|
+
__publicField(this, "fetchOptions");
|
|
63
|
+
__publicField(this, "defaultParams");
|
|
64
|
+
__publicField(this, "refState", {
|
|
65
|
+
mode: RefStateMode.Master,
|
|
66
|
+
autoPreviewsEnabled: true
|
|
67
|
+
});
|
|
68
|
+
__publicField(this, "cachedRepository");
|
|
69
|
+
__publicField(this, "cachedRepositoryExpiration", 0);
|
|
70
|
+
__publicField(this, "fetchJobs", {});
|
|
71
|
+
if (isRepositoryEndpoint.isRepositoryEndpoint(repositoryNameOrEndpoint)) {
|
|
72
|
+
if (process.env.NODE_ENV === "development") {
|
|
73
|
+
if (/\.prismic\.io\/(?!api\/v2\/?)/i.test(repositoryNameOrEndpoint)) {
|
|
74
|
+
throw new PrismicError.PrismicError("@prismicio/client only supports Prismic Rest API V2. Please provide only the repository name to the first createClient() parameter or use the getRepositoryEndpoint() helper to generate a valid Rest API V2 endpoint URL.", void 0, void 0);
|
|
75
|
+
}
|
|
76
|
+
const hostname = new URL(repositoryNameOrEndpoint).hostname.toLowerCase();
|
|
77
|
+
if (hostname.endsWith(".prismic.io") && !hostname.endsWith(".cdn.prismic.io")) {
|
|
78
|
+
const repositoryName = getRepositoryName.getRepositoryName(repositoryNameOrEndpoint);
|
|
79
|
+
const dotCDNEndpoint = getRepositoryEndpoint.getRepositoryEndpoint(repositoryName);
|
|
80
|
+
console.warn(`[@prismicio/client] A non-.cdn endpoint was provided to create a client with (\`${repositoryNameOrEndpoint}\`). Non-.cdn endpoints can have unexpected side-effects and cause performance issues when querying Prismic. Please convert it to the \`.cdn\` alternative (\`${dotCDNEndpoint}\`) or use the repository name directly instead (\`${repositoryName}\`). For more details, see ${devMsg.devMsg("endpoint-must-use-cdn")}`);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
this.endpoint = repositoryNameOrEndpoint;
|
|
84
|
+
} else {
|
|
85
|
+
this.endpoint = getRepositoryEndpoint.getRepositoryEndpoint(repositoryNameOrEndpoint);
|
|
86
|
+
}
|
|
87
|
+
this.accessToken = options.accessToken;
|
|
88
|
+
this.routes = options.routes;
|
|
89
|
+
this.brokenRoute = options.brokenRoute;
|
|
90
|
+
this.fetchOptions = options.fetchOptions;
|
|
91
|
+
this.defaultParams = options.defaultParams;
|
|
92
|
+
if (options.ref) {
|
|
93
|
+
this.queryContentFromRef(options.ref);
|
|
94
|
+
}
|
|
95
|
+
if (typeof options.fetch === "function") {
|
|
96
|
+
this.fetchFn = options.fetch;
|
|
97
|
+
} else if (typeof globalThis.fetch === "function") {
|
|
98
|
+
this.fetchFn = globalThis.fetch;
|
|
99
|
+
} else {
|
|
100
|
+
throw new PrismicError.PrismicError("A valid fetch implementation was not provided. In environments where fetch is not available (including Node.js), a fetch implementation must be provided via a polyfill or the `fetch` option.", void 0, void 0);
|
|
101
|
+
}
|
|
102
|
+
if (this.fetchFn === globalThis.fetch) {
|
|
103
|
+
this.fetchFn = this.fetchFn.bind(globalThis);
|
|
104
|
+
}
|
|
105
|
+
this.graphQLFetch = this.graphQLFetch.bind(this);
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Enables the client to automatically query content from a preview session if
|
|
109
|
+
* one is active in browser environments. This is enabled by default in the
|
|
110
|
+
* browser.
|
|
111
|
+
*
|
|
112
|
+
* For server environments, use `enableAutoPreviewsFromReq`.
|
|
113
|
+
*
|
|
114
|
+
* @example
|
|
115
|
+
*
|
|
116
|
+
* ```ts
|
|
117
|
+
* client.enableAutoPreviews();
|
|
118
|
+
* ```
|
|
119
|
+
*
|
|
120
|
+
* @see enableAutoPreviewsFromReq
|
|
121
|
+
*/
|
|
122
|
+
enableAutoPreviews() {
|
|
123
|
+
this.refState.autoPreviewsEnabled = true;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Enables the client to automatically query content from a preview session if
|
|
127
|
+
* one is active in server environments. This is disabled by default on the
|
|
128
|
+
* server.
|
|
129
|
+
*
|
|
130
|
+
* For browser environments, use `enableAutoPreviews`.
|
|
131
|
+
*
|
|
132
|
+
* @example
|
|
133
|
+
*
|
|
134
|
+
* ```ts
|
|
135
|
+
* // In an express app
|
|
136
|
+
* app.get("/", function (req, res) {
|
|
137
|
+
* client.enableAutoPreviewsFromReq(req);
|
|
138
|
+
* });
|
|
139
|
+
* ```
|
|
140
|
+
*
|
|
141
|
+
* @param req - An HTTP server request object containing the request's
|
|
142
|
+
* cookies.
|
|
143
|
+
*/
|
|
144
|
+
enableAutoPreviewsFromReq(req) {
|
|
145
|
+
this.refState.httpRequest = req;
|
|
146
|
+
this.refState.autoPreviewsEnabled = true;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Disables the client from automatically querying content from a preview
|
|
150
|
+
* session if one is active.
|
|
151
|
+
*
|
|
152
|
+
* Automatic preview content querying is enabled by default unless this method
|
|
153
|
+
* is called.
|
|
154
|
+
*
|
|
155
|
+
* @example
|
|
156
|
+
*
|
|
157
|
+
* ```ts
|
|
158
|
+
* client.disableAutoPreviews();
|
|
159
|
+
* ```
|
|
160
|
+
*/
|
|
161
|
+
disableAutoPreviews() {
|
|
162
|
+
this.refState.autoPreviewsEnabled = false;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Queries content from the Prismic repository.
|
|
166
|
+
*
|
|
167
|
+
* @example
|
|
168
|
+
*
|
|
169
|
+
* ```ts
|
|
170
|
+
* const response = await client.get();
|
|
171
|
+
* ```
|
|
172
|
+
*
|
|
173
|
+
* @typeParam TDocument - Type of Prismic documents returned.
|
|
174
|
+
*
|
|
175
|
+
* @param params - Parameters to filter, sort, and paginate results.
|
|
176
|
+
*
|
|
177
|
+
* @returns A paginated response containing the result of the query.
|
|
178
|
+
*/
|
|
179
|
+
async get(params) {
|
|
180
|
+
const url = await this.buildQueryURL(params);
|
|
181
|
+
return await this.fetch(url, params);
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Queries content from the Prismic repository and returns only the first
|
|
185
|
+
* result, if any.
|
|
186
|
+
*
|
|
187
|
+
* @example
|
|
188
|
+
*
|
|
189
|
+
* ```ts
|
|
190
|
+
* const document = await client.getFirst();
|
|
191
|
+
* ```
|
|
192
|
+
*
|
|
193
|
+
* @typeParam TDocument - Type of the Prismic document returned.
|
|
194
|
+
*
|
|
195
|
+
* @param params - Parameters to filter, sort, and paginate results. @returns
|
|
196
|
+
* The first result of the query, if any.
|
|
197
|
+
*/
|
|
198
|
+
async getFirst(params) {
|
|
199
|
+
var _a;
|
|
200
|
+
const actualParams = { ...params };
|
|
201
|
+
if (!(params && params.page) && !(params == null ? void 0 : params.pageSize)) {
|
|
202
|
+
actualParams.pageSize = ((_a = this.defaultParams) == null ? void 0 : _a.pageSize) ?? 1;
|
|
203
|
+
}
|
|
204
|
+
const url = await this.buildQueryURL(actualParams);
|
|
205
|
+
const result = await this.fetch(url, params);
|
|
206
|
+
const firstResult = result.results[0];
|
|
207
|
+
if (firstResult) {
|
|
208
|
+
return firstResult;
|
|
209
|
+
}
|
|
210
|
+
throw new PrismicError.PrismicError("No documents were returned", url, void 0);
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* **IMPORTANT**: Avoid using `dangerouslyGetAll` as it may be slower and
|
|
214
|
+
* require more resources than other methods. Prefer using other methods that
|
|
215
|
+
* filter by filters such as `getAllByType`.
|
|
216
|
+
*
|
|
217
|
+
* Queries content from the Prismic repository and returns all matching
|
|
218
|
+
* content. If no filters are provided, all documents will be fetched.
|
|
219
|
+
*
|
|
220
|
+
* This method may make multiple network requests to query all matching
|
|
221
|
+
* content.
|
|
222
|
+
*
|
|
223
|
+
* @example
|
|
224
|
+
*
|
|
225
|
+
* ```ts
|
|
226
|
+
* const response = await client.dangerouslyGetAll();
|
|
227
|
+
* ```
|
|
228
|
+
*
|
|
229
|
+
* @typeParam TDocument - Type of Prismic documents returned.
|
|
230
|
+
*
|
|
231
|
+
* @param params - Parameters to filter, sort, and paginate results.
|
|
232
|
+
*
|
|
233
|
+
* @returns A list of documents matching the query.
|
|
234
|
+
*/
|
|
235
|
+
async dangerouslyGetAll(params = {}) {
|
|
236
|
+
var _a;
|
|
237
|
+
const { limit = Infinity, ...actualParams } = params;
|
|
238
|
+
const resolvedParams = {
|
|
239
|
+
...actualParams,
|
|
240
|
+
pageSize: Math.min(limit, actualParams.pageSize || ((_a = this.defaultParams) == null ? void 0 : _a.pageSize) || MAX_PAGE_SIZE)
|
|
241
|
+
};
|
|
242
|
+
const documents = [];
|
|
243
|
+
let latestResult;
|
|
244
|
+
while ((!latestResult || latestResult.next_page) && documents.length < limit) {
|
|
245
|
+
const page = latestResult ? latestResult.page + 1 : void 0;
|
|
246
|
+
latestResult = await this.get({ ...resolvedParams, page });
|
|
247
|
+
documents.push(...latestResult.results);
|
|
248
|
+
if (latestResult.next_page) {
|
|
249
|
+
await new Promise((res) => setTimeout(res, GET_ALL_QUERY_DELAY));
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
return documents.slice(0, limit);
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* Queries a document from the Prismic repository with a specific ID.
|
|
256
|
+
*
|
|
257
|
+
* @remarks
|
|
258
|
+
* A document's UID is different from its ID. An ID is automatically generated
|
|
259
|
+
* for all documents and is made available on its `id` property. A UID is
|
|
260
|
+
* provided in the Prismic editor and is unique among all documents of its
|
|
261
|
+
* custom type.
|
|
262
|
+
* @example
|
|
263
|
+
*
|
|
264
|
+
* ```ts
|
|
265
|
+
* const document = await client.getByID("WW4bKScAAMAqmluX");
|
|
266
|
+
* ```
|
|
267
|
+
*
|
|
268
|
+
* @typeParam TDocument- Type of the Prismic document returned.
|
|
269
|
+
*
|
|
270
|
+
* @param id - ID of the document.
|
|
271
|
+
* @param params - Parameters to filter, sort, and paginate the results.
|
|
272
|
+
*
|
|
273
|
+
* @returns The document with an ID matching the `id` parameter, if a matching
|
|
274
|
+
* document exists.
|
|
275
|
+
*/
|
|
276
|
+
async getByID(id, params) {
|
|
277
|
+
return await this.getFirst(appendFilters.appendFilters(params, filter.filter.at("document.id", id)));
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Queries documents from the Prismic repository with specific IDs.
|
|
281
|
+
*
|
|
282
|
+
* @remarks
|
|
283
|
+
* A document's UID is different from its ID. An ID is automatically generated
|
|
284
|
+
* for all documents and is made available on its `id` property. A UID is
|
|
285
|
+
* provided in the Prismic editor and is unique among all documents of its
|
|
286
|
+
* custom type.
|
|
287
|
+
* @example
|
|
288
|
+
*
|
|
289
|
+
* ```ts
|
|
290
|
+
* const response = await client.getByIDs([
|
|
291
|
+
* "WW4bKScAAMAqmluX",
|
|
292
|
+
* "U1kTRgEAAC8A5ldS",
|
|
293
|
+
* ]);
|
|
294
|
+
* ```
|
|
295
|
+
*
|
|
296
|
+
* @typeParam TDocument - Type of Prismic documents returned.
|
|
297
|
+
*
|
|
298
|
+
* @param ids - A list of document IDs.
|
|
299
|
+
* @param params - Parameters to filter, sort, and paginate the results.
|
|
300
|
+
*
|
|
301
|
+
* @returns A paginated response containing documents with IDs matching the
|
|
302
|
+
* `ids` parameter.
|
|
303
|
+
*/
|
|
304
|
+
async getByIDs(ids, params) {
|
|
305
|
+
return await this.get(appendFilters.appendFilters(params, filter.filter.in("document.id", ids)));
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* Queries all documents from the Prismic repository with specific IDs.
|
|
309
|
+
*
|
|
310
|
+
* This method may make multiple network requests to query all matching
|
|
311
|
+
* content.
|
|
312
|
+
*
|
|
313
|
+
* @remarks
|
|
314
|
+
* A document's UID is different from its ID. An ID is automatically generated
|
|
315
|
+
* for all documents and is made available on its `id` property. A UID is
|
|
316
|
+
* provided in the Prismic editor and is unique among all documents of its
|
|
317
|
+
* custom type.
|
|
318
|
+
* @example
|
|
319
|
+
*
|
|
320
|
+
* ```ts
|
|
321
|
+
* const response = await client.getAllByIDs([
|
|
322
|
+
* "WW4bKScAAMAqmluX",
|
|
323
|
+
* "U1kTRgEAAC8A5ldS",
|
|
324
|
+
* ]);
|
|
325
|
+
* ```
|
|
326
|
+
*
|
|
327
|
+
* @typeParam TDocument - Type of Prismic documents returned.
|
|
328
|
+
*
|
|
329
|
+
* @param ids - A list of document IDs.
|
|
330
|
+
* @param params - Parameters to filter, sort, and paginate the results.
|
|
331
|
+
*
|
|
332
|
+
* @returns A list of documents with IDs matching the `ids` parameter.
|
|
333
|
+
*/
|
|
334
|
+
async getAllByIDs(ids, params) {
|
|
335
|
+
return await this.dangerouslyGetAll(appendFilters.appendFilters(params, filter.filter.in("document.id", ids)));
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
338
|
+
* Queries a document from the Prismic repository with a specific UID and
|
|
339
|
+
* custom type.
|
|
340
|
+
*
|
|
341
|
+
* @remarks
|
|
342
|
+
* A document's UID is different from its ID. An ID is automatically generated
|
|
343
|
+
* for all documents and is made available on its `id` property. A UID is
|
|
344
|
+
* provided in the Prismic editor and is unique among all documents of its
|
|
345
|
+
* custom type.
|
|
346
|
+
* @example
|
|
347
|
+
*
|
|
348
|
+
* ```ts
|
|
349
|
+
* const document = await client.getByUID("blog_post", "my-first-post");
|
|
350
|
+
* ```
|
|
351
|
+
*
|
|
352
|
+
* @typeParam TDocument - Type of the Prismic document returned.
|
|
353
|
+
*
|
|
354
|
+
* @param documentType - The API ID of the document's custom type.
|
|
355
|
+
* @param uid - UID of the document.
|
|
356
|
+
* @param params - Parameters to filter, sort, and paginate the results.
|
|
357
|
+
*
|
|
358
|
+
* @returns The document with a UID matching the `uid` parameter, if a
|
|
359
|
+
* matching document exists.
|
|
360
|
+
*/
|
|
361
|
+
async getByUID(documentType, uid, params) {
|
|
362
|
+
return await this.getFirst(appendFilters.appendFilters(params, [
|
|
363
|
+
typeFilter.typeFilter(documentType),
|
|
364
|
+
filter.filter.at(`my.${documentType}.uid`, uid)
|
|
365
|
+
]));
|
|
366
|
+
}
|
|
367
|
+
/**
|
|
368
|
+
* Queries document from the Prismic repository with specific UIDs and Custom
|
|
369
|
+
* Type.
|
|
370
|
+
*
|
|
371
|
+
* @remarks
|
|
372
|
+
* A document's UID is different from its ID. An ID is automatically generated
|
|
373
|
+
* for all documents and is made available on its `id` property. A UID is
|
|
374
|
+
* provided in the Prismic editor and is unique among all documents of its
|
|
375
|
+
* custom type.
|
|
376
|
+
* @example
|
|
377
|
+
*
|
|
378
|
+
* ```ts
|
|
379
|
+
* const document = await client.getByUIDs("blog_post", [
|
|
380
|
+
* "my-first-post",
|
|
381
|
+
* "my-second-post",
|
|
382
|
+
* ]);
|
|
383
|
+
* ```
|
|
384
|
+
*
|
|
385
|
+
* @typeParam TDocument - Type of the Prismic document returned.
|
|
386
|
+
*
|
|
387
|
+
* @param documentType - The API ID of the document's custom type.
|
|
388
|
+
* @param uids - A list of document UIDs.
|
|
389
|
+
* @param params - Parameters to filter, sort, and paginate the results.
|
|
390
|
+
*
|
|
391
|
+
* @returns A paginated response containing documents with UIDs matching the
|
|
392
|
+
* `uids` parameter.
|
|
393
|
+
*/
|
|
394
|
+
async getByUIDs(documentType, uids, params) {
|
|
395
|
+
return await this.get(appendFilters.appendFilters(params, [
|
|
396
|
+
typeFilter.typeFilter(documentType),
|
|
397
|
+
filter.filter.in(`my.${documentType}.uid`, uids)
|
|
398
|
+
]));
|
|
399
|
+
}
|
|
400
|
+
/**
|
|
401
|
+
* Queries all documents from the Prismic repository with specific UIDs and
|
|
402
|
+
* custom type.
|
|
403
|
+
*
|
|
404
|
+
* This method may make multiple network requests to query all matching
|
|
405
|
+
* content.
|
|
406
|
+
*
|
|
407
|
+
* @remarks
|
|
408
|
+
* A document's UID is different from its ID. An ID is automatically generated
|
|
409
|
+
* for all documents and is made available on its `id` property. A UID is
|
|
410
|
+
* provided in the Prismic editor and is unique among all documents of its
|
|
411
|
+
* custom type.
|
|
412
|
+
* @example
|
|
413
|
+
*
|
|
414
|
+
* ```ts
|
|
415
|
+
* const response = await client.getAllByUIDs([
|
|
416
|
+
* "my-first-post",
|
|
417
|
+
* "my-second-post",
|
|
418
|
+
* ]);
|
|
419
|
+
* ```
|
|
420
|
+
*
|
|
421
|
+
* @typeParam TDocument - Type of Prismic documents returned.
|
|
422
|
+
*
|
|
423
|
+
* @param documentType - The API ID of the document's custom type.
|
|
424
|
+
* @param uids - A list of document UIDs.
|
|
425
|
+
* @param params - Parameters to filter, sort, and paginate the results.
|
|
426
|
+
*
|
|
427
|
+
* @returns A list of documents with UIDs matching the `uids` parameter.
|
|
428
|
+
*/
|
|
429
|
+
async getAllByUIDs(documentType, uids, params) {
|
|
430
|
+
return await this.dangerouslyGetAll(appendFilters.appendFilters(params, [
|
|
431
|
+
typeFilter.typeFilter(documentType),
|
|
432
|
+
filter.filter.in(`my.${documentType}.uid`, uids)
|
|
433
|
+
]));
|
|
434
|
+
}
|
|
435
|
+
/**
|
|
436
|
+
* Queries a singleton document from the Prismic repository for a specific
|
|
437
|
+
* custom type.
|
|
438
|
+
*
|
|
439
|
+
* @remarks
|
|
440
|
+
* A singleton document is one that is configured in Prismic to only allow one
|
|
441
|
+
* instance. For example, a repository may be configured to contain just one
|
|
442
|
+
* Settings document. This is in contrast to a repeatable custom type which
|
|
443
|
+
* allows multiple instances of itself.
|
|
444
|
+
* @example
|
|
445
|
+
*
|
|
446
|
+
* ```ts
|
|
447
|
+
* const document = await client.getSingle("settings");
|
|
448
|
+
* ```
|
|
449
|
+
*
|
|
450
|
+
* @typeParam TDocument - Type of the Prismic document returned.
|
|
451
|
+
*
|
|
452
|
+
* @param documentType - The API ID of the singleton custom type.
|
|
453
|
+
* @param params - Parameters to filter, sort, and paginate the results.
|
|
454
|
+
*
|
|
455
|
+
* @returns The singleton document for the custom type, if a matching document
|
|
456
|
+
* exists.
|
|
457
|
+
*/
|
|
458
|
+
async getSingle(documentType, params) {
|
|
459
|
+
return await this.getFirst(appendFilters.appendFilters(params, typeFilter.typeFilter(documentType)));
|
|
460
|
+
}
|
|
461
|
+
/**
|
|
462
|
+
* Queries documents from the Prismic repository for a specific custom type.
|
|
463
|
+
*
|
|
464
|
+
* Use `getAllByType` instead if you need to query all documents for a
|
|
465
|
+
* specific custom type.
|
|
466
|
+
*
|
|
467
|
+
* @example
|
|
468
|
+
*
|
|
469
|
+
* ```ts
|
|
470
|
+
* const response = await client.getByType("blog_post");
|
|
471
|
+
* ```
|
|
472
|
+
*
|
|
473
|
+
* @typeParam TDocument - Type of Prismic documents returned.
|
|
474
|
+
*
|
|
475
|
+
* @param documentType - The API ID of the custom type.
|
|
476
|
+
* @param params - Parameters to filter, sort, and paginate the results.
|
|
477
|
+
*
|
|
478
|
+
* @returns A paginated response containing documents of the custom type.
|
|
479
|
+
*/
|
|
480
|
+
async getByType(documentType, params) {
|
|
481
|
+
return await this.get(appendFilters.appendFilters(params, typeFilter.typeFilter(documentType)));
|
|
482
|
+
}
|
|
483
|
+
/**
|
|
484
|
+
* Queries all documents from the Prismic repository for a specific Custom
|
|
485
|
+
* Type.
|
|
486
|
+
*
|
|
487
|
+
* This method may make multiple network requests to query all matching
|
|
488
|
+
* content.
|
|
489
|
+
*
|
|
490
|
+
* @example
|
|
491
|
+
*
|
|
492
|
+
* ```ts
|
|
493
|
+
* const response = await client.getByType("blog_post");
|
|
494
|
+
* ```
|
|
495
|
+
*
|
|
496
|
+
* @typeParam TDocument - Type of Prismic documents returned.
|
|
497
|
+
*
|
|
498
|
+
* @param documentType - The API ID of the custom type.
|
|
499
|
+
* @param params - Parameters to filter, sort, and paginate the results.
|
|
500
|
+
*
|
|
501
|
+
* @returns A list of all documents of the custom type.
|
|
502
|
+
*/
|
|
503
|
+
async getAllByType(documentType, params) {
|
|
504
|
+
return await this.dangerouslyGetAll(appendFilters.appendFilters(params, typeFilter.typeFilter(documentType)));
|
|
505
|
+
}
|
|
506
|
+
/**
|
|
507
|
+
* Queries documents from the Prismic repository with a specific tag.
|
|
508
|
+
*
|
|
509
|
+
* Use `getAllByTag` instead if you need to query all documents with a
|
|
510
|
+
* specific tag.
|
|
511
|
+
*
|
|
512
|
+
* @example
|
|
513
|
+
*
|
|
514
|
+
* ```ts
|
|
515
|
+
* const response = await client.getByTag("food");
|
|
516
|
+
* ```
|
|
517
|
+
*
|
|
518
|
+
* @typeParam TDocument - Type of Prismic documents returned.
|
|
519
|
+
*
|
|
520
|
+
* @param tag - The tag that must be included on a document.
|
|
521
|
+
* @param params - Parameters to filter, sort, and paginate the results.
|
|
522
|
+
*
|
|
523
|
+
* @returns A paginated response containing documents with the tag.
|
|
524
|
+
*/
|
|
525
|
+
async getByTag(tag, params) {
|
|
526
|
+
return await this.get(appendFilters.appendFilters(params, someTagsFilter.someTagsFilter(tag)));
|
|
527
|
+
}
|
|
528
|
+
/**
|
|
529
|
+
* Queries all documents from the Prismic repository with a specific tag.
|
|
530
|
+
*
|
|
531
|
+
* This method may make multiple network requests to query all matching
|
|
532
|
+
* content.
|
|
533
|
+
*
|
|
534
|
+
* @example
|
|
535
|
+
*
|
|
536
|
+
* ```ts
|
|
537
|
+
* const response = await client.getAllByTag("food");
|
|
538
|
+
* ```
|
|
539
|
+
*
|
|
540
|
+
* @typeParam TDocument - Type of Prismic documents returned.
|
|
541
|
+
*
|
|
542
|
+
* @param tag - The tag that must be included on a document.
|
|
543
|
+
* @param params - Parameters to filter, sort, and paginate the results.
|
|
544
|
+
*
|
|
545
|
+
* @returns A list of all documents with the tag.
|
|
546
|
+
*/
|
|
547
|
+
async getAllByTag(tag, params) {
|
|
548
|
+
return await this.dangerouslyGetAll(appendFilters.appendFilters(params, someTagsFilter.someTagsFilter(tag)));
|
|
549
|
+
}
|
|
550
|
+
/**
|
|
551
|
+
* Queries documents from the Prismic repository with specific tags. A
|
|
552
|
+
* document must be tagged with all of the queried tags to be included.
|
|
553
|
+
*
|
|
554
|
+
* @example
|
|
555
|
+
*
|
|
556
|
+
* ```ts
|
|
557
|
+
* const response = await client.getByEveryTag(["food", "fruit"]);
|
|
558
|
+
* ```
|
|
559
|
+
*
|
|
560
|
+
* @typeParam TDocument - Type of Prismic documents returned.
|
|
561
|
+
*
|
|
562
|
+
* @param tags - A list of tags that must be included on a document.
|
|
563
|
+
* @param params - Parameters to filter, sort, and paginate the results.
|
|
564
|
+
*
|
|
565
|
+
* @returns A paginated response containing documents with the tags.
|
|
566
|
+
*/
|
|
567
|
+
async getByEveryTag(tags, params) {
|
|
568
|
+
return await this.get(appendFilters.appendFilters(params, everyTagFilter.everyTagFilter(tags)));
|
|
569
|
+
}
|
|
570
|
+
/**
|
|
571
|
+
* Queries documents from the Prismic repository with specific tags. A
|
|
572
|
+
* document must be tagged with all of the queried tags to be included.
|
|
573
|
+
*
|
|
574
|
+
* This method may make multiple network requests to query all matching
|
|
575
|
+
* content.
|
|
576
|
+
*
|
|
577
|
+
* @example
|
|
578
|
+
*
|
|
579
|
+
* ```ts
|
|
580
|
+
* const response = await client.getAllByEveryTag(["food", "fruit"]);
|
|
581
|
+
* ```
|
|
582
|
+
*
|
|
583
|
+
* @typeParam TDocument - Type of Prismic documents returned.
|
|
584
|
+
*
|
|
585
|
+
* @param tags - A list of tags that must be included on a document.
|
|
586
|
+
* @param params - Parameters to filter, sort, and paginate the results.
|
|
587
|
+
*
|
|
588
|
+
* @returns A list of all documents with the tags.
|
|
589
|
+
*/
|
|
590
|
+
async getAllByEveryTag(tags, params) {
|
|
591
|
+
return await this.dangerouslyGetAll(appendFilters.appendFilters(params, everyTagFilter.everyTagFilter(tags)));
|
|
592
|
+
}
|
|
593
|
+
/**
|
|
594
|
+
* Queries documents from the Prismic repository with specific tags. A
|
|
595
|
+
* document must be tagged with at least one of the queried tags to be
|
|
596
|
+
* included.
|
|
597
|
+
*
|
|
598
|
+
* @example
|
|
599
|
+
*
|
|
600
|
+
* ```ts
|
|
601
|
+
* const response = await client.getByEveryTag(["food", "fruit"]);
|
|
602
|
+
* ```
|
|
603
|
+
*
|
|
604
|
+
* @typeParam TDocument - Type of Prismic documents returned.
|
|
605
|
+
*
|
|
606
|
+
* @param tags - A list of tags that must be included on a document.
|
|
607
|
+
* @param params - Parameters to filter, sort, and paginate the results.
|
|
608
|
+
*
|
|
609
|
+
* @returns A paginated response containing documents with at least one of the
|
|
610
|
+
* tags.
|
|
611
|
+
*/
|
|
612
|
+
async getBySomeTags(tags, params) {
|
|
613
|
+
return await this.get(appendFilters.appendFilters(params, someTagsFilter.someTagsFilter(tags)));
|
|
614
|
+
}
|
|
615
|
+
/**
|
|
616
|
+
* Queries documents from the Prismic repository with specific tags. A
|
|
617
|
+
* document must be tagged with at least one of the queried tags to be
|
|
618
|
+
* included.
|
|
619
|
+
*
|
|
620
|
+
* This method may make multiple network requests to query all matching
|
|
621
|
+
* content.
|
|
622
|
+
*
|
|
623
|
+
* @example
|
|
624
|
+
*
|
|
625
|
+
* ```ts
|
|
626
|
+
* const response = await client.getAllBySomeTags(["food", "fruit"]);
|
|
627
|
+
* ```
|
|
628
|
+
*
|
|
629
|
+
* @typeParam TDocument - Type of Prismic documents returned.
|
|
630
|
+
*
|
|
631
|
+
* @param tags - A list of tags that must be included on a document.
|
|
632
|
+
* @param params - Parameters to filter, sort, and paginate the results.
|
|
633
|
+
*
|
|
634
|
+
* @returns A list of all documents with at least one of the tags.
|
|
635
|
+
*/
|
|
636
|
+
async getAllBySomeTags(tags, params) {
|
|
637
|
+
return await this.dangerouslyGetAll(appendFilters.appendFilters(params, someTagsFilter.someTagsFilter(tags)));
|
|
638
|
+
}
|
|
639
|
+
/**
|
|
640
|
+
* Returns metadata about the Prismic repository, such as its refs, releases,
|
|
641
|
+
* and custom types.
|
|
642
|
+
*
|
|
643
|
+
* @returns Repository metadata.
|
|
644
|
+
*/
|
|
645
|
+
async getRepository(params) {
|
|
646
|
+
const url = new URL(this.endpoint);
|
|
647
|
+
if (this.accessToken) {
|
|
648
|
+
url.searchParams.set("access_token", this.accessToken);
|
|
649
|
+
}
|
|
650
|
+
return await this.fetch(url.toString(), params);
|
|
651
|
+
}
|
|
652
|
+
/**
|
|
653
|
+
* Returns a list of all refs for the Prismic repository.
|
|
654
|
+
*
|
|
655
|
+
* Refs are used to identify which version of the repository's content should
|
|
656
|
+
* be queried. All repositories will have at least one ref pointing to the
|
|
657
|
+
* latest published content called the "master ref".
|
|
658
|
+
*
|
|
659
|
+
* @returns A list of all refs for the Prismic repository.
|
|
660
|
+
*/
|
|
661
|
+
async getRefs(params) {
|
|
662
|
+
const repository = await this.getRepository(params);
|
|
663
|
+
return repository.refs;
|
|
664
|
+
}
|
|
665
|
+
/**
|
|
666
|
+
* Returns a ref for the Prismic repository with a matching ID.
|
|
667
|
+
*
|
|
668
|
+
* @param id - ID of the ref.
|
|
669
|
+
*
|
|
670
|
+
* @returns The ref with a matching ID, if it exists.
|
|
671
|
+
*/
|
|
672
|
+
async getRefByID(id, params) {
|
|
673
|
+
const refs = await this.getRefs(params);
|
|
674
|
+
return findRefByID.findRefByID(refs, id);
|
|
675
|
+
}
|
|
676
|
+
/**
|
|
677
|
+
* Returns a ref for the Prismic repository with a matching label.
|
|
678
|
+
*
|
|
679
|
+
* @param label - Label of the ref.
|
|
680
|
+
*
|
|
681
|
+
* @returns The ref with a matching label, if it exists.
|
|
682
|
+
*/
|
|
683
|
+
async getRefByLabel(label, params) {
|
|
684
|
+
const refs = await this.getRefs(params);
|
|
685
|
+
return findRefByLabel.findRefByLabel(refs, label);
|
|
686
|
+
}
|
|
687
|
+
/**
|
|
688
|
+
* Returns the master ref for the Prismic repository. The master ref points to
|
|
689
|
+
* the repository's latest published content.
|
|
690
|
+
*
|
|
691
|
+
* @returns The repository's master ref.
|
|
692
|
+
*/
|
|
693
|
+
async getMasterRef(params) {
|
|
694
|
+
const refs = await this.getRefs(params);
|
|
695
|
+
return findMasterRef.findMasterRef(refs);
|
|
696
|
+
}
|
|
697
|
+
/**
|
|
698
|
+
* Returns a list of all Releases for the Prismic repository. Releases are
|
|
699
|
+
* used to group content changes before publishing.
|
|
700
|
+
*
|
|
701
|
+
* @returns A list of all Releases for the Prismic repository.
|
|
702
|
+
*/
|
|
703
|
+
async getReleases(params) {
|
|
704
|
+
const refs = await this.getRefs(params);
|
|
705
|
+
return refs.filter((ref) => !ref.isMasterRef);
|
|
706
|
+
}
|
|
707
|
+
/**
|
|
708
|
+
* Returns a Release for the Prismic repository with a matching ID.
|
|
709
|
+
*
|
|
710
|
+
* @param id - ID of the Release.
|
|
711
|
+
*
|
|
712
|
+
* @returns The Release with a matching ID, if it exists.
|
|
713
|
+
*/
|
|
714
|
+
async getReleaseByID(id, params) {
|
|
715
|
+
const releases = await this.getReleases(params);
|
|
716
|
+
return findRefByID.findRefByID(releases, id);
|
|
717
|
+
}
|
|
718
|
+
/**
|
|
719
|
+
* Returns a Release for the Prismic repository with a matching label.
|
|
720
|
+
*
|
|
721
|
+
* @param label - Label of the ref.
|
|
722
|
+
*
|
|
723
|
+
* @returns The ref with a matching label, if it exists.
|
|
724
|
+
*/
|
|
725
|
+
async getReleaseByLabel(label, params) {
|
|
726
|
+
const releases = await this.getReleases(params);
|
|
727
|
+
return findRefByLabel.findRefByLabel(releases, label);
|
|
728
|
+
}
|
|
729
|
+
/**
|
|
730
|
+
* Returns a list of all tags used in the Prismic repository.
|
|
731
|
+
*
|
|
732
|
+
* @returns A list of all tags used in the repository.
|
|
733
|
+
*/
|
|
734
|
+
async getTags(params) {
|
|
735
|
+
try {
|
|
736
|
+
const tagsForm = await this.getCachedRepositoryForm("tags", params);
|
|
737
|
+
const url = new URL(tagsForm.action);
|
|
738
|
+
if (this.accessToken) {
|
|
739
|
+
url.searchParams.set("access_token", this.accessToken);
|
|
740
|
+
}
|
|
741
|
+
return await this.fetch(url.toString(), params);
|
|
742
|
+
} catch {
|
|
743
|
+
const repository = await this.getRepository(params);
|
|
744
|
+
return repository.tags;
|
|
745
|
+
}
|
|
746
|
+
}
|
|
747
|
+
/**
|
|
748
|
+
* Builds a URL used to query content from the Prismic repository.
|
|
749
|
+
*
|
|
750
|
+
* @param params - Parameters to filter, sort, and paginate the results.
|
|
751
|
+
*
|
|
752
|
+
* @returns A URL string that can be requested to query content.
|
|
753
|
+
*/
|
|
754
|
+
async buildQueryURL({ signal, fetchOptions, ...params } = {}) {
|
|
755
|
+
const ref = params.ref || await this.getResolvedRefString({ signal, fetchOptions });
|
|
756
|
+
const integrationFieldsRef = params.integrationFieldsRef || (await this.getCachedRepository({ signal, fetchOptions })).integrationFieldsRef || void 0;
|
|
757
|
+
return buildQueryURL.buildQueryURL(this.endpoint, {
|
|
758
|
+
...this.defaultParams,
|
|
759
|
+
...params,
|
|
760
|
+
ref,
|
|
761
|
+
integrationFieldsRef,
|
|
762
|
+
routes: params.routes || this.routes,
|
|
763
|
+
brokenRoute: params.brokenRoute || this.brokenRoute,
|
|
764
|
+
accessToken: params.accessToken || this.accessToken
|
|
765
|
+
});
|
|
766
|
+
}
|
|
767
|
+
/**
|
|
768
|
+
* Determines the URL for a previewed document during an active preview
|
|
769
|
+
* session. The result of this method should be used to redirect the user to
|
|
770
|
+
* the document's URL.
|
|
771
|
+
*
|
|
772
|
+
* @example
|
|
773
|
+
*
|
|
774
|
+
* ```ts
|
|
775
|
+
* const url = client.resolvePreviewURL({
|
|
776
|
+
* linkResolver: (document) => `/${document.uid}`
|
|
777
|
+
* defaultURL: '/'
|
|
778
|
+
* })
|
|
779
|
+
* ```
|
|
780
|
+
*
|
|
781
|
+
* @param args - Arguments to configure the URL resolving.
|
|
782
|
+
*
|
|
783
|
+
* @returns The URL for the previewed document during an active preview
|
|
784
|
+
* session. The user should be redirected to this URL.
|
|
785
|
+
*/
|
|
786
|
+
async resolvePreviewURL(args) {
|
|
787
|
+
var _a, _b;
|
|
788
|
+
let documentID = args.documentID;
|
|
789
|
+
let previewToken = args.previewToken;
|
|
790
|
+
if (typeof globalThis.location !== "undefined") {
|
|
791
|
+
const searchParams = new URLSearchParams(globalThis.location.search);
|
|
792
|
+
documentID = documentID || searchParams.get("documentId");
|
|
793
|
+
previewToken = previewToken || searchParams.get("token");
|
|
794
|
+
} else if (this.refState.httpRequest) {
|
|
795
|
+
if ("query" in this.refState.httpRequest) {
|
|
796
|
+
documentID = documentID || ((_a = this.refState.httpRequest.query) == null ? void 0 : _a.documentId);
|
|
797
|
+
previewToken = previewToken || ((_b = this.refState.httpRequest.query) == null ? void 0 : _b.token);
|
|
798
|
+
} else if ("url" in this.refState.httpRequest && this.refState.httpRequest.url) {
|
|
799
|
+
const searchParams = new URL(this.refState.httpRequest.url, "missing-host://").searchParams;
|
|
800
|
+
documentID = documentID || searchParams.get("documentId");
|
|
801
|
+
previewToken = previewToken || searchParams.get("token");
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
if (documentID != null && previewToken != null) {
|
|
805
|
+
const document = await this.getByID(documentID, {
|
|
806
|
+
ref: previewToken,
|
|
807
|
+
lang: "*",
|
|
808
|
+
signal: args.signal,
|
|
809
|
+
fetchOptions: args.fetchOptions
|
|
810
|
+
});
|
|
811
|
+
const url = asLink.asLink(document, { linkResolver: args.linkResolver });
|
|
812
|
+
if (typeof url === "string") {
|
|
813
|
+
return url;
|
|
814
|
+
}
|
|
815
|
+
}
|
|
816
|
+
return args.defaultURL;
|
|
817
|
+
}
|
|
818
|
+
/**
|
|
819
|
+
* Configures the client to query the latest published content for all future
|
|
820
|
+
* queries.
|
|
821
|
+
*
|
|
822
|
+
* If the `ref` parameter is provided during a query, it takes priority for
|
|
823
|
+
* that query.
|
|
824
|
+
*
|
|
825
|
+
* @example
|
|
826
|
+
*
|
|
827
|
+
* ```ts
|
|
828
|
+
* await client.queryLatestContent();
|
|
829
|
+
* const document = await client.getByID("WW4bKScAAMAqmluX");
|
|
830
|
+
* ```
|
|
831
|
+
*/
|
|
832
|
+
queryLatestContent() {
|
|
833
|
+
this.refState.mode = RefStateMode.Master;
|
|
834
|
+
}
|
|
835
|
+
/**
|
|
836
|
+
* Configures the client to query content from a specific Release identified
|
|
837
|
+
* by its ID for all future queries.
|
|
838
|
+
*
|
|
839
|
+
* If the `ref` parameter is provided during a query, it takes priority for
|
|
840
|
+
* that query.
|
|
841
|
+
*
|
|
842
|
+
* @example
|
|
843
|
+
*
|
|
844
|
+
* ```ts
|
|
845
|
+
* await client.queryContentFromReleaseByID("YLB7OBAAACMA7Cpa");
|
|
846
|
+
* const document = await client.getByID("WW4bKScAAMAqmluX");
|
|
847
|
+
* ```
|
|
848
|
+
*
|
|
849
|
+
* @param releaseID - The ID of the Release.
|
|
850
|
+
*/
|
|
851
|
+
queryContentFromReleaseByID(releaseID) {
|
|
852
|
+
this.refState = {
|
|
853
|
+
...this.refState,
|
|
854
|
+
mode: RefStateMode.ReleaseID,
|
|
855
|
+
releaseID
|
|
856
|
+
};
|
|
857
|
+
}
|
|
858
|
+
/**
|
|
859
|
+
* Configures the client to query content from a specific Release identified
|
|
860
|
+
* by its label for all future queries.
|
|
861
|
+
*
|
|
862
|
+
* If the `ref` parameter is provided during a query, it takes priority for
|
|
863
|
+
* that query.
|
|
864
|
+
*
|
|
865
|
+
* @example
|
|
866
|
+
*
|
|
867
|
+
* ```ts
|
|
868
|
+
* await client.queryContentFromReleaseByLabel("My Release");
|
|
869
|
+
* const document = await client.getByID("WW4bKScAAMAqmluX");
|
|
870
|
+
* ```
|
|
871
|
+
*
|
|
872
|
+
* @param releaseLabel - The label of the Release.
|
|
873
|
+
*/
|
|
874
|
+
queryContentFromReleaseByLabel(releaseLabel) {
|
|
875
|
+
this.refState = {
|
|
876
|
+
...this.refState,
|
|
877
|
+
mode: RefStateMode.ReleaseLabel,
|
|
878
|
+
releaseLabel
|
|
879
|
+
};
|
|
880
|
+
}
|
|
881
|
+
/**
|
|
882
|
+
* Configures the client to query content from a specific ref. The ref can be
|
|
883
|
+
* provided as a string or a function.
|
|
884
|
+
*
|
|
885
|
+
* If a function is provided, the ref is fetched lazily before each query. The
|
|
886
|
+
* function may also be asynchronous.
|
|
887
|
+
*
|
|
888
|
+
* @example
|
|
889
|
+
*
|
|
890
|
+
* ```ts
|
|
891
|
+
* await client.queryContentFromRef("my-ref");
|
|
892
|
+
* const document = await client.getByID("WW4bKScAAMAqmluX");
|
|
893
|
+
* ```
|
|
894
|
+
*
|
|
895
|
+
* @param ref - The ref or a function that returns the ref from which to query
|
|
896
|
+
* content.
|
|
897
|
+
*/
|
|
898
|
+
queryContentFromRef(ref) {
|
|
899
|
+
this.refState = {
|
|
900
|
+
...this.refState,
|
|
901
|
+
mode: RefStateMode.Manual,
|
|
902
|
+
ref
|
|
903
|
+
};
|
|
904
|
+
}
|
|
905
|
+
/**
|
|
906
|
+
* A `fetch()` function to be used with GraphQL clients configured for
|
|
907
|
+
* Prismic's GraphQL API. It automatically applies the necessary `prismic-ref`
|
|
908
|
+
* and Authorization headers. Queries will automatically be minified by
|
|
909
|
+
* removing whitespace where possible.
|
|
910
|
+
*
|
|
911
|
+
* @example
|
|
912
|
+
*
|
|
913
|
+
* ```ts
|
|
914
|
+
* const graphQLClient = new ApolloClient({
|
|
915
|
+
* link: new HttpLink({
|
|
916
|
+
* uri: prismic.getGraphQLEndpoint(repositoryName),
|
|
917
|
+
* // Provide `client.graphQLFetch` as the fetch implementation.
|
|
918
|
+
* fetch: client.graphQLFetch,
|
|
919
|
+
* // Using GET is required.
|
|
920
|
+
* useGETForQueries: true,
|
|
921
|
+
* }),
|
|
922
|
+
* cache: new InMemoryCache(),
|
|
923
|
+
* });
|
|
924
|
+
* ```
|
|
925
|
+
*
|
|
926
|
+
* @param input - The `fetch()` `input` parameter. Only strings are supported.
|
|
927
|
+
* @param init - The `fetch()` `init` parameter. Only plain objects are
|
|
928
|
+
* supported.
|
|
929
|
+
*
|
|
930
|
+
* @returns The `fetch()` Response for the request.
|
|
931
|
+
*
|
|
932
|
+
* @experimental
|
|
933
|
+
*/
|
|
934
|
+
async graphQLFetch(input, init) {
|
|
935
|
+
const cachedRepository = await this.getCachedRepository();
|
|
936
|
+
const ref = await this.getResolvedRefString();
|
|
937
|
+
const unsanitizedHeaders = {
|
|
938
|
+
"Prismic-ref": ref,
|
|
939
|
+
Authorization: this.accessToken ? `Token ${this.accessToken}` : "",
|
|
940
|
+
// Asserting `init.headers` is a Record since popular GraphQL
|
|
941
|
+
// libraries pass this as a Record. Header objects as input
|
|
942
|
+
// are unsupported.
|
|
943
|
+
...init ? init.headers : {}
|
|
944
|
+
};
|
|
945
|
+
if (cachedRepository.integrationFieldsRef) {
|
|
946
|
+
unsanitizedHeaders["Prismic-integration-field-ref"] = cachedRepository.integrationFieldsRef;
|
|
947
|
+
}
|
|
948
|
+
const headers = {};
|
|
949
|
+
for (const key in unsanitizedHeaders) {
|
|
950
|
+
if (unsanitizedHeaders[key]) {
|
|
951
|
+
headers[key.toLowerCase()] = unsanitizedHeaders[key];
|
|
952
|
+
}
|
|
953
|
+
}
|
|
954
|
+
const url = new URL(
|
|
955
|
+
// Asserting `input` is a string since popular GraphQL
|
|
956
|
+
// libraries pass this as a string. Request objects as
|
|
957
|
+
// input are unsupported.
|
|
958
|
+
input
|
|
959
|
+
);
|
|
960
|
+
url.searchParams.set("ref", ref);
|
|
961
|
+
const query = url.searchParams.get("query");
|
|
962
|
+
if (query) {
|
|
963
|
+
url.searchParams.set(
|
|
964
|
+
"query",
|
|
965
|
+
// Compress the GraphQL query (if it exists) by
|
|
966
|
+
// removing whitespace. This is done to
|
|
967
|
+
// optimize the query size and avoid
|
|
968
|
+
// hitting the upper limit of GET requests
|
|
969
|
+
// (2048 characters).
|
|
970
|
+
minifyGraphQLQuery.minifyGraphQLQuery(query)
|
|
971
|
+
);
|
|
972
|
+
}
|
|
973
|
+
return await this.fetchFn(url.toString(), {
|
|
974
|
+
...init,
|
|
975
|
+
headers
|
|
976
|
+
});
|
|
977
|
+
}
|
|
978
|
+
/**
|
|
979
|
+
* Returns a cached version of `getRepository` with a TTL.
|
|
980
|
+
*
|
|
981
|
+
* @returns Cached repository metadata.
|
|
982
|
+
*/
|
|
983
|
+
async getCachedRepository(params) {
|
|
984
|
+
if (!this.cachedRepository || Date.now() >= this.cachedRepositoryExpiration) {
|
|
985
|
+
this.cachedRepositoryExpiration = Date.now() + REPOSITORY_CACHE_TTL;
|
|
986
|
+
this.cachedRepository = await this.getRepository(params);
|
|
987
|
+
}
|
|
988
|
+
return this.cachedRepository;
|
|
989
|
+
}
|
|
990
|
+
/**
|
|
991
|
+
* Returns a cached Prismic repository form. Forms are used to determine API
|
|
992
|
+
* endpoints for types of repository data.
|
|
993
|
+
*
|
|
994
|
+
* @param name - Name of the form.
|
|
995
|
+
*
|
|
996
|
+
* @returns The repository form.
|
|
997
|
+
*
|
|
998
|
+
* @throws If a matching form cannot be found.
|
|
999
|
+
*/
|
|
1000
|
+
async getCachedRepositoryForm(name, params) {
|
|
1001
|
+
const cachedRepository = await this.getCachedRepository(params);
|
|
1002
|
+
const form = cachedRepository.forms[name];
|
|
1003
|
+
if (!form) {
|
|
1004
|
+
throw new PrismicError.PrismicError(`Form with name "${name}" could not be found`, void 0, void 0);
|
|
1005
|
+
}
|
|
1006
|
+
return form;
|
|
1007
|
+
}
|
|
1008
|
+
/**
|
|
1009
|
+
* Returns the ref needed to query based on the client's current state. This
|
|
1010
|
+
* method may make a network request to fetch a ref or resolve the user's ref
|
|
1011
|
+
* thunk.
|
|
1012
|
+
*
|
|
1013
|
+
* If auto previews are enabled, the preview ref takes priority if available.
|
|
1014
|
+
*
|
|
1015
|
+
* The following strategies are used depending on the client's state:
|
|
1016
|
+
*
|
|
1017
|
+
* - If the user called `queryLatestContent`: Use the repository's master ref.
|
|
1018
|
+
* The ref is cached for 5 seconds. After 5 seconds, a new master ref is
|
|
1019
|
+
* fetched.
|
|
1020
|
+
* - If the user called `queryContentFromReleaseByID`: Use the release's ref.
|
|
1021
|
+
* The ref is cached for 5 seconds. After 5 seconds, a new ref for the
|
|
1022
|
+
* release is fetched.
|
|
1023
|
+
* - If the user called `queryContentFromReleaseByLabel`: Use the release's ref.
|
|
1024
|
+
* The ref is cached for 5 seconds. After 5 seconds, a new ref for the
|
|
1025
|
+
* release is fetched.
|
|
1026
|
+
* - If the user called `queryContentFromRef`: Use the provided ref. Fall back
|
|
1027
|
+
* to the master ref if the ref is not a string.
|
|
1028
|
+
*
|
|
1029
|
+
* @returns The ref to use during a query.
|
|
1030
|
+
*/
|
|
1031
|
+
async getResolvedRefString(params) {
|
|
1032
|
+
var _a, _b;
|
|
1033
|
+
if (this.refState.autoPreviewsEnabled) {
|
|
1034
|
+
let previewRef;
|
|
1035
|
+
let cookieJar;
|
|
1036
|
+
if ((_a = this.refState.httpRequest) == null ? void 0 : _a.headers) {
|
|
1037
|
+
if ("get" in this.refState.httpRequest.headers && typeof this.refState.httpRequest.headers.get === "function") {
|
|
1038
|
+
cookieJar = this.refState.httpRequest.headers.get("cookie");
|
|
1039
|
+
} else if ("cookie" in this.refState.httpRequest.headers) {
|
|
1040
|
+
cookieJar = this.refState.httpRequest.headers.cookie;
|
|
1041
|
+
}
|
|
1042
|
+
} else if ((_b = globalThis.document) == null ? void 0 : _b.cookie) {
|
|
1043
|
+
cookieJar = globalThis.document.cookie;
|
|
1044
|
+
}
|
|
1045
|
+
if (cookieJar) {
|
|
1046
|
+
previewRef = getPreviewCookie.getPreviewCookie(cookieJar);
|
|
1047
|
+
}
|
|
1048
|
+
if (previewRef) {
|
|
1049
|
+
return previewRef;
|
|
1050
|
+
}
|
|
1051
|
+
}
|
|
1052
|
+
const cachedRepository = await this.getCachedRepository(params);
|
|
1053
|
+
const refModeType = this.refState.mode;
|
|
1054
|
+
if (refModeType === RefStateMode.ReleaseID) {
|
|
1055
|
+
return findRefByID.findRefByID(cachedRepository.refs, this.refState.releaseID).ref;
|
|
1056
|
+
} else if (refModeType === RefStateMode.ReleaseLabel) {
|
|
1057
|
+
return findRefByLabel.findRefByLabel(cachedRepository.refs, this.refState.releaseLabel).ref;
|
|
1058
|
+
} else if (refModeType === RefStateMode.Manual) {
|
|
1059
|
+
const res = await castThunk.castThunk(this.refState.ref)();
|
|
1060
|
+
if (typeof res === "string") {
|
|
1061
|
+
return res;
|
|
1062
|
+
}
|
|
1063
|
+
}
|
|
1064
|
+
return findMasterRef.findMasterRef(cachedRepository.refs).ref;
|
|
1065
|
+
}
|
|
1066
|
+
/**
|
|
1067
|
+
* Performs a network request using the configured `fetch` function. It
|
|
1068
|
+
* assumes all successful responses will have a JSON content type. It also
|
|
1069
|
+
* normalizes unsuccessful network requests.
|
|
1070
|
+
*
|
|
1071
|
+
* @typeParam T - The JSON response.
|
|
1072
|
+
*
|
|
1073
|
+
* @param url - URL to the resource to fetch.
|
|
1074
|
+
* @param params - Prismic REST API parameters for the network request.
|
|
1075
|
+
*
|
|
1076
|
+
* @returns The JSON response from the network request.
|
|
1077
|
+
*/
|
|
1078
|
+
async fetch(url, params = {}) {
|
|
1079
|
+
var _a, _b, _c, _d;
|
|
1080
|
+
const requestInit = {
|
|
1081
|
+
...this.fetchOptions,
|
|
1082
|
+
...params.fetchOptions,
|
|
1083
|
+
headers: {
|
|
1084
|
+
...(_a = this.fetchOptions) == null ? void 0 : _a.headers,
|
|
1085
|
+
...(_b = params.fetchOptions) == null ? void 0 : _b.headers
|
|
1086
|
+
},
|
|
1087
|
+
signal: ((_c = params.fetchOptions) == null ? void 0 : _c.signal) || params.signal || ((_d = this.fetchOptions) == null ? void 0 : _d.signal)
|
|
1088
|
+
};
|
|
1089
|
+
let job;
|
|
1090
|
+
if (this.fetchJobs[url] && this.fetchJobs[url].has(requestInit.signal)) {
|
|
1091
|
+
job = this.fetchJobs[url].get(requestInit.signal);
|
|
1092
|
+
} else {
|
|
1093
|
+
this.fetchJobs[url] = this.fetchJobs[url] || /* @__PURE__ */ new Map();
|
|
1094
|
+
job = this.fetchFn(url, requestInit).then(async (res2) => {
|
|
1095
|
+
let json = void 0;
|
|
1096
|
+
try {
|
|
1097
|
+
json = await res2.json();
|
|
1098
|
+
} catch {
|
|
1099
|
+
}
|
|
1100
|
+
return {
|
|
1101
|
+
status: res2.status,
|
|
1102
|
+
json
|
|
1103
|
+
};
|
|
1104
|
+
}).finally(() => {
|
|
1105
|
+
this.fetchJobs[url].delete(requestInit.signal);
|
|
1106
|
+
if (this.fetchJobs[url].size === 0) {
|
|
1107
|
+
delete this.fetchJobs[url];
|
|
1108
|
+
}
|
|
1109
|
+
});
|
|
1110
|
+
this.fetchJobs[url].set(requestInit.signal, job);
|
|
1111
|
+
}
|
|
1112
|
+
const res = await job;
|
|
1113
|
+
if (res.status !== 404 && res.json == null) {
|
|
1114
|
+
throw new PrismicError.PrismicError(void 0, url, res.json);
|
|
1115
|
+
}
|
|
1116
|
+
switch (res.status) {
|
|
1117
|
+
case 200: {
|
|
1118
|
+
return res.json;
|
|
1119
|
+
}
|
|
1120
|
+
case 400: {
|
|
1121
|
+
throw new ParsingError.ParsingError(res.json.message, url, res.json);
|
|
1122
|
+
}
|
|
1123
|
+
case 401:
|
|
1124
|
+
case 403: {
|
|
1125
|
+
throw new ForbiddenError.ForbiddenError("error" in res.json ? res.json.error : res.json.message, url, res.json);
|
|
1126
|
+
}
|
|
1127
|
+
case 404: {
|
|
1128
|
+
throw new NotFoundError.NotFoundError(`Prismic repository not found. Check that "${this.endpoint}" is pointing to the correct repository.`, url, void 0);
|
|
1129
|
+
}
|
|
1130
|
+
}
|
|
1131
|
+
throw new PrismicError.PrismicError(void 0, url, res.json);
|
|
1132
|
+
}
|
|
1133
|
+
}
|
|
1134
|
+
exports.Client = Client;
|
|
1135
|
+
exports.GET_ALL_QUERY_DELAY = GET_ALL_QUERY_DELAY;
|
|
1136
|
+
exports.REPOSITORY_CACHE_TTL = REPOSITORY_CACHE_TTL;
|
|
1137
|
+
exports.createClient = createClient;
|
|
1138
|
+
//# sourceMappingURL=createClient.cjs.map
|