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