@prismicio/client 7.9.0 → 7.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (107) hide show
  1. package/dist/BaseClient.cjs +108 -0
  2. package/dist/BaseClient.cjs.map +1 -0
  3. package/dist/BaseClient.d.ts +152 -0
  4. package/dist/BaseClient.js +108 -0
  5. package/dist/BaseClient.js.map +1 -0
  6. package/dist/Client.cjs +1217 -0
  7. package/dist/Client.cjs.map +1 -0
  8. package/dist/Client.d.ts +924 -0
  9. package/dist/Client.js +1217 -0
  10. package/dist/Client.js.map +1 -0
  11. package/dist/Migration.cjs +318 -0
  12. package/dist/Migration.cjs.map +1 -0
  13. package/dist/Migration.d.ts +213 -0
  14. package/dist/Migration.js +318 -0
  15. package/dist/Migration.js.map +1 -0
  16. package/dist/WriteClient.cjs +512 -0
  17. package/dist/WriteClient.cjs.map +1 -0
  18. package/dist/WriteClient.d.ts +314 -0
  19. package/dist/WriteClient.js +512 -0
  20. package/dist/WriteClient.js.map +1 -0
  21. package/dist/createClient.cjs +2 -1215
  22. package/dist/createClient.cjs.map +1 -1
  23. package/dist/createClient.d.ts +2 -1003
  24. package/dist/createClient.js +1 -1214
  25. package/dist/createClient.js.map +1 -1
  26. package/dist/createMigration.cjs +6 -0
  27. package/dist/createMigration.cjs.map +1 -0
  28. package/dist/createMigration.d.ts +24 -0
  29. package/dist/createMigration.js +6 -0
  30. package/dist/createMigration.js.map +1 -0
  31. package/dist/createWriteClient.cjs +6 -0
  32. package/dist/createWriteClient.cjs.map +1 -0
  33. package/dist/createWriteClient.d.ts +32 -0
  34. package/dist/createWriteClient.js +6 -0
  35. package/dist/createWriteClient.js.map +1 -0
  36. package/dist/getRepositoryName.cjs +7 -2
  37. package/dist/getRepositoryName.cjs.map +1 -1
  38. package/dist/getRepositoryName.d.ts +3 -6
  39. package/dist/getRepositoryName.js +7 -2
  40. package/dist/getRepositoryName.js.map +1 -1
  41. package/dist/index.cjs +14 -1
  42. package/dist/index.cjs.map +1 -1
  43. package/dist/index.d.ts +17 -2
  44. package/dist/index.js +14 -1
  45. package/dist/index.js.map +1 -1
  46. package/dist/lib/isMigrationValue.cjs +24 -0
  47. package/dist/lib/isMigrationValue.cjs.map +1 -0
  48. package/dist/lib/isMigrationValue.d.ts +62 -0
  49. package/dist/lib/isMigrationValue.js +24 -0
  50. package/dist/lib/isMigrationValue.js.map +1 -0
  51. package/dist/lib/isValue.cjs +53 -0
  52. package/dist/lib/isValue.cjs.map +1 -0
  53. package/dist/lib/isValue.d.ts +72 -0
  54. package/dist/lib/isValue.js +53 -0
  55. package/dist/lib/isValue.js.map +1 -0
  56. package/dist/lib/pLimit.cjs +49 -0
  57. package/dist/lib/pLimit.cjs.map +1 -0
  58. package/dist/lib/pLimit.d.ts +22 -0
  59. package/dist/lib/pLimit.js +49 -0
  60. package/dist/lib/pLimit.js.map +1 -0
  61. package/dist/lib/resolveMigrationDocumentData.cjs +123 -0
  62. package/dist/lib/resolveMigrationDocumentData.cjs.map +1 -0
  63. package/dist/lib/resolveMigrationDocumentData.d.ts +52 -0
  64. package/dist/lib/resolveMigrationDocumentData.js +123 -0
  65. package/dist/lib/resolveMigrationDocumentData.js.map +1 -0
  66. package/dist/lib/validateAssetMetadata.cjs +28 -0
  67. package/dist/lib/validateAssetMetadata.cjs.map +1 -0
  68. package/dist/lib/validateAssetMetadata.d.ts +10 -0
  69. package/dist/lib/validateAssetMetadata.js +28 -0
  70. package/dist/lib/validateAssetMetadata.js.map +1 -0
  71. package/dist/package.json.cjs +1 -1
  72. package/dist/package.json.js +1 -1
  73. package/dist/types/api/asset/asset.d.ts +177 -0
  74. package/dist/types/api/asset/tag.d.ts +53 -0
  75. package/dist/types/api/migration/document.d.ts +60 -0
  76. package/dist/types/migration/Asset.cjs +33 -0
  77. package/dist/types/migration/Asset.cjs.map +1 -0
  78. package/dist/types/migration/Asset.d.ts +109 -0
  79. package/dist/types/migration/Asset.js +33 -0
  80. package/dist/types/migration/Asset.js.map +1 -0
  81. package/dist/types/migration/ContentRelationship.d.ts +17 -0
  82. package/dist/types/migration/Document.cjs +47 -0
  83. package/dist/types/migration/Document.cjs.map +1 -0
  84. package/dist/types/migration/Document.d.ts +94 -0
  85. package/dist/types/migration/Document.js +47 -0
  86. package/dist/types/migration/Document.js.map +1 -0
  87. package/package.json +2 -2
  88. package/src/BaseClient.ts +330 -0
  89. package/src/Client.ts +1787 -0
  90. package/src/Migration.ts +531 -0
  91. package/src/WriteClient.ts +911 -0
  92. package/src/createClient.ts +3 -1931
  93. package/src/createMigration.ts +31 -0
  94. package/src/createWriteClient.ts +43 -0
  95. package/src/getRepositoryName.ts +19 -14
  96. package/src/index.ts +32 -4
  97. package/src/lib/isMigrationValue.ts +126 -0
  98. package/src/lib/isValue.ts +196 -0
  99. package/src/lib/pLimit.ts +106 -0
  100. package/src/lib/resolveMigrationDocumentData.ts +233 -0
  101. package/src/lib/validateAssetMetadata.ts +82 -0
  102. package/src/types/api/asset/asset.ts +211 -0
  103. package/src/types/api/asset/tag.ts +59 -0
  104. package/src/types/api/migration/document.ts +84 -0
  105. package/src/types/migration/Asset.ts +156 -0
  106. package/src/types/migration/ContentRelationship.ts +36 -0
  107. package/src/types/migration/Document.ts +157 -0
@@ -0,0 +1,156 @@
1
+ import type { Asset } from "../api/asset/asset"
2
+ import type { FilledImageFieldImage } from "../value/image"
3
+ import type { EmptyLinkField } from "../value/link"
4
+ import type { LinkToMediaField } from "../value/linkToMedia"
5
+ import { type RTImageNode } from "../value/richText"
6
+
7
+ import type { InjectMigrationSpecificTypes } from "./Document"
8
+
9
+ /**
10
+ * An asset to be uploaded to Prismic media library.
11
+ */
12
+ export type MigrationAssetConfig = {
13
+ /**
14
+ * ID the assets is indexed with on the migration instance.
15
+ *
16
+ * @remarks
17
+ * This property's value is not necessarily the same as the as the one in the
18
+ * `file` property. It is mainly used for deduplication within a `Migration`
19
+ * instance.
20
+ */
21
+ id: string | URL | File | NonNullable<ConstructorParameters<File>[0]>[0]
22
+
23
+ /**
24
+ * File to be uploaded as an asset.
25
+ */
26
+ file: string | URL | File | NonNullable<ConstructorParameters<File>[0]>[0]
27
+
28
+ /**
29
+ * Filename of the asset.
30
+ */
31
+ filename: string
32
+
33
+ /**
34
+ * Notes about the asset. Notes are private and only visible in Prismic media
35
+ * library.
36
+ */
37
+ notes?: string
38
+
39
+ /**
40
+ * Credits and copyright for the asset if any.
41
+ */
42
+ credits?: string
43
+
44
+ /**
45
+ * Alternate text for the asset.
46
+ */
47
+ alt?: string
48
+
49
+ /**
50
+ * Tags associated with the asset.
51
+ *
52
+ * @remarks
53
+ * Tags should be at least 3 characters long and 20 characters at most.
54
+ */
55
+ tags?: string[]
56
+ }
57
+
58
+ /**
59
+ * An image field in a migration.
60
+ */
61
+ export type MigrationImage =
62
+ | PrismicMigrationAsset
63
+ | ({
64
+ /**
65
+ * A reference to the migration asset used to resolve the image field's
66
+ * value.
67
+ */
68
+ id: PrismicMigrationAsset
69
+ } & Record<string, PrismicMigrationAsset>)
70
+
71
+ /**
72
+ * A link to media field in a migration.
73
+ */
74
+ export type MigrationLinkToMedia = Pick<
75
+ LinkToMediaField<"filled">,
76
+ "link_type"
77
+ > &
78
+ Partial<
79
+ Pick<
80
+ LinkToMediaField<"filled">,
81
+ // TODO: Remove when link text PR is merged
82
+ // @ts-expect-error - Future-proofing for link text
83
+ "text"
84
+ >
85
+ > & {
86
+ /**
87
+ * A reference to the migration asset used to resolve the link to media
88
+ * field's value.
89
+ */
90
+ id: PrismicMigrationAsset
91
+ }
92
+
93
+ /**
94
+ * The minimum amount of information needed to represent a link to media field
95
+ * with the migration API.
96
+ */
97
+ export type MigrationLinkToMediaField =
98
+ // TODO: Remove when link text PR is merged
99
+ // @ts-expect-error - Future-proofing for link text
100
+ | Pick<LinkToMediaField<"filled">, "link_type" | "id" | "text">
101
+ | EmptyLinkField<"Media">
102
+
103
+ /**
104
+ * A rich text image node in a migration.
105
+ */
106
+ export type MigrationRTImageNode = InjectMigrationSpecificTypes<
107
+ Pick<RTImageNode, "type" | "linkTo">
108
+ > & {
109
+ /**
110
+ * A reference to the migration asset used to resolve the rich text image
111
+ * node's value.
112
+ */
113
+ id: PrismicMigrationAsset
114
+ }
115
+
116
+ /**
117
+ * A migration asset used with the Prismic Migration API.
118
+ */
119
+ export class PrismicMigrationAsset {
120
+ /**
121
+ * Asset object from Prismic, available once created.
122
+ */
123
+ asset?: Asset
124
+
125
+ /**
126
+ * Configuration of the asset.
127
+ */
128
+ config: MigrationAssetConfig
129
+
130
+ /**
131
+ * The initial field value this migration field was created with.
132
+ */
133
+ originalField?:
134
+ | FilledImageFieldImage
135
+ | LinkToMediaField<"filled">
136
+ | RTImageNode
137
+
138
+ /**
139
+ * Creates a migration asset used with the Prismic Migration API.
140
+ *
141
+ * @param config - Configuration of the asset.
142
+ * @param initialField - The initial field value if any.
143
+ *
144
+ * @returns A migration asset instance.
145
+ */
146
+ constructor(
147
+ config: MigrationAssetConfig,
148
+ initialField?:
149
+ | FilledImageFieldImage
150
+ | LinkToMediaField<"filled">
151
+ | RTImageNode,
152
+ ) {
153
+ this.config = config
154
+ this.originalField = initialField
155
+ }
156
+ }
@@ -0,0 +1,36 @@
1
+ import type { FilledContentRelationshipField } from "../value/contentRelationship"
2
+ import type { PrismicDocument } from "../value/document"
3
+ import type { EmptyLinkField } from "../value/link"
4
+
5
+ import type { PrismicMigrationDocument } from "./Document"
6
+
7
+ type ValueOrThunk<T> = T | (() => Promise<T> | T)
8
+
9
+ /**
10
+ * A content relationship field in a migration.
11
+ */
12
+ export type MigrationContentRelationship<
13
+ TDocuments extends PrismicDocument = PrismicDocument,
14
+ > =
15
+ | ValueOrThunk<TDocuments | PrismicMigrationDocument<TDocuments> | undefined>
16
+ | (Pick<FilledContentRelationshipField, "link_type"> &
17
+ Partial<
18
+ Pick<
19
+ FilledContentRelationshipField,
20
+ // TODO: Remove when link text PR is merged
21
+ // @ts-expect-error - Future-proofing for link text
22
+ "text"
23
+ >
24
+ > & {
25
+ id: ValueOrThunk<
26
+ TDocuments | PrismicMigrationDocument<TDocuments> | undefined
27
+ >
28
+ })
29
+
30
+ /**
31
+ * The minimum amount of information needed to represent a content relationship
32
+ * field with the migration API.
33
+ */
34
+ export type MigrationContentRelationshipField =
35
+ | Pick<FilledContentRelationshipField, "link_type" | "id">
36
+ | EmptyLinkField<"Document">
@@ -0,0 +1,157 @@
1
+ import type { FilledContentRelationshipField } from "../value/contentRelationship"
2
+ import type { PrismicDocument, PrismicDocumentWithUID } from "../value/document"
3
+ import type { AnyOEmbed, EmbedField, OEmbedExtra } from "../value/embed"
4
+ import type { FilledImageFieldImage } from "../value/image"
5
+ import type { FilledLinkToMediaField } from "../value/linkToMedia"
6
+ import type { RTImageNode } from "../value/richText"
7
+ import type { SharedSlice } from "../value/sharedSlice"
8
+
9
+ import type {
10
+ MigrationImage,
11
+ MigrationLinkToMedia,
12
+ MigrationRTImageNode,
13
+ } from "./Asset"
14
+ import type { MigrationContentRelationship } from "./ContentRelationship"
15
+
16
+ /**
17
+ * A utility type that extends any fields in a record with their migration
18
+ * fields equivalent.
19
+ *
20
+ * @typeParam T - Type of the record to extend.
21
+ */
22
+ export type InjectMigrationSpecificTypes<T> = T extends RTImageNode
23
+ ?
24
+ | T
25
+ | (Omit<T, "linkTo"> & InjectMigrationSpecificTypes<Pick<T, "linkTo">>)
26
+ | MigrationRTImageNode
27
+ | undefined
28
+ : T extends FilledImageFieldImage
29
+ ? T | MigrationImage | undefined
30
+ : T extends FilledLinkToMediaField
31
+ ? T | MigrationLinkToMedia | undefined
32
+ : T extends FilledContentRelationshipField
33
+ ? T | MigrationContentRelationship
34
+ : T extends EmbedField<AnyOEmbed & OEmbedExtra, "filled">
35
+ ? T | Pick<T, "embed_url">
36
+ : T extends SharedSlice
37
+ ?
38
+ | T
39
+ | InjectMigrationSpecificTypes<
40
+ Omit<T, "id" | "slice_label" | "version">
41
+ >
42
+ : // eslint-disable-next-line @typescript-eslint/no-explicit-any
43
+ T extends Record<any, any>
44
+ ? { [P in keyof T]: InjectMigrationSpecificTypes<T[P]> }
45
+ : T extends Array<infer U>
46
+ ? Array<InjectMigrationSpecificTypes<U>>
47
+ : T
48
+
49
+ /**
50
+ * A utility type that ties the type and data of a Prismic document, creating a
51
+ * strict union.
52
+ */
53
+ type TiedDocumentTypeAndData<TDocument extends PrismicDocument> =
54
+ TDocument extends PrismicDocument<infer TData, infer TType>
55
+ ? {
56
+ /**
57
+ * Type of the document.
58
+ */
59
+ type: TType
60
+
61
+ /**
62
+ * Data contained in the document.
63
+ */
64
+ data: InjectMigrationSpecificTypes<TData>
65
+ } & (TDocument extends PrismicDocumentWithUID
66
+ ? Pick<TDocument, "uid">
67
+ : Partial<Pick<TDocument, "uid">>)
68
+ : never
69
+
70
+ /**
71
+ * A pending Prismic document to be created with the Migration API.
72
+ *
73
+ * @typeParam TDocument - Type of the Prismic document.
74
+ */
75
+ export type PendingPrismicDocument<
76
+ TDocument extends PrismicDocument = PrismicDocument,
77
+ > = Pick<TDocument, "lang"> &
78
+ Partial<Pick<TDocument, "tags">> &
79
+ TiedDocumentTypeAndData<TDocument>
80
+
81
+ /**
82
+ * An existing Prismic document to be updated with the Migration API.
83
+ *
84
+ * @typeParam TDocument - Type of the Prismic document.
85
+ */
86
+ export type ExistingPrismicDocument<
87
+ TDocument extends PrismicDocument = PrismicDocument,
88
+ > = Omit<TDocument, "uid" | "type" | "data"> &
89
+ TiedDocumentTypeAndData<TDocument>
90
+
91
+ /**
92
+ * A Prismic document to be sent to the Migration API.
93
+ *
94
+ * @typeParam TDocument - Type of the Prismic document.
95
+ */
96
+ export type MigrationDocument<
97
+ TDocument extends PrismicDocument = PrismicDocument,
98
+ > = PendingPrismicDocument<TDocument> | ExistingPrismicDocument<TDocument>
99
+
100
+ /**
101
+ * A Prismic migration document instance.
102
+ *
103
+ * @typeParam TDocument - Type of the Prismic document.
104
+ */
105
+ export class PrismicMigrationDocument<
106
+ TDocument extends PrismicDocument = PrismicDocument,
107
+ > {
108
+ /**
109
+ * The document to be sent to the Migration API.
110
+ */
111
+ document: MigrationDocument<TDocument> & Partial<Pick<TDocument, "id">>
112
+
113
+ /**
114
+ * The name of the document displayed in the editor.
115
+ */
116
+ title?: string
117
+
118
+ /**
119
+ * The link to the master language document to relate the document to if any.
120
+ */
121
+ masterLanguageDocument?: MigrationContentRelationship
122
+
123
+ /**
124
+ * Original Prismic document when the migration document came from another
125
+ * Prismic repository.
126
+ *
127
+ * @remarks
128
+ * When migrating a document from another repository, one might want to alter
129
+ * it with migration specific types, hence accepting an
130
+ * `ExistingPrismicDocument` instead of a regular `PrismicDocument`.
131
+ */
132
+ originalPrismicDocument?: ExistingPrismicDocument<PrismicDocument>
133
+
134
+ /**
135
+ * Creates a Prismic migration document instance.
136
+ *
137
+ * @param document - The document to be sent to the Migration API.
138
+ * @param title - The name of the document displayed in the editor.
139
+ * @param params - Parameters to create/update the document with on the
140
+ * Migration API.
141
+ *
142
+ * @returns A Prismic migration document instance.
143
+ */
144
+ constructor(
145
+ document: MigrationDocument<TDocument>,
146
+ title?: string,
147
+ params?: {
148
+ masterLanguageDocument?: MigrationContentRelationship
149
+ originalPrismicDocument?: ExistingPrismicDocument<PrismicDocument>
150
+ },
151
+ ) {
152
+ this.document = document
153
+ this.title = title
154
+ this.masterLanguageDocument = params?.masterLanguageDocument
155
+ this.originalPrismicDocument = params?.originalPrismicDocument
156
+ }
157
+ }