@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.
- package/README.md +575 -0
- package/dist/cjs/fieldTypes/boolean.js +2 -2
- package/dist/cjs/fieldTypes/boolean.js.map +1 -1
- package/dist/cjs/fieldTypes/color.js +2 -2
- package/dist/cjs/fieldTypes/color.js.map +1 -1
- package/dist/cjs/fieldTypes/date.js +2 -3
- package/dist/cjs/fieldTypes/date.js.map +1 -1
- package/dist/cjs/fieldTypes/date_time.js +2 -2
- package/dist/cjs/fieldTypes/date_time.js.map +1 -1
- package/dist/cjs/fieldTypes/file.js +33 -5
- package/dist/cjs/fieldTypes/file.js.map +1 -1
- package/dist/cjs/fieldTypes/float.js +2 -2
- package/dist/cjs/fieldTypes/float.js.map +1 -1
- package/dist/cjs/fieldTypes/gallery.js +20 -5
- package/dist/cjs/fieldTypes/gallery.js.map +1 -1
- package/dist/cjs/fieldTypes/index.js +2 -2
- package/dist/cjs/fieldTypes/index.js.map +1 -1
- package/dist/cjs/fieldTypes/integer.js +2 -2
- package/dist/cjs/fieldTypes/integer.js.map +1 -1
- package/dist/cjs/fieldTypes/json.js +2 -3
- package/dist/cjs/fieldTypes/json.js.map +1 -1
- package/dist/cjs/fieldTypes/lat_lon.js +2 -2
- package/dist/cjs/fieldTypes/lat_lon.js.map +1 -1
- package/dist/cjs/fieldTypes/link.js +4 -4
- package/dist/cjs/fieldTypes/link.js.map +1 -1
- package/dist/cjs/fieldTypes/links.js +5 -3
- package/dist/cjs/fieldTypes/links.js.map +1 -1
- package/dist/cjs/fieldTypes/rich_text.js +4 -6
- package/dist/cjs/fieldTypes/rich_text.js.map +1 -1
- package/dist/cjs/fieldTypes/seo.js +2 -3
- package/dist/cjs/fieldTypes/seo.js.map +1 -1
- package/dist/cjs/fieldTypes/single_block.js +7 -7
- package/dist/cjs/fieldTypes/single_block.js.map +1 -1
- package/dist/cjs/fieldTypes/slug.js +2 -3
- package/dist/cjs/fieldTypes/slug.js.map +1 -1
- package/dist/cjs/fieldTypes/string.js +2 -2
- package/dist/cjs/fieldTypes/string.js.map +1 -1
- package/dist/cjs/fieldTypes/structured_text.js +4 -6
- package/dist/cjs/fieldTypes/structured_text.js.map +1 -1
- package/dist/cjs/fieldTypes/text.js +2 -3
- package/dist/cjs/fieldTypes/text.js.map +1 -1
- package/dist/cjs/fieldTypes/video.js +2 -2
- package/dist/cjs/fieldTypes/video.js.map +1 -1
- package/dist/cjs/generated/Client.js +1 -1
- package/dist/cjs/index.js +4 -4
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/utilities/buildBlockRecord.js +8 -7
- package/dist/cjs/utilities/buildBlockRecord.js.map +1 -1
- package/dist/cjs/utilities/inspectItem.js +397 -0
- package/dist/cjs/utilities/inspectItem.js.map +1 -0
- package/dist/cjs/utilities/{blocks.js → nonRecursiveBlocks.js} +106 -111
- package/dist/cjs/utilities/nonRecursiveBlocks.js.map +1 -0
- package/dist/cjs/utilities/{fieldValue.js → normalizedFieldValues.js} +53 -41
- package/dist/cjs/utilities/normalizedFieldValues.js.map +1 -0
- package/dist/cjs/utilities/recursiveBlocks.js +121 -80
- package/dist/cjs/utilities/recursiveBlocks.js.map +1 -1
- package/dist/cjs/utilities/schemaRepository.js +2 -2
- package/dist/esm/fieldTypes/boolean.d.ts +1 -1
- package/dist/esm/fieldTypes/boolean.js +2 -2
- package/dist/esm/fieldTypes/boolean.js.map +1 -1
- package/dist/esm/fieldTypes/color.d.ts +1 -1
- package/dist/esm/fieldTypes/color.js +2 -2
- package/dist/esm/fieldTypes/color.js.map +1 -1
- package/dist/esm/fieldTypes/date.d.ts +1 -1
- package/dist/esm/fieldTypes/date.js +2 -3
- package/dist/esm/fieldTypes/date.js.map +1 -1
- package/dist/esm/fieldTypes/date_time.d.ts +1 -1
- package/dist/esm/fieldTypes/date_time.js +2 -2
- package/dist/esm/fieldTypes/date_time.js.map +1 -1
- package/dist/esm/fieldTypes/file.d.ts +68 -1
- package/dist/esm/fieldTypes/file.js +29 -3
- package/dist/esm/fieldTypes/file.js.map +1 -1
- package/dist/esm/fieldTypes/float.d.ts +1 -1
- package/dist/esm/fieldTypes/float.js +2 -2
- package/dist/esm/fieldTypes/float.js.map +1 -1
- package/dist/esm/fieldTypes/gallery.d.ts +27 -11
- package/dist/esm/fieldTypes/gallery.js +17 -4
- package/dist/esm/fieldTypes/gallery.js.map +1 -1
- package/dist/esm/fieldTypes/index.d.ts +2 -2
- package/dist/esm/fieldTypes/index.js +2 -2
- package/dist/esm/fieldTypes/index.js.map +1 -1
- package/dist/esm/fieldTypes/integer.d.ts +1 -1
- package/dist/esm/fieldTypes/integer.js +2 -2
- package/dist/esm/fieldTypes/integer.js.map +1 -1
- package/dist/esm/fieldTypes/json.d.ts +1 -1
- package/dist/esm/fieldTypes/json.js +2 -3
- package/dist/esm/fieldTypes/json.js.map +1 -1
- package/dist/esm/fieldTypes/lat_lon.d.ts +1 -1
- package/dist/esm/fieldTypes/lat_lon.js +2 -2
- package/dist/esm/fieldTypes/lat_lon.js.map +1 -1
- package/dist/esm/fieldTypes/link.d.ts +1 -1
- package/dist/esm/fieldTypes/link.js +4 -4
- package/dist/esm/fieldTypes/link.js.map +1 -1
- package/dist/esm/fieldTypes/links.d.ts +1 -1
- package/dist/esm/fieldTypes/links.js +5 -3
- package/dist/esm/fieldTypes/links.js.map +1 -1
- package/dist/esm/fieldTypes/rich_text.d.ts +1 -1
- package/dist/esm/fieldTypes/rich_text.js +4 -6
- package/dist/esm/fieldTypes/rich_text.js.map +1 -1
- package/dist/esm/fieldTypes/seo.d.ts +1 -1
- package/dist/esm/fieldTypes/seo.js +2 -3
- package/dist/esm/fieldTypes/seo.js.map +1 -1
- package/dist/esm/fieldTypes/single_block.d.ts +1 -1
- package/dist/esm/fieldTypes/single_block.js +7 -7
- package/dist/esm/fieldTypes/single_block.js.map +1 -1
- package/dist/esm/fieldTypes/slug.d.ts +1 -1
- package/dist/esm/fieldTypes/slug.js +2 -3
- package/dist/esm/fieldTypes/slug.js.map +1 -1
- package/dist/esm/fieldTypes/string.d.ts +1 -1
- package/dist/esm/fieldTypes/string.js +2 -2
- package/dist/esm/fieldTypes/string.js.map +1 -1
- package/dist/esm/fieldTypes/structured_text.d.ts +1 -1
- package/dist/esm/fieldTypes/structured_text.js +4 -6
- package/dist/esm/fieldTypes/structured_text.js.map +1 -1
- package/dist/esm/fieldTypes/text.d.ts +1 -1
- package/dist/esm/fieldTypes/text.js +2 -3
- package/dist/esm/fieldTypes/text.js.map +1 -1
- package/dist/esm/fieldTypes/video.d.ts +1 -1
- package/dist/esm/fieldTypes/video.js +2 -2
- package/dist/esm/fieldTypes/video.js.map +1 -1
- package/dist/esm/generated/Client.js +1 -1
- package/dist/esm/index.d.ts +4 -4
- package/dist/esm/index.js +4 -4
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/utilities/buildBlockRecord.js +9 -8
- package/dist/esm/utilities/buildBlockRecord.js.map +1 -1
- package/dist/esm/utilities/inspectItem.d.ts +8 -0
- package/dist/esm/utilities/inspectItem.js +393 -0
- package/dist/esm/utilities/inspectItem.js.map +1 -0
- package/dist/esm/utilities/itemDefinition.d.ts +28 -4
- package/dist/esm/utilities/nonRecursiveBlocks.d.ts +179 -0
- package/dist/esm/utilities/{blocks.js → nonRecursiveBlocks.js} +91 -96
- package/dist/esm/utilities/nonRecursiveBlocks.js.map +1 -0
- package/dist/{types/utilities/fieldValue.d.ts → esm/utilities/normalizedFieldValues.d.ts} +15 -14
- package/dist/esm/utilities/{fieldValue.js → normalizedFieldValues.js} +39 -28
- package/dist/esm/utilities/normalizedFieldValues.js.map +1 -0
- package/dist/esm/utilities/recursiveBlocks.d.ts +92 -9
- package/dist/esm/utilities/recursiveBlocks.js +113 -72
- package/dist/esm/utilities/recursiveBlocks.js.map +1 -1
- package/dist/esm/utilities/schemaRepository.d.ts +2 -2
- package/dist/esm/utilities/schemaRepository.js +2 -2
- package/dist/types/fieldTypes/boolean.d.ts +1 -1
- package/dist/types/fieldTypes/color.d.ts +1 -1
- package/dist/types/fieldTypes/date.d.ts +1 -1
- package/dist/types/fieldTypes/date_time.d.ts +1 -1
- package/dist/types/fieldTypes/file.d.ts +68 -1
- package/dist/types/fieldTypes/float.d.ts +1 -1
- package/dist/types/fieldTypes/gallery.d.ts +27 -11
- package/dist/types/fieldTypes/index.d.ts +2 -2
- package/dist/types/fieldTypes/integer.d.ts +1 -1
- package/dist/types/fieldTypes/json.d.ts +1 -1
- package/dist/types/fieldTypes/lat_lon.d.ts +1 -1
- package/dist/types/fieldTypes/link.d.ts +1 -1
- package/dist/types/fieldTypes/links.d.ts +1 -1
- package/dist/types/fieldTypes/rich_text.d.ts +1 -1
- package/dist/types/fieldTypes/seo.d.ts +1 -1
- package/dist/types/fieldTypes/single_block.d.ts +1 -1
- package/dist/types/fieldTypes/slug.d.ts +1 -1
- package/dist/types/fieldTypes/string.d.ts +1 -1
- package/dist/types/fieldTypes/structured_text.d.ts +1 -1
- package/dist/types/fieldTypes/text.d.ts +1 -1
- package/dist/types/fieldTypes/video.d.ts +1 -1
- package/dist/types/index.d.ts +4 -4
- package/dist/types/utilities/inspectItem.d.ts +8 -0
- package/dist/types/utilities/itemDefinition.d.ts +28 -4
- package/dist/types/utilities/nonRecursiveBlocks.d.ts +179 -0
- package/dist/{esm/utilities/fieldValue.d.ts → types/utilities/normalizedFieldValues.d.ts} +15 -14
- package/dist/types/utilities/recursiveBlocks.d.ts +92 -9
- package/dist/types/utilities/schemaRepository.d.ts +2 -2
- package/package.json +3 -3
- package/src/fieldTypes/boolean.ts +5 -3
- package/src/fieldTypes/color.ts +5 -3
- package/src/fieldTypes/date.ts +5 -4
- package/src/fieldTypes/date_time.ts +5 -3
- package/src/fieldTypes/file.ts +98 -4
- package/src/fieldTypes/float.ts +5 -3
- package/src/fieldTypes/gallery.ts +53 -20
- package/src/fieldTypes/index.ts +2 -3
- package/src/fieldTypes/integer.ts +5 -3
- package/src/fieldTypes/json.ts +5 -4
- package/src/fieldTypes/lat_lon.ts +5 -3
- package/src/fieldTypes/link.ts +7 -5
- package/src/fieldTypes/links.ts +8 -4
- package/src/fieldTypes/rich_text.ts +7 -7
- package/src/fieldTypes/seo.ts +5 -4
- package/src/fieldTypes/single_block.ts +10 -8
- package/src/fieldTypes/slug.ts +5 -4
- package/src/fieldTypes/string.ts +5 -3
- package/src/fieldTypes/structured_text.ts +7 -7
- package/src/fieldTypes/text.ts +5 -4
- package/src/fieldTypes/video.ts +5 -3
- package/src/generated/Client.ts +1 -1
- package/src/index.ts +4 -4
- package/src/utilities/buildBlockRecord.ts +16 -15
- package/src/utilities/inspectItem.ts +590 -0
- package/src/utilities/itemDefinition.ts +30 -3
- package/src/utilities/{blocks.ts → nonRecursiveBlocks.ts} +170 -136
- package/src/utilities/{fieldValue.ts → normalizedFieldValues.ts} +70 -30
- package/src/utilities/recursiveBlocks.ts +186 -171
- package/src/utilities/schemaRepository.ts +2 -2
- package/dist/cjs/utilities/blocks.js.map +0 -1
- package/dist/cjs/utilities/fieldValue.js.map +0 -1
- package/dist/esm/utilities/blocks.d.ts +0 -180
- package/dist/esm/utilities/blocks.js.map +0 -1
- package/dist/esm/utilities/fieldValue.js.map +0 -1
- package/dist/types/utilities/blocks.d.ts +0 -180
package/README.md
CHANGED
|
@@ -10,6 +10,581 @@ 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
|
+
schemaRepository: SchemaRepository,
|
|
79
|
+
fieldType: string,
|
|
80
|
+
nonLocalizedFieldValue: unknown,
|
|
81
|
+
visitor: (item: BlockItemInARequest, path: TreePath) => void | Promise<void>,
|
|
82
|
+
path?: TreePath
|
|
83
|
+
): Promise<void>
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
**Parameters:**
|
|
87
|
+
- `schemaRepository`: Repository for caching schema lookups
|
|
88
|
+
- `fieldType`: The typeo of DatoCMS field (ie. `string`, `rich_text`, etc.)
|
|
89
|
+
- `nonLocalizedFieldValue`: The non-localized field value
|
|
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
|
+
schemaRepository: SchemaRepository,
|
|
104
|
+
fieldType: string,
|
|
105
|
+
nonLocalizedFieldValue: unknown,
|
|
106
|
+
mapper: (item: BlockItemInARequest, path: TreePath) => BlockItemInARequest | Promise<BlockItemInARequest>,
|
|
107
|
+
path?: TreePath
|
|
108
|
+
): Promise<unknown>
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
**Parameters:**
|
|
112
|
+
- `schemaRepository`: Repository for caching schema lookups
|
|
113
|
+
- `fieldType`: The typeo of DatoCMS field (ie. `string`, `rich_text`, etc.)
|
|
114
|
+
- `nonLocalizedFieldValue`: The non-localized field value
|
|
115
|
+
- `mapper`: Function that transforms each block
|
|
116
|
+
- `path`: Optional base path
|
|
117
|
+
|
|
118
|
+
**Returns:** New field value
|
|
119
|
+
</details>
|
|
120
|
+
|
|
121
|
+
<details>
|
|
122
|
+
<summary><strong>filterBlocksInNonLocalizedFieldValue()</strong> - Recursively filter blocks</summary>
|
|
123
|
+
|
|
124
|
+
Filter blocks recursively, removing blocks at any nesting level that don't match the predicate.
|
|
125
|
+
|
|
126
|
+
**TypeScript Signature:**
|
|
127
|
+
```typescript
|
|
128
|
+
async function filterBlocksInNonLocalizedFieldValue(
|
|
129
|
+
schemaRepository: SchemaRepository,
|
|
130
|
+
fieldType: string,
|
|
131
|
+
nonLocalizedFieldValue: unknown,
|
|
132
|
+
predicate: (item: BlockItemInARequest, path: TreePath) => boolean | Promise<boolean>,
|
|
133
|
+
path?: TreePath
|
|
134
|
+
): Promise<unknown>
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
**Parameters:**
|
|
138
|
+
- `schemaRepository`: Repository for caching schema lookups
|
|
139
|
+
- `fieldType`: The typeo of DatoCMS field (ie. `string`, `rich_text`, etc.)
|
|
140
|
+
- `nonLocalizedFieldValue`: The non-localized field value to filter
|
|
141
|
+
- `predicate`: Function that tests each block
|
|
142
|
+
- `path`: Optional base path
|
|
143
|
+
|
|
144
|
+
**Returns:** New field value with filtered blocks
|
|
145
|
+
|
|
146
|
+
**Usage Example:**
|
|
147
|
+
```typescript
|
|
148
|
+
// Remove all video blocks at any nesting level
|
|
149
|
+
const noVideos = await filterBlocksInNonLocalizedFieldValue(
|
|
150
|
+
schemaRepository,
|
|
151
|
+
field,
|
|
152
|
+
fieldValue,
|
|
153
|
+
(block) => block.relationships.item_type.data.id !== 'video_block'
|
|
154
|
+
);
|
|
155
|
+
```
|
|
156
|
+
</details>
|
|
157
|
+
|
|
158
|
+
<details>
|
|
159
|
+
<summary><strong>findAllBlocksInNonLocalizedFieldValue()</strong> - Recursively search for blocks</summary>
|
|
160
|
+
|
|
161
|
+
Find all blocks that match the predicate, searching recursively through nested blocks.
|
|
162
|
+
|
|
163
|
+
**TypeScript Signature:**
|
|
164
|
+
```typescript
|
|
165
|
+
async function findAllBlocksInNonLocalizedFieldValue(
|
|
166
|
+
schemaRepository: SchemaRepository,
|
|
167
|
+
fieldType: string,
|
|
168
|
+
nonLocalizedFieldValue: unknown,
|
|
169
|
+
predicate: (item: BlockItemInARequest, path: TreePath) => boolean | Promise<boolean>,
|
|
170
|
+
path?: TreePath
|
|
171
|
+
): Promise<Array<{ item: BlockItemInARequest; path: TreePath }>>
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
**Parameters:**
|
|
175
|
+
- `schemaRepository`: Repository for caching schema lookups
|
|
176
|
+
- `fieldType`: The typeo of DatoCMS field (ie. `string`, `rich_text`, etc.)
|
|
177
|
+
- `nonLocalizedFieldValue`: The non-localized field value to search
|
|
178
|
+
- `predicate`: Function that tests each block
|
|
179
|
+
- `path`: Optional base path
|
|
180
|
+
|
|
181
|
+
**Returns:** Array of all matching blocks with their paths
|
|
182
|
+
</details>
|
|
183
|
+
|
|
184
|
+
<details>
|
|
185
|
+
<summary><strong>reduceBlocksInNonLocalizedFieldValue()</strong> - Recursively reduce blocks</summary>
|
|
186
|
+
|
|
187
|
+
Reduce all blocks recursively to a single value.
|
|
188
|
+
|
|
189
|
+
**TypeScript Signature:**
|
|
190
|
+
```typescript
|
|
191
|
+
async function reduceBlocksInNonLocalizedFieldValue<R>(
|
|
192
|
+
schemaRepository: SchemaRepository,
|
|
193
|
+
fieldType: string,
|
|
194
|
+
nonLocalizedFieldValue: unknown,
|
|
195
|
+
reducer: (accumulator: R, item: BlockItemInARequest, path: TreePath) => R | Promise<R>,
|
|
196
|
+
initialValue: R,
|
|
197
|
+
path?: TreePath
|
|
198
|
+
): Promise<R>
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
**Parameters:**
|
|
202
|
+
- `schemaRepository`: Repository for caching schema lookups
|
|
203
|
+
- `fieldType`: The typeo of DatoCMS field (ie. `string`, `rich_text`, etc.)
|
|
204
|
+
- `nonLocalizedFieldValue`: The non-localized field value to reduce
|
|
205
|
+
- `reducer`: Function that processes each block
|
|
206
|
+
- `initialValue`: Initial accumulator value
|
|
207
|
+
- `path`: Optional base path
|
|
208
|
+
|
|
209
|
+
**Returns:** The final accumulated value
|
|
210
|
+
```
|
|
211
|
+
</details>
|
|
212
|
+
|
|
213
|
+
<details>
|
|
214
|
+
<summary><strong>someBlocksInNonLocalizedFieldValue()</strong> - Recursively test for any match</summary>
|
|
215
|
+
|
|
216
|
+
Check if any block (including nested) matches the predicate.
|
|
217
|
+
|
|
218
|
+
**TypeScript Signature:**
|
|
219
|
+
```typescript
|
|
220
|
+
async function someBlocksInNonLocalizedFieldValue(
|
|
221
|
+
schemaRepository: SchemaRepository,
|
|
222
|
+
fieldType: string,
|
|
223
|
+
nonLocalizedFieldValue: unknown,
|
|
224
|
+
predicate: (item: BlockItemInARequest, path: TreePath) => boolean | Promise<boolean>,
|
|
225
|
+
path?: TreePath
|
|
226
|
+
): Promise<boolean>
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
**Parameters:**
|
|
230
|
+
- `schemaRepository`: Repository for caching schema lookups
|
|
231
|
+
- `fieldType`: The typeo of DatoCMS field (ie. `string`, `rich_text`, etc.)
|
|
232
|
+
- `nonLocalizedFieldValue`: The non-localized field value to test
|
|
233
|
+
- `predicate`: Function that tests each block
|
|
234
|
+
- `path`: Optional base path
|
|
235
|
+
|
|
236
|
+
**Returns:** True if any block matches
|
|
237
|
+
```
|
|
238
|
+
</details>
|
|
239
|
+
|
|
240
|
+
<details>
|
|
241
|
+
<summary><strong>everyBlockInNonLocalizedFieldValue()</strong> - Recursively test if all match</summary>
|
|
242
|
+
|
|
243
|
+
Check if every block (including nested) matches the predicate.
|
|
244
|
+
|
|
245
|
+
**TypeScript Signature:**
|
|
246
|
+
```typescript
|
|
247
|
+
async function everyBlockInNonLocalizedFieldValue(
|
|
248
|
+
schemaRepository: SchemaRepository,
|
|
249
|
+
fieldType: string,
|
|
250
|
+
nonLocalizedFieldValue: unknown,
|
|
251
|
+
predicate: (item: BlockItemInARequest, path: TreePath) => boolean | Promise<boolean>,
|
|
252
|
+
path?: TreePath
|
|
253
|
+
): Promise<boolean>
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
**Parameters:**
|
|
257
|
+
- `schemaRepository`: Repository for caching schema lookups
|
|
258
|
+
- `fieldType`: The typeo of DatoCMS field (ie. `string`, `rich_text`, etc.)
|
|
259
|
+
- `nonLocalizedFieldValue`: The non-localized field value to test
|
|
260
|
+
- `predicate`: Function that tests each block
|
|
261
|
+
- `path`: Optional base path
|
|
262
|
+
|
|
263
|
+
**Returns:** True if all blocks match
|
|
264
|
+
</details>
|
|
265
|
+
|
|
266
|
+
#### Block Record Management
|
|
267
|
+
|
|
268
|
+
<details>
|
|
269
|
+
<summary><strong>buildBlockRecord()</strong> - Create block records from data</summary>
|
|
270
|
+
|
|
271
|
+
Converts a block data object into the proper format for API requests.
|
|
272
|
+
|
|
273
|
+
**TypeScript Signature:**
|
|
274
|
+
```typescript
|
|
275
|
+
function buildBlockRecord<D extends ItemTypeDefinition>(
|
|
276
|
+
body: ItemUpdateSchema<ToItemDefinitionAsRequest<D>>
|
|
277
|
+
): NewBlockInARequest<ToItemDefinitionAsRequest<D>>
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
**Parameters:**
|
|
281
|
+
- `body`: Block data in update schema format
|
|
282
|
+
|
|
283
|
+
**Returns:** Formatted block record ready for API requests
|
|
284
|
+
</details>
|
|
285
|
+
|
|
286
|
+
<details>
|
|
287
|
+
<summary><strong>duplicateBlockRecord()</strong> - Deep clone blocks with nested content</summary>
|
|
288
|
+
|
|
289
|
+
Creates a deep copy of a block record, including all nested blocks, removing IDs to create new instances.
|
|
290
|
+
|
|
291
|
+
**TypeScript Signature:**
|
|
292
|
+
```typescript
|
|
293
|
+
async function duplicateBlockRecord<D extends ItemTypeDefinition>(
|
|
294
|
+
existingBlock: ItemWithOptionalIdAndMeta<ToItemDefinitionWithNestedBlocks<D>>,
|
|
295
|
+
schemaRepository: SchemaRepository
|
|
296
|
+
): Promise<NewBlockInARequest<ToItemDefinitionAsRequest<D>>>
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
**Parameters:**
|
|
300
|
+
- `existingBlock`: The block to duplicate
|
|
301
|
+
- `schemaRepository`: Repository for schema lookups
|
|
302
|
+
|
|
303
|
+
**Returns:** New block record without IDs, ready to be created
|
|
304
|
+
</details>
|
|
305
|
+
|
|
306
|
+
### 3. Localization-Aware Field Utilities
|
|
307
|
+
|
|
308
|
+
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.
|
|
309
|
+
|
|
310
|
+
<details>
|
|
311
|
+
<summary><strong>isLocalized()</strong> - Check if a field is localized</summary>
|
|
312
|
+
|
|
313
|
+
Determines whether a DatoCMS field is configured for localization.
|
|
314
|
+
|
|
315
|
+
**TypeScript Signature:**
|
|
316
|
+
```typescript
|
|
317
|
+
function isLocalized(field: Field): boolean
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
**Parameters:**
|
|
321
|
+
- `fieldType`: The typeo of DatoCMS field (ie. `string`, `rich_text`, etc.)
|
|
322
|
+
|
|
323
|
+
**Returns:** True if the field is localized, false otherwise
|
|
324
|
+
</details>
|
|
325
|
+
|
|
326
|
+
<details>
|
|
327
|
+
<summary><strong>mapNormalizedFieldValues() / mapNormalizedFieldValuesAsync()</strong> - Transform field values</summary>
|
|
328
|
+
|
|
329
|
+
Apply a transformation function to field values, handling both localized and non-localized fields uniformly.
|
|
330
|
+
|
|
331
|
+
**TypeScript Signatures:**
|
|
332
|
+
```typescript
|
|
333
|
+
function mapNormalizedFieldValues<TInput, TOutput>(
|
|
334
|
+
field: Field,
|
|
335
|
+
value: TInput | LocalizedFieldValue<TInput>,
|
|
336
|
+
mapFn: (locale: string | undefined, localeValue: TInput) => TOutput
|
|
337
|
+
): TOutput | LocalizedFieldValue<TOutput>
|
|
338
|
+
|
|
339
|
+
async function mapNormalizedFieldValuesAsync<TInput, TOutput>(
|
|
340
|
+
field: Field,
|
|
341
|
+
value: TInput | LocalizedFieldValue<TInput>,
|
|
342
|
+
mapFn: (locale: string | undefined, localeValue: TInput) => Promise<TOutput>
|
|
343
|
+
): Promise<TOutput | LocalizedFieldValue<TOutput>>
|
|
344
|
+
```
|
|
345
|
+
|
|
346
|
+
**Parameters:**
|
|
347
|
+
- `fieldType`: The typeo of DatoCMS field (ie. `string`, `rich_text`, etc.)
|
|
348
|
+
- `nonLocalizedFieldValue`: The non-localized field value (localized or non-localized)
|
|
349
|
+
- `mapFn`: Function to transform each value (receives locale for localized fields, undefined for non-localized)
|
|
350
|
+
|
|
351
|
+
**Returns:** Transformed value maintaining the same structure
|
|
352
|
+
</details>
|
|
353
|
+
|
|
354
|
+
<details>
|
|
355
|
+
<summary><strong>filterNormalizedFieldValues() / filterNormalizedFieldValuesAsync()</strong> - Filter field values</summary>
|
|
356
|
+
|
|
357
|
+
Filter field values based on a predicate, handling both localized and non-localized fields.
|
|
358
|
+
|
|
359
|
+
**TypeScript Signatures:**
|
|
360
|
+
```typescript
|
|
361
|
+
function filterNormalizedFieldValues<T>(
|
|
362
|
+
field: Field,
|
|
363
|
+
value: T | LocalizedFieldValue<T>,
|
|
364
|
+
filterFn: (locale: string | undefined, localeValue: T) => boolean
|
|
365
|
+
): T | LocalizedFieldValue<T> | undefined
|
|
366
|
+
|
|
367
|
+
async function filterNormalizedFieldValuesAsync<T>(
|
|
368
|
+
field: Field,
|
|
369
|
+
value: T | LocalizedFieldValue<T>,
|
|
370
|
+
filterFn: (locale: string | undefined, localeValue: T) => Promise<boolean>
|
|
371
|
+
): Promise<T | LocalizedFieldValue<T> | undefined>
|
|
372
|
+
```
|
|
373
|
+
|
|
374
|
+
**Parameters:**
|
|
375
|
+
- `fieldType`: The typeo of DatoCMS field (ie. `string`, `rich_text`, etc.)
|
|
376
|
+
- `nonLocalizedFieldValue`: The non-localized field value to filter
|
|
377
|
+
- `filterFn`: Predicate function for filtering
|
|
378
|
+
|
|
379
|
+
**Returns:** Filtered value or undefined if all filtered out
|
|
380
|
+
</details>
|
|
381
|
+
|
|
382
|
+
<details>
|
|
383
|
+
<summary><strong>visitNormalizedFieldValues() / visitNormalizedFieldValuesAsync()</strong> - Iterate over field values</summary>
|
|
384
|
+
|
|
385
|
+
Visit each value in a field, handling both localized and non-localized fields.
|
|
386
|
+
|
|
387
|
+
**TypeScript Signatures:**
|
|
388
|
+
```typescript
|
|
389
|
+
function visitNormalizedFieldValues<T>(
|
|
390
|
+
field: Field,
|
|
391
|
+
value: T | LocalizedFieldValue<T>,
|
|
392
|
+
visitFn: (locale: string | undefined, localeValue: T) => void
|
|
393
|
+
): void
|
|
394
|
+
|
|
395
|
+
async function visitNormalizedFieldValuesAsync<T>(
|
|
396
|
+
field: Field,
|
|
397
|
+
value: T | LocalizedFieldValue<T>,
|
|
398
|
+
visitFn: (locale: string | undefined, localeValue: T) => Promise<void>
|
|
399
|
+
): Promise<void>
|
|
400
|
+
```
|
|
401
|
+
|
|
402
|
+
**Parameters:**
|
|
403
|
+
- `fieldType`: The typeo of DatoCMS field (ie. `string`, `rich_text`, etc.)
|
|
404
|
+
- `nonLocalizedFieldValue`: The non-localized field value to visit
|
|
405
|
+
- `visitFn`: Function called for each value
|
|
406
|
+
</details>
|
|
407
|
+
|
|
408
|
+
<details>
|
|
409
|
+
<summary><strong>someNormalizedFieldValues() / someNormalizedFieldValuesAsync()</strong> - Test if any value matches</summary>
|
|
410
|
+
|
|
411
|
+
Check if at least one field value passes the test.
|
|
412
|
+
|
|
413
|
+
**TypeScript Signatures:**
|
|
414
|
+
```typescript
|
|
415
|
+
function someNormalizedFieldValues<T>(
|
|
416
|
+
field: Field,
|
|
417
|
+
value: T | LocalizedFieldValue<T>,
|
|
418
|
+
testFn: (locale: string | undefined, localeValue: T) => boolean
|
|
419
|
+
): boolean
|
|
420
|
+
|
|
421
|
+
async function someNormalizedFieldValuesAsync<T>(
|
|
422
|
+
field: Field,
|
|
423
|
+
value: T | LocalizedFieldValue<T>,
|
|
424
|
+
testFn: (locale: string | undefined, localeValue: T) => Promise<boolean>
|
|
425
|
+
): Promise<boolean>
|
|
426
|
+
```
|
|
427
|
+
|
|
428
|
+
**Parameters:**
|
|
429
|
+
- `fieldType`: The typeo of DatoCMS field (ie. `string`, `rich_text`, etc.)
|
|
430
|
+
- `nonLocalizedFieldValue`: The non-localized field value to test
|
|
431
|
+
- `testFn`: Predicate function
|
|
432
|
+
|
|
433
|
+
**Returns:** True if any value passes the test
|
|
434
|
+
</details>
|
|
435
|
+
|
|
436
|
+
<details>
|
|
437
|
+
<summary><strong>everyNormalizedFieldValue() / everyNormalizedFieldValueAsync()</strong> - Test if all values match</summary>
|
|
438
|
+
|
|
439
|
+
Check if all field values pass the test.
|
|
440
|
+
|
|
441
|
+
**TypeScript Signatures:**
|
|
442
|
+
```typescript
|
|
443
|
+
function everyNormalizedFieldValue<T>(
|
|
444
|
+
field: Field,
|
|
445
|
+
value: T | LocalizedFieldValue<T>,
|
|
446
|
+
testFn: (locale: string | undefined, localeValue: T) => boolean
|
|
447
|
+
): boolean
|
|
448
|
+
|
|
449
|
+
async function everyNormalizedFieldValueAsync<T>(
|
|
450
|
+
field: Field,
|
|
451
|
+
value: T | LocalizedFieldValue<T>,
|
|
452
|
+
testFn: (locale: string | undefined, localeValue: T) => Promise<boolean>
|
|
453
|
+
): Promise<boolean>
|
|
454
|
+
```
|
|
455
|
+
|
|
456
|
+
**Parameters:**
|
|
457
|
+
- `fieldType`: The typeo of DatoCMS field (ie. `string`, `rich_text`, etc.)
|
|
458
|
+
- `nonLocalizedFieldValue`: The non-localized field value to test
|
|
459
|
+
- `testFn`: Predicate function
|
|
460
|
+
|
|
461
|
+
**Returns:** True if all values pass the test
|
|
462
|
+
</details>
|
|
463
|
+
|
|
464
|
+
<details>
|
|
465
|
+
<summary><strong>toNormalizedFieldValueEntries() / fromNormalizedFieldValueEntries()</strong> - Convert between formats</summary>
|
|
466
|
+
|
|
467
|
+
Convert field values to/from a normalized entry format for uniform processing.
|
|
468
|
+
|
|
469
|
+
**TypeScript Signatures:**
|
|
470
|
+
```typescript
|
|
471
|
+
function toNormalizedFieldValueEntries<T>(
|
|
472
|
+
field: Field,
|
|
473
|
+
value: T | LocalizedFieldValue<T>
|
|
474
|
+
): NormalizedFieldValueEntry<T>[]
|
|
475
|
+
|
|
476
|
+
function fromNormalizedFieldValueEntries<T>(
|
|
477
|
+
field: Field,
|
|
478
|
+
entries: NormalizedFieldValueEntry<T>[]
|
|
479
|
+
): T | LocalizedFieldValue<T>
|
|
480
|
+
|
|
481
|
+
type NormalizedFieldValueEntry<T> = {
|
|
482
|
+
locale: string | undefined;
|
|
483
|
+
value: T;
|
|
484
|
+
}
|
|
485
|
+
```
|
|
486
|
+
|
|
487
|
+
**Parameters:**
|
|
488
|
+
- `fieldType`: The typeo of DatoCMS field (ie. `string`, `rich_text`, etc.)
|
|
489
|
+
- `nonLocalizedFieldValue`/`entries non-localized`: Value to convert from/to
|
|
490
|
+
|
|
491
|
+
**Returns:** Normalized entries array or reconstructed field value
|
|
492
|
+
|
|
493
|
+
**Usage Example:**
|
|
494
|
+
```typescript
|
|
495
|
+
// Convert to entries for processing
|
|
496
|
+
const entries = toNormalizedFieldValueEntries(field, fieldValue);
|
|
497
|
+
|
|
498
|
+
// Process entries uniformly
|
|
499
|
+
const processed = entries.map(({ locale, value }) => ({
|
|
500
|
+
locale,
|
|
501
|
+
value: processValue(value)
|
|
502
|
+
}));
|
|
503
|
+
|
|
504
|
+
// Convert back to field value format
|
|
505
|
+
const result = fromNormalizedFieldValueEntries(field, processed);
|
|
506
|
+
```
|
|
507
|
+
</details>
|
|
508
|
+
|
|
509
|
+
### 4. Schema Repository
|
|
510
|
+
|
|
511
|
+
The `SchemaRepository` class provides an in-memory caching system for DatoCMS schema entities, significantly improving performance when working with complex content structures.
|
|
512
|
+
|
|
513
|
+
<details>
|
|
514
|
+
<summary><strong>SchemaRepository</strong> - Cache schema entities for performance</summary>
|
|
515
|
+
|
|
516
|
+
Repository for DatoCMS schema entities including item types, fields, fieldsets, and plugins. Provides caching and efficient lookup functionality for schema-related operations.
|
|
517
|
+
|
|
518
|
+
**Key Features:**
|
|
519
|
+
- Automatic caching of schema entities after first fetch
|
|
520
|
+
- Efficient lookups by ID, API key, or package name
|
|
521
|
+
- Essential for recursive block operations
|
|
522
|
+
- Dramatically reduces API calls during complex traversals
|
|
523
|
+
|
|
524
|
+
**TypeScript Class:**
|
|
525
|
+
```typescript
|
|
526
|
+
class SchemaRepository {
|
|
527
|
+
constructor(client: GenericClient)
|
|
528
|
+
|
|
529
|
+
// Item Type methods
|
|
530
|
+
async getAllItemTypes(): Promise<ItemType[]>
|
|
531
|
+
async getAllModels(): Promise<ItemType[]>
|
|
532
|
+
async getAllBlockModels(): Promise<ItemType[]>
|
|
533
|
+
async getItemTypeByApiKey(apiKey: string): Promise<ItemType>
|
|
534
|
+
async getItemTypeById(id: string): Promise<ItemType>
|
|
535
|
+
|
|
536
|
+
// Field methods
|
|
537
|
+
async getItemTypeFields(itemType: ItemType): Promise<Field[]>
|
|
538
|
+
async getItemTypeFieldsets(itemType: ItemType): Promise<Fieldset[]>
|
|
539
|
+
|
|
540
|
+
// Plugin methods
|
|
541
|
+
async getAllPlugins(): Promise<Plugin[]>
|
|
542
|
+
async getPluginById(id: string): Promise<Plugin>
|
|
543
|
+
async getPluginByPackageName(packageName: string): Promise<Plugin>
|
|
544
|
+
|
|
545
|
+
// Raw variants (return API response format)
|
|
546
|
+
async getAllRawItemTypes(): Promise<RawItemType[]>
|
|
547
|
+
async getRawItemTypeByApiKey(apiKey: string): Promise<RawItemType>
|
|
548
|
+
// ... and more raw variants
|
|
549
|
+
}
|
|
550
|
+
```
|
|
551
|
+
|
|
552
|
+
**When to Use:**
|
|
553
|
+
- Complex traversal operations that repeatedly lookup schema
|
|
554
|
+
- Bulk operations processing multiple records
|
|
555
|
+
- Scripts that need efficient access to schema information
|
|
556
|
+
- Working with recursive block utilities
|
|
557
|
+
|
|
558
|
+
**When NOT to Use:**
|
|
559
|
+
- Scripts that modify schema (models, fields, etc.)
|
|
560
|
+
- Long-running applications (no cache expiration)
|
|
561
|
+
- When schema might change during execution
|
|
562
|
+
|
|
563
|
+
**Usage Example:**
|
|
564
|
+
```typescript
|
|
565
|
+
const schemaRepository = new SchemaRepository(client);
|
|
566
|
+
|
|
567
|
+
// First call fetches from API and caches
|
|
568
|
+
const blogPost = await schemaRepository.getItemTypeByApiKey('blog_post');
|
|
569
|
+
const fields = await schemaRepository.getItemTypeFields(blogPost);
|
|
570
|
+
|
|
571
|
+
// Subsequent calls use cached data (no API calls)
|
|
572
|
+
const sameBlogPost = await schemaRepository.getItemTypeByApiKey('blog_post');
|
|
573
|
+
const sameFields = await schemaRepository.getItemTypeFields(blogPost);
|
|
574
|
+
|
|
575
|
+
// Use with recursive utilities for optimal performance
|
|
576
|
+
await mapBlocksInNonLocalizedFieldValue(
|
|
577
|
+
schemaRepository, // Pass repository for efficient lookups
|
|
578
|
+
field,
|
|
579
|
+
fieldValue,
|
|
580
|
+
async (block) => { /* transform */ }
|
|
581
|
+
);
|
|
582
|
+
```
|
|
583
|
+
|
|
584
|
+
**Performance Impact:**
|
|
585
|
+
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.
|
|
586
|
+
</details>
|
|
587
|
+
|
|
13
588
|
## Contributing
|
|
14
589
|
|
|
15
590
|
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 (
|
|
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":";;;
|
|
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 (
|
|
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":";;;
|
|
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 (
|
|
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":";;;
|
|
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 (
|
|
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":";;;
|
|
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"}
|