@datocms/cma-client 5.4.12 → 5.4.14

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 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/fieldTypes/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,wDAAsC;AACtC,+CAA6B;AAC7B,6CAA2B;AAC3B,4CAA0B;AAC1B,iDAA+B;AAC/B,4CAA0B;AAC1B,6CAA2B;AAC3B,+CAA6B;AAC7B,+CAA6B;AAC7B,4CAA0B;AAC1B,+CAA6B;AAC7B,4CAA0B;AAC1B,6CAA2B;AAC3B,iDAA+B;AAC/B,2CAAyB;AACzB,oDAAkC;AAClC,4CAA0B;AAC1B,8CAA4B;AAC5B,uDAAqC;AACrC,4CAA0B;AAC1B,wDAAsC;AACtC,6CAA2B"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/fieldTypes/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAwGA,wDAAsC;AACtC,+CAA6B;AAC7B,6CAA2B;AAC3B,4CAA0B;AAC1B,iDAA+B;AAC/B,4CAA0B;AAC1B,6CAA2B;AAC3B,+CAA6B;AAC7B,+CAA6B;AAC7B,4CAA0B;AAC1B,+CAA6B;AAC7B,4CAA0B;AAC1B,6CAA2B;AAC3B,iDAA+B;AAC/B,2CAAyB;AACzB,oDAAkC;AAClC,4CAA0B;AAC1B,8CAA4B;AAC5B,uDAAqC;AACrC,4CAA0B;AAC1B,wDAAsC;AACtC,6CAA2B"}
@@ -90,7 +90,7 @@ class Client {
90
90
  return this.config.baseUrl || Client.defaultBaseUrl;
91
91
  }
92
92
  request(options) {
93
- return (0, rest_client_utils_1.request)(Object.assign(Object.assign(Object.assign({}, this.config), options), { logFn: this.config.logFn || console.log, userAgent: '@datocms/cma-client v5.4.12', baseUrl: this.baseUrl, preCallStack: new Error().stack, extraHeaders: Object.assign(Object.assign(Object.assign({}, (this.config.extraHeaders || {})), (this.config.environment
93
+ return (0, rest_client_utils_1.request)(Object.assign(Object.assign(Object.assign({}, this.config), options), { logFn: this.config.logFn || console.log, userAgent: '@datocms/cma-client v5.4.14', baseUrl: this.baseUrl, preCallStack: new Error().stack, extraHeaders: Object.assign(Object.assign(Object.assign({}, (this.config.extraHeaders || {})), (this.config.environment
94
94
  ? { 'X-Environment': this.config.environment }
95
95
  : {})), { 'X-API-Version': '3' }), fetchJobResult: (jobId) => {
96
96
  return this.jobResultsFetcher
@@ -1,3 +1,72 @@
1
+ import type * as ApiTypes from '../generated/ApiTypes.js';
2
+ import type * as RawApiTypes from '../generated/RawApiTypes.js';
3
+ import type { ItemTypeDefinition, ToItemAttributes, ToItemAttributesInNestedResponse, ToItemAttributesInRequest } from '../utilities/itemDefinition.js';
4
+ type ItemTypeDefinitionOf<T> = T extends ItemTypeDefinition<any, any, any> ? T : T extends ApiTypes.Item<infer D> ? D : T extends ApiTypes.ItemInNestedResponse<infer D> ? D : T extends RawApiTypes.Item<infer D> ? D : T extends RawApiTypes.ItemInNestedResponse<infer D> ? D : never;
5
+ /**
6
+ * Given a record or block you've read from the CMA and one of its field keys,
7
+ * resolves to the type you'd send back when writing that field — for example,
8
+ * inside the payload of `client.items.update`.
9
+ *
10
+ * Reach for it when you're rebuilding a field value piece-by-piece (typically
11
+ * an array of blocks or links) and want a type for the variable you're
12
+ * collecting into, without restating the field's shape by hand.
13
+ *
14
+ * The first parameter accepts any item-shaped value the CMA produces:
15
+ * top-level records as well as nested blocks inside a parent record's
16
+ * modular-content / structured-text / single-block field. You can also pass
17
+ * an `ItemTypeDefinition` directly when you already have the definition type
18
+ * in hand and don't need to round-trip through an `ApiTypes.Item<…>` shape.
19
+ *
20
+ * @example
21
+ * // Read a record with nested blocks, edit one block, write the whole field
22
+ * // back to the CMA.
23
+ * const page = await client.items.find<LandingPage>(id, { nested: true });
24
+ *
25
+ * const sections: NonNullable<FieldValueInRequest<typeof page, 'sections'>> = [];
26
+ *
27
+ * for (const block of page.sections) {
28
+ * if (isBlockOfType(HeroBlock.ID, block)) {
29
+ * sections.push(buildBlockRecord<HeroBlock>({ id: block.id, title: 'New' }));
30
+ * } else {
31
+ * sections.push(block.id);
32
+ * }
33
+ * }
34
+ *
35
+ * await client.items.update<LandingPage>(page.id, { sections });
36
+ */
37
+ export type FieldValueInRequest<T, K extends keyof ToItemAttributesInRequest<ItemTypeDefinitionOf<T>>> = K extends keyof ToItemAttributesInRequest<ItemTypeDefinitionOf<T>> ? Required<ToItemAttributesInRequest<ItemTypeDefinitionOf<T>>>[K] : never;
38
+ /**
39
+ * Given a record or block you've read from the CMA and one of its field keys,
40
+ * resolves to the field's value type as it appears in a standard (non-nested)
41
+ * response — for example, what you'd read off `record.attributes[fieldKey]`
42
+ * after `client.items.find(id)`.
43
+ *
44
+ * The first parameter accepts any item-shaped value the CMA produces, or an
45
+ * `ItemTypeDefinition` directly.
46
+ *
47
+ * @example
48
+ * // Read nested, then collect just the block IDs for an outline view.
49
+ * const page = await client.items.find<LandingPage>(id, { nested: true });
50
+ * const sectionIds: FieldValue<typeof page, 'sections'> = page.sections.map(
51
+ * (block) => block.id,
52
+ * );
53
+ */
54
+ export type FieldValue<T, K extends keyof ToItemAttributes<ItemTypeDefinitionOf<T>>> = K extends keyof ToItemAttributes<ItemTypeDefinitionOf<T>> ? ToItemAttributes<ItemTypeDefinitionOf<T>>[K] : never;
55
+ /**
56
+ * Given a record or block you've read from the CMA and one of its field keys,
57
+ * resolves to the field's value type in a nested response — i.e. what you'd
58
+ * read off the field after `client.items.find(id, { nested: true })`, where
59
+ * blocks are inlined as full objects instead of ID strings.
60
+ *
61
+ * The first parameter accepts any item-shaped value the CMA produces, or an
62
+ * `ItemTypeDefinition` directly.
63
+ *
64
+ * @example
65
+ * const page = await client.items.find<LandingPage>(id, { nested: true });
66
+ * const sections: FieldValueInNestedResponse<typeof page, 'sections'> = page.sections;
67
+ * // sections elements are full block objects, not ID strings.
68
+ */
69
+ export type FieldValueInNestedResponse<T, K extends keyof ToItemAttributesInNestedResponse<ItemTypeDefinitionOf<T>>> = K extends keyof ToItemAttributesInNestedResponse<ItemTypeDefinitionOf<T>> ? ToItemAttributesInNestedResponse<ItemTypeDefinitionOf<T>>[K] : never;
1
70
  export * from './appearance/index.js';
2
71
  export * from './boolean.js';
3
72
  export * from './color.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/fieldTypes/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,UAAU,CAAC;AACzB,cAAc,mBAAmB,CAAC;AAClC,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,sBAAsB,CAAC;AACrC,cAAc,WAAW,CAAC;AAC1B,cAAc,uBAAuB,CAAC;AACtC,cAAc,YAAY,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/fieldTypes/index.ts"],"names":[],"mappings":"AAwGA,cAAc,uBAAuB,CAAC;AACtC,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,UAAU,CAAC;AACzB,cAAc,mBAAmB,CAAC;AAClC,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,sBAAsB,CAAC;AACrC,cAAc,WAAW,CAAC;AAC1B,cAAc,uBAAuB,CAAC;AACtC,cAAc,YAAY,CAAC"}
@@ -64,7 +64,7 @@ export class Client {
64
64
  return this.config.baseUrl || Client.defaultBaseUrl;
65
65
  }
66
66
  request(options) {
67
- return request(Object.assign(Object.assign(Object.assign({}, this.config), options), { logFn: this.config.logFn || console.log, userAgent: '@datocms/cma-client v5.4.12', baseUrl: this.baseUrl, preCallStack: new Error().stack, extraHeaders: Object.assign(Object.assign(Object.assign({}, (this.config.extraHeaders || {})), (this.config.environment
67
+ return request(Object.assign(Object.assign(Object.assign({}, this.config), options), { logFn: this.config.logFn || console.log, userAgent: '@datocms/cma-client v5.4.14', baseUrl: this.baseUrl, preCallStack: new Error().stack, extraHeaders: Object.assign(Object.assign(Object.assign({}, (this.config.extraHeaders || {})), (this.config.environment
68
68
  ? { 'X-Environment': this.config.environment }
69
69
  : {})), { 'X-API-Version': '3' }), fetchJobResult: (jobId) => {
70
70
  return this.jobResultsFetcher