@datocms/cma-client 5.1.3 → 5.1.4

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.
Files changed (84) hide show
  1. package/dist/cjs/fieldTypes/lat_lon.js +6 -6
  2. package/dist/cjs/fieldTypes/lat_lon.js.map +1 -1
  3. package/dist/cjs/fieldTypes/rich_text.js.map +1 -1
  4. package/dist/cjs/fieldTypes/single_block.js.map +1 -1
  5. package/dist/cjs/fieldTypes/structured_text.js.map +1 -1
  6. package/dist/cjs/generated/Client.js +1 -1
  7. package/dist/cjs/generated/resources/Item.js +41 -23
  8. package/dist/cjs/generated/resources/Item.js.map +1 -1
  9. package/dist/cjs/generated/resources/ScheduledPublication.js +4 -2
  10. package/dist/cjs/generated/resources/ScheduledPublication.js.map +1 -1
  11. package/dist/cjs/generated/resources/ScheduledUnpublishing.js +4 -2
  12. package/dist/cjs/generated/resources/ScheduledUnpublishing.js.map +1 -1
  13. package/dist/cjs/generated/resources/Upload.js +4 -2
  14. package/dist/cjs/generated/resources/Upload.js.map +1 -1
  15. package/dist/cjs/index.js +1 -0
  16. package/dist/cjs/index.js.map +1 -1
  17. package/dist/cjs/utilities/buildBlockRecord.js.map +1 -1
  18. package/dist/cjs/utilities/itemDefinition.js +3 -0
  19. package/dist/cjs/utilities/itemDefinition.js.map +1 -0
  20. package/dist/esm/fieldTypes/lat_lon.d.ts +5 -5
  21. package/dist/esm/fieldTypes/lat_lon.js +3 -3
  22. package/dist/esm/fieldTypes/lat_lon.js.map +1 -1
  23. package/dist/esm/fieldTypes/rich_text.d.ts +8 -7
  24. package/dist/esm/fieldTypes/rich_text.js.map +1 -1
  25. package/dist/esm/fieldTypes/single_block.d.ts +15 -14
  26. package/dist/esm/fieldTypes/single_block.js.map +1 -1
  27. package/dist/esm/fieldTypes/structured_text.d.ts +13 -12
  28. package/dist/esm/fieldTypes/structured_text.js.map +1 -1
  29. package/dist/esm/generated/ApiTypes.d.ts +67 -62
  30. package/dist/esm/generated/Client.js +1 -1
  31. package/dist/esm/generated/RawApiTypes.d.ts +116 -121
  32. package/dist/esm/generated/resources/Field.d.ts +230 -230
  33. package/dist/esm/generated/resources/Item.d.ts +42 -24
  34. package/dist/esm/generated/resources/Item.js +41 -23
  35. package/dist/esm/generated/resources/Item.js.map +1 -1
  36. package/dist/esm/generated/resources/ItemVersion.d.ts +1 -1
  37. package/dist/esm/generated/resources/ScheduledPublication.d.ts +5 -2
  38. package/dist/esm/generated/resources/ScheduledPublication.js +4 -2
  39. package/dist/esm/generated/resources/ScheduledPublication.js.map +1 -1
  40. package/dist/esm/generated/resources/ScheduledUnpublishing.d.ts +5 -2
  41. package/dist/esm/generated/resources/ScheduledUnpublishing.js +4 -2
  42. package/dist/esm/generated/resources/ScheduledUnpublishing.js.map +1 -1
  43. package/dist/esm/generated/resources/Upload.d.ts +10 -2
  44. package/dist/esm/generated/resources/Upload.js +4 -2
  45. package/dist/esm/generated/resources/Upload.js.map +1 -1
  46. package/dist/esm/index.d.ts +1 -0
  47. package/dist/esm/index.js +1 -0
  48. package/dist/esm/index.js.map +1 -1
  49. package/dist/esm/utilities/buildBlockRecord.d.ts +5 -31
  50. package/dist/esm/utilities/buildBlockRecord.js.map +1 -1
  51. package/dist/esm/utilities/itemDefinition.d.ts +74 -0
  52. package/dist/esm/utilities/itemDefinition.js +2 -0
  53. package/dist/esm/utilities/itemDefinition.js.map +1 -0
  54. package/dist/types/fieldTypes/lat_lon.d.ts +5 -5
  55. package/dist/types/fieldTypes/rich_text.d.ts +8 -7
  56. package/dist/types/fieldTypes/single_block.d.ts +15 -14
  57. package/dist/types/fieldTypes/structured_text.d.ts +13 -12
  58. package/dist/types/generated/ApiTypes.d.ts +67 -62
  59. package/dist/types/generated/RawApiTypes.d.ts +116 -121
  60. package/dist/types/generated/resources/Field.d.ts +230 -230
  61. package/dist/types/generated/resources/Item.d.ts +42 -24
  62. package/dist/types/generated/resources/ItemVersion.d.ts +1 -1
  63. package/dist/types/generated/resources/ScheduledPublication.d.ts +5 -2
  64. package/dist/types/generated/resources/ScheduledUnpublishing.d.ts +5 -2
  65. package/dist/types/generated/resources/Upload.d.ts +10 -2
  66. package/dist/types/index.d.ts +1 -0
  67. package/dist/types/utilities/buildBlockRecord.d.ts +5 -31
  68. package/dist/types/utilities/itemDefinition.d.ts +74 -0
  69. package/package.json +5 -5
  70. package/resources.json +564 -0
  71. package/src/fieldTypes/lat_lon.ts +7 -9
  72. package/src/fieldTypes/rich_text.ts +22 -13
  73. package/src/fieldTypes/single_block.ts +42 -32
  74. package/src/fieldTypes/structured_text.ts +60 -23
  75. package/src/generated/ApiTypes.ts +110 -70
  76. package/src/generated/Client.ts +1 -1
  77. package/src/generated/RawApiTypes.ts +160 -138
  78. package/src/generated/resources/Item.ts +360 -108
  79. package/src/generated/resources/ScheduledPublication.ts +31 -11
  80. package/src/generated/resources/ScheduledUnpublishing.ts +31 -11
  81. package/src/generated/resources/Upload.ts +54 -12
  82. package/src/index.ts +1 -0
  83. package/src/utilities/buildBlockRecord.ts +19 -3
  84. package/src/utilities/itemDefinition.ts +229 -0
@@ -1,8 +1,16 @@
1
1
  import * as Utils from '@datocms/rest-client-utils';
2
2
  import BaseResource from '../../BaseResource';
3
+ import type {
4
+ ItemTypeDefinition,
5
+ ItemTypeDefinitionToItemDefinition,
6
+ ItemTypeDefinitionToItemDefinitionAsRequest,
7
+ ItemTypeDefinitionToItemDefinitionWithNestedBlocks,
8
+ } from '../../utilities/itemDefinition';
3
9
  import type * as ApiTypes from '../ApiTypes';
4
10
  import type * as RawApiTypes from '../RawApiTypes';
5
11
 
12
+ type NoInfer<T> = [T][T extends any ? 0 : never];
13
+
6
14
  export default class Item extends BaseResource {
7
15
  static readonly TYPE = 'item' as const;
8
16
 
@@ -14,9 +22,35 @@ export default class Item extends BaseResource {
14
22
  * @throws {ApiError}
15
23
  * @throws {TimeoutError}
16
24
  */
17
- list(queryParams?: ApiTypes.ItemInstancesHrefSchema) {
18
- return this.rawList(queryParams).then((body) =>
19
- Utils.deserializeResponseBody<ApiTypes.ItemInstancesTargetSchema>(body),
25
+ list<D extends ItemTypeDefinition = ItemTypeDefinition>(
26
+ queryParams: ApiTypes.ItemInstancesHrefSchema & { nested: true },
27
+ ): Promise<
28
+ ApiTypes.ItemInstancesTargetSchema<
29
+ ItemTypeDefinitionToItemDefinitionWithNestedBlocks<NoInfer<D>>
30
+ >
31
+ >;
32
+ list<D extends ItemTypeDefinition = ItemTypeDefinition>(
33
+ queryParams?: ApiTypes.ItemInstancesHrefSchema & {
34
+ nested?: false | undefined;
35
+ },
36
+ ): Promise<
37
+ ApiTypes.ItemInstancesTargetSchema<
38
+ ItemTypeDefinitionToItemDefinition<NoInfer<D>>
39
+ >
40
+ >;
41
+ /**
42
+ * List all records
43
+ *
44
+ * Read more: https://www.datocms.com/docs/content-management-api/resources/item/instances
45
+ *
46
+ * @throws {ApiError}
47
+ * @throws {TimeoutError}
48
+ */
49
+ list<D extends ItemTypeDefinition = ItemTypeDefinition>(
50
+ queryParams?: ApiTypes.ItemInstancesHrefSchema,
51
+ ) {
52
+ return this.rawList<D>(queryParams).then((body) =>
53
+ Utils.deserializeResponseBody(body),
20
54
  );
21
55
  }
22
56
 
@@ -28,14 +62,24 @@ export default class Item extends BaseResource {
28
62
  * @throws {ApiError}
29
63
  * @throws {TimeoutError}
30
64
  */
31
- rawList(
65
+ rawList<D extends ItemTypeDefinition = ItemTypeDefinition>(
32
66
  queryParams?: RawApiTypes.ItemInstancesHrefSchema,
33
- ): Promise<RawApiTypes.ItemInstancesTargetSchema> {
34
- return this.client.request<RawApiTypes.ItemInstancesTargetSchema>({
35
- method: 'GET',
36
- url: '/items',
37
- queryParams,
38
- });
67
+ ): Promise<
68
+ RawApiTypes.ItemInstancesTargetSchema<
69
+ ItemTypeDefinitionToItemDefinitionWithNestedBlocks<NoInfer<D>>
70
+ >
71
+ > {
72
+ return this.client
73
+ .request({
74
+ method: 'GET',
75
+ url: '/items',
76
+ queryParams,
77
+ })
78
+ .then<
79
+ RawApiTypes.ItemInstancesTargetSchema<
80
+ ItemTypeDefinitionToItemDefinitionWithNestedBlocks<NoInfer<D>>
81
+ >
82
+ >(Utils.deserializeRawResponseBodyWithItems);
39
83
  }
40
84
 
41
85
  /**
@@ -46,20 +90,22 @@ export default class Item extends BaseResource {
46
90
  * @throws {ApiError}
47
91
  * @throws {TimeoutError}
48
92
  */
49
- async *listPagedIterator(
93
+ async *listPagedIterator<D extends ItemTypeDefinition = ItemTypeDefinition>(
50
94
  queryParams?: Utils.OmitFromKnownKeys<
51
95
  ApiTypes.ItemInstancesHrefSchema,
52
96
  'page'
53
97
  >,
54
98
  iteratorOptions?: Utils.IteratorOptions,
55
99
  ) {
56
- for await (const element of this.rawListPagedIterator(
100
+ for await (const element of this.rawListPagedIterator<NoInfer<D>>(
57
101
  queryParams,
58
102
  iteratorOptions,
59
103
  )) {
60
- yield Utils.deserializeJsonEntity<ApiTypes.ItemInstancesTargetSchema[0]>(
61
- element,
62
- );
104
+ yield Utils.deserializeJsonEntity<
105
+ ApiTypes.ItemInstancesTargetSchema<
106
+ ItemTypeDefinitionToItemDefinitionWithNestedBlocks<NoInfer<D>>
107
+ >[0]
108
+ >(element);
63
109
  }
64
110
  }
65
111
 
@@ -71,7 +117,7 @@ export default class Item extends BaseResource {
71
117
  * @throws {ApiError}
72
118
  * @throws {TimeoutError}
73
119
  */
74
- rawListPagedIterator(
120
+ rawListPagedIterator<D extends ItemTypeDefinition = ItemTypeDefinition>(
75
121
  queryParams?: Utils.OmitFromKnownKeys<
76
122
  RawApiTypes.ItemInstancesHrefSchema,
77
123
  'page'
@@ -81,15 +127,18 @@ export default class Item extends BaseResource {
81
127
  Utils.warnOnPageQueryParam(queryParams);
82
128
 
83
129
  return Utils.rawPageIterator<
84
- RawApiTypes.ItemInstancesTargetSchema['data'][0]
130
+ RawApiTypes.ItemInstancesTargetSchema<
131
+ ItemTypeDefinitionToItemDefinitionWithNestedBlocks<NoInfer<D>>
132
+ >['data'][0]
85
133
  >(
86
134
  {
87
135
  defaultLimit: 30,
88
136
  maxLimit: 500,
89
137
  },
90
138
  (page: RawApiTypes.ItemInstancesHrefSchema['page']) =>
91
- this.rawList({ ...queryParams, page }),
139
+ this.rawList<D>({ ...queryParams, page }),
92
140
  iteratorOptions,
141
+ true,
93
142
  );
94
143
  }
95
144
 
@@ -103,13 +152,19 @@ export default class Item extends BaseResource {
103
152
  *
104
153
  * @deprecated This API call is to be considered private and might change without notice
105
154
  */
106
- validateExisting(
155
+ validateExisting<D extends ItemTypeDefinition = ItemTypeDefinition>(
107
156
  itemId: string | ApiTypes.ItemData,
108
- body: ApiTypes.ItemValidateExistingSchema,
157
+ body: ApiTypes.ItemValidateExistingSchema<
158
+ ItemTypeDefinitionToItemDefinitionAsRequest<NoInfer<D>>
159
+ >,
109
160
  ) {
110
161
  return this.rawValidateExisting(
111
162
  Utils.toId(itemId),
112
- Utils.serializeRequestBody<RawApiTypes.ItemValidateExistingSchema>(body, {
163
+ Utils.serializeRequestBody<
164
+ RawApiTypes.ItemValidateExistingSchema<
165
+ ItemTypeDefinitionToItemDefinitionAsRequest<NoInfer<D>>
166
+ >
167
+ >(body, {
113
168
  id: Utils.toId(itemId),
114
169
  type: 'item',
115
170
  attributes: '*',
@@ -128,9 +183,11 @@ export default class Item extends BaseResource {
128
183
  *
129
184
  * @deprecated This API call is to be considered private and might change without notice
130
185
  */
131
- rawValidateExisting(
186
+ rawValidateExisting<D extends ItemTypeDefinition = ItemTypeDefinition>(
132
187
  itemId: string,
133
- body: RawApiTypes.ItemValidateExistingSchema,
188
+ body: RawApiTypes.ItemValidateExistingSchema<
189
+ ItemTypeDefinitionToItemDefinitionAsRequest<NoInfer<D>>
190
+ >,
134
191
  ): Promise<void> {
135
192
  return this.client.request<void>({
136
193
  method: 'POST',
@@ -149,9 +206,17 @@ export default class Item extends BaseResource {
149
206
  *
150
207
  * @deprecated This API call is to be considered private and might change without notice
151
208
  */
152
- validateNew(body: ApiTypes.ItemValidateNewSchema) {
209
+ validateNew<D extends ItemTypeDefinition = ItemTypeDefinition>(
210
+ body: ApiTypes.ItemValidateNewSchema<
211
+ ItemTypeDefinitionToItemDefinitionAsRequest<NoInfer<D>>
212
+ >,
213
+ ) {
153
214
  return this.rawValidateNew(
154
- Utils.serializeRequestBody<RawApiTypes.ItemValidateNewSchema>(body, {
215
+ Utils.serializeRequestBody<
216
+ RawApiTypes.ItemValidateNewSchema<
217
+ ItemTypeDefinitionToItemDefinitionAsRequest<NoInfer<D>>
218
+ >
219
+ >(body, {
155
220
  type: 'item',
156
221
  attributes: '*',
157
222
  relationships: ['item_type', 'creator'],
@@ -169,7 +234,11 @@ export default class Item extends BaseResource {
169
234
  *
170
235
  * @deprecated This API call is to be considered private and might change without notice
171
236
  */
172
- rawValidateNew(body: RawApiTypes.ItemValidateNewSchema): Promise<void> {
237
+ rawValidateNew<D extends ItemTypeDefinition = ItemTypeDefinition>(
238
+ body: RawApiTypes.ItemValidateNewSchema<
239
+ ItemTypeDefinitionToItemDefinitionAsRequest<NoInfer<D>>
240
+ >,
241
+ ): Promise<void> {
173
242
  return this.client.request<void>({
174
243
  method: 'POST',
175
244
  url: '/items/validate',
@@ -185,15 +254,27 @@ export default class Item extends BaseResource {
185
254
  * @throws {ApiError}
186
255
  * @throws {TimeoutError}
187
256
  */
188
- create(body: ApiTypes.ItemCreateSchema) {
189
- return this.rawCreate(
190
- Utils.serializeRequestBody<RawApiTypes.ItemCreateSchema>(body, {
257
+ create<D extends ItemTypeDefinition = ItemTypeDefinition>(
258
+ body: ApiTypes.ItemCreateSchema<
259
+ ItemTypeDefinitionToItemDefinitionAsRequest<NoInfer<D>>
260
+ >,
261
+ ) {
262
+ return this.rawCreate<D>(
263
+ Utils.serializeRequestBody<
264
+ RawApiTypes.ItemCreateSchema<
265
+ ItemTypeDefinitionToItemDefinitionAsRequest<NoInfer<D>>
266
+ >
267
+ >(body, {
191
268
  type: 'item',
192
269
  attributes: '*',
193
270
  relationships: ['item_type', 'creator'],
194
271
  }),
195
272
  ).then((body) =>
196
- Utils.deserializeResponseBody<ApiTypes.ItemCreateTargetSchema>(body),
273
+ Utils.deserializeResponseBody<
274
+ ApiTypes.ItemCreateTargetSchema<
275
+ ItemTypeDefinitionToItemDefinition<NoInfer<D>>
276
+ >
277
+ >(body),
197
278
  );
198
279
  }
199
280
 
@@ -205,14 +286,26 @@ export default class Item extends BaseResource {
205
286
  * @throws {ApiError}
206
287
  * @throws {TimeoutError}
207
288
  */
208
- rawCreate(
209
- body: RawApiTypes.ItemCreateSchema,
210
- ): Promise<RawApiTypes.ItemCreateTargetSchema> {
211
- return this.client.request<RawApiTypes.ItemCreateTargetSchema>({
212
- method: 'POST',
213
- url: '/items',
214
- body,
215
- });
289
+ rawCreate<D extends ItemTypeDefinition = ItemTypeDefinition>(
290
+ body: RawApiTypes.ItemCreateSchema<
291
+ ItemTypeDefinitionToItemDefinitionAsRequest<NoInfer<D>>
292
+ >,
293
+ ): Promise<
294
+ RawApiTypes.ItemCreateTargetSchema<
295
+ ItemTypeDefinitionToItemDefinitionWithNestedBlocks<NoInfer<D>>
296
+ >
297
+ > {
298
+ return this.client
299
+ .request({
300
+ method: 'POST',
301
+ url: '/items',
302
+ body: Utils.serializeRawRequestBodyWithItems(body),
303
+ })
304
+ .then<
305
+ RawApiTypes.ItemCreateTargetSchema<
306
+ ItemTypeDefinitionToItemDefinitionWithNestedBlocks<NoInfer<D>>
307
+ >
308
+ >(Utils.deserializeRawResponseBodyWithItems);
216
309
  }
217
310
 
218
311
  /**
@@ -223,9 +316,15 @@ export default class Item extends BaseResource {
223
316
  * @throws {ApiError}
224
317
  * @throws {TimeoutError}
225
318
  */
226
- duplicate(itemId: string | ApiTypes.ItemData) {
227
- return this.rawDuplicate(Utils.toId(itemId)).then((body) =>
228
- Utils.deserializeResponseBody<ApiTypes.ItemDuplicateJobSchema>(body),
319
+ duplicate<D extends ItemTypeDefinition = ItemTypeDefinition>(
320
+ itemId: string | ApiTypes.ItemData,
321
+ ) {
322
+ return this.rawDuplicate<D>(Utils.toId(itemId)).then((body) =>
323
+ Utils.deserializeResponseBody<
324
+ ApiTypes.ItemDuplicateJobSchema<
325
+ ItemTypeDefinitionToItemDefinition<NoInfer<D>>
326
+ >
327
+ >(body),
229
328
  );
230
329
  }
231
330
 
@@ -237,11 +336,23 @@ export default class Item extends BaseResource {
237
336
  * @throws {ApiError}
238
337
  * @throws {TimeoutError}
239
338
  */
240
- rawDuplicate(itemId: string): Promise<RawApiTypes.ItemDuplicateJobSchema> {
241
- return this.client.request<RawApiTypes.ItemDuplicateJobSchema>({
242
- method: 'POST',
243
- url: `/items/${itemId}/duplicate`,
244
- });
339
+ rawDuplicate<D extends ItemTypeDefinition = ItemTypeDefinition>(
340
+ itemId: string,
341
+ ): Promise<
342
+ RawApiTypes.ItemDuplicateJobSchema<
343
+ ItemTypeDefinitionToItemDefinitionWithNestedBlocks<NoInfer<D>>
344
+ >
345
+ > {
346
+ return this.client
347
+ .request({
348
+ method: 'POST',
349
+ url: `/items/${itemId}/duplicate`,
350
+ })
351
+ .then<
352
+ RawApiTypes.ItemDuplicateJobSchema<
353
+ ItemTypeDefinitionToItemDefinitionWithNestedBlocks<NoInfer<D>>
354
+ >
355
+ >(Utils.deserializeRawResponseBodyWithItems);
245
356
  }
246
357
 
247
358
  /**
@@ -252,17 +363,30 @@ export default class Item extends BaseResource {
252
363
  * @throws {ApiError}
253
364
  * @throws {TimeoutError}
254
365
  */
255
- update(itemId: string | ApiTypes.ItemData, body: ApiTypes.ItemUpdateSchema) {
256
- return this.rawUpdate(
366
+ update<D extends ItemTypeDefinition = ItemTypeDefinition>(
367
+ itemId: string | ApiTypes.ItemData,
368
+ body: ApiTypes.ItemUpdateSchema<
369
+ ItemTypeDefinitionToItemDefinitionAsRequest<NoInfer<D>>
370
+ >,
371
+ ) {
372
+ return this.rawUpdate<D>(
257
373
  Utils.toId(itemId),
258
- Utils.serializeRequestBody<RawApiTypes.ItemUpdateSchema>(body, {
374
+ Utils.serializeRequestBody<
375
+ RawApiTypes.ItemUpdateSchema<
376
+ ItemTypeDefinitionToItemDefinitionAsRequest<NoInfer<D>>
377
+ >
378
+ >(body, {
259
379
  id: Utils.toId(itemId),
260
380
  type: 'item',
261
381
  attributes: '*',
262
382
  relationships: ['item_type', 'creator'],
263
383
  }),
264
384
  ).then((body) =>
265
- Utils.deserializeResponseBody<ApiTypes.ItemUpdateTargetSchema>(body),
385
+ Utils.deserializeResponseBody<
386
+ ApiTypes.ItemUpdateTargetSchema<
387
+ ItemTypeDefinitionToItemDefinition<NoInfer<D>>
388
+ >
389
+ >(body),
266
390
  );
267
391
  }
268
392
 
@@ -274,15 +398,27 @@ export default class Item extends BaseResource {
274
398
  * @throws {ApiError}
275
399
  * @throws {TimeoutError}
276
400
  */
277
- rawUpdate(
401
+ rawUpdate<D extends ItemTypeDefinition = ItemTypeDefinition>(
278
402
  itemId: string,
279
- body: RawApiTypes.ItemUpdateSchema,
280
- ): Promise<RawApiTypes.ItemUpdateTargetSchema> {
281
- return this.client.request<RawApiTypes.ItemUpdateTargetSchema>({
282
- method: 'PUT',
283
- url: `/items/${itemId}`,
284
- body,
285
- });
403
+ body: RawApiTypes.ItemUpdateSchema<
404
+ ItemTypeDefinitionToItemDefinitionAsRequest<NoInfer<D>>
405
+ >,
406
+ ): Promise<
407
+ RawApiTypes.ItemUpdateTargetSchema<
408
+ ItemTypeDefinitionToItemDefinitionWithNestedBlocks<NoInfer<D>>
409
+ >
410
+ > {
411
+ return this.client
412
+ .request({
413
+ method: 'PUT',
414
+ url: `/items/${itemId}`,
415
+ body: Utils.serializeRawRequestBodyWithItems(body),
416
+ })
417
+ .then<
418
+ RawApiTypes.ItemUpdateTargetSchema<
419
+ ItemTypeDefinitionToItemDefinitionWithNestedBlocks<NoInfer<D>>
420
+ >
421
+ >(Utils.deserializeRawResponseBodyWithItems);
286
422
  }
287
423
 
288
424
  /**
@@ -293,12 +429,38 @@ export default class Item extends BaseResource {
293
429
  * @throws {ApiError}
294
430
  * @throws {TimeoutError}
295
431
  */
296
- references(
432
+ references<D extends ItemTypeDefinition = ItemTypeDefinition>(
433
+ itemId: string | ApiTypes.ItemData,
434
+ queryParams: ApiTypes.ItemReferencesHrefSchema & { nested: true },
435
+ ): Promise<
436
+ ApiTypes.ItemReferencesTargetSchema<
437
+ ItemTypeDefinitionToItemDefinitionWithNestedBlocks<NoInfer<D>>
438
+ >
439
+ >;
440
+ references<D extends ItemTypeDefinition = ItemTypeDefinition>(
441
+ itemId: string | ApiTypes.ItemData,
442
+ queryParams?: ApiTypes.ItemReferencesHrefSchema & {
443
+ nested?: false | undefined;
444
+ },
445
+ ): Promise<
446
+ ApiTypes.ItemReferencesTargetSchema<
447
+ ItemTypeDefinitionToItemDefinition<NoInfer<D>>
448
+ >
449
+ >;
450
+ /**
451
+ * Referenced records
452
+ *
453
+ * Read more: https://www.datocms.com/docs/content-management-api/resources/item/references
454
+ *
455
+ * @throws {ApiError}
456
+ * @throws {TimeoutError}
457
+ */
458
+ references<D extends ItemTypeDefinition = ItemTypeDefinition>(
297
459
  itemId: string | ApiTypes.ItemData,
298
460
  queryParams?: ApiTypes.ItemReferencesHrefSchema,
299
461
  ) {
300
- return this.rawReferences(Utils.toId(itemId), queryParams).then((body) =>
301
- Utils.deserializeResponseBody<ApiTypes.ItemReferencesTargetSchema>(body),
462
+ return this.rawReferences<D>(Utils.toId(itemId), queryParams).then((body) =>
463
+ Utils.deserializeResponseBody(body),
302
464
  );
303
465
  }
304
466
 
@@ -310,15 +472,25 @@ export default class Item extends BaseResource {
310
472
  * @throws {ApiError}
311
473
  * @throws {TimeoutError}
312
474
  */
313
- rawReferences(
475
+ rawReferences<D extends ItemTypeDefinition = ItemTypeDefinition>(
314
476
  itemId: string,
315
477
  queryParams?: RawApiTypes.ItemReferencesHrefSchema,
316
- ): Promise<RawApiTypes.ItemReferencesTargetSchema> {
317
- return this.client.request<RawApiTypes.ItemReferencesTargetSchema>({
318
- method: 'GET',
319
- url: `/items/${itemId}/references`,
320
- queryParams,
321
- });
478
+ ): Promise<
479
+ RawApiTypes.ItemReferencesTargetSchema<
480
+ ItemTypeDefinitionToItemDefinitionWithNestedBlocks<NoInfer<D>>
481
+ >
482
+ > {
483
+ return this.client
484
+ .request({
485
+ method: 'GET',
486
+ url: `/items/${itemId}/references`,
487
+ queryParams,
488
+ })
489
+ .then<
490
+ RawApiTypes.ItemReferencesTargetSchema<
491
+ ItemTypeDefinitionToItemDefinitionWithNestedBlocks<NoInfer<D>>
492
+ >
493
+ >(Utils.deserializeRawResponseBodyWithItems);
322
494
  }
323
495
 
324
496
  /**
@@ -329,12 +501,36 @@ export default class Item extends BaseResource {
329
501
  * @throws {ApiError}
330
502
  * @throws {TimeoutError}
331
503
  */
332
- find(
504
+ find<D extends ItemTypeDefinition = ItemTypeDefinition>(
505
+ itemId: string | ApiTypes.ItemData,
506
+ queryParams: ApiTypes.ItemSelfHrefSchema & { nested: true },
507
+ ): Promise<
508
+ ApiTypes.ItemSelfTargetSchema<
509
+ ItemTypeDefinitionToItemDefinitionWithNestedBlocks<NoInfer<D>>
510
+ >
511
+ >;
512
+ find<D extends ItemTypeDefinition = ItemTypeDefinition>(
513
+ itemId: string | ApiTypes.ItemData,
514
+ queryParams?: ApiTypes.ItemSelfHrefSchema & { nested?: false | undefined },
515
+ ): Promise<
516
+ ApiTypes.ItemSelfTargetSchema<
517
+ ItemTypeDefinitionToItemDefinition<NoInfer<D>>
518
+ >
519
+ >;
520
+ /**
521
+ * Retrieve a record
522
+ *
523
+ * Read more: https://www.datocms.com/docs/content-management-api/resources/item/self
524
+ *
525
+ * @throws {ApiError}
526
+ * @throws {TimeoutError}
527
+ */
528
+ find<D extends ItemTypeDefinition = ItemTypeDefinition>(
333
529
  itemId: string | ApiTypes.ItemData,
334
530
  queryParams?: ApiTypes.ItemSelfHrefSchema,
335
531
  ) {
336
- return this.rawFind(Utils.toId(itemId), queryParams).then((body) =>
337
- Utils.deserializeResponseBody<ApiTypes.ItemSelfTargetSchema>(body),
532
+ return this.rawFind<D>(Utils.toId(itemId), queryParams).then((body) =>
533
+ Utils.deserializeResponseBody(body),
338
534
  );
339
535
  }
340
536
 
@@ -346,15 +542,25 @@ export default class Item extends BaseResource {
346
542
  * @throws {ApiError}
347
543
  * @throws {TimeoutError}
348
544
  */
349
- rawFind(
545
+ rawFind<D extends ItemTypeDefinition = ItemTypeDefinition>(
350
546
  itemId: string,
351
547
  queryParams?: RawApiTypes.ItemSelfHrefSchema,
352
- ): Promise<RawApiTypes.ItemSelfTargetSchema> {
353
- return this.client.request<RawApiTypes.ItemSelfTargetSchema>({
354
- method: 'GET',
355
- url: `/items/${itemId}`,
356
- queryParams,
357
- });
548
+ ): Promise<
549
+ RawApiTypes.ItemSelfTargetSchema<
550
+ ItemTypeDefinitionToItemDefinitionWithNestedBlocks<NoInfer<D>>
551
+ >
552
+ > {
553
+ return this.client
554
+ .request({
555
+ method: 'GET',
556
+ url: `/items/${itemId}`,
557
+ queryParams,
558
+ })
559
+ .then<
560
+ RawApiTypes.ItemSelfTargetSchema<
561
+ ItemTypeDefinitionToItemDefinitionWithNestedBlocks<NoInfer<D>>
562
+ >
563
+ >(Utils.deserializeRawResponseBodyWithItems);
358
564
  }
359
565
 
360
566
  /**
@@ -404,9 +610,15 @@ export default class Item extends BaseResource {
404
610
  * @throws {ApiError}
405
611
  * @throws {TimeoutError}
406
612
  */
407
- destroy(itemId: string | ApiTypes.ItemData) {
408
- return this.rawDestroy(Utils.toId(itemId)).then((body) =>
409
- Utils.deserializeResponseBody<ApiTypes.ItemDestroyJobSchema>(body),
613
+ destroy<D extends ItemTypeDefinition = ItemTypeDefinition>(
614
+ itemId: string | ApiTypes.ItemData,
615
+ ) {
616
+ return this.rawDestroy<D>(Utils.toId(itemId)).then((body) =>
617
+ Utils.deserializeResponseBody<
618
+ ApiTypes.ItemDestroyJobSchema<
619
+ ItemTypeDefinitionToItemDefinition<NoInfer<D>>
620
+ >
621
+ >(body),
410
622
  );
411
623
  }
412
624
 
@@ -418,11 +630,23 @@ export default class Item extends BaseResource {
418
630
  * @throws {ApiError}
419
631
  * @throws {TimeoutError}
420
632
  */
421
- rawDestroy(itemId: string): Promise<RawApiTypes.ItemDestroyJobSchema> {
422
- return this.client.request<RawApiTypes.ItemDestroyJobSchema>({
423
- method: 'DELETE',
424
- url: `/items/${itemId}`,
425
- });
633
+ rawDestroy<D extends ItemTypeDefinition = ItemTypeDefinition>(
634
+ itemId: string,
635
+ ): Promise<
636
+ RawApiTypes.ItemDestroyJobSchema<
637
+ ItemTypeDefinitionToItemDefinitionWithNestedBlocks<NoInfer<D>>
638
+ >
639
+ > {
640
+ return this.client
641
+ .request({
642
+ method: 'DELETE',
643
+ url: `/items/${itemId}`,
644
+ })
645
+ .then<
646
+ RawApiTypes.ItemDestroyJobSchema<
647
+ ItemTypeDefinitionToItemDefinitionWithNestedBlocks<NoInfer<D>>
648
+ >
649
+ >(Utils.deserializeRawResponseBodyWithItems);
426
650
  }
427
651
 
428
652
  /**
@@ -433,12 +657,12 @@ export default class Item extends BaseResource {
433
657
  * @throws {ApiError}
434
658
  * @throws {TimeoutError}
435
659
  */
436
- publish(
660
+ publish<D extends ItemTypeDefinition = ItemTypeDefinition>(
437
661
  itemId: string | ApiTypes.ItemData,
438
662
  body?: ApiTypes.ItemPublishSchema,
439
663
  queryParams?: ApiTypes.ItemPublishHrefSchema,
440
664
  ) {
441
- return this.rawPublish(
665
+ return this.rawPublish<D>(
442
666
  Utils.toId(itemId),
443
667
  body
444
668
  ? Utils.serializeRequestBody<RawApiTypes.ItemPublishSchema>(body, {
@@ -449,7 +673,11 @@ export default class Item extends BaseResource {
449
673
  : null,
450
674
  queryParams,
451
675
  ).then((body) =>
452
- Utils.deserializeResponseBody<ApiTypes.ItemPublishTargetSchema>(body),
676
+ Utils.deserializeResponseBody<
677
+ ApiTypes.ItemPublishTargetSchema<
678
+ ItemTypeDefinitionToItemDefinition<NoInfer<D>>
679
+ >
680
+ >(body),
453
681
  );
454
682
  }
455
683
 
@@ -461,17 +689,27 @@ export default class Item extends BaseResource {
461
689
  * @throws {ApiError}
462
690
  * @throws {TimeoutError}
463
691
  */
464
- rawPublish(
692
+ rawPublish<D extends ItemTypeDefinition = ItemTypeDefinition>(
465
693
  itemId: string,
466
694
  body?: RawApiTypes.ItemPublishSchema,
467
695
  queryParams?: RawApiTypes.ItemPublishHrefSchema,
468
- ): Promise<RawApiTypes.ItemPublishTargetSchema> {
469
- return this.client.request<RawApiTypes.ItemPublishTargetSchema>({
470
- method: 'PUT',
471
- url: `/items/${itemId}/publish`,
472
- body,
473
- queryParams,
474
- });
696
+ ): Promise<
697
+ RawApiTypes.ItemPublishTargetSchema<
698
+ ItemTypeDefinitionToItemDefinitionWithNestedBlocks<NoInfer<D>>
699
+ >
700
+ > {
701
+ return this.client
702
+ .request({
703
+ method: 'PUT',
704
+ url: `/items/${itemId}/publish`,
705
+ body: Utils.serializeRawRequestBodyWithItems(body),
706
+ queryParams,
707
+ })
708
+ .then<
709
+ RawApiTypes.ItemPublishTargetSchema<
710
+ ItemTypeDefinitionToItemDefinitionWithNestedBlocks<NoInfer<D>>
711
+ >
712
+ >(Utils.deserializeRawResponseBodyWithItems);
475
713
  }
476
714
 
477
715
  /**
@@ -482,12 +720,12 @@ export default class Item extends BaseResource {
482
720
  * @throws {ApiError}
483
721
  * @throws {TimeoutError}
484
722
  */
485
- unpublish(
723
+ unpublish<D extends ItemTypeDefinition = ItemTypeDefinition>(
486
724
  itemId: string | ApiTypes.ItemData,
487
725
  body?: ApiTypes.ItemUnpublishSchema,
488
726
  queryParams?: ApiTypes.ItemUnpublishHrefSchema,
489
727
  ) {
490
- return this.rawUnpublish(
728
+ return this.rawUnpublish<D>(
491
729
  Utils.toId(itemId),
492
730
  body
493
731
  ? Utils.serializeRequestBody<RawApiTypes.ItemUnpublishSchema>(body, {
@@ -498,7 +736,11 @@ export default class Item extends BaseResource {
498
736
  : null,
499
737
  queryParams,
500
738
  ).then((body) =>
501
- Utils.deserializeResponseBody<ApiTypes.ItemUnpublishTargetSchema>(body),
739
+ Utils.deserializeResponseBody<
740
+ ApiTypes.ItemUnpublishTargetSchema<
741
+ ItemTypeDefinitionToItemDefinition<NoInfer<D>>
742
+ >
743
+ >(body),
502
744
  );
503
745
  }
504
746
 
@@ -510,17 +752,27 @@ export default class Item extends BaseResource {
510
752
  * @throws {ApiError}
511
753
  * @throws {TimeoutError}
512
754
  */
513
- rawUnpublish(
755
+ rawUnpublish<D extends ItemTypeDefinition = ItemTypeDefinition>(
514
756
  itemId: string,
515
757
  body?: RawApiTypes.ItemUnpublishSchema,
516
758
  queryParams?: RawApiTypes.ItemUnpublishHrefSchema,
517
- ): Promise<RawApiTypes.ItemUnpublishTargetSchema> {
518
- return this.client.request<RawApiTypes.ItemUnpublishTargetSchema>({
519
- method: 'PUT',
520
- url: `/items/${itemId}/unpublish`,
521
- body,
522
- queryParams,
523
- });
759
+ ): Promise<
760
+ RawApiTypes.ItemUnpublishTargetSchema<
761
+ ItemTypeDefinitionToItemDefinitionWithNestedBlocks<NoInfer<D>>
762
+ >
763
+ > {
764
+ return this.client
765
+ .request({
766
+ method: 'PUT',
767
+ url: `/items/${itemId}/unpublish`,
768
+ body: Utils.serializeRawRequestBodyWithItems(body),
769
+ queryParams,
770
+ })
771
+ .then<
772
+ RawApiTypes.ItemUnpublishTargetSchema<
773
+ ItemTypeDefinitionToItemDefinitionWithNestedBlocks<NoInfer<D>>
774
+ >
775
+ >(Utils.deserializeRawResponseBodyWithItems);
524
776
  }
525
777
 
526
778
  /**