@prismicio/client 7.0.1 → 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.
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ function unstable_mapSliceZone(sliceZone, mappers, context) {
4
+ return Promise.all(sliceZone.map(async (slice, index, slices) => {
5
+ const isRestSliceType = "slice_type" in slice;
6
+ const sliceType = isRestSliceType ? slice.slice_type : slice.type;
7
+ const mapper = mappers[sliceType];
8
+ if (!mapper) {
9
+ return slice;
10
+ }
11
+ const mapperArgs = { slice, slices, index, context };
12
+ let result = await mapper(mapperArgs);
13
+ if (
14
+ // `mapper.length < 1` ensures the given
15
+ // function is something of the form:
16
+ // `() => import(...)`
17
+ mapper.length < 1 && (typeof result === "function" || typeof result === "object" && "default" in result)
18
+ ) {
19
+ result = "default" in result ? result.default : result;
20
+ result = await result(mapperArgs);
21
+ }
22
+ if (isRestSliceType) {
23
+ return {
24
+ __mapped: true,
25
+ id: slice.id,
26
+ slice_type: sliceType,
27
+ ...result
28
+ };
29
+ } else {
30
+ return {
31
+ __mapped: true,
32
+ type: sliceType,
33
+ ...result
34
+ };
35
+ }
36
+ }));
37
+ }
38
+ exports.unstable_mapSliceZone = unstable_mapSliceZone;
39
+ //# sourceMappingURL=unstable_mapSliceZone.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unstable_mapSliceZone.cjs","sources":["../../../src/helpers/unstable_mapSliceZone.ts"],"sourcesContent":["import { Slice } from \"../types/value/slice\";\n\n/**\n * Convert a value to a lazyily loaded module. This is useful when using\n * functions like `() => import(\"...\")`.\n */\ntype LazyModule<T> = () => Promise<T | { default: T }>;\n\n/**\n * Mark a type as potentially lazy-loaded via a module.\n */\ntype MaybeLazyModule<T> = T | LazyModule<T>;\n\n/**\n * Returns the type of a `SliceLike` type.\n *\n * @typeParam Slice - The Slice from which the type will be extracted.\n */\ntype ExtractSliceType<TSlice extends SliceLike> = TSlice extends Slice\n\t? TSlice[\"slice_type\"]\n\t: TSlice extends SliceGraphQLLike\n\t? TSlice[\"type\"]\n\t: never;\n\n/**\n * The minimum required properties to represent a Prismic Slice from the Prismic\n * GraphQL API for the `unstable_mapSliceZone()` helper.\n *\n * @typeParam SliceType - Type name of the Slice.\n */\ntype SliceGraphQLLike<TSliceType extends string = string> = {\n\ttype: Slice<TSliceType>[\"slice_type\"];\n};\n\n/**\n * The minimum required properties to represent a Prismic Slice for the\n * `unstable_mapSliceZone()` helper.\n *\n * If using Prismic's Rest API V2, use the `Slice` export from\n * `@prismicio/client` for a full interface.\n *\n * @typeParam SliceType - Type name of the Slice.\n */\ntype SliceLike<TSliceType extends string = string> =\n\t| Slice<TSliceType>\n\t| SliceGraphQLLike<TSliceType>;\n\n/**\n * A looser version of the `SliceZone` type from `@prismicio/client` using\n * `SliceLike`.\n *\n * If using Prismic's Rest API V2, use the `SliceZone` export from\n * `@prismicio/client` for the full type.\n *\n * @typeParam TSlice - The type(s) of a Slice in the Slice Zone.\n */\ntype SliceZoneLike<TSlice extends SliceLike = SliceLike> = readonly TSlice[];\n\n/**\n * A set of properties that identify a Slice as having been mapped. Consumers of\n * the mapped Slice Zone can use these properties to detect and specially handle\n * mapped Slices.\n */\ntype MappedSliceLike = {\n\t/**\n\t * If `true`, this Slice has been modified from its original value using a\n\t * mapper.\n\t *\n\t * @internal\n\t */\n\t__mapped: true;\n};\n\n/**\n * Arguments for a function mapping content from a Prismic Slice using the\n * `unstable_mapSliceZone()` helper.\n *\n * @typeParam TSlice - The Slice passed as a prop.\n * @typeParam TContext - Arbitrary data passed to `unstable_mapSliceZone()` and\n * made available to all Slice mappers.\n */\ntype SliceMapperArgs<\n\tTSlice extends SliceLike = SliceLike,\n\tTContext = unknown,\n> = {\n\t/**\n\t * Slice data.\n\t */\n\tslice: TSlice;\n\n\t/**\n\t * The index of the Slice in the Slice Zone.\n\t */\n\tindex: number;\n\n\t/**\n\t * All Slices from the Slice Zone to which the Slice belongs.\n\t */\n\t// TODO: We have to keep this list of Slices general due to circular\n\t// reference limtiations. If we had another generic to determine the full\n\t// union of Slice types, it would include TSlice. This causes TypeScript to\n\t// throw a compilation error.\n\tslices: SliceZoneLike<\n\t\tTSlice extends SliceGraphQLLike ? SliceGraphQLLike : Slice\n\t>;\n\n\t/**\n\t * Arbitrary data passed to `unstable_mapSliceZone()` and made available to\n\t * all Slice mappers.\n\t */\n\tcontext: TContext;\n};\n\n/**\n * A record of mappers.\n */\nexport type Mappers<\n\tTSlice extends SliceLike = SliceLike,\n\tTContext = unknown,\n> = {\n\t[P in ExtractSliceType<TSlice>]: MaybeLazyModule<\n\t\tMapper<\n\t\t\tExtract<TSlice, SliceLike<P>>,\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t\t\tany,\n\t\t\tTContext\n\t\t>\n\t>;\n};\n\n/**\n * A function that maps a Slice and its metadata to a modified version. The\n * return value will replace the Slice in the Slice Zone.\n */\nexport type Mapper<\n\tTSlice extends SliceLike = SliceLike,\n\tTMappedSlice extends Record<string, unknown> | undefined | void =\n\t\t| Record<string, unknown>\n\t\t| undefined\n\t\t| void,\n\tTContext = unknown,\n> = (\n\targs: MapperArgs<TSlice, TContext>,\n) => TMappedSlice | Promise<TMappedSlice>;\n\n/**\n * Arguments provided to a mapper function.\n */\nexport type MapperArgs<\n\tTSlice extends SliceLike = SliceLike,\n\tTContext = unknown,\n> = SliceMapperArgs<TSlice, TContext>;\n\n/**\n * Unwraps a lazily loaded mapper module.\n */\ntype ResolveLazyMapperModule<TMapper extends Mapper | LazyModule<Mapper>> =\n\tTMapper extends LazyModule<Mapper>\n\t\t? Awaited<ReturnType<TMapper>> extends {\n\t\t\t\tdefault: unknown;\n\t\t }\n\t\t\t? Awaited<ReturnType<TMapper>>[\"default\"]\n\t\t\t: Awaited<ReturnType<TMapper>>\n\t\t: TMapper;\n\n/**\n * Transforms a Slice into its mapped version.\n */\ntype MapSliceLike<\n\tTSliceLike extends SliceLike,\n\tTMappers extends Mappers,\n> = TSliceLike extends Slice\n\t? TSliceLike[\"slice_type\"] extends keyof TMappers\n\t\t? Slice<TSliceLike[\"slice_type\"]> &\n\t\t\t\tMappedSliceLike &\n\t\t\t\tAwaited<\n\t\t\t\t\tReturnType<\n\t\t\t\t\t\tResolveLazyMapperModule<TMappers[TSliceLike[\"slice_type\"]]>\n\t\t\t\t\t>\n\t\t\t\t>\n\t\t: TSliceLike\n\t: TSliceLike extends SliceGraphQLLike\n\t? TSliceLike[\"type\"] extends keyof TMappers\n\t\t? SliceGraphQLLike<TSliceLike[\"type\"]> &\n\t\t\t\tMappedSliceLike &\n\t\t\t\tAwaited<\n\t\t\t\t\tReturnType<ResolveLazyMapperModule<TMappers[TSliceLike[\"type\"]]>>\n\t\t\t\t>\n\t\t: TSliceLike\n\t: never;\n\n/**\n * Transforms a Slice Zone using a set of mapping functions, one for each type\n * of Slice. Mapping functions can be async.\n *\n * Whenever possible, use this function on the server to minimize client-side\n * processing.\n *\n * @example\n *\n * ```typescript\n * const mappedSliceZone = await unstable_mapSliceZone(page.data.slices, {\n * \tcode_block: ({ slice }) => ({\n * \t\tcodeHTML: await highlight(slice.primary.code),\n * \t}),\n * });\n * ```\n *\n * @experimental Names and implementations may change in the future.\n * `unstable_mapSliceZone()` does not follow SemVer.\n */\nexport function unstable_mapSliceZone<\n\tTSliceLike extends SliceLike,\n\tTMappers extends Mappers,\n\tTContext = unknown,\n>(\n\tsliceZone: SliceZoneLike<TSliceLike>,\n\tmappers: TMappers,\n\tcontext?: TContext,\n): Promise<MapSliceLike<TSliceLike, TMappers>[]> {\n\treturn Promise.all(\n\t\tsliceZone.map(async (slice, index, slices) => {\n\t\t\tconst isRestSliceType = \"slice_type\" in slice;\n\t\t\tconst sliceType = isRestSliceType ? slice.slice_type : slice.type;\n\n\t\t\tconst mapper = mappers[sliceType];\n\n\t\t\tif (!mapper) {\n\t\t\t\treturn slice;\n\t\t\t}\n\n\t\t\tconst mapperArgs = { slice, slices, index, context };\n\n\t\t\t// `result` may be a mapper function OR a module\n\t\t\t// containing a mapper function.\n\t\t\tlet result = await mapper(mapperArgs);\n\n\t\t\t// `result` is a module containing a mapper function,\n\t\t\t// we need to dig out the mapper function. `result`\n\t\t\t// will be reassigned with the mapper function's value.\n\t\t\tif (\n\t\t\t\t// `mapper.length < 1` ensures the given\n\t\t\t\t// function is something of the form:\n\t\t\t\t// `() => import(...)`\n\t\t\t\tmapper.length < 1 &&\n\t\t\t\t(typeof result === \"function\" ||\n\t\t\t\t\t(typeof result === \"object\" && \"default\" in result))\n\t\t\t) {\n\t\t\t\tresult = \"default\" in result ? result.default : result;\n\t\t\t\tresult = await result(mapperArgs);\n\t\t\t}\n\n\t\t\tif (isRestSliceType) {\n\t\t\t\treturn {\n\t\t\t\t\t__mapped: true,\n\t\t\t\t\tid: slice.id,\n\t\t\t\t\tslice_type: sliceType,\n\t\t\t\t\t...result,\n\t\t\t\t};\n\t\t\t} else {\n\t\t\t\treturn {\n\t\t\t\t\t__mapped: true,\n\t\t\t\t\ttype: sliceType,\n\t\t\t\t\t...result,\n\t\t\t\t};\n\t\t\t}\n\t\t}),\n\t);\n}\n"],"names":[],"mappings":";;AAmNgB,SAAA,sBAKf,WACA,SACA,SAAkB;AAElB,SAAO,QAAQ,IACd,UAAU,IAAI,OAAO,OAAO,OAAO,WAAU;AAC5C,UAAM,kBAAkB,gBAAgB;AACxC,UAAM,YAAY,kBAAkB,MAAM,aAAa,MAAM;AAEvD,UAAA,SAAS,QAAQ,SAAS;AAEhC,QAAI,CAAC,QAAQ;AACL,aAAA;AAAA,IACP;AAED,UAAM,aAAa,EAAE,OAAO,QAAQ,OAAO,QAAO;AAI9C,QAAA,SAAS,MAAM,OAAO,UAAU;AAKpC;AAAA;AAAA;AAAA;AAAA,MAIC,OAAO,SAAS,MACf,OAAO,WAAW,cACjB,OAAO,WAAW,YAAY,aAAa;AAAA,MAC5C;AACQ,eAAA,aAAa,SAAS,OAAO,UAAU;AACvC,eAAA,MAAM,OAAO,UAAU;AAAA,IAChC;AAED,QAAI,iBAAiB;AACb,aAAA;AAAA,QACN,UAAU;AAAA,QACV,IAAI,MAAM;AAAA,QACV,YAAY;AAAA,QACZ,GAAG;AAAA,MAAA;AAAA,WAEE;AACC,aAAA;AAAA,QACN,UAAU;AAAA,QACV,MAAM;AAAA,QACN,GAAG;AAAA,MAAA;AAAA,IAEJ;AAAA,EACD,CAAA,CAAC;AAEJ;;"}
@@ -0,0 +1,135 @@
1
+ import { Slice } from "../types/value/slice";
2
+ /**
3
+ * Convert a value to a lazyily loaded module. This is useful when using
4
+ * functions like `() => import("...")`.
5
+ */
6
+ type LazyModule<T> = () => Promise<T | {
7
+ 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
+ * Returns the type of a `SliceLike` type.
15
+ *
16
+ * @typeParam Slice - The Slice from which the type will be extracted.
17
+ */
18
+ type ExtractSliceType<TSlice extends SliceLike> = TSlice extends Slice ? TSlice["slice_type"] : TSlice extends SliceGraphQLLike ? TSlice["type"] : never;
19
+ /**
20
+ * The minimum required properties to represent a Prismic Slice from the Prismic
21
+ * GraphQL API for the `unstable_mapSliceZone()` helper.
22
+ *
23
+ * @typeParam SliceType - Type name of the Slice.
24
+ */
25
+ type SliceGraphQLLike<TSliceType extends string = string> = {
26
+ type: Slice<TSliceType>["slice_type"];
27
+ };
28
+ /**
29
+ * The minimum required properties to represent a Prismic Slice for the
30
+ * `unstable_mapSliceZone()` helper.
31
+ *
32
+ * If using Prismic's Rest API V2, use the `Slice` export from
33
+ * `@prismicio/client` for a full interface.
34
+ *
35
+ * @typeParam SliceType - Type name of the Slice.
36
+ */
37
+ type SliceLike<TSliceType extends string = string> = Slice<TSliceType> | SliceGraphQLLike<TSliceType>;
38
+ /**
39
+ * A looser version of the `SliceZone` type from `@prismicio/client` using
40
+ * `SliceLike`.
41
+ *
42
+ * If using Prismic's Rest API V2, use the `SliceZone` export from
43
+ * `@prismicio/client` for the full type.
44
+ *
45
+ * @typeParam TSlice - The type(s) of a Slice in the Slice Zone.
46
+ */
47
+ type SliceZoneLike<TSlice extends SliceLike = SliceLike> = readonly TSlice[];
48
+ /**
49
+ * A set of properties that identify a Slice as having been mapped. Consumers of
50
+ * the mapped Slice Zone can use these properties to detect and specially handle
51
+ * mapped Slices.
52
+ */
53
+ type MappedSliceLike = {
54
+ /**
55
+ * If `true`, this Slice has been modified from its original value using a
56
+ * mapper.
57
+ *
58
+ * @internal
59
+ */
60
+ __mapped: true;
61
+ };
62
+ /**
63
+ * Arguments for a function mapping content from a Prismic Slice using the
64
+ * `unstable_mapSliceZone()` helper.
65
+ *
66
+ * @typeParam TSlice - The Slice passed as a prop.
67
+ * @typeParam TContext - Arbitrary data passed to `unstable_mapSliceZone()` and
68
+ * made available to all Slice mappers.
69
+ */
70
+ type SliceMapperArgs<TSlice extends SliceLike = SliceLike, TContext = unknown> = {
71
+ /**
72
+ * Slice data.
73
+ */
74
+ slice: TSlice;
75
+ /**
76
+ * The index of the Slice in the Slice Zone.
77
+ */
78
+ index: number;
79
+ /**
80
+ * All Slices from the Slice Zone to which the Slice belongs.
81
+ */
82
+ slices: SliceZoneLike<TSlice extends SliceGraphQLLike ? SliceGraphQLLike : Slice>;
83
+ /**
84
+ * Arbitrary data passed to `unstable_mapSliceZone()` and made available to
85
+ * all Slice mappers.
86
+ */
87
+ context: TContext;
88
+ };
89
+ /**
90
+ * A record of mappers.
91
+ */
92
+ export type Mappers<TSlice extends SliceLike = SliceLike, TContext = unknown> = {
93
+ [P in ExtractSliceType<TSlice>]: MaybeLazyModule<Mapper<Extract<TSlice, SliceLike<P>>, any, TContext>>;
94
+ };
95
+ /**
96
+ * A function that maps a Slice and its metadata to a modified version. The
97
+ * return value will replace the Slice in the Slice Zone.
98
+ */
99
+ export type Mapper<TSlice extends SliceLike = SliceLike, TMappedSlice extends Record<string, unknown> | undefined | void = Record<string, unknown> | undefined | void, TContext = unknown> = (args: MapperArgs<TSlice, TContext>) => TMappedSlice | Promise<TMappedSlice>;
100
+ /**
101
+ * Arguments provided to a mapper function.
102
+ */
103
+ export type MapperArgs<TSlice extends SliceLike = SliceLike, TContext = unknown> = SliceMapperArgs<TSlice, TContext>;
104
+ /**
105
+ * Unwraps a lazily loaded mapper module.
106
+ */
107
+ type ResolveLazyMapperModule<TMapper extends Mapper | LazyModule<Mapper>> = TMapper extends LazyModule<Mapper> ? Awaited<ReturnType<TMapper>> extends {
108
+ default: unknown;
109
+ } ? Awaited<ReturnType<TMapper>>["default"] : Awaited<ReturnType<TMapper>> : TMapper;
110
+ /**
111
+ * Transforms a Slice into its mapped version.
112
+ */
113
+ type MapSliceLike<TSliceLike extends SliceLike, TMappers extends Mappers> = TSliceLike extends Slice ? TSliceLike["slice_type"] extends keyof TMappers ? Slice<TSliceLike["slice_type"]> & MappedSliceLike & Awaited<ReturnType<ResolveLazyMapperModule<TMappers[TSliceLike["slice_type"]]>>> : TSliceLike : TSliceLike extends SliceGraphQLLike ? TSliceLike["type"] extends keyof TMappers ? SliceGraphQLLike<TSliceLike["type"]> & MappedSliceLike & Awaited<ReturnType<ResolveLazyMapperModule<TMappers[TSliceLike["type"]]>>> : TSliceLike : never;
114
+ /**
115
+ * Transforms a Slice Zone using a set of mapping functions, one for each type
116
+ * of Slice. Mapping functions can be async.
117
+ *
118
+ * Whenever possible, use this function on the server to minimize client-side
119
+ * processing.
120
+ *
121
+ * @example
122
+ *
123
+ * ```typescript
124
+ * const mappedSliceZone = await unstable_mapSliceZone(page.data.slices, {
125
+ * code_block: ({ slice }) => ({
126
+ * codeHTML: await highlight(slice.primary.code),
127
+ * }),
128
+ * });
129
+ * ```
130
+ *
131
+ * @experimental Names and implementations may change in the future.
132
+ * `unstable_mapSliceZone()` does not follow SemVer.
133
+ */
134
+ export declare function unstable_mapSliceZone<TSliceLike extends SliceLike, TMappers extends Mappers, TContext = unknown>(sliceZone: SliceZoneLike<TSliceLike>, mappers: TMappers, context?: TContext): Promise<MapSliceLike<TSliceLike, TMappers>[]>;
135
+ export {};
@@ -0,0 +1,39 @@
1
+ function unstable_mapSliceZone(sliceZone, mappers, context) {
2
+ return Promise.all(sliceZone.map(async (slice, index, slices) => {
3
+ const isRestSliceType = "slice_type" in slice;
4
+ const sliceType = isRestSliceType ? slice.slice_type : slice.type;
5
+ const mapper = mappers[sliceType];
6
+ if (!mapper) {
7
+ return slice;
8
+ }
9
+ const mapperArgs = { slice, slices, index, context };
10
+ let result = await mapper(mapperArgs);
11
+ if (
12
+ // `mapper.length < 1` ensures the given
13
+ // function is something of the form:
14
+ // `() => import(...)`
15
+ mapper.length < 1 && (typeof result === "function" || typeof result === "object" && "default" in result)
16
+ ) {
17
+ result = "default" in result ? result.default : result;
18
+ result = await result(mapperArgs);
19
+ }
20
+ if (isRestSliceType) {
21
+ return {
22
+ __mapped: true,
23
+ id: slice.id,
24
+ slice_type: sliceType,
25
+ ...result
26
+ };
27
+ } else {
28
+ return {
29
+ __mapped: true,
30
+ type: sliceType,
31
+ ...result
32
+ };
33
+ }
34
+ }));
35
+ }
36
+ export {
37
+ unstable_mapSliceZone
38
+ };
39
+ //# sourceMappingURL=unstable_mapSliceZone.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unstable_mapSliceZone.js","sources":["../../../src/helpers/unstable_mapSliceZone.ts"],"sourcesContent":["import { Slice } from \"../types/value/slice\";\n\n/**\n * Convert a value to a lazyily loaded module. This is useful when using\n * functions like `() => import(\"...\")`.\n */\ntype LazyModule<T> = () => Promise<T | { default: T }>;\n\n/**\n * Mark a type as potentially lazy-loaded via a module.\n */\ntype MaybeLazyModule<T> = T | LazyModule<T>;\n\n/**\n * Returns the type of a `SliceLike` type.\n *\n * @typeParam Slice - The Slice from which the type will be extracted.\n */\ntype ExtractSliceType<TSlice extends SliceLike> = TSlice extends Slice\n\t? TSlice[\"slice_type\"]\n\t: TSlice extends SliceGraphQLLike\n\t? TSlice[\"type\"]\n\t: never;\n\n/**\n * The minimum required properties to represent a Prismic Slice from the Prismic\n * GraphQL API for the `unstable_mapSliceZone()` helper.\n *\n * @typeParam SliceType - Type name of the Slice.\n */\ntype SliceGraphQLLike<TSliceType extends string = string> = {\n\ttype: Slice<TSliceType>[\"slice_type\"];\n};\n\n/**\n * The minimum required properties to represent a Prismic Slice for the\n * `unstable_mapSliceZone()` helper.\n *\n * If using Prismic's Rest API V2, use the `Slice` export from\n * `@prismicio/client` for a full interface.\n *\n * @typeParam SliceType - Type name of the Slice.\n */\ntype SliceLike<TSliceType extends string = string> =\n\t| Slice<TSliceType>\n\t| SliceGraphQLLike<TSliceType>;\n\n/**\n * A looser version of the `SliceZone` type from `@prismicio/client` using\n * `SliceLike`.\n *\n * If using Prismic's Rest API V2, use the `SliceZone` export from\n * `@prismicio/client` for the full type.\n *\n * @typeParam TSlice - The type(s) of a Slice in the Slice Zone.\n */\ntype SliceZoneLike<TSlice extends SliceLike = SliceLike> = readonly TSlice[];\n\n/**\n * A set of properties that identify a Slice as having been mapped. Consumers of\n * the mapped Slice Zone can use these properties to detect and specially handle\n * mapped Slices.\n */\ntype MappedSliceLike = {\n\t/**\n\t * If `true`, this Slice has been modified from its original value using a\n\t * mapper.\n\t *\n\t * @internal\n\t */\n\t__mapped: true;\n};\n\n/**\n * Arguments for a function mapping content from a Prismic Slice using the\n * `unstable_mapSliceZone()` helper.\n *\n * @typeParam TSlice - The Slice passed as a prop.\n * @typeParam TContext - Arbitrary data passed to `unstable_mapSliceZone()` and\n * made available to all Slice mappers.\n */\ntype SliceMapperArgs<\n\tTSlice extends SliceLike = SliceLike,\n\tTContext = unknown,\n> = {\n\t/**\n\t * Slice data.\n\t */\n\tslice: TSlice;\n\n\t/**\n\t * The index of the Slice in the Slice Zone.\n\t */\n\tindex: number;\n\n\t/**\n\t * All Slices from the Slice Zone to which the Slice belongs.\n\t */\n\t// TODO: We have to keep this list of Slices general due to circular\n\t// reference limtiations. If we had another generic to determine the full\n\t// union of Slice types, it would include TSlice. This causes TypeScript to\n\t// throw a compilation error.\n\tslices: SliceZoneLike<\n\t\tTSlice extends SliceGraphQLLike ? SliceGraphQLLike : Slice\n\t>;\n\n\t/**\n\t * Arbitrary data passed to `unstable_mapSliceZone()` and made available to\n\t * all Slice mappers.\n\t */\n\tcontext: TContext;\n};\n\n/**\n * A record of mappers.\n */\nexport type Mappers<\n\tTSlice extends SliceLike = SliceLike,\n\tTContext = unknown,\n> = {\n\t[P in ExtractSliceType<TSlice>]: MaybeLazyModule<\n\t\tMapper<\n\t\t\tExtract<TSlice, SliceLike<P>>,\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t\t\tany,\n\t\t\tTContext\n\t\t>\n\t>;\n};\n\n/**\n * A function that maps a Slice and its metadata to a modified version. The\n * return value will replace the Slice in the Slice Zone.\n */\nexport type Mapper<\n\tTSlice extends SliceLike = SliceLike,\n\tTMappedSlice extends Record<string, unknown> | undefined | void =\n\t\t| Record<string, unknown>\n\t\t| undefined\n\t\t| void,\n\tTContext = unknown,\n> = (\n\targs: MapperArgs<TSlice, TContext>,\n) => TMappedSlice | Promise<TMappedSlice>;\n\n/**\n * Arguments provided to a mapper function.\n */\nexport type MapperArgs<\n\tTSlice extends SliceLike = SliceLike,\n\tTContext = unknown,\n> = SliceMapperArgs<TSlice, TContext>;\n\n/**\n * Unwraps a lazily loaded mapper module.\n */\ntype ResolveLazyMapperModule<TMapper extends Mapper | LazyModule<Mapper>> =\n\tTMapper extends LazyModule<Mapper>\n\t\t? Awaited<ReturnType<TMapper>> extends {\n\t\t\t\tdefault: unknown;\n\t\t }\n\t\t\t? Awaited<ReturnType<TMapper>>[\"default\"]\n\t\t\t: Awaited<ReturnType<TMapper>>\n\t\t: TMapper;\n\n/**\n * Transforms a Slice into its mapped version.\n */\ntype MapSliceLike<\n\tTSliceLike extends SliceLike,\n\tTMappers extends Mappers,\n> = TSliceLike extends Slice\n\t? TSliceLike[\"slice_type\"] extends keyof TMappers\n\t\t? Slice<TSliceLike[\"slice_type\"]> &\n\t\t\t\tMappedSliceLike &\n\t\t\t\tAwaited<\n\t\t\t\t\tReturnType<\n\t\t\t\t\t\tResolveLazyMapperModule<TMappers[TSliceLike[\"slice_type\"]]>\n\t\t\t\t\t>\n\t\t\t\t>\n\t\t: TSliceLike\n\t: TSliceLike extends SliceGraphQLLike\n\t? TSliceLike[\"type\"] extends keyof TMappers\n\t\t? SliceGraphQLLike<TSliceLike[\"type\"]> &\n\t\t\t\tMappedSliceLike &\n\t\t\t\tAwaited<\n\t\t\t\t\tReturnType<ResolveLazyMapperModule<TMappers[TSliceLike[\"type\"]]>>\n\t\t\t\t>\n\t\t: TSliceLike\n\t: never;\n\n/**\n * Transforms a Slice Zone using a set of mapping functions, one for each type\n * of Slice. Mapping functions can be async.\n *\n * Whenever possible, use this function on the server to minimize client-side\n * processing.\n *\n * @example\n *\n * ```typescript\n * const mappedSliceZone = await unstable_mapSliceZone(page.data.slices, {\n * \tcode_block: ({ slice }) => ({\n * \t\tcodeHTML: await highlight(slice.primary.code),\n * \t}),\n * });\n * ```\n *\n * @experimental Names and implementations may change in the future.\n * `unstable_mapSliceZone()` does not follow SemVer.\n */\nexport function unstable_mapSliceZone<\n\tTSliceLike extends SliceLike,\n\tTMappers extends Mappers,\n\tTContext = unknown,\n>(\n\tsliceZone: SliceZoneLike<TSliceLike>,\n\tmappers: TMappers,\n\tcontext?: TContext,\n): Promise<MapSliceLike<TSliceLike, TMappers>[]> {\n\treturn Promise.all(\n\t\tsliceZone.map(async (slice, index, slices) => {\n\t\t\tconst isRestSliceType = \"slice_type\" in slice;\n\t\t\tconst sliceType = isRestSliceType ? slice.slice_type : slice.type;\n\n\t\t\tconst mapper = mappers[sliceType];\n\n\t\t\tif (!mapper) {\n\t\t\t\treturn slice;\n\t\t\t}\n\n\t\t\tconst mapperArgs = { slice, slices, index, context };\n\n\t\t\t// `result` may be a mapper function OR a module\n\t\t\t// containing a mapper function.\n\t\t\tlet result = await mapper(mapperArgs);\n\n\t\t\t// `result` is a module containing a mapper function,\n\t\t\t// we need to dig out the mapper function. `result`\n\t\t\t// will be reassigned with the mapper function's value.\n\t\t\tif (\n\t\t\t\t// `mapper.length < 1` ensures the given\n\t\t\t\t// function is something of the form:\n\t\t\t\t// `() => import(...)`\n\t\t\t\tmapper.length < 1 &&\n\t\t\t\t(typeof result === \"function\" ||\n\t\t\t\t\t(typeof result === \"object\" && \"default\" in result))\n\t\t\t) {\n\t\t\t\tresult = \"default\" in result ? result.default : result;\n\t\t\t\tresult = await result(mapperArgs);\n\t\t\t}\n\n\t\t\tif (isRestSliceType) {\n\t\t\t\treturn {\n\t\t\t\t\t__mapped: true,\n\t\t\t\t\tid: slice.id,\n\t\t\t\t\tslice_type: sliceType,\n\t\t\t\t\t...result,\n\t\t\t\t};\n\t\t\t} else {\n\t\t\t\treturn {\n\t\t\t\t\t__mapped: true,\n\t\t\t\t\ttype: sliceType,\n\t\t\t\t\t...result,\n\t\t\t\t};\n\t\t\t}\n\t\t}),\n\t);\n}\n"],"names":[],"mappings":"AAmNgB,SAAA,sBAKf,WACA,SACA,SAAkB;AAElB,SAAO,QAAQ,IACd,UAAU,IAAI,OAAO,OAAO,OAAO,WAAU;AAC5C,UAAM,kBAAkB,gBAAgB;AACxC,UAAM,YAAY,kBAAkB,MAAM,aAAa,MAAM;AAEvD,UAAA,SAAS,QAAQ,SAAS;AAEhC,QAAI,CAAC,QAAQ;AACL,aAAA;AAAA,IACP;AAED,UAAM,aAAa,EAAE,OAAO,QAAQ,OAAO,QAAO;AAI9C,QAAA,SAAS,MAAM,OAAO,UAAU;AAKpC;AAAA;AAAA;AAAA;AAAA,MAIC,OAAO,SAAS,MACf,OAAO,WAAW,cACjB,OAAO,WAAW,YAAY,aAAa;AAAA,MAC5C;AACQ,eAAA,aAAa,SAAS,OAAO,UAAU;AACvC,eAAA,MAAM,OAAO,UAAU;AAAA,IAChC;AAED,QAAI,iBAAiB;AACb,aAAA;AAAA,QACN,UAAU;AAAA,QACV,IAAI,MAAM;AAAA,QACV,YAAY;AAAA,QACZ,GAAG;AAAA,MAAA;AAAA,WAEE;AACC,aAAA;AAAA,QACN,UAAU;AAAA,QACV,MAAM;AAAA,QACN,GAAG;AAAA,MAAA;AAAA,IAEJ;AAAA,EACD,CAAA,CAAC;AAEJ;"}
package/dist/index.cjs CHANGED
@@ -18,6 +18,7 @@ const asHTML = require("./helpers/asHTML.cjs");
18
18
  const asImageSrc = require("./helpers/asImageSrc.cjs");
19
19
  const asImageWidthSrcSet = require("./helpers/asImageWidthSrcSet.cjs");
20
20
  const asImagePixelDensitySrcSet = require("./helpers/asImagePixelDensitySrcSet.cjs");
21
+ const unstable_mapSliceZone = require("./helpers/unstable_mapSliceZone.cjs");
21
22
  const isFilled = require("./helpers/isFilled.cjs");
22
23
  const documentToLinkField = require("./helpers/documentToLinkField.cjs");
23
24
  const richtext = require("@prismicio/richtext");
@@ -53,6 +54,7 @@ exports.asHTML = asHTML.asHTML;
53
54
  exports.asImageSrc = asImageSrc.asImageSrc;
54
55
  exports.asImageWidthSrcSet = asImageWidthSrcSet.asImageWidthSrcSet;
55
56
  exports.asImagePixelDensitySrcSet = asImagePixelDensitySrcSet.asImagePixelDensitySrcSet;
57
+ exports.unstable_mapSliceZone = unstable_mapSliceZone.unstable_mapSliceZone;
56
58
  exports.isFilled = isFilled;
57
59
  exports.documentToLinkField = documentToLinkField.documentToLinkField;
58
60
  Object.defineProperty(exports, "Element", {
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../../src/index.ts"],"sourcesContent":["// Imports are used for deprecations.\nimport type { CustomTypeModelIntegrationField } from \"./types/model/integration\";\nimport type { IntegrationField } from \"./types/value/integration\";\n\nimport type {\n\tHTMLRichTextFunctionSerializer,\n\tHTMLRichTextMapSerializer,\n} from \"./helpers/asHTML\";\n\nimport { filter } from \"./filter\";\n\n//=============================================================================\n// Client - Query content from Prismic.\n//=============================================================================\n\n// Primary Client API.\nexport { createClient, Client } from \"./createClient\";\n\n// API endpoint helpers.\nexport { getRepositoryEndpoint } from \"./getRepositoryEndpoint\";\nexport { getRepositoryName } from \"./getRepositoryName\";\nexport { getGraphQLEndpoint } from \"./getGraphQLEndpoint\";\nexport { isRepositoryName } from \"./isRepositoryName\";\nexport { isRepositoryEndpoint } from \"./isRepositoryEndpoint\";\nexport { buildQueryURL } from \"./buildQueryURL\";\n\n// Toolbar helpers.\nexport { getToolbarSrc } from \"./getToolbarSrc\";\n\n// Query filters API.\n/**\n * @deprecated Renamed to `filter`\n */\n// TODO: Remove when we remove support for deprecated `predicate` export.\nconst predicate = filter;\nexport { filter, predicate };\n\n// A collection of well-known cookie names shared between Prismic libraries and systems.\nexport * as cookie from \"./cookie\";\n\n// General types used to query content from Prismic. These are made public to allow users to better type their projects.\nexport type {\n\tAbortSignalLike,\n\tClientConfig,\n\tCreateClient,\n\tFetchLike,\n\tHttpRequestLike,\n\tRequestInitLike,\n\tResponseLike,\n} from \"./createClient\";\nexport type {\n\tBuildQueryURLArgs,\n\tOrdering,\n\tQueryParams,\n\tRoute,\n} from \"./buildQueryURL\";\n\n//=============================================================================\n// Helpers - Manipulate content from Prismic.\n//=============================================================================\n\n// Primary Helpers API.\nexport { asDate } from \"./helpers/asDate\";\nexport { asLink } from \"./helpers/asLink\";\nexport { asLinkAttrs } from \"./helpers/asLinkAttrs\";\nexport { asText } from \"./helpers/asText\";\nexport { asHTML } from \"./helpers/asHTML\";\nexport { asImageSrc } from \"./helpers/asImageSrc\";\nexport { asImageWidthSrcSet } from \"./helpers/asImageWidthSrcSet\";\nexport { asImagePixelDensitySrcSet } from \"./helpers/asImagePixelDensitySrcSet\";\nexport * as isFilled from \"./helpers/isFilled\";\n\n// Conversion helper.\nexport { documentToLinkField } from \"./helpers/documentToLinkField\";\n\n// RichText element types.\nexport { Element } from \"@prismicio/richtext\";\n\nexport type { LinkResolverFunction } from \"./helpers/asLink\";\nexport type { AsLinkAttrsConfig } from \"./helpers/asLinkAttrs\";\n\n/**\n * @deprecated Renamed to `HTMLRichTextMapSerializer`\n */\ntype HTMLMapSerializer = HTMLRichTextMapSerializer;\n/**\n * @deprecated Renamed to `HTMLRichTextFunctionSerializer`\n */\ntype HTMLFunctionSerializer = HTMLRichTextFunctionSerializer;\nexport type {\n\tHTMLRichTextMapSerializer,\n\tHTMLRichTextFunctionSerializer,\n\tHTMLMapSerializer,\n\tHTMLFunctionSerializer,\n};\nexport type { HTMLRichTextSerializer } from \"./helpers/asHTML\";\n\n//=============================================================================\n// Errors - Custom errors for Prismic APIs.\n//=============================================================================\n\nexport { PrismicError } from \"./errors/PrismicError\";\nexport { ForbiddenError } from \"./errors/ForbiddenError\";\nexport { NotFoundError } from \"./errors/NotFoundError\";\nexport { ParsingError } from \"./errors/ParsingError\";\n\n//=============================================================================\n// Types - Types representing Prismic content, models, and API payloads.\n//=============================================================================\n\n// Values - Types representing Prismic content.\nexport { RichTextNodeType } from \"./types/value/richText\";\nexport { LinkType } from \"./types/value/link\";\nexport { OEmbedType } from \"./types/value/embed\";\n\nexport type {\n\tPrismicDocument,\n\tPrismicDocumentWithUID,\n\tPrismicDocumentWithoutUID,\n\tPrismicDocumentHeader,\n\tAlternateLanguage,\n} from \"./types/value/document\";\n\nexport type {\n\t// RichText & Title\n\tRichTextField,\n\t// RichText & Title (block nodes)\n\tRTTextNodeBase,\n\tRTHeading1Node,\n\tRTHeading2Node,\n\tRTHeading3Node,\n\tRTHeading4Node,\n\tRTHeading5Node,\n\tRTHeading6Node,\n\tRTParagraphNode,\n\tRTPreformattedNode,\n\tRTListItemNode,\n\tRTOListItemNode,\n\t// RichText & Title (span nodes)\n\tRTSpanNodeBase,\n\tRTStrongNode,\n\tRTEmNode,\n\tRTLabelNode,\n\t// RichText & Title (media nodes)\n\tRTImageNode,\n\tRTEmbedNode,\n\t// RichText & Title (link nodes)\n\tRTLinkNode,\n\t// RichText & Title (serialization related nodes)\n\tRTListNode,\n\tRTOListNode,\n\tRTSpanNode,\n\t// RichText & Title (helpers)\n\tRTNode,\n\tRTTextNode,\n\tRTBlockNode,\n\tRTInlineNode,\n\tRTAnyNode,\n} from \"./types/value/richText\";\nexport type { TitleField } from \"./types/value/title\";\n\nexport type {\n\tImageField,\n\tImageFieldImage,\n\tFilledImageFieldImage,\n\tEmptyImageFieldImage,\n} from \"./types/value/image\";\n\nexport type {\n\tEmptyLinkField,\n\tLinkField,\n\tFilledLinkToWebField,\n} from \"./types/value/link\";\nexport type {\n\tContentRelationshipField,\n\tFilledContentRelationshipField,\n} from \"./types/value/contentRelationship\";\nexport type {\n\tLinkToMediaField,\n\tFilledLinkToMediaField,\n} from \"./types/value/linkToMedia\";\n\nexport type {\n\tOEmbedExtra,\n\tPhotoOEmbed,\n\tVideoOEmbed,\n\tLinkOEmbed,\n\tRichOEmbed,\n\tAnyOEmbed,\n\tEmbedField,\n} from \"./types/value/embed\";\n\nexport type { BooleanField } from \"./types/value/boolean\";\nexport type { ColorField } from \"./types/value/color\";\nexport type { DateField } from \"./types/value/date\";\nexport type { KeyTextField } from \"./types/value/keyText\";\nexport type { NumberField } from \"./types/value/number\";\nexport type { SelectField } from \"./types/value/select\";\nexport type { TimestampField } from \"./types/value/timestamp\";\nexport type { GeoPointField } from \"./types/value/geoPoint\";\n\n/**\n * @deprecated Renamed to `IntegrationField`\n */\n// TODO: Remove when we remove support for deprecated `IntegrationFields` export.\ntype IntegrationFields = IntegrationField;\nexport { IntegrationField, IntegrationFields };\n\nexport type { GroupField } from \"./types/value/group\";\n\nexport type { SliceZone } from \"./types/value/sliceZone\";\nexport type { Slice } from \"./types/value/slice\";\nexport type { SharedSlice } from \"./types/value/sharedSlice\";\nexport type { SharedSliceVariation } from \"./types/value/sharedSliceVariation\";\n\nexport type { FieldState, AnyRegularField } from \"./types/value/types\";\n\n// Models - Types representing Prismic content models.\nexport { CustomTypeModelFieldType } from \"./types/model/types\";\nexport { CustomTypeModelLinkSelectType } from \"./types/model/link\";\nexport { CustomTypeModelSliceType } from \"./types/model/sliceZone\";\nexport { CustomTypeModelSliceDisplay } from \"./types/model/slice\";\n\nexport type {\n\tCustomTypeModel,\n\tCustomTypeModelDefinition,\n\tCustomTypeModelTab,\n} from \"./types/model/customType\";\n\nexport type {\n\tCustomTypeModelRichTextField,\n\tCustomTypeModelRichTextMultiField,\n\tCustomTypeModelRichTextSingleField,\n} from \"./types/model/richText\";\nexport type { CustomTypeModelTitleField } from \"./types/model/title\";\n\nexport type {\n\tCustomTypeModelImageField,\n\tCustomTypeModelImageConstraint,\n\tCustomTypeModelImageThumbnail,\n} from \"./types/model/image\";\n\nexport type { CustomTypeModelContentRelationshipField } from \"./types/model/contentRelationship\";\nexport type { CustomTypeModelLinkField } from \"./types/model/link\";\nexport type { CustomTypeModelLinkToMediaField } from \"./types/model/linkToMedia\";\n\nexport type { CustomTypeModelEmbedField } from \"./types/model/embed\";\n\nexport type { CustomTypeModelBooleanField } from \"./types/model/boolean\";\nexport type { CustomTypeModelColorField } from \"./types/model/color\";\nexport type { CustomTypeModelDateField } from \"./types/model/date\";\nexport type { CustomTypeModelKeyTextField } from \"./types/model/keyText\";\nexport type { CustomTypeModelNumberField } from \"./types/model/number\";\nexport type { CustomTypeModelSelectField } from \"./types/model/select\";\nexport type { CustomTypeModelTimestampField } from \"./types/model/timestamp\";\nexport type { CustomTypeModelGeoPointField } from \"./types/model/geoPoint\";\n\n/**\n * @deprecated Renamed to `CustomTypeModelIntegrationField`.\n */\n// TODO: Remove when we remove support for deprecated `CustomTypeModelIntegrationField` export.\ntype CustomTypeModelIntegrationFieldsField = CustomTypeModelIntegrationField;\nexport {\n\tCustomTypeModelIntegrationField,\n\tCustomTypeModelIntegrationFieldsField,\n};\nexport type { CustomTypeModelGroupField } from \"./types/model/group\";\nexport type {\n\tCustomTypeModelSliceZoneField,\n\tCustomTypeModelSliceLabel,\n\tCustomTypeModelSharedSlice,\n} from \"./types/model/sliceZone\";\nexport type {\n\tCustomTypeModelSlice,\n\tCustomTypeModelLegacySlice,\n} from \"./types/model/slice\";\nexport type { SharedSliceModel } from \"./types/model/sharedSlice\";\nexport type { SharedSliceModelVariation } from \"./types/model/sharedSliceVariation\";\n\nexport type { CustomTypeModelUIDField } from \"./types/model/uid\";\n\nexport type { CustomTypeModelRangeField } from \"./types/model/range\";\nexport type { CustomTypeModelSeparatorField } from \"./types/model/separator\";\n\nexport type {\n\tCustomTypeModelField,\n\tCustomTypeModelFieldForGroup,\n} from \"./types/model/types\";\n\n// API - Types representing Prismic Rest API V2 responses.\nexport type { Query } from \"./types/api/query\";\n\nexport type { Ref } from \"./types/api/ref\";\n\nexport type { Release } from \"./types/api/release\";\n\nexport type {\n\tRepository,\n\tLanguage,\n\tForm,\n\tFormField,\n} from \"./types/api/repository\";\n\nexport type { Tags } from \"./types/api/tags\";\n\n// Webhook - Types representing Prismic webhooks.\nexport { WebhookType } from \"./types/webhook/types\";\n\nexport type { WebhookBody } from \"./types/webhook/types\";\n\nexport type { WebhookBodyAPIUpdate } from \"./types/webhook/apiUpdate\";\n\nexport type { WebhookBodyTestTrigger } from \"./types/webhook/testTrigger\";\n"],"names":["filter"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCA,MAAM,YAAYA,OAAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.cjs","sources":["../../src/index.ts"],"sourcesContent":["// Imports are used for deprecations.\nimport type { CustomTypeModelIntegrationField } from \"./types/model/integration\";\nimport type { IntegrationField } from \"./types/value/integration\";\n\nimport type {\n\tHTMLRichTextFunctionSerializer,\n\tHTMLRichTextMapSerializer,\n} from \"./helpers/asHTML\";\n\nimport { filter } from \"./filter\";\n\n//=============================================================================\n// Client - Query content from Prismic.\n//=============================================================================\n\n// Primary Client API.\nexport { createClient, Client } from \"./createClient\";\n\n// API endpoint helpers.\nexport { getRepositoryEndpoint } from \"./getRepositoryEndpoint\";\nexport { getRepositoryName } from \"./getRepositoryName\";\nexport { getGraphQLEndpoint } from \"./getGraphQLEndpoint\";\nexport { isRepositoryName } from \"./isRepositoryName\";\nexport { isRepositoryEndpoint } from \"./isRepositoryEndpoint\";\nexport { buildQueryURL } from \"./buildQueryURL\";\n\n// Toolbar helpers.\nexport { getToolbarSrc } from \"./getToolbarSrc\";\n\n// Query filters API.\n/**\n * @deprecated Renamed to `filter`\n */\n// TODO: Remove when we remove support for deprecated `predicate` export.\nconst predicate = filter;\nexport { filter, predicate };\n\n// A collection of well-known cookie names shared between Prismic libraries and systems.\nexport * as cookie from \"./cookie\";\n\n// General types used to query content from Prismic. These are made public to allow users to better type their projects.\nexport type {\n\tAbortSignalLike,\n\tClientConfig,\n\tCreateClient,\n\tFetchLike,\n\tHttpRequestLike,\n\tRequestInitLike,\n\tResponseLike,\n} from \"./createClient\";\nexport type {\n\tBuildQueryURLArgs,\n\tOrdering,\n\tQueryParams,\n\tRoute,\n} from \"./buildQueryURL\";\n\n//=============================================================================\n// Helpers - Manipulate content from Prismic.\n//=============================================================================\n\n// Primary Helpers API.\nexport { asDate } from \"./helpers/asDate\";\nexport { asLink } from \"./helpers/asLink\";\nexport { asLinkAttrs } from \"./helpers/asLinkAttrs\";\nexport { asText } from \"./helpers/asText\";\nexport { asHTML } from \"./helpers/asHTML\";\nexport { asImageSrc } from \"./helpers/asImageSrc\";\nexport { asImageWidthSrcSet } from \"./helpers/asImageWidthSrcSet\";\nexport { asImagePixelDensitySrcSet } from \"./helpers/asImagePixelDensitySrcSet\";\nexport { unstable_mapSliceZone } from \"./helpers/unstable_mapSliceZone\";\nexport * as isFilled from \"./helpers/isFilled\";\n\n// Conversion helper.\nexport { documentToLinkField } from \"./helpers/documentToLinkField\";\n\n// RichText element types.\nexport { Element } from \"@prismicio/richtext\";\n\nexport type { LinkResolverFunction } from \"./helpers/asLink\";\nexport type { AsLinkAttrsConfig } from \"./helpers/asLinkAttrs\";\n\n/**\n * @deprecated Renamed to `HTMLRichTextMapSerializer`\n */\ntype HTMLMapSerializer = HTMLRichTextMapSerializer;\n/**\n * @deprecated Renamed to `HTMLRichTextFunctionSerializer`\n */\ntype HTMLFunctionSerializer = HTMLRichTextFunctionSerializer;\nexport type {\n\tHTMLRichTextMapSerializer,\n\tHTMLRichTextFunctionSerializer,\n\tHTMLMapSerializer,\n\tHTMLFunctionSerializer,\n};\nexport type { HTMLRichTextSerializer } from \"./helpers/asHTML\";\n\n//=============================================================================\n// Errors - Custom errors for Prismic APIs.\n//=============================================================================\n\nexport { PrismicError } from \"./errors/PrismicError\";\nexport { ForbiddenError } from \"./errors/ForbiddenError\";\nexport { NotFoundError } from \"./errors/NotFoundError\";\nexport { ParsingError } from \"./errors/ParsingError\";\n\n//=============================================================================\n// Types - Types representing Prismic content, models, and API payloads.\n//=============================================================================\n\n// Values - Types representing Prismic content.\nexport { RichTextNodeType } from \"./types/value/richText\";\nexport { LinkType } from \"./types/value/link\";\nexport { OEmbedType } from \"./types/value/embed\";\n\nexport type {\n\tPrismicDocument,\n\tPrismicDocumentWithUID,\n\tPrismicDocumentWithoutUID,\n\tPrismicDocumentHeader,\n\tAlternateLanguage,\n} from \"./types/value/document\";\n\nexport type {\n\t// RichText & Title\n\tRichTextField,\n\t// RichText & Title (block nodes)\n\tRTTextNodeBase,\n\tRTHeading1Node,\n\tRTHeading2Node,\n\tRTHeading3Node,\n\tRTHeading4Node,\n\tRTHeading5Node,\n\tRTHeading6Node,\n\tRTParagraphNode,\n\tRTPreformattedNode,\n\tRTListItemNode,\n\tRTOListItemNode,\n\t// RichText & Title (span nodes)\n\tRTSpanNodeBase,\n\tRTStrongNode,\n\tRTEmNode,\n\tRTLabelNode,\n\t// RichText & Title (media nodes)\n\tRTImageNode,\n\tRTEmbedNode,\n\t// RichText & Title (link nodes)\n\tRTLinkNode,\n\t// RichText & Title (serialization related nodes)\n\tRTListNode,\n\tRTOListNode,\n\tRTSpanNode,\n\t// RichText & Title (helpers)\n\tRTNode,\n\tRTTextNode,\n\tRTBlockNode,\n\tRTInlineNode,\n\tRTAnyNode,\n} from \"./types/value/richText\";\nexport type { TitleField } from \"./types/value/title\";\n\nexport type {\n\tImageField,\n\tImageFieldImage,\n\tFilledImageFieldImage,\n\tEmptyImageFieldImage,\n} from \"./types/value/image\";\n\nexport type {\n\tEmptyLinkField,\n\tLinkField,\n\tFilledLinkToWebField,\n} from \"./types/value/link\";\nexport type {\n\tContentRelationshipField,\n\tFilledContentRelationshipField,\n} from \"./types/value/contentRelationship\";\nexport type {\n\tLinkToMediaField,\n\tFilledLinkToMediaField,\n} from \"./types/value/linkToMedia\";\n\nexport type {\n\tOEmbedExtra,\n\tPhotoOEmbed,\n\tVideoOEmbed,\n\tLinkOEmbed,\n\tRichOEmbed,\n\tAnyOEmbed,\n\tEmbedField,\n} from \"./types/value/embed\";\n\nexport type { BooleanField } from \"./types/value/boolean\";\nexport type { ColorField } from \"./types/value/color\";\nexport type { DateField } from \"./types/value/date\";\nexport type { KeyTextField } from \"./types/value/keyText\";\nexport type { NumberField } from \"./types/value/number\";\nexport type { SelectField } from \"./types/value/select\";\nexport type { TimestampField } from \"./types/value/timestamp\";\nexport type { GeoPointField } from \"./types/value/geoPoint\";\n\n/**\n * @deprecated Renamed to `IntegrationField`\n */\n// TODO: Remove when we remove support for deprecated `IntegrationFields` export.\ntype IntegrationFields = IntegrationField;\nexport { IntegrationField, IntegrationFields };\n\nexport type { GroupField } from \"./types/value/group\";\n\nexport type { SliceZone } from \"./types/value/sliceZone\";\nexport type { Slice } from \"./types/value/slice\";\nexport type { SharedSlice } from \"./types/value/sharedSlice\";\nexport type { SharedSliceVariation } from \"./types/value/sharedSliceVariation\";\n\nexport type { FieldState, AnyRegularField } from \"./types/value/types\";\n\n// Models - Types representing Prismic content models.\nexport { CustomTypeModelFieldType } from \"./types/model/types\";\nexport { CustomTypeModelLinkSelectType } from \"./types/model/link\";\nexport { CustomTypeModelSliceType } from \"./types/model/sliceZone\";\nexport { CustomTypeModelSliceDisplay } from \"./types/model/slice\";\n\nexport type {\n\tCustomTypeModel,\n\tCustomTypeModelDefinition,\n\tCustomTypeModelTab,\n} from \"./types/model/customType\";\n\nexport type {\n\tCustomTypeModelRichTextField,\n\tCustomTypeModelRichTextMultiField,\n\tCustomTypeModelRichTextSingleField,\n} from \"./types/model/richText\";\nexport type { CustomTypeModelTitleField } from \"./types/model/title\";\n\nexport type {\n\tCustomTypeModelImageField,\n\tCustomTypeModelImageConstraint,\n\tCustomTypeModelImageThumbnail,\n} from \"./types/model/image\";\n\nexport type { CustomTypeModelContentRelationshipField } from \"./types/model/contentRelationship\";\nexport type { CustomTypeModelLinkField } from \"./types/model/link\";\nexport type { CustomTypeModelLinkToMediaField } from \"./types/model/linkToMedia\";\n\nexport type { CustomTypeModelEmbedField } from \"./types/model/embed\";\n\nexport type { CustomTypeModelBooleanField } from \"./types/model/boolean\";\nexport type { CustomTypeModelColorField } from \"./types/model/color\";\nexport type { CustomTypeModelDateField } from \"./types/model/date\";\nexport type { CustomTypeModelKeyTextField } from \"./types/model/keyText\";\nexport type { CustomTypeModelNumberField } from \"./types/model/number\";\nexport type { CustomTypeModelSelectField } from \"./types/model/select\";\nexport type { CustomTypeModelTimestampField } from \"./types/model/timestamp\";\nexport type { CustomTypeModelGeoPointField } from \"./types/model/geoPoint\";\n\n/**\n * @deprecated Renamed to `CustomTypeModelIntegrationField`.\n */\n// TODO: Remove when we remove support for deprecated `CustomTypeModelIntegrationField` export.\ntype CustomTypeModelIntegrationFieldsField = CustomTypeModelIntegrationField;\nexport {\n\tCustomTypeModelIntegrationField,\n\tCustomTypeModelIntegrationFieldsField,\n};\nexport type { CustomTypeModelGroupField } from \"./types/model/group\";\nexport type {\n\tCustomTypeModelSliceZoneField,\n\tCustomTypeModelSliceLabel,\n\tCustomTypeModelSharedSlice,\n} from \"./types/model/sliceZone\";\nexport type {\n\tCustomTypeModelSlice,\n\tCustomTypeModelLegacySlice,\n} from \"./types/model/slice\";\nexport type { SharedSliceModel } from \"./types/model/sharedSlice\";\nexport type { SharedSliceModelVariation } from \"./types/model/sharedSliceVariation\";\n\nexport type { CustomTypeModelUIDField } from \"./types/model/uid\";\n\nexport type { CustomTypeModelRangeField } from \"./types/model/range\";\nexport type { CustomTypeModelSeparatorField } from \"./types/model/separator\";\n\nexport type {\n\tCustomTypeModelField,\n\tCustomTypeModelFieldForGroup,\n} from \"./types/model/types\";\n\n// API - Types representing Prismic Rest API V2 responses.\nexport type { Query } from \"./types/api/query\";\n\nexport type { Ref } from \"./types/api/ref\";\n\nexport type { Release } from \"./types/api/release\";\n\nexport type {\n\tRepository,\n\tLanguage,\n\tForm,\n\tFormField,\n} from \"./types/api/repository\";\n\nexport type { Tags } from \"./types/api/tags\";\n\n// Webhook - Types representing Prismic webhooks.\nexport { WebhookType } from \"./types/webhook/types\";\n\nexport type { WebhookBody } from \"./types/webhook/types\";\n\nexport type { WebhookBodyAPIUpdate } from \"./types/webhook/apiUpdate\";\n\nexport type { WebhookBodyTestTrigger } from \"./types/webhook/testTrigger\";\n"],"names":["filter"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCA,MAAM,YAAYA,OAAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
package/dist/index.d.ts CHANGED
@@ -55,6 +55,7 @@ export { asHTML } from "./helpers/asHTML";
55
55
  export { asImageSrc } from "./helpers/asImageSrc";
56
56
  export { asImageWidthSrcSet } from "./helpers/asImageWidthSrcSet";
57
57
  export { asImagePixelDensitySrcSet } from "./helpers/asImagePixelDensitySrcSet";
58
+ export { unstable_mapSliceZone } from "./helpers/unstable_mapSliceZone";
58
59
  export * as isFilled from "./helpers/isFilled";
59
60
  export { documentToLinkField } from "./helpers/documentToLinkField";
60
61
  export { Element } from "@prismicio/richtext";
package/dist/index.js CHANGED
@@ -16,6 +16,7 @@ import { asHTML } from "./helpers/asHTML.js";
16
16
  import { asImageSrc } from "./helpers/asImageSrc.js";
17
17
  import { asImageWidthSrcSet } from "./helpers/asImageWidthSrcSet.js";
18
18
  import { asImagePixelDensitySrcSet } from "./helpers/asImagePixelDensitySrcSet.js";
19
+ import { unstable_mapSliceZone } from "./helpers/unstable_mapSliceZone.js";
19
20
  import * as isFilled from "./helpers/isFilled.js";
20
21
  import { documentToLinkField } from "./helpers/documentToLinkField.js";
21
22
  import { Element } from "@prismicio/richtext";
@@ -67,6 +68,7 @@ export {
67
68
  isFilled,
68
69
  isRepositoryEndpoint,
69
70
  isRepositoryName,
70
- predicate
71
+ predicate,
72
+ unstable_mapSliceZone
71
73
  };
72
74
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../src/index.ts"],"sourcesContent":["// Imports are used for deprecations.\nimport type { CustomTypeModelIntegrationField } from \"./types/model/integration\";\nimport type { IntegrationField } from \"./types/value/integration\";\n\nimport type {\n\tHTMLRichTextFunctionSerializer,\n\tHTMLRichTextMapSerializer,\n} from \"./helpers/asHTML\";\n\nimport { filter } from \"./filter\";\n\n//=============================================================================\n// Client - Query content from Prismic.\n//=============================================================================\n\n// Primary Client API.\nexport { createClient, Client } from \"./createClient\";\n\n// API endpoint helpers.\nexport { getRepositoryEndpoint } from \"./getRepositoryEndpoint\";\nexport { getRepositoryName } from \"./getRepositoryName\";\nexport { getGraphQLEndpoint } from \"./getGraphQLEndpoint\";\nexport { isRepositoryName } from \"./isRepositoryName\";\nexport { isRepositoryEndpoint } from \"./isRepositoryEndpoint\";\nexport { buildQueryURL } from \"./buildQueryURL\";\n\n// Toolbar helpers.\nexport { getToolbarSrc } from \"./getToolbarSrc\";\n\n// Query filters API.\n/**\n * @deprecated Renamed to `filter`\n */\n// TODO: Remove when we remove support for deprecated `predicate` export.\nconst predicate = filter;\nexport { filter, predicate };\n\n// A collection of well-known cookie names shared between Prismic libraries and systems.\nexport * as cookie from \"./cookie\";\n\n// General types used to query content from Prismic. These are made public to allow users to better type their projects.\nexport type {\n\tAbortSignalLike,\n\tClientConfig,\n\tCreateClient,\n\tFetchLike,\n\tHttpRequestLike,\n\tRequestInitLike,\n\tResponseLike,\n} from \"./createClient\";\nexport type {\n\tBuildQueryURLArgs,\n\tOrdering,\n\tQueryParams,\n\tRoute,\n} from \"./buildQueryURL\";\n\n//=============================================================================\n// Helpers - Manipulate content from Prismic.\n//=============================================================================\n\n// Primary Helpers API.\nexport { asDate } from \"./helpers/asDate\";\nexport { asLink } from \"./helpers/asLink\";\nexport { asLinkAttrs } from \"./helpers/asLinkAttrs\";\nexport { asText } from \"./helpers/asText\";\nexport { asHTML } from \"./helpers/asHTML\";\nexport { asImageSrc } from \"./helpers/asImageSrc\";\nexport { asImageWidthSrcSet } from \"./helpers/asImageWidthSrcSet\";\nexport { asImagePixelDensitySrcSet } from \"./helpers/asImagePixelDensitySrcSet\";\nexport * as isFilled from \"./helpers/isFilled\";\n\n// Conversion helper.\nexport { documentToLinkField } from \"./helpers/documentToLinkField\";\n\n// RichText element types.\nexport { Element } from \"@prismicio/richtext\";\n\nexport type { LinkResolverFunction } from \"./helpers/asLink\";\nexport type { AsLinkAttrsConfig } from \"./helpers/asLinkAttrs\";\n\n/**\n * @deprecated Renamed to `HTMLRichTextMapSerializer`\n */\ntype HTMLMapSerializer = HTMLRichTextMapSerializer;\n/**\n * @deprecated Renamed to `HTMLRichTextFunctionSerializer`\n */\ntype HTMLFunctionSerializer = HTMLRichTextFunctionSerializer;\nexport type {\n\tHTMLRichTextMapSerializer,\n\tHTMLRichTextFunctionSerializer,\n\tHTMLMapSerializer,\n\tHTMLFunctionSerializer,\n};\nexport type { HTMLRichTextSerializer } from \"./helpers/asHTML\";\n\n//=============================================================================\n// Errors - Custom errors for Prismic APIs.\n//=============================================================================\n\nexport { PrismicError } from \"./errors/PrismicError\";\nexport { ForbiddenError } from \"./errors/ForbiddenError\";\nexport { NotFoundError } from \"./errors/NotFoundError\";\nexport { ParsingError } from \"./errors/ParsingError\";\n\n//=============================================================================\n// Types - Types representing Prismic content, models, and API payloads.\n//=============================================================================\n\n// Values - Types representing Prismic content.\nexport { RichTextNodeType } from \"./types/value/richText\";\nexport { LinkType } from \"./types/value/link\";\nexport { OEmbedType } from \"./types/value/embed\";\n\nexport type {\n\tPrismicDocument,\n\tPrismicDocumentWithUID,\n\tPrismicDocumentWithoutUID,\n\tPrismicDocumentHeader,\n\tAlternateLanguage,\n} from \"./types/value/document\";\n\nexport type {\n\t// RichText & Title\n\tRichTextField,\n\t// RichText & Title (block nodes)\n\tRTTextNodeBase,\n\tRTHeading1Node,\n\tRTHeading2Node,\n\tRTHeading3Node,\n\tRTHeading4Node,\n\tRTHeading5Node,\n\tRTHeading6Node,\n\tRTParagraphNode,\n\tRTPreformattedNode,\n\tRTListItemNode,\n\tRTOListItemNode,\n\t// RichText & Title (span nodes)\n\tRTSpanNodeBase,\n\tRTStrongNode,\n\tRTEmNode,\n\tRTLabelNode,\n\t// RichText & Title (media nodes)\n\tRTImageNode,\n\tRTEmbedNode,\n\t// RichText & Title (link nodes)\n\tRTLinkNode,\n\t// RichText & Title (serialization related nodes)\n\tRTListNode,\n\tRTOListNode,\n\tRTSpanNode,\n\t// RichText & Title (helpers)\n\tRTNode,\n\tRTTextNode,\n\tRTBlockNode,\n\tRTInlineNode,\n\tRTAnyNode,\n} from \"./types/value/richText\";\nexport type { TitleField } from \"./types/value/title\";\n\nexport type {\n\tImageField,\n\tImageFieldImage,\n\tFilledImageFieldImage,\n\tEmptyImageFieldImage,\n} from \"./types/value/image\";\n\nexport type {\n\tEmptyLinkField,\n\tLinkField,\n\tFilledLinkToWebField,\n} from \"./types/value/link\";\nexport type {\n\tContentRelationshipField,\n\tFilledContentRelationshipField,\n} from \"./types/value/contentRelationship\";\nexport type {\n\tLinkToMediaField,\n\tFilledLinkToMediaField,\n} from \"./types/value/linkToMedia\";\n\nexport type {\n\tOEmbedExtra,\n\tPhotoOEmbed,\n\tVideoOEmbed,\n\tLinkOEmbed,\n\tRichOEmbed,\n\tAnyOEmbed,\n\tEmbedField,\n} from \"./types/value/embed\";\n\nexport type { BooleanField } from \"./types/value/boolean\";\nexport type { ColorField } from \"./types/value/color\";\nexport type { DateField } from \"./types/value/date\";\nexport type { KeyTextField } from \"./types/value/keyText\";\nexport type { NumberField } from \"./types/value/number\";\nexport type { SelectField } from \"./types/value/select\";\nexport type { TimestampField } from \"./types/value/timestamp\";\nexport type { GeoPointField } from \"./types/value/geoPoint\";\n\n/**\n * @deprecated Renamed to `IntegrationField`\n */\n// TODO: Remove when we remove support for deprecated `IntegrationFields` export.\ntype IntegrationFields = IntegrationField;\nexport { IntegrationField, IntegrationFields };\n\nexport type { GroupField } from \"./types/value/group\";\n\nexport type { SliceZone } from \"./types/value/sliceZone\";\nexport type { Slice } from \"./types/value/slice\";\nexport type { SharedSlice } from \"./types/value/sharedSlice\";\nexport type { SharedSliceVariation } from \"./types/value/sharedSliceVariation\";\n\nexport type { FieldState, AnyRegularField } from \"./types/value/types\";\n\n// Models - Types representing Prismic content models.\nexport { CustomTypeModelFieldType } from \"./types/model/types\";\nexport { CustomTypeModelLinkSelectType } from \"./types/model/link\";\nexport { CustomTypeModelSliceType } from \"./types/model/sliceZone\";\nexport { CustomTypeModelSliceDisplay } from \"./types/model/slice\";\n\nexport type {\n\tCustomTypeModel,\n\tCustomTypeModelDefinition,\n\tCustomTypeModelTab,\n} from \"./types/model/customType\";\n\nexport type {\n\tCustomTypeModelRichTextField,\n\tCustomTypeModelRichTextMultiField,\n\tCustomTypeModelRichTextSingleField,\n} from \"./types/model/richText\";\nexport type { CustomTypeModelTitleField } from \"./types/model/title\";\n\nexport type {\n\tCustomTypeModelImageField,\n\tCustomTypeModelImageConstraint,\n\tCustomTypeModelImageThumbnail,\n} from \"./types/model/image\";\n\nexport type { CustomTypeModelContentRelationshipField } from \"./types/model/contentRelationship\";\nexport type { CustomTypeModelLinkField } from \"./types/model/link\";\nexport type { CustomTypeModelLinkToMediaField } from \"./types/model/linkToMedia\";\n\nexport type { CustomTypeModelEmbedField } from \"./types/model/embed\";\n\nexport type { CustomTypeModelBooleanField } from \"./types/model/boolean\";\nexport type { CustomTypeModelColorField } from \"./types/model/color\";\nexport type { CustomTypeModelDateField } from \"./types/model/date\";\nexport type { CustomTypeModelKeyTextField } from \"./types/model/keyText\";\nexport type { CustomTypeModelNumberField } from \"./types/model/number\";\nexport type { CustomTypeModelSelectField } from \"./types/model/select\";\nexport type { CustomTypeModelTimestampField } from \"./types/model/timestamp\";\nexport type { CustomTypeModelGeoPointField } from \"./types/model/geoPoint\";\n\n/**\n * @deprecated Renamed to `CustomTypeModelIntegrationField`.\n */\n// TODO: Remove when we remove support for deprecated `CustomTypeModelIntegrationField` export.\ntype CustomTypeModelIntegrationFieldsField = CustomTypeModelIntegrationField;\nexport {\n\tCustomTypeModelIntegrationField,\n\tCustomTypeModelIntegrationFieldsField,\n};\nexport type { CustomTypeModelGroupField } from \"./types/model/group\";\nexport type {\n\tCustomTypeModelSliceZoneField,\n\tCustomTypeModelSliceLabel,\n\tCustomTypeModelSharedSlice,\n} from \"./types/model/sliceZone\";\nexport type {\n\tCustomTypeModelSlice,\n\tCustomTypeModelLegacySlice,\n} from \"./types/model/slice\";\nexport type { SharedSliceModel } from \"./types/model/sharedSlice\";\nexport type { SharedSliceModelVariation } from \"./types/model/sharedSliceVariation\";\n\nexport type { CustomTypeModelUIDField } from \"./types/model/uid\";\n\nexport type { CustomTypeModelRangeField } from \"./types/model/range\";\nexport type { CustomTypeModelSeparatorField } from \"./types/model/separator\";\n\nexport type {\n\tCustomTypeModelField,\n\tCustomTypeModelFieldForGroup,\n} from \"./types/model/types\";\n\n// API - Types representing Prismic Rest API V2 responses.\nexport type { Query } from \"./types/api/query\";\n\nexport type { Ref } from \"./types/api/ref\";\n\nexport type { Release } from \"./types/api/release\";\n\nexport type {\n\tRepository,\n\tLanguage,\n\tForm,\n\tFormField,\n} from \"./types/api/repository\";\n\nexport type { Tags } from \"./types/api/tags\";\n\n// Webhook - Types representing Prismic webhooks.\nexport { WebhookType } from \"./types/webhook/types\";\n\nexport type { WebhookBody } from \"./types/webhook/types\";\n\nexport type { WebhookBodyAPIUpdate } from \"./types/webhook/apiUpdate\";\n\nexport type { WebhookBodyTestTrigger } from \"./types/webhook/testTrigger\";\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCA,MAAM,YAAY;"}
1
+ {"version":3,"file":"index.js","sources":["../../src/index.ts"],"sourcesContent":["// Imports are used for deprecations.\nimport type { CustomTypeModelIntegrationField } from \"./types/model/integration\";\nimport type { IntegrationField } from \"./types/value/integration\";\n\nimport type {\n\tHTMLRichTextFunctionSerializer,\n\tHTMLRichTextMapSerializer,\n} from \"./helpers/asHTML\";\n\nimport { filter } from \"./filter\";\n\n//=============================================================================\n// Client - Query content from Prismic.\n//=============================================================================\n\n// Primary Client API.\nexport { createClient, Client } from \"./createClient\";\n\n// API endpoint helpers.\nexport { getRepositoryEndpoint } from \"./getRepositoryEndpoint\";\nexport { getRepositoryName } from \"./getRepositoryName\";\nexport { getGraphQLEndpoint } from \"./getGraphQLEndpoint\";\nexport { isRepositoryName } from \"./isRepositoryName\";\nexport { isRepositoryEndpoint } from \"./isRepositoryEndpoint\";\nexport { buildQueryURL } from \"./buildQueryURL\";\n\n// Toolbar helpers.\nexport { getToolbarSrc } from \"./getToolbarSrc\";\n\n// Query filters API.\n/**\n * @deprecated Renamed to `filter`\n */\n// TODO: Remove when we remove support for deprecated `predicate` export.\nconst predicate = filter;\nexport { filter, predicate };\n\n// A collection of well-known cookie names shared between Prismic libraries and systems.\nexport * as cookie from \"./cookie\";\n\n// General types used to query content from Prismic. These are made public to allow users to better type their projects.\nexport type {\n\tAbortSignalLike,\n\tClientConfig,\n\tCreateClient,\n\tFetchLike,\n\tHttpRequestLike,\n\tRequestInitLike,\n\tResponseLike,\n} from \"./createClient\";\nexport type {\n\tBuildQueryURLArgs,\n\tOrdering,\n\tQueryParams,\n\tRoute,\n} from \"./buildQueryURL\";\n\n//=============================================================================\n// Helpers - Manipulate content from Prismic.\n//=============================================================================\n\n// Primary Helpers API.\nexport { asDate } from \"./helpers/asDate\";\nexport { asLink } from \"./helpers/asLink\";\nexport { asLinkAttrs } from \"./helpers/asLinkAttrs\";\nexport { asText } from \"./helpers/asText\";\nexport { asHTML } from \"./helpers/asHTML\";\nexport { asImageSrc } from \"./helpers/asImageSrc\";\nexport { asImageWidthSrcSet } from \"./helpers/asImageWidthSrcSet\";\nexport { asImagePixelDensitySrcSet } from \"./helpers/asImagePixelDensitySrcSet\";\nexport { unstable_mapSliceZone } from \"./helpers/unstable_mapSliceZone\";\nexport * as isFilled from \"./helpers/isFilled\";\n\n// Conversion helper.\nexport { documentToLinkField } from \"./helpers/documentToLinkField\";\n\n// RichText element types.\nexport { Element } from \"@prismicio/richtext\";\n\nexport type { LinkResolverFunction } from \"./helpers/asLink\";\nexport type { AsLinkAttrsConfig } from \"./helpers/asLinkAttrs\";\n\n/**\n * @deprecated Renamed to `HTMLRichTextMapSerializer`\n */\ntype HTMLMapSerializer = HTMLRichTextMapSerializer;\n/**\n * @deprecated Renamed to `HTMLRichTextFunctionSerializer`\n */\ntype HTMLFunctionSerializer = HTMLRichTextFunctionSerializer;\nexport type {\n\tHTMLRichTextMapSerializer,\n\tHTMLRichTextFunctionSerializer,\n\tHTMLMapSerializer,\n\tHTMLFunctionSerializer,\n};\nexport type { HTMLRichTextSerializer } from \"./helpers/asHTML\";\n\n//=============================================================================\n// Errors - Custom errors for Prismic APIs.\n//=============================================================================\n\nexport { PrismicError } from \"./errors/PrismicError\";\nexport { ForbiddenError } from \"./errors/ForbiddenError\";\nexport { NotFoundError } from \"./errors/NotFoundError\";\nexport { ParsingError } from \"./errors/ParsingError\";\n\n//=============================================================================\n// Types - Types representing Prismic content, models, and API payloads.\n//=============================================================================\n\n// Values - Types representing Prismic content.\nexport { RichTextNodeType } from \"./types/value/richText\";\nexport { LinkType } from \"./types/value/link\";\nexport { OEmbedType } from \"./types/value/embed\";\n\nexport type {\n\tPrismicDocument,\n\tPrismicDocumentWithUID,\n\tPrismicDocumentWithoutUID,\n\tPrismicDocumentHeader,\n\tAlternateLanguage,\n} from \"./types/value/document\";\n\nexport type {\n\t// RichText & Title\n\tRichTextField,\n\t// RichText & Title (block nodes)\n\tRTTextNodeBase,\n\tRTHeading1Node,\n\tRTHeading2Node,\n\tRTHeading3Node,\n\tRTHeading4Node,\n\tRTHeading5Node,\n\tRTHeading6Node,\n\tRTParagraphNode,\n\tRTPreformattedNode,\n\tRTListItemNode,\n\tRTOListItemNode,\n\t// RichText & Title (span nodes)\n\tRTSpanNodeBase,\n\tRTStrongNode,\n\tRTEmNode,\n\tRTLabelNode,\n\t// RichText & Title (media nodes)\n\tRTImageNode,\n\tRTEmbedNode,\n\t// RichText & Title (link nodes)\n\tRTLinkNode,\n\t// RichText & Title (serialization related nodes)\n\tRTListNode,\n\tRTOListNode,\n\tRTSpanNode,\n\t// RichText & Title (helpers)\n\tRTNode,\n\tRTTextNode,\n\tRTBlockNode,\n\tRTInlineNode,\n\tRTAnyNode,\n} from \"./types/value/richText\";\nexport type { TitleField } from \"./types/value/title\";\n\nexport type {\n\tImageField,\n\tImageFieldImage,\n\tFilledImageFieldImage,\n\tEmptyImageFieldImage,\n} from \"./types/value/image\";\n\nexport type {\n\tEmptyLinkField,\n\tLinkField,\n\tFilledLinkToWebField,\n} from \"./types/value/link\";\nexport type {\n\tContentRelationshipField,\n\tFilledContentRelationshipField,\n} from \"./types/value/contentRelationship\";\nexport type {\n\tLinkToMediaField,\n\tFilledLinkToMediaField,\n} from \"./types/value/linkToMedia\";\n\nexport type {\n\tOEmbedExtra,\n\tPhotoOEmbed,\n\tVideoOEmbed,\n\tLinkOEmbed,\n\tRichOEmbed,\n\tAnyOEmbed,\n\tEmbedField,\n} from \"./types/value/embed\";\n\nexport type { BooleanField } from \"./types/value/boolean\";\nexport type { ColorField } from \"./types/value/color\";\nexport type { DateField } from \"./types/value/date\";\nexport type { KeyTextField } from \"./types/value/keyText\";\nexport type { NumberField } from \"./types/value/number\";\nexport type { SelectField } from \"./types/value/select\";\nexport type { TimestampField } from \"./types/value/timestamp\";\nexport type { GeoPointField } from \"./types/value/geoPoint\";\n\n/**\n * @deprecated Renamed to `IntegrationField`\n */\n// TODO: Remove when we remove support for deprecated `IntegrationFields` export.\ntype IntegrationFields = IntegrationField;\nexport { IntegrationField, IntegrationFields };\n\nexport type { GroupField } from \"./types/value/group\";\n\nexport type { SliceZone } from \"./types/value/sliceZone\";\nexport type { Slice } from \"./types/value/slice\";\nexport type { SharedSlice } from \"./types/value/sharedSlice\";\nexport type { SharedSliceVariation } from \"./types/value/sharedSliceVariation\";\n\nexport type { FieldState, AnyRegularField } from \"./types/value/types\";\n\n// Models - Types representing Prismic content models.\nexport { CustomTypeModelFieldType } from \"./types/model/types\";\nexport { CustomTypeModelLinkSelectType } from \"./types/model/link\";\nexport { CustomTypeModelSliceType } from \"./types/model/sliceZone\";\nexport { CustomTypeModelSliceDisplay } from \"./types/model/slice\";\n\nexport type {\n\tCustomTypeModel,\n\tCustomTypeModelDefinition,\n\tCustomTypeModelTab,\n} from \"./types/model/customType\";\n\nexport type {\n\tCustomTypeModelRichTextField,\n\tCustomTypeModelRichTextMultiField,\n\tCustomTypeModelRichTextSingleField,\n} from \"./types/model/richText\";\nexport type { CustomTypeModelTitleField } from \"./types/model/title\";\n\nexport type {\n\tCustomTypeModelImageField,\n\tCustomTypeModelImageConstraint,\n\tCustomTypeModelImageThumbnail,\n} from \"./types/model/image\";\n\nexport type { CustomTypeModelContentRelationshipField } from \"./types/model/contentRelationship\";\nexport type { CustomTypeModelLinkField } from \"./types/model/link\";\nexport type { CustomTypeModelLinkToMediaField } from \"./types/model/linkToMedia\";\n\nexport type { CustomTypeModelEmbedField } from \"./types/model/embed\";\n\nexport type { CustomTypeModelBooleanField } from \"./types/model/boolean\";\nexport type { CustomTypeModelColorField } from \"./types/model/color\";\nexport type { CustomTypeModelDateField } from \"./types/model/date\";\nexport type { CustomTypeModelKeyTextField } from \"./types/model/keyText\";\nexport type { CustomTypeModelNumberField } from \"./types/model/number\";\nexport type { CustomTypeModelSelectField } from \"./types/model/select\";\nexport type { CustomTypeModelTimestampField } from \"./types/model/timestamp\";\nexport type { CustomTypeModelGeoPointField } from \"./types/model/geoPoint\";\n\n/**\n * @deprecated Renamed to `CustomTypeModelIntegrationField`.\n */\n// TODO: Remove when we remove support for deprecated `CustomTypeModelIntegrationField` export.\ntype CustomTypeModelIntegrationFieldsField = CustomTypeModelIntegrationField;\nexport {\n\tCustomTypeModelIntegrationField,\n\tCustomTypeModelIntegrationFieldsField,\n};\nexport type { CustomTypeModelGroupField } from \"./types/model/group\";\nexport type {\n\tCustomTypeModelSliceZoneField,\n\tCustomTypeModelSliceLabel,\n\tCustomTypeModelSharedSlice,\n} from \"./types/model/sliceZone\";\nexport type {\n\tCustomTypeModelSlice,\n\tCustomTypeModelLegacySlice,\n} from \"./types/model/slice\";\nexport type { SharedSliceModel } from \"./types/model/sharedSlice\";\nexport type { SharedSliceModelVariation } from \"./types/model/sharedSliceVariation\";\n\nexport type { CustomTypeModelUIDField } from \"./types/model/uid\";\n\nexport type { CustomTypeModelRangeField } from \"./types/model/range\";\nexport type { CustomTypeModelSeparatorField } from \"./types/model/separator\";\n\nexport type {\n\tCustomTypeModelField,\n\tCustomTypeModelFieldForGroup,\n} from \"./types/model/types\";\n\n// API - Types representing Prismic Rest API V2 responses.\nexport type { Query } from \"./types/api/query\";\n\nexport type { Ref } from \"./types/api/ref\";\n\nexport type { Release } from \"./types/api/release\";\n\nexport type {\n\tRepository,\n\tLanguage,\n\tForm,\n\tFormField,\n} from \"./types/api/repository\";\n\nexport type { Tags } from \"./types/api/tags\";\n\n// Webhook - Types representing Prismic webhooks.\nexport { WebhookType } from \"./types/webhook/types\";\n\nexport type { WebhookBody } from \"./types/webhook/types\";\n\nexport type { WebhookBodyAPIUpdate } from \"./types/webhook/apiUpdate\";\n\nexport type { WebhookBodyTestTrigger } from \"./types/webhook/testTrigger\";\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCA,MAAM,YAAY;"}
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const version = "7.0.1";
3
+ const version = "7.1.0";
4
4
  exports.version = version;
5
5
  //# sourceMappingURL=package.json.cjs.map
@@ -1,4 +1,4 @@
1
- const version = "7.0.1";
1
+ const version = "7.1.0";
2
2
  export {
3
3
  version
4
4
  };
@@ -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",
3
+ "version": "7.1.0",
4
4
  "description": "The official JavaScript + TypeScript client library for Prismic",
5
5
  "keywords": [
6
6
  "typescript",
@@ -63,7 +63,7 @@
63
63
  "imgix-url-builder": "^0.0.3"
64
64
  },
65
65
  "devDependencies": {
66
- "@prismicio/mock": "^0.2.0",
66
+ "@prismicio/mock": "^0.3.0",
67
67
  "@prismicio/types-internal": "2.0.0-alpha.11",
68
68
  "@size-limit/preset-small-lib": "^8.2.4",
69
69
  "@trivago/prettier-plugin-sort-imports": "^4.1.1",
@@ -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
@@ -68,6 +68,7 @@ export { asHTML } from "./helpers/asHTML";
68
68
  export { asImageSrc } from "./helpers/asImageSrc";
69
69
  export { asImageWidthSrcSet } from "./helpers/asImageWidthSrcSet";
70
70
  export { asImagePixelDensitySrcSet } from "./helpers/asImagePixelDensitySrcSet";
71
+ export { unstable_mapSliceZone } from "./helpers/unstable_mapSliceZone";
71
72
  export * as isFilled from "./helpers/isFilled";
72
73
 
73
74
  // Conversion helper.
@@ -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
  *