@prismicio/client 7.0.1-alpha.0 → 7.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/dist/createClient.cjs +6 -18
  2. package/dist/createClient.cjs.map +1 -1
  3. package/dist/createClient.d.ts +9 -42
  4. package/dist/createClient.js +6 -18
  5. package/dist/createClient.js.map +1 -1
  6. package/dist/helpers/asHTML.cjs.map +1 -1
  7. package/dist/helpers/asHTML.d.ts +6 -9
  8. package/dist/helpers/asHTML.js.map +1 -1
  9. package/dist/helpers/asLink.cjs.map +1 -1
  10. package/dist/helpers/asLink.d.ts +4 -7
  11. package/dist/helpers/asLink.js.map +1 -1
  12. package/dist/helpers/asText.cjs.map +1 -1
  13. package/dist/helpers/asText.d.ts +4 -7
  14. package/dist/helpers/asText.js.map +1 -1
  15. package/dist/helpers/unstable_mapSliceZone.cjs +39 -0
  16. package/dist/helpers/unstable_mapSliceZone.cjs.map +1 -0
  17. package/dist/helpers/unstable_mapSliceZone.d.ts +135 -0
  18. package/dist/helpers/unstable_mapSliceZone.js +39 -0
  19. package/dist/helpers/unstable_mapSliceZone.js.map +1 -0
  20. package/dist/index.cjs +2 -0
  21. package/dist/index.cjs.map +1 -1
  22. package/dist/index.d.ts +2 -1
  23. package/dist/index.js +3 -1
  24. package/dist/index.js.map +1 -1
  25. package/dist/lib/castThunk.cjs.map +1 -1
  26. package/dist/lib/castThunk.d.ts +1 -1
  27. package/dist/lib/castThunk.js.map +1 -1
  28. package/dist/package.json.cjs +1 -1
  29. package/dist/package.json.js +1 -1
  30. package/dist/types/model/customType.d.ts +6 -0
  31. package/dist/types/value/document.d.ts +3 -2
  32. package/package.json +13 -7
  33. package/src/createClient.ts +16 -59
  34. package/src/helpers/asHTML.ts +6 -9
  35. package/src/helpers/asLink.ts +4 -7
  36. package/src/helpers/asText.ts +4 -7
  37. package/src/helpers/unstable_mapSliceZone.ts +269 -0
  38. package/src/index.ts +1 -1
  39. package/src/lib/castThunk.ts +2 -8
  40. package/src/types/model/customType.ts +7 -0
  41. package/src/types/value/document.ts +3 -2
@@ -14,6 +14,12 @@ export interface CustomTypeModel<ID extends string = string, Definition extends
14
14
  * The human readable name of the custom type model.
15
15
  */
16
16
  label: string | null | undefined;
17
+ /**
18
+ * The format of the custom type model.
19
+ *
20
+ * Fallback to "custom" if undefined.
21
+ */
22
+ format?: "page" | "custom";
17
23
  /**
18
24
  * Determines if more than one document for the custom type can be created.
19
25
  */
@@ -1,6 +1,7 @@
1
1
  import { AnyRegularField } from "./types";
2
2
  import { GroupField } from "./group";
3
3
  import { SliceZone } from "./sliceZone";
4
+ import { TimestampField } from "./timestamp";
4
5
  /**
5
6
  * Document metadata for a translation of a Prismic document.
6
7
  */
@@ -43,11 +44,11 @@ export interface PrismicDocumentHeader<TypeEnum = string, LangEnum = string> {
43
44
  /**
44
45
  * The timestamp at which the document was first published.
45
46
  */
46
- first_publication_date: string;
47
+ first_publication_date: TimestampField<"filled">;
47
48
  /**
48
49
  * The timestamp at which the document was last published.
49
50
  */
50
- last_publication_date: string;
51
+ last_publication_date: TimestampField<"filled">;
51
52
  /**
52
53
  * Slugs associated with document.
53
54
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prismicio/client",
3
- "version": "7.0.1-alpha.0",
3
+ "version": "7.1.0",
4
4
  "description": "The official JavaScript + TypeScript client library for Prismic",
5
5
  "keywords": [
6
6
  "typescript",
@@ -23,8 +23,14 @@
23
23
  "type": "module",
24
24
  "exports": {
25
25
  ".": {
26
- "require": "./dist/index.cjs",
27
- "import": "./dist/index.js"
26
+ "require": {
27
+ "types": "./dist/index.d.ts",
28
+ "default": "./dist/index.cjs"
29
+ },
30
+ "import": {
31
+ "types": "./dist/index.d.ts",
32
+ "default": "./dist/index.js"
33
+ }
28
34
  },
29
35
  "./package.json": "./package.json"
30
36
  },
@@ -43,8 +49,8 @@
43
49
  "prepare": "npm run build",
44
50
  "release": "npm run test && standard-version && git push --follow-tags && npm run build && npm publish",
45
51
  "release:dry": "standard-version --dry-run",
46
- "release:alpha": "npm run test && standard-version --prerelease alpha && git push --follow-tags && npm run build && npm publish --tag alpha",
47
- "release:alpha:dry": "standard-version --prerelease alpha --dry-run",
52
+ "release:alpha": "npm run test && standard-version --release-as major --prerelease alpha && git push --follow-tags && npm run build && npm publish --tag alpha",
53
+ "release:alpha:dry": "standard-version --release-as major --prerelease alpha --dry-run",
48
54
  "lint": "eslint --ext .js,.ts .",
49
55
  "types": "tsc --noEmit",
50
56
  "unit": "vitest run --coverage",
@@ -53,11 +59,11 @@
53
59
  "test": "npm run lint && npm run types && npm run unit && npm run build && npm run size"
54
60
  },
55
61
  "dependencies": {
56
- "@prismicio/richtext": "^2.1.4",
62
+ "@prismicio/richtext": "^2.1.5",
57
63
  "imgix-url-builder": "^0.0.3"
58
64
  },
59
65
  "devDependencies": {
60
- "@prismicio/mock": "^0.2.0",
66
+ "@prismicio/mock": "^0.3.0",
61
67
  "@prismicio/types-internal": "2.0.0-alpha.11",
62
68
  "@size-limit/preset-small-lib": "^8.2.4",
63
69
  "@trivago/prettier-plugin-sort-imports": "^4.1.1",
@@ -217,22 +217,6 @@ type RefStringOrThunk =
217
217
  | string
218
218
  | (() => string | undefined | Promise<string | undefined>);
219
219
 
220
- /**
221
- * Options or a function that returns options provided to the client's `fetch()`
222
- * on all network requests. These options will be merged with internally
223
- * required options. They can also be overriden on a per-query basis using the
224
- * query's `fetchOptions` parameter.
225
- *
226
- * If the options must be determined on-demand, a function can be provided. This
227
- * function can be asynchronous.
228
- */
229
- export type RequestInitLikeOrThunk =
230
- | RequestInitLike
231
- | ((
232
- url: string,
233
- init?: RequestInitLike,
234
- ) => RequestInitLike | undefined | Promise<RequestInitLike | undefined>);
235
-
236
220
  /**
237
221
  * Configuration for clients that determine how content is queried.
238
222
  */
@@ -285,17 +269,11 @@ export type ClientConfig = {
285
269
  fetch?: FetchLike;
286
270
 
287
271
  /**
288
- * Options or a function that returns options provided to the client's
289
- * `fetch()` on all network requests. These options will be merged with
290
- * internally required options. They can also be overriden on a per-query
291
- * basis using the query's `fetchOptions` parameter.
292
- *
293
- * If the options must be determined on-demand, a function can be provided.
294
- * This function can be asynchronous.
295
- *
296
- * @experimental
272
+ * Options provided to the client's `fetch()` on all network requests. These
273
+ * options will be merged with internally required options. They can also be
274
+ * overriden on a per-query basis using the query's `fetchOptions` parameter.
297
275
  */
298
- fetchOptions?: RequestInitLikeOrThunk;
276
+ fetchOptions?: RequestInitLike;
299
277
  };
300
278
 
301
279
  /**
@@ -303,17 +281,11 @@ export type ClientConfig = {
303
281
  */
304
282
  type FetchParams = {
305
283
  /**
306
- * Options or a function that returns options provided to the client's
307
- * `fetch()` on all network requests. These options will be merged with
308
- * internally required options. They can also be overriden on a per-query
309
- * basis using the query's `fetchOptions` parameter.
310
- *
311
- * If the options must be determined on-demand, a function can be provided.
312
- * This function can be asynchronous.
313
- *
314
- * @experimental
284
+ * Options provided to the client's `fetch()` on all network requests. These
285
+ * options will be merged with internally required options. They can also be
286
+ * overriden on a per-query basis using the query's `fetchOptions` parameter.
315
287
  */
316
- fetchOptions?: RequestInitLikeOrThunk;
288
+ fetchOptions?: RequestInitLike;
317
289
 
318
290
  /**
319
291
  * An `AbortSignal` provided by an `AbortController`. This allows the network
@@ -460,18 +432,7 @@ export class Client<TDocuments extends PrismicDocument = PrismicDocument> {
460
432
  */
461
433
  fetchFn: FetchLike;
462
434
 
463
- /**
464
- * Options or a function that returns options provided to the client's
465
- * `fetch()` on all network requests. These options will be merged with
466
- * internally required options. They can also be overriden on a per-query
467
- * basis using the query's `fetchOptions` parameter.
468
- *
469
- * If the options must be determined on-demand, a function can be provided.
470
- * This function can be asynchronous.
471
- *
472
- * @experimental
473
- */
474
- fetchOptions?: RequestInitLikeOrThunk;
435
+ fetchOptions?: RequestInitLike;
475
436
 
476
437
  /**
477
438
  * Default parameters that will be sent with each query. These parameters can
@@ -1827,21 +1788,17 @@ export class Client<TDocuments extends PrismicDocument = PrismicDocument> {
1827
1788
  url: string,
1828
1789
  params: FetchParams = {},
1829
1790
  ): Promise<T> {
1830
- const paramsFetchOptions = await castThunk(params.fetchOptions)(url);
1831
- const thisFetchOptions = await castThunk(this.fetchOptions)(
1832
- url,
1833
- paramsFetchOptions,
1834
- );
1835
-
1836
1791
  const requestInit: RequestInitLike = {
1837
- ...paramsFetchOptions,
1838
- ...thisFetchOptions,
1792
+ ...this.fetchOptions,
1793
+ ...params.fetchOptions,
1839
1794
  headers: {
1840
- ...paramsFetchOptions?.headers,
1841
- ...thisFetchOptions?.headers,
1795
+ ...this.fetchOptions?.headers,
1796
+ ...params.fetchOptions?.headers,
1842
1797
  },
1843
1798
  signal:
1844
- paramsFetchOptions?.signal || params.signal || thisFetchOptions?.signal,
1799
+ params.fetchOptions?.signal ||
1800
+ params.signal ||
1801
+ this.fetchOptions?.signal,
1845
1802
  };
1846
1803
 
1847
1804
  let job: Promise<FetchJobResult>;
@@ -238,15 +238,6 @@ export const asHTML: {
238
238
  /**
239
239
  * Serializes a rich text or title field to an HTML string.
240
240
  *
241
- * @example
242
- *
243
- * ```ts
244
- * asHTML(field);
245
- * asHTML(field, { linkResolver });
246
- * asHTML(field, { serializer });
247
- * asHTML(field, { linkResolver, serializer });
248
- * ```
249
- *
250
241
  * @param richTextField - A rich text or title field from Prismic
251
242
  * @param config - Configuration that determines the output of `asHTML()`
252
243
  *
@@ -264,6 +255,12 @@ export const asHTML: {
264
255
  *
265
256
  * @deprecated Use object-style configuration instead.
266
257
  *
258
+ * ```ts
259
+ * asHTML(field);
260
+ * asHTML(field, { linkResolver });
261
+ * asHTML(field, { serializer });
262
+ * asHTML(field, { linkResolver, serializer });
263
+ * ```
267
264
  * @param richTextField - A rich text or title field from Prismic
268
265
  * @param linkResolver - An optional link resolver function to resolve links,
269
266
  * without it you're expected to use the `routes` options from the API
@@ -65,13 +65,6 @@ export const asLink: {
65
65
  /**
66
66
  * Resolves any type of link field or Prismic document to a URL.
67
67
  *
68
- * @example
69
- *
70
- * ```ts
71
- * asLink(field);
72
- * asLink(field, { linkResolver });
73
- * ```
74
- *
75
68
  * @typeParam LinkResolverFunctionReturnType - link resolver function return
76
69
  * type
77
70
  * @typeParam Field - Link field or Prismic document to resolve to a URL
@@ -102,6 +95,10 @@ export const asLink: {
102
95
  *
103
96
  * @deprecated Use object-style configuration instead.
104
97
  *
98
+ * ```ts
99
+ * asLink(field);
100
+ * asLink(field, { linkResolver });
101
+ * ```
105
102
  * @typeParam LinkResolverFunctionReturnType - link resolver function return
106
103
  * type
107
104
  * @typeParam Field - Link field or Prismic document to resolve to a URL
@@ -30,13 +30,6 @@ export const asText: {
30
30
  /**
31
31
  * Serializes a rich text or title field to a plain text string.
32
32
  *
33
- * @example
34
- *
35
- * ```ts
36
- * asText(field);
37
- * asText(field, { separator });
38
- * ```
39
- *
40
33
  * @param richTextField - A rich text or title field from Prismic
41
34
  * @param config - Configuration that determines the output of `asText()`
42
35
  *
@@ -54,6 +47,10 @@ export const asText: {
54
47
  *
55
48
  * @deprecated Use object-style configuration instead.
56
49
  *
50
+ * ```ts
51
+ * asText(field);
52
+ * asText(field, { separator });
53
+ * ```
57
54
  * @param richTextField - A rich text or title field from Prismic
58
55
  * @param separator - Separator used to join each element, defaults to a space
59
56
  *
@@ -0,0 +1,269 @@
1
+ import { Slice } from "../types/value/slice";
2
+
3
+ /**
4
+ * Convert a value to a lazyily loaded module. This is useful when using
5
+ * functions like `() => import("...")`.
6
+ */
7
+ type LazyModule<T> = () => Promise<T | { default: T }>;
8
+
9
+ /**
10
+ * Mark a type as potentially lazy-loaded via a module.
11
+ */
12
+ type MaybeLazyModule<T> = T | LazyModule<T>;
13
+
14
+ /**
15
+ * Returns the type of a `SliceLike` type.
16
+ *
17
+ * @typeParam Slice - The Slice from which the type will be extracted.
18
+ */
19
+ type ExtractSliceType<TSlice extends SliceLike> = TSlice extends Slice
20
+ ? TSlice["slice_type"]
21
+ : TSlice extends SliceGraphQLLike
22
+ ? TSlice["type"]
23
+ : never;
24
+
25
+ /**
26
+ * The minimum required properties to represent a Prismic Slice from the Prismic
27
+ * GraphQL API for the `unstable_mapSliceZone()` helper.
28
+ *
29
+ * @typeParam SliceType - Type name of the Slice.
30
+ */
31
+ type SliceGraphQLLike<TSliceType extends string = string> = {
32
+ type: Slice<TSliceType>["slice_type"];
33
+ };
34
+
35
+ /**
36
+ * The minimum required properties to represent a Prismic Slice for the
37
+ * `unstable_mapSliceZone()` helper.
38
+ *
39
+ * If using Prismic's Rest API V2, use the `Slice` export from
40
+ * `@prismicio/client` for a full interface.
41
+ *
42
+ * @typeParam SliceType - Type name of the Slice.
43
+ */
44
+ type SliceLike<TSliceType extends string = string> =
45
+ | Slice<TSliceType>
46
+ | SliceGraphQLLike<TSliceType>;
47
+
48
+ /**
49
+ * A looser version of the `SliceZone` type from `@prismicio/client` using
50
+ * `SliceLike`.
51
+ *
52
+ * If using Prismic's Rest API V2, use the `SliceZone` export from
53
+ * `@prismicio/client` for the full type.
54
+ *
55
+ * @typeParam TSlice - The type(s) of a Slice in the Slice Zone.
56
+ */
57
+ type SliceZoneLike<TSlice extends SliceLike = SliceLike> = readonly TSlice[];
58
+
59
+ /**
60
+ * A set of properties that identify a Slice as having been mapped. Consumers of
61
+ * the mapped Slice Zone can use these properties to detect and specially handle
62
+ * mapped Slices.
63
+ */
64
+ type MappedSliceLike = {
65
+ /**
66
+ * If `true`, this Slice has been modified from its original value using a
67
+ * mapper.
68
+ *
69
+ * @internal
70
+ */
71
+ __mapped: true;
72
+ };
73
+
74
+ /**
75
+ * Arguments for a function mapping content from a Prismic Slice using the
76
+ * `unstable_mapSliceZone()` helper.
77
+ *
78
+ * @typeParam TSlice - The Slice passed as a prop.
79
+ * @typeParam TContext - Arbitrary data passed to `unstable_mapSliceZone()` and
80
+ * made available to all Slice mappers.
81
+ */
82
+ type SliceMapperArgs<
83
+ TSlice extends SliceLike = SliceLike,
84
+ TContext = unknown,
85
+ > = {
86
+ /**
87
+ * Slice data.
88
+ */
89
+ slice: TSlice;
90
+
91
+ /**
92
+ * The index of the Slice in the Slice Zone.
93
+ */
94
+ index: number;
95
+
96
+ /**
97
+ * All Slices from the Slice Zone to which the Slice belongs.
98
+ */
99
+ // TODO: We have to keep this list of Slices general due to circular
100
+ // reference limtiations. If we had another generic to determine the full
101
+ // union of Slice types, it would include TSlice. This causes TypeScript to
102
+ // throw a compilation error.
103
+ slices: SliceZoneLike<
104
+ TSlice extends SliceGraphQLLike ? SliceGraphQLLike : Slice
105
+ >;
106
+
107
+ /**
108
+ * Arbitrary data passed to `unstable_mapSliceZone()` and made available to
109
+ * all Slice mappers.
110
+ */
111
+ context: TContext;
112
+ };
113
+
114
+ /**
115
+ * A record of mappers.
116
+ */
117
+ export type Mappers<
118
+ TSlice extends SliceLike = SliceLike,
119
+ TContext = unknown,
120
+ > = {
121
+ [P in ExtractSliceType<TSlice>]: MaybeLazyModule<
122
+ Mapper<
123
+ Extract<TSlice, SliceLike<P>>,
124
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
125
+ any,
126
+ TContext
127
+ >
128
+ >;
129
+ };
130
+
131
+ /**
132
+ * A function that maps a Slice and its metadata to a modified version. The
133
+ * return value will replace the Slice in the Slice Zone.
134
+ */
135
+ export type Mapper<
136
+ TSlice extends SliceLike = SliceLike,
137
+ TMappedSlice extends Record<string, unknown> | undefined | void =
138
+ | Record<string, unknown>
139
+ | undefined
140
+ | void,
141
+ TContext = unknown,
142
+ > = (
143
+ args: MapperArgs<TSlice, TContext>,
144
+ ) => TMappedSlice | Promise<TMappedSlice>;
145
+
146
+ /**
147
+ * Arguments provided to a mapper function.
148
+ */
149
+ export type MapperArgs<
150
+ TSlice extends SliceLike = SliceLike,
151
+ TContext = unknown,
152
+ > = SliceMapperArgs<TSlice, TContext>;
153
+
154
+ /**
155
+ * Unwraps a lazily loaded mapper module.
156
+ */
157
+ type ResolveLazyMapperModule<TMapper extends Mapper | LazyModule<Mapper>> =
158
+ TMapper extends LazyModule<Mapper>
159
+ ? Awaited<ReturnType<TMapper>> extends {
160
+ default: unknown;
161
+ }
162
+ ? Awaited<ReturnType<TMapper>>["default"]
163
+ : Awaited<ReturnType<TMapper>>
164
+ : TMapper;
165
+
166
+ /**
167
+ * Transforms a Slice into its mapped version.
168
+ */
169
+ type MapSliceLike<
170
+ TSliceLike extends SliceLike,
171
+ TMappers extends Mappers,
172
+ > = TSliceLike extends Slice
173
+ ? TSliceLike["slice_type"] extends keyof TMappers
174
+ ? Slice<TSliceLike["slice_type"]> &
175
+ MappedSliceLike &
176
+ Awaited<
177
+ ReturnType<
178
+ ResolveLazyMapperModule<TMappers[TSliceLike["slice_type"]]>
179
+ >
180
+ >
181
+ : TSliceLike
182
+ : TSliceLike extends SliceGraphQLLike
183
+ ? TSliceLike["type"] extends keyof TMappers
184
+ ? SliceGraphQLLike<TSliceLike["type"]> &
185
+ MappedSliceLike &
186
+ Awaited<
187
+ ReturnType<ResolveLazyMapperModule<TMappers[TSliceLike["type"]]>>
188
+ >
189
+ : TSliceLike
190
+ : never;
191
+
192
+ /**
193
+ * Transforms a Slice Zone using a set of mapping functions, one for each type
194
+ * of Slice. Mapping functions can be async.
195
+ *
196
+ * Whenever possible, use this function on the server to minimize client-side
197
+ * processing.
198
+ *
199
+ * @example
200
+ *
201
+ * ```typescript
202
+ * const mappedSliceZone = await unstable_mapSliceZone(page.data.slices, {
203
+ * code_block: ({ slice }) => ({
204
+ * codeHTML: await highlight(slice.primary.code),
205
+ * }),
206
+ * });
207
+ * ```
208
+ *
209
+ * @experimental Names and implementations may change in the future.
210
+ * `unstable_mapSliceZone()` does not follow SemVer.
211
+ */
212
+ export function unstable_mapSliceZone<
213
+ TSliceLike extends SliceLike,
214
+ TMappers extends Mappers,
215
+ TContext = unknown,
216
+ >(
217
+ sliceZone: SliceZoneLike<TSliceLike>,
218
+ mappers: TMappers,
219
+ context?: TContext,
220
+ ): Promise<MapSliceLike<TSliceLike, TMappers>[]> {
221
+ return Promise.all(
222
+ sliceZone.map(async (slice, index, slices) => {
223
+ const isRestSliceType = "slice_type" in slice;
224
+ const sliceType = isRestSliceType ? slice.slice_type : slice.type;
225
+
226
+ const mapper = mappers[sliceType];
227
+
228
+ if (!mapper) {
229
+ return slice;
230
+ }
231
+
232
+ const mapperArgs = { slice, slices, index, context };
233
+
234
+ // `result` may be a mapper function OR a module
235
+ // containing a mapper function.
236
+ let result = await mapper(mapperArgs);
237
+
238
+ // `result` is a module containing a mapper function,
239
+ // we need to dig out the mapper function. `result`
240
+ // will be reassigned with the mapper function's value.
241
+ if (
242
+ // `mapper.length < 1` ensures the given
243
+ // function is something of the form:
244
+ // `() => import(...)`
245
+ mapper.length < 1 &&
246
+ (typeof result === "function" ||
247
+ (typeof result === "object" && "default" in result))
248
+ ) {
249
+ result = "default" in result ? result.default : result;
250
+ result = await result(mapperArgs);
251
+ }
252
+
253
+ if (isRestSliceType) {
254
+ return {
255
+ __mapped: true,
256
+ id: slice.id,
257
+ slice_type: sliceType,
258
+ ...result,
259
+ };
260
+ } else {
261
+ return {
262
+ __mapped: true,
263
+ type: sliceType,
264
+ ...result,
265
+ };
266
+ }
267
+ }),
268
+ );
269
+ }
package/src/index.ts CHANGED
@@ -46,7 +46,6 @@ export type {
46
46
  FetchLike,
47
47
  HttpRequestLike,
48
48
  RequestInitLike,
49
- RequestInitLikeOrThunk,
50
49
  ResponseLike,
51
50
  } from "./createClient";
52
51
  export type {
@@ -69,6 +68,7 @@ export { asHTML } from "./helpers/asHTML";
69
68
  export { asImageSrc } from "./helpers/asImageSrc";
70
69
  export { asImageWidthSrcSet } from "./helpers/asImageWidthSrcSet";
71
70
  export { asImagePixelDensitySrcSet } from "./helpers/asImagePixelDensitySrcSet";
71
+ export { unstable_mapSliceZone } from "./helpers/unstable_mapSliceZone";
72
72
  export * as isFilled from "./helpers/isFilled";
73
73
 
74
74
  // Conversion helper.
@@ -8,12 +8,6 @@
8
8
  *
9
9
  * @returns `a` as a a thunk.
10
10
  */
11
- export const castThunk = <
12
- A,
13
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
14
- TArgs extends any[],
15
- >(
16
- a: A | ((...args: TArgs) => A),
17
- ): ((...args: TArgs) => A) => {
18
- return typeof a === "function" ? (a as (...args: TArgs) => A) : () => a;
11
+ export const castThunk = <A>(a: A | (() => A)): (() => A) => {
12
+ return typeof a === "function" ? (a as () => A) : () => a;
19
13
  };
@@ -21,6 +21,13 @@ export interface CustomTypeModel<
21
21
  // TODO: Revert to `label?: string | null` if `label` can be partial in: https://github.com/prismicio/prismic-types-internal/blob/HEAD/src/customtypes/CustomType.ts#L39
22
22
  label: string | null | undefined;
23
23
 
24
+ /**
25
+ * The format of the custom type model.
26
+ *
27
+ * Fallback to "custom" if undefined.
28
+ */
29
+ format?: "page" | "custom";
30
+
24
31
  /**
25
32
  * Determines if more than one document for the custom type can be created.
26
33
  */
@@ -2,6 +2,7 @@ import { AnyRegularField } from "./types";
2
2
 
3
3
  import { GroupField } from "./group";
4
4
  import { SliceZone } from "./sliceZone";
5
+ import { TimestampField } from "./timestamp";
5
6
 
6
7
  /**
7
8
  * Document metadata for a translation of a Prismic document.
@@ -46,11 +47,11 @@ export interface PrismicDocumentHeader<TypeEnum = string, LangEnum = string> {
46
47
  /**
47
48
  * The timestamp at which the document was first published.
48
49
  */
49
- first_publication_date: string;
50
+ first_publication_date: TimestampField<"filled">;
50
51
  /**
51
52
  * The timestamp at which the document was last published.
52
53
  */
53
- last_publication_date: string;
54
+ last_publication_date: TimestampField<"filled">;
54
55
  /**
55
56
  * Slugs associated with document.
56
57
  *