@datocms/cma-client 5.1.11 → 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.
- package/README.md +40 -46
- package/dist/cjs/fieldTypes/file.js +6 -6
- package/dist/cjs/fieldTypes/gallery.js +7 -7
- package/dist/cjs/fieldTypes/rich_text.js +14 -12
- package/dist/cjs/fieldTypes/rich_text.js.map +1 -1
- package/dist/cjs/fieldTypes/schema.js +3 -0
- package/dist/cjs/fieldTypes/schema.js.map +1 -0
- package/dist/cjs/fieldTypes/single_block.js +13 -12
- package/dist/cjs/fieldTypes/single_block.js.map +1 -1
- package/dist/cjs/fieldTypes/structured_text.js +13 -12
- package/dist/cjs/fieldTypes/structured_text.js.map +1 -1
- package/dist/cjs/generated/Client.js +1 -1
- package/dist/cjs/generated/resources/Item.js.map +1 -1
- package/dist/cjs/generated/resources/ScheduledPublication.js.map +1 -1
- package/dist/cjs/generated/resources/ScheduledUnpublishing.js.map +1 -1
- package/dist/cjs/generated/resources/Upload.js.map +1 -1
- package/dist/cjs/index.js +1 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/utilities/buildBlockRecord.js +1 -46
- package/dist/cjs/utilities/buildBlockRecord.js.map +1 -1
- package/dist/cjs/utilities/duplicateBlockRecord.js +49 -0
- package/dist/cjs/utilities/duplicateBlockRecord.js.map +1 -0
- package/dist/cjs/utilities/inspectItem.js +50 -20
- package/dist/cjs/utilities/inspectItem.js.map +1 -1
- package/dist/cjs/utilities/nonRecursiveBlocks.js +1 -170
- package/dist/cjs/utilities/nonRecursiveBlocks.js.map +1 -1
- package/dist/cjs/utilities/recursiveBlocks.js +52 -112
- package/dist/cjs/utilities/recursiveBlocks.js.map +1 -1
- package/dist/esm/fieldTypes/file.d.ts +3 -3
- package/dist/esm/fieldTypes/file.js +3 -3
- package/dist/esm/fieldTypes/gallery.d.ts +5 -5
- package/dist/esm/fieldTypes/gallery.js +5 -5
- package/dist/esm/fieldTypes/rich_text.d.ts +8 -9
- package/dist/esm/fieldTypes/rich_text.js +9 -7
- package/dist/esm/fieldTypes/rich_text.js.map +1 -1
- package/dist/esm/fieldTypes/schema.d.ts +59 -0
- package/dist/esm/fieldTypes/schema.js +2 -0
- package/dist/esm/fieldTypes/schema.js.map +1 -0
- package/dist/esm/fieldTypes/single_block.d.ts +30 -15
- package/dist/esm/fieldTypes/single_block.js +8 -7
- package/dist/esm/fieldTypes/single_block.js.map +1 -1
- package/dist/esm/fieldTypes/structured_text.d.ts +14 -15
- package/dist/esm/fieldTypes/structured_text.js +8 -7
- package/dist/esm/fieldTypes/structured_text.js.map +1 -1
- package/dist/esm/generated/ApiTypes.d.ts +90 -980
- package/dist/esm/generated/Client.js +1 -1
- package/dist/esm/generated/RawApiTypes.d.ts +156 -999
- package/dist/esm/generated/resources/Field.d.ts +200 -200
- package/dist/esm/generated/resources/Item.d.ts +34 -34
- package/dist/esm/generated/resources/Item.js.map +1 -1
- package/dist/esm/generated/resources/ItemVersion.d.ts +3 -1
- package/dist/esm/generated/resources/ScheduledPublication.d.ts +3 -3
- package/dist/esm/generated/resources/ScheduledPublication.js.map +1 -1
- package/dist/esm/generated/resources/ScheduledUnpublishing.d.ts +3 -3
- package/dist/esm/generated/resources/ScheduledUnpublishing.js.map +1 -1
- package/dist/esm/generated/resources/Upload.d.ts +6 -6
- package/dist/esm/generated/resources/Upload.js.map +1 -1
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/utilities/buildBlockRecord.d.ts +3 -5
- package/dist/esm/utilities/buildBlockRecord.js +0 -44
- package/dist/esm/utilities/buildBlockRecord.js.map +1 -1
- package/dist/esm/utilities/duplicateBlockRecord.d.ts +6 -0
- package/dist/esm/utilities/duplicateBlockRecord.js +45 -0
- package/dist/esm/utilities/duplicateBlockRecord.js.map +1 -0
- package/dist/esm/utilities/inspectItem.d.ts +3 -3
- package/dist/esm/utilities/inspectItem.js +28 -21
- package/dist/esm/utilities/inspectItem.js.map +1 -1
- package/dist/esm/utilities/itemDefinition.d.ts +25 -27
- package/dist/esm/utilities/nonRecursiveBlocks.d.ts +10 -75
- package/dist/esm/utilities/nonRecursiveBlocks.js +1 -164
- package/dist/esm/utilities/nonRecursiveBlocks.js.map +1 -1
- package/dist/esm/utilities/recursiveBlocks.d.ts +53 -23
- package/dist/esm/utilities/recursiveBlocks.js +52 -112
- package/dist/esm/utilities/recursiveBlocks.js.map +1 -1
- package/dist/types/fieldTypes/file.d.ts +3 -3
- package/dist/types/fieldTypes/gallery.d.ts +5 -5
- package/dist/types/fieldTypes/rich_text.d.ts +8 -9
- package/dist/types/fieldTypes/schema.d.ts +59 -0
- package/dist/types/fieldTypes/single_block.d.ts +30 -15
- package/dist/types/fieldTypes/structured_text.d.ts +14 -15
- package/dist/types/generated/ApiTypes.d.ts +90 -980
- package/dist/types/generated/RawApiTypes.d.ts +156 -999
- package/dist/types/generated/resources/Field.d.ts +200 -200
- package/dist/types/generated/resources/Item.d.ts +34 -34
- package/dist/types/generated/resources/ItemVersion.d.ts +3 -1
- package/dist/types/generated/resources/ScheduledPublication.d.ts +3 -3
- package/dist/types/generated/resources/ScheduledUnpublishing.d.ts +3 -3
- package/dist/types/generated/resources/Upload.d.ts +6 -6
- package/dist/types/index.d.ts +1 -0
- package/dist/types/utilities/buildBlockRecord.d.ts +3 -5
- package/dist/types/utilities/duplicateBlockRecord.d.ts +6 -0
- package/dist/types/utilities/inspectItem.d.ts +3 -3
- package/dist/types/utilities/itemDefinition.d.ts +25 -27
- package/dist/types/utilities/nonRecursiveBlocks.d.ts +10 -75
- package/dist/types/utilities/recursiveBlocks.d.ts +53 -23
- package/package.json +3 -3
- package/src/fieldTypes/file.ts +6 -6
- package/src/fieldTypes/gallery.ts +10 -10
- package/src/fieldTypes/rich_text.ts +26 -24
- package/src/fieldTypes/schema.ts +657 -0
- package/src/fieldTypes/single_block.ts +61 -38
- package/src/fieldTypes/structured_text.ts +57 -51
- package/src/generated/ApiTypes.ts +217 -1880
- package/src/generated/Client.ts +1 -1
- package/src/generated/RawApiTypes.ts +272 -2113
- package/src/generated/resources/Item.ts +93 -187
- package/src/generated/resources/ScheduledPublication.ts +4 -15
- package/src/generated/resources/ScheduledUnpublishing.ts +4 -15
- package/src/generated/resources/Upload.ts +9 -32
- package/src/index.ts +1 -0
- package/src/utilities/buildBlockRecord.ts +4 -60
- package/src/utilities/duplicateBlockRecord.ts +52 -0
- package/src/utilities/inspectItem.ts +64 -52
- package/src/utilities/itemDefinition.ts +109 -98
- package/src/utilities/nonRecursiveBlocks.ts +25 -279
- package/src/utilities/recursiveBlocks.ts +337 -72
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import type * as RawApiTypes from '../generated/RawApiTypes';
|
|
2
|
-
import
|
|
2
|
+
import { isValidId } from '../utilities/id';
|
|
3
|
+
import type {
|
|
4
|
+
ItemTypeDefinition,
|
|
5
|
+
ToItemAttributesInRequest,
|
|
6
|
+
} from '../utilities/itemDefinition';
|
|
3
7
|
import {
|
|
4
8
|
type LocalizedFieldValue,
|
|
5
9
|
isLocalizedFieldValue,
|
|
@@ -55,17 +59,31 @@ export type SingleBlockFieldValue = string | null;
|
|
|
55
59
|
*/
|
|
56
60
|
|
|
57
61
|
/** Represents an existing block in a CMA request */
|
|
58
|
-
export type
|
|
59
|
-
D extends ItemDefinition = ItemDefinition,
|
|
60
|
-
> = RawApiTypes.Item<D>['id'];
|
|
62
|
+
export type UnchangedBlockInRequest = RawApiTypes.ItemIdentity;
|
|
61
63
|
|
|
62
64
|
/** Represents a block we want to update in a CMA request */
|
|
63
|
-
export type
|
|
64
|
-
D extends
|
|
65
|
+
export type UpdatedBlockInRequest<
|
|
66
|
+
D extends ItemTypeDefinition = ItemTypeDefinition,
|
|
67
|
+
> = {
|
|
68
|
+
__itemTypeId?: D['itemTypeId'];
|
|
69
|
+
type: RawApiTypes.ItemType1;
|
|
70
|
+
id: RawApiTypes.ItemIdentity;
|
|
71
|
+
relationships?: RawApiTypes.ItemRelationships<D>;
|
|
72
|
+
meta?: RawApiTypes.ItemMeta;
|
|
73
|
+
attributes: ToItemAttributesInRequest<D>;
|
|
74
|
+
};
|
|
65
75
|
|
|
66
76
|
/** Represents a new block to create in a CMA request */
|
|
67
|
-
export type
|
|
68
|
-
D extends
|
|
77
|
+
export type NewBlockInRequest<
|
|
78
|
+
D extends ItemTypeDefinition = ItemTypeDefinition,
|
|
79
|
+
> = {
|
|
80
|
+
__itemTypeId?: D['itemTypeId'];
|
|
81
|
+
type: RawApiTypes.ItemType1;
|
|
82
|
+
id?: RawApiTypes.ItemIdentity;
|
|
83
|
+
relationships: RawApiTypes.ItemRelationships<D>;
|
|
84
|
+
meta?: RawApiTypes.ItemMeta;
|
|
85
|
+
attributes: ToItemAttributesInRequest<D>;
|
|
86
|
+
};
|
|
69
87
|
|
|
70
88
|
/**
|
|
71
89
|
* Union type representing the different ways a block can be specified in API requests:
|
|
@@ -75,10 +93,14 @@ export type NewBlockInARequest<D extends ItemDefinition = ItemDefinition> =
|
|
|
75
93
|
*
|
|
76
94
|
* Also, 'meta' can always be omitted
|
|
77
95
|
*/
|
|
78
|
-
export type
|
|
79
|
-
|
|
|
80
|
-
|
|
|
81
|
-
|
|
|
96
|
+
export type BlockInRequest<D extends ItemTypeDefinition = ItemTypeDefinition> =
|
|
97
|
+
| UnchangedBlockInRequest
|
|
98
|
+
| UpdatedBlockInRequest<D>
|
|
99
|
+
| NewBlockInRequest<D>;
|
|
100
|
+
|
|
101
|
+
export type BlockInNestedResponse<
|
|
102
|
+
D extends ItemTypeDefinition = ItemTypeDefinition,
|
|
103
|
+
> = D extends unknown ? RawApiTypes.ItemInNestedResponse<D> : never;
|
|
82
104
|
|
|
83
105
|
/**
|
|
84
106
|
* Single Block field value for API requests - allows flexible block representations:
|
|
@@ -86,9 +108,9 @@ export type BlockItemInARequest<D extends ItemDefinition = ItemDefinition> =
|
|
|
86
108
|
* - Full block object with ID (to update an existing block)
|
|
87
109
|
* - Block object without ID (to create a new block)
|
|
88
110
|
*/
|
|
89
|
-
export type
|
|
90
|
-
D extends
|
|
91
|
-
> =
|
|
111
|
+
export type SingleBlockFieldValueInRequest<
|
|
112
|
+
D extends ItemTypeDefinition = ItemTypeDefinition,
|
|
113
|
+
> = BlockInRequest<D> | null;
|
|
92
114
|
|
|
93
115
|
/**
|
|
94
116
|
* =============================================================================
|
|
@@ -103,9 +125,9 @@ export type SingleBlockFieldValueAsRequest<
|
|
|
103
125
|
/**
|
|
104
126
|
* Single Block field value with nested block - fully populated block object
|
|
105
127
|
*/
|
|
106
|
-
export type
|
|
107
|
-
D extends
|
|
108
|
-
> =
|
|
128
|
+
export type SingleBlockFieldValueInNestedResponse<
|
|
129
|
+
D extends ItemTypeDefinition = ItemTypeDefinition,
|
|
130
|
+
> = BlockInNestedResponse<D> | null;
|
|
109
131
|
|
|
110
132
|
/**
|
|
111
133
|
* =============================================================================
|
|
@@ -122,14 +144,14 @@ export function isItemId(input: unknown): input is string {
|
|
|
122
144
|
}
|
|
123
145
|
|
|
124
146
|
export type ItemWithOptionalIdAndMeta<
|
|
125
|
-
D extends
|
|
147
|
+
D extends ItemTypeDefinition = ItemTypeDefinition,
|
|
126
148
|
> = D extends any ? OptionalFields<RawApiTypes.Item<D>, 'id' | 'meta'> : never;
|
|
127
149
|
|
|
128
150
|
/**
|
|
129
151
|
* Validates if the input is a RawApiTypes.Item object (with optional `id` and `meta`)
|
|
130
152
|
*/
|
|
131
153
|
export function isItemWithOptionalIdAndMeta<
|
|
132
|
-
D extends
|
|
154
|
+
D extends ItemTypeDefinition = ItemTypeDefinition,
|
|
133
155
|
>(block: unknown): block is ItemWithOptionalIdAndMeta<D> {
|
|
134
156
|
return (
|
|
135
157
|
typeof block === 'object' &&
|
|
@@ -141,14 +163,15 @@ export function isItemWithOptionalIdAndMeta<
|
|
|
141
163
|
);
|
|
142
164
|
}
|
|
143
165
|
|
|
144
|
-
export type ItemWithOptionalMeta<
|
|
145
|
-
D extends
|
|
166
|
+
export type ItemWithOptionalMeta<
|
|
167
|
+
D extends ItemTypeDefinition = ItemTypeDefinition,
|
|
168
|
+
> = D extends any ? OptionalFields<RawApiTypes.Item<D>, 'meta'> : never;
|
|
146
169
|
|
|
147
170
|
/**
|
|
148
171
|
* Validates if the input is a a complete RawApiTypes.Item object with optional `meta`
|
|
149
172
|
*/
|
|
150
173
|
export function isItemWithOptionalMeta<
|
|
151
|
-
D extends
|
|
174
|
+
D extends ItemTypeDefinition = ItemTypeDefinition,
|
|
152
175
|
>(block: unknown): block is ItemWithOptionalMeta<D> {
|
|
153
176
|
return (
|
|
154
177
|
isItemWithOptionalIdAndMeta(block) &&
|
|
@@ -170,7 +193,7 @@ export function isItemWithOptionalMeta<
|
|
|
170
193
|
export function isSingleBlockFieldValue(
|
|
171
194
|
value: unknown,
|
|
172
195
|
): value is SingleBlockFieldValue {
|
|
173
|
-
return typeof value === 'string' || value === null;
|
|
196
|
+
return (typeof value === 'string' && isValidId(value)) || value === null;
|
|
174
197
|
}
|
|
175
198
|
|
|
176
199
|
export function isLocalizedSingleBlockFieldValue(
|
|
@@ -186,9 +209,9 @@ export function isLocalizedSingleBlockFieldValue(
|
|
|
186
209
|
* Type guard for Single Block field values in API request format.
|
|
187
210
|
* Allows block as string ID, full object with ID, or object without ID.
|
|
188
211
|
*/
|
|
189
|
-
export function
|
|
190
|
-
D extends
|
|
191
|
-
>(value: unknown): value is
|
|
212
|
+
export function isSingleBlockFieldValueInRequest<
|
|
213
|
+
D extends ItemTypeDefinition = ItemTypeDefinition,
|
|
214
|
+
>(value: unknown): value is SingleBlockFieldValueInRequest<D> {
|
|
192
215
|
if (value === null) return true;
|
|
193
216
|
|
|
194
217
|
// String ID - referencing existing block
|
|
@@ -198,14 +221,14 @@ export function isSingleBlockFieldValueAsRequest<
|
|
|
198
221
|
return isItemWithOptionalIdAndMeta(value);
|
|
199
222
|
}
|
|
200
223
|
|
|
201
|
-
export function
|
|
202
|
-
D extends
|
|
224
|
+
export function isLocalizedSingleBlockFieldValueInRequest<
|
|
225
|
+
D extends ItemTypeDefinition = ItemTypeDefinition,
|
|
203
226
|
>(
|
|
204
227
|
value: unknown,
|
|
205
|
-
): value is LocalizedFieldValue<
|
|
228
|
+
): value is LocalizedFieldValue<SingleBlockFieldValueInRequest<D>> {
|
|
206
229
|
return (
|
|
207
230
|
isLocalizedFieldValue(value) &&
|
|
208
|
-
Object.values(value).every(
|
|
231
|
+
Object.values(value).every(isSingleBlockFieldValueInRequest)
|
|
209
232
|
);
|
|
210
233
|
}
|
|
211
234
|
|
|
@@ -213,23 +236,23 @@ export function isLocalizedSingleBlockFieldValueAsRequest<
|
|
|
213
236
|
* Type guard for Single Block field values with nested blocks (?nested=true format).
|
|
214
237
|
* Ensures block is a full RawApiTypes.Item object with complete data.
|
|
215
238
|
*/
|
|
216
|
-
export function
|
|
217
|
-
D extends
|
|
218
|
-
>(value: unknown): value is
|
|
239
|
+
export function isSingleBlockFieldValueInNestedResponse<
|
|
240
|
+
D extends ItemTypeDefinition = ItemTypeDefinition,
|
|
241
|
+
>(value: unknown): value is SingleBlockFieldValueInNestedResponse<D> {
|
|
219
242
|
if (value === null) return true;
|
|
220
243
|
|
|
221
244
|
// Must be a full object with ID (nested format always includes complete block objects)
|
|
222
245
|
return isItemWithOptionalMeta(value);
|
|
223
246
|
}
|
|
224
247
|
|
|
225
|
-
export function
|
|
226
|
-
D extends
|
|
248
|
+
export function isLocalizedSingleBlockFieldValueInNestedResponse<
|
|
249
|
+
D extends ItemTypeDefinition = ItemTypeDefinition,
|
|
227
250
|
>(
|
|
228
251
|
value: unknown,
|
|
229
|
-
): value is LocalizedFieldValue<
|
|
252
|
+
): value is LocalizedFieldValue<SingleBlockFieldValueInNestedResponse<D>> {
|
|
230
253
|
return (
|
|
231
254
|
isLocalizedFieldValue(value) &&
|
|
232
|
-
Object.values(value).every(
|
|
255
|
+
Object.values(value).every(isSingleBlockFieldValueInNestedResponse)
|
|
233
256
|
);
|
|
234
257
|
}
|
|
235
258
|
|
|
@@ -8,15 +8,16 @@ import {
|
|
|
8
8
|
isDocument,
|
|
9
9
|
isInlineBlock,
|
|
10
10
|
} from 'datocms-structured-text-utils';
|
|
11
|
-
import
|
|
12
|
-
import type {
|
|
11
|
+
import { isValidId } from '../utilities/id';
|
|
12
|
+
import type { ItemTypeDefinition } from '../utilities/itemDefinition';
|
|
13
13
|
import {
|
|
14
14
|
type LocalizedFieldValue,
|
|
15
15
|
isLocalizedFieldValue,
|
|
16
16
|
} from '../utilities/normalizedFieldValues';
|
|
17
17
|
import type { StructuredTextEditorConfiguration } from './appearance/structured_text';
|
|
18
18
|
import {
|
|
19
|
-
type
|
|
19
|
+
type BlockInNestedResponse,
|
|
20
|
+
type BlockInRequest,
|
|
20
21
|
isItemId,
|
|
21
22
|
isItemWithOptionalIdAndMeta,
|
|
22
23
|
isItemWithOptionalMeta,
|
|
@@ -60,25 +61,26 @@ import type { StructuredTextLinksValidator } from './validators/structured_text_
|
|
|
60
61
|
/**
|
|
61
62
|
* Variant of 'block' structured text node for API requests
|
|
62
63
|
*/
|
|
63
|
-
export type
|
|
64
|
-
|
|
65
|
-
|
|
64
|
+
export type BlockNodeInRequest<
|
|
65
|
+
D extends ItemTypeDefinition = ItemTypeDefinition,
|
|
66
|
+
> = Block<BlockInRequest<D>>;
|
|
66
67
|
|
|
67
68
|
/**
|
|
68
69
|
* Variant of 'inlineBlock' structured text node for API requests
|
|
69
70
|
*/
|
|
70
|
-
export type
|
|
71
|
-
|
|
71
|
+
export type InlineBlockNodeInRequest<
|
|
72
|
+
D extends ItemTypeDefinition = ItemTypeDefinition,
|
|
73
|
+
> = InlineBlock<BlockInRequest<D>>;
|
|
72
74
|
|
|
73
75
|
/**
|
|
74
76
|
* Variant of Structured Text document for API requests
|
|
75
77
|
*/
|
|
76
|
-
export type
|
|
77
|
-
|
|
78
|
-
|
|
78
|
+
export type DocumentInRequest<
|
|
79
|
+
BlockItemTypeDefinition extends ItemTypeDefinition = ItemTypeDefinition,
|
|
80
|
+
InlineBlockItemTypeDefinition extends ItemTypeDefinition = ItemTypeDefinition,
|
|
79
81
|
> = Document<
|
|
80
|
-
|
|
81
|
-
|
|
82
|
+
BlockInRequest<BlockItemTypeDefinition>,
|
|
83
|
+
BlockInRequest<InlineBlockItemTypeDefinition>
|
|
82
84
|
>;
|
|
83
85
|
|
|
84
86
|
/**
|
|
@@ -94,25 +96,26 @@ export type DocumentAsRequest<
|
|
|
94
96
|
/**
|
|
95
97
|
* Variant of 'block' structured text node for ?nested=true API responses
|
|
96
98
|
*/
|
|
97
|
-
export type
|
|
98
|
-
|
|
99
|
+
export type BlockNodeInNestedResponse<
|
|
100
|
+
D extends ItemTypeDefinition = ItemTypeDefinition,
|
|
101
|
+
> = Block<BlockInNestedResponse<D>>;
|
|
99
102
|
|
|
100
103
|
/**
|
|
101
104
|
* Variant of 'inlineBlock' structured text node for ?nested=true API responses
|
|
102
105
|
*/
|
|
103
|
-
export type
|
|
104
|
-
D extends
|
|
105
|
-
> = InlineBlock<
|
|
106
|
+
export type InlineBlockNodeInNestedResponse<
|
|
107
|
+
D extends ItemTypeDefinition = ItemTypeDefinition,
|
|
108
|
+
> = InlineBlock<BlockInNestedResponse<D>>;
|
|
106
109
|
|
|
107
110
|
/**
|
|
108
111
|
* Variant of Structured Text document for ?nested=true API responses
|
|
109
112
|
*/
|
|
110
|
-
export type
|
|
111
|
-
|
|
112
|
-
|
|
113
|
+
export type DocumentInNestedResponse<
|
|
114
|
+
BlockItemTypeDefinition extends ItemTypeDefinition = ItemTypeDefinition,
|
|
115
|
+
InlineBlockItemTypeDefinition extends ItemTypeDefinition = ItemTypeDefinition,
|
|
113
116
|
> = Document<
|
|
114
|
-
|
|
115
|
-
|
|
117
|
+
BlockInNestedResponse<BlockItemTypeDefinition>,
|
|
118
|
+
BlockInNestedResponse<InlineBlockItemTypeDefinition>
|
|
116
119
|
>;
|
|
117
120
|
|
|
118
121
|
/**
|
|
@@ -126,16 +129,19 @@ export type DocumentWithNestedBlocks<
|
|
|
126
129
|
* Can be null (empty field) or a document with blocks as string IDs
|
|
127
130
|
*/
|
|
128
131
|
export type StructuredTextFieldValue = Document | null;
|
|
129
|
-
export type
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
> =
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
132
|
+
export type StructuredTextFieldValueInRequest<
|
|
133
|
+
BlockItemTypeDefinition extends ItemTypeDefinition = ItemTypeDefinition,
|
|
134
|
+
InlineBlockItemTypeDefinition extends ItemTypeDefinition = ItemTypeDefinition,
|
|
135
|
+
> = DocumentInRequest<
|
|
136
|
+
BlockItemTypeDefinition,
|
|
137
|
+
InlineBlockItemTypeDefinition
|
|
138
|
+
> | null;
|
|
139
|
+
export type StructuredTextFieldValueInNestedResponse<
|
|
140
|
+
BlockItemTypeDefinition extends ItemTypeDefinition = ItemTypeDefinition,
|
|
141
|
+
InlineBlockItemTypeDefinition extends ItemTypeDefinition = ItemTypeDefinition,
|
|
142
|
+
> = DocumentInNestedResponse<
|
|
143
|
+
BlockItemTypeDefinition,
|
|
144
|
+
InlineBlockItemTypeDefinition
|
|
139
145
|
> | null;
|
|
140
146
|
|
|
141
147
|
/**
|
|
@@ -171,7 +177,7 @@ export function isStructuredTextFieldValue(
|
|
|
171
177
|
|
|
172
178
|
// Check that all block/inlineBlock nodes have string item IDs
|
|
173
179
|
return validateAllBlockNodes(value.document, (node) => {
|
|
174
|
-
return typeof node.item === 'string';
|
|
180
|
+
return typeof node.item === 'string' && isValidId(node.item);
|
|
175
181
|
});
|
|
176
182
|
}
|
|
177
183
|
|
|
@@ -188,14 +194,14 @@ export function isLocalizedStructuredTextFieldValue(
|
|
|
188
194
|
* Type guard for structured text field values in API request format.
|
|
189
195
|
* Allows blocks as string IDs, full objects with IDs, or objects without IDs.
|
|
190
196
|
*/
|
|
191
|
-
export function
|
|
192
|
-
|
|
193
|
-
|
|
197
|
+
export function isStructuredTextFieldValueInRequest<
|
|
198
|
+
BlockItemTypeDefinition extends ItemTypeDefinition = ItemTypeDefinition,
|
|
199
|
+
InlineBlockItemTypeDefinition extends ItemTypeDefinition = ItemTypeDefinition,
|
|
194
200
|
>(
|
|
195
201
|
value: unknown,
|
|
196
|
-
): value is
|
|
197
|
-
|
|
198
|
-
|
|
202
|
+
): value is StructuredTextFieldValueInRequest<
|
|
203
|
+
BlockItemTypeDefinition,
|
|
204
|
+
InlineBlockItemTypeDefinition
|
|
199
205
|
> {
|
|
200
206
|
if (value === null) return true;
|
|
201
207
|
|
|
@@ -215,14 +221,14 @@ export function isStructuredTextFieldValueAsRequest<
|
|
|
215
221
|
});
|
|
216
222
|
}
|
|
217
223
|
|
|
218
|
-
export function
|
|
219
|
-
D extends
|
|
224
|
+
export function isLocalizedStructuredTextFieldValueInRequest<
|
|
225
|
+
D extends ItemTypeDefinition = ItemTypeDefinition,
|
|
220
226
|
>(
|
|
221
227
|
value: unknown,
|
|
222
|
-
): value is LocalizedFieldValue<
|
|
228
|
+
): value is LocalizedFieldValue<StructuredTextFieldValueInRequest<D>> {
|
|
223
229
|
return (
|
|
224
230
|
isLocalizedFieldValue(value) &&
|
|
225
|
-
Object.values(value).every(
|
|
231
|
+
Object.values(value).every(isStructuredTextFieldValueInRequest)
|
|
226
232
|
);
|
|
227
233
|
}
|
|
228
234
|
|
|
@@ -230,9 +236,9 @@ export function isLocalizedStructuredTextFieldValueAsRequest<
|
|
|
230
236
|
* Type guard for structured text field values with nested blocks (?nested=true format).
|
|
231
237
|
* Ensures all block/inlineBlock nodes have full RawApiTypes.Item objects.
|
|
232
238
|
*/
|
|
233
|
-
export function
|
|
234
|
-
D extends
|
|
235
|
-
>(value: unknown): value is
|
|
239
|
+
export function isStructuredTextFieldValueInNestedResponse<
|
|
240
|
+
D extends ItemTypeDefinition = ItemTypeDefinition,
|
|
241
|
+
>(value: unknown): value is StructuredTextFieldValueInNestedResponse<D> {
|
|
236
242
|
if (value === null) return true;
|
|
237
243
|
|
|
238
244
|
if (!isDocument<unknown>(value)) {
|
|
@@ -248,14 +254,14 @@ export function isStructuredTextFieldValueWithNestedBlocks<
|
|
|
248
254
|
});
|
|
249
255
|
}
|
|
250
256
|
|
|
251
|
-
export function
|
|
252
|
-
D extends
|
|
257
|
+
export function isLocalizedStructuredTextFieldValueInNestedResponse<
|
|
258
|
+
D extends ItemTypeDefinition = ItemTypeDefinition,
|
|
253
259
|
>(
|
|
254
260
|
value: unknown,
|
|
255
|
-
): value is LocalizedFieldValue<
|
|
261
|
+
): value is LocalizedFieldValue<StructuredTextFieldValueInNestedResponse<D>> {
|
|
256
262
|
return (
|
|
257
263
|
isLocalizedFieldValue(value) &&
|
|
258
|
-
Object.values(value).every(
|
|
264
|
+
Object.values(value).every(isStructuredTextFieldValueInNestedResponse)
|
|
259
265
|
);
|
|
260
266
|
}
|
|
261
267
|
|