@datocms/cma-client 5.1.11 → 5.1.13
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 +313 -178
- 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 +50 -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 +94 -980
- package/dist/esm/generated/Client.js +1 -1
- package/dist/esm/generated/RawApiTypes.d.ts +160 -999
- package/dist/esm/generated/resources/Field.d.ts +300 -300
- 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 +11 -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 +46 -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 +94 -980
- package/dist/types/generated/RawApiTypes.d.ts +160 -999
- package/dist/types/generated/resources/Field.d.ts +300 -300
- 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 +11 -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 +4 -4
- 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 +221 -1880
- package/src/generated/Client.ts +1 -1
- package/src/generated/RawApiTypes.ts +276 -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 +16 -56
- package/src/utilities/duplicateBlockRecord.ts +53 -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,5 @@
|
|
|
1
1
|
import type * as RawApiTypes from '../generated/RawApiTypes';
|
|
2
|
-
import type {
|
|
2
|
+
import type { ItemTypeDefinition, ToItemAttributesInRequest } from '../utilities/itemDefinition';
|
|
3
3
|
import { type LocalizedFieldValue } from '../utilities/normalizedFieldValues';
|
|
4
4
|
import type { FramedSingleBlockEditorConfiguration } from './appearance/framed_single_block';
|
|
5
5
|
import type { FramelessSingleBlockEditorConfiguration } from './appearance/frameless_single_block';
|
|
@@ -46,11 +46,25 @@ export type SingleBlockFieldValue = string | null;
|
|
|
46
46
|
* - Omit ID for new blocks being created
|
|
47
47
|
*/
|
|
48
48
|
/** Represents an existing block in a CMA request */
|
|
49
|
-
export type
|
|
49
|
+
export type UnchangedBlockInRequest = RawApiTypes.ItemIdentity;
|
|
50
50
|
/** Represents a block we want to update in a CMA request */
|
|
51
|
-
export type
|
|
51
|
+
export type UpdatedBlockInRequest<D extends ItemTypeDefinition = ItemTypeDefinition> = {
|
|
52
|
+
__itemTypeId?: D['itemTypeId'];
|
|
53
|
+
type: RawApiTypes.ItemType1;
|
|
54
|
+
id: RawApiTypes.ItemIdentity;
|
|
55
|
+
relationships: RawApiTypes.ItemRelationships<D>;
|
|
56
|
+
meta?: RawApiTypes.ItemMeta;
|
|
57
|
+
attributes: ToItemAttributesInRequest<D>;
|
|
58
|
+
};
|
|
52
59
|
/** Represents a new block to create in a CMA request */
|
|
53
|
-
export type
|
|
60
|
+
export type NewBlockInRequest<D extends ItemTypeDefinition = ItemTypeDefinition> = {
|
|
61
|
+
__itemTypeId?: D['itemTypeId'];
|
|
62
|
+
type: RawApiTypes.ItemType1;
|
|
63
|
+
id?: RawApiTypes.ItemIdentity;
|
|
64
|
+
relationships: RawApiTypes.ItemRelationships<D>;
|
|
65
|
+
meta?: RawApiTypes.ItemMeta;
|
|
66
|
+
attributes: ToItemAttributesInRequest<D>;
|
|
67
|
+
};
|
|
54
68
|
/**
|
|
55
69
|
* Union type representing the different ways a block can be specified in API requests:
|
|
56
70
|
* - string: Just the block ID (to keep existing blocks unchanged)
|
|
@@ -59,14 +73,15 @@ export type NewBlockInARequest<D extends ItemDefinition = ItemDefinition> = D ex
|
|
|
59
73
|
*
|
|
60
74
|
* Also, 'meta' can always be omitted
|
|
61
75
|
*/
|
|
62
|
-
export type
|
|
76
|
+
export type BlockInRequest<D extends ItemTypeDefinition = ItemTypeDefinition> = UnchangedBlockInRequest | UpdatedBlockInRequest<D> | NewBlockInRequest<D>;
|
|
77
|
+
export type BlockInNestedResponse<D extends ItemTypeDefinition = ItemTypeDefinition> = D extends unknown ? RawApiTypes.ItemInNestedResponse<D> : never;
|
|
63
78
|
/**
|
|
64
79
|
* Single Block field value for API requests - allows flexible block representations:
|
|
65
80
|
* - string: Just the block ID (to keep existing blocks unchanged)
|
|
66
81
|
* - Full block object with ID (to update an existing block)
|
|
67
82
|
* - Block object without ID (to create a new block)
|
|
68
83
|
*/
|
|
69
|
-
export type
|
|
84
|
+
export type SingleBlockFieldValueInRequest<D extends ItemTypeDefinition = ItemTypeDefinition> = BlockInRequest<D> | null;
|
|
70
85
|
/**
|
|
71
86
|
* =============================================================================
|
|
72
87
|
* NESTED VARIANT - Type for API responses with ?nested=true parameter
|
|
@@ -79,7 +94,7 @@ export type SingleBlockFieldValueAsRequest<D extends ItemDefinition = ItemDefini
|
|
|
79
94
|
/**
|
|
80
95
|
* Single Block field value with nested block - fully populated block object
|
|
81
96
|
*/
|
|
82
|
-
export type
|
|
97
|
+
export type SingleBlockFieldValueInNestedResponse<D extends ItemTypeDefinition = ItemTypeDefinition> = BlockInNestedResponse<D> | null;
|
|
83
98
|
/**
|
|
84
99
|
* =============================================================================
|
|
85
100
|
* SHARED UTILITY FUNCTIONS
|
|
@@ -90,16 +105,16 @@ export type SingleBlockFieldValueWithNestedBlocks<D extends ItemDefinition = Ite
|
|
|
90
105
|
* Validates if the input is a valid item (either block or record) ID
|
|
91
106
|
*/
|
|
92
107
|
export declare function isItemId(input: unknown): input is string;
|
|
93
|
-
export type ItemWithOptionalIdAndMeta<D extends
|
|
108
|
+
export type ItemWithOptionalIdAndMeta<D extends ItemTypeDefinition = ItemTypeDefinition> = D extends any ? OptionalFields<RawApiTypes.Item<D>, 'id' | 'meta'> : never;
|
|
94
109
|
/**
|
|
95
110
|
* Validates if the input is a RawApiTypes.Item object (with optional `id` and `meta`)
|
|
96
111
|
*/
|
|
97
|
-
export declare function isItemWithOptionalIdAndMeta<D extends
|
|
98
|
-
export type ItemWithOptionalMeta<D extends
|
|
112
|
+
export declare function isItemWithOptionalIdAndMeta<D extends ItemTypeDefinition = ItemTypeDefinition>(block: unknown): block is ItemWithOptionalIdAndMeta<D>;
|
|
113
|
+
export type ItemWithOptionalMeta<D extends ItemTypeDefinition = ItemTypeDefinition> = D extends any ? OptionalFields<RawApiTypes.Item<D>, 'meta'> : never;
|
|
99
114
|
/**
|
|
100
115
|
* Validates if the input is a a complete RawApiTypes.Item object with optional `meta`
|
|
101
116
|
*/
|
|
102
|
-
export declare function isItemWithOptionalMeta<D extends
|
|
117
|
+
export declare function isItemWithOptionalMeta<D extends ItemTypeDefinition = ItemTypeDefinition>(block: unknown): block is ItemWithOptionalMeta<D>;
|
|
103
118
|
/**
|
|
104
119
|
* =============================================================================
|
|
105
120
|
* TYPE GUARDS - Runtime validation functions
|
|
@@ -115,14 +130,14 @@ export declare function isLocalizedSingleBlockFieldValue(value: unknown): value
|
|
|
115
130
|
* Type guard for Single Block field values in API request format.
|
|
116
131
|
* Allows block as string ID, full object with ID, or object without ID.
|
|
117
132
|
*/
|
|
118
|
-
export declare function
|
|
119
|
-
export declare function
|
|
133
|
+
export declare function isSingleBlockFieldValueInRequest<D extends ItemTypeDefinition = ItemTypeDefinition>(value: unknown): value is SingleBlockFieldValueInRequest<D>;
|
|
134
|
+
export declare function isLocalizedSingleBlockFieldValueInRequest<D extends ItemTypeDefinition = ItemTypeDefinition>(value: unknown): value is LocalizedFieldValue<SingleBlockFieldValueInRequest<D>>;
|
|
120
135
|
/**
|
|
121
136
|
* Type guard for Single Block field values with nested blocks (?nested=true format).
|
|
122
137
|
* Ensures block is a full RawApiTypes.Item object with complete data.
|
|
123
138
|
*/
|
|
124
|
-
export declare function
|
|
125
|
-
export declare function
|
|
139
|
+
export declare function isSingleBlockFieldValueInNestedResponse<D extends ItemTypeDefinition = ItemTypeDefinition>(value: unknown): value is SingleBlockFieldValueInNestedResponse<D>;
|
|
140
|
+
export declare function isLocalizedSingleBlockFieldValueInNestedResponse<D extends ItemTypeDefinition = ItemTypeDefinition>(value: unknown): value is LocalizedFieldValue<SingleBlockFieldValueInNestedResponse<D>>;
|
|
126
141
|
export type SingleBlockFieldValidators = {
|
|
127
142
|
/** Only accept references to block records of the specified block models */
|
|
128
143
|
single_block_blocks: SingleBlockBlocksValidator;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isValidId } from '../utilities/id';
|
|
1
2
|
import { isLocalizedFieldValue, } from '../utilities/normalizedFieldValues';
|
|
2
3
|
/**
|
|
3
4
|
* =============================================================================
|
|
@@ -40,7 +41,7 @@ export function isItemWithOptionalMeta(block) {
|
|
|
40
41
|
* Checks for string structure and ensures block is a string reference.
|
|
41
42
|
*/
|
|
42
43
|
export function isSingleBlockFieldValue(value) {
|
|
43
|
-
return typeof value === 'string' || value === null;
|
|
44
|
+
return (typeof value === 'string' && isValidId(value)) || value === null;
|
|
44
45
|
}
|
|
45
46
|
export function isLocalizedSingleBlockFieldValue(value) {
|
|
46
47
|
return (isLocalizedFieldValue(value) &&
|
|
@@ -50,7 +51,7 @@ export function isLocalizedSingleBlockFieldValue(value) {
|
|
|
50
51
|
* Type guard for Single Block field values in API request format.
|
|
51
52
|
* Allows block as string ID, full object with ID, or object without ID.
|
|
52
53
|
*/
|
|
53
|
-
export function
|
|
54
|
+
export function isSingleBlockFieldValueInRequest(value) {
|
|
54
55
|
if (value === null)
|
|
55
56
|
return true;
|
|
56
57
|
// String ID - referencing existing block
|
|
@@ -59,22 +60,22 @@ export function isSingleBlockFieldValueAsRequest(value) {
|
|
|
59
60
|
// Object (either with or without ID for updates/creation)
|
|
60
61
|
return isItemWithOptionalIdAndMeta(value);
|
|
61
62
|
}
|
|
62
|
-
export function
|
|
63
|
+
export function isLocalizedSingleBlockFieldValueInRequest(value) {
|
|
63
64
|
return (isLocalizedFieldValue(value) &&
|
|
64
|
-
Object.values(value).every(
|
|
65
|
+
Object.values(value).every(isSingleBlockFieldValueInRequest));
|
|
65
66
|
}
|
|
66
67
|
/**
|
|
67
68
|
* Type guard for Single Block field values with nested blocks (?nested=true format).
|
|
68
69
|
* Ensures block is a full RawApiTypes.Item object with complete data.
|
|
69
70
|
*/
|
|
70
|
-
export function
|
|
71
|
+
export function isSingleBlockFieldValueInNestedResponse(value) {
|
|
71
72
|
if (value === null)
|
|
72
73
|
return true;
|
|
73
74
|
// Must be a full object with ID (nested format always includes complete block objects)
|
|
74
75
|
return isItemWithOptionalMeta(value);
|
|
75
76
|
}
|
|
76
|
-
export function
|
|
77
|
+
export function isLocalizedSingleBlockFieldValueInNestedResponse(value) {
|
|
77
78
|
return (isLocalizedFieldValue(value) &&
|
|
78
|
-
Object.values(value).every(
|
|
79
|
+
Object.values(value).every(isSingleBlockFieldValueInNestedResponse));
|
|
79
80
|
}
|
|
80
81
|
//# sourceMappingURL=single_block.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"single_block.js","sourceRoot":"","sources":["../../../src/fieldTypes/single_block.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"single_block.js","sourceRoot":"","sources":["../../../src/fieldTypes/single_block.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAK5C,OAAO,EAEL,qBAAqB,GACtB,MAAM,oCAAoC,CAAC;AA0H5C;;;;;GAKG;AAEH;;GAEG;AACH,MAAM,UAAU,QAAQ,CAAC,KAAc;IACrC,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC;AACnC,CAAC;AAMD;;GAEG;AACH,MAAM,UAAU,2BAA2B,CAEzC,KAAc;IACd,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,MAAM,IAAI,KAAK;QACf,KAAK,CAAC,IAAI,KAAK,MAAM;QACrB,YAAY,IAAI,KAAK;QACrB,eAAe,IAAI,KAAK,CACzB,CAAC;AACJ,CAAC;AAMD;;GAEG;AACH,MAAM,UAAU,sBAAsB,CAEpC,KAAc;IACd,OAAO,CACL,2BAA2B,CAAC,KAAK,CAAC;QAClC,IAAI,IAAI,KAAK;QACb,OAAO,KAAK,CAAC,EAAE,KAAK,QAAQ,CAC7B,CAAC;AACJ,CAAC;AAED;;;;GAIG;AAEH;;;GAGG;AACH,MAAM,UAAU,uBAAuB,CACrC,KAAc;IAEd,OAAO,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAI,SAAS,CAAC,KAAK,CAAC,CAAC,IAAI,KAAK,KAAK,IAAI,CAAC;AAC3E,CAAC;AAED,MAAM,UAAU,gCAAgC,CAC9C,KAAc;IAEd,OAAO,CACL,qBAAqB,CAAC,KAAK,CAAC;QAC5B,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,uBAAuB,CAAC,CACpD,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,gCAAgC,CAE9C,KAAc;IACd,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,IAAI,CAAC;IAEhC,yCAAyC;IACzC,IAAI,QAAQ,CAAC,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IAEjC,0DAA0D;IAC1D,OAAO,2BAA2B,CAAC,KAAK,CAAC,CAAC;AAC5C,CAAC;AAED,MAAM,UAAU,yCAAyC,CAGvD,KAAc;IAEd,OAAO,CACL,qBAAqB,CAAC,KAAK,CAAC;QAC5B,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,gCAAgC,CAAC,CAC7D,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,uCAAuC,CAErD,KAAc;IACd,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,IAAI,CAAC;IAEhC,uFAAuF;IACvF,OAAO,sBAAsB,CAAC,KAAK,CAAC,CAAC;AACvC,CAAC;AAED,MAAM,UAAU,gDAAgD,CAG9D,KAAc;IAEd,OAAO,CACL,qBAAqB,CAAC,KAAK,CAAC;QAC5B,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,uCAAuC,CAAC,CACpE,CAAC;AACJ,CAAC"}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { type Block, type Document, type InlineBlock } from 'datocms-structured-text-utils';
|
|
2
|
-
import type
|
|
3
|
-
import type { ItemDefinition } from '../utilities/itemDefinition';
|
|
2
|
+
import type { ItemTypeDefinition } from '../utilities/itemDefinition';
|
|
4
3
|
import { type LocalizedFieldValue } from '../utilities/normalizedFieldValues';
|
|
5
4
|
import type { StructuredTextEditorConfiguration } from './appearance/structured_text';
|
|
6
|
-
import { type
|
|
5
|
+
import { type BlockInNestedResponse, type BlockInRequest } from './single_block';
|
|
7
6
|
import type { LengthValidator } from './validators/length';
|
|
8
7
|
import type { StructuredTextBlocksValidator } from './validators/structured_text_blocks';
|
|
9
8
|
import type { StructuredTextInlineBlocksValidator } from './validators/structured_text_inline_blocks';
|
|
@@ -40,15 +39,15 @@ import type { StructuredTextLinksValidator } from './validators/structured_text_
|
|
|
40
39
|
/**
|
|
41
40
|
* Variant of 'block' structured text node for API requests
|
|
42
41
|
*/
|
|
43
|
-
export type
|
|
42
|
+
export type BlockNodeInRequest<D extends ItemTypeDefinition = ItemTypeDefinition> = Block<BlockInRequest<D>>;
|
|
44
43
|
/**
|
|
45
44
|
* Variant of 'inlineBlock' structured text node for API requests
|
|
46
45
|
*/
|
|
47
|
-
export type
|
|
46
|
+
export type InlineBlockNodeInRequest<D extends ItemTypeDefinition = ItemTypeDefinition> = InlineBlock<BlockInRequest<D>>;
|
|
48
47
|
/**
|
|
49
48
|
* Variant of Structured Text document for API requests
|
|
50
49
|
*/
|
|
51
|
-
export type
|
|
50
|
+
export type DocumentInRequest<BlockItemTypeDefinition extends ItemTypeDefinition = ItemTypeDefinition, InlineBlockItemTypeDefinition extends ItemTypeDefinition = ItemTypeDefinition> = Document<BlockInRequest<BlockItemTypeDefinition>, BlockInRequest<InlineBlockItemTypeDefinition>>;
|
|
52
51
|
/**
|
|
53
52
|
* =============================================================================
|
|
54
53
|
* NESTED VARIANTS - Types for API responses with ?nested=true parameter
|
|
@@ -61,15 +60,15 @@ export type DocumentAsRequest<BlockItemDefinition extends ItemDefinition = ItemD
|
|
|
61
60
|
/**
|
|
62
61
|
* Variant of 'block' structured text node for ?nested=true API responses
|
|
63
62
|
*/
|
|
64
|
-
export type
|
|
63
|
+
export type BlockNodeInNestedResponse<D extends ItemTypeDefinition = ItemTypeDefinition> = Block<BlockInNestedResponse<D>>;
|
|
65
64
|
/**
|
|
66
65
|
* Variant of 'inlineBlock' structured text node for ?nested=true API responses
|
|
67
66
|
*/
|
|
68
|
-
export type
|
|
67
|
+
export type InlineBlockNodeInNestedResponse<D extends ItemTypeDefinition = ItemTypeDefinition> = InlineBlock<BlockInNestedResponse<D>>;
|
|
69
68
|
/**
|
|
70
69
|
* Variant of Structured Text document for ?nested=true API responses
|
|
71
70
|
*/
|
|
72
|
-
export type
|
|
71
|
+
export type DocumentInNestedResponse<BlockItemTypeDefinition extends ItemTypeDefinition = ItemTypeDefinition, InlineBlockItemTypeDefinition extends ItemTypeDefinition = ItemTypeDefinition> = Document<BlockInNestedResponse<BlockItemTypeDefinition>, BlockInNestedResponse<InlineBlockItemTypeDefinition>>;
|
|
73
72
|
/**
|
|
74
73
|
* =============================================================================
|
|
75
74
|
* MAIN APPLICATION TYPES
|
|
@@ -80,8 +79,8 @@ export type DocumentWithNestedBlocks<BlockItemDefinition extends ItemDefinition
|
|
|
80
79
|
* Can be null (empty field) or a document with blocks as string IDs
|
|
81
80
|
*/
|
|
82
81
|
export type StructuredTextFieldValue = Document | null;
|
|
83
|
-
export type
|
|
84
|
-
export type
|
|
82
|
+
export type StructuredTextFieldValueInRequest<BlockItemTypeDefinition extends ItemTypeDefinition = ItemTypeDefinition, InlineBlockItemTypeDefinition extends ItemTypeDefinition = ItemTypeDefinition> = DocumentInRequest<BlockItemTypeDefinition, InlineBlockItemTypeDefinition> | null;
|
|
83
|
+
export type StructuredTextFieldValueInNestedResponse<BlockItemTypeDefinition extends ItemTypeDefinition = ItemTypeDefinition, InlineBlockItemTypeDefinition extends ItemTypeDefinition = ItemTypeDefinition> = DocumentInNestedResponse<BlockItemTypeDefinition, InlineBlockItemTypeDefinition> | null;
|
|
85
84
|
/**
|
|
86
85
|
* Type guard for basic structured text field values (blocks as string IDs only).
|
|
87
86
|
* Checks for the expected structure and ensures all block/inlineBlock nodes have string IDs.
|
|
@@ -92,14 +91,14 @@ export declare function isLocalizedStructuredTextFieldValue(value: unknown): val
|
|
|
92
91
|
* Type guard for structured text field values in API request format.
|
|
93
92
|
* Allows blocks as string IDs, full objects with IDs, or objects without IDs.
|
|
94
93
|
*/
|
|
95
|
-
export declare function
|
|
96
|
-
export declare function
|
|
94
|
+
export declare function isStructuredTextFieldValueInRequest<BlockItemTypeDefinition extends ItemTypeDefinition = ItemTypeDefinition, InlineBlockItemTypeDefinition extends ItemTypeDefinition = ItemTypeDefinition>(value: unknown): value is StructuredTextFieldValueInRequest<BlockItemTypeDefinition, InlineBlockItemTypeDefinition>;
|
|
95
|
+
export declare function isLocalizedStructuredTextFieldValueInRequest<D extends ItemTypeDefinition = ItemTypeDefinition>(value: unknown): value is LocalizedFieldValue<StructuredTextFieldValueInRequest<D>>;
|
|
97
96
|
/**
|
|
98
97
|
* Type guard for structured text field values with nested blocks (?nested=true format).
|
|
99
98
|
* Ensures all block/inlineBlock nodes have full RawApiTypes.Item objects.
|
|
100
99
|
*/
|
|
101
|
-
export declare function
|
|
102
|
-
export declare function
|
|
100
|
+
export declare function isStructuredTextFieldValueInNestedResponse<D extends ItemTypeDefinition = ItemTypeDefinition>(value: unknown): value is StructuredTextFieldValueInNestedResponse<D>;
|
|
101
|
+
export declare function isLocalizedStructuredTextFieldValueInNestedResponse<D extends ItemTypeDefinition = ItemTypeDefinition>(value: unknown): value is LocalizedFieldValue<StructuredTextFieldValueInNestedResponse<D>>;
|
|
103
102
|
export type StructuredTextFieldValidators = {
|
|
104
103
|
/** Only accept references to block records of the specified block models */
|
|
105
104
|
structured_text_blocks: StructuredTextBlocksValidator;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { everyNode, isBlock, isDocument, isInlineBlock, } from 'datocms-structured-text-utils';
|
|
2
|
+
import { isValidId } from '../utilities/id';
|
|
2
3
|
import { isLocalizedFieldValue, } from '../utilities/normalizedFieldValues';
|
|
3
4
|
import { isItemId, isItemWithOptionalIdAndMeta, isItemWithOptionalMeta, } from './single_block';
|
|
4
5
|
/**
|
|
@@ -27,7 +28,7 @@ export function isStructuredTextFieldValue(value) {
|
|
|
27
28
|
}
|
|
28
29
|
// Check that all block/inlineBlock nodes have string item IDs
|
|
29
30
|
return validateAllBlockNodes(value.document, (node) => {
|
|
30
|
-
return typeof node.item === 'string';
|
|
31
|
+
return typeof node.item === 'string' && isValidId(node.item);
|
|
31
32
|
});
|
|
32
33
|
}
|
|
33
34
|
export function isLocalizedStructuredTextFieldValue(value) {
|
|
@@ -38,7 +39,7 @@ export function isLocalizedStructuredTextFieldValue(value) {
|
|
|
38
39
|
* Type guard for structured text field values in API request format.
|
|
39
40
|
* Allows blocks as string IDs, full objects with IDs, or objects without IDs.
|
|
40
41
|
*/
|
|
41
|
-
export function
|
|
42
|
+
export function isStructuredTextFieldValueInRequest(value) {
|
|
42
43
|
if (value === null)
|
|
43
44
|
return true;
|
|
44
45
|
if (!isDocument(value)) {
|
|
@@ -54,15 +55,15 @@ export function isStructuredTextFieldValueAsRequest(value) {
|
|
|
54
55
|
return isItemWithOptionalIdAndMeta(item);
|
|
55
56
|
});
|
|
56
57
|
}
|
|
57
|
-
export function
|
|
58
|
+
export function isLocalizedStructuredTextFieldValueInRequest(value) {
|
|
58
59
|
return (isLocalizedFieldValue(value) &&
|
|
59
|
-
Object.values(value).every(
|
|
60
|
+
Object.values(value).every(isStructuredTextFieldValueInRequest));
|
|
60
61
|
}
|
|
61
62
|
/**
|
|
62
63
|
* Type guard for structured text field values with nested blocks (?nested=true format).
|
|
63
64
|
* Ensures all block/inlineBlock nodes have full RawApiTypes.Item objects.
|
|
64
65
|
*/
|
|
65
|
-
export function
|
|
66
|
+
export function isStructuredTextFieldValueInNestedResponse(value) {
|
|
66
67
|
if (value === null)
|
|
67
68
|
return true;
|
|
68
69
|
if (!isDocument(value)) {
|
|
@@ -75,8 +76,8 @@ export function isStructuredTextFieldValueWithNestedBlocks(value) {
|
|
|
75
76
|
return isItemWithOptionalMeta(item);
|
|
76
77
|
});
|
|
77
78
|
}
|
|
78
|
-
export function
|
|
79
|
+
export function isLocalizedStructuredTextFieldValueInNestedResponse(value) {
|
|
79
80
|
return (isLocalizedFieldValue(value) &&
|
|
80
|
-
Object.values(value).every(
|
|
81
|
+
Object.values(value).every(isStructuredTextFieldValueInNestedResponse));
|
|
81
82
|
}
|
|
82
83
|
//# sourceMappingURL=structured_text.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"structured_text.js","sourceRoot":"","sources":["../../../src/fieldTypes/structured_text.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,SAAS,EACT,OAAO,EACP,UAAU,EACV,aAAa,GACd,MAAM,+BAA+B,CAAC;
|
|
1
|
+
{"version":3,"file":"structured_text.js","sourceRoot":"","sources":["../../../src/fieldTypes/structured_text.ts"],"names":[],"mappings":"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"}
|