@datocms/cma-client 5.1.10 → 5.1.12

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 (253) hide show
  1. package/README.md +569 -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 +18 -18
  29. package/dist/cjs/fieldTypes/rich_text.js.map +1 -1
  30. package/dist/cjs/fieldTypes/schema.js +3 -0
  31. package/dist/cjs/fieldTypes/schema.js.map +1 -0
  32. package/dist/cjs/fieldTypes/seo.js +2 -3
  33. package/dist/cjs/fieldTypes/seo.js.map +1 -1
  34. package/dist/cjs/fieldTypes/single_block.js +20 -19
  35. package/dist/cjs/fieldTypes/single_block.js.map +1 -1
  36. package/dist/cjs/fieldTypes/slug.js +2 -3
  37. package/dist/cjs/fieldTypes/slug.js.map +1 -1
  38. package/dist/cjs/fieldTypes/string.js +2 -2
  39. package/dist/cjs/fieldTypes/string.js.map +1 -1
  40. package/dist/cjs/fieldTypes/structured_text.js +17 -18
  41. package/dist/cjs/fieldTypes/structured_text.js.map +1 -1
  42. package/dist/cjs/fieldTypes/text.js +2 -3
  43. package/dist/cjs/fieldTypes/text.js.map +1 -1
  44. package/dist/cjs/fieldTypes/video.js +2 -2
  45. package/dist/cjs/fieldTypes/video.js.map +1 -1
  46. package/dist/cjs/generated/Client.js +1 -1
  47. package/dist/cjs/generated/resources/Item.js.map +1 -1
  48. package/dist/cjs/generated/resources/ScheduledPublication.js.map +1 -1
  49. package/dist/cjs/generated/resources/ScheduledUnpublishing.js.map +1 -1
  50. package/dist/cjs/generated/resources/Upload.js.map +1 -1
  51. package/dist/cjs/index.js +5 -4
  52. package/dist/cjs/index.js.map +1 -1
  53. package/dist/cjs/utilities/buildBlockRecord.js +1 -45
  54. package/dist/cjs/utilities/buildBlockRecord.js.map +1 -1
  55. package/dist/cjs/utilities/duplicateBlockRecord.js +49 -0
  56. package/dist/cjs/utilities/duplicateBlockRecord.js.map +1 -0
  57. package/dist/cjs/utilities/inspectItem.js +427 -0
  58. package/dist/cjs/utilities/inspectItem.js.map +1 -0
  59. package/dist/cjs/utilities/{blocks.js → nonRecursiveBlocks.js} +60 -234
  60. package/dist/cjs/utilities/nonRecursiveBlocks.js.map +1 -0
  61. package/dist/cjs/utilities/{fieldValue.js → normalizedFieldValues.js} +53 -41
  62. package/dist/cjs/utilities/normalizedFieldValues.js.map +1 -0
  63. package/dist/cjs/utilities/recursiveBlocks.js +73 -92
  64. package/dist/cjs/utilities/recursiveBlocks.js.map +1 -1
  65. package/dist/cjs/utilities/schemaRepository.js +2 -2
  66. package/dist/esm/fieldTypes/boolean.d.ts +1 -1
  67. package/dist/esm/fieldTypes/boolean.js +2 -2
  68. package/dist/esm/fieldTypes/boolean.js.map +1 -1
  69. package/dist/esm/fieldTypes/color.d.ts +1 -1
  70. package/dist/esm/fieldTypes/color.js +2 -2
  71. package/dist/esm/fieldTypes/color.js.map +1 -1
  72. package/dist/esm/fieldTypes/date.d.ts +1 -1
  73. package/dist/esm/fieldTypes/date.js +2 -3
  74. package/dist/esm/fieldTypes/date.js.map +1 -1
  75. package/dist/esm/fieldTypes/date_time.d.ts +1 -1
  76. package/dist/esm/fieldTypes/date_time.js +2 -2
  77. package/dist/esm/fieldTypes/date_time.js.map +1 -1
  78. package/dist/esm/fieldTypes/file.d.ts +68 -1
  79. package/dist/esm/fieldTypes/file.js +29 -3
  80. package/dist/esm/fieldTypes/file.js.map +1 -1
  81. package/dist/esm/fieldTypes/float.d.ts +1 -1
  82. package/dist/esm/fieldTypes/float.js +2 -2
  83. package/dist/esm/fieldTypes/float.js.map +1 -1
  84. package/dist/esm/fieldTypes/gallery.d.ts +27 -11
  85. package/dist/esm/fieldTypes/gallery.js +17 -4
  86. package/dist/esm/fieldTypes/gallery.js.map +1 -1
  87. package/dist/esm/fieldTypes/index.d.ts +2 -2
  88. package/dist/esm/fieldTypes/index.js +2 -2
  89. package/dist/esm/fieldTypes/index.js.map +1 -1
  90. package/dist/esm/fieldTypes/integer.d.ts +1 -1
  91. package/dist/esm/fieldTypes/integer.js +2 -2
  92. package/dist/esm/fieldTypes/integer.js.map +1 -1
  93. package/dist/esm/fieldTypes/json.d.ts +1 -1
  94. package/dist/esm/fieldTypes/json.js +2 -3
  95. package/dist/esm/fieldTypes/json.js.map +1 -1
  96. package/dist/esm/fieldTypes/lat_lon.d.ts +1 -1
  97. package/dist/esm/fieldTypes/lat_lon.js +2 -2
  98. package/dist/esm/fieldTypes/lat_lon.js.map +1 -1
  99. package/dist/esm/fieldTypes/link.d.ts +1 -1
  100. package/dist/esm/fieldTypes/link.js +4 -4
  101. package/dist/esm/fieldTypes/link.js.map +1 -1
  102. package/dist/esm/fieldTypes/links.d.ts +1 -1
  103. package/dist/esm/fieldTypes/links.js +5 -3
  104. package/dist/esm/fieldTypes/links.js.map +1 -1
  105. package/dist/esm/fieldTypes/rich_text.d.ts +9 -10
  106. package/dist/esm/fieldTypes/rich_text.js +13 -13
  107. package/dist/esm/fieldTypes/rich_text.js.map +1 -1
  108. package/dist/esm/fieldTypes/schema.d.ts +59 -0
  109. package/dist/esm/fieldTypes/schema.js +2 -0
  110. package/dist/esm/fieldTypes/schema.js.map +1 -0
  111. package/dist/esm/fieldTypes/seo.d.ts +1 -1
  112. package/dist/esm/fieldTypes/seo.js +2 -3
  113. package/dist/esm/fieldTypes/seo.js.map +1 -1
  114. package/dist/esm/fieldTypes/single_block.d.ts +31 -16
  115. package/dist/esm/fieldTypes/single_block.js +15 -14
  116. package/dist/esm/fieldTypes/single_block.js.map +1 -1
  117. package/dist/esm/fieldTypes/slug.d.ts +1 -1
  118. package/dist/esm/fieldTypes/slug.js +2 -3
  119. package/dist/esm/fieldTypes/slug.js.map +1 -1
  120. package/dist/esm/fieldTypes/string.d.ts +1 -1
  121. package/dist/esm/fieldTypes/string.js +2 -2
  122. package/dist/esm/fieldTypes/string.js.map +1 -1
  123. package/dist/esm/fieldTypes/structured_text.d.ts +15 -16
  124. package/dist/esm/fieldTypes/structured_text.js +12 -13
  125. package/dist/esm/fieldTypes/structured_text.js.map +1 -1
  126. package/dist/esm/fieldTypes/text.d.ts +1 -1
  127. package/dist/esm/fieldTypes/text.js +2 -3
  128. package/dist/esm/fieldTypes/text.js.map +1 -1
  129. package/dist/esm/fieldTypes/video.d.ts +1 -1
  130. package/dist/esm/fieldTypes/video.js +2 -2
  131. package/dist/esm/fieldTypes/video.js.map +1 -1
  132. package/dist/esm/generated/ApiTypes.d.ts +90 -980
  133. package/dist/esm/generated/Client.js +1 -1
  134. package/dist/esm/generated/RawApiTypes.d.ts +156 -999
  135. package/dist/esm/generated/resources/Field.d.ts +200 -200
  136. package/dist/esm/generated/resources/Item.d.ts +34 -34
  137. package/dist/esm/generated/resources/Item.js.map +1 -1
  138. package/dist/esm/generated/resources/ItemVersion.d.ts +3 -1
  139. package/dist/esm/generated/resources/ScheduledPublication.d.ts +3 -3
  140. package/dist/esm/generated/resources/ScheduledPublication.js.map +1 -1
  141. package/dist/esm/generated/resources/ScheduledUnpublishing.d.ts +3 -3
  142. package/dist/esm/generated/resources/ScheduledUnpublishing.js.map +1 -1
  143. package/dist/esm/generated/resources/Upload.d.ts +6 -6
  144. package/dist/esm/generated/resources/Upload.js.map +1 -1
  145. package/dist/esm/index.d.ts +5 -4
  146. package/dist/esm/index.js +5 -4
  147. package/dist/esm/index.js.map +1 -1
  148. package/dist/esm/utilities/buildBlockRecord.d.ts +3 -5
  149. package/dist/esm/utilities/buildBlockRecord.js +0 -43
  150. package/dist/esm/utilities/buildBlockRecord.js.map +1 -1
  151. package/dist/esm/utilities/duplicateBlockRecord.d.ts +6 -0
  152. package/dist/esm/utilities/duplicateBlockRecord.js +45 -0
  153. package/dist/esm/utilities/duplicateBlockRecord.js.map +1 -0
  154. package/dist/esm/utilities/inspectItem.d.ts +8 -0
  155. package/dist/esm/utilities/inspectItem.js +400 -0
  156. package/dist/esm/utilities/inspectItem.js.map +1 -0
  157. package/dist/esm/utilities/itemDefinition.d.ts +45 -23
  158. package/dist/esm/utilities/nonRecursiveBlocks.d.ts +114 -0
  159. package/dist/esm/utilities/{blocks.js → nonRecursiveBlocks.js} +52 -220
  160. package/dist/esm/utilities/nonRecursiveBlocks.js.map +1 -0
  161. package/dist/{types/utilities/fieldValue.d.ts → esm/utilities/normalizedFieldValues.d.ts} +15 -14
  162. package/dist/esm/utilities/{fieldValue.js → normalizedFieldValues.js} +39 -28
  163. package/dist/esm/utilities/normalizedFieldValues.js.map +1 -0
  164. package/dist/esm/utilities/recursiveBlocks.d.ts +124 -11
  165. package/dist/esm/utilities/recursiveBlocks.js +65 -84
  166. package/dist/esm/utilities/recursiveBlocks.js.map +1 -1
  167. package/dist/esm/utilities/schemaRepository.d.ts +2 -2
  168. package/dist/esm/utilities/schemaRepository.js +2 -2
  169. package/dist/types/fieldTypes/boolean.d.ts +1 -1
  170. package/dist/types/fieldTypes/color.d.ts +1 -1
  171. package/dist/types/fieldTypes/date.d.ts +1 -1
  172. package/dist/types/fieldTypes/date_time.d.ts +1 -1
  173. package/dist/types/fieldTypes/file.d.ts +68 -1
  174. package/dist/types/fieldTypes/float.d.ts +1 -1
  175. package/dist/types/fieldTypes/gallery.d.ts +27 -11
  176. package/dist/types/fieldTypes/index.d.ts +2 -2
  177. package/dist/types/fieldTypes/integer.d.ts +1 -1
  178. package/dist/types/fieldTypes/json.d.ts +1 -1
  179. package/dist/types/fieldTypes/lat_lon.d.ts +1 -1
  180. package/dist/types/fieldTypes/link.d.ts +1 -1
  181. package/dist/types/fieldTypes/links.d.ts +1 -1
  182. package/dist/types/fieldTypes/rich_text.d.ts +9 -10
  183. package/dist/types/fieldTypes/schema.d.ts +59 -0
  184. package/dist/types/fieldTypes/seo.d.ts +1 -1
  185. package/dist/types/fieldTypes/single_block.d.ts +31 -16
  186. package/dist/types/fieldTypes/slug.d.ts +1 -1
  187. package/dist/types/fieldTypes/string.d.ts +1 -1
  188. package/dist/types/fieldTypes/structured_text.d.ts +15 -16
  189. package/dist/types/fieldTypes/text.d.ts +1 -1
  190. package/dist/types/fieldTypes/video.d.ts +1 -1
  191. package/dist/types/generated/ApiTypes.d.ts +90 -980
  192. package/dist/types/generated/RawApiTypes.d.ts +156 -999
  193. package/dist/types/generated/resources/Field.d.ts +200 -200
  194. package/dist/types/generated/resources/Item.d.ts +34 -34
  195. package/dist/types/generated/resources/ItemVersion.d.ts +3 -1
  196. package/dist/types/generated/resources/ScheduledPublication.d.ts +3 -3
  197. package/dist/types/generated/resources/ScheduledUnpublishing.d.ts +3 -3
  198. package/dist/types/generated/resources/Upload.d.ts +6 -6
  199. package/dist/types/index.d.ts +5 -4
  200. package/dist/types/utilities/buildBlockRecord.d.ts +3 -5
  201. package/dist/types/utilities/duplicateBlockRecord.d.ts +6 -0
  202. package/dist/types/utilities/inspectItem.d.ts +8 -0
  203. package/dist/types/utilities/itemDefinition.d.ts +45 -23
  204. package/dist/types/utilities/nonRecursiveBlocks.d.ts +114 -0
  205. package/dist/{esm/utilities/fieldValue.d.ts → types/utilities/normalizedFieldValues.d.ts} +15 -14
  206. package/dist/types/utilities/recursiveBlocks.d.ts +124 -11
  207. package/dist/types/utilities/schemaRepository.d.ts +2 -2
  208. package/package.json +4 -4
  209. package/src/fieldTypes/boolean.ts +5 -3
  210. package/src/fieldTypes/color.ts +5 -3
  211. package/src/fieldTypes/date.ts +5 -4
  212. package/src/fieldTypes/date_time.ts +5 -3
  213. package/src/fieldTypes/file.ts +98 -4
  214. package/src/fieldTypes/float.ts +5 -3
  215. package/src/fieldTypes/gallery.ts +53 -20
  216. package/src/fieldTypes/index.ts +2 -3
  217. package/src/fieldTypes/integer.ts +5 -3
  218. package/src/fieldTypes/json.ts +5 -4
  219. package/src/fieldTypes/lat_lon.ts +5 -3
  220. package/src/fieldTypes/link.ts +7 -5
  221. package/src/fieldTypes/links.ts +8 -4
  222. package/src/fieldTypes/rich_text.ts +33 -31
  223. package/src/fieldTypes/schema.ts +657 -0
  224. package/src/fieldTypes/seo.ts +5 -4
  225. package/src/fieldTypes/single_block.ts +71 -46
  226. package/src/fieldTypes/slug.ts +5 -4
  227. package/src/fieldTypes/string.ts +5 -3
  228. package/src/fieldTypes/structured_text.ts +64 -58
  229. package/src/fieldTypes/text.ts +5 -4
  230. package/src/fieldTypes/video.ts +5 -3
  231. package/src/generated/ApiTypes.ts +217 -1880
  232. package/src/generated/Client.ts +1 -1
  233. package/src/generated/RawApiTypes.ts +272 -2113
  234. package/src/generated/resources/Item.ts +93 -187
  235. package/src/generated/resources/ScheduledPublication.ts +4 -15
  236. package/src/generated/resources/ScheduledUnpublishing.ts +4 -15
  237. package/src/generated/resources/Upload.ts +9 -32
  238. package/src/index.ts +5 -4
  239. package/src/utilities/buildBlockRecord.ts +4 -59
  240. package/src/utilities/duplicateBlockRecord.ts +52 -0
  241. package/src/utilities/inspectItem.ts +602 -0
  242. package/src/utilities/itemDefinition.ts +130 -92
  243. package/src/utilities/nonRecursiveBlocks.ts +406 -0
  244. package/src/utilities/{fieldValue.ts → normalizedFieldValues.ts} +70 -30
  245. package/src/utilities/recursiveBlocks.ts +484 -204
  246. package/src/utilities/schemaRepository.ts +2 -2
  247. package/dist/cjs/utilities/blocks.js.map +0 -1
  248. package/dist/cjs/utilities/fieldValue.js.map +0 -1
  249. package/dist/esm/utilities/blocks.d.ts +0 -180
  250. package/dist/esm/utilities/blocks.js.map +0 -1
  251. package/dist/esm/utilities/fieldValue.js.map +0 -1
  252. package/dist/types/utilities/blocks.d.ts +0 -180
  253. package/src/utilities/blocks.ts +0 -626
package/README.md CHANGED
@@ -10,6 +10,575 @@ API client for [DatoCMS](https://www.datocms.com). Take a look at the full [API
10
10
  </a>
11
11
  <br /><br />
12
12
 
13
+ ## Utility Functions
14
+
15
+ This library provides a comprehensive set of utility functions to work with DatoCMS records, blocks, and field values. These utilities make it easier to manipulate, traverse, and inspect your content programmatically.
16
+
17
+ ### 1. Record Inspection Utilities
18
+
19
+ The `inspectItem()` function provides a visual, tree-structured representation of DatoCMS records in the console, making it easier to debug and understand complex content structures.
20
+
21
+ <details>
22
+ <summary><strong>inspectItem()</strong> - Display records with visual appeal</summary>
23
+
24
+ Formats a DatoCMS item (record or block) as a visual tree structure, showing all fields with proper formatting for each field type. Particularly useful for debugging nested structures like modular content and structured text.
25
+
26
+ **TypeScript Signature:**
27
+ ```typescript
28
+ function inspectItem(
29
+ item: Item,
30
+ options?: InspectItemOptions
31
+ ): string
32
+
33
+ type InspectItemOptions = {
34
+ maxWidth?: number; // Maximum width for text fields before truncation (default: 80)
35
+ }
36
+ ```
37
+
38
+ **Parameters:**
39
+ - `item`: Any DatoCMS item, including records, blocks, or items in create/update format
40
+ - `options`: Optional configuration object
41
+ - `maxWidth`: Maximum characters to display for text fields before truncating with "..."
42
+
43
+ **Returns:** A formatted string representation of the item as a tree structure
44
+
45
+ **Usage Example:**
46
+ ```typescript
47
+ import { inspectItem } from '@datocms/cma-client';
48
+
49
+ const record = await client.items.find('MgCNaAI0RxSG8CA9sDXCHg');
50
+ console.log(inspectItem(record));
51
+
52
+ // Output:
53
+ // Item "MgCNaAI0RxSG8CA9sDXCHg" (item_type: "bJse85JFR0GbA37ey6kA1w")
54
+ // ├─ title: "My Blog Post"
55
+ // ├─ slug: "my-blog-post"
56
+ // └─ content:
57
+ // ├─ en: "This is the English content..."
58
+ // └─ it: "Questo è il contenuto italiano..."
59
+ ```
60
+ </details>
61
+
62
+ ### 2. Block Processing Utilities
63
+
64
+ These utilities provide a unified interface for working with blocks embedded within DatoCMS field values. DatoCMS supports three field types that can contain blocks: Modular Content (arrays of blocks), Single Block fields, and Structured Text (with embedded blocks). These functions abstract away the differences between field types, providing consistent APIs for common operations.
65
+
66
+ #### Recursive Block Operations
67
+
68
+ These functions traverse blocks recursively, processing nested blocks within blocks. They require a `SchemaRepository` instance to look up field definitions for nested blocks.
69
+
70
+ <details>
71
+ <summary><strong>visitBlocksInNonLocalizedFieldValue()</strong> - Recursively visit all blocks</summary>
72
+
73
+ Visit every block in a non-localized field value recursively, including blocks nested within other blocks.
74
+
75
+ **TypeScript Signature:**
76
+ ```typescript
77
+ async function visitBlocksInNonLocalizedFieldValue(
78
+ nonLocalizedFieldValue: unknown,
79
+ fieldType: string,
80
+ schemaRepository: SchemaRepository,
81
+ visitor: (item: BlockInRequest, path: TreePath) => void | Promise<void>,
82
+ path?: TreePath
83
+ ): Promise<void>
84
+ ```
85
+
86
+ **Parameters:**
87
+ - `nonLocalizedFieldValue`: The non-localized field value
88
+ - `fieldType`: The typeo of DatoCMS field (ie. `string`, `rich_text`, etc.)
89
+ - `schemaRepository`: Repository for caching schema lookups
90
+ - `visitor`: Function called for each block (including nested)
91
+ - `path`: Optional base path for tracking location
92
+ ```
93
+ </details>
94
+
95
+ <details>
96
+ <summary><strong>mapBlocksInNonLocalizedFieldValue()</strong> - Recursively transform all blocks</summary>
97
+
98
+ Transform all blocks in a non-localized field value recursively, including nested blocks.
99
+
100
+ **TypeScript Signature:**
101
+ ```typescript
102
+ async function mapBlocksInNonLocalizedFieldValue(
103
+ nonLocalizedFieldValue: unknown,
104
+ fieldType: string,
105
+ schemaRepository: SchemaRepository,
106
+ mapper: (item: BlockInRequest, path: TreePath) => BlockInRequest | Promise<BlockInRequest>,
107
+ path?: TreePath
108
+ ): Promise<unknown>
109
+ ```
110
+
111
+ **Parameters:**
112
+ - `nonLocalizedFieldValue`: The non-localized field value
113
+ - `fieldType`: The typeo of DatoCMS field (ie. `string`, `rich_text`, etc.)
114
+ - `schemaRepository`: Repository for caching schema lookups
115
+ - `mapper`: Function that transforms each block
116
+
117
+ **Returns:** New field value
118
+ </details>
119
+
120
+ <details>
121
+ <summary><strong>filterBlocksInNonLocalizedFieldValue()</strong> - Recursively filter blocks</summary>
122
+
123
+ Filter blocks recursively, removing blocks at any nesting level that don't match the predicate.
124
+
125
+ **TypeScript Signature:**
126
+ ```typescript
127
+ async function filterBlocksInNonLocalizedFieldValue(
128
+ nonLocalizedFieldValue: unknown,
129
+ fieldType: string,
130
+ schemaRepository: SchemaRepository,
131
+ predicate: (item: BlockInRequest, path: TreePath) => boolean | Promise<boolean>,
132
+ path?: TreePath
133
+ ): Promise<unknown>
134
+ ```
135
+
136
+ **Parameters:**
137
+ - `nonLocalizedFieldValue`: The non-localized field value to filter
138
+ - `fieldType`: The typeo of DatoCMS field (ie. `string`, `rich_text`, etc.)
139
+ - `schemaRepository`: Repository for caching schema lookups
140
+ - `predicate`: Function that tests each block
141
+
142
+ **Returns:** New field value with filtered blocks
143
+
144
+ **Usage Example:**
145
+ ```typescript
146
+ // Remove all video blocks at any nesting level
147
+ const noVideos = await filterBlocksInNonLocalizedFieldValue(
148
+ schemaRepository,
149
+ field,
150
+ fieldValue,
151
+ (block) => block.relationships.item_type.data.id !== 'video_block'
152
+ );
153
+ ```
154
+ </details>
155
+
156
+ <details>
157
+ <summary><strong>findAllBlocksInNonLocalizedFieldValue()</strong> - Recursively search for blocks</summary>
158
+
159
+ Find all blocks that match the predicate, searching recursively through nested blocks.
160
+
161
+ **TypeScript Signature:**
162
+ ```typescript
163
+ async function findAllBlocksInNonLocalizedFieldValue(
164
+ nonLocalizedFieldValue: unknown,
165
+ fieldType: string,
166
+ schemaRepository: SchemaRepository,
167
+ predicate: (item: BlockInRequest, path: TreePath) => boolean | Promise<boolean>,
168
+ path?: TreePath
169
+ ): Promise<Array<{ item: BlockInRequest; path: TreePath }>>
170
+ ```
171
+
172
+ **Parameters:**
173
+ - `nonLocalizedFieldValue`: The non-localized field value to search
174
+ - `fieldType`: The typeo of DatoCMS field (ie. `string`, `rich_text`, etc.)
175
+ - `schemaRepository`: Repository for caching schema lookups
176
+ - `predicate`: Function that tests each block
177
+
178
+ **Returns:** Array of all matching blocks with their paths
179
+ </details>
180
+
181
+ <details>
182
+ <summary><strong>reduceBlocksInNonLocalizedFieldValue()</strong> - Recursively reduce blocks</summary>
183
+
184
+ Reduce all blocks recursively to a single value.
185
+
186
+ **TypeScript Signature:**
187
+ ```typescript
188
+ async function reduceBlocksInNonLocalizedFieldValue<R>(
189
+ nonLocalizedFieldValue: unknown,
190
+ fieldType: string,
191
+ schemaRepository: SchemaRepository,
192
+ reducer: (accumulator: R, item: BlockInRequest, path: TreePath) => R | Promise<R>,
193
+ initialValue: R,
194
+ path?: TreePath
195
+ ): Promise<R>
196
+ ```
197
+
198
+ **Parameters:**
199
+ - `nonLocalizedFieldValue`: The non-localized field value to reduce
200
+ - `fieldType`: The typeo of DatoCMS field (ie. `string`, `rich_text`, etc.)
201
+ - `schemaRepository`: Repository for caching schema lookups
202
+ - `reducer`: Function that processes each block
203
+ - `initialValue`: Initial accumulator value
204
+
205
+ **Returns:** The final accumulated value
206
+ ```
207
+ </details>
208
+
209
+ <details>
210
+ <summary><strong>someBlocksInNonLocalizedFieldValue()</strong> - Recursively test for any match</summary>
211
+
212
+ Check if any block (including nested) matches the predicate.
213
+
214
+ **TypeScript Signature:**
215
+ ```typescript
216
+ async function someBlocksInNonLocalizedFieldValue(
217
+ nonLocalizedFieldValue: unknown,
218
+ fieldType: string,
219
+ schemaRepository: SchemaRepository,
220
+ predicate: (item: BlockInRequest, path: TreePath) => boolean | Promise<boolean>,
221
+ path?: TreePath
222
+ ): Promise<boolean>
223
+ ```
224
+
225
+ **Parameters:**
226
+ - `nonLocalizedFieldValue`: The non-localized field value to test
227
+ - `fieldType`: The typeo of DatoCMS field (ie. `string`, `rich_text`, etc.)
228
+ - `schemaRepository`: Repository for caching schema lookups
229
+ - `predicate`: Function that tests each block
230
+
231
+ **Returns:** True if any block matches
232
+ ```
233
+ </details>
234
+
235
+ <details>
236
+ <summary><strong>everyBlockInNonLocalizedFieldValue()</strong> - Recursively test if all match</summary>
237
+
238
+ Check if every block (including nested) matches the predicate.
239
+
240
+ **TypeScript Signature:**
241
+ ```typescript
242
+ async function everyBlockInNonLocalizedFieldValue(
243
+ nonLocalizedFieldValue: unknown,
244
+ fieldType: string,
245
+ schemaRepository: SchemaRepository,
246
+ predicate: (item: BlockInRequest, path: TreePath) => boolean | Promise<boolean>,
247
+ path?: TreePath
248
+ ): Promise<boolean>
249
+ ```
250
+
251
+ **Parameters:**
252
+ - `nonLocalizedFieldValue`: The non-localized field value to test
253
+ - `fieldType`: The typeo of DatoCMS field (ie. `string`, `rich_text`, etc.)
254
+ - `schemaRepository`: Repository for caching schema lookups
255
+ - `predicate`: Function that tests each block
256
+
257
+ **Returns:** True if all blocks match
258
+ </details>
259
+
260
+ #### Block Record Management
261
+
262
+ <details>
263
+ <summary><strong>buildBlockRecord()</strong> - Create block records from data</summary>
264
+
265
+ Converts a block data object into the proper format for API requests.
266
+
267
+ **TypeScript Signature:**
268
+ ```typescript
269
+ function buildBlockRecord<D extends ItemTypeDefinition>(
270
+ body: ItemUpdateSchema<ToItemDefinitionInRequest<D>>
271
+ ): NewBlockInRequest<ToItemDefinitionInRequest<D>>
272
+ ```
273
+
274
+ **Parameters:**
275
+ - `body`: Block data in update schema format
276
+
277
+ **Returns:** Formatted block record ready for API requests
278
+ </details>
279
+
280
+ <details>
281
+ <summary><strong>duplicateBlockRecord()</strong> - Deep clone blocks with nested content</summary>
282
+
283
+ Creates a deep copy of a block record, including all nested blocks, removing IDs to create new instances.
284
+
285
+ **TypeScript Signature:**
286
+ ```typescript
287
+ async function duplicateBlockRecord<D extends ItemTypeDefinition>(
288
+ existingBlock: ItemWithOptionalIdAndMeta<ToItemDefinitionInNestedResponse<D>>,
289
+ schemaRepository: SchemaRepository
290
+ ): Promise<NewBlockInRequest<ToItemDefinitionInRequest<D>>>
291
+ ```
292
+
293
+ **Parameters:**
294
+ - `existingBlock`: The block to duplicate
295
+ - `schemaRepository`: Repository for schema lookups
296
+
297
+ **Returns:** New block record without IDs, ready to be created
298
+ </details>
299
+
300
+ ### 3. Localization-Aware Field Utilities
301
+
302
+ These utilities provide a unified interface for working with DatoCMS field values that may or may not be localized. They eliminate the need for conditional logic when processing fields that could be either localized or non-localized.
303
+
304
+ <details>
305
+ <summary><strong>isLocalized()</strong> - Check if a field is localized</summary>
306
+
307
+ Determines whether a DatoCMS field is configured for localization.
308
+
309
+ **TypeScript Signature:**
310
+ ```typescript
311
+ function isLocalized(field: Field): boolean
312
+ ```
313
+
314
+ **Parameters:**
315
+ - `fieldType`: The typeo of DatoCMS field (ie. `string`, `rich_text`, etc.)
316
+
317
+ **Returns:** True if the field is localized, false otherwise
318
+ </details>
319
+
320
+ <details>
321
+ <summary><strong>mapNormalizedFieldValues() / mapNormalizedFieldValuesAsync()</strong> - Transform field values</summary>
322
+
323
+ Apply a transformation function to field values, handling both localized and non-localized fields uniformly.
324
+
325
+ **TypeScript Signatures:**
326
+ ```typescript
327
+ function mapNormalizedFieldValues<TInput, TOutput>(
328
+ field: Field,
329
+ value: TInput | LocalizedFieldValue<TInput>,
330
+ mapFn: (locale: string | undefined, localeValue: TInput) => TOutput
331
+ ): TOutput | LocalizedFieldValue<TOutput>
332
+
333
+ async function mapNormalizedFieldValuesAsync<TInput, TOutput>(
334
+ field: Field,
335
+ value: TInput | LocalizedFieldValue<TInput>,
336
+ mapFn: (locale: string | undefined, localeValue: TInput) => Promise<TOutput>
337
+ ): Promise<TOutput | LocalizedFieldValue<TOutput>>
338
+ ```
339
+
340
+ **Parameters:**
341
+ - `fieldType`: The typeo of DatoCMS field (ie. `string`, `rich_text`, etc.)
342
+ - `nonLocalizedFieldValue`: The non-localized field value (localized or non-localized)
343
+ - `mapFn`: Function to transform each value (receives locale for localized fields, undefined for non-localized)
344
+
345
+ **Returns:** Transformed value maintaining the same structure
346
+ </details>
347
+
348
+ <details>
349
+ <summary><strong>filterNormalizedFieldValues() / filterNormalizedFieldValuesAsync()</strong> - Filter field values</summary>
350
+
351
+ Filter field values based on a predicate, handling both localized and non-localized fields.
352
+
353
+ **TypeScript Signatures:**
354
+ ```typescript
355
+ function filterNormalizedFieldValues<T>(
356
+ field: Field,
357
+ value: T | LocalizedFieldValue<T>,
358
+ filterFn: (locale: string | undefined, localeValue: T) => boolean
359
+ ): T | LocalizedFieldValue<T> | undefined
360
+
361
+ async function filterNormalizedFieldValuesAsync<T>(
362
+ field: Field,
363
+ value: T | LocalizedFieldValue<T>,
364
+ filterFn: (locale: string | undefined, localeValue: T) => Promise<boolean>
365
+ ): Promise<T | LocalizedFieldValue<T> | undefined>
366
+ ```
367
+
368
+ **Parameters:**
369
+ - `fieldType`: The typeo of DatoCMS field (ie. `string`, `rich_text`, etc.)
370
+ - `nonLocalizedFieldValue`: The non-localized field value to filter
371
+ - `filterFn`: Predicate function for filtering
372
+
373
+ **Returns:** Filtered value or undefined if all filtered out
374
+ </details>
375
+
376
+ <details>
377
+ <summary><strong>visitNormalizedFieldValues() / visitNormalizedFieldValuesAsync()</strong> - Iterate over field values</summary>
378
+
379
+ Visit each value in a field, handling both localized and non-localized fields.
380
+
381
+ **TypeScript Signatures:**
382
+ ```typescript
383
+ function visitNormalizedFieldValues<T>(
384
+ field: Field,
385
+ value: T | LocalizedFieldValue<T>,
386
+ visitFn: (locale: string | undefined, localeValue: T) => void
387
+ ): void
388
+
389
+ async function visitNormalizedFieldValuesAsync<T>(
390
+ field: Field,
391
+ value: T | LocalizedFieldValue<T>,
392
+ visitFn: (locale: string | undefined, localeValue: T) => Promise<void>
393
+ ): Promise<void>
394
+ ```
395
+
396
+ **Parameters:**
397
+ - `fieldType`: The typeo of DatoCMS field (ie. `string`, `rich_text`, etc.)
398
+ - `nonLocalizedFieldValue`: The non-localized field value to visit
399
+ - `visitFn`: Function called for each value
400
+ </details>
401
+
402
+ <details>
403
+ <summary><strong>someNormalizedFieldValues() / someNormalizedFieldValuesAsync()</strong> - Test if any value matches</summary>
404
+
405
+ Check if at least one field value passes the test.
406
+
407
+ **TypeScript Signatures:**
408
+ ```typescript
409
+ function someNormalizedFieldValues<T>(
410
+ field: Field,
411
+ value: T | LocalizedFieldValue<T>,
412
+ testFn: (locale: string | undefined, localeValue: T) => boolean
413
+ ): boolean
414
+
415
+ async function someNormalizedFieldValuesAsync<T>(
416
+ field: Field,
417
+ value: T | LocalizedFieldValue<T>,
418
+ testFn: (locale: string | undefined, localeValue: T) => Promise<boolean>
419
+ ): Promise<boolean>
420
+ ```
421
+
422
+ **Parameters:**
423
+ - `fieldType`: The typeo of DatoCMS field (ie. `string`, `rich_text`, etc.)
424
+ - `nonLocalizedFieldValue`: The non-localized field value to test
425
+ - `testFn`: Predicate function
426
+
427
+ **Returns:** True if any value passes the test
428
+ </details>
429
+
430
+ <details>
431
+ <summary><strong>everyNormalizedFieldValue() / everyNormalizedFieldValueAsync()</strong> - Test if all values match</summary>
432
+
433
+ Check if all field values pass the test.
434
+
435
+ **TypeScript Signatures:**
436
+ ```typescript
437
+ function everyNormalizedFieldValue<T>(
438
+ field: Field,
439
+ value: T | LocalizedFieldValue<T>,
440
+ testFn: (locale: string | undefined, localeValue: T) => boolean
441
+ ): boolean
442
+
443
+ async function everyNormalizedFieldValueAsync<T>(
444
+ field: Field,
445
+ value: T | LocalizedFieldValue<T>,
446
+ testFn: (locale: string | undefined, localeValue: T) => Promise<boolean>
447
+ ): Promise<boolean>
448
+ ```
449
+
450
+ **Parameters:**
451
+ - `fieldType`: The typeo of DatoCMS field (ie. `string`, `rich_text`, etc.)
452
+ - `nonLocalizedFieldValue`: The non-localized field value to test
453
+ - `testFn`: Predicate function
454
+
455
+ **Returns:** True if all values pass the test
456
+ </details>
457
+
458
+ <details>
459
+ <summary><strong>toNormalizedFieldValueEntries() / fromNormalizedFieldValueEntries()</strong> - Convert between formats</summary>
460
+
461
+ Convert field values to/from a normalized entry format for uniform processing.
462
+
463
+ **TypeScript Signatures:**
464
+ ```typescript
465
+ function toNormalizedFieldValueEntries<T>(
466
+ field: Field,
467
+ value: T | LocalizedFieldValue<T>
468
+ ): NormalizedFieldValueEntry<T>[]
469
+
470
+ function fromNormalizedFieldValueEntries<T>(
471
+ field: Field,
472
+ entries: NormalizedFieldValueEntry<T>[]
473
+ ): T | LocalizedFieldValue<T>
474
+
475
+ type NormalizedFieldValueEntry<T> = {
476
+ locale: string | undefined;
477
+ value: T;
478
+ }
479
+ ```
480
+
481
+ **Parameters:**
482
+ - `fieldType`: The typeo of DatoCMS field (ie. `string`, `rich_text`, etc.)
483
+ - `nonLocalizedFieldValue`/`entries non-localized`: Value to convert from/to
484
+
485
+ **Returns:** Normalized entries array or reconstructed field value
486
+
487
+ **Usage Example:**
488
+ ```typescript
489
+ // Convert to entries for processing
490
+ const entries = toNormalizedFieldValueEntries(field, fieldValue);
491
+
492
+ // Process entries uniformly
493
+ const processed = entries.map(({ locale, value }) => ({
494
+ locale,
495
+ value: processValue(value)
496
+ }));
497
+
498
+ // Convert back to field value format
499
+ const result = fromNormalizedFieldValueEntries(field, processed);
500
+ ```
501
+ </details>
502
+
503
+ ### 4. Schema Repository
504
+
505
+ The `SchemaRepository` class provides an in-memory caching system for DatoCMS schema entities, significantly improving performance when working with complex content structures.
506
+
507
+ <details>
508
+ <summary><strong>SchemaRepository</strong> - Cache schema entities for performance</summary>
509
+
510
+ Repository for DatoCMS schema entities including item types, fields, fieldsets, and plugins. Provides caching and efficient lookup functionality for schema-related operations.
511
+
512
+ **Key Features:**
513
+ - Automatic caching of schema entities after first fetch
514
+ - Efficient lookups by ID, API key, or package name
515
+ - Essential for recursive block operations
516
+ - Dramatically reduces API calls during complex traversals
517
+
518
+ **TypeScript Class:**
519
+ ```typescript
520
+ class SchemaRepository {
521
+ constructor(client: GenericClient)
522
+
523
+ // Item Type methods
524
+ async getAllItemTypes(): Promise<ItemType[]>
525
+ async getAllModels(): Promise<ItemType[]>
526
+ async getAllBlockModels(): Promise<ItemType[]>
527
+ async getItemTypeByApiKey(apiKey: string): Promise<ItemType>
528
+ async getItemTypeById(id: string): Promise<ItemType>
529
+
530
+ // Field methods
531
+ async getItemTypeFields(itemType: ItemType): Promise<Field[]>
532
+ async getItemTypeFieldsets(itemType: ItemType): Promise<Fieldset[]>
533
+
534
+ // Plugin methods
535
+ async getAllPlugins(): Promise<Plugin[]>
536
+ async getPluginById(id: string): Promise<Plugin>
537
+ async getPluginByPackageName(packageName: string): Promise<Plugin>
538
+
539
+ // Raw variants (return API response format)
540
+ async getAllRawItemTypes(): Promise<RawItemType[]>
541
+ async getRawItemTypeByApiKey(apiKey: string): Promise<RawItemType>
542
+ // ... and more raw variants
543
+ }
544
+ ```
545
+
546
+ **When to Use:**
547
+ - Complex traversal operations that repeatedly lookup schema
548
+ - Bulk operations processing multiple records
549
+ - Scripts that need efficient access to schema information
550
+ - Working with recursive block utilities
551
+
552
+ **When NOT to Use:**
553
+ - Scripts that modify schema (models, fields, etc.)
554
+ - Long-running applications (no cache expiration)
555
+ - When schema might change during execution
556
+
557
+ **Usage Example:**
558
+ ```typescript
559
+ const schemaRepository = new SchemaRepository(client);
560
+
561
+ // First call fetches from API and caches
562
+ const blogPost = await schemaRepository.getItemTypeByApiKey('blog_post');
563
+ const fields = await schemaRepository.getItemTypeFields(blogPost);
564
+
565
+ // Subsequent calls use cached data (no API calls)
566
+ const sameBlogPost = await schemaRepository.getItemTypeByApiKey('blog_post');
567
+ const sameFields = await schemaRepository.getItemTypeFields(blogPost);
568
+
569
+ // Use with recursive utilities for optimal performance
570
+ await mapBlocksInNonLocalizedFieldValue(
571
+ schemaRepository, // Pass repository for efficient lookups
572
+ field,
573
+ fieldValue,
574
+ async (block) => { /* transform */ }
575
+ );
576
+ ```
577
+
578
+ **Performance Impact:**
579
+ Without SchemaRepository, a script processing structured text with nested blocks might make the same API calls dozens of times. SchemaRepository ensures each unique schema request is made only once, dramatically improving performance for complex operations.
580
+ </details>
581
+
13
582
  ## Contributing
14
583
 
15
584
  Bug reports and pull requests are welcome on GitHub at https://github.com/datocms/js-rest-api-clients. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
@@ -1,13 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isLocalizedBooleanFieldValue = exports.isBooleanFieldValue = void 0;
4
+ const normalizedFieldValues_1 = require("../utilities/normalizedFieldValues");
4
5
  function isBooleanFieldValue(value) {
5
6
  return typeof value === 'boolean' || value === null;
6
7
  }
7
8
  exports.isBooleanFieldValue = isBooleanFieldValue;
8
9
  function isLocalizedBooleanFieldValue(value) {
9
- return (typeof value === 'object' &&
10
- value !== null &&
10
+ return ((0, normalizedFieldValues_1.isLocalizedFieldValue)(value) &&
11
11
  Object.values(value).every(isBooleanFieldValue));
12
12
  }
13
13
  exports.isLocalizedBooleanFieldValue = isLocalizedBooleanFieldValue;
@@ -1 +1 @@
1
- {"version":3,"file":"boolean.js","sourceRoot":"","sources":["../../../src/fieldTypes/boolean.ts"],"names":[],"mappings":";;;AAMA,SAAgB,mBAAmB,CACjC,KAAc;IAEd,OAAO,OAAO,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI,CAAC;AACtD,CAAC;AAJD,kDAIC;AAED,SAAgB,4BAA4B,CAC1C,KAAc;IAEd,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,mBAAmB,CAAC,CAChD,CAAC;AACJ,CAAC;AARD,oEAQC"}
1
+ {"version":3,"file":"boolean.js","sourceRoot":"","sources":["../../../src/fieldTypes/boolean.ts"],"names":[],"mappings":";;;AAAA,8EAG4C;AAM5C,SAAgB,mBAAmB,CACjC,KAAc;IAEd,OAAO,OAAO,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI,CAAC;AACtD,CAAC;AAJD,kDAIC;AAED,SAAgB,4BAA4B,CAC1C,KAAc;IAEd,OAAO,CACL,IAAA,6CAAqB,EAAC,KAAK,CAAC;QAC5B,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,mBAAmB,CAAC,CAChD,CAAC;AACJ,CAAC;AAPD,oEAOC"}
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isLocalizedColorFieldValue = exports.isColorFieldValue = void 0;
4
+ const normalizedFieldValues_1 = require("../utilities/normalizedFieldValues");
4
5
  function isColorFieldValue(value) {
5
6
  if (value === null)
6
7
  return true;
@@ -13,8 +14,7 @@ function isColorFieldValue(value) {
13
14
  }
14
15
  exports.isColorFieldValue = isColorFieldValue;
15
16
  function isLocalizedColorFieldValue(value) {
16
- return (typeof value === 'object' &&
17
- value !== null &&
17
+ return ((0, normalizedFieldValues_1.isLocalizedFieldValue)(value) &&
18
18
  Object.values(value).every(isColorFieldValue));
19
19
  }
20
20
  exports.isLocalizedColorFieldValue = isLocalizedColorFieldValue;
@@ -1 +1 @@
1
- {"version":3,"file":"color.js","sourceRoot":"","sources":["../../../src/fieldTypes/color.ts"],"names":[],"mappings":";;;AAWA,SAAgB,iBAAiB,CAAC,KAAc;IAC9C,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,IAAI,CAAC;IAChC,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,KAAK,IAAI,KAAK;QACd,OAAO,IAAI,KAAK;QAChB,MAAM,IAAI,KAAK;QACf,OAAO,IAAI,KAAK,CACjB,CAAC;AACJ,CAAC;AAVD,8CAUC;AAED,SAAgB,0BAA0B,CACxC,KAAc;IAEd,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAC9C,CAAC;AACJ,CAAC;AARD,gEAQC"}
1
+ {"version":3,"file":"color.js","sourceRoot":"","sources":["../../../src/fieldTypes/color.ts"],"names":[],"mappings":";;;AAAA,8EAG4C;AAW5C,SAAgB,iBAAiB,CAAC,KAAc;IAC9C,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,IAAI,CAAC;IAChC,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,KAAK,IAAI,KAAK;QACd,OAAO,IAAI,KAAK;QAChB,MAAM,IAAI,KAAK;QACf,OAAO,IAAI,KAAK,CACjB,CAAC;AACJ,CAAC;AAVD,8CAUC;AAED,SAAgB,0BAA0B,CACxC,KAAc;IAEd,OAAO,CACL,IAAA,6CAAqB,EAAC,KAAK,CAAC;QAC5B,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAC9C,CAAC;AACJ,CAAC;AAPD,gEAOC"}
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isLocalizedDateFieldValue = exports.isDateFieldValue = void 0;
4
+ const normalizedFieldValues_1 = require("../utilities/normalizedFieldValues");
4
5
  function isDateFieldValue(value) {
5
6
  if (value === null)
6
7
  return true;
@@ -8,9 +9,7 @@ function isDateFieldValue(value) {
8
9
  }
9
10
  exports.isDateFieldValue = isDateFieldValue;
10
11
  function isLocalizedDateFieldValue(value) {
11
- return (typeof value === 'object' &&
12
- value !== null &&
13
- Object.values(value).every(isDateFieldValue));
12
+ return ((0, normalizedFieldValues_1.isLocalizedFieldValue)(value) && Object.values(value).every(isDateFieldValue));
14
13
  }
15
14
  exports.isLocalizedDateFieldValue = isLocalizedDateFieldValue;
16
15
  //# sourceMappingURL=date.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"date.js","sourceRoot":"","sources":["../../../src/fieldTypes/date.ts"],"names":[],"mappings":";;;AAOA,SAAgB,gBAAgB,CAAC,KAAc;IAC7C,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,IAAI,CAAC;IAChC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,qBAAqB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AACxE,CAAC;AAHD,4CAGC;AAED,SAAgB,yBAAyB,CACvC,KAAc;IAEd,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAC7C,CAAC;AACJ,CAAC;AARD,8DAQC"}
1
+ {"version":3,"file":"date.js","sourceRoot":"","sources":["../../../src/fieldTypes/date.ts"],"names":[],"mappings":";;;AAAA,8EAG4C;AAO5C,SAAgB,gBAAgB,CAAC,KAAc;IAC7C,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,IAAI,CAAC;IAChC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,qBAAqB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AACxE,CAAC;AAHD,4CAGC;AAED,SAAgB,yBAAyB,CACvC,KAAc;IAEd,OAAO,CACL,IAAA,6CAAqB,EAAC,KAAK,CAAC,IAAI,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAC7E,CAAC;AACJ,CAAC;AAND,8DAMC"}
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isLocalizedDateTimeFieldValue = exports.isDateTimeFieldValue = void 0;
4
+ const normalizedFieldValues_1 = require("../utilities/normalizedFieldValues");
4
5
  function isDateTimeFieldValue(value) {
5
6
  if (value === null)
6
7
  return true;
@@ -9,8 +10,7 @@ function isDateTimeFieldValue(value) {
9
10
  }
10
11
  exports.isDateTimeFieldValue = isDateTimeFieldValue;
11
12
  function isLocalizedDateTimeFieldValue(value) {
12
- return (typeof value === 'object' &&
13
- value !== null &&
13
+ return ((0, normalizedFieldValues_1.isLocalizedFieldValue)(value) &&
14
14
  Object.values(value).every(isDateTimeFieldValue));
15
15
  }
16
16
  exports.isLocalizedDateTimeFieldValue = isLocalizedDateTimeFieldValue;
@@ -1 +1 @@
1
- {"version":3,"file":"date_time.js","sourceRoot":"","sources":["../../../src/fieldTypes/date_time.ts"],"names":[],"mappings":";;;AAOA,SAAgB,oBAAoB,CAClC,KAAc;IAEd,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,IAAI,CAAC;IAChC,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ;QACzB,sCAAsC,CAAC,IAAI,CAAC,KAAK,CAAC,CACnD,CAAC;AACJ,CAAC;AARD,oDAQC;AAED,SAAgB,6BAA6B,CAC3C,KAAc;IAEd,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,oBAAoB,CAAC,CACjD,CAAC;AACJ,CAAC;AARD,sEAQC"}
1
+ {"version":3,"file":"date_time.js","sourceRoot":"","sources":["../../../src/fieldTypes/date_time.ts"],"names":[],"mappings":";;;AAAA,8EAG4C;AAO5C,SAAgB,oBAAoB,CAClC,KAAc;IAEd,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,IAAI,CAAC;IAChC,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ;QACzB,sCAAsC,CAAC,IAAI,CAAC,KAAK,CAAC,CACnD,CAAC;AACJ,CAAC;AARD,oDAQC;AAED,SAAgB,6BAA6B,CAC3C,KAAc;IAEd,OAAO,CACL,IAAA,6CAAqB,EAAC,KAAK,CAAC;QAC5B,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,oBAAoB,CAAC,CACjD,CAAC;AACJ,CAAC;AAPD,sEAOC"}