@datocms/cma-client 5.1.3 → 5.1.5
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/dist/cjs/fieldTypes/lat_lon.js +6 -6
- package/dist/cjs/fieldTypes/lat_lon.js.map +1 -1
- package/dist/cjs/fieldTypes/rich_text.js.map +1 -1
- package/dist/cjs/fieldTypes/single_block.js.map +1 -1
- 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 +41 -23
- package/dist/cjs/generated/resources/Item.js.map +1 -1
- package/dist/cjs/generated/resources/ScheduledPublication.js +4 -2
- package/dist/cjs/generated/resources/ScheduledPublication.js.map +1 -1
- package/dist/cjs/generated/resources/ScheduledUnpublishing.js +4 -2
- package/dist/cjs/generated/resources/ScheduledUnpublishing.js.map +1 -1
- package/dist/cjs/generated/resources/Upload.js +4 -2
- 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.map +1 -1
- package/dist/cjs/utilities/itemDefinition.js +3 -0
- package/dist/cjs/utilities/itemDefinition.js.map +1 -0
- package/dist/esm/fieldTypes/gallery.d.ts +1 -1
- package/dist/esm/fieldTypes/lat_lon.d.ts +5 -5
- package/dist/esm/fieldTypes/lat_lon.js +3 -3
- package/dist/esm/fieldTypes/lat_lon.js.map +1 -1
- package/dist/esm/fieldTypes/rich_text.d.ts +8 -7
- package/dist/esm/fieldTypes/rich_text.js.map +1 -1
- package/dist/esm/fieldTypes/single_block.d.ts +15 -14
- package/dist/esm/fieldTypes/single_block.js.map +1 -1
- package/dist/esm/fieldTypes/structured_text.d.ts +13 -12
- package/dist/esm/fieldTypes/structured_text.js.map +1 -1
- package/dist/esm/generated/ApiTypes.d.ts +74 -62
- package/dist/esm/generated/Client.js +1 -1
- package/dist/esm/generated/RawApiTypes.d.ts +123 -121
- package/dist/esm/generated/resources/Field.d.ts +230 -230
- package/dist/esm/generated/resources/Item.d.ts +42 -24
- package/dist/esm/generated/resources/Item.js +41 -23
- package/dist/esm/generated/resources/Item.js.map +1 -1
- package/dist/esm/generated/resources/ItemVersion.d.ts +1 -1
- package/dist/esm/generated/resources/ScheduledPublication.d.ts +5 -2
- package/dist/esm/generated/resources/ScheduledPublication.js +4 -2
- package/dist/esm/generated/resources/ScheduledPublication.js.map +1 -1
- package/dist/esm/generated/resources/ScheduledUnpublishing.d.ts +5 -2
- package/dist/esm/generated/resources/ScheduledUnpublishing.js +4 -2
- package/dist/esm/generated/resources/ScheduledUnpublishing.js.map +1 -1
- package/dist/esm/generated/resources/Upload.d.ts +10 -2
- package/dist/esm/generated/resources/Upload.js +4 -2
- 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 +5 -31
- package/dist/esm/utilities/buildBlockRecord.js.map +1 -1
- package/dist/esm/utilities/itemDefinition.d.ts +74 -0
- package/dist/esm/utilities/itemDefinition.js +2 -0
- package/dist/esm/utilities/itemDefinition.js.map +1 -0
- package/dist/types/fieldTypes/gallery.d.ts +1 -1
- package/dist/types/fieldTypes/lat_lon.d.ts +5 -5
- package/dist/types/fieldTypes/rich_text.d.ts +8 -7
- package/dist/types/fieldTypes/single_block.d.ts +15 -14
- package/dist/types/fieldTypes/structured_text.d.ts +13 -12
- package/dist/types/generated/ApiTypes.d.ts +74 -62
- package/dist/types/generated/RawApiTypes.d.ts +123 -121
- package/dist/types/generated/resources/Field.d.ts +230 -230
- package/dist/types/generated/resources/Item.d.ts +42 -24
- package/dist/types/generated/resources/ItemVersion.d.ts +1 -1
- package/dist/types/generated/resources/ScheduledPublication.d.ts +5 -2
- package/dist/types/generated/resources/ScheduledUnpublishing.d.ts +5 -2
- package/dist/types/generated/resources/Upload.d.ts +10 -2
- package/dist/types/index.d.ts +1 -0
- package/dist/types/utilities/buildBlockRecord.d.ts +5 -31
- package/dist/types/utilities/itemDefinition.d.ts +74 -0
- package/package.json +5 -5
- package/resources.json +564 -0
- package/src/fieldTypes/gallery.ts +1 -1
- package/src/fieldTypes/lat_lon.ts +7 -9
- package/src/fieldTypes/rich_text.ts +22 -13
- package/src/fieldTypes/single_block.ts +42 -32
- package/src/fieldTypes/structured_text.ts +60 -23
- package/src/generated/ApiTypes.ts +123 -70
- package/src/generated/Client.ts +1 -1
- package/src/generated/RawApiTypes.ts +174 -138
- package/src/generated/resources/Item.ts +360 -108
- package/src/generated/resources/ScheduledPublication.ts +31 -11
- package/src/generated/resources/ScheduledUnpublishing.ts +31 -11
- package/src/generated/resources/Upload.ts +54 -12
- package/src/index.ts +1 -0
- package/src/utilities/buildBlockRecord.ts +19 -3
- package/src/utilities/itemDefinition.ts +229 -0
package/dist/esm/index.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ export * from './utilities/fieldValue';
|
|
|
10
10
|
export * from './utilities/id';
|
|
11
11
|
export * from './utilities/recursiveBlocks';
|
|
12
12
|
export * from './utilities/schemaRepository';
|
|
13
|
+
export * from './utilities/itemDefinition';
|
|
13
14
|
export * from './fieldTypes';
|
|
14
15
|
export type { ApiTypes, RawApiTypes };
|
|
15
16
|
export type { ApiTypes as SchemaTypes, RawApiTypes as SimpleSchemaTypes };
|
package/dist/esm/index.js
CHANGED
|
@@ -9,5 +9,6 @@ export * from './utilities/fieldValue';
|
|
|
9
9
|
export * from './utilities/id';
|
|
10
10
|
export * from './utilities/recursiveBlocks';
|
|
11
11
|
export * from './utilities/schemaRepository';
|
|
12
|
+
export * from './utilities/itemDefinition';
|
|
12
13
|
export * from './fieldTypes';
|
|
13
14
|
//# sourceMappingURL=index.js.map
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC9E,cAAc,eAAe,CAAC;AAC9B,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAE5C,OAAO,KAAK,SAAS,MAAM,uBAAuB,CAAC;AACnD,cAAc,oBAAoB,CAAC;AACnC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,wCAAwC,CAAC;AACvD,cAAc,wBAAwB,CAAC;AACvC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,6BAA6B,CAAC;AAC5C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,cAAc,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC9E,cAAc,eAAe,CAAC;AAC9B,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAE5C,OAAO,KAAK,SAAS,MAAM,uBAAuB,CAAC;AACnD,cAAc,oBAAoB,CAAC;AACnC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,wCAAwC,CAAC;AACvD,cAAc,wBAAwB,CAAC;AACvC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,6BAA6B,CAAC;AAC5C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,cAAc,CAAC"}
|
|
@@ -1,32 +1,6 @@
|
|
|
1
|
+
import type { NewBlockInARequest } from '../fieldTypes';
|
|
1
2
|
import type * as ApiTypes from '../generated/ApiTypes';
|
|
2
|
-
import type
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
attributes?: {
|
|
7
|
-
[k: string]: unknown;
|
|
8
|
-
} | undefined;
|
|
9
|
-
meta?: {
|
|
10
|
-
created_at?: string | undefined;
|
|
11
|
-
updated_at?: string | undefined;
|
|
12
|
-
published_at?: string | null | undefined;
|
|
13
|
-
first_published_at?: string | null | undefined;
|
|
14
|
-
publication_scheduled_at?: string | null | undefined;
|
|
15
|
-
unpublishing_scheduled_at?: string | null | undefined;
|
|
16
|
-
status?: "published" | "draft" | "updated" | null | undefined;
|
|
17
|
-
is_valid?: boolean | undefined;
|
|
18
|
-
current_version?: string | undefined;
|
|
19
|
-
is_current_version_valid?: boolean | null | undefined;
|
|
20
|
-
is_published_version_valid?: boolean | null | undefined;
|
|
21
|
-
stage?: string | null | undefined;
|
|
22
|
-
has_children?: boolean | null | undefined;
|
|
23
|
-
} | undefined;
|
|
24
|
-
relationships?: {
|
|
25
|
-
item_type?: {
|
|
26
|
-
data: RawApiTypes.ItemTypeData;
|
|
27
|
-
} | undefined;
|
|
28
|
-
creator?: {
|
|
29
|
-
data: RawApiTypes.UserData | RawApiTypes.SsoUserData | RawApiTypes.AccessTokenData | RawApiTypes.AccountData | RawApiTypes.OrganizationData;
|
|
30
|
-
} | undefined;
|
|
31
|
-
} | undefined;
|
|
32
|
-
};
|
|
3
|
+
import type { ItemTypeDefinition, ItemTypeDefinitionToItemDefinitionAsRequest } from './itemDefinition';
|
|
4
|
+
type NoInfer<T> = [T][T extends any ? 0 : never];
|
|
5
|
+
export declare function buildBlockRecord<D extends ItemTypeDefinition = ItemTypeDefinition>(body: ApiTypes.ItemUpdateSchema<ItemTypeDefinitionToItemDefinitionAsRequest<NoInfer<D>>>): NewBlockInARequest<ItemTypeDefinitionToItemDefinitionAsRequest<NoInfer<D>>>;
|
|
6
|
+
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildBlockRecord.js","sourceRoot":"","sources":["../../../src/utilities/buildBlockRecord.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,4BAA4B,CAAC;AAGpD,OAAO,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"buildBlockRecord.js","sourceRoot":"","sources":["../../../src/utilities/buildBlockRecord.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,4BAA4B,CAAC;AAGpD,OAAO,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC;AAQ9C,MAAM,UAAU,gBAAgB,CAG9B,IAEC;IAED,OAAO,KAAK,CAAC,oBAAoB,CAI9B,IAAI,EAAE;QACP,IAAI,EAAE,IAAI,CAAC,IAAI;QACf,UAAU,EAAE,GAAG;QACf,aAAa,EAAE,CAAC,WAAW,CAAC;KAC7B,CAAC,CAAC,IAAI,CAAC;AACV,CAAC"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { BooleanFieldValue, ColorFieldValue, DateFieldValue, DateTimeFieldValue, FileFieldValue, FloatFieldValue, GalleryFieldValue, IntegerFieldValue, JsonFieldValue, LatLonFieldValue, LinkFieldValue, LinksFieldValue, RichTextFieldValue, RichTextFieldValueAsRequest, RichTextFieldValueWithNestedBlocks, SeoFieldValue, SingleBlockFieldValue, SingleBlockFieldValueAsRequest, SingleBlockFieldValueWithNestedBlocks, SlugFieldValue, StringFieldValue, StructuredTextFieldValue, StructuredTextFieldValueAsRequest, StructuredTextFieldValueWithNestedBlocks, TextFieldValue, VideoFieldValue } from '../fieldTypes';
|
|
2
|
+
import type { LocalizedFieldValue } from './fieldValue';
|
|
3
|
+
/** Base field definition */
|
|
4
|
+
type BaseFieldDefinition<Type extends string> = {
|
|
5
|
+
type: Type;
|
|
6
|
+
localized?: boolean;
|
|
7
|
+
};
|
|
8
|
+
type RichTextFieldDefinition<AllowedBlocks extends ItemTypeDefinition = ItemTypeDefinition> = BaseFieldDefinition<'rich_text'> & {
|
|
9
|
+
blocks: AllowedBlocks;
|
|
10
|
+
};
|
|
11
|
+
type SingleBlockFieldDefinition<AllowedBlocks extends ItemTypeDefinition = ItemTypeDefinition> = BaseFieldDefinition<'single_block'> & {
|
|
12
|
+
blocks: AllowedBlocks;
|
|
13
|
+
};
|
|
14
|
+
type StructuredTextFieldDefinition<AllowedBlocks extends ItemTypeDefinition = ItemTypeDefinition, AllowedInlineBlocks extends ItemTypeDefinition = ItemTypeDefinition> = BaseFieldDefinition<'structured_text'> & {
|
|
15
|
+
blocks: AllowedBlocks;
|
|
16
|
+
inline_blocks: AllowedInlineBlocks;
|
|
17
|
+
};
|
|
18
|
+
/** Field definition union */
|
|
19
|
+
export type FieldDefinition = BaseFieldDefinition<'boolean' | 'color' | 'date' | 'date_time' | 'file' | 'float' | 'gallery' | 'integer' | 'json' | 'lat_lon' | 'link' | 'links' | 'seo' | 'slug' | 'string' | 'text' | 'video' | 'unknown'> | RichTextFieldDefinition | SingleBlockFieldDefinition | StructuredTextFieldDefinition;
|
|
20
|
+
/** Item type definition */
|
|
21
|
+
export type ItemTypeDefinition<ItemTypeId extends string = string, FieldDefinitions extends Record<string, FieldDefinition> = {}> = {
|
|
22
|
+
itemTypeId: ItemTypeId;
|
|
23
|
+
fields: FieldDefinitions;
|
|
24
|
+
};
|
|
25
|
+
/** Item definition */
|
|
26
|
+
export type ItemDefinition<ItemTypeId extends string = string, FieldValues extends Record<string, unknown> = Record<string, unknown>> = {
|
|
27
|
+
itemTypeId: ItemTypeId;
|
|
28
|
+
fields: FieldValues;
|
|
29
|
+
};
|
|
30
|
+
/** Standard field values */
|
|
31
|
+
type FieldTypeToValue = {
|
|
32
|
+
boolean: BooleanFieldValue;
|
|
33
|
+
color: ColorFieldValue;
|
|
34
|
+
date: DateFieldValue;
|
|
35
|
+
date_time: DateTimeFieldValue;
|
|
36
|
+
file: FileFieldValue;
|
|
37
|
+
float: FloatFieldValue;
|
|
38
|
+
gallery: GalleryFieldValue;
|
|
39
|
+
integer: IntegerFieldValue;
|
|
40
|
+
json: JsonFieldValue;
|
|
41
|
+
lat_lon: LatLonFieldValue;
|
|
42
|
+
link: LinkFieldValue;
|
|
43
|
+
links: LinksFieldValue;
|
|
44
|
+
rich_text: RichTextFieldValue;
|
|
45
|
+
seo: SeoFieldValue;
|
|
46
|
+
single_block: SingleBlockFieldValue;
|
|
47
|
+
slug: SlugFieldValue;
|
|
48
|
+
string: StringFieldValue;
|
|
49
|
+
structured_text: StructuredTextFieldValue;
|
|
50
|
+
text: TextFieldValue;
|
|
51
|
+
video: VideoFieldValue;
|
|
52
|
+
unknown: unknown;
|
|
53
|
+
};
|
|
54
|
+
/** Localized wrapper */
|
|
55
|
+
type LocalizeIfNeeded<T extends FieldDefinition, Value> = T extends {
|
|
56
|
+
localized: true;
|
|
57
|
+
} ? LocalizedFieldValue<Value> : Value;
|
|
58
|
+
/** Standard mapping */
|
|
59
|
+
type FieldDefinitionToFieldValue<T extends FieldDefinition> = LocalizeIfNeeded<T, FieldTypeToValue[T['type']]>;
|
|
60
|
+
/** AsRequest mapping (block fields become generic over allowed blocks) */
|
|
61
|
+
type FieldDefinitionToFieldValueAsRequest<T extends FieldDefinition> = T extends RichTextFieldDefinition<infer B> ? LocalizeIfNeeded<T, RichTextFieldValueAsRequest<ItemTypeDefinitionToItemDefinitionAsRequest<B>>> : T extends SingleBlockFieldDefinition<infer B> ? LocalizeIfNeeded<T, SingleBlockFieldValueAsRequest<ItemTypeDefinitionToItemDefinitionAsRequest<B>>> : T extends StructuredTextFieldDefinition<infer B, infer I> ? LocalizeIfNeeded<T, StructuredTextFieldValueAsRequest<ItemTypeDefinitionToItemDefinitionAsRequest<B>, ItemTypeDefinitionToItemDefinitionAsRequest<I>>> : LocalizeIfNeeded<T, FieldTypeToValue[T['type']]>;
|
|
62
|
+
type FieldDefinitionToFieldValueWithNestedBlocks<T extends FieldDefinition> = T extends RichTextFieldDefinition<infer B> ? LocalizeIfNeeded<T, RichTextFieldValueWithNestedBlocks<ItemTypeDefinitionToItemDefinitionWithNestedBlocks<B>>> : T extends SingleBlockFieldDefinition<infer B> ? LocalizeIfNeeded<T, SingleBlockFieldValueWithNestedBlocks<ItemTypeDefinitionToItemDefinitionWithNestedBlocks<B>>> : T extends StructuredTextFieldDefinition<infer B, infer I> ? LocalizeIfNeeded<T, StructuredTextFieldValueWithNestedBlocks<ItemTypeDefinitionToItemDefinitionWithNestedBlocks<B>, ItemTypeDefinitionToItemDefinitionWithNestedBlocks<I>>> : LocalizeIfNeeded<T, FieldTypeToValue[T['type']]>;
|
|
63
|
+
/** Transformers */
|
|
64
|
+
export type ItemTypeDefinitionToItemDefinition<T extends ItemTypeDefinition> = T extends ItemTypeDefinition ? keyof T['fields'] extends never ? ItemDefinition<T['itemTypeId']> : ItemDefinition<T['itemTypeId'], {
|
|
65
|
+
[K in keyof T['fields']]: T['fields'][K] extends FieldDefinition ? FieldDefinitionToFieldValue<T['fields'][K]> : never;
|
|
66
|
+
}> : never;
|
|
67
|
+
export type ItemTypeDefinitionToItemDefinitionAsRequest<T extends ItemTypeDefinition> = T extends ItemTypeDefinition ? keyof T['fields'] extends never ? ItemDefinition<T['itemTypeId']> : ItemDefinition<T['itemTypeId'], Partial<{
|
|
68
|
+
[K in keyof T['fields']]: T['fields'][K] extends FieldDefinition ? FieldDefinitionToFieldValueAsRequest<T['fields'][K]> : never;
|
|
69
|
+
}>> : never;
|
|
70
|
+
export type ItemTypeDefinitionToItemDefinitionWithNestedBlocks<T extends ItemTypeDefinition> = T extends ItemTypeDefinition ? keyof T['fields'] extends never ? ItemDefinition<T['itemTypeId']> : ItemDefinition<T['itemTypeId'], {
|
|
71
|
+
[K in keyof T['fields']]: T['fields'][K] extends FieldDefinition ? FieldDefinitionToFieldValueWithNestedBlocks<T['fields'][K]> : never;
|
|
72
|
+
}> : never;
|
|
73
|
+
export type UnknownField = Record<string, unknown>;
|
|
74
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"itemDefinition.js","sourceRoot":"","sources":["../../../src/utilities/itemDefinition.ts"],"names":[],"mappings":""}
|
|
@@ -15,7 +15,7 @@ export type GalleryFieldValue = Array<{
|
|
|
15
15
|
x: number;
|
|
16
16
|
y: number;
|
|
17
17
|
} | null;
|
|
18
|
-
}
|
|
18
|
+
}>;
|
|
19
19
|
export declare function isGalleryFieldValue(value: unknown): value is GalleryFieldValue;
|
|
20
20
|
export declare function isLocalizedGalleryFieldValue(value: unknown): value is LocalizedFieldValue<GalleryFieldValue>;
|
|
21
21
|
export type GalleryFieldValidators = {
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import type { LocalizedFieldValue } from '../utilities/fieldValue';
|
|
2
2
|
import type { MapEditorConfiguration } from './appearance/map';
|
|
3
3
|
import type { RequiredValidator } from './validators/required';
|
|
4
|
-
export type
|
|
4
|
+
export type LatLonFieldValue = {
|
|
5
5
|
latitude: number;
|
|
6
6
|
longitude: number;
|
|
7
7
|
} | null;
|
|
8
|
-
export declare function
|
|
9
|
-
export declare function
|
|
10
|
-
export type
|
|
8
|
+
export declare function isLatLonFieldValue(value: unknown): value is LatLonFieldValue;
|
|
9
|
+
export declare function isLocalizedLatLonFieldValue(value: unknown): value is LocalizedFieldValue<LatLonFieldValue>;
|
|
10
|
+
export type LatLonFieldValidators = {
|
|
11
11
|
/** Value must be specified or it won't be valid */
|
|
12
12
|
required?: RequiredValidator;
|
|
13
13
|
};
|
|
14
|
-
export type
|
|
14
|
+
export type LatLonFieldAppearance = {
|
|
15
15
|
editor: 'map';
|
|
16
16
|
parameters: MapEditorConfiguration;
|
|
17
17
|
} | {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type * as RawApiTypes from '../generated/RawApiTypes';
|
|
2
2
|
import type { LocalizedFieldValue } from '../utilities/fieldValue';
|
|
3
|
+
import type { ItemDefinition } from '../utilities/itemDefinition';
|
|
3
4
|
import type { RichTextEditorConfiguration } from './appearance/rich_text';
|
|
4
5
|
import { type BlockItemInARequest } from './single_block';
|
|
5
6
|
import type { RichTextBlocksValidator } from './validators/rich_text_blocks';
|
|
@@ -33,7 +34,7 @@ import type { SizeValidator } from './validators/size';
|
|
|
33
34
|
/**
|
|
34
35
|
* Basic Modular Content field value - array of string block IDs (lightweight references)
|
|
35
36
|
*/
|
|
36
|
-
export type RichTextFieldValue = string[]
|
|
37
|
+
export type RichTextFieldValue = string[];
|
|
37
38
|
/**
|
|
38
39
|
* =============================================================================
|
|
39
40
|
* REQUEST VARIANT - Type for sending data TO the DatoCMS API
|
|
@@ -50,7 +51,7 @@ export type RichTextFieldValue = string[] | null;
|
|
|
50
51
|
* - RawApiTypes.Item: Full block object with ID (for updates)
|
|
51
52
|
* - Omit<RawApiTypes.Item, 'id'>: Block object without ID (for creation)
|
|
52
53
|
*/
|
|
53
|
-
export type RichTextFieldValueAsRequest = BlockItemInARequest[] | null;
|
|
54
|
+
export type RichTextFieldValueAsRequest<D extends ItemDefinition = ItemDefinition> = BlockItemInARequest<D>[] | null;
|
|
54
55
|
/**
|
|
55
56
|
* =============================================================================
|
|
56
57
|
* NESTED VARIANT - Type for API responses with ?nested=true parameter
|
|
@@ -63,7 +64,7 @@ export type RichTextFieldValueAsRequest = BlockItemInARequest[] | null;
|
|
|
63
64
|
/**
|
|
64
65
|
* Modular Content field value with nested blocks - array of fully populated block objects
|
|
65
66
|
*/
|
|
66
|
-
export type RichTextFieldValueWithNestedBlocks = RawApiTypes.Item[]
|
|
67
|
+
export type RichTextFieldValueWithNestedBlocks<D extends ItemDefinition = ItemDefinition> = RawApiTypes.Item<D>[];
|
|
67
68
|
/**
|
|
68
69
|
* =============================================================================
|
|
69
70
|
* TYPE GUARDS - Runtime validation functions
|
|
@@ -79,14 +80,14 @@ export declare function isLocalizedRichTextFieldValue(value: unknown): value is
|
|
|
79
80
|
* Type guard for Modular Content field values in API request format.
|
|
80
81
|
* Allows blocks as string IDs, full objects with IDs, or objects without IDs.
|
|
81
82
|
*/
|
|
82
|
-
export declare function isRichTextFieldValueAsRequest(value: unknown): value is RichTextFieldValueAsRequest
|
|
83
|
-
export declare function isLocalizedRichTextFieldValueAsRequest(value: unknown): value is LocalizedFieldValue<RichTextFieldValueAsRequest
|
|
83
|
+
export declare function isRichTextFieldValueAsRequest<D extends ItemDefinition = ItemDefinition>(value: unknown): value is RichTextFieldValueAsRequest<D>;
|
|
84
|
+
export declare function isLocalizedRichTextFieldValueAsRequest<D extends ItemDefinition = ItemDefinition>(value: unknown): value is LocalizedFieldValue<RichTextFieldValueAsRequest<D>>;
|
|
84
85
|
/**
|
|
85
86
|
* Type guard for Modular Content field values with nested blocks (?nested=true format).
|
|
86
87
|
* Ensures all blocks are full RawApiTypes.Item objects with complete data.
|
|
87
88
|
*/
|
|
88
|
-
export declare function isRichTextFieldValueWithNestedBlocks(value: unknown): value is RichTextFieldValueWithNestedBlocks
|
|
89
|
-
export declare function isLocalizedRichTextFieldValueWithNestedBlocks(value: unknown): value is LocalizedFieldValue<RichTextFieldValueWithNestedBlocks
|
|
89
|
+
export declare function isRichTextFieldValueWithNestedBlocks<D extends ItemDefinition = ItemDefinition>(value: unknown): value is RichTextFieldValueWithNestedBlocks<D>;
|
|
90
|
+
export declare function isLocalizedRichTextFieldValueWithNestedBlocks<D extends ItemDefinition = ItemDefinition>(value: unknown): value is LocalizedFieldValue<RichTextFieldValueWithNestedBlocks<D>>;
|
|
90
91
|
export type RichTextFieldValidators = {
|
|
91
92
|
/** Only accept references to block records of the specified block models */
|
|
92
93
|
rich_text_blocks: RichTextBlocksValidator;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type * as RawApiTypes from '../generated/RawApiTypes';
|
|
2
2
|
import type { LocalizedFieldValue } from '../utilities/fieldValue';
|
|
3
|
+
import type { ItemDefinition } from '../utilities/itemDefinition';
|
|
3
4
|
import type { FramedSingleBlockEditorConfiguration } from './appearance/framed_single_block';
|
|
4
5
|
import type { FramelessSingleBlockEditorConfiguration } from './appearance/frameless_single_block';
|
|
5
6
|
import type { RequiredValidator } from './validators/required';
|
|
@@ -45,11 +46,11 @@ export type SingleBlockFieldValue = string | null;
|
|
|
45
46
|
* - Omit ID for new blocks being created
|
|
46
47
|
*/
|
|
47
48
|
/** Represents an existing block in a CMA request */
|
|
48
|
-
export type UnchangedBlockInARequest =
|
|
49
|
+
export type UnchangedBlockInARequest<D extends ItemDefinition = ItemDefinition> = RawApiTypes.Item<D>['id'];
|
|
49
50
|
/** Represents a block we want to update in a CMA request */
|
|
50
|
-
export type UpdatedBlockInARequest = OptionalFields<RawApiTypes.Item
|
|
51
|
+
export type UpdatedBlockInARequest<D extends ItemDefinition = ItemDefinition> = OptionalFields<RawApiTypes.Item<D>, 'meta'>;
|
|
51
52
|
/** Represents a new block to create in a CMA request */
|
|
52
|
-
export type NewBlockInARequest = OptionalFields<RawApiTypes.Item
|
|
53
|
+
export type NewBlockInARequest<D extends ItemDefinition = ItemDefinition> = OptionalFields<RawApiTypes.Item<D>, 'id' | 'meta'>;
|
|
53
54
|
/**
|
|
54
55
|
* Union type representing the different ways a block can be specified in API requests:
|
|
55
56
|
* - string: Just the block ID (to keep existing blocks unchanged)
|
|
@@ -58,14 +59,14 @@ export type NewBlockInARequest = OptionalFields<RawApiTypes.Item, 'id' | 'meta'>
|
|
|
58
59
|
*
|
|
59
60
|
* Also, 'meta' can always be omitted
|
|
60
61
|
*/
|
|
61
|
-
export type BlockItemInARequest = UnchangedBlockInARequest | UpdatedBlockInARequest | NewBlockInARequest
|
|
62
|
+
export type BlockItemInARequest<D extends ItemDefinition = ItemDefinition> = UnchangedBlockInARequest | UpdatedBlockInARequest<D> | NewBlockInARequest<D>;
|
|
62
63
|
/**
|
|
63
64
|
* Single Block field value for API requests - allows flexible block representations:
|
|
64
65
|
* - string: Just the block ID (to keep existing blocks unchanged)
|
|
65
66
|
* - Full block object with ID (to update an existing block)
|
|
66
67
|
* - Block object without ID (to create a new block)
|
|
67
68
|
*/
|
|
68
|
-
export type SingleBlockFieldValueAsRequest = BlockItemInARequest | null;
|
|
69
|
+
export type SingleBlockFieldValueAsRequest<D extends ItemDefinition = ItemDefinition> = BlockItemInARequest<D> | null;
|
|
69
70
|
/**
|
|
70
71
|
* =============================================================================
|
|
71
72
|
* NESTED VARIANT - Type for API responses with ?nested=true parameter
|
|
@@ -78,7 +79,7 @@ export type SingleBlockFieldValueAsRequest = BlockItemInARequest | null;
|
|
|
78
79
|
/**
|
|
79
80
|
* Single Block field value with nested block - fully populated block object
|
|
80
81
|
*/
|
|
81
|
-
export type SingleBlockFieldValueWithNestedBlocks = RawApiTypes.Item | null;
|
|
82
|
+
export type SingleBlockFieldValueWithNestedBlocks<D extends ItemDefinition = ItemDefinition> = RawApiTypes.Item<D> | null;
|
|
82
83
|
/**
|
|
83
84
|
* =============================================================================
|
|
84
85
|
* SHARED UTILITY FUNCTIONS
|
|
@@ -89,16 +90,16 @@ export type SingleBlockFieldValueWithNestedBlocks = RawApiTypes.Item | null;
|
|
|
89
90
|
* Validates if the input is a valid item (either block or record) ID
|
|
90
91
|
*/
|
|
91
92
|
export declare function isItemId(input: unknown): input is string;
|
|
92
|
-
export type ItemWithOptionalIdAndMeta = OptionalFields<RawApiTypes.Item
|
|
93
|
+
export type ItemWithOptionalIdAndMeta<D extends ItemDefinition = ItemDefinition> = OptionalFields<RawApiTypes.Item<D>, 'id' | 'meta'>;
|
|
93
94
|
/**
|
|
94
95
|
* Validates if the input is a RawApiTypes.Item object (with optional `id` and `meta`)
|
|
95
96
|
*/
|
|
96
|
-
export declare function isItemWithOptionalIdAndMeta(block: unknown): block is ItemWithOptionalIdAndMeta
|
|
97
|
-
export type ItemWithOptionalMeta = OptionalFields<RawApiTypes.Item
|
|
97
|
+
export declare function isItemWithOptionalIdAndMeta<D extends ItemDefinition = ItemDefinition>(block: unknown): block is ItemWithOptionalIdAndMeta<D>;
|
|
98
|
+
export type ItemWithOptionalMeta<D extends ItemDefinition = ItemDefinition> = OptionalFields<RawApiTypes.Item<D>, 'meta'>;
|
|
98
99
|
/**
|
|
99
100
|
* Validates if the input is a a complete RawApiTypes.Item object with optional `meta`
|
|
100
101
|
*/
|
|
101
|
-
export declare function isItemWithOptionalMeta(block: unknown): block is ItemWithOptionalMeta
|
|
102
|
+
export declare function isItemWithOptionalMeta<D extends ItemDefinition = ItemDefinition>(block: unknown): block is ItemWithOptionalMeta<D>;
|
|
102
103
|
/**
|
|
103
104
|
* =============================================================================
|
|
104
105
|
* TYPE GUARDS - Runtime validation functions
|
|
@@ -114,14 +115,14 @@ export declare function isLocalizedSingleBlockFieldValue(value: unknown): value
|
|
|
114
115
|
* Type guard for Single Block field values in API request format.
|
|
115
116
|
* Allows block as string ID, full object with ID, or object without ID.
|
|
116
117
|
*/
|
|
117
|
-
export declare function isSingleBlockFieldValueAsRequest(value: unknown): value is SingleBlockFieldValueAsRequest
|
|
118
|
-
export declare function isLocalizedSingleBlockFieldValueAsRequest(value: unknown): value is LocalizedFieldValue<SingleBlockFieldValueAsRequest
|
|
118
|
+
export declare function isSingleBlockFieldValueAsRequest<D extends ItemDefinition = ItemDefinition>(value: unknown): value is SingleBlockFieldValueAsRequest<D>;
|
|
119
|
+
export declare function isLocalizedSingleBlockFieldValueAsRequest<D extends ItemDefinition = ItemDefinition>(value: unknown): value is LocalizedFieldValue<SingleBlockFieldValueAsRequest<D>>;
|
|
119
120
|
/**
|
|
120
121
|
* Type guard for Single Block field values with nested blocks (?nested=true format).
|
|
121
122
|
* Ensures block is a full RawApiTypes.Item object with complete data.
|
|
122
123
|
*/
|
|
123
|
-
export declare function isSingleBlockFieldValueWithNestedBlocks(value: unknown): value is SingleBlockFieldValueWithNestedBlocks
|
|
124
|
-
export declare function isLocalizedSingleBlockFieldValueWithNestedBlocks(value: unknown): value is LocalizedFieldValue<SingleBlockFieldValueWithNestedBlocks
|
|
124
|
+
export declare function isSingleBlockFieldValueWithNestedBlocks<D extends ItemDefinition = ItemDefinition>(value: unknown): value is SingleBlockFieldValueWithNestedBlocks<D>;
|
|
125
|
+
export declare function isLocalizedSingleBlockFieldValueWithNestedBlocks<D extends ItemDefinition = ItemDefinition>(value: unknown): value is LocalizedFieldValue<SingleBlockFieldValueWithNestedBlocks<D>>;
|
|
125
126
|
export type SingleBlockFieldValidators = {
|
|
126
127
|
/** Only accept references to block records of the specified block models */
|
|
127
128
|
single_block_blocks: SingleBlockBlocksValidator;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type Block, type Document, type InlineBlock } from 'datocms-structured-text-utils';
|
|
2
2
|
import type * as RawApiTypes from '../generated/RawApiTypes';
|
|
3
3
|
import type { LocalizedFieldValue } from '../utilities/fieldValue';
|
|
4
|
+
import type { ItemDefinition } from '../utilities/itemDefinition';
|
|
4
5
|
import type { StructuredTextEditorConfiguration } from './appearance/structured_text';
|
|
5
6
|
import { type BlockItemInARequest } from './single_block';
|
|
6
7
|
import type { LengthValidator } from './validators/length';
|
|
@@ -39,15 +40,15 @@ import type { StructuredTextLinksValidator } from './validators/structured_text_
|
|
|
39
40
|
/**
|
|
40
41
|
* Variant of 'block' structured text node for API requests
|
|
41
42
|
*/
|
|
42
|
-
export type BlockAsRequest = Block<BlockItemInARequest
|
|
43
|
+
export type BlockAsRequest<D extends ItemDefinition = ItemDefinition> = Block<BlockItemInARequest<D>>;
|
|
43
44
|
/**
|
|
44
45
|
* Variant of 'inlineBlock' structured text node for API requests
|
|
45
46
|
*/
|
|
46
|
-
export type InlineBlockAsRequest = InlineBlock<BlockItemInARequest
|
|
47
|
+
export type InlineBlockAsRequest<D extends ItemDefinition = ItemDefinition> = InlineBlock<BlockItemInARequest<D>>;
|
|
47
48
|
/**
|
|
48
49
|
* Variant of Structured Text document for API requests
|
|
49
50
|
*/
|
|
50
|
-
export type DocumentAsRequest = Document<BlockItemInARequest
|
|
51
|
+
export type DocumentAsRequest<BlockItemDefinition extends ItemDefinition = ItemDefinition, InlineBlockItemDefinition extends ItemDefinition = ItemDefinition> = Document<BlockItemInARequest<BlockItemDefinition>, BlockItemInARequest<InlineBlockItemDefinition>>;
|
|
51
52
|
/**
|
|
52
53
|
* =============================================================================
|
|
53
54
|
* NESTED VARIANTS - Types for API responses with ?nested=true parameter
|
|
@@ -60,15 +61,15 @@ export type DocumentAsRequest = Document<BlockItemInARequest>;
|
|
|
60
61
|
/**
|
|
61
62
|
* Variant of 'block' structured text node for ?nested=true API responses
|
|
62
63
|
*/
|
|
63
|
-
export type BlockWithNestedBlocks = Block<RawApiTypes.Item
|
|
64
|
+
export type BlockWithNestedBlocks<D extends ItemDefinition = ItemDefinition> = Block<RawApiTypes.Item<D>>;
|
|
64
65
|
/**
|
|
65
66
|
* Variant of 'inlineBlock' structured text node for ?nested=true API responses
|
|
66
67
|
*/
|
|
67
|
-
export type InlineBlockWithNestedBlocks = InlineBlock<RawApiTypes.Item
|
|
68
|
+
export type InlineBlockWithNestedBlocks<D extends ItemDefinition = ItemDefinition> = InlineBlock<RawApiTypes.Item<D>>;
|
|
68
69
|
/**
|
|
69
70
|
* Variant of Structured Text document for ?nested=true API responses
|
|
70
71
|
*/
|
|
71
|
-
export type DocumentWithNestedBlocks = Document<RawApiTypes.Item
|
|
72
|
+
export type DocumentWithNestedBlocks<BlockItemDefinition extends ItemDefinition = ItemDefinition, InlineBlockItemDefinition extends ItemDefinition = ItemDefinition> = Document<RawApiTypes.Item<BlockItemDefinition>, RawApiTypes.Item<InlineBlockItemDefinition>>;
|
|
72
73
|
/**
|
|
73
74
|
* =============================================================================
|
|
74
75
|
* MAIN APPLICATION TYPES
|
|
@@ -79,8 +80,8 @@ export type DocumentWithNestedBlocks = Document<RawApiTypes.Item>;
|
|
|
79
80
|
* Can be null (empty field) or a document with blocks as string IDs
|
|
80
81
|
*/
|
|
81
82
|
export type StructuredTextFieldValue = Document | null;
|
|
82
|
-
export type StructuredTextFieldValueAsRequest = DocumentAsRequest | null;
|
|
83
|
-
export type StructuredTextFieldValueWithNestedBlocks = DocumentWithNestedBlocks | null;
|
|
83
|
+
export type StructuredTextFieldValueAsRequest<BlockItemDefinition extends ItemDefinition = ItemDefinition, InlineBlockItemDefinition extends ItemDefinition = ItemDefinition> = DocumentAsRequest<BlockItemDefinition, InlineBlockItemDefinition> | null;
|
|
84
|
+
export type StructuredTextFieldValueWithNestedBlocks<BlockItemDefinition extends ItemDefinition = ItemDefinition, InlineBlockItemDefinition extends ItemDefinition = ItemDefinition> = DocumentWithNestedBlocks<BlockItemDefinition, InlineBlockItemDefinition> | null;
|
|
84
85
|
/**
|
|
85
86
|
* Type guard for basic structured text field values (blocks as string IDs only).
|
|
86
87
|
* Checks for the expected structure and ensures all block/inlineBlock nodes have string IDs.
|
|
@@ -91,14 +92,14 @@ export declare function isLocalizedStructuredTextFieldValue(value: unknown): val
|
|
|
91
92
|
* Type guard for structured text field values in API request format.
|
|
92
93
|
* Allows blocks as string IDs, full objects with IDs, or objects without IDs.
|
|
93
94
|
*/
|
|
94
|
-
export declare function isStructuredTextFieldValueAsRequest(value: unknown): value is StructuredTextFieldValueAsRequest
|
|
95
|
-
export declare function isLocalizedStructuredTextFieldValueAsRequest(value: unknown): value is LocalizedFieldValue<StructuredTextFieldValueAsRequest
|
|
95
|
+
export declare function isStructuredTextFieldValueAsRequest<BlockItemDefinition extends ItemDefinition = ItemDefinition, InlineBlockItemDefinition extends ItemDefinition = ItemDefinition>(value: unknown): value is StructuredTextFieldValueAsRequest<BlockItemDefinition, InlineBlockItemDefinition>;
|
|
96
|
+
export declare function isLocalizedStructuredTextFieldValueAsRequest<D extends ItemDefinition = ItemDefinition>(value: unknown): value is LocalizedFieldValue<StructuredTextFieldValueAsRequest<D>>;
|
|
96
97
|
/**
|
|
97
98
|
* Type guard for structured text field values with nested blocks (?nested=true format).
|
|
98
99
|
* Ensures all block/inlineBlock nodes have full RawApiTypes.Item objects.
|
|
99
100
|
*/
|
|
100
|
-
export declare function isStructuredTextFieldValueWithNestedBlocks(value: unknown): value is StructuredTextFieldValueWithNestedBlocks
|
|
101
|
-
export declare function isLocalizedStructuredTextFieldValueWithNestedBlocks(value: unknown): value is LocalizedFieldValue<StructuredTextFieldValueWithNestedBlocks
|
|
101
|
+
export declare function isStructuredTextFieldValueWithNestedBlocks<D extends ItemDefinition = ItemDefinition>(value: unknown): value is StructuredTextFieldValueWithNestedBlocks<D>;
|
|
102
|
+
export declare function isLocalizedStructuredTextFieldValueWithNestedBlocks<D extends ItemDefinition = ItemDefinition>(value: unknown): value is LocalizedFieldValue<StructuredTextFieldValueWithNestedBlocks<D>>;
|
|
102
103
|
export type StructuredTextFieldValidators = {
|
|
103
104
|
/** Only accept references to block records of the specified block models */
|
|
104
105
|
structured_text_blocks: StructuredTextBlocksValidator;
|