@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,11 +1,6 @@
|
|
|
1
1
|
import * as Utils from '@datocms/rest-client-utils';
|
|
2
2
|
import BaseResource from '../../BaseResource';
|
|
3
|
-
import type {
|
|
4
|
-
ItemTypeDefinition,
|
|
5
|
-
ToItemDefinition,
|
|
6
|
-
ToItemDefinitionAsRequest,
|
|
7
|
-
ToItemDefinitionWithNestedBlocks,
|
|
8
|
-
} from '../../utilities/itemDefinition';
|
|
3
|
+
import type { ItemTypeDefinition } from '../../utilities/itemDefinition';
|
|
9
4
|
import type * as ApiTypes from '../ApiTypes';
|
|
10
5
|
import type * as RawApiTypes from '../RawApiTypes';
|
|
11
6
|
|
|
@@ -267,19 +262,13 @@ export default class Upload extends BaseResource {
|
|
|
267
262
|
references<D extends ItemTypeDefinition = ItemTypeDefinition>(
|
|
268
263
|
uploadId: string | ApiTypes.UploadData,
|
|
269
264
|
queryParams: ApiTypes.UploadReferencesHrefSchema & { nested: true },
|
|
270
|
-
): Promise<
|
|
271
|
-
ApiTypes.UploadReferencesTargetSchema<
|
|
272
|
-
ToItemDefinitionWithNestedBlocks<NoInfer<D>>
|
|
273
|
-
>
|
|
274
|
-
>;
|
|
265
|
+
): Promise<ApiTypes.UploadReferencesTargetSchema<NoInfer<D>, true>>;
|
|
275
266
|
references<D extends ItemTypeDefinition = ItemTypeDefinition>(
|
|
276
267
|
uploadId: string | ApiTypes.UploadData,
|
|
277
268
|
queryParams?: ApiTypes.UploadReferencesHrefSchema & {
|
|
278
269
|
nested?: false | undefined;
|
|
279
270
|
},
|
|
280
|
-
): Promise<
|
|
281
|
-
ApiTypes.UploadReferencesTargetSchema<ToItemDefinition<NoInfer<D>>>
|
|
282
|
-
>;
|
|
271
|
+
): Promise<ApiTypes.UploadReferencesTargetSchema<NoInfer<D>, false>>;
|
|
283
272
|
/**
|
|
284
273
|
* Referenced records
|
|
285
274
|
*
|
|
@@ -308,27 +297,17 @@ export default class Upload extends BaseResource {
|
|
|
308
297
|
rawReferences<D extends ItemTypeDefinition = ItemTypeDefinition>(
|
|
309
298
|
uploadId: string,
|
|
310
299
|
queryParams: RawApiTypes.UploadReferencesHrefSchema & { nested: true },
|
|
311
|
-
): Promise<
|
|
312
|
-
RawApiTypes.UploadReferencesTargetSchema<
|
|
313
|
-
ToItemDefinitionWithNestedBlocks<NoInfer<D>>
|
|
314
|
-
>
|
|
315
|
-
>;
|
|
300
|
+
): Promise<RawApiTypes.UploadReferencesTargetSchema<NoInfer<D>, true>>;
|
|
316
301
|
rawReferences<D extends ItemTypeDefinition = ItemTypeDefinition>(
|
|
317
302
|
uploadId: string,
|
|
318
303
|
queryParams?: RawApiTypes.UploadReferencesHrefSchema & {
|
|
319
304
|
nested?: false | undefined;
|
|
320
305
|
},
|
|
321
|
-
): Promise<
|
|
322
|
-
RawApiTypes.UploadReferencesTargetSchema<ToItemDefinition<NoInfer<D>>>
|
|
323
|
-
>;
|
|
306
|
+
): Promise<RawApiTypes.UploadReferencesTargetSchema<NoInfer<D>, false>>;
|
|
324
307
|
rawReferences<D extends ItemTypeDefinition = ItemTypeDefinition>(
|
|
325
308
|
uploadId: string,
|
|
326
309
|
queryParams?: RawApiTypes.UploadReferencesHrefSchema,
|
|
327
|
-
): Promise<
|
|
328
|
-
RawApiTypes.UploadReferencesTargetSchema<
|
|
329
|
-
ToItemDefinitionWithNestedBlocks<NoInfer<D>>
|
|
330
|
-
>
|
|
331
|
-
>;
|
|
310
|
+
): Promise<RawApiTypes.UploadReferencesTargetSchema<NoInfer<D>, true>>;
|
|
332
311
|
/**
|
|
333
312
|
* Referenced records
|
|
334
313
|
*
|
|
@@ -347,11 +326,9 @@ export default class Upload extends BaseResource {
|
|
|
347
326
|
url: `/uploads/${uploadId}/references`,
|
|
348
327
|
queryParams,
|
|
349
328
|
})
|
|
350
|
-
.then<
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
>
|
|
354
|
-
>(Utils.deserializeRawResponseBodyWithItems);
|
|
329
|
+
.then<RawApiTypes.UploadReferencesTargetSchema<NoInfer<D>, true>>(
|
|
330
|
+
Utils.deserializeRawResponseBodyWithItems,
|
|
331
|
+
);
|
|
355
332
|
}
|
|
356
333
|
|
|
357
334
|
/**
|
package/src/index.ts
CHANGED
|
@@ -5,6 +5,7 @@ export { Client } from './generated/Client';
|
|
|
5
5
|
export type { ClientConfigOptions } from './generated/Client';
|
|
6
6
|
export * as Resources from './generated/resources';
|
|
7
7
|
export * from './utilities/buildBlockRecord';
|
|
8
|
+
export * from './utilities/duplicateBlockRecord';
|
|
8
9
|
export * from './utilities/fieldsContainingReferences';
|
|
9
10
|
export * from './utilities/id';
|
|
10
11
|
export * from './utilities/inspectItem';
|
|
@@ -1,75 +1,35 @@
|
|
|
1
1
|
import * as Utils from '@datocms/rest-client-utils';
|
|
2
|
-
import type {
|
|
3
|
-
ItemWithOptionalIdAndMeta,
|
|
4
|
-
NewBlockInARequest,
|
|
5
|
-
} from '../fieldTypes';
|
|
2
|
+
import type { NewBlockInRequest } from '../fieldTypes';
|
|
6
3
|
import type * as ApiTypes from '../generated/ApiTypes';
|
|
7
4
|
import { Item } from '../generated/resources';
|
|
8
5
|
import type {
|
|
9
6
|
ItemTypeDefinition,
|
|
10
|
-
|
|
11
|
-
ToItemDefinitionWithNestedBlocks,
|
|
7
|
+
ToItemAttributesInRequest,
|
|
12
8
|
} from './itemDefinition';
|
|
13
|
-
import { mapBlocksInNonLocalizedFieldValue } from './recursiveBlocks';
|
|
14
|
-
import type { SchemaRepository } from './schemaRepository';
|
|
15
9
|
|
|
16
10
|
type NoInfer<T> = [T][T extends any ? 0 : never];
|
|
17
11
|
|
|
12
|
+
type UpdateOrCreateBlockRecordSchema<
|
|
13
|
+
D extends ItemTypeDefinition = ItemTypeDefinition,
|
|
14
|
+
> = {
|
|
15
|
+
id?: ApiTypes.ItemIdentity;
|
|
16
|
+
type?: ApiTypes.ItemType1;
|
|
17
|
+
item_type: ApiTypes.ItemTypeData<D>;
|
|
18
|
+
meta?: ApiTypes.ItemUpdateSchema['meta'];
|
|
19
|
+
creator?: ApiTypes.ItemUpdateSchema['creator'];
|
|
20
|
+
__itemTypeId?: D['itemTypeId'];
|
|
21
|
+
} & ToItemAttributesInRequest<D>;
|
|
22
|
+
|
|
18
23
|
export function buildBlockRecord<
|
|
19
24
|
D extends ItemTypeDefinition = ItemTypeDefinition,
|
|
20
25
|
>(
|
|
21
|
-
body:
|
|
22
|
-
):
|
|
26
|
+
body: UpdateOrCreateBlockRecordSchema<NoInfer<D>>,
|
|
27
|
+
): NewBlockInRequest<NoInfer<D>> {
|
|
23
28
|
return Utils.serializeRequestBody<{
|
|
24
|
-
data:
|
|
29
|
+
data: NewBlockInRequest<NoInfer<D>>;
|
|
25
30
|
}>(body, {
|
|
26
31
|
type: Item.TYPE,
|
|
27
32
|
attributes: '*',
|
|
28
33
|
relationships: ['item_type'],
|
|
29
34
|
}).data;
|
|
30
35
|
}
|
|
31
|
-
|
|
32
|
-
export async function duplicateBlockRecord<
|
|
33
|
-
D extends ItemTypeDefinition = ItemTypeDefinition,
|
|
34
|
-
>(
|
|
35
|
-
existingBlock: ItemWithOptionalIdAndMeta<
|
|
36
|
-
ToItemDefinitionWithNestedBlocks<NoInfer<D>>
|
|
37
|
-
>,
|
|
38
|
-
schemaRepository: SchemaRepository,
|
|
39
|
-
): Promise<NewBlockInARequest<ToItemDefinitionAsRequest<NoInfer<D>>>> {
|
|
40
|
-
const { type, attributes, relationships } = existingBlock;
|
|
41
|
-
|
|
42
|
-
const itemType = await schemaRepository.getRawItemTypeById(
|
|
43
|
-
existingBlock.relationships.item_type.data.id,
|
|
44
|
-
);
|
|
45
|
-
|
|
46
|
-
const newBlock = {
|
|
47
|
-
type,
|
|
48
|
-
relationships,
|
|
49
|
-
attributes,
|
|
50
|
-
} as NewBlockInARequest;
|
|
51
|
-
|
|
52
|
-
const fields = await schemaRepository.getRawItemTypeFields(itemType);
|
|
53
|
-
|
|
54
|
-
for (const field of fields) {
|
|
55
|
-
newBlock.attributes[field.attributes.api_key] =
|
|
56
|
-
mapBlocksInNonLocalizedFieldValue(
|
|
57
|
-
schemaRepository,
|
|
58
|
-
field.attributes.field_type,
|
|
59
|
-
newBlock.attributes[field.attributes.api_key],
|
|
60
|
-
(block, path) => {
|
|
61
|
-
if (typeof block === 'string') {
|
|
62
|
-
throw new Error(
|
|
63
|
-
`Block cannot be duplicated as it contains nested block at ${path.join('.')} that is expressed as ID (${block}) instead of full object!`,
|
|
64
|
-
);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
const { id, meta, ...blockWithoutIdAndMeta } = block;
|
|
68
|
-
|
|
69
|
-
return blockWithoutIdAndMeta;
|
|
70
|
-
},
|
|
71
|
-
);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
return newBlock as NewBlockInARequest<ToItemDefinitionAsRequest<NoInfer<D>>>;
|
|
75
|
-
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ItemWithOptionalIdAndMeta,
|
|
3
|
+
NewBlockInRequest,
|
|
4
|
+
} from '../fieldTypes';
|
|
5
|
+
import type { ItemTypeDefinition } from './itemDefinition';
|
|
6
|
+
import { mapBlocksInNonLocalizedFieldValue } from './recursiveBlocks';
|
|
7
|
+
import type { SchemaRepository } from './schemaRepository';
|
|
8
|
+
|
|
9
|
+
type NoInfer<T> = [T][T extends any ? 0 : never];
|
|
10
|
+
|
|
11
|
+
export async function duplicateBlockRecord<
|
|
12
|
+
D extends ItemTypeDefinition = ItemTypeDefinition,
|
|
13
|
+
>(
|
|
14
|
+
existingBlock: ItemWithOptionalIdAndMeta<NoInfer<D>>,
|
|
15
|
+
schemaRepository: SchemaRepository,
|
|
16
|
+
): Promise<NewBlockInRequest<NoInfer<D>>> {
|
|
17
|
+
const { __itemTypeId, type, attributes, relationships } = existingBlock;
|
|
18
|
+
|
|
19
|
+
const itemType = await schemaRepository.getRawItemTypeById(
|
|
20
|
+
existingBlock.relationships.item_type.data.id,
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
const newBlock = {
|
|
24
|
+
__itemTypeId,
|
|
25
|
+
type,
|
|
26
|
+
relationships,
|
|
27
|
+
attributes,
|
|
28
|
+
} as NewBlockInRequest;
|
|
29
|
+
|
|
30
|
+
const fields = await schemaRepository.getRawItemTypeFields(itemType);
|
|
31
|
+
|
|
32
|
+
for (const field of fields) {
|
|
33
|
+
newBlock.attributes[field.attributes.api_key] =
|
|
34
|
+
await mapBlocksInNonLocalizedFieldValue(
|
|
35
|
+
newBlock.attributes[field.attributes.api_key],
|
|
36
|
+
field.attributes.field_type,
|
|
37
|
+
schemaRepository,
|
|
38
|
+
(block, path) => {
|
|
39
|
+
if (typeof block === 'string') {
|
|
40
|
+
throw new Error(
|
|
41
|
+
`Block cannot be duplicated as it contains nested block at ${path.join('.')} that is expressed as ID (${block}) instead of full object!`,
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const { id, meta, ...blockWithoutIdAndMeta } = block;
|
|
46
|
+
|
|
47
|
+
return blockWithoutIdAndMeta as NewBlockInRequest;
|
|
48
|
+
},
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return newBlock as NewBlockInRequest<NoInfer<D>>;
|
|
53
|
+
}
|
|
@@ -1,79 +1,81 @@
|
|
|
1
|
+
import * as Utils from '@datocms/rest-client-utils';
|
|
1
2
|
import {
|
|
2
3
|
type TreeNode,
|
|
3
4
|
formatAsTree,
|
|
4
5
|
inspectionTreeNodes,
|
|
5
6
|
} from 'datocms-structured-text-utils';
|
|
6
7
|
import {
|
|
7
|
-
type
|
|
8
|
+
type BlockInRequest,
|
|
8
9
|
type BooleanFieldValue,
|
|
9
10
|
type ColorFieldValue,
|
|
10
11
|
type DateFieldValue,
|
|
11
12
|
type DateTimeFieldValue,
|
|
12
13
|
type FileFieldValue,
|
|
13
|
-
type
|
|
14
|
+
type FileFieldValueInRequest,
|
|
14
15
|
type FloatFieldValue,
|
|
15
16
|
type GalleryFieldValue,
|
|
16
|
-
type
|
|
17
|
+
type GalleryFieldValueInRequest,
|
|
17
18
|
type IntegerFieldValue,
|
|
18
19
|
type JsonFieldValue,
|
|
19
20
|
type LatLonFieldValue,
|
|
20
21
|
type LinkFieldValue,
|
|
21
22
|
type LinksFieldValue,
|
|
22
|
-
type
|
|
23
|
+
type NewBlockInRequest,
|
|
23
24
|
type RichTextFieldValue,
|
|
24
|
-
type
|
|
25
|
-
type
|
|
25
|
+
type RichTextFieldValueInNestedResponse,
|
|
26
|
+
type RichTextFieldValueInRequest,
|
|
26
27
|
type SeoFieldValue,
|
|
27
28
|
type SingleBlockFieldValue,
|
|
28
|
-
type
|
|
29
|
-
type
|
|
29
|
+
type SingleBlockFieldValueInNestedResponse,
|
|
30
|
+
type SingleBlockFieldValueInRequest,
|
|
30
31
|
type SlugFieldValue,
|
|
31
32
|
type StringFieldValue,
|
|
32
33
|
type StructuredTextFieldValue,
|
|
33
|
-
type
|
|
34
|
-
type
|
|
34
|
+
type StructuredTextFieldValueInNestedResponse,
|
|
35
|
+
type StructuredTextFieldValueInRequest,
|
|
35
36
|
type TextFieldValue,
|
|
36
|
-
type
|
|
37
|
+
type UpdatedBlockInRequest,
|
|
37
38
|
type VideoFieldValue,
|
|
38
39
|
isBooleanFieldValue,
|
|
39
40
|
isColorFieldValue,
|
|
40
41
|
isDateFieldValue,
|
|
41
42
|
isDateTimeFieldValue,
|
|
42
43
|
isFileFieldValue,
|
|
43
|
-
|
|
44
|
+
isFileFieldValueInRequest,
|
|
44
45
|
isFloatFieldValue,
|
|
45
46
|
isGalleryFieldValue,
|
|
46
|
-
|
|
47
|
+
isGalleryFieldValueInRequest,
|
|
47
48
|
isIntegerFieldValue,
|
|
48
49
|
isJsonFieldValue,
|
|
49
50
|
isLatLonFieldValue,
|
|
50
51
|
isLinkFieldValue,
|
|
51
52
|
isLinksFieldValue,
|
|
52
53
|
isRichTextFieldValue,
|
|
53
|
-
|
|
54
|
-
|
|
54
|
+
isRichTextFieldValueInNestedResponse,
|
|
55
|
+
isRichTextFieldValueInRequest,
|
|
55
56
|
isSeoFieldValue,
|
|
56
57
|
isSingleBlockFieldValue,
|
|
57
|
-
|
|
58
|
-
|
|
58
|
+
isSingleBlockFieldValueInNestedResponse,
|
|
59
|
+
isSingleBlockFieldValueInRequest,
|
|
59
60
|
isSlugFieldValue,
|
|
60
61
|
isStringFieldValue,
|
|
61
62
|
isStructuredTextFieldValue,
|
|
62
|
-
|
|
63
|
-
|
|
63
|
+
isStructuredTextFieldValueInNestedResponse,
|
|
64
|
+
isStructuredTextFieldValueInRequest,
|
|
64
65
|
isTextFieldValue,
|
|
65
66
|
isVideoFieldValue,
|
|
66
67
|
} from '../fieldTypes';
|
|
68
|
+
import { Item as ItemResource } from '../generated/resources';
|
|
67
69
|
|
|
68
|
-
import {
|
|
70
|
+
import type { ApiTypes, RawApiTypes } from '../index';
|
|
69
71
|
import type { LocalizedFieldValue } from './normalizedFieldValues';
|
|
70
72
|
import { isLocalizedFieldValue } from './normalizedFieldValues';
|
|
71
73
|
|
|
72
74
|
type Item =
|
|
73
75
|
| ApiTypes.Item
|
|
74
76
|
| RawApiTypes.Item
|
|
75
|
-
|
|
|
76
|
-
|
|
|
77
|
+
| NewBlockInRequest
|
|
78
|
+
| UpdatedBlockInRequest
|
|
77
79
|
| RawApiTypes.ItemCreateSchema
|
|
78
80
|
| RawApiTypes.ItemUpdateSchema
|
|
79
81
|
| ApiTypes.ItemCreateSchema
|
|
@@ -95,9 +97,9 @@ const fieldTypeHandlers: FieldTypeHandler[] = [
|
|
|
95
97
|
{ guard: isDateFieldValue, inspect: dateInspectionTreeNodes },
|
|
96
98
|
{ guard: isDateTimeFieldValue, inspect: dateTimeInspectionTreeNodes },
|
|
97
99
|
{ guard: isGalleryFieldValue, inspect: galleryInspectionTreeNodes },
|
|
98
|
-
{ guard:
|
|
100
|
+
{ guard: isGalleryFieldValueInRequest, inspect: galleryInspectionTreeNodes },
|
|
99
101
|
{ guard: isFileFieldValue, inspect: fileInspectionTreeNodes },
|
|
100
|
-
{ guard:
|
|
102
|
+
{ guard: isFileFieldValueInRequest, inspect: fileInspectionTreeNodes },
|
|
101
103
|
{ guard: isJsonFieldValue, inspect: jsonInspectionTreeNodes },
|
|
102
104
|
{ guard: isSlugFieldValue, inspect: slugInspectionTreeNodes },
|
|
103
105
|
{ guard: isStringFieldValue, inspect: stringInspectionTreeNodes },
|
|
@@ -112,29 +114,29 @@ const fieldTypeHandlers: FieldTypeHandler[] = [
|
|
|
112
114
|
inspect: structuredTextInspectionTreeNodes,
|
|
113
115
|
},
|
|
114
116
|
{
|
|
115
|
-
guard:
|
|
117
|
+
guard: isStructuredTextFieldValueInRequest,
|
|
116
118
|
inspect: structuredTextInspectionTreeNodes,
|
|
117
119
|
},
|
|
118
120
|
{
|
|
119
|
-
guard:
|
|
121
|
+
guard: isStructuredTextFieldValueInNestedResponse,
|
|
120
122
|
inspect: structuredTextInspectionTreeNodes,
|
|
121
123
|
},
|
|
122
124
|
{ guard: isSingleBlockFieldValue, inspect: singleBlockInspectionTreeNodes },
|
|
123
125
|
{
|
|
124
|
-
guard:
|
|
126
|
+
guard: isSingleBlockFieldValueInRequest,
|
|
125
127
|
inspect: singleBlockInspectionTreeNodes,
|
|
126
128
|
},
|
|
127
129
|
{
|
|
128
|
-
guard:
|
|
130
|
+
guard: isSingleBlockFieldValueInNestedResponse,
|
|
129
131
|
inspect: singleBlockInspectionTreeNodes,
|
|
130
132
|
},
|
|
131
133
|
{ guard: isRichTextFieldValue, inspect: richTextInspectionTreeNodes },
|
|
132
134
|
{
|
|
133
|
-
guard:
|
|
135
|
+
guard: isRichTextFieldValueInRequest,
|
|
134
136
|
inspect: richTextInspectionTreeNodes,
|
|
135
137
|
},
|
|
136
138
|
{
|
|
137
|
-
guard:
|
|
139
|
+
guard: isRichTextFieldValueInNestedResponse,
|
|
138
140
|
inspect: richTextInspectionTreeNodes,
|
|
139
141
|
},
|
|
140
142
|
];
|
|
@@ -208,14 +210,20 @@ function inspectFieldValue(
|
|
|
208
210
|
return `UNKNOWN: ${JSON.stringify(value)}`;
|
|
209
211
|
}
|
|
210
212
|
|
|
211
|
-
function
|
|
213
|
+
function normalizeItem(item: any): RawApiTypes.Item {
|
|
212
214
|
if ('attributes' in item) {
|
|
213
|
-
return item
|
|
215
|
+
return item;
|
|
214
216
|
}
|
|
215
217
|
|
|
216
|
-
const
|
|
217
|
-
|
|
218
|
-
return
|
|
218
|
+
const { __itemTypeId, ...itemWithoutItemTypeId } = item;
|
|
219
|
+
|
|
220
|
+
return Utils.serializeRequestBody<{
|
|
221
|
+
data: RawApiTypes.Item;
|
|
222
|
+
}>(itemWithoutItemTypeId, {
|
|
223
|
+
type: ItemResource.TYPE,
|
|
224
|
+
attributes: '*',
|
|
225
|
+
relationships: ['item_type', 'creator'],
|
|
226
|
+
}).data;
|
|
219
227
|
}
|
|
220
228
|
|
|
221
229
|
export type InspectItemOptions = {
|
|
@@ -232,8 +240,10 @@ function itemInspectionTreeNodes(
|
|
|
232
240
|
): TreeNode {
|
|
233
241
|
let itemTypeId: string | undefined;
|
|
234
242
|
|
|
235
|
-
|
|
236
|
-
|
|
243
|
+
const normalizedItem = normalizeItem(item);
|
|
244
|
+
|
|
245
|
+
if ('relationships' in normalizedItem && normalizedItem.relationships) {
|
|
246
|
+
const relationships = normalizedItem.relationships as any;
|
|
237
247
|
if (relationships.item_type?.data?.id) {
|
|
238
248
|
itemTypeId = relationships.item_type.data.id;
|
|
239
249
|
}
|
|
@@ -241,7 +251,7 @@ function itemInspectionTreeNodes(
|
|
|
241
251
|
|
|
242
252
|
const rootLabel = [
|
|
243
253
|
'Item',
|
|
244
|
-
'id' in item ? JSON.stringify(
|
|
254
|
+
'id' in item ? JSON.stringify(normalizedItem.id) : null,
|
|
245
255
|
itemTypeId ? `(item_type: ${JSON.stringify(itemTypeId)})` : null,
|
|
246
256
|
]
|
|
247
257
|
.filter(Boolean)
|
|
@@ -249,11 +259,13 @@ function itemInspectionTreeNodes(
|
|
|
249
259
|
|
|
250
260
|
const nodes: TreeNode[] = [];
|
|
251
261
|
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
262
|
+
if ('attributes' in normalizedItem) {
|
|
263
|
+
for (const [attributeName, attributeValue] of Object.entries(
|
|
264
|
+
normalizedItem.attributes,
|
|
265
|
+
)) {
|
|
266
|
+
const inspectResult = inspectFieldValue(attributeValue, options);
|
|
267
|
+
nodes.push(createChildNode(attributeName, inspectResult));
|
|
268
|
+
}
|
|
257
269
|
}
|
|
258
270
|
|
|
259
271
|
return {
|
|
@@ -265,13 +277,13 @@ function itemInspectionTreeNodes(
|
|
|
265
277
|
function structuredTextInspectionTreeNodes(
|
|
266
278
|
value:
|
|
267
279
|
| StructuredTextFieldValue
|
|
268
|
-
|
|
|
269
|
-
|
|
|
280
|
+
| StructuredTextFieldValueInRequest
|
|
281
|
+
| StructuredTextFieldValueInNestedResponse,
|
|
270
282
|
options?: InspectItemOptions,
|
|
271
283
|
) {
|
|
272
284
|
if (value === null) return 'null';
|
|
273
285
|
|
|
274
|
-
return inspectionTreeNodes<
|
|
286
|
+
return inspectionTreeNodes<BlockInRequest, BlockInRequest>(value, {
|
|
275
287
|
maxWidth: options?.maxWidth || 80,
|
|
276
288
|
blockFormatter: (block, maxWidth) => {
|
|
277
289
|
if (typeof block === 'string') {
|
|
@@ -286,8 +298,8 @@ function structuredTextInspectionTreeNodes(
|
|
|
286
298
|
function singleBlockInspectionTreeNodes(
|
|
287
299
|
value:
|
|
288
300
|
| SingleBlockFieldValue
|
|
289
|
-
|
|
|
290
|
-
|
|
|
301
|
+
| SingleBlockFieldValueInRequest
|
|
302
|
+
| SingleBlockFieldValueInNestedResponse,
|
|
291
303
|
options?: InspectItemOptions,
|
|
292
304
|
) {
|
|
293
305
|
if (value === null) return 'null';
|
|
@@ -298,8 +310,8 @@ function singleBlockInspectionTreeNodes(
|
|
|
298
310
|
function richTextInspectionTreeNodes(
|
|
299
311
|
value:
|
|
300
312
|
| RichTextFieldValue
|
|
301
|
-
|
|
|
302
|
-
|
|
|
313
|
+
| RichTextFieldValueInRequest
|
|
314
|
+
| RichTextFieldValueInNestedResponse,
|
|
303
315
|
options?: InspectItemOptions,
|
|
304
316
|
): string | TreeNode[] {
|
|
305
317
|
if (value === null) return 'null';
|
|
@@ -342,7 +354,7 @@ function dateTimeInspectionTreeNodes(value: DateTimeFieldValue): string {
|
|
|
342
354
|
}
|
|
343
355
|
|
|
344
356
|
function fileInspectionTreeNodes(
|
|
345
|
-
value: FileFieldValue |
|
|
357
|
+
value: FileFieldValue | FileFieldValueInRequest,
|
|
346
358
|
options?: InspectItemOptions,
|
|
347
359
|
): string | TreeNode[] {
|
|
348
360
|
if (value === null) return 'null';
|
|
@@ -384,7 +396,7 @@ function floatInspectionTreeNodes(value: FloatFieldValue): string {
|
|
|
384
396
|
}
|
|
385
397
|
|
|
386
398
|
function galleryInspectionTreeNodes(
|
|
387
|
-
value: GalleryFieldValue |
|
|
399
|
+
value: GalleryFieldValue | GalleryFieldValueInRequest,
|
|
388
400
|
options?: InspectItemOptions,
|
|
389
401
|
): string | TreeNode[] {
|
|
390
402
|
if (!value || value.length === 0) return '[]';
|