@prismicio/client
Advanced tools
Comparing version 6.0.0-alpha.11 to 6.0.0-alpha.12
@@ -14,53 +14,2 @@ import * as prismicT from '@prismicio/types'; | ||
interface Ref { | ||
ref: string; | ||
label: string; | ||
isMasterRef: boolean; | ||
scheduledAt?: string; | ||
id: string; | ||
} | ||
interface Language { | ||
id: string; | ||
name: string; | ||
} | ||
interface Repository { | ||
refs: Ref[]; | ||
integrationFieldsRef: string | null; | ||
bookmarks: Record<string, string>; | ||
languages: Language[]; | ||
types: Record<string, string>; | ||
tags: string[]; | ||
forms: Record<string, Form>; | ||
/** | ||
* @deprecated Experiments are no longer part of Prismic. | ||
*/ | ||
experiments: unknown; | ||
oauth_initiate: string; | ||
oauth_token: string; | ||
version: string; | ||
license: string; | ||
} | ||
interface Query<TDocument extends prismicT.PrismicDocument = prismicT.PrismicDocument> { | ||
page: number; | ||
results_per_page: number; | ||
results_size: number; | ||
total_results_size: number; | ||
total_pages: number; | ||
next_page: string | null; | ||
prev_page: string | null; | ||
results: TDocument[]; | ||
} | ||
interface Form { | ||
method: "GET"; | ||
enctype: string; | ||
action: string; | ||
name?: string; | ||
rel?: string; | ||
fields: Record<string, FormField>; | ||
} | ||
interface FormField { | ||
type: "String" | "Integer"; | ||
multiple: boolean; | ||
default?: string; | ||
} | ||
/** | ||
@@ -315,3 +264,3 @@ * A universal API to make network requests. A subset of the `fetch()` API. | ||
*/ | ||
documentId?: string; | ||
documentID?: string; | ||
}; | ||
@@ -458,3 +407,3 @@ /** | ||
*/ | ||
query: <TDocument extends prismicT.PrismicDocument<Record<string, prismicT.AnyRegularField | prismicT.GroupField<Record<string, prismicT.AnyRegularField>> | prismicT.SliceZone<prismicT.Slice<string, Record<string, prismicT.AnyRegularField>, Record<string, prismicT.AnyRegularField>> | prismicT.SharedSlice<string, prismicT.SharedSliceVariation<string, Record<string, prismicT.AnyRegularField>, Record<string, prismicT.AnyRegularField>>>>>, string, string>>(params?: Partial<BuildQueryURLArgs> | undefined) => Promise<Query<TDocument>>; | ||
query: <TDocument extends prismicT.PrismicDocument<Record<string, prismicT.AnyRegularField | prismicT.GroupField<Record<string, prismicT.AnyRegularField>> | prismicT.SliceZone<prismicT.Slice<string, Record<string, prismicT.AnyRegularField>, Record<string, prismicT.AnyRegularField>> | prismicT.SharedSlice<string, prismicT.SharedSliceVariation<string, Record<string, prismicT.AnyRegularField>, Record<string, prismicT.AnyRegularField>>>>>, string, string>>(params?: Partial<BuildQueryURLArgs> | undefined) => Promise<prismicT.Query<TDocument>>; | ||
/** | ||
@@ -474,3 +423,3 @@ * Queries content from the Prismic repository. | ||
*/ | ||
get<TDocument extends prismicT.PrismicDocument>(params?: Partial<BuildQueryURLArgs>): Promise<Query<TDocument>>; | ||
get<TDocument extends prismicT.PrismicDocument>(params?: Partial<BuildQueryURLArgs>): Promise<prismicT.Query<TDocument>>; | ||
/** | ||
@@ -552,3 +501,3 @@ * Queries content from the Prismic repository and returns only the first | ||
*/ | ||
getByIDs<TDocument extends prismicT.PrismicDocument>(ids: string[], params?: Partial<BuildQueryURLArgs>): Promise<Query<TDocument>>; | ||
getByIDs<TDocument extends prismicT.PrismicDocument>(ids: string[], params?: Partial<BuildQueryURLArgs>): Promise<prismicT.Query<TDocument>>; | ||
/** | ||
@@ -641,3 +590,3 @@ * Queries all documents from the Prismic repository with specific IDs. | ||
*/ | ||
getByType<TDocument extends prismicT.PrismicDocument>(documentType: string, params?: Partial<BuildQueryURLArgs>): Promise<Query<TDocument>>; | ||
getByType<TDocument extends prismicT.PrismicDocument>(documentType: string, params?: Partial<BuildQueryURLArgs>): Promise<prismicT.Query<TDocument>>; | ||
/** | ||
@@ -678,3 +627,3 @@ * Queries all documents from the Prismic repository for a specific Custom Type. | ||
*/ | ||
getByTag<TDocument extends prismicT.PrismicDocument>(tag: string, params?: Partial<BuildQueryURLArgs>): Promise<Query<TDocument>>; | ||
getByTag<TDocument extends prismicT.PrismicDocument>(tag: string, params?: Partial<BuildQueryURLArgs>): Promise<prismicT.Query<TDocument>>; | ||
/** | ||
@@ -713,3 +662,3 @@ * Queries all documents from the Prismic repository with a specific tag. | ||
*/ | ||
getByTags<TDocument extends prismicT.PrismicDocument>(tags: string[], params?: Partial<BuildQueryURLArgs>): Promise<Query<TDocument>>; | ||
getByTags<TDocument extends prismicT.PrismicDocument>(tags: string[], params?: Partial<BuildQueryURLArgs>): Promise<prismicT.Query<TDocument>>; | ||
/** | ||
@@ -739,3 +688,3 @@ * Queries all documents from the Prismic repository with a specific tag. | ||
*/ | ||
getRepository(): Promise<Repository>; | ||
getRepository(): Promise<prismicT.Repository>; | ||
/** | ||
@@ -750,3 +699,3 @@ * Returns a list of all refs for the Prismic repository. | ||
*/ | ||
getRefs(): Promise<Ref[]>; | ||
getRefs(): Promise<prismicT.Ref[]>; | ||
/** | ||
@@ -759,3 +708,3 @@ * Returns a ref for the Prismic repository with a matching ID. | ||
*/ | ||
getRefById(id: string): Promise<Ref>; | ||
getRefByID(id: string): Promise<prismicT.Ref>; | ||
/** | ||
@@ -768,3 +717,3 @@ * Returns a ref for the Prismic repository with a matching label. | ||
*/ | ||
getRefByLabel(label: string): Promise<Ref>; | ||
getRefByLabel(label: string): Promise<prismicT.Ref>; | ||
/** | ||
@@ -776,3 +725,3 @@ * Returns the master ref for the Prismic repository. The master ref points to | ||
*/ | ||
getMasterRef(): Promise<Ref>; | ||
getMasterRef(): Promise<prismicT.Ref>; | ||
/** | ||
@@ -784,3 +733,3 @@ * Returns a list of all Releases for the Prismic repository. Releases are | ||
*/ | ||
getReleases(): Promise<Ref[]>; | ||
getReleases(): Promise<prismicT.Ref[]>; | ||
/** | ||
@@ -793,3 +742,3 @@ * Returns a Release for the Prismic repository with a matching ID. | ||
*/ | ||
getReleaseByID(id: string): Promise<Ref>; | ||
getReleaseByID(id: string): Promise<prismicT.Ref>; | ||
/** | ||
@@ -802,3 +751,3 @@ * Returns a Release for the Prismic repository with a matching label. | ||
*/ | ||
getReleaseByLabel(label: string): Promise<Ref>; | ||
getReleaseByLabel(label: string): Promise<prismicT.Ref>; | ||
/** | ||
@@ -866,3 +815,3 @@ * Returns a list of all tags used in the Prismic repository. | ||
*/ | ||
queryContentFromReleaseByID(releaseId: string): void; | ||
queryContentFromReleaseByID(releaseID: string): void; | ||
/** | ||
@@ -1322,2 +1271,2 @@ * Configures the client to query content from a specific Release identified | ||
export { BuildQueryURLArgs, Client, ClientConfig, FetchLike, ForbiddenError, Form, FormField, HttpRequestLike, Language, Ordering, ParsingError, PrismicError, Query, QueryParams, Ref, Repository, RequestInitLike, ResponseLike, Route, buildQueryURL, cookie, createClient, getEndpoint, predicate }; | ||
export { BuildQueryURLArgs, Client, ClientConfig, FetchLike, ForbiddenError, HttpRequestLike, Ordering, ParsingError, PrismicError, QueryParams, RequestInitLike, ResponseLike, Route, buildQueryURL, cookie, createClient, getEndpoint, predicate }; |
{ | ||
"name": "@prismicio/client", | ||
"version": "6.0.0-alpha.11", | ||
"version": "6.0.0-alpha.12", | ||
"description": "The official JavaScript + TypeScript client library for Prismic", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -10,7 +10,3 @@ import * as prismicT from "@prismicio/types"; | ||
FetchLike, | ||
Form, | ||
HttpRequestLike, | ||
Query, | ||
Ref, | ||
Repository, | ||
// TODO: Uncomment when the Authorization header can be used | ||
@@ -156,3 +152,3 @@ // @see Related issue - {@link https://github.com/prismicio/issue-tracker-wroom/issues/351} | ||
*/ | ||
releaseId: string; | ||
releaseID: string; | ||
}; | ||
@@ -263,3 +259,3 @@ } | ||
*/ | ||
documentId?: string; | ||
documentID?: string; | ||
}; | ||
@@ -298,3 +294,6 @@ | ||
*/ | ||
const findRef = (refs: Ref[], predicate: (ref: Ref) => boolean): Ref => { | ||
const findRef = ( | ||
refs: prismicT.Ref[], | ||
predicate: (ref: prismicT.Ref) => boolean, | ||
): prismicT.Ref => { | ||
const ref = refs.find((ref) => predicate(ref)); | ||
@@ -522,3 +521,3 @@ | ||
params?: Partial<BuildQueryURLArgs>, | ||
): Promise<Query<TDocument>> { | ||
): Promise<prismicT.Query<TDocument>> { | ||
const url = await this.buildQueryURL(params); | ||
@@ -529,3 +528,3 @@ | ||
// return await this.fetch<Query<TDocument>>(url, params); | ||
return await this.fetch<Query<TDocument>>(url); | ||
return await this.fetch<prismicT.Query<TDocument>>(url); | ||
} | ||
@@ -651,3 +650,3 @@ | ||
params?: Partial<BuildQueryURLArgs>, | ||
): Promise<Query<TDocument>> { | ||
): Promise<prismicT.Query<TDocument>> { | ||
return await this.get<TDocument>( | ||
@@ -776,3 +775,3 @@ appendPredicates(predicate.in("document.id", ids))(params), | ||
params?: Partial<BuildQueryURLArgs>, | ||
): Promise<Query<TDocument>> { | ||
): Promise<prismicT.Query<TDocument>> { | ||
return await this.get<TDocument>( | ||
@@ -829,3 +828,3 @@ appendPredicates(typePredicate(documentType))(params), | ||
params?: Partial<BuildQueryURLArgs>, | ||
): Promise<Query<TDocument>> { | ||
): Promise<prismicT.Query<TDocument>> { | ||
return await this.get<TDocument>( | ||
@@ -880,3 +879,3 @@ appendPredicates(tagsPredicate(tag))(params), | ||
params?: Partial<BuildQueryURLArgs>, | ||
): Promise<Query<TDocument>> { | ||
): Promise<prismicT.Query<TDocument>> { | ||
return await this.get<TDocument>( | ||
@@ -919,3 +918,3 @@ appendPredicates(tagsPredicate(tags))(params), | ||
*/ | ||
async getRepository(): Promise<Repository> { | ||
async getRepository(): Promise<prismicT.Repository> { | ||
// TODO: Uncomment when the Authorization header can be used | ||
@@ -931,3 +930,3 @@ // @see Related issue - {@link https://github.com/prismicio/issue-tracker-wroom/issues/351} | ||
return await this.fetch<Repository>(url.toString()); | ||
return await this.fetch<prismicT.Repository>(url.toString()); | ||
} | ||
@@ -944,3 +943,3 @@ | ||
*/ | ||
async getRefs(): Promise<Ref[]> { | ||
async getRefs(): Promise<prismicT.Ref[]> { | ||
const res = await this.getRepository(); | ||
@@ -958,3 +957,3 @@ | ||
*/ | ||
async getRefById(id: string): Promise<Ref> { | ||
async getRefByID(id: string): Promise<prismicT.Ref> { | ||
const refs = await this.getRefs(); | ||
@@ -972,3 +971,3 @@ | ||
*/ | ||
async getRefByLabel(label: string): Promise<Ref> { | ||
async getRefByLabel(label: string): Promise<prismicT.Ref> { | ||
const refs = await this.getRefs(); | ||
@@ -985,3 +984,3 @@ | ||
*/ | ||
async getMasterRef(): Promise<Ref> { | ||
async getMasterRef(): Promise<prismicT.Ref> { | ||
const refs = await this.getRefs(); | ||
@@ -998,3 +997,3 @@ | ||
*/ | ||
async getReleases(): Promise<Ref[]> { | ||
async getReleases(): Promise<prismicT.Ref[]> { | ||
const refs = await this.getRefs(); | ||
@@ -1012,3 +1011,3 @@ | ||
*/ | ||
async getReleaseByID(id: string): Promise<Ref> { | ||
async getReleaseByID(id: string): Promise<prismicT.Ref> { | ||
const releases = await this.getReleases(); | ||
@@ -1026,3 +1025,3 @@ | ||
*/ | ||
async getReleaseByLabel(label: string): Promise<Ref> { | ||
async getReleaseByLabel(label: string): Promise<prismicT.Ref> { | ||
const releases = await this.getReleases(); | ||
@@ -1105,3 +1104,3 @@ | ||
async resolvePreviewURL(args: ResolvePreviewArgs): Promise<string> { | ||
let documentId = args.documentId; | ||
let documentID = args.documentID; | ||
let previewToken = args.previewToken; | ||
@@ -1111,7 +1110,7 @@ | ||
const searchParams = new URLSearchParams(globalThis.location.search); | ||
documentId = documentId || searchParams.get("documentId") || undefined; | ||
documentID = documentID || searchParams.get("documentId") || undefined; | ||
previewToken = previewToken || searchParams.get("token") || undefined; | ||
} else if (this.refMode.httpRequest?.query) { | ||
if (typeof this.refMode.httpRequest.query.documentId === "string") { | ||
documentId = documentId || this.refMode.httpRequest.query.documentId; | ||
documentID = documentID || this.refMode.httpRequest.query.documentId; | ||
} | ||
@@ -1123,4 +1122,4 @@ if (typeof this.refMode.httpRequest.query.token === "string") { | ||
if (documentId != null) { | ||
const document = await this.getByID(documentId, { | ||
if (documentID != null) { | ||
const document = await this.getByID(documentID, { | ||
ref: previewToken, | ||
@@ -1174,7 +1173,7 @@ }); | ||
*/ | ||
queryContentFromReleaseByID(releaseId: string): void { | ||
queryContentFromReleaseByID(releaseID: string): void { | ||
this.refMode = { | ||
...this.refMode, | ||
type: RefStateType.ReleaseByID, | ||
payload: { releaseId }, | ||
payload: { releaseID: releaseID }, | ||
}; | ||
@@ -1235,6 +1234,7 @@ } | ||
*/ | ||
private async getCachedRepository(): Promise<Repository> { | ||
private async getCachedRepository(): Promise<prismicT.Repository> { | ||
const cacheKey = this.endpoint; | ||
const cachedRepository = this.internalCache.get<Repository>(cacheKey); | ||
const cachedRepository = | ||
this.internalCache.get<prismicT.Repository>(cacheKey); | ||
@@ -1261,3 +1261,3 @@ if (cachedRepository) { | ||
*/ | ||
private async getCachedRepositoryForm(name: string): Promise<Form> { | ||
private async getCachedRepositoryForm(name: string): Promise<prismicT.Form> { | ||
const cachedRepository = await this.getCachedRepository(); | ||
@@ -1353,5 +1353,5 @@ const form = cachedRepository.forms[name]; | ||
case RefStateType.ReleaseByID: { | ||
const releaseId = this.refMode.payload.releaseId; | ||
const releaseID = this.refMode.payload.releaseID; | ||
const repository = await this.getCachedRepository(); | ||
const ref = findRef(repository.refs, (ref) => ref.id === releaseId); | ||
const ref = findRef(repository.refs, (ref) => ref.id === releaseID); | ||
@@ -1358,0 +1358,0 @@ return ref.ref; |
@@ -21,10 +21,4 @@ // Primary library API. | ||
FetchLike, | ||
Form, | ||
FormField, | ||
HttpRequestLike, | ||
Language, | ||
Ordering, | ||
Query, | ||
Ref, | ||
Repository, | ||
RequestInitLike, | ||
@@ -31,0 +25,0 @@ ResponseLike, |
@@ -1,64 +0,1 @@ | ||
import * as prismicT from "@prismicio/types"; | ||
export interface Ref { | ||
ref: string; | ||
label: string; | ||
isMasterRef: boolean; | ||
scheduledAt?: string; | ||
id: string; | ||
} | ||
export type Release = Ref; | ||
export interface Language { | ||
id: string; | ||
name: string; | ||
} | ||
export interface Repository { | ||
refs: Ref[]; | ||
integrationFieldsRef: string | null; | ||
bookmarks: Record<string, string>; | ||
languages: Language[]; | ||
types: Record<string, string>; | ||
tags: string[]; | ||
forms: Record<string, Form>; | ||
/** | ||
* @deprecated Experiments are no longer part of Prismic. | ||
*/ | ||
experiments: unknown; | ||
oauth_initiate: string; | ||
oauth_token: string; | ||
version: string; | ||
license: string; | ||
} | ||
export interface Query< | ||
TDocument extends prismicT.PrismicDocument = prismicT.PrismicDocument, | ||
> { | ||
page: number; | ||
results_per_page: number; | ||
results_size: number; | ||
total_results_size: number; | ||
total_pages: number; | ||
next_page: string | null; | ||
prev_page: string | null; | ||
results: TDocument[]; | ||
} | ||
export interface Form { | ||
method: "GET"; | ||
enctype: string; | ||
action: string; | ||
name?: string; | ||
rel?: string; | ||
fields: Record<string, FormField>; | ||
} | ||
export interface FormField { | ||
type: "String" | "Integer"; | ||
multiple: boolean; | ||
default?: string; | ||
} | ||
/** | ||
@@ -65,0 +2,0 @@ * A universal API to make network requests. A subset of the `fetch()` API. |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
174948
4506