@datocms/cma-client 5.1.12 → 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.
@@ -1,6 +1,14 @@
1
1
  import type { NewBlockInRequest } from '../fieldTypes';
2
2
  import type * as ApiTypes from '../generated/ApiTypes';
3
- import type { ItemTypeDefinition } from './itemDefinition';
3
+ import type { ItemTypeDefinition, ToItemAttributesInRequest } from './itemDefinition';
4
4
  type NoInfer<T> = [T][T extends any ? 0 : never];
5
- export declare function buildBlockRecord<D extends ItemTypeDefinition = ItemTypeDefinition>(body: ApiTypes.ItemUpdateSchema<NoInfer<D>>): NewBlockInRequest<NoInfer<D>>;
5
+ type UpdateOrCreateBlockRecordSchema<D extends ItemTypeDefinition = ItemTypeDefinition> = {
6
+ id?: ApiTypes.ItemIdentity;
7
+ type?: ApiTypes.ItemType1;
8
+ item_type: ApiTypes.ItemTypeData<D>;
9
+ meta?: ApiTypes.ItemUpdateSchema['meta'];
10
+ creator?: ApiTypes.ItemUpdateSchema['creator'];
11
+ __itemTypeId?: D['itemTypeId'];
12
+ } & ToItemAttributesInRequest<D>;
13
+ export declare function buildBlockRecord<D extends ItemTypeDefinition = ItemTypeDefinition>(body: UpdateOrCreateBlockRecordSchema<NoInfer<D>>): NewBlockInRequest<NoInfer<D>>;
6
14
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@datocms/cma-client",
3
- "version": "5.1.12",
3
+ "version": "5.1.13",
4
4
  "description": "JS client for DatoCMS REST Content Management API",
5
5
  "keywords": [
6
6
  "datocms",
@@ -37,13 +37,13 @@
37
37
  "url": "https://github.com/datocms/js-rest-api-clients/issues"
38
38
  },
39
39
  "dependencies": {
40
- "@datocms/rest-client-utils": "^5.1.6",
40
+ "@datocms/rest-client-utils": "^5.1.13",
41
41
  "datocms-structured-text-utils": "^5.1.4",
42
42
  "uuid": "^9.0.1"
43
43
  },
44
44
  "devDependencies": {
45
- "@datocms/dashboard-client": "^5.1.12",
45
+ "@datocms/dashboard-client": "^5.1.13",
46
46
  "@types/uuid": "^9.0.7"
47
47
  },
48
- "gitHead": "20ef29ad11049203a14461a9565e0f7833593867"
48
+ "gitHead": "966b5835bf69f9e87b34f2075a8596c9208e07c0"
49
49
  }
@@ -93,7 +93,7 @@ type LocalizedFieldAttributesForFieldType<
93
93
  > & {
94
94
  field_type: FieldType;
95
95
  localized: true;
96
- default_value: FieldValue | Record<string, FieldValue>;
96
+ default_value: Record<string, FieldValue>;
97
97
  validators: FieldValidators;
98
98
  appearance: FieldAppearanceConfig<FieldAppearance>;
99
99
  };
@@ -68,7 +68,7 @@ export type UpdatedBlockInRequest<
68
68
  __itemTypeId?: D['itemTypeId'];
69
69
  type: RawApiTypes.ItemType1;
70
70
  id: RawApiTypes.ItemIdentity;
71
- relationships?: RawApiTypes.ItemRelationships<D>;
71
+ relationships: RawApiTypes.ItemRelationships<D>;
72
72
  meta?: RawApiTypes.ItemMeta;
73
73
  attributes: ToItemAttributesInRequest<D>;
74
74
  };
@@ -7412,6 +7412,7 @@ export type ItemValidateExistingSchema<
7412
7412
  | UserData
7413
7413
  | SsoUserData
7414
7414
  | OrganizationData;
7415
+ __itemTypeId?: D['itemTypeId'];
7415
7416
  } & ToItemAttributesInRequest<D>;
7416
7417
  /**
7417
7418
  * This interface was referenced by `Item`'s JSON-Schema
@@ -7428,6 +7429,7 @@ export type ItemValidateNewSchema<
7428
7429
  | UserData
7429
7430
  | SsoUserData
7430
7431
  | OrganizationData;
7432
+ __itemTypeId?: D['itemTypeId'];
7431
7433
  } & ToItemAttributesInRequest<D>;
7432
7434
  /**
7433
7435
  * This interface was referenced by `Item`'s JSON-Schema
@@ -7490,6 +7492,7 @@ export type ItemCreateSchema<
7490
7492
  */
7491
7493
  current_version?: string;
7492
7494
  };
7495
+ __itemTypeId?: D['itemTypeId'];
7493
7496
  } & ToItemAttributesInRequest<D>;
7494
7497
  /**
7495
7498
  * This interface was referenced by `Item`'s JSON-Schema
@@ -7564,6 +7567,7 @@ export type ItemUpdateSchema<
7564
7567
  */
7565
7568
  has_children?: null | boolean;
7566
7569
  };
7570
+ __itemTypeId?: D['itemTypeId'];
7567
7571
  } & ToItemAttributesInRequest<D>;
7568
7572
  /**
7569
7573
  * Information about the record
@@ -147,7 +147,7 @@ export class Client {
147
147
  ...this.config,
148
148
  ...options,
149
149
  logFn: this.config.logFn || console.log,
150
- userAgent: '@datocms/cma-client v5.1.12',
150
+ userAgent: '@datocms/cma-client v5.1.13',
151
151
  baseUrl: this.baseUrl,
152
152
  preCallStack: new Error().stack,
153
153
  extraHeaders: {
@@ -7133,6 +7133,7 @@ export type ItemValidateExistingSchema<
7133
7133
  | OrganizationData;
7134
7134
  };
7135
7135
  };
7136
+ __itemTypeId?: D['itemTypeId'];
7136
7137
  };
7137
7138
  };
7138
7139
  /**
@@ -7167,6 +7168,7 @@ export type ItemValidateNewSchema<
7167
7168
  | OrganizationData;
7168
7169
  };
7169
7170
  };
7171
+ __itemTypeId?: D['itemTypeId'];
7170
7172
  };
7171
7173
  };
7172
7174
  /**
@@ -7247,6 +7249,7 @@ export type ItemCreateSchema<
7247
7249
  | OrganizationData;
7248
7250
  };
7249
7251
  };
7252
+ __itemTypeId?: D['itemTypeId'];
7250
7253
  };
7251
7254
  };
7252
7255
  /**
@@ -7378,6 +7381,7 @@ export type ItemUpdateSchema<
7378
7381
  | OrganizationData;
7379
7382
  };
7380
7383
  };
7384
+ __itemTypeId?: D['itemTypeId'];
7381
7385
  };
7382
7386
  };
7383
7387
  /**
@@ -2,13 +2,29 @@ import * as Utils from '@datocms/rest-client-utils';
2
2
  import type { NewBlockInRequest } from '../fieldTypes';
3
3
  import type * as ApiTypes from '../generated/ApiTypes';
4
4
  import { Item } from '../generated/resources';
5
- import type { ItemTypeDefinition } from './itemDefinition';
5
+ import type {
6
+ ItemTypeDefinition,
7
+ ToItemAttributesInRequest,
8
+ } from './itemDefinition';
6
9
 
7
10
  type NoInfer<T> = [T][T extends any ? 0 : never];
8
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
+
9
23
  export function buildBlockRecord<
10
24
  D extends ItemTypeDefinition = ItemTypeDefinition,
11
- >(body: ApiTypes.ItemUpdateSchema<NoInfer<D>>): NewBlockInRequest<NoInfer<D>> {
25
+ >(
26
+ body: UpdateOrCreateBlockRecordSchema<NoInfer<D>>,
27
+ ): NewBlockInRequest<NoInfer<D>> {
12
28
  return Utils.serializeRequestBody<{
13
29
  data: NewBlockInRequest<NoInfer<D>>;
14
30
  }>(body, {
@@ -14,13 +14,14 @@ export async function duplicateBlockRecord<
14
14
  existingBlock: ItemWithOptionalIdAndMeta<NoInfer<D>>,
15
15
  schemaRepository: SchemaRepository,
16
16
  ): Promise<NewBlockInRequest<NoInfer<D>>> {
17
- const { type, attributes, relationships } = existingBlock;
17
+ const { __itemTypeId, type, attributes, relationships } = existingBlock;
18
18
 
19
19
  const itemType = await schemaRepository.getRawItemTypeById(
20
20
  existingBlock.relationships.item_type.data.id,
21
21
  );
22
22
 
23
23
  const newBlock = {
24
+ __itemTypeId,
24
25
  type,
25
26
  relationships,
26
27
  attributes,