@datocms/cma-client 5.4.12 → 5.4.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/dist/cjs/fieldTypes/index.js.map +1 -1
- package/dist/cjs/generated/Client.js +1 -1
- package/dist/esm/fieldTypes/index.d.ts +38 -0
- package/dist/esm/fieldTypes/index.js.map +1 -1
- package/dist/esm/generated/Client.js +1 -1
- package/dist/esm/generated/resources/Field.d.ts +200 -200
- package/dist/types/fieldTypes/index.d.ts +38 -0
- package/dist/types/generated/resources/Field.d.ts +200 -200
- package/package.json +2 -2
- package/src/fieldTypes/index.ts +54 -0
- package/src/generated/Client.ts +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/fieldTypes/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/fieldTypes/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAsDA,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.
|
|
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.13', 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,41 @@
|
|
|
1
|
+
import type * as ApiTypes from '../generated/ApiTypes.js';
|
|
2
|
+
import type * as RawApiTypes from '../generated/RawApiTypes.js';
|
|
3
|
+
import type { ToItemAttributesInRequest } from '../utilities/itemDefinition.js';
|
|
4
|
+
type ItemTypeDefinitionOf<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.
|
|
17
|
+
*
|
|
18
|
+
* The resulting type preserves `null`. Every CMA field can be cleared by
|
|
19
|
+
* sending `null`, so the type reflects that.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* // Read a record with nested blocks, edit one block, write the whole field
|
|
23
|
+
* // back to the CMA.
|
|
24
|
+
* const page = await client.items.find<LandingPage>(id, { nested: true });
|
|
25
|
+
*
|
|
26
|
+
* const sections: NonNullable<FieldValueInRequest<typeof page, 'sections'>> = [];
|
|
27
|
+
*
|
|
28
|
+
* for (const block of page.sections) {
|
|
29
|
+
* if (isBlockOfType(HeroBlock.ID, block)) {
|
|
30
|
+
* sections.push(buildBlockRecord<HeroBlock>({ id: block.id, title: 'New' }));
|
|
31
|
+
* } else {
|
|
32
|
+
* sections.push(block.id);
|
|
33
|
+
* }
|
|
34
|
+
* }
|
|
35
|
+
*
|
|
36
|
+
* await client.items.update<LandingPage>(page.id, { sections });
|
|
37
|
+
*/
|
|
38
|
+
export type FieldValueInRequest<T, K extends keyof ToItemAttributesInRequest<ItemTypeDefinitionOf<T>>> = K extends keyof ToItemAttributesInRequest<ItemTypeDefinitionOf<T>> ? Required<ToItemAttributesInRequest<ItemTypeDefinitionOf<T>>>[K] : never;
|
|
1
39
|
export * from './appearance/index.js';
|
|
2
40
|
export * from './boolean.js';
|
|
3
41
|
export * from './color.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/fieldTypes/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/fieldTypes/index.ts"],"names":[],"mappings":"AAsDA,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.
|
|
67
|
+
return request(Object.assign(Object.assign(Object.assign({}, this.config), options), { logFn: this.config.logFn || console.log, userAgent: '@datocms/cma-client v5.4.13', 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
|