@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
@@ -1,4 +1,7 @@
1
- import type { LocalizedFieldValue } from '../utilities/fieldValue';
1
+ import {
2
+ type LocalizedFieldValue,
3
+ isLocalizedFieldValue,
4
+ } from '../utilities/normalizedFieldValues';
2
5
  import type { FileEditorConfiguration } from './appearance/file';
3
6
  import type { ExtensionValidator } from './validators/extension';
4
7
  import type { FileSizeValidator } from './validators/file_size';
@@ -7,7 +10,63 @@ import type { ImageDimensionsValidator } from './validators/image_dimensions';
7
10
  import type { RequiredValidator } from './validators/required';
8
11
  import type { RequiredAltTitleValidator } from './validators/required_alt_title';
9
12
 
13
+ /**
14
+ * FILE FIELD TYPE SYSTEM FOR DATOCMS
15
+ *
16
+ * This module defines a comprehensive type system for handling DatoCMS File fields,
17
+ * which contain file uploads with optional metadata like alt text, title, custom data, and focal points.
18
+ *
19
+ * The challenge we're solving:
20
+ * - DatoCMS File fields can have optional metadata fields (alt, title, custom_data, focal_point)
21
+ * - For API requests, all these fields are optional and can be omitted
22
+ * - For API responses, DatoCMS provides default values for missing fields:
23
+ * - alt: null
24
+ * - title: null
25
+ * - custom_data: {}
26
+ * - focal_point: null
27
+ * - This creates a need for different type variants for the same conceptual data structure
28
+ *
29
+ * This module provides separate types for:
30
+ * 1. API request format (optional metadata fields)
31
+ * 2. API response format (all fields present with defaults)
32
+ */
33
+
34
+ /**
35
+ * =============================================================================
36
+ * BASIC FILE TYPE - Default API response format
37
+ * =============================================================================
38
+ *
39
+ * The standard File field value with all metadata fields present and default values applied.
40
+ * This is what you get from API responses where DatoCMS has applied default values.
41
+ */
42
+
43
+ /**
44
+ * Basic File field value - all metadata fields present with defaults applied
45
+ */
10
46
  export type FileFieldValue = {
47
+ upload_id: string;
48
+ alt: string | null;
49
+ title: string | null;
50
+ custom_data: Record<string, unknown>;
51
+ focal_point: {
52
+ x: number;
53
+ y: number;
54
+ } | null;
55
+ } | null;
56
+
57
+ /**
58
+ * =============================================================================
59
+ * REQUEST VARIANT - Type for sending data TO the DatoCMS API
60
+ * =============================================================================
61
+ *
62
+ * When making API requests, metadata fields are optional and can be omitted.
63
+ * DatoCMS will apply default values for any missing fields in the response.
64
+ */
65
+
66
+ /**
67
+ * File field value for API requests - metadata fields are optional
68
+ */
69
+ export type FileFieldValueAsRequest = {
11
70
  upload_id: string;
12
71
  alt?: string | null;
13
72
  title?: string | null;
@@ -18,7 +77,35 @@ export type FileFieldValue = {
18
77
  } | null;
19
78
  } | null;
20
79
 
80
+ /**
81
+ * =============================================================================
82
+ * TYPE GUARDS - Runtime validation functions
83
+ * =============================================================================
84
+ */
85
+
86
+ /**
87
+ * Type guard for basic File field values (response format with all fields present).
88
+ * Validates that all required metadata fields are present.
89
+ */
21
90
  export function isFileFieldValue(value: unknown): value is FileFieldValue {
91
+ if (value === null) return true;
92
+ return (
93
+ isLocalizedFieldValue(value) &&
94
+ 'upload_id' in value &&
95
+ 'alt' in value &&
96
+ 'title' in value &&
97
+ 'custom_data' in value &&
98
+ 'focal_point' in value
99
+ );
100
+ }
101
+
102
+ /**
103
+ * Type guard for File field values in API request format.
104
+ * Allows metadata fields to be optional or omitted.
105
+ */
106
+ export function isFileFieldValueAsRequest(
107
+ value: unknown,
108
+ ): value is FileFieldValueAsRequest {
22
109
  if (value === null) return true;
23
110
  return typeof value === 'object' && value !== null && 'upload_id' in value;
24
111
  }
@@ -27,9 +114,16 @@ export function isLocalizedFileFieldValue(
27
114
  value: unknown,
28
115
  ): value is LocalizedFieldValue<FileFieldValue> {
29
116
  return (
30
- typeof value === 'object' &&
31
- value !== null &&
32
- Object.values(value).every(isFileFieldValue)
117
+ isLocalizedFieldValue(value) && Object.values(value).every(isFileFieldValue)
118
+ );
119
+ }
120
+
121
+ export function isLocalizedFileFieldValueAsRequest(
122
+ value: unknown,
123
+ ): value is LocalizedFieldValue<FileFieldValueAsRequest> {
124
+ return (
125
+ isLocalizedFieldValue(value) &&
126
+ Object.values(value).every(isFileFieldValueAsRequest)
33
127
  );
34
128
  }
35
129
 
@@ -1,4 +1,7 @@
1
- import type { LocalizedFieldValue } from '../utilities/fieldValue';
1
+ import {
2
+ type LocalizedFieldValue,
3
+ isLocalizedFieldValue,
4
+ } from '../utilities/normalizedFieldValues';
2
5
  import type { FloatEditorConfiguration } from './appearance/float';
3
6
  import type { NumberRangeValidator } from './validators/number_range';
4
7
  import type { RequiredValidator } from './validators/required';
@@ -13,8 +16,7 @@ export function isLocalizedFloatFieldValue(
13
16
  value: unknown,
14
17
  ): value is LocalizedFieldValue<FloatFieldValue> {
15
18
  return (
16
- typeof value === 'object' &&
17
- value !== null &&
19
+ isLocalizedFieldValue(value) &&
18
20
  Object.values(value).every(isFloatFieldValue)
19
21
  );
20
22
  }
@@ -1,5 +1,14 @@
1
- import type { LocalizedFieldValue } from '../utilities/fieldValue';
1
+ import {
2
+ type LocalizedFieldValue,
3
+ isLocalizedFieldValue,
4
+ } from '../utilities/normalizedFieldValues';
2
5
  import type { GalleryEditorConfiguration } from './appearance/gallery';
6
+ import {
7
+ type FileFieldValue,
8
+ type FileFieldValueAsRequest,
9
+ isFileFieldValue,
10
+ isFileFieldValueAsRequest,
11
+ } from './file';
3
12
  import type { ExtensionValidator } from './validators/extension';
4
13
  import type { FileSizeValidator } from './validators/file_size';
5
14
  import type { ImageAspectRatioValidator } from './validators/image_aspect_ratio';
@@ -7,39 +16,63 @@ import type { ImageDimensionsValidator } from './validators/image_dimensions';
7
16
  import type { RequiredAltTitleValidator } from './validators/required_alt_title';
8
17
  import type { SizeValidator } from './validators/size';
9
18
 
10
- export type GalleryFieldValue = Array<{
11
- upload_id: string;
12
- alt?: string | null;
13
- title?: string | null;
14
- custom_data?: Record<string, unknown>;
15
- focal_point?: {
16
- x: number;
17
- y: number;
18
- } | null;
19
- }>;
19
+ /**
20
+ * Gallery field type system - similar to File field but for arrays.
21
+ * See file.ts for detailed explanation of request/response duality.
22
+ */
20
23
 
24
+ /**
25
+ * Individual gallery item types - extracted from File field types
26
+ */
27
+ export type GalleryItem = NonNullable<FileFieldValue>;
28
+ export type GalleryItemAsRequest = NonNullable<FileFieldValueAsRequest>;
29
+
30
+ /**
31
+ * Gallery field value - response format with all metadata fields present
32
+ */
33
+ export type GalleryFieldValue = Array<GalleryItem>;
34
+
35
+ /**
36
+ * Gallery field value for API requests - metadata fields are optional
37
+ */
38
+ export type GalleryFieldValueAsRequest = Array<GalleryItemAsRequest>;
39
+
40
+ /**
41
+ * Type guard for Gallery field values - validates each item using File field validation
42
+ */
21
43
  export function isGalleryFieldValue(
22
44
  value: unknown,
23
45
  ): value is GalleryFieldValue {
24
- return (
25
- Array.isArray(value) &&
26
- value.every(
27
- (item) =>
28
- typeof item === 'object' && item !== null && 'upload_id' in item,
29
- )
30
- );
46
+ return Array.isArray(value) && value.every(isFileFieldValue);
47
+ }
48
+
49
+ /**
50
+ * Type guard for Gallery field values in API request format
51
+ */
52
+ export function isGalleryFieldValueAsRequest(
53
+ value: unknown,
54
+ ): value is GalleryFieldValueAsRequest {
55
+ return Array.isArray(value) && value.every(isFileFieldValueAsRequest);
31
56
  }
32
57
 
33
58
  export function isLocalizedGalleryFieldValue(
34
59
  value: unknown,
35
60
  ): value is LocalizedFieldValue<GalleryFieldValue> {
36
61
  return (
37
- typeof value === 'object' &&
38
- value !== null &&
62
+ isLocalizedFieldValue(value) &&
39
63
  Object.values(value).every(isGalleryFieldValue)
40
64
  );
41
65
  }
42
66
 
67
+ export function isLocalizedGalleryFieldValueAsRequest(
68
+ value: unknown,
69
+ ): value is LocalizedFieldValue<GalleryFieldValueAsRequest> {
70
+ return (
71
+ isLocalizedFieldValue(value) &&
72
+ Object.values(value).every(isGalleryFieldValueAsRequest)
73
+ );
74
+ }
75
+
43
76
  export type GalleryFieldValidators = {
44
77
  /** Only accept a number of items within the specified range */
45
78
  size?: SizeValidator;
@@ -1,3 +1,4 @@
1
+ export * from './appearance';
1
2
  export * from './boolean';
2
3
  export * from './color';
3
4
  export * from './date';
@@ -17,7 +18,5 @@ export * from './slug';
17
18
  export * from './string';
18
19
  export * from './structured_text';
19
20
  export * from './text';
20
- export * from './video';
21
-
22
- export * from './appearance';
23
21
  export * from './validators';
22
+ export * from './video';
@@ -1,4 +1,7 @@
1
- import type { LocalizedFieldValue } from '../utilities/fieldValue';
1
+ import {
2
+ type LocalizedFieldValue,
3
+ isLocalizedFieldValue,
4
+ } from '../utilities/normalizedFieldValues';
2
5
  import type { IntegerEditorConfiguration } from './appearance/integer';
3
6
  import type { NumberRangeValidator } from './validators/number_range';
4
7
  import type { RequiredValidator } from './validators/required';
@@ -15,8 +18,7 @@ export function isLocalizedIntegerFieldValue(
15
18
  value: unknown,
16
19
  ): value is LocalizedFieldValue<IntegerFieldValue> {
17
20
  return (
18
- typeof value === 'object' &&
19
- value !== null &&
21
+ isLocalizedFieldValue(value) &&
20
22
  Object.values(value).every(isIntegerFieldValue)
21
23
  );
22
24
  }
@@ -1,4 +1,7 @@
1
- import type { LocalizedFieldValue } from '../utilities/fieldValue';
1
+ import {
2
+ type LocalizedFieldValue,
3
+ isLocalizedFieldValue,
4
+ } from '../utilities/normalizedFieldValues';
2
5
  import type { JsonEditorConfiguration } from './appearance/json';
3
6
  import type { StringCheckboxGroupEditorConfiguration } from './appearance/string_checkbox_group';
4
7
  import type { StringMultiSelectEditorConfiguration } from './appearance/string_multi_select';
@@ -21,9 +24,7 @@ export function isLocalizedJsonFieldValue(
21
24
  value: unknown,
22
25
  ): value is LocalizedFieldValue<JsonFieldValue> {
23
26
  return (
24
- typeof value === 'object' &&
25
- value !== null &&
26
- Object.values(value).every(isJsonFieldValue)
27
+ isLocalizedFieldValue(value) && Object.values(value).every(isJsonFieldValue)
27
28
  );
28
29
  }
29
30
 
@@ -1,4 +1,7 @@
1
- import type { LocalizedFieldValue } from '../utilities/fieldValue';
1
+ import {
2
+ type LocalizedFieldValue,
3
+ isLocalizedFieldValue,
4
+ } from '../utilities/normalizedFieldValues';
2
5
  import type { MapEditorConfiguration } from './appearance/map';
3
6
  import type { RequiredValidator } from './validators/required';
4
7
 
@@ -21,8 +24,7 @@ export function isLocalizedLatLonFieldValue(
21
24
  value: unknown,
22
25
  ): value is LocalizedFieldValue<LatLonFieldValue> {
23
26
  return (
24
- typeof value === 'object' &&
25
- value !== null &&
27
+ isLocalizedFieldValue(value) &&
26
28
  Object.values(value).every(isLatLonFieldValue)
27
29
  );
28
30
  }
@@ -1,4 +1,8 @@
1
- import type { LocalizedFieldValue } from '../utilities/fieldValue';
1
+ import { isValidId } from '../utilities/id';
2
+ import {
3
+ type LocalizedFieldValue,
4
+ isLocalizedFieldValue,
5
+ } from '../utilities/normalizedFieldValues';
2
6
  import type { LinkEmbedEditorConfiguration } from './appearance/link_embed';
3
7
  import type { LinkSelectEditorConfiguration } from './appearance/link_select';
4
8
  import type { ItemItemTypeValidator } from './validators/item_item_type';
@@ -8,16 +12,14 @@ import type { UniqueValidator } from './validators/unique';
8
12
  export type LinkFieldValue = string | null;
9
13
 
10
14
  export function isLinkFieldValue(value: unknown): value is LinkFieldValue {
11
- return typeof value === 'string' || value === null;
15
+ return (typeof value === 'string' && isValidId(value)) || value === null;
12
16
  }
13
17
 
14
18
  export function isLocalizedLinkFieldValue(
15
19
  value: unknown,
16
20
  ): value is LocalizedFieldValue<LinkFieldValue> {
17
21
  return (
18
- typeof value === 'object' &&
19
- value !== null &&
20
- Object.values(value).every(isLinkFieldValue)
22
+ isLocalizedFieldValue(value) && Object.values(value).every(isLinkFieldValue)
21
23
  );
22
24
  }
23
25
 
@@ -1,4 +1,8 @@
1
- import type { LocalizedFieldValue } from '../utilities/fieldValue';
1
+ import { isValidId } from '../utilities/id';
2
+ import {
3
+ type LocalizedFieldValue,
4
+ isLocalizedFieldValue,
5
+ } from '../utilities/normalizedFieldValues';
2
6
  import type { LinksEmbedEditorConfiguration } from './appearance/links_embed';
3
7
  import type { LinksSelectEditorConfiguration } from './appearance/links_select';
4
8
  import type { ItemsItemTypeValidator } from './validators/items_item_type';
@@ -8,7 +12,8 @@ export type LinksFieldValue = string[];
8
12
 
9
13
  export function isLinksFieldValue(value: unknown): value is LinksFieldValue {
10
14
  return (
11
- Array.isArray(value) && value.every((item) => typeof item === 'string')
15
+ Array.isArray(value) &&
16
+ value.every((item) => typeof item === 'string' && isValidId(item))
12
17
  );
13
18
  }
14
19
 
@@ -16,8 +21,7 @@ export function isLocalizedLinksFieldValue(
16
21
  value: unknown,
17
22
  ): value is LocalizedFieldValue<LinksFieldValue> {
18
23
  return (
19
- typeof value === 'object' &&
20
- value !== null &&
24
+ isLocalizedFieldValue(value) &&
21
25
  Object.values(value).every(isLinksFieldValue)
22
26
  );
23
27
  }
@@ -1,6 +1,9 @@
1
1
  import type * as RawApiTypes from '../generated/RawApiTypes';
2
- import type { LocalizedFieldValue } from '../utilities/fieldValue';
3
2
  import type { ItemDefinition } from '../utilities/itemDefinition';
3
+ import {
4
+ type LocalizedFieldValue,
5
+ isLocalizedFieldValue,
6
+ } from '../utilities/normalizedFieldValues';
4
7
  import type { RichTextEditorConfiguration } from './appearance/rich_text';
5
8
  import {
6
9
  type BlockItemInARequest,
@@ -104,8 +107,7 @@ export function isLocalizedRichTextFieldValue(
104
107
  value: unknown,
105
108
  ): value is LocalizedFieldValue<RichTextFieldValue> {
106
109
  return (
107
- typeof value === 'object' &&
108
- value !== null &&
110
+ isLocalizedFieldValue(value) &&
109
111
  Object.values(value).every(isRichTextFieldValue)
110
112
  );
111
113
  }
@@ -136,8 +138,7 @@ export function isLocalizedRichTextFieldValueAsRequest<
136
138
  value: unknown,
137
139
  ): value is LocalizedFieldValue<RichTextFieldValueAsRequest<D>> {
138
140
  return (
139
- typeof value === 'object' &&
140
- value !== null &&
141
+ isLocalizedFieldValue(value) &&
141
142
  Object.values(value).every(isRichTextFieldValueAsRequest)
142
143
  );
143
144
  }
@@ -163,8 +164,7 @@ export function isLocalizedRichTextFieldValueWithNestedBlocks<
163
164
  value: unknown,
164
165
  ): value is LocalizedFieldValue<RichTextFieldValueWithNestedBlocks<D>> {
165
166
  return (
166
- typeof value === 'object' &&
167
- value !== null &&
167
+ isLocalizedFieldValue(value) &&
168
168
  Object.values(value).every(isRichTextFieldValueWithNestedBlocks)
169
169
  );
170
170
  }
@@ -1,4 +1,7 @@
1
- import type { LocalizedFieldValue } from '../utilities/fieldValue';
1
+ import {
2
+ type LocalizedFieldValue,
3
+ isLocalizedFieldValue,
4
+ } from '../utilities/normalizedFieldValues';
2
5
  import type { SeoEditorConfiguration } from './appearance/seo';
3
6
  import type { DescriptionLengthValidator } from './validators/description_length';
4
7
  import type { FileSizeValidator } from './validators/file_size';
@@ -32,9 +35,7 @@ export function isLocalizedSeoFieldValue(
32
35
  value: unknown,
33
36
  ): value is LocalizedFieldValue<SeoFieldValue> {
34
37
  return (
35
- typeof value === 'object' &&
36
- value !== null &&
37
- Object.values(value).every(isSeoFieldValue)
38
+ isLocalizedFieldValue(value) && Object.values(value).every(isSeoFieldValue)
38
39
  );
39
40
  }
40
41
 
@@ -1,6 +1,9 @@
1
1
  import type * as RawApiTypes from '../generated/RawApiTypes';
2
- import type { LocalizedFieldValue } from '../utilities/fieldValue';
3
2
  import type { ItemDefinition } from '../utilities/itemDefinition';
3
+ import {
4
+ type LocalizedFieldValue,
5
+ isLocalizedFieldValue,
6
+ } from '../utilities/normalizedFieldValues';
4
7
 
5
8
  import type { FramedSingleBlockEditorConfiguration } from './appearance/framed_single_block';
6
9
  import type { FramelessSingleBlockEditorConfiguration } from './appearance/frameless_single_block';
@@ -132,7 +135,9 @@ export function isItemWithOptionalIdAndMeta<
132
135
  typeof block === 'object' &&
133
136
  block !== null &&
134
137
  'type' in block &&
135
- 'attributes' in block
138
+ block.type === 'item' &&
139
+ 'attributes' in block &&
140
+ 'relationships' in block
136
141
  );
137
142
  }
138
143
 
@@ -172,8 +177,7 @@ export function isLocalizedSingleBlockFieldValue(
172
177
  value: unknown,
173
178
  ): value is LocalizedFieldValue<SingleBlockFieldValue> {
174
179
  return (
175
- typeof value === 'object' &&
176
- value !== null &&
180
+ isLocalizedFieldValue(value) &&
177
181
  Object.values(value).every(isSingleBlockFieldValue)
178
182
  );
179
183
  }
@@ -200,8 +204,7 @@ export function isLocalizedSingleBlockFieldValueAsRequest<
200
204
  value: unknown,
201
205
  ): value is LocalizedFieldValue<SingleBlockFieldValueAsRequest<D>> {
202
206
  return (
203
- typeof value === 'object' &&
204
- value !== null &&
207
+ isLocalizedFieldValue(value) &&
205
208
  Object.values(value).every(isSingleBlockFieldValueAsRequest)
206
209
  );
207
210
  }
@@ -225,8 +228,7 @@ export function isLocalizedSingleBlockFieldValueWithNestedBlocks<
225
228
  value: unknown,
226
229
  ): value is LocalizedFieldValue<SingleBlockFieldValueWithNestedBlocks<D>> {
227
230
  return (
228
- typeof value === 'object' &&
229
- value !== null &&
231
+ isLocalizedFieldValue(value) &&
230
232
  Object.values(value).every(isSingleBlockFieldValueWithNestedBlocks)
231
233
  );
232
234
  }
@@ -1,4 +1,7 @@
1
- import type { LocalizedFieldValue } from '../utilities/fieldValue';
1
+ import {
2
+ type LocalizedFieldValue,
3
+ isLocalizedFieldValue,
4
+ } from '../utilities/normalizedFieldValues';
2
5
  import type { SlugEditorConfiguration } from './appearance/slug';
3
6
  import type { LengthValidator } from './validators/length';
4
7
  import type { RequiredValidator } from './validators/required';
@@ -16,9 +19,7 @@ export function isLocalizedSlugFieldValue(
16
19
  value: unknown,
17
20
  ): value is LocalizedFieldValue<SlugFieldValue> {
18
21
  return (
19
- typeof value === 'object' &&
20
- value !== null &&
21
- Object.values(value).every(isSlugFieldValue)
22
+ isLocalizedFieldValue(value) && Object.values(value).every(isSlugFieldValue)
22
23
  );
23
24
  }
24
25
 
@@ -1,4 +1,7 @@
1
- import type { LocalizedFieldValue } from '../utilities/fieldValue';
1
+ import {
2
+ type LocalizedFieldValue,
3
+ isLocalizedFieldValue,
4
+ } from '../utilities/normalizedFieldValues';
2
5
  import type { SingleLineEditorConfiguration } from './appearance/single_line';
3
6
  import type { StringRadioGroupEditorConfiguration } from './appearance/string_radio_group';
4
7
  import type { StringSelectEditorConfiguration } from './appearance/string_select';
@@ -18,8 +21,7 @@ export function isLocalizedStringFieldValue(
18
21
  value: unknown,
19
22
  ): value is LocalizedFieldValue<StringFieldValue> {
20
23
  return (
21
- typeof value === 'object' &&
22
- value !== null &&
24
+ isLocalizedFieldValue(value) &&
23
25
  Object.values(value).every(isStringFieldValue)
24
26
  );
25
27
  }
@@ -9,8 +9,11 @@ import {
9
9
  isInlineBlock,
10
10
  } from 'datocms-structured-text-utils';
11
11
  import type * as RawApiTypes from '../generated/RawApiTypes';
12
- import type { LocalizedFieldValue } from '../utilities/fieldValue';
13
12
  import type { ItemDefinition } from '../utilities/itemDefinition';
13
+ import {
14
+ type LocalizedFieldValue,
15
+ isLocalizedFieldValue,
16
+ } from '../utilities/normalizedFieldValues';
14
17
  import type { StructuredTextEditorConfiguration } from './appearance/structured_text';
15
18
  import {
16
19
  type BlockItemInARequest,
@@ -176,8 +179,7 @@ export function isLocalizedStructuredTextFieldValue(
176
179
  value: unknown,
177
180
  ): value is LocalizedFieldValue<StructuredTextFieldValue> {
178
181
  return (
179
- typeof value === 'object' &&
180
- value !== null &&
182
+ isLocalizedFieldValue(value) &&
181
183
  Object.values(value).every(isStructuredTextFieldValue)
182
184
  );
183
185
  }
@@ -219,8 +221,7 @@ export function isLocalizedStructuredTextFieldValueAsRequest<
219
221
  value: unknown,
220
222
  ): value is LocalizedFieldValue<StructuredTextFieldValueAsRequest<D>> {
221
223
  return (
222
- typeof value === 'object' &&
223
- value !== null &&
224
+ isLocalizedFieldValue(value) &&
224
225
  Object.values(value).every(isStructuredTextFieldValueAsRequest)
225
226
  );
226
227
  }
@@ -253,8 +254,7 @@ export function isLocalizedStructuredTextFieldValueWithNestedBlocks<
253
254
  value: unknown,
254
255
  ): value is LocalizedFieldValue<StructuredTextFieldValueWithNestedBlocks<D>> {
255
256
  return (
256
- typeof value === 'object' &&
257
- value !== null &&
257
+ isLocalizedFieldValue(value) &&
258
258
  Object.values(value).every(isStructuredTextFieldValueWithNestedBlocks)
259
259
  );
260
260
  }
@@ -1,4 +1,7 @@
1
- import type { LocalizedFieldValue } from '../utilities/fieldValue';
1
+ import {
2
+ type LocalizedFieldValue,
3
+ isLocalizedFieldValue,
4
+ } from '../utilities/normalizedFieldValues';
2
5
  import type { MarkdownEditorConfiguration } from './appearance/markdown';
3
6
  import type { TextareaEditorConfiguration } from './appearance/textarea';
4
7
  import type { WysiwygEditorConfiguration } from './appearance/wysiwyg';
@@ -17,9 +20,7 @@ export function isLocalizedTextFieldValue(
17
20
  value: unknown,
18
21
  ): value is LocalizedFieldValue<TextFieldValue> {
19
22
  return (
20
- typeof value === 'object' &&
21
- value !== null &&
22
- Object.values(value).every(isTextFieldValue)
23
+ isLocalizedFieldValue(value) && Object.values(value).every(isTextFieldValue)
23
24
  );
24
25
  }
25
26
 
@@ -1,4 +1,7 @@
1
- import type { LocalizedFieldValue } from '../utilities/fieldValue';
1
+ import {
2
+ type LocalizedFieldValue,
3
+ isLocalizedFieldValue,
4
+ } from '../utilities/normalizedFieldValues';
2
5
  import type { VideoEditorConfiguration } from './appearance/video';
3
6
  import type { RequiredValidator } from './validators/required';
4
7
 
@@ -27,8 +30,7 @@ export function isLocalizedVideoFieldValue(
27
30
  value: unknown,
28
31
  ): value is LocalizedFieldValue<VideoFieldValue> {
29
32
  return (
30
- typeof value === 'object' &&
31
- value !== null &&
33
+ isLocalizedFieldValue(value) &&
32
34
  Object.values(value).every(isVideoFieldValue)
33
35
  );
34
36
  }
@@ -147,7 +147,7 @@ export class Client {
147
147
  ...this.config,
148
148
  ...options,
149
149
  logFn: this.config.logFn || console.log,
150
- userAgent: '@datocms/cma-client v5.1.10',
150
+ userAgent: '@datocms/cma-client v5.1.11',
151
151
  baseUrl: this.baseUrl,
152
152
  preCallStack: new Error().stack,
153
153
  extraHeaders: {
package/src/index.ts CHANGED
@@ -1,17 +1,17 @@
1
1
  export { ApiError, LogLevel, TimeoutError } from '@datocms/rest-client-utils';
2
2
  export * from './buildClient';
3
+ export * from './fieldTypes';
3
4
  export { Client } from './generated/Client';
4
5
  export type { ClientConfigOptions } from './generated/Client';
5
6
  export * as Resources from './generated/resources';
6
- export * from './utilities/blocks';
7
7
  export * from './utilities/buildBlockRecord';
8
8
  export * from './utilities/fieldsContainingReferences';
9
- export * from './utilities/fieldValue';
10
9
  export * from './utilities/id';
10
+ export * from './utilities/inspectItem';
11
+ export * from './utilities/itemDefinition';
12
+ export * from './utilities/normalizedFieldValues';
11
13
  export * from './utilities/recursiveBlocks';
12
14
  export * from './utilities/schemaRepository';
13
- export * from './utilities/itemDefinition';
14
- export * from './fieldTypes';
15
15
  export type { ApiTypes, RawApiTypes };
16
16
  // Legacy names
17
17
  export type { ApiTypes as SchemaTypes, RawApiTypes as SimpleSchemaTypes };