@datocms/cma-client 5.1.10 → 5.1.11

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 (206) hide show
  1. package/README.md +575 -0
  2. package/dist/cjs/fieldTypes/boolean.js +2 -2
  3. package/dist/cjs/fieldTypes/boolean.js.map +1 -1
  4. package/dist/cjs/fieldTypes/color.js +2 -2
  5. package/dist/cjs/fieldTypes/color.js.map +1 -1
  6. package/dist/cjs/fieldTypes/date.js +2 -3
  7. package/dist/cjs/fieldTypes/date.js.map +1 -1
  8. package/dist/cjs/fieldTypes/date_time.js +2 -2
  9. package/dist/cjs/fieldTypes/date_time.js.map +1 -1
  10. package/dist/cjs/fieldTypes/file.js +33 -5
  11. package/dist/cjs/fieldTypes/file.js.map +1 -1
  12. package/dist/cjs/fieldTypes/float.js +2 -2
  13. package/dist/cjs/fieldTypes/float.js.map +1 -1
  14. package/dist/cjs/fieldTypes/gallery.js +20 -5
  15. package/dist/cjs/fieldTypes/gallery.js.map +1 -1
  16. package/dist/cjs/fieldTypes/index.js +2 -2
  17. package/dist/cjs/fieldTypes/index.js.map +1 -1
  18. package/dist/cjs/fieldTypes/integer.js +2 -2
  19. package/dist/cjs/fieldTypes/integer.js.map +1 -1
  20. package/dist/cjs/fieldTypes/json.js +2 -3
  21. package/dist/cjs/fieldTypes/json.js.map +1 -1
  22. package/dist/cjs/fieldTypes/lat_lon.js +2 -2
  23. package/dist/cjs/fieldTypes/lat_lon.js.map +1 -1
  24. package/dist/cjs/fieldTypes/link.js +4 -4
  25. package/dist/cjs/fieldTypes/link.js.map +1 -1
  26. package/dist/cjs/fieldTypes/links.js +5 -3
  27. package/dist/cjs/fieldTypes/links.js.map +1 -1
  28. package/dist/cjs/fieldTypes/rich_text.js +4 -6
  29. package/dist/cjs/fieldTypes/rich_text.js.map +1 -1
  30. package/dist/cjs/fieldTypes/seo.js +2 -3
  31. package/dist/cjs/fieldTypes/seo.js.map +1 -1
  32. package/dist/cjs/fieldTypes/single_block.js +7 -7
  33. package/dist/cjs/fieldTypes/single_block.js.map +1 -1
  34. package/dist/cjs/fieldTypes/slug.js +2 -3
  35. package/dist/cjs/fieldTypes/slug.js.map +1 -1
  36. package/dist/cjs/fieldTypes/string.js +2 -2
  37. package/dist/cjs/fieldTypes/string.js.map +1 -1
  38. package/dist/cjs/fieldTypes/structured_text.js +4 -6
  39. package/dist/cjs/fieldTypes/structured_text.js.map +1 -1
  40. package/dist/cjs/fieldTypes/text.js +2 -3
  41. package/dist/cjs/fieldTypes/text.js.map +1 -1
  42. package/dist/cjs/fieldTypes/video.js +2 -2
  43. package/dist/cjs/fieldTypes/video.js.map +1 -1
  44. package/dist/cjs/generated/Client.js +1 -1
  45. package/dist/cjs/index.js +4 -4
  46. package/dist/cjs/index.js.map +1 -1
  47. package/dist/cjs/utilities/buildBlockRecord.js +8 -7
  48. package/dist/cjs/utilities/buildBlockRecord.js.map +1 -1
  49. package/dist/cjs/utilities/inspectItem.js +397 -0
  50. package/dist/cjs/utilities/inspectItem.js.map +1 -0
  51. package/dist/cjs/utilities/{blocks.js → nonRecursiveBlocks.js} +106 -111
  52. package/dist/cjs/utilities/nonRecursiveBlocks.js.map +1 -0
  53. package/dist/cjs/utilities/{fieldValue.js → normalizedFieldValues.js} +53 -41
  54. package/dist/cjs/utilities/normalizedFieldValues.js.map +1 -0
  55. package/dist/cjs/utilities/recursiveBlocks.js +121 -80
  56. package/dist/cjs/utilities/recursiveBlocks.js.map +1 -1
  57. package/dist/cjs/utilities/schemaRepository.js +2 -2
  58. package/dist/esm/fieldTypes/boolean.d.ts +1 -1
  59. package/dist/esm/fieldTypes/boolean.js +2 -2
  60. package/dist/esm/fieldTypes/boolean.js.map +1 -1
  61. package/dist/esm/fieldTypes/color.d.ts +1 -1
  62. package/dist/esm/fieldTypes/color.js +2 -2
  63. package/dist/esm/fieldTypes/color.js.map +1 -1
  64. package/dist/esm/fieldTypes/date.d.ts +1 -1
  65. package/dist/esm/fieldTypes/date.js +2 -3
  66. package/dist/esm/fieldTypes/date.js.map +1 -1
  67. package/dist/esm/fieldTypes/date_time.d.ts +1 -1
  68. package/dist/esm/fieldTypes/date_time.js +2 -2
  69. package/dist/esm/fieldTypes/date_time.js.map +1 -1
  70. package/dist/esm/fieldTypes/file.d.ts +68 -1
  71. package/dist/esm/fieldTypes/file.js +29 -3
  72. package/dist/esm/fieldTypes/file.js.map +1 -1
  73. package/dist/esm/fieldTypes/float.d.ts +1 -1
  74. package/dist/esm/fieldTypes/float.js +2 -2
  75. package/dist/esm/fieldTypes/float.js.map +1 -1
  76. package/dist/esm/fieldTypes/gallery.d.ts +27 -11
  77. package/dist/esm/fieldTypes/gallery.js +17 -4
  78. package/dist/esm/fieldTypes/gallery.js.map +1 -1
  79. package/dist/esm/fieldTypes/index.d.ts +2 -2
  80. package/dist/esm/fieldTypes/index.js +2 -2
  81. package/dist/esm/fieldTypes/index.js.map +1 -1
  82. package/dist/esm/fieldTypes/integer.d.ts +1 -1
  83. package/dist/esm/fieldTypes/integer.js +2 -2
  84. package/dist/esm/fieldTypes/integer.js.map +1 -1
  85. package/dist/esm/fieldTypes/json.d.ts +1 -1
  86. package/dist/esm/fieldTypes/json.js +2 -3
  87. package/dist/esm/fieldTypes/json.js.map +1 -1
  88. package/dist/esm/fieldTypes/lat_lon.d.ts +1 -1
  89. package/dist/esm/fieldTypes/lat_lon.js +2 -2
  90. package/dist/esm/fieldTypes/lat_lon.js.map +1 -1
  91. package/dist/esm/fieldTypes/link.d.ts +1 -1
  92. package/dist/esm/fieldTypes/link.js +4 -4
  93. package/dist/esm/fieldTypes/link.js.map +1 -1
  94. package/dist/esm/fieldTypes/links.d.ts +1 -1
  95. package/dist/esm/fieldTypes/links.js +5 -3
  96. package/dist/esm/fieldTypes/links.js.map +1 -1
  97. package/dist/esm/fieldTypes/rich_text.d.ts +1 -1
  98. package/dist/esm/fieldTypes/rich_text.js +4 -6
  99. package/dist/esm/fieldTypes/rich_text.js.map +1 -1
  100. package/dist/esm/fieldTypes/seo.d.ts +1 -1
  101. package/dist/esm/fieldTypes/seo.js +2 -3
  102. package/dist/esm/fieldTypes/seo.js.map +1 -1
  103. package/dist/esm/fieldTypes/single_block.d.ts +1 -1
  104. package/dist/esm/fieldTypes/single_block.js +7 -7
  105. package/dist/esm/fieldTypes/single_block.js.map +1 -1
  106. package/dist/esm/fieldTypes/slug.d.ts +1 -1
  107. package/dist/esm/fieldTypes/slug.js +2 -3
  108. package/dist/esm/fieldTypes/slug.js.map +1 -1
  109. package/dist/esm/fieldTypes/string.d.ts +1 -1
  110. package/dist/esm/fieldTypes/string.js +2 -2
  111. package/dist/esm/fieldTypes/string.js.map +1 -1
  112. package/dist/esm/fieldTypes/structured_text.d.ts +1 -1
  113. package/dist/esm/fieldTypes/structured_text.js +4 -6
  114. package/dist/esm/fieldTypes/structured_text.js.map +1 -1
  115. package/dist/esm/fieldTypes/text.d.ts +1 -1
  116. package/dist/esm/fieldTypes/text.js +2 -3
  117. package/dist/esm/fieldTypes/text.js.map +1 -1
  118. package/dist/esm/fieldTypes/video.d.ts +1 -1
  119. package/dist/esm/fieldTypes/video.js +2 -2
  120. package/dist/esm/fieldTypes/video.js.map +1 -1
  121. package/dist/esm/generated/Client.js +1 -1
  122. package/dist/esm/index.d.ts +4 -4
  123. package/dist/esm/index.js +4 -4
  124. package/dist/esm/index.js.map +1 -1
  125. package/dist/esm/utilities/buildBlockRecord.js +9 -8
  126. package/dist/esm/utilities/buildBlockRecord.js.map +1 -1
  127. package/dist/esm/utilities/inspectItem.d.ts +8 -0
  128. package/dist/esm/utilities/inspectItem.js +393 -0
  129. package/dist/esm/utilities/inspectItem.js.map +1 -0
  130. package/dist/esm/utilities/itemDefinition.d.ts +28 -4
  131. package/dist/esm/utilities/nonRecursiveBlocks.d.ts +179 -0
  132. package/dist/esm/utilities/{blocks.js → nonRecursiveBlocks.js} +91 -96
  133. package/dist/esm/utilities/nonRecursiveBlocks.js.map +1 -0
  134. package/dist/{types/utilities/fieldValue.d.ts → esm/utilities/normalizedFieldValues.d.ts} +15 -14
  135. package/dist/esm/utilities/{fieldValue.js → normalizedFieldValues.js} +39 -28
  136. package/dist/esm/utilities/normalizedFieldValues.js.map +1 -0
  137. package/dist/esm/utilities/recursiveBlocks.d.ts +92 -9
  138. package/dist/esm/utilities/recursiveBlocks.js +113 -72
  139. package/dist/esm/utilities/recursiveBlocks.js.map +1 -1
  140. package/dist/esm/utilities/schemaRepository.d.ts +2 -2
  141. package/dist/esm/utilities/schemaRepository.js +2 -2
  142. package/dist/types/fieldTypes/boolean.d.ts +1 -1
  143. package/dist/types/fieldTypes/color.d.ts +1 -1
  144. package/dist/types/fieldTypes/date.d.ts +1 -1
  145. package/dist/types/fieldTypes/date_time.d.ts +1 -1
  146. package/dist/types/fieldTypes/file.d.ts +68 -1
  147. package/dist/types/fieldTypes/float.d.ts +1 -1
  148. package/dist/types/fieldTypes/gallery.d.ts +27 -11
  149. package/dist/types/fieldTypes/index.d.ts +2 -2
  150. package/dist/types/fieldTypes/integer.d.ts +1 -1
  151. package/dist/types/fieldTypes/json.d.ts +1 -1
  152. package/dist/types/fieldTypes/lat_lon.d.ts +1 -1
  153. package/dist/types/fieldTypes/link.d.ts +1 -1
  154. package/dist/types/fieldTypes/links.d.ts +1 -1
  155. package/dist/types/fieldTypes/rich_text.d.ts +1 -1
  156. package/dist/types/fieldTypes/seo.d.ts +1 -1
  157. package/dist/types/fieldTypes/single_block.d.ts +1 -1
  158. package/dist/types/fieldTypes/slug.d.ts +1 -1
  159. package/dist/types/fieldTypes/string.d.ts +1 -1
  160. package/dist/types/fieldTypes/structured_text.d.ts +1 -1
  161. package/dist/types/fieldTypes/text.d.ts +1 -1
  162. package/dist/types/fieldTypes/video.d.ts +1 -1
  163. package/dist/types/index.d.ts +4 -4
  164. package/dist/types/utilities/inspectItem.d.ts +8 -0
  165. package/dist/types/utilities/itemDefinition.d.ts +28 -4
  166. package/dist/types/utilities/nonRecursiveBlocks.d.ts +179 -0
  167. package/dist/{esm/utilities/fieldValue.d.ts → types/utilities/normalizedFieldValues.d.ts} +15 -14
  168. package/dist/types/utilities/recursiveBlocks.d.ts +92 -9
  169. package/dist/types/utilities/schemaRepository.d.ts +2 -2
  170. package/package.json +3 -3
  171. package/src/fieldTypes/boolean.ts +5 -3
  172. package/src/fieldTypes/color.ts +5 -3
  173. package/src/fieldTypes/date.ts +5 -4
  174. package/src/fieldTypes/date_time.ts +5 -3
  175. package/src/fieldTypes/file.ts +98 -4
  176. package/src/fieldTypes/float.ts +5 -3
  177. package/src/fieldTypes/gallery.ts +53 -20
  178. package/src/fieldTypes/index.ts +2 -3
  179. package/src/fieldTypes/integer.ts +5 -3
  180. package/src/fieldTypes/json.ts +5 -4
  181. package/src/fieldTypes/lat_lon.ts +5 -3
  182. package/src/fieldTypes/link.ts +7 -5
  183. package/src/fieldTypes/links.ts +8 -4
  184. package/src/fieldTypes/rich_text.ts +7 -7
  185. package/src/fieldTypes/seo.ts +5 -4
  186. package/src/fieldTypes/single_block.ts +10 -8
  187. package/src/fieldTypes/slug.ts +5 -4
  188. package/src/fieldTypes/string.ts +5 -3
  189. package/src/fieldTypes/structured_text.ts +7 -7
  190. package/src/fieldTypes/text.ts +5 -4
  191. package/src/fieldTypes/video.ts +5 -3
  192. package/src/generated/Client.ts +1 -1
  193. package/src/index.ts +4 -4
  194. package/src/utilities/buildBlockRecord.ts +16 -15
  195. package/src/utilities/inspectItem.ts +590 -0
  196. package/src/utilities/itemDefinition.ts +30 -3
  197. package/src/utilities/{blocks.ts → nonRecursiveBlocks.ts} +170 -136
  198. package/src/utilities/{fieldValue.ts → normalizedFieldValues.ts} +70 -30
  199. package/src/utilities/recursiveBlocks.ts +186 -171
  200. package/src/utilities/schemaRepository.ts +2 -2
  201. package/dist/cjs/utilities/blocks.js.map +0 -1
  202. package/dist/cjs/utilities/fieldValue.js.map +0 -1
  203. package/dist/esm/utilities/blocks.d.ts +0 -180
  204. package/dist/esm/utilities/blocks.js.map +0 -1
  205. package/dist/esm/utilities/fieldValue.js.map +0 -1
  206. package/dist/types/utilities/blocks.d.ts +0 -180
@@ -10,7 +10,7 @@ import type {
10
10
  ToItemDefinitionAsRequest,
11
11
  ToItemDefinitionWithNestedBlocks,
12
12
  } from './itemDefinition';
13
- import { mapBlocksInFieldValues } from './recursiveBlocks';
13
+ import { mapBlocksInNonLocalizedFieldValue } from './recursiveBlocks';
14
14
  import type { SchemaRepository } from './schemaRepository';
15
15
 
16
16
  type NoInfer<T> = [T][T extends any ? 0 : never];
@@ -52,22 +52,23 @@ export async function duplicateBlockRecord<
52
52
  const fields = await schemaRepository.getRawItemTypeFields(itemType);
53
53
 
54
54
  for (const field of fields) {
55
- newBlock.attributes[field.attributes.api_key] = mapBlocksInFieldValues(
56
- schemaRepository,
57
- field,
58
- newBlock.attributes[field.attributes.api_key],
59
- (block, path) => {
60
- if (typeof block === 'string') {
61
- throw new Error(
62
- `Block cannot be duplicated as it contains nested block at ${path.join('.')} that is expressed as ID (${block}) instead of full object!`,
63
- );
64
- }
55
+ newBlock.attributes[field.attributes.api_key] =
56
+ mapBlocksInNonLocalizedFieldValue(
57
+ schemaRepository,
58
+ field.attributes.field_type,
59
+ newBlock.attributes[field.attributes.api_key],
60
+ (block, path) => {
61
+ if (typeof block === 'string') {
62
+ throw new Error(
63
+ `Block cannot be duplicated as it contains nested block at ${path.join('.')} that is expressed as ID (${block}) instead of full object!`,
64
+ );
65
+ }
65
66
 
66
- const { id, meta, ...blockWithoutIdAndMeta } = block;
67
+ const { id, meta, ...blockWithoutIdAndMeta } = block;
67
68
 
68
- return blockWithoutIdAndMeta;
69
- },
70
- );
69
+ return blockWithoutIdAndMeta;
70
+ },
71
+ );
71
72
  }
72
73
 
73
74
  return newBlock as NewBlockInARequest<ToItemDefinitionAsRequest<NoInfer<D>>>;
@@ -0,0 +1,590 @@
1
+ import {
2
+ type TreeNode,
3
+ formatAsTree,
4
+ inspectionTreeNodes,
5
+ } from 'datocms-structured-text-utils';
6
+ import {
7
+ type BlockItemInARequest,
8
+ type BooleanFieldValue,
9
+ type ColorFieldValue,
10
+ type DateFieldValue,
11
+ type DateTimeFieldValue,
12
+ type FileFieldValue,
13
+ type FileFieldValueAsRequest,
14
+ type FloatFieldValue,
15
+ type GalleryFieldValue,
16
+ type GalleryFieldValueAsRequest,
17
+ type IntegerFieldValue,
18
+ type JsonFieldValue,
19
+ type LatLonFieldValue,
20
+ type LinkFieldValue,
21
+ type LinksFieldValue,
22
+ type NewBlockInARequest,
23
+ type RichTextFieldValue,
24
+ type RichTextFieldValueAsRequest,
25
+ type RichTextFieldValueWithNestedBlocks,
26
+ type SeoFieldValue,
27
+ type SingleBlockFieldValue,
28
+ type SingleBlockFieldValueAsRequest,
29
+ type SingleBlockFieldValueWithNestedBlocks,
30
+ type SlugFieldValue,
31
+ type StringFieldValue,
32
+ type StructuredTextFieldValue,
33
+ type StructuredTextFieldValueAsRequest,
34
+ type StructuredTextFieldValueWithNestedBlocks,
35
+ type TextFieldValue,
36
+ type UpdatedBlockInARequest,
37
+ type VideoFieldValue,
38
+ isBooleanFieldValue,
39
+ isColorFieldValue,
40
+ isDateFieldValue,
41
+ isDateTimeFieldValue,
42
+ isFileFieldValue,
43
+ isFileFieldValueAsRequest,
44
+ isFloatFieldValue,
45
+ isGalleryFieldValue,
46
+ isGalleryFieldValueAsRequest,
47
+ isIntegerFieldValue,
48
+ isJsonFieldValue,
49
+ isLatLonFieldValue,
50
+ isLinkFieldValue,
51
+ isLinksFieldValue,
52
+ isRichTextFieldValue,
53
+ isRichTextFieldValueAsRequest,
54
+ isRichTextFieldValueWithNestedBlocks,
55
+ isSeoFieldValue,
56
+ isSingleBlockFieldValue,
57
+ isSingleBlockFieldValueAsRequest,
58
+ isSingleBlockFieldValueWithNestedBlocks,
59
+ isSlugFieldValue,
60
+ isStringFieldValue,
61
+ isStructuredTextFieldValue,
62
+ isStructuredTextFieldValueAsRequest,
63
+ isStructuredTextFieldValueWithNestedBlocks,
64
+ isTextFieldValue,
65
+ isVideoFieldValue,
66
+ } from '../fieldTypes';
67
+
68
+ import { type ApiTypes, type RawApiTypes, buildBlockRecord } from '../index';
69
+ import type { LocalizedFieldValue } from './normalizedFieldValues';
70
+ import { isLocalizedFieldValue } from './normalizedFieldValues';
71
+
72
+ type Item =
73
+ | ApiTypes.Item
74
+ | RawApiTypes.Item
75
+ | NewBlockInARequest
76
+ | UpdatedBlockInARequest
77
+ | RawApiTypes.ItemCreateSchema
78
+ | RawApiTypes.ItemUpdateSchema
79
+ | ApiTypes.ItemCreateSchema
80
+ | ApiTypes.ItemUpdateSchema;
81
+
82
+ interface FieldTypeHandler {
83
+ guard: (value: unknown) => boolean;
84
+ inspect: (
85
+ value: any,
86
+ options?: InspectItemOptions,
87
+ ) => string | TreeNode | TreeNode[];
88
+ }
89
+
90
+ const fieldTypeHandlers: FieldTypeHandler[] = [
91
+ { guard: isBooleanFieldValue, inspect: booleanInspectionTreeNodes },
92
+ { guard: isFloatFieldValue, inspect: floatInspectionTreeNodes },
93
+ { guard: isIntegerFieldValue, inspect: integerInspectionTreeNodes },
94
+ { guard: isColorFieldValue, inspect: colorInspectionTreeNodes },
95
+ { guard: isDateFieldValue, inspect: dateInspectionTreeNodes },
96
+ { guard: isDateTimeFieldValue, inspect: dateTimeInspectionTreeNodes },
97
+ { guard: isGalleryFieldValue, inspect: galleryInspectionTreeNodes },
98
+ { guard: isGalleryFieldValueAsRequest, inspect: galleryInspectionTreeNodes },
99
+ { guard: isFileFieldValue, inspect: fileInspectionTreeNodes },
100
+ { guard: isFileFieldValueAsRequest, inspect: fileInspectionTreeNodes },
101
+ { guard: isJsonFieldValue, inspect: jsonInspectionTreeNodes },
102
+ { guard: isSlugFieldValue, inspect: slugInspectionTreeNodes },
103
+ { guard: isStringFieldValue, inspect: stringInspectionTreeNodes },
104
+ { guard: isTextFieldValue, inspect: textInspectionTreeNodes },
105
+ { guard: isLatLonFieldValue, inspect: latLonInspectionTreeNodes },
106
+ { guard: isLinkFieldValue, inspect: linkInspectionTreeNodes },
107
+ { guard: isLinksFieldValue, inspect: linksInspectionTreeNodes },
108
+ { guard: isSeoFieldValue, inspect: seoFieldInspectionTreeNodes },
109
+ { guard: isVideoFieldValue, inspect: videoFieldInspectionTreeNodes },
110
+ {
111
+ guard: isStructuredTextFieldValue,
112
+ inspect: structuredTextInspectionTreeNodes,
113
+ },
114
+ {
115
+ guard: isStructuredTextFieldValueAsRequest,
116
+ inspect: structuredTextInspectionTreeNodes,
117
+ },
118
+ {
119
+ guard: isStructuredTextFieldValueWithNestedBlocks,
120
+ inspect: structuredTextInspectionTreeNodes,
121
+ },
122
+ { guard: isSingleBlockFieldValue, inspect: singleBlockInspectionTreeNodes },
123
+ {
124
+ guard: isSingleBlockFieldValueAsRequest,
125
+ inspect: singleBlockInspectionTreeNodes,
126
+ },
127
+ {
128
+ guard: isSingleBlockFieldValueWithNestedBlocks,
129
+ inspect: singleBlockInspectionTreeNodes,
130
+ },
131
+ { guard: isRichTextFieldValue, inspect: richTextInspectionTreeNodes },
132
+ {
133
+ guard: isRichTextFieldValueAsRequest,
134
+ inspect: richTextInspectionTreeNodes,
135
+ },
136
+ {
137
+ guard: isRichTextFieldValueWithNestedBlocks,
138
+ inspect: richTextInspectionTreeNodes,
139
+ },
140
+ ];
141
+
142
+ function createChildNode(
143
+ attributeName: string,
144
+ inspectResult: string | TreeNode | TreeNode[],
145
+ ): TreeNode {
146
+ if (typeof inspectResult === 'string') {
147
+ return { label: `${attributeName}: ${inspectResult}` };
148
+ }
149
+
150
+ if (Array.isArray(inspectResult)) {
151
+ return {
152
+ label: attributeName,
153
+ nodes: inspectResult,
154
+ };
155
+ }
156
+
157
+ // Single TreeNode
158
+ return {
159
+ label: attributeName,
160
+ nodes: [inspectResult],
161
+ };
162
+ }
163
+
164
+ function inspectFieldValue(
165
+ value: unknown,
166
+ options?: InspectItemOptions,
167
+ ): string | TreeNode | TreeNode[] {
168
+ if (isLocalizedFieldValue(value)) {
169
+ for (const handler of fieldTypeHandlers) {
170
+ if (
171
+ Object.values(value).every((localeValue) => handler.guard(localeValue))
172
+ ) {
173
+ const localeEntries = Object.entries(value).sort(([a], [b]) =>
174
+ a.localeCompare(b),
175
+ );
176
+
177
+ return localeEntries.map(([locale, localeValue]) => {
178
+ const inspectResult = handler.inspect(localeValue, options);
179
+
180
+ if (typeof inspectResult === 'string') {
181
+ return { label: `${locale}: ${inspectResult}` };
182
+ }
183
+
184
+ if (Array.isArray(inspectResult)) {
185
+ return {
186
+ label: locale,
187
+ nodes: inspectResult,
188
+ };
189
+ }
190
+
191
+ // Single TreeNode
192
+ return {
193
+ label: locale,
194
+ nodes: [inspectResult],
195
+ };
196
+ });
197
+ }
198
+ }
199
+ }
200
+
201
+ for (const handler of fieldTypeHandlers) {
202
+ if (handler.guard(value)) {
203
+ return handler.inspect(value, options);
204
+ }
205
+ }
206
+
207
+ // Fallback for unknown field types
208
+ return `UNKNOWN: ${JSON.stringify(value)}`;
209
+ }
210
+
211
+ function extractAttributes(item: Item): Record<string, unknown> {
212
+ if ('attributes' in item) {
213
+ return item.attributes as Record<string, unknown>;
214
+ }
215
+
216
+ const serializedItem = buildBlockRecord(item);
217
+ const { __itemTypeId, ...rest } = serializedItem.attributes;
218
+ return rest;
219
+ }
220
+
221
+ export type InspectItemOptions = {
222
+ maxWidth?: number;
223
+ };
224
+
225
+ export function inspectItem(item: Item, options?: InspectItemOptions): string {
226
+ return formatAsTree(itemInspectionTreeNodes(item, options));
227
+ }
228
+
229
+ function itemInspectionTreeNodes(
230
+ item: Item,
231
+ options?: InspectItemOptions,
232
+ ): TreeNode {
233
+ let itemTypeId: string | undefined;
234
+
235
+ if ('relationships' in item && item.relationships) {
236
+ const relationships = item.relationships as any;
237
+ if (relationships.item_type?.data?.id) {
238
+ itemTypeId = relationships.item_type.data.id;
239
+ }
240
+ }
241
+
242
+ const rootLabel = [
243
+ 'Item',
244
+ 'id' in item ? JSON.stringify(item.id) : null,
245
+ itemTypeId ? `(item_type: ${JSON.stringify(itemTypeId)})` : null,
246
+ ]
247
+ .filter(Boolean)
248
+ .join(' ');
249
+
250
+ const nodes: TreeNode[] = [];
251
+
252
+ for (const [attributeName, attributeValue] of Object.entries(
253
+ extractAttributes(item),
254
+ )) {
255
+ const inspectResult = inspectFieldValue(attributeValue, options);
256
+ nodes.push(createChildNode(attributeName, inspectResult));
257
+ }
258
+
259
+ return {
260
+ label: rootLabel,
261
+ nodes: nodes.length > 0 ? nodes : undefined,
262
+ };
263
+ }
264
+
265
+ function structuredTextInspectionTreeNodes(
266
+ value:
267
+ | StructuredTextFieldValue
268
+ | StructuredTextFieldValueAsRequest
269
+ | StructuredTextFieldValueWithNestedBlocks,
270
+ options?: InspectItemOptions,
271
+ ) {
272
+ if (value === null) return 'null';
273
+
274
+ return inspectionTreeNodes<BlockItemInARequest, BlockItemInARequest>(value, {
275
+ maxWidth: options?.maxWidth || 80,
276
+ blockFormatter: (block, maxWidth) => {
277
+ if (typeof block === 'string') {
278
+ return JSON.stringify(block);
279
+ }
280
+
281
+ return itemInspectionTreeNodes(block, options);
282
+ },
283
+ });
284
+ }
285
+
286
+ function singleBlockInspectionTreeNodes(
287
+ value:
288
+ | SingleBlockFieldValue
289
+ | SingleBlockFieldValueAsRequest
290
+ | SingleBlockFieldValueWithNestedBlocks,
291
+ options?: InspectItemOptions,
292
+ ) {
293
+ if (value === null) return 'null';
294
+ if (typeof value === 'string') return JSON.stringify(value);
295
+ return itemInspectionTreeNodes(value, options);
296
+ }
297
+
298
+ function richTextInspectionTreeNodes(
299
+ value:
300
+ | RichTextFieldValue
301
+ | RichTextFieldValueAsRequest
302
+ | RichTextFieldValueWithNestedBlocks,
303
+ options?: InspectItemOptions,
304
+ ): string | TreeNode[] {
305
+ if (value === null) return 'null';
306
+
307
+ return value.map<TreeNode>((item, index) => {
308
+ const result = singleBlockInspectionTreeNodes(item, options);
309
+ if (typeof result === 'string') {
310
+ return { label: `[${index}] ${result}` };
311
+ }
312
+ result.label = `[${index}] ${result.label}`;
313
+ return result;
314
+ });
315
+ }
316
+
317
+ function booleanInspectionTreeNodes(value: BooleanFieldValue): string {
318
+ return JSON.stringify(value);
319
+ }
320
+
321
+ function colorInspectionTreeNodes(value: ColorFieldValue): string {
322
+ if (value === null) return 'null';
323
+
324
+ const { red, green, blue, alpha } = value;
325
+ const hex = `#${red.toString(16).padStart(2, '0').toUpperCase()}${green.toString(16).padStart(2, '0').toUpperCase()}${blue.toString(16).padStart(2, '0').toUpperCase()}`;
326
+
327
+ if (alpha === 255) {
328
+ return hex;
329
+ }
330
+ const alphaPercent = Math.round((alpha / 255) * 100);
331
+ return `${hex} ${alphaPercent}%`;
332
+ }
333
+
334
+ function dateInspectionTreeNodes(value: DateFieldValue): string {
335
+ if (value === null) return 'null';
336
+ return value;
337
+ }
338
+
339
+ function dateTimeInspectionTreeNodes(value: DateTimeFieldValue): string {
340
+ if (value === null) return 'null';
341
+ return value;
342
+ }
343
+
344
+ function fileInspectionTreeNodes(
345
+ value: FileFieldValue | FileFieldValueAsRequest,
346
+ options?: InspectItemOptions,
347
+ ): string | TreeNode[] {
348
+ if (value === null) return 'null';
349
+
350
+ const nodes: TreeNode[] = [];
351
+
352
+ nodes.push({ label: `upload_id: ${JSON.stringify(value.upload_id)}` });
353
+
354
+ if (value.alt) {
355
+ nodes.push({
356
+ label: `alt: ${JSON.stringify(truncate(value.alt, options?.maxWidth || 80))}`,
357
+ });
358
+ }
359
+
360
+ if (value.title) {
361
+ nodes.push({
362
+ label: `title: ${JSON.stringify(truncate(value.title, options?.maxWidth || 80))}`,
363
+ });
364
+ }
365
+
366
+ if (value.custom_data && Object.keys(value.custom_data).length > 0) {
367
+ nodes.push({
368
+ label: `custom_data: ${truncate(JSON.stringify(value.custom_data), options?.maxWidth || 80)}`,
369
+ });
370
+ }
371
+
372
+ if (value.focal_point) {
373
+ const x = value.focal_point.x * 100;
374
+ const y = value.focal_point.y * 100;
375
+ nodes.push({ label: `focal_point: x=${x}% y=${y}%` });
376
+ }
377
+
378
+ return nodes;
379
+ }
380
+
381
+ function floatInspectionTreeNodes(value: FloatFieldValue): string {
382
+ if (value === null) return 'null';
383
+ return value.toString();
384
+ }
385
+
386
+ function galleryInspectionTreeNodes(
387
+ value: GalleryFieldValue | GalleryFieldValueAsRequest,
388
+ options?: InspectItemOptions,
389
+ ): string | TreeNode[] {
390
+ if (!value || value.length === 0) return '[]';
391
+
392
+ const itemNodes: TreeNode[] = value.map((item, index) => {
393
+ const nodes: TreeNode[] = [];
394
+
395
+ nodes.push({
396
+ label: `upload_id: ${JSON.stringify(item.upload_id)}`,
397
+ });
398
+
399
+ if (item.alt) {
400
+ nodes.push({
401
+ label: `alt: ${JSON.stringify(truncate(item.alt, options?.maxWidth || 80))}`,
402
+ });
403
+ }
404
+
405
+ if (item.title) {
406
+ nodes.push({
407
+ label: `title: ${JSON.stringify(truncate(item.title, options?.maxWidth || 80))}`,
408
+ });
409
+ }
410
+
411
+ if (item.custom_data && Object.keys(item.custom_data).length > 0) {
412
+ nodes.push({
413
+ label: `custom_data: ${truncate(JSON.stringify(item.custom_data), options?.maxWidth || 80)}`,
414
+ });
415
+ }
416
+
417
+ if (item.focal_point) {
418
+ const x = item.focal_point.x * 100;
419
+ const y = item.focal_point.y * 100;
420
+ nodes.push({ label: `focal_point: x=${x}% y=${y}%` });
421
+ }
422
+
423
+ return {
424
+ label: `[${index}]`,
425
+ nodes: nodes,
426
+ };
427
+ });
428
+
429
+ return itemNodes;
430
+ }
431
+
432
+ function integerInspectionTreeNodes(value: IntegerFieldValue): string {
433
+ if (value === null) return 'null';
434
+ return value.toString();
435
+ }
436
+
437
+ function jsonInspectionTreeNodes(
438
+ value: JsonFieldValue,
439
+ options?: InspectItemOptions,
440
+ ): string {
441
+ if (value === null) return 'null';
442
+ return truncate(JSON.stringify(JSON.parse(value)), options?.maxWidth || 80);
443
+ }
444
+
445
+ function latLonInspectionTreeNodes(
446
+ value: LatLonFieldValue,
447
+ ): string | TreeNode[] {
448
+ if (value === null) return 'null';
449
+
450
+ return [
451
+ { label: `latitude: ${value.latitude}` },
452
+ { label: `longitude: ${value.longitude}` },
453
+ ];
454
+ }
455
+
456
+ function linkInspectionTreeNodes(value: LinkFieldValue): string {
457
+ if (value === null) return 'null';
458
+ return JSON.stringify(value);
459
+ }
460
+
461
+ function linksInspectionTreeNodes(value: LinksFieldValue): string | TreeNode[] {
462
+ if (value === null) return 'null';
463
+
464
+ return value.map<TreeNode>((itemId, index) => ({
465
+ label: `[${index}]: ${JSON.stringify(itemId)}`,
466
+ }));
467
+ }
468
+
469
+ function seoFieldInspectionTreeNodes(
470
+ value: SeoFieldValue,
471
+ options?: InspectItemOptions,
472
+ ): string | TreeNode[] {
473
+ if (value === null) return 'null';
474
+
475
+ const nodes: TreeNode[] = [];
476
+
477
+ if (value.title) {
478
+ nodes.push({
479
+ label: `title: ${JSON.stringify(truncate(value.title, options?.maxWidth || 80))}`,
480
+ });
481
+ }
482
+
483
+ if (value.description) {
484
+ nodes.push({
485
+ label: `description: ${JSON.stringify(truncate(value.description, options?.maxWidth || 80))}`,
486
+ });
487
+ }
488
+
489
+ if (value.image) {
490
+ nodes.push({
491
+ label: `image: ${value.image}`,
492
+ });
493
+ }
494
+
495
+ if (value.twitter_card) {
496
+ nodes.push({
497
+ label: `twitter_card: ${value.twitter_card}`,
498
+ });
499
+ }
500
+
501
+ if (value.no_index !== undefined) {
502
+ nodes.push({
503
+ label: `no_index: ${value.no_index}`,
504
+ });
505
+ }
506
+
507
+ return nodes;
508
+ }
509
+
510
+ function slugInspectionTreeNodes(
511
+ value: SlugFieldValue,
512
+ options?: InspectItemOptions,
513
+ ): string {
514
+ if (value === null) return 'null';
515
+ return JSON.stringify(truncate(value, options?.maxWidth || 80));
516
+ }
517
+
518
+ function stringInspectionTreeNodes(
519
+ value: StringFieldValue,
520
+ options?: InspectItemOptions,
521
+ ): string {
522
+ if (value === null) return 'null';
523
+ return JSON.stringify(truncate(value, options?.maxWidth || 80));
524
+ }
525
+
526
+ function textInspectionTreeNodes(
527
+ value: TextFieldValue,
528
+ options?: InspectItemOptions,
529
+ ): string {
530
+ if (value === null) return 'null';
531
+ return JSON.stringify(truncate(value, options?.maxWidth || 80));
532
+ }
533
+
534
+ function videoFieldInspectionTreeNodes(
535
+ value: VideoFieldValue,
536
+ options?: InspectItemOptions,
537
+ ): string | TreeNode[] {
538
+ if (value === null) return 'null';
539
+
540
+ const nodes: TreeNode[] = [];
541
+
542
+ nodes.push({ label: `provider: ${value.provider}` });
543
+ nodes.push({ label: `provider_uid: ${value.provider_uid}` });
544
+ nodes.push({ label: `url: ${value.url}` });
545
+ nodes.push({ label: `size: ${value.width}⨯${value.height}px` });
546
+ nodes.push({ label: `thumbnail_url: ${value.thumbnail_url}` });
547
+
548
+ if (value.title) {
549
+ nodes.push({
550
+ label: `title: ${JSON.stringify(truncate(value.title, options?.maxWidth || 80))}`,
551
+ });
552
+ }
553
+
554
+ return nodes;
555
+ }
556
+
557
+ function localizedFieldValueInspectionTreeNodes(
558
+ value: LocalizedFieldValue<unknown>,
559
+ options?: InspectItemOptions,
560
+ ): TreeNode[] {
561
+ const localeEntries = Object.entries(value).sort(([a], [b]) =>
562
+ a.localeCompare(b),
563
+ );
564
+
565
+ return localeEntries.map(([locale, localeValue]) => {
566
+ const inspectResult = inspectFieldValue(localeValue, options);
567
+
568
+ if (typeof inspectResult === 'string') {
569
+ return { label: `${locale}: ${inspectResult}` };
570
+ }
571
+
572
+ if (Array.isArray(inspectResult)) {
573
+ return {
574
+ label: locale,
575
+ nodes: inspectResult,
576
+ };
577
+ }
578
+
579
+ // Single TreeNode
580
+ return {
581
+ label: locale,
582
+ nodes: [inspectResult],
583
+ };
584
+ });
585
+ }
586
+
587
+ function truncate(text: string, maxWidth: number): string {
588
+ if (text.length <= maxWidth) return text;
589
+ return `${text.slice(0, maxWidth - 3)}...`;
590
+ }
@@ -4,8 +4,10 @@ import type {
4
4
  DateFieldValue,
5
5
  DateTimeFieldValue,
6
6
  FileFieldValue,
7
+ FileFieldValueAsRequest,
7
8
  FloatFieldValue,
8
9
  GalleryFieldValue,
10
+ GalleryFieldValueAsRequest,
9
11
  IntegerFieldValue,
10
12
  JsonFieldValue,
11
13
  LatLonFieldValue,
@@ -26,7 +28,7 @@ import type {
26
28
  TextFieldValue,
27
29
  VideoFieldValue,
28
30
  } from '../fieldTypes';
29
- import type { LocalizedFieldValue } from './fieldValue';
31
+ import type { LocalizedFieldValue } from './normalizedFieldValues';
30
32
 
31
33
  /** Base field definition */
32
34
  type BaseFieldDefinition<Type extends string> = {
@@ -94,7 +96,7 @@ export type ItemDefinition<
94
96
  fields: FieldValues;
95
97
  };
96
98
 
97
- /** Standard field values */
99
+ /** Standard field values (response format) */
98
100
  type FieldTypeToValue = {
99
101
  boolean: BooleanFieldValue;
100
102
  color: ColorFieldValue;
@@ -119,6 +121,31 @@ type FieldTypeToValue = {
119
121
  unknown: unknown;
120
122
  };
121
123
 
124
+ /** Request field values (request format with optional metadata) */
125
+ type FieldTypeToValueAsRequest = {
126
+ boolean: BooleanFieldValue;
127
+ color: ColorFieldValue;
128
+ date: DateFieldValue;
129
+ date_time: DateTimeFieldValue;
130
+ file: FileFieldValueAsRequest;
131
+ float: FloatFieldValue;
132
+ gallery: GalleryFieldValueAsRequest;
133
+ integer: IntegerFieldValue;
134
+ json: JsonFieldValue;
135
+ lat_lon: LatLonFieldValue;
136
+ link: LinkFieldValue;
137
+ links: LinksFieldValue;
138
+ rich_text: RichTextFieldValueAsRequest;
139
+ seo: SeoFieldValue;
140
+ single_block: SingleBlockFieldValueAsRequest;
141
+ slug: SlugFieldValue;
142
+ string: StringFieldValue;
143
+ structured_text: StructuredTextFieldValueAsRequest;
144
+ text: TextFieldValue;
145
+ video: VideoFieldValue;
146
+ unknown: unknown;
147
+ };
148
+
122
149
  /** Localized wrapper */
123
150
  type LocalizeIfNeeded<
124
151
  T extends FieldDefinition,
@@ -159,7 +186,7 @@ type FieldDefinitionToFieldValueAsRequest<
159
186
  >,
160
187
  Locales
161
188
  >
162
- : LocalizeIfNeeded<T, FieldTypeToValue[T['type']], Locales>;
189
+ : LocalizeIfNeeded<T, FieldTypeToValueAsRequest[T['type']], Locales>;
163
190
 
164
191
  type FieldDefinitionToFieldValueWithNestedBlocks<
165
192
  T extends FieldDefinition,