@prismicio/client 7.0.0-alpha.1 → 7.0.0-alpha.3

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.
@@ -136,7 +136,7 @@ export type ClientConfig = {
136
136
  * Node.js, this function must be provided.
137
137
  */
138
138
  fetch?: FetchLike;
139
- };
139
+ } & OptimizeParams;
140
140
  /**
141
141
  * Parameters for any client method that use `fetch()`. Only a subset of
142
142
  * `fetch()` parameters are exposed.
@@ -150,6 +150,34 @@ type FetchParams = {
150
150
  */
151
151
  signal?: AbortSignalLike;
152
152
  };
153
+ /**
154
+ * Parameters that determine if or how the client is optimized.
155
+ */
156
+ type OptimizeParams = {
157
+ /**
158
+ * Options that determine if or how the client is optimized.
159
+ */
160
+ optimize?: {
161
+ /**
162
+ * Determines if fetching repository metadata should be optimized. The
163
+ * optimizations result in faster queries, less network requests, and more
164
+ * accurate cache-busting.
165
+ *
166
+ * Only opt out of this optimization if you know what you are doing.
167
+ *
168
+ * @defaultValue `true`
169
+ */
170
+ repositoryRequests?: boolean;
171
+ /**
172
+ * Determines if concurrent requests to the same URL should be optimized. The optimizations result in less network requests and quicker responses.
173
+ *
174
+ * Only opt out of this optimization if you know what you are doing.
175
+ *
176
+ * @defaultValue `true`
177
+ */
178
+ concurrentRequests?: boolean;
179
+ };
180
+ };
153
181
  /**
154
182
  * Parameters specific to client methods that fetch all documents. These methods
155
183
  * start with `getAll` (for example, `getAllByType`).
@@ -263,6 +291,10 @@ export declare class Client<TDocuments extends PrismicDocument = PrismicDocument
263
291
  * be overridden on each query if needed.
264
292
  */
265
293
  defaultParams?: Omit<BuildQueryURLArgs, "ref" | "integrationFieldsRef" | "accessToken" | "routes">;
294
+ /**
295
+ * Options that determine if or how the client is optimized.
296
+ */
297
+ optimize: NonNullable<OptimizeParams["optimize"]>;
266
298
  /**
267
299
  * The client's ref mode state. This determines which ref is used during
268
300
  * queries.
@@ -359,7 +391,7 @@ export declare class Client<TDocuments extends PrismicDocument = PrismicDocument
359
391
  *
360
392
  * @returns A paginated response containing the result of the query.
361
393
  */
362
- get<TDocument extends TDocuments>(params?: Partial<BuildQueryURLArgs> & FetchParams): Promise<Query<TDocument>>;
394
+ get<TDocument extends TDocuments>(params?: Partial<BuildQueryURLArgs> & FetchParams & OptimizeParams): Promise<Query<TDocument>>;
363
395
  /**
364
396
  * Queries content from the Prismic repository and returns only the first
365
397
  * result, if any.
@@ -374,7 +406,7 @@ export declare class Client<TDocuments extends PrismicDocument = PrismicDocument
374
406
  * @param params - Parameters to filter, sort, and paginate results. @returns
375
407
  * The first result of the query, if any.
376
408
  */
377
- getFirst<TDocument extends TDocuments>(params?: Partial<BuildQueryURLArgs> & FetchParams): Promise<TDocument>;
409
+ getFirst<TDocument extends TDocuments>(params?: Partial<BuildQueryURLArgs> & FetchParams & OptimizeParams): Promise<TDocument>;
378
410
  /**
379
411
  * **IMPORTANT**: Avoid using `dangerouslyGetAll` as it may be slower and
380
412
  * require more resources than other methods. Prefer using other methods that
@@ -397,7 +429,7 @@ export declare class Client<TDocuments extends PrismicDocument = PrismicDocument
397
429
  *
398
430
  * @returns A list of documents matching the query.
399
431
  */
400
- dangerouslyGetAll<TDocument extends TDocuments>(params?: Partial<Omit<BuildQueryURLArgs, "page">> & GetAllParams & FetchParams): Promise<TDocument[]>;
432
+ dangerouslyGetAll<TDocument extends TDocuments>(params?: Partial<Omit<BuildQueryURLArgs, "page">> & GetAllParams & FetchParams & OptimizeParams): Promise<TDocument[]>;
401
433
  /**
402
434
  * Queries a document from the Prismic repository with a specific ID.
403
435
  *
@@ -419,7 +451,7 @@ export declare class Client<TDocuments extends PrismicDocument = PrismicDocument
419
451
  * @returns The document with an ID matching the `id` parameter, if a matching
420
452
  * document exists.
421
453
  */
422
- getByID<TDocument extends TDocuments>(id: string, params?: Partial<BuildQueryURLArgs> & FetchParams): Promise<TDocument>;
454
+ getByID<TDocument extends TDocuments>(id: string, params?: Partial<BuildQueryURLArgs> & FetchParams & OptimizeParams): Promise<TDocument>;
423
455
  /**
424
456
  * Queries documents from the Prismic repository with specific IDs.
425
457
  *
@@ -444,7 +476,7 @@ export declare class Client<TDocuments extends PrismicDocument = PrismicDocument
444
476
  * @returns A paginated response containing documents with IDs matching the
445
477
  * `ids` parameter.
446
478
  */
447
- getByIDs<TDocument extends TDocuments>(ids: string[], params?: Partial<BuildQueryURLArgs> & FetchParams): Promise<Query<TDocument>>;
479
+ getByIDs<TDocument extends TDocuments>(ids: string[], params?: Partial<BuildQueryURLArgs> & FetchParams & OptimizeParams): Promise<Query<TDocument>>;
448
480
  /**
449
481
  * Queries all documents from the Prismic repository with specific IDs.
450
482
  *
@@ -471,7 +503,7 @@ export declare class Client<TDocuments extends PrismicDocument = PrismicDocument
471
503
  *
472
504
  * @returns A list of documents with IDs matching the `ids` parameter.
473
505
  */
474
- getAllByIDs<TDocument extends TDocuments>(ids: string[], params?: Partial<BuildQueryURLArgs> & GetAllParams & FetchParams): Promise<TDocument[]>;
506
+ getAllByIDs<TDocument extends TDocuments>(ids: string[], params?: Partial<BuildQueryURLArgs> & GetAllParams & FetchParams & OptimizeParams): Promise<TDocument[]>;
475
507
  /**
476
508
  * Queries a document from the Prismic repository with a specific UID and
477
509
  * Custom Type.
@@ -495,7 +527,7 @@ export declare class Client<TDocuments extends PrismicDocument = PrismicDocument
495
527
  * @returns The document with a UID matching the `uid` parameter, if a
496
528
  * matching document exists.
497
529
  */
498
- getByUID<TDocument extends TDocuments, TDocumentType extends TDocument["type"] = TDocument["type"]>(documentType: TDocumentType, uid: string, params?: Partial<BuildQueryURLArgs> & FetchParams): Promise<ExtractDocumentType<TDocument, TDocumentType>>;
530
+ getByUID<TDocument extends TDocuments, TDocumentType extends TDocument["type"] = TDocument["type"]>(documentType: TDocumentType, uid: string, params?: Partial<BuildQueryURLArgs> & FetchParams & OptimizeParams): Promise<ExtractDocumentType<TDocument, TDocumentType>>;
499
531
  /**
500
532
  * Queries document from the Prismic repository with specific UIDs and Custom
501
533
  * Type.
@@ -522,7 +554,7 @@ export declare class Client<TDocuments extends PrismicDocument = PrismicDocument
522
554
  * @returns A paginated response containing documents with UIDs matching the
523
555
  * `uids` parameter.
524
556
  */
525
- getByUIDs<TDocument extends TDocuments, TDocumentType extends TDocument["type"] = TDocument["type"]>(documentType: TDocumentType, uids: string[], params?: Partial<BuildQueryURLArgs> & FetchParams): Promise<Query<ExtractDocumentType<TDocument, TDocumentType>>>;
557
+ getByUIDs<TDocument extends TDocuments, TDocumentType extends TDocument["type"] = TDocument["type"]>(documentType: TDocumentType, uids: string[], params?: Partial<BuildQueryURLArgs> & FetchParams & OptimizeParams): Promise<Query<ExtractDocumentType<TDocument, TDocumentType>>>;
526
558
  /**
527
559
  * Queries all documents from the Prismic repository with specific UIDs and
528
560
  * Custom Type.
@@ -551,7 +583,7 @@ export declare class Client<TDocuments extends PrismicDocument = PrismicDocument
551
583
  *
552
584
  * @returns A list of documents with UIDs matching the `uids` parameter.
553
585
  */
554
- getAllByUIDs<TDocument extends TDocuments, TDocumentType extends TDocument["type"] = TDocument["type"]>(documentType: TDocumentType, uids: string[], params?: Partial<BuildQueryURLArgs> & GetAllParams & FetchParams): Promise<ExtractDocumentType<TDocument, TDocumentType>[]>;
586
+ getAllByUIDs<TDocument extends TDocuments, TDocumentType extends TDocument["type"] = TDocument["type"]>(documentType: TDocumentType, uids: string[], params?: Partial<BuildQueryURLArgs> & GetAllParams & FetchParams & OptimizeParams): Promise<ExtractDocumentType<TDocument, TDocumentType>[]>;
555
587
  /**
556
588
  * Queries a singleton document from the Prismic repository for a specific
557
589
  * Custom Type.
@@ -574,7 +606,7 @@ export declare class Client<TDocuments extends PrismicDocument = PrismicDocument
574
606
  * @returns The singleton document for the Custom Type, if a matching document
575
607
  * exists.
576
608
  */
577
- getSingle<TDocument extends TDocuments, TDocumentType extends TDocument["type"] = TDocument["type"]>(documentType: TDocumentType, params?: Partial<BuildQueryURLArgs> & FetchParams): Promise<ExtractDocumentType<TDocument, TDocumentType>>;
609
+ getSingle<TDocument extends TDocuments, TDocumentType extends TDocument["type"] = TDocument["type"]>(documentType: TDocumentType, params?: Partial<BuildQueryURLArgs> & FetchParams & OptimizeParams): Promise<ExtractDocumentType<TDocument, TDocumentType>>;
578
610
  /**
579
611
  * Queries documents from the Prismic repository for a specific Custom Type.
580
612
  *
@@ -593,7 +625,7 @@ export declare class Client<TDocuments extends PrismicDocument = PrismicDocument
593
625
  *
594
626
  * @returns A paginated response containing documents of the Custom Type.
595
627
  */
596
- getByType<TDocument extends TDocuments, TDocumentType extends TDocument["type"] = TDocument["type"]>(documentType: TDocumentType, params?: Partial<BuildQueryURLArgs> & FetchParams): Promise<Query<ExtractDocumentType<TDocument, TDocumentType>>>;
628
+ getByType<TDocument extends TDocuments, TDocumentType extends TDocument["type"] = TDocument["type"]>(documentType: TDocumentType, params?: Partial<BuildQueryURLArgs> & FetchParams & OptimizeParams): Promise<Query<ExtractDocumentType<TDocument, TDocumentType>>>;
597
629
  /**
598
630
  * Queries all documents from the Prismic repository for a specific Custom
599
631
  * Type.
@@ -613,7 +645,7 @@ export declare class Client<TDocuments extends PrismicDocument = PrismicDocument
613
645
  *
614
646
  * @returns A list of all documents of the Custom Type.
615
647
  */
616
- getAllByType<TDocument extends TDocuments, TDocumentType extends TDocument["type"] = TDocument["type"]>(documentType: TDocumentType, params?: Partial<Omit<BuildQueryURLArgs, "page">> & GetAllParams & FetchParams): Promise<ExtractDocumentType<TDocument, TDocumentType>[]>;
648
+ getAllByType<TDocument extends TDocuments, TDocumentType extends TDocument["type"] = TDocument["type"]>(documentType: TDocumentType, params?: Partial<Omit<BuildQueryURLArgs, "page">> & GetAllParams & FetchParams & OptimizeParams): Promise<ExtractDocumentType<TDocument, TDocumentType>[]>;
617
649
  /**
618
650
  * Queries documents from the Prismic repository with a specific tag.
619
651
  *
@@ -632,7 +664,7 @@ export declare class Client<TDocuments extends PrismicDocument = PrismicDocument
632
664
  *
633
665
  * @returns A paginated response containing documents with the tag.
634
666
  */
635
- getByTag<TDocument extends TDocuments>(tag: string, params?: Partial<BuildQueryURLArgs> & FetchParams): Promise<Query<TDocument>>;
667
+ getByTag<TDocument extends TDocuments>(tag: string, params?: Partial<BuildQueryURLArgs> & FetchParams & OptimizeParams): Promise<Query<TDocument>>;
636
668
  /**
637
669
  * Queries all documents from the Prismic repository with a specific tag.
638
670
  *
@@ -651,7 +683,7 @@ export declare class Client<TDocuments extends PrismicDocument = PrismicDocument
651
683
  *
652
684
  * @returns A list of all documents with the tag.
653
685
  */
654
- getAllByTag<TDocument extends TDocuments>(tag: string, params?: Partial<Omit<BuildQueryURLArgs, "page">> & GetAllParams & FetchParams): Promise<TDocument[]>;
686
+ getAllByTag<TDocument extends TDocuments>(tag: string, params?: Partial<Omit<BuildQueryURLArgs, "page">> & GetAllParams & FetchParams & OptimizeParams): Promise<TDocument[]>;
655
687
  /**
656
688
  * Queries documents from the Prismic repository with specific tags. A
657
689
  * document must be tagged with all of the queried tags to be included.
@@ -668,7 +700,7 @@ export declare class Client<TDocuments extends PrismicDocument = PrismicDocument
668
700
  *
669
701
  * @returns A paginated response containing documents with the tags.
670
702
  */
671
- getByEveryTag<TDocument extends TDocuments>(tags: string[], params?: Partial<BuildQueryURLArgs> & FetchParams): Promise<Query<TDocument>>;
703
+ getByEveryTag<TDocument extends TDocuments>(tags: string[], params?: Partial<BuildQueryURLArgs> & FetchParams & OptimizeParams): Promise<Query<TDocument>>;
672
704
  /**
673
705
  * Queries documents from the Prismic repository with specific tags. A
674
706
  * document must be tagged with all of the queried tags to be included.
@@ -688,7 +720,7 @@ export declare class Client<TDocuments extends PrismicDocument = PrismicDocument
688
720
  *
689
721
  * @returns A list of all documents with the tags.
690
722
  */
691
- getAllByEveryTag<TDocument extends TDocuments>(tags: string[], params?: Partial<Omit<BuildQueryURLArgs, "page">> & GetAllParams & FetchParams): Promise<TDocument[]>;
723
+ getAllByEveryTag<TDocument extends TDocuments>(tags: string[], params?: Partial<Omit<BuildQueryURLArgs, "page">> & GetAllParams & FetchParams & OptimizeParams): Promise<TDocument[]>;
692
724
  /**
693
725
  * Queries documents from the Prismic repository with specific tags. A
694
726
  * document must be tagged with at least one of the queried tags to be
@@ -707,7 +739,7 @@ export declare class Client<TDocuments extends PrismicDocument = PrismicDocument
707
739
  * @returns A paginated response containing documents with at least one of the
708
740
  * tags.
709
741
  */
710
- getBySomeTags<TDocument extends TDocuments>(tags: string[], params?: Partial<BuildQueryURLArgs> & FetchParams): Promise<Query<TDocument>>;
742
+ getBySomeTags<TDocument extends TDocuments>(tags: string[], params?: Partial<BuildQueryURLArgs> & FetchParams & OptimizeParams): Promise<Query<TDocument>>;
711
743
  /**
712
744
  * Queries documents from the Prismic repository with specific tags. A
713
745
  * document must be tagged with at least one of the queried tags to be
@@ -728,14 +760,14 @@ export declare class Client<TDocuments extends PrismicDocument = PrismicDocument
728
760
  *
729
761
  * @returns A list of all documents with at least one of the tags.
730
762
  */
731
- getAllBySomeTags<TDocument extends TDocuments>(tags: string[], params?: Partial<Omit<BuildQueryURLArgs, "page">> & GetAllParams & FetchParams): Promise<TDocument[]>;
763
+ getAllBySomeTags<TDocument extends TDocuments>(tags: string[], params?: Partial<Omit<BuildQueryURLArgs, "page">> & GetAllParams & FetchParams & OptimizeParams): Promise<TDocument[]>;
732
764
  /**
733
765
  * Returns metadata about the Prismic repository, such as its refs, releases,
734
766
  * and custom types.
735
767
  *
736
768
  * @returns Repository metadata.
737
769
  */
738
- getRepository(params?: FetchParams): Promise<Repository>;
770
+ getRepository(params?: FetchParams & OptimizeParams): Promise<Repository>;
739
771
  /**
740
772
  * Returns a list of all refs for the Prismic repository.
741
773
  *
@@ -745,7 +777,7 @@ export declare class Client<TDocuments extends PrismicDocument = PrismicDocument
745
777
  *
746
778
  * @returns A list of all refs for the Prismic repository.
747
779
  */
748
- getRefs(params?: FetchParams): Promise<Ref[]>;
780
+ getRefs(params?: FetchParams & OptimizeParams): Promise<Ref[]>;
749
781
  /**
750
782
  * Returns a ref for the Prismic repository with a matching ID.
751
783
  *
@@ -753,7 +785,7 @@ export declare class Client<TDocuments extends PrismicDocument = PrismicDocument
753
785
  *
754
786
  * @returns The ref with a matching ID, if it exists.
755
787
  */
756
- getRefByID(id: string, params?: FetchParams): Promise<Ref>;
788
+ getRefByID(id: string, params?: FetchParams & OptimizeParams): Promise<Ref>;
757
789
  /**
758
790
  * Returns a ref for the Prismic repository with a matching label.
759
791
  *
@@ -761,21 +793,21 @@ export declare class Client<TDocuments extends PrismicDocument = PrismicDocument
761
793
  *
762
794
  * @returns The ref with a matching label, if it exists.
763
795
  */
764
- getRefByLabel(label: string, params?: FetchParams): Promise<Ref>;
796
+ getRefByLabel(label: string, params?: FetchParams & OptimizeParams): Promise<Ref>;
765
797
  /**
766
798
  * Returns the master ref for the Prismic repository. The master ref points to
767
799
  * the repository's latest published content.
768
800
  *
769
801
  * @returns The repository's master ref.
770
802
  */
771
- getMasterRef(params?: FetchParams): Promise<Ref>;
803
+ getMasterRef(params?: FetchParams & OptimizeParams): Promise<Ref>;
772
804
  /**
773
805
  * Returns a list of all Releases for the Prismic repository. Releases are
774
806
  * used to group content changes before publishing.
775
807
  *
776
808
  * @returns A list of all Releases for the Prismic repository.
777
809
  */
778
- getReleases(params?: FetchParams): Promise<Ref[]>;
810
+ getReleases(params?: FetchParams & OptimizeParams): Promise<Ref[]>;
779
811
  /**
780
812
  * Returns a Release for the Prismic repository with a matching ID.
781
813
  *
@@ -783,7 +815,7 @@ export declare class Client<TDocuments extends PrismicDocument = PrismicDocument
783
815
  *
784
816
  * @returns The Release with a matching ID, if it exists.
785
817
  */
786
- getReleaseByID(id: string, params?: FetchParams): Promise<Ref>;
818
+ getReleaseByID(id: string, params?: FetchParams & OptimizeParams): Promise<Ref>;
787
819
  /**
788
820
  * Returns a Release for the Prismic repository with a matching label.
789
821
  *
@@ -791,13 +823,13 @@ export declare class Client<TDocuments extends PrismicDocument = PrismicDocument
791
823
  *
792
824
  * @returns The ref with a matching label, if it exists.
793
825
  */
794
- getReleaseByLabel(label: string, params?: FetchParams): Promise<Ref>;
826
+ getReleaseByLabel(label: string, params?: FetchParams & OptimizeParams): Promise<Ref>;
795
827
  /**
796
828
  * Returns a list of all tags used in the Prismic repository.
797
829
  *
798
830
  * @returns A list of all tags used in the repository.
799
831
  */
800
- getTags(params?: FetchParams): Promise<string[]>;
832
+ getTags(params?: FetchParams & OptimizeParams): Promise<string[]>;
801
833
  /**
802
834
  * Builds a URL used to query content from the Prismic repository.
803
835
  *
@@ -805,7 +837,7 @@ export declare class Client<TDocuments extends PrismicDocument = PrismicDocument
805
837
  *
806
838
  * @returns A URL string that can be requested to query content.
807
839
  */
808
- buildQueryURL({ signal, ...params }?: Partial<BuildQueryURLArgs> & FetchParams): Promise<string>;
840
+ buildQueryURL({ signal, optimize, ...params }?: Partial<BuildQueryURLArgs> & FetchParams & OptimizeParams): Promise<string>;
809
841
  /**
810
842
  * Determines the URL for a previewed document during an active preview
811
843
  * session. The result of this method should be used to redirect the user to
@@ -825,7 +857,7 @@ export declare class Client<TDocuments extends PrismicDocument = PrismicDocument
825
857
  * @returns The URL for the previewed document during an active preview
826
858
  * session. The user should be redirected to this URL.
827
859
  */
828
- resolvePreviewURL<LinkResolverReturnType>(args: ResolvePreviewArgs<LinkResolverReturnType> & FetchParams): Promise<string>;
860
+ resolvePreviewURL<LinkResolverReturnType>(args: ResolvePreviewArgs<LinkResolverReturnType> & FetchParams & OptimizeParams): Promise<string>;
829
861
  /**
830
862
  * Configures the client to query the latest published content for all future
831
863
  * queries.
@@ -26,6 +26,7 @@ import { isRepositoryEndpoint } from "./isRepositoryEndpoint.js";
26
26
  const MAX_PAGE_SIZE = 100;
27
27
  const REPOSITORY_CACHE_TTL = 5e3;
28
28
  const GET_ALL_QUERY_DELAY = 500;
29
+ const OPTIMIZE_REPOSITORY_REQUESTS_VALID_UNTIL_PARAMETER_NAME = "x-valid-until";
29
30
  var RefStateMode;
30
31
  (function(RefStateMode2) {
31
32
  RefStateMode2["Master"] = "Master";
@@ -89,6 +90,10 @@ class Client {
89
90
  * be overridden on each query if needed.
90
91
  */
91
92
  __publicField(this, "defaultParams");
93
+ /**
94
+ * Options that determine if or how the client is optimized.
95
+ */
96
+ __publicField(this, "optimize");
92
97
  /**
93
98
  * The client's ref mode state. This determines which ref is used during
94
99
  * queries.
@@ -109,6 +114,7 @@ class Client {
109
114
  * Active `fetch()` jobs keyed by URL and AbortSignal (if it exists).
110
115
  */
111
116
  __publicField(this, "fetchJobs", {});
117
+ var _a, _b;
112
118
  if (isRepositoryEndpoint(repositoryNameOrEndpoint)) {
113
119
  if (process.env.NODE_ENV === "development" && /\.prismic\.io\/(?!api\/v2\/?)/.test(repositoryNameOrEndpoint)) {
114
120
  throw new 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);
@@ -121,6 +127,10 @@ class Client {
121
127
  this.routes = options.routes;
122
128
  this.brokenRoute = options.brokenRoute;
123
129
  this.defaultParams = options.defaultParams;
130
+ this.optimize = {
131
+ repositoryRequests: ((_a = options.optimize) == null ? void 0 : _a.repositoryRequests) ?? true,
132
+ concurrentRequests: ((_b = options.optimize) == null ? void 0 : _b.concurrentRequests) ?? true
133
+ };
124
134
  if (options.ref) {
125
135
  this.queryContentFromRef(options.ref);
126
136
  }
@@ -226,10 +236,10 @@ class Client {
226
236
  * The first result of the query, if any.
227
237
  */
228
238
  async getFirst(params) {
229
- var _a, _b;
239
+ var _a;
230
240
  const actualParams = { ...params };
231
241
  if (!(params && params.page) && !(params == null ? void 0 : params.pageSize)) {
232
- actualParams.pageSize = ((_a = this.defaultParams) == null ? void 0 : _a.pageSize) == null ? 1 : (_b = this.defaultParams) == null ? void 0 : _b.pageSize;
242
+ actualParams.pageSize = ((_a = this.defaultParams) == null ? void 0 : _a.pageSize) ?? 1;
233
243
  }
234
244
  const url = await this.buildQueryURL(actualParams);
235
245
  const result = await this.fetch(url, params);
@@ -657,10 +667,14 @@ class Client {
657
667
  * @returns Repository metadata.
658
668
  */
659
669
  async getRepository(params) {
670
+ var _a;
660
671
  const url = new URL(this.endpoint);
661
672
  if (this.accessToken) {
662
673
  url.searchParams.set("access_token", this.accessToken);
663
674
  }
675
+ if (((_a = params == null ? void 0 : params.optimize) == null ? void 0 : _a.repositoryRequests) ?? this.optimize.repositoryRequests) {
676
+ url.searchParams.set(OPTIMIZE_REPOSITORY_REQUESTS_VALID_UNTIL_PARAMETER_NAME, (Math.floor(Date.now() / REPOSITORY_CACHE_TTL) * REPOSITORY_CACHE_TTL + REPOSITORY_CACHE_TTL).toString());
677
+ }
664
678
  return await this.fetch(url.toString(), params);
665
679
  }
666
680
  /**
@@ -765,9 +779,9 @@ class Client {
765
779
  *
766
780
  * @returns A URL string that can be requested to query content.
767
781
  */
768
- async buildQueryURL({ signal, ...params } = {}) {
769
- const ref = params.ref || await this.getResolvedRefString();
770
- const integrationFieldsRef = params.integrationFieldsRef || (await this.getCachedRepository({ signal })).integrationFieldsRef || void 0;
782
+ async buildQueryURL({ signal, optimize, ...params } = {}) {
783
+ const ref = params.ref || await this.getResolvedRefString({ signal, optimize });
784
+ const integrationFieldsRef = params.integrationFieldsRef || (await this.getCachedRepository({ signal, optimize })).integrationFieldsRef || void 0;
771
785
  return buildQueryURL(this.endpoint, {
772
786
  ...this.defaultParams,
773
787
  ...params,
@@ -817,6 +831,7 @@ class Client {
817
831
  }
818
832
  if (documentID != null && previewToken != null) {
819
833
  const document = await this.getByID(documentID, {
834
+ optimize: args.optimize,
820
835
  signal: args.signal,
821
836
  ref: previewToken,
822
837
  lang: "*"
@@ -993,11 +1008,16 @@ class Client {
993
1008
  * @returns Cached repository metadata.
994
1009
  */
995
1010
  async getCachedRepository(params) {
996
- if (!this.cachedRepository || Date.now() >= this.cachedRepositoryExpiration) {
997
- this.cachedRepositoryExpiration = Date.now() + REPOSITORY_CACHE_TTL;
998
- this.cachedRepository = await this.getRepository(params);
1011
+ var _a;
1012
+ if (((_a = params == null ? void 0 : params.optimize) == null ? void 0 : _a.repositoryRequests) ?? this.optimize.repositoryRequests) {
1013
+ if (!this.cachedRepository || Date.now() >= this.cachedRepositoryExpiration) {
1014
+ this.cachedRepositoryExpiration = Date.now() + REPOSITORY_CACHE_TTL;
1015
+ this.cachedRepository = await this.getRepository(params);
1016
+ }
1017
+ return this.cachedRepository;
1018
+ } else {
1019
+ return await this.getRepository(params);
999
1020
  }
1000
- return this.cachedRepository;
1001
1021
  }
1002
1022
  /**
1003
1023
  * Returns a cached Prismic repository form. Forms are used to determine API
@@ -1086,32 +1106,52 @@ class Client {
1086
1106
  * @returns The JSON response from the network request.
1087
1107
  */
1088
1108
  async fetch(url, params = {}) {
1089
- let job;
1090
- if (this.fetchJobs[url] && this.fetchJobs[url].has(params.signal)) {
1091
- job = this.fetchJobs[url].get(params.signal);
1109
+ var _a;
1110
+ let res;
1111
+ if (((_a = params.optimize) == null ? void 0 : _a.concurrentRequests) ?? this.optimize.concurrentRequests) {
1112
+ let job;
1113
+ const fetchJobKeyInstance = new URL(url);
1114
+ fetchJobKeyInstance.searchParams.delete(OPTIMIZE_REPOSITORY_REQUESTS_VALID_UNTIL_PARAMETER_NAME);
1115
+ const fetchJobKey = fetchJobKeyInstance.toString();
1116
+ if (this.fetchJobs[fetchJobKey] && this.fetchJobs[fetchJobKey].has(params.signal)) {
1117
+ job = this.fetchJobs[fetchJobKey].get(params.signal);
1118
+ } else {
1119
+ this.fetchJobs[fetchJobKey] = this.fetchJobs[fetchJobKey] || /* @__PURE__ */ new Map();
1120
+ job = this.fetchFn(url, {
1121
+ signal: params.signal
1122
+ }).then(async (res2) => {
1123
+ let json = void 0;
1124
+ try {
1125
+ json = await res2.json();
1126
+ } catch {
1127
+ }
1128
+ return {
1129
+ status: res2.status,
1130
+ json
1131
+ };
1132
+ }).finally(() => {
1133
+ this.fetchJobs[fetchJobKey].delete(params.signal);
1134
+ if (this.fetchJobs[fetchJobKey].size === 0) {
1135
+ delete this.fetchJobs[fetchJobKey];
1136
+ }
1137
+ });
1138
+ this.fetchJobs[fetchJobKey].set(params.signal, job);
1139
+ }
1140
+ res = await job;
1092
1141
  } else {
1093
- this.fetchJobs[url] = this.fetchJobs[url] || /* @__PURE__ */ new Map();
1094
- job = this.fetchFn(url, {
1142
+ const job = await this.fetchFn(url, {
1095
1143
  signal: params.signal
1096
- }).then(async (res2) => {
1097
- let json = void 0;
1098
- try {
1099
- json = await res2.json();
1100
- } catch {
1101
- }
1102
- return {
1103
- status: res2.status,
1104
- json
1105
- };
1106
- }).finally(() => {
1107
- this.fetchJobs[url].delete(params.signal);
1108
- if (this.fetchJobs[url].size === 0) {
1109
- delete this.fetchJobs[url];
1110
- }
1111
1144
  });
1112
- this.fetchJobs[url].set(params.signal, job);
1145
+ let json = void 0;
1146
+ try {
1147
+ json = await job.json();
1148
+ } catch {
1149
+ }
1150
+ res = {
1151
+ status: job.status,
1152
+ json
1153
+ };
1113
1154
  }
1114
- const res = await job;
1115
1155
  if (res.status !== 404 && res.json == null) {
1116
1156
  throw new PrismicError(void 0, url, res.json);
1117
1157
  }