@prismicio/client 7.12.0-alpha.0 → 7.13.0-alpha.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.
- package/dist/Client.cjs +47 -7
- package/dist/Client.cjs.map +1 -1
- package/dist/Client.d.ts +20 -2
- package/dist/Client.js +47 -7
- package/dist/Client.js.map +1 -1
- package/dist/helpers/asLink.cjs +7 -9
- package/dist/helpers/asLink.cjs.map +1 -1
- package/dist/helpers/asLink.js +7 -9
- package/dist/helpers/asLink.js.map +1 -1
- package/dist/helpers/isFilled.cjs +4 -3
- package/dist/helpers/isFilled.cjs.map +1 -1
- package/dist/helpers/isFilled.d.ts +11 -3
- package/dist/helpers/isFilled.js +4 -3
- package/dist/helpers/isFilled.js.map +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js.map +1 -1
- package/dist/lib/resolveMigrationDocumentData.cjs +1 -6
- package/dist/lib/resolveMigrationDocumentData.cjs.map +1 -1
- package/dist/lib/resolveMigrationDocumentData.js +1 -6
- package/dist/lib/resolveMigrationDocumentData.js.map +1 -1
- package/dist/lib/serializerHelpers.cjs +3 -0
- package/dist/lib/serializerHelpers.cjs.map +1 -1
- package/dist/lib/serializerHelpers.js +3 -0
- package/dist/lib/serializerHelpers.js.map +1 -1
- package/dist/package.json.cjs +1 -1
- package/dist/package.json.js +1 -1
- package/dist/types/migration/Asset.cjs.map +1 -1
- package/dist/types/migration/Asset.d.ts +3 -3
- package/dist/types/migration/Asset.js.map +1 -1
- package/dist/types/model/contentRelationship.d.ts +0 -1
- package/dist/types/model/linkToMedia.d.ts +0 -1
- package/dist/types/value/contentRelationship.d.ts +1 -24
- package/dist/types/value/link.cjs.map +1 -1
- package/dist/types/value/link.d.ts +3 -26
- package/dist/types/value/link.js.map +1 -1
- package/dist/types/value/linkToMedia.d.ts +1 -13
- package/dist/types/value/types.d.ts +5 -1
- package/package.json +9 -9
- package/src/Client.ts +74 -7
- package/src/helpers/asLink.ts +8 -11
- package/src/helpers/isFilled.ts +16 -7
- package/src/index.ts +1 -1
- package/src/lib/resolveMigrationDocumentData.ts +3 -10
- package/src/lib/serializerHelpers.ts +5 -0
- package/src/types/migration/Asset.ts +4 -7
- package/src/types/model/contentRelationship.ts +0 -1
- package/src/types/model/linkToMedia.ts +0 -1
- package/src/types/value/contentRelationship.ts +2 -45
- package/src/types/value/link.ts +6 -49
- package/src/types/value/linkToMedia.ts +2 -21
- package/src/types/value/types.ts +9 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Asset } from "../api/asset/asset";
|
|
2
2
|
import type { FilledImageFieldImage } from "../value/image";
|
|
3
3
|
import type { EmptyLinkField } from "../value/link";
|
|
4
|
-
import type { LinkToMediaField
|
|
4
|
+
import type { LinkToMediaField } from "../value/linkToMedia";
|
|
5
5
|
import { type RTImageNode } from "../value/richText";
|
|
6
6
|
import type { InjectMigrationSpecificTypes } from "./Document";
|
|
7
7
|
/**
|
|
@@ -59,7 +59,7 @@ export type MigrationImage = PrismicMigrationAsset | ({
|
|
|
59
59
|
/**
|
|
60
60
|
* A link to media field in a migration.
|
|
61
61
|
*/
|
|
62
|
-
export type MigrationLinkToMedia = Pick<
|
|
62
|
+
export type MigrationLinkToMedia = Pick<LinkToMediaField<"filled">, "link_type"> & Partial<Pick<LinkToMediaField<"filled">, "text">> & {
|
|
63
63
|
/**
|
|
64
64
|
* A reference to the migration asset used to resolve the link to media
|
|
65
65
|
* field's value.
|
|
@@ -70,7 +70,7 @@ export type MigrationLinkToMedia = Pick<SingleLinkToMediaField<"filled">, "link_
|
|
|
70
70
|
* The minimum amount of information needed to represent a link to media field
|
|
71
71
|
* with the migration API.
|
|
72
72
|
*/
|
|
73
|
-
export type MigrationLinkToMediaField = Pick<
|
|
73
|
+
export type MigrationLinkToMediaField = Pick<LinkToMediaField<"filled">, "link_type" | "id" | "text"> | EmptyLinkField<"Media">;
|
|
74
74
|
/**
|
|
75
75
|
* A rich text image node in a migration.
|
|
76
76
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Asset.js","sources":["../../../../src/types/migration/Asset.ts"],"sourcesContent":["import type { Asset } from \"../api/asset/asset\"\nimport type { FilledImageFieldImage } from \"../value/image\"\nimport type { EmptyLinkField } from \"../value/link\"\nimport type {
|
|
1
|
+
{"version":3,"file":"Asset.js","sources":["../../../../src/types/migration/Asset.ts"],"sourcesContent":["import type { Asset } from \"../api/asset/asset\"\nimport type { FilledImageFieldImage } from \"../value/image\"\nimport type { EmptyLinkField } from \"../value/link\"\nimport type { LinkToMediaField } from \"../value/linkToMedia\"\nimport { type RTImageNode } from \"../value/richText\"\n\nimport type { InjectMigrationSpecificTypes } from \"./Document\"\n\n/**\n * An asset to be uploaded to Prismic media library.\n */\nexport type MigrationAssetConfig = {\n\t/**\n\t * ID the assets is indexed with on the migration instance.\n\t *\n\t * @remarks\n\t * This property's value is not necessarily the same as the as the one in the\n\t * `file` property. It is mainly used for deduplication within a `Migration`\n\t * instance.\n\t */\n\tid: string | URL | File | NonNullable<ConstructorParameters<File>[0]>[0]\n\n\t/**\n\t * File to be uploaded as an asset.\n\t */\n\tfile: string | URL | File | NonNullable<ConstructorParameters<File>[0]>[0]\n\n\t/**\n\t * Filename of the asset.\n\t */\n\tfilename: string\n\n\t/**\n\t * Notes about the asset. Notes are private and only visible in Prismic media\n\t * library.\n\t */\n\tnotes?: string\n\n\t/**\n\t * Credits and copyright for the asset if any.\n\t */\n\tcredits?: string\n\n\t/**\n\t * Alternate text for the asset.\n\t */\n\talt?: string\n\n\t/**\n\t * Tags associated with the asset.\n\t *\n\t * @remarks\n\t * Tags should be at least 3 characters long and 20 characters at most.\n\t */\n\ttags?: string[]\n}\n\n/**\n * An image field in a migration.\n */\nexport type MigrationImage =\n\t| PrismicMigrationAsset\n\t| ({\n\t\t\t/**\n\t\t\t * A reference to the migration asset used to resolve the image field's\n\t\t\t * value.\n\t\t\t */\n\t\t\tid: PrismicMigrationAsset\n\t } & Record<string, PrismicMigrationAsset>)\n\n/**\n * A link to media field in a migration.\n */\nexport type MigrationLinkToMedia = Pick<\n\tLinkToMediaField<\"filled\">,\n\t\"link_type\"\n> &\n\tPartial<Pick<LinkToMediaField<\"filled\">, \"text\">> & {\n\t\t/**\n\t\t * A reference to the migration asset used to resolve the link to media\n\t\t * field's value.\n\t\t */\n\t\tid: PrismicMigrationAsset\n\t}\n\n/**\n * The minimum amount of information needed to represent a link to media field\n * with the migration API.\n */\nexport type MigrationLinkToMediaField =\n\t| Pick<LinkToMediaField<\"filled\">, \"link_type\" | \"id\" | \"text\">\n\t| EmptyLinkField<\"Media\">\n\n/**\n * A rich text image node in a migration.\n */\nexport type MigrationRTImageNode = InjectMigrationSpecificTypes<\n\tPick<RTImageNode, \"type\" | \"linkTo\">\n> & {\n\t/**\n\t * A reference to the migration asset used to resolve the rich text image\n\t * node's value.\n\t */\n\tid: PrismicMigrationAsset\n}\n\n/**\n * A migration asset used with the Prismic Migration API.\n */\nexport class PrismicMigrationAsset {\n\t/**\n\t * Asset object from Prismic, available once created.\n\t */\n\tasset?: Asset\n\n\t/**\n\t * Configuration of the asset.\n\t */\n\tconfig: MigrationAssetConfig\n\n\t/**\n\t * The initial field value this migration field was created with.\n\t */\n\toriginalField?:\n\t\t| FilledImageFieldImage\n\t\t| LinkToMediaField<\"filled\">\n\t\t| RTImageNode\n\n\t/**\n\t * Creates a migration asset used with the Prismic Migration API.\n\t *\n\t * @param config - Configuration of the asset.\n\t * @param initialField - The initial field value if any.\n\t *\n\t * @returns A migration asset instance.\n\t */\n\tconstructor(\n\t\tconfig: MigrationAssetConfig,\n\t\tinitialField?:\n\t\t\t| FilledImageFieldImage\n\t\t\t| LinkToMediaField<\"filled\">\n\t\t\t| RTImageNode,\n\t) {\n\t\tthis.config = config\n\t\tthis.originalField = initialField\n\t}\n}\n"],"names":[],"mappings":";;;MA6Ga,sBAAqB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EA2BjC,YACC,QACA,cAGc;AA5Bf;AAAA;AAAA;AAAA;AAKA;AAAA;AAAA;AAAA;AAKA;AAAA;AAAA;AAAA;AAoBC,SAAK,SAAS;AACd,SAAK,gBAAgB;AAAA,EACtB;AACA;"}
|
|
@@ -2,29 +2,6 @@ import type { AnyRegularField, FieldState } from "./types";
|
|
|
2
2
|
import type { GroupField } from "./group";
|
|
3
3
|
import type { EmptyLinkField, LinkType } from "./link";
|
|
4
4
|
import type { SliceZone } from "./sliceZone";
|
|
5
|
-
/**
|
|
6
|
-
* Single field value for related documents
|
|
7
|
-
*
|
|
8
|
-
* @typeParam TypeEnum - Type API ID of the document.
|
|
9
|
-
* @typeParam LangEnum - Language API ID of the document.
|
|
10
|
-
* @typeParam DataInterface - Data fields for the document (filled in via
|
|
11
|
-
* GraphQuery of `fetchLinks`).
|
|
12
|
-
* @typeParam State - State of the field which determines its shape.
|
|
13
|
-
*/
|
|
14
|
-
export type SingleContentRelationshipField<TypeEnum = string, LangEnum = string, DataInterface extends Record<string, AnyRegularField | GroupField | SliceZone> | unknown = unknown, State extends FieldState = FieldState> = State extends "empty" ? EmptyLinkField<typeof LinkType.Document> : FilledContentRelationshipField<TypeEnum, LangEnum, DataInterface>;
|
|
15
|
-
/**
|
|
16
|
-
* Repeatable field value for related documents
|
|
17
|
-
*
|
|
18
|
-
* @typeParam TypeEnum - Type API ID of the document.
|
|
19
|
-
* @typeParam LangEnum - Language API ID of the document.
|
|
20
|
-
* @typeParam DataInterface - Data fields for the document (filled in via
|
|
21
|
-
* GraphQuery of `fetchLinks`).
|
|
22
|
-
* @typeParam State - State of the field which determines its shape.
|
|
23
|
-
*/
|
|
24
|
-
export type RepeatableContentRelationshipField<TypeEnum = string, LangEnum = string, DataInterface extends Record<string, AnyRegularField | GroupField | SliceZone> | unknown = unknown, State extends FieldState = FieldState> = State extends "empty" ? [] : [
|
|
25
|
-
SingleContentRelationshipField<TypeEnum, LangEnum, DataInterface>,
|
|
26
|
-
...SingleContentRelationshipField<TypeEnum, LangEnum, DataInterface>[]
|
|
27
|
-
];
|
|
28
5
|
/**
|
|
29
6
|
* Field for related documents
|
|
30
7
|
*
|
|
@@ -34,7 +11,7 @@ export type RepeatableContentRelationshipField<TypeEnum = string, LangEnum = str
|
|
|
34
11
|
* GraphQuery of `fetchLinks`).
|
|
35
12
|
* @typeParam State - State of the field which determines its shape.
|
|
36
13
|
*/
|
|
37
|
-
export type ContentRelationshipField<TypeEnum = string, LangEnum = string, DataInterface extends Record<string, AnyRegularField | GroupField | SliceZone> | unknown = unknown, State extends FieldState = FieldState> =
|
|
14
|
+
export type ContentRelationshipField<TypeEnum = string, LangEnum = string, DataInterface extends Record<string, AnyRegularField | GroupField | SliceZone> | unknown = unknown, State extends FieldState = FieldState> = State extends "empty" ? EmptyLinkField<typeof LinkType.Document> : FilledContentRelationshipField<TypeEnum, LangEnum, DataInterface>;
|
|
38
15
|
/**
|
|
39
16
|
* Links that refer to documents
|
|
40
17
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"link.cjs","sources":["../../../../src/types/value/link.ts"],"sourcesContent":["import type { AnyRegularField, FieldState } from \"./types\"\n\nimport type {
|
|
1
|
+
{"version":3,"file":"link.cjs","sources":["../../../../src/types/value/link.ts"],"sourcesContent":["import type { AnyRegularField, FieldState } from \"./types\"\n\nimport type { ContentRelationshipField } from \"./contentRelationship\"\nimport type { GroupField } from \"./group\"\nimport type { LinkToMediaField } from \"./linkToMedia\"\nimport type { SliceZone } from \"./sliceZone\"\n\n/**\n * Link types\n */\nexport const LinkType = {\n\tAny: \"Any\",\n\tDocument: \"Document\",\n\tMedia: \"Media\",\n\tWeb: \"Web\",\n} as const\n\n/**\n * For link fields that haven't been filled\n *\n * @typeParam Type - The type of link.\n */\nexport type EmptyLinkField<\n\tType extends (typeof LinkType)[keyof typeof LinkType] = typeof LinkType.Any,\n> = {\n\tlink_type: Type | string\n\ttext?: string\n}\n\n/**\n * Link that points to external website\n */\nexport interface FilledLinkToWebField {\n\tlink_type: typeof LinkType.Web\n\turl: string\n\ttarget?: string\n\ttext?: string\n}\n\n/**\n * A link field.\n *\n * @typeParam TypeEnum - Type API ID of the document.\n * @typeParam LangEnum - Language API ID of the document.\n * @typeParam DataInterface - Data fields for the document (filled in via\n * GraphQuery of `fetchLinks`).\n * @typeParam State - State of the field which determines its shape.\n */\nexport type LinkField<\n\tTypeEnum = string,\n\tLangEnum = string,\n\tDataInterface extends\n\t\t| Record<string, AnyRegularField | GroupField | SliceZone>\n\t\t| unknown = unknown,\n\tState extends FieldState = FieldState,\n> = State extends \"empty\"\n\t? EmptyLinkField<typeof LinkType.Any>\n\t:\n\t\t\t| ContentRelationshipField<TypeEnum, LangEnum, DataInterface, State>\n\t\t\t| FilledLinkToWebField\n\t\t\t| LinkToMediaField<State>\n"],"names":[],"mappings":";;AAUO,MAAM,WAAW;AAAA,EACvB,KAAK;AAAA,EACL,UAAU;AAAA,EACV,OAAO;AAAA,EACP,KAAK;;;"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { AnyRegularField, FieldState } from "./types";
|
|
2
|
-
import type {
|
|
2
|
+
import type { ContentRelationshipField } from "./contentRelationship";
|
|
3
3
|
import type { GroupField } from "./group";
|
|
4
|
-
import type {
|
|
4
|
+
import type { LinkToMediaField } from "./linkToMedia";
|
|
5
5
|
import type { SliceZone } from "./sliceZone";
|
|
6
6
|
/**
|
|
7
7
|
* Link types
|
|
@@ -30,29 +30,6 @@ export interface FilledLinkToWebField {
|
|
|
30
30
|
target?: string;
|
|
31
31
|
text?: string;
|
|
32
32
|
}
|
|
33
|
-
/**
|
|
34
|
-
* A single link field value.
|
|
35
|
-
*
|
|
36
|
-
* @typeParam TypeEnum - Type API ID of the document.
|
|
37
|
-
* @typeParam LangEnum - Language API ID of the document.
|
|
38
|
-
* @typeParam DataInterface - Data fields for the document (filled in via
|
|
39
|
-
* GraphQuery of `fetchLinks`).
|
|
40
|
-
* @typeParam State - State of the field which determines its shape.
|
|
41
|
-
*/
|
|
42
|
-
export type SingleLinkField<TypeEnum = string, LangEnum = string, DataInterface extends Record<string, AnyRegularField | GroupField | SliceZone> | unknown = unknown, State extends FieldState = FieldState> = State extends "empty" ? EmptyLinkField<typeof LinkType.Any> : SingleContentRelationshipField<TypeEnum, LangEnum, DataInterface, State> | FilledLinkToWebField | SingleLinkToMediaField<State>;
|
|
43
|
-
/**
|
|
44
|
-
* A repeatable link field value.
|
|
45
|
-
*
|
|
46
|
-
* @typeParam TypeEnum - Type API ID of the document.
|
|
47
|
-
* @typeParam LangEnum - Language API ID of the document.
|
|
48
|
-
* @typeParam DataInterface - Data fields for the document (filled in via
|
|
49
|
-
* GraphQuery of `fetchLinks`).
|
|
50
|
-
* @typeParam State - State of the field which determines its shape.
|
|
51
|
-
*/
|
|
52
|
-
export type RepeatableLinkFieldValue<TypeEnum = string, LangEnum = string, DataInterface extends Record<string, AnyRegularField | GroupField | SliceZone> | unknown = unknown, State extends FieldState = FieldState> = State extends "empty" ? [] : [
|
|
53
|
-
SingleLinkField<TypeEnum, LangEnum, DataInterface>,
|
|
54
|
-
...SingleLinkField<TypeEnum, LangEnum, DataInterface>[]
|
|
55
|
-
];
|
|
56
33
|
/**
|
|
57
34
|
* A link field.
|
|
58
35
|
*
|
|
@@ -62,4 +39,4 @@ export type RepeatableLinkFieldValue<TypeEnum = string, LangEnum = string, DataI
|
|
|
62
39
|
* GraphQuery of `fetchLinks`).
|
|
63
40
|
* @typeParam State - State of the field which determines its shape.
|
|
64
41
|
*/
|
|
65
|
-
export type LinkField<TypeEnum = string, LangEnum = string, DataInterface extends Record<string, AnyRegularField | GroupField | SliceZone> | unknown = unknown, State extends FieldState = FieldState> =
|
|
42
|
+
export type LinkField<TypeEnum = string, LangEnum = string, DataInterface extends Record<string, AnyRegularField | GroupField | SliceZone> | unknown = unknown, State extends FieldState = FieldState> = State extends "empty" ? EmptyLinkField<typeof LinkType.Any> : ContentRelationshipField<TypeEnum, LangEnum, DataInterface, State> | FilledLinkToWebField | LinkToMediaField<State>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"link.js","sources":["../../../../src/types/value/link.ts"],"sourcesContent":["import type { AnyRegularField, FieldState } from \"./types\"\n\nimport type {
|
|
1
|
+
{"version":3,"file":"link.js","sources":["../../../../src/types/value/link.ts"],"sourcesContent":["import type { AnyRegularField, FieldState } from \"./types\"\n\nimport type { ContentRelationshipField } from \"./contentRelationship\"\nimport type { GroupField } from \"./group\"\nimport type { LinkToMediaField } from \"./linkToMedia\"\nimport type { SliceZone } from \"./sliceZone\"\n\n/**\n * Link types\n */\nexport const LinkType = {\n\tAny: \"Any\",\n\tDocument: \"Document\",\n\tMedia: \"Media\",\n\tWeb: \"Web\",\n} as const\n\n/**\n * For link fields that haven't been filled\n *\n * @typeParam Type - The type of link.\n */\nexport type EmptyLinkField<\n\tType extends (typeof LinkType)[keyof typeof LinkType] = typeof LinkType.Any,\n> = {\n\tlink_type: Type | string\n\ttext?: string\n}\n\n/**\n * Link that points to external website\n */\nexport interface FilledLinkToWebField {\n\tlink_type: typeof LinkType.Web\n\turl: string\n\ttarget?: string\n\ttext?: string\n}\n\n/**\n * A link field.\n *\n * @typeParam TypeEnum - Type API ID of the document.\n * @typeParam LangEnum - Language API ID of the document.\n * @typeParam DataInterface - Data fields for the document (filled in via\n * GraphQuery of `fetchLinks`).\n * @typeParam State - State of the field which determines its shape.\n */\nexport type LinkField<\n\tTypeEnum = string,\n\tLangEnum = string,\n\tDataInterface extends\n\t\t| Record<string, AnyRegularField | GroupField | SliceZone>\n\t\t| unknown = unknown,\n\tState extends FieldState = FieldState,\n> = State extends \"empty\"\n\t? EmptyLinkField<typeof LinkType.Any>\n\t:\n\t\t\t| ContentRelationshipField<TypeEnum, LangEnum, DataInterface, State>\n\t\t\t| FilledLinkToWebField\n\t\t\t| LinkToMediaField<State>\n"],"names":[],"mappings":"AAUO,MAAM,WAAW;AAAA,EACvB,KAAK;AAAA,EACL,UAAU;AAAA,EACV,OAAO;AAAA,EACP,KAAK;;"}
|
|
@@ -1,23 +1,11 @@
|
|
|
1
1
|
import type { FieldState } from "./types";
|
|
2
2
|
import type { EmptyLinkField, LinkType } from "./link";
|
|
3
|
-
/**
|
|
4
|
-
* A single link field value that points to media.
|
|
5
|
-
*
|
|
6
|
-
* @typeParam State - State of the field which determines its shape.
|
|
7
|
-
*/
|
|
8
|
-
export type SingleLinkToMediaField<State extends FieldState = FieldState> = State extends "empty" ? EmptyLinkField<typeof LinkType.Media> : FilledLinkToMediaField;
|
|
9
|
-
/**
|
|
10
|
-
* Repeatable link field values that point to media.
|
|
11
|
-
*
|
|
12
|
-
* @typeParam State - State of the field which determines its shape.
|
|
13
|
-
*/
|
|
14
|
-
export type RepeatableLinkToMediaField<State extends FieldState = FieldState> = State extends "empty" ? [] : [SingleLinkToMediaField, ...SingleLinkToMediaField[]];
|
|
15
3
|
/**
|
|
16
4
|
* A link field that points to media.
|
|
17
5
|
*
|
|
18
6
|
* @typeParam State - State of the field which determines its shape.
|
|
19
7
|
*/
|
|
20
|
-
export type LinkToMediaField<State extends FieldState = FieldState> =
|
|
8
|
+
export type LinkToMediaField<State extends FieldState = FieldState> = State extends "empty" ? EmptyLinkField<typeof LinkType.Media> : FilledLinkToMediaField;
|
|
21
9
|
/**
|
|
22
10
|
* A link that points to media.
|
|
23
11
|
*/
|
|
@@ -26,11 +26,15 @@ export type FieldState = "empty" | "filled";
|
|
|
26
26
|
/**
|
|
27
27
|
* Any regular field that can be nested in a group-like field.
|
|
28
28
|
*/
|
|
29
|
-
export type AnyRegularField = TitleField | RichTextField | ImageField | ContentRelationshipField | LinkField | LinkToMediaField | EmbedField | DateField | TimestampField | ColorField | NumberField | KeyTextField | SelectField | BooleanField | GeoPointField | IntegrationField;
|
|
29
|
+
export type AnyRegularField = TitleField | RichTextField | ImageField | ContentRelationshipField | LinkField | Repeatable<LinkField> | LinkToMediaField | EmbedField | DateField | TimestampField | ColorField | NumberField | KeyTextField | SelectField | BooleanField | GeoPointField | IntegrationField;
|
|
30
30
|
/**
|
|
31
31
|
* Any field that can be used in a slice's primary section.
|
|
32
32
|
*/
|
|
33
33
|
export type AnySlicePrimaryField = GroupField | AnyRegularField;
|
|
34
|
+
/**
|
|
35
|
+
* A list of repeatable fields.
|
|
36
|
+
*/
|
|
37
|
+
export type Repeatable<Field extends LinkField, State extends FieldState = FieldState> = State extends "empty" ? [] : [Field, ...Field[]];
|
|
34
38
|
/**
|
|
35
39
|
* Useful to flatten the type output to improve type hints shown in editors. And
|
|
36
40
|
* also to transform an interface into a type to aide with assignability.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prismicio/client",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.13.0-alpha.0",
|
|
4
4
|
"description": "The official JavaScript + TypeScript client library for Prismic",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -83,28 +83,28 @@
|
|
|
83
83
|
},
|
|
84
84
|
"devDependencies": {
|
|
85
85
|
"@prismicio/mock": "^0.3.9",
|
|
86
|
-
"@prismicio/types-internal": "
|
|
87
|
-
"@size-limit/preset-small-lib": "^11.1.
|
|
86
|
+
"@prismicio/types-internal": "3.1.0-alpha.4",
|
|
87
|
+
"@size-limit/preset-small-lib": "^11.1.6",
|
|
88
88
|
"@trivago/prettier-plugin-sort-imports": "^4.3.0",
|
|
89
89
|
"@typescript-eslint/eslint-plugin": "^6.21.0",
|
|
90
90
|
"@typescript-eslint/parser": "^6.21.0",
|
|
91
|
-
"@vitest/coverage-v8": "^2.
|
|
91
|
+
"@vitest/coverage-v8": "^2.1.4",
|
|
92
92
|
"abort-controller": "^3.0.0",
|
|
93
|
-
"eslint": "^8.57.
|
|
93
|
+
"eslint": "^8.57.1",
|
|
94
94
|
"eslint-config-prettier": "^9.1.0",
|
|
95
95
|
"eslint-plugin-prettier": "^5.2.1",
|
|
96
96
|
"eslint-plugin-tsdoc": "^0.3.0",
|
|
97
|
-
"msw": "^1.3.
|
|
97
|
+
"msw": "^1.3.5",
|
|
98
98
|
"node-fetch": "^3.3.2",
|
|
99
99
|
"prettier": "^3.3.3",
|
|
100
100
|
"prettier-plugin-jsdoc": "1.3.0",
|
|
101
|
-
"size-limit": "^11.1.
|
|
101
|
+
"size-limit": "^11.1.6",
|
|
102
102
|
"standard-version": "^9.5.0",
|
|
103
103
|
"ts-expect": "^1.3.0",
|
|
104
|
-
"typescript": "^5.
|
|
104
|
+
"typescript": "^5.6.3",
|
|
105
105
|
"vite": "^5.3.5",
|
|
106
106
|
"vite-plugin-sdk": "^0.1.2",
|
|
107
|
-
"vitest": "^2.
|
|
107
|
+
"vitest": "^2.1.4"
|
|
108
108
|
},
|
|
109
109
|
"engines": {
|
|
110
110
|
"node": ">=14.15.0"
|
package/src/Client.ts
CHANGED
|
@@ -73,6 +73,13 @@ export const GET_ALL_QUERY_DELAY = 500
|
|
|
73
73
|
*/
|
|
74
74
|
const DEFUALT_RETRY_AFTER_MS = 1000
|
|
75
75
|
|
|
76
|
+
/**
|
|
77
|
+
* The maximum number of attemps to retry a query with an invalid ref. We allow
|
|
78
|
+
* multiple attempts since each attempt may use a different (and possibly
|
|
79
|
+
* invalid) ref. Capping the number of attemps prevents infinite loops.
|
|
80
|
+
*/
|
|
81
|
+
const MAX_INVALID_REF_RETRY_ATTEMPS = 3
|
|
82
|
+
|
|
76
83
|
/**
|
|
77
84
|
* Extracts one or more Prismic document types that match a given Prismic
|
|
78
85
|
* document type. If no matches are found, no extraction is performed and the
|
|
@@ -529,9 +536,9 @@ export class Client<
|
|
|
529
536
|
async get<TDocument extends TDocuments>(
|
|
530
537
|
params?: Partial<BuildQueryURLArgs> & FetchParams,
|
|
531
538
|
): Promise<Query<TDocument>> {
|
|
532
|
-
const
|
|
539
|
+
const { data } = await this._get<TDocument>(params)
|
|
533
540
|
|
|
534
|
-
return
|
|
541
|
+
return data
|
|
535
542
|
}
|
|
536
543
|
|
|
537
544
|
/**
|
|
@@ -546,8 +553,9 @@ export class Client<
|
|
|
546
553
|
*
|
|
547
554
|
* @typeParam TDocument - Type of the Prismic document returned.
|
|
548
555
|
*
|
|
549
|
-
* @param params - Parameters to filter, sort, and paginate results.
|
|
550
|
-
*
|
|
556
|
+
* @param params - Parameters to filter, sort, and paginate results.
|
|
557
|
+
*
|
|
558
|
+
* @returns The first result of the query, if any.
|
|
551
559
|
*/
|
|
552
560
|
async getFirst<TDocument extends TDocuments>(
|
|
553
561
|
params?: Partial<BuildQueryURLArgs> & FetchParams,
|
|
@@ -556,10 +564,9 @@ export class Client<
|
|
|
556
564
|
if (!(params && params.page) && !params?.pageSize) {
|
|
557
565
|
actualParams.pageSize = this.defaultParams?.pageSize ?? 1
|
|
558
566
|
}
|
|
559
|
-
const url = await this.
|
|
560
|
-
const result = await this.fetch<Query<TDocument>>(url, params)
|
|
567
|
+
const { data, url } = await this._get<TDocument>(actualParams)
|
|
561
568
|
|
|
562
|
-
const firstResult =
|
|
569
|
+
const firstResult = data.results[0]
|
|
563
570
|
|
|
564
571
|
if (firstResult) {
|
|
565
572
|
return firstResult
|
|
@@ -1678,6 +1685,66 @@ export class Client<
|
|
|
1678
1685
|
return findMasterRef(cachedRepository.refs).ref
|
|
1679
1686
|
}
|
|
1680
1687
|
|
|
1688
|
+
/**
|
|
1689
|
+
* The private implementation of `this.get`. It returns the API response and
|
|
1690
|
+
* the URL used to make the request. The URL is sometimes used in the public
|
|
1691
|
+
* method to include in thrown errors.
|
|
1692
|
+
*
|
|
1693
|
+
* This method retries requests that throw `RefNotFoundError` or
|
|
1694
|
+
* `RefExpiredError`. It contains special logic to retry with the latest
|
|
1695
|
+
* master ref, provided in the API's error message.
|
|
1696
|
+
*
|
|
1697
|
+
* @typeParam TDocument - Type of Prismic documents returned.
|
|
1698
|
+
*
|
|
1699
|
+
* @param params - Parameters to filter, sort, and paginate results.
|
|
1700
|
+
*
|
|
1701
|
+
* @returns An object containing the paginated response containing the result
|
|
1702
|
+
* of the query and the URL used to make the API request.
|
|
1703
|
+
*/
|
|
1704
|
+
private async _get<TDocument extends TDocuments>(
|
|
1705
|
+
params?: Partial<BuildQueryURLArgs> & FetchParams,
|
|
1706
|
+
attemptCount = 0,
|
|
1707
|
+
): Promise<{ data: Query<TDocument>; url: string }> {
|
|
1708
|
+
const url = await this.buildQueryURL(params)
|
|
1709
|
+
|
|
1710
|
+
try {
|
|
1711
|
+
const data = await this.fetch<Query<TDocument>>(url, params)
|
|
1712
|
+
|
|
1713
|
+
return { data, url }
|
|
1714
|
+
} catch (error) {
|
|
1715
|
+
if (
|
|
1716
|
+
!(
|
|
1717
|
+
error instanceof RefNotFoundError || error instanceof RefExpiredError
|
|
1718
|
+
) ||
|
|
1719
|
+
attemptCount >= MAX_INVALID_REF_RETRY_ATTEMPS - 1
|
|
1720
|
+
) {
|
|
1721
|
+
throw error
|
|
1722
|
+
}
|
|
1723
|
+
|
|
1724
|
+
// If no explicit ref is given (i.e. the master ref from
|
|
1725
|
+
// /api/v2 is used), clear the cached repository value.
|
|
1726
|
+
// Clearing the cached value prevents other methods from
|
|
1727
|
+
// using a known-stale ref.
|
|
1728
|
+
if (!params?.ref) {
|
|
1729
|
+
this.cachedRepository = undefined
|
|
1730
|
+
}
|
|
1731
|
+
|
|
1732
|
+
const masterRef = error.message.match(/Master ref is: (?<ref>.*)$/)
|
|
1733
|
+
?.groups?.ref
|
|
1734
|
+
if (!masterRef) {
|
|
1735
|
+
throw error
|
|
1736
|
+
}
|
|
1737
|
+
|
|
1738
|
+
const badRef = new URL(url).searchParams.get("ref")
|
|
1739
|
+
const issue = error instanceof RefNotFoundError ? "invalid" : "expired"
|
|
1740
|
+
console.warn(
|
|
1741
|
+
`The ref (${badRef}) was ${issue}. Now retrying with the latest master ref (${masterRef}). If you were previewing content, the response will not include draft content.`,
|
|
1742
|
+
)
|
|
1743
|
+
|
|
1744
|
+
return await this._get({ ...params, ref: masterRef }, attemptCount + 1)
|
|
1745
|
+
}
|
|
1746
|
+
}
|
|
1747
|
+
|
|
1681
1748
|
/**
|
|
1682
1749
|
* Performs a network request using the configured `fetch` function. It
|
|
1683
1750
|
* assumes all successful responses will have a JSON content type. It also
|
package/src/helpers/asLink.ts
CHANGED
|
@@ -140,20 +140,17 @@ export const asLink: {
|
|
|
140
140
|
return null as AsLinkReturnType<LinkResolverFunctionReturnType, Field>
|
|
141
141
|
}
|
|
142
142
|
|
|
143
|
-
//
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
linkField = linkFieldOrDocument[0]
|
|
151
|
-
} else {
|
|
152
|
-
linkField =
|
|
143
|
+
// Converts document to link field if needed
|
|
144
|
+
const linkField =
|
|
145
|
+
// prettier-ignore
|
|
146
|
+
(
|
|
147
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
148
|
+
// @ts-ignore - Bug in TypeScript 4.9: https://github.com/microsoft/TypeScript/issues/51501
|
|
149
|
+
// TODO: Remove the `prettier-ignore` comment when this bug is fixed.
|
|
153
150
|
"link_type" in linkFieldOrDocument
|
|
154
151
|
? linkFieldOrDocument
|
|
155
152
|
: documentToLinkField(linkFieldOrDocument)
|
|
156
|
-
|
|
153
|
+
) as LinkField
|
|
157
154
|
|
|
158
155
|
// TODO: Remove when we remove support for deprecated tuple-style configuration.
|
|
159
156
|
const [configObjectOrLinkResolver] = configObjectOrTuple
|
package/src/helpers/isFilled.ts
CHANGED
|
@@ -17,7 +17,7 @@ import type { Slice } from "../types/value/slice"
|
|
|
17
17
|
import type { SliceZone } from "../types/value/sliceZone"
|
|
18
18
|
import type { TimestampField } from "../types/value/timestamp"
|
|
19
19
|
import type { TitleField } from "../types/value/title"
|
|
20
|
-
import type { AnyRegularField } from "../types/value/types"
|
|
20
|
+
import type { AnyRegularField, Repeatable } from "../types/value/types"
|
|
21
21
|
|
|
22
22
|
/**
|
|
23
23
|
* Determines if a value is not nullish (i.e. not `null` or `undefined`). This
|
|
@@ -100,8 +100,7 @@ export const image = imageThumbnail as <
|
|
|
100
100
|
) => field is ImageField<ThumbnailNames, "filled">
|
|
101
101
|
|
|
102
102
|
/**
|
|
103
|
-
* Determines if a link field is filled.
|
|
104
|
-
* if the link array contains at least one item
|
|
103
|
+
* Determines if a link field is filled.
|
|
105
104
|
*
|
|
106
105
|
* @param field - Link field to check.
|
|
107
106
|
*
|
|
@@ -116,10 +115,6 @@ export const link = <
|
|
|
116
115
|
>(
|
|
117
116
|
field: LinkField<TypeEnum, LangEnum, DataInterface> | null | undefined,
|
|
118
117
|
): field is LinkField<TypeEnum, LangEnum, DataInterface, "filled"> => {
|
|
119
|
-
if (Array.isArray(field)) {
|
|
120
|
-
return isNonNullish(field) && isNonEmptyArray(field)
|
|
121
|
-
}
|
|
122
|
-
|
|
123
118
|
return isNonNullish(field) && ("id" in field || "url" in field)
|
|
124
119
|
}
|
|
125
120
|
|
|
@@ -271,6 +266,20 @@ export const integrationField = isNonNullish as <
|
|
|
271
266
|
// TODO: Remove when we remove support for deprecated `integrationFields` export.
|
|
272
267
|
export const integrationFields = integrationField
|
|
273
268
|
|
|
269
|
+
/**
|
|
270
|
+
* Determines if a repeatable field has at least one item.
|
|
271
|
+
*
|
|
272
|
+
* @param repeatable - Repeatable to check.
|
|
273
|
+
*
|
|
274
|
+
* @returns `true` if `repeatable` contains at least one item, `false`
|
|
275
|
+
* otherwise.
|
|
276
|
+
*/
|
|
277
|
+
export const repeatable = <T extends LinkField>(
|
|
278
|
+
repeatable: Repeatable<T> | null | undefined,
|
|
279
|
+
): repeatable is Repeatable<T, "filled"> => {
|
|
280
|
+
return isNonNullish(repeatable) && isNonEmptyArray(repeatable)
|
|
281
|
+
}
|
|
282
|
+
|
|
274
283
|
/**
|
|
275
284
|
* Determines if a Group has at least one item.
|
|
276
285
|
*
|
package/src/index.ts
CHANGED
|
@@ -207,7 +207,6 @@ export type {
|
|
|
207
207
|
export type {
|
|
208
208
|
LinkToMediaField,
|
|
209
209
|
FilledLinkToMediaField,
|
|
210
|
-
SingleLinkToMediaField,
|
|
211
210
|
} from "./types/value/linkToMedia"
|
|
212
211
|
|
|
213
212
|
export type {
|
|
@@ -247,6 +246,7 @@ export type {
|
|
|
247
246
|
FieldState,
|
|
248
247
|
AnyRegularField,
|
|
249
248
|
AnySlicePrimaryField,
|
|
249
|
+
Repeatable,
|
|
250
250
|
} from "./types/value/types"
|
|
251
251
|
|
|
252
252
|
// Models - Types representing Prismic content models.
|
|
@@ -11,7 +11,7 @@ import type {
|
|
|
11
11
|
} from "../types/migration/ContentRelationship"
|
|
12
12
|
import { PrismicMigrationDocument } from "../types/migration/Document"
|
|
13
13
|
import type { FilledImageFieldImage } from "../types/value/image"
|
|
14
|
-
import type {
|
|
14
|
+
import type { LinkField } from "../types/value/link"
|
|
15
15
|
import { LinkType } from "../types/value/link"
|
|
16
16
|
import type { RTImageNode } from "../types/value/richText"
|
|
17
17
|
import { RichTextNodeType } from "../types/value/richText"
|
|
@@ -78,14 +78,7 @@ export const resolveMigrationImage = (
|
|
|
78
78
|
image instanceof PrismicMigrationAsset ? { id: image } : image
|
|
79
79
|
|
|
80
80
|
const asset = migration._assets.get(master.config.id)?.asset
|
|
81
|
-
|
|
82
|
-
if (Array.isArray(master.originalField)) {
|
|
83
|
-
maybeInitialField = isFilled.link(master.originalField[0])
|
|
84
|
-
? master.originalField[0]
|
|
85
|
-
: undefined
|
|
86
|
-
} else {
|
|
87
|
-
maybeInitialField = master.originalField
|
|
88
|
-
}
|
|
81
|
+
const maybeInitialField = master.originalField
|
|
89
82
|
|
|
90
83
|
if (asset) {
|
|
91
84
|
const parameters = (maybeInitialField?.url || asset.url).split("?")[1]
|
|
@@ -142,7 +135,7 @@ export const resolveMigrationRTImageNode = async (
|
|
|
142
135
|
const linkTo = (await resolveMigrationDocumentData(
|
|
143
136
|
rtImageNode.linkTo,
|
|
144
137
|
migration,
|
|
145
|
-
)) as
|
|
138
|
+
)) as LinkField
|
|
146
139
|
|
|
147
140
|
return {
|
|
148
141
|
...image,
|
|
@@ -15,6 +15,11 @@ type Attributes = Record<string, string | boolean | null | undefined>
|
|
|
15
15
|
const formatAttributes = (node: RTAnyNode, attributes: Attributes): string => {
|
|
16
16
|
const _attributes = { ...attributes }
|
|
17
17
|
|
|
18
|
+
// Respect `ltr` and `rtl` direction
|
|
19
|
+
if ("direction" in node && node.direction === "rtl") {
|
|
20
|
+
_attributes.dir = node.direction
|
|
21
|
+
}
|
|
22
|
+
|
|
18
23
|
// Add label to attributes
|
|
19
24
|
if ("data" in node && "label" in node.data && node.data.label) {
|
|
20
25
|
_attributes.class = _attributes.class
|
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
import type { Asset } from "../api/asset/asset"
|
|
2
2
|
import type { FilledImageFieldImage } from "../value/image"
|
|
3
3
|
import type { EmptyLinkField } from "../value/link"
|
|
4
|
-
import type {
|
|
5
|
-
LinkToMediaField,
|
|
6
|
-
SingleLinkToMediaField,
|
|
7
|
-
} from "../value/linkToMedia"
|
|
4
|
+
import type { LinkToMediaField } from "../value/linkToMedia"
|
|
8
5
|
import { type RTImageNode } from "../value/richText"
|
|
9
6
|
|
|
10
7
|
import type { InjectMigrationSpecificTypes } from "./Document"
|
|
@@ -75,10 +72,10 @@ export type MigrationImage =
|
|
|
75
72
|
* A link to media field in a migration.
|
|
76
73
|
*/
|
|
77
74
|
export type MigrationLinkToMedia = Pick<
|
|
78
|
-
|
|
75
|
+
LinkToMediaField<"filled">,
|
|
79
76
|
"link_type"
|
|
80
77
|
> &
|
|
81
|
-
Partial<Pick<
|
|
78
|
+
Partial<Pick<LinkToMediaField<"filled">, "text">> & {
|
|
82
79
|
/**
|
|
83
80
|
* A reference to the migration asset used to resolve the link to media
|
|
84
81
|
* field's value.
|
|
@@ -91,7 +88,7 @@ export type MigrationLinkToMedia = Pick<
|
|
|
91
88
|
* with the migration API.
|
|
92
89
|
*/
|
|
93
90
|
export type MigrationLinkToMediaField =
|
|
94
|
-
| Pick<
|
|
91
|
+
| Pick<LinkToMediaField<"filled">, "link_type" | "id" | "text">
|
|
95
92
|
| EmptyLinkField<"Media">
|
|
96
93
|
|
|
97
94
|
/**
|