@datocms/cma-client 5.4.13 → 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.
- package/dist/cjs/fieldTypes/index.js.map +1 -1
- package/dist/cjs/generated/Client.js +1 -1
- package/dist/esm/fieldTypes/index.d.ts +37 -6
- package/dist/esm/fieldTypes/index.js.map +1 -1
- package/dist/esm/generated/Client.js +1 -1
- package/dist/types/fieldTypes/index.d.ts +37 -6
- package/package.json +2 -2
- package/src/fieldTypes/index.ts +61 -11
- 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":";;;;;;;;;;;;;;;;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.
|
|
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,7 +1,7 @@
|
|
|
1
1
|
import type * as ApiTypes from '../generated/ApiTypes.js';
|
|
2
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;
|
|
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
5
|
/**
|
|
6
6
|
* Given a record or block you've read from the CMA and one of its field keys,
|
|
7
7
|
* resolves to the type you'd send back when writing that field — for example,
|
|
@@ -13,10 +13,9 @@ type ItemTypeDefinitionOf<T> = T extends ApiTypes.Item<infer D> ? D : T extends
|
|
|
13
13
|
*
|
|
14
14
|
* The first parameter accepts any item-shaped value the CMA produces:
|
|
15
15
|
* top-level records as well as nested blocks inside a parent record's
|
|
16
|
-
* modular-content / structured-text / single-block field.
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
* sending `null`, so the type reflects that.
|
|
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.
|
|
20
19
|
*
|
|
21
20
|
* @example
|
|
22
21
|
* // Read a record with nested blocks, edit one block, write the whole field
|
|
@@ -36,6 +35,38 @@ type ItemTypeDefinitionOf<T> = T extends ApiTypes.Item<infer D> ? D : T extends
|
|
|
36
35
|
* await client.items.update<LandingPage>(page.id, { sections });
|
|
37
36
|
*/
|
|
38
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;
|
|
39
70
|
export * from './appearance/index.js';
|
|
40
71
|
export * from './boolean.js';
|
|
41
72
|
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":"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.
|
|
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
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type * as ApiTypes from '../generated/ApiTypes.js';
|
|
2
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;
|
|
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
5
|
/**
|
|
6
6
|
* Given a record or block you've read from the CMA and one of its field keys,
|
|
7
7
|
* resolves to the type you'd send back when writing that field — for example,
|
|
@@ -13,10 +13,9 @@ type ItemTypeDefinitionOf<T> = T extends ApiTypes.Item<infer D> ? D : T extends
|
|
|
13
13
|
*
|
|
14
14
|
* The first parameter accepts any item-shaped value the CMA produces:
|
|
15
15
|
* top-level records as well as nested blocks inside a parent record's
|
|
16
|
-
* modular-content / structured-text / single-block field.
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
* sending `null`, so the type reflects that.
|
|
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.
|
|
20
19
|
*
|
|
21
20
|
* @example
|
|
22
21
|
* // Read a record with nested blocks, edit one block, write the whole field
|
|
@@ -36,6 +35,38 @@ type ItemTypeDefinitionOf<T> = T extends ApiTypes.Item<infer D> ? D : T extends
|
|
|
36
35
|
* await client.items.update<LandingPage>(page.id, { sections });
|
|
37
36
|
*/
|
|
38
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;
|
|
39
70
|
export * from './appearance/index.js';
|
|
40
71
|
export * from './boolean.js';
|
|
41
72
|
export * from './color.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@datocms/cma-client",
|
|
3
|
-
"version": "5.4.
|
|
3
|
+
"version": "5.4.14",
|
|
4
4
|
"description": "JS client for DatoCMS REST Content Management API",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"datocms",
|
|
@@ -45,5 +45,5 @@
|
|
|
45
45
|
"@datocms/dashboard-client": "^5.4.9",
|
|
46
46
|
"@types/uuid": "^9.0.7"
|
|
47
47
|
},
|
|
48
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "aad77038aa0c91a6439c46f836199d129f88f70f"
|
|
49
49
|
}
|
package/src/fieldTypes/index.ts
CHANGED
|
@@ -1,16 +1,23 @@
|
|
|
1
1
|
import type * as ApiTypes from '../generated/ApiTypes.js';
|
|
2
2
|
import type * as RawApiTypes from '../generated/RawApiTypes.js';
|
|
3
|
-
import type {
|
|
3
|
+
import type {
|
|
4
|
+
ItemTypeDefinition,
|
|
5
|
+
ToItemAttributes,
|
|
6
|
+
ToItemAttributesInNestedResponse,
|
|
7
|
+
ToItemAttributesInRequest,
|
|
8
|
+
} from '../utilities/itemDefinition.js';
|
|
4
9
|
|
|
5
|
-
type ItemTypeDefinitionOf<T> = T extends
|
|
6
|
-
?
|
|
7
|
-
: T extends ApiTypes.
|
|
10
|
+
type ItemTypeDefinitionOf<T> = T extends ItemTypeDefinition<any, any, any>
|
|
11
|
+
? T
|
|
12
|
+
: T extends ApiTypes.Item<infer D>
|
|
8
13
|
? D
|
|
9
|
-
: T extends
|
|
14
|
+
: T extends ApiTypes.ItemInNestedResponse<infer D>
|
|
10
15
|
? D
|
|
11
|
-
: T extends RawApiTypes.
|
|
16
|
+
: T extends RawApiTypes.Item<infer D>
|
|
12
17
|
? D
|
|
13
|
-
:
|
|
18
|
+
: T extends RawApiTypes.ItemInNestedResponse<infer D>
|
|
19
|
+
? D
|
|
20
|
+
: never;
|
|
14
21
|
|
|
15
22
|
/**
|
|
16
23
|
* Given a record or block you've read from the CMA and one of its field keys,
|
|
@@ -23,10 +30,9 @@ type ItemTypeDefinitionOf<T> = T extends ApiTypes.Item<infer D>
|
|
|
23
30
|
*
|
|
24
31
|
* The first parameter accepts any item-shaped value the CMA produces:
|
|
25
32
|
* top-level records as well as nested blocks inside a parent record's
|
|
26
|
-
* modular-content / structured-text / single-block field.
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
* sending `null`, so the type reflects that.
|
|
33
|
+
* modular-content / structured-text / single-block field. You can also pass
|
|
34
|
+
* an `ItemTypeDefinition` directly when you already have the definition type
|
|
35
|
+
* in hand and don't need to round-trip through an `ApiTypes.Item<…>` shape.
|
|
30
36
|
*
|
|
31
37
|
* @example
|
|
32
38
|
* // Read a record with nested blocks, edit one block, write the whole field
|
|
@@ -52,6 +58,50 @@ export type FieldValueInRequest<
|
|
|
52
58
|
? Required<ToItemAttributesInRequest<ItemTypeDefinitionOf<T>>>[K]
|
|
53
59
|
: never;
|
|
54
60
|
|
|
61
|
+
/**
|
|
62
|
+
* Given a record or block you've read from the CMA and one of its field keys,
|
|
63
|
+
* resolves to the field's value type as it appears in a standard (non-nested)
|
|
64
|
+
* response — for example, what you'd read off `record.attributes[fieldKey]`
|
|
65
|
+
* after `client.items.find(id)`.
|
|
66
|
+
*
|
|
67
|
+
* The first parameter accepts any item-shaped value the CMA produces, or an
|
|
68
|
+
* `ItemTypeDefinition` directly.
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* // Read nested, then collect just the block IDs for an outline view.
|
|
72
|
+
* const page = await client.items.find<LandingPage>(id, { nested: true });
|
|
73
|
+
* const sectionIds: FieldValue<typeof page, 'sections'> = page.sections.map(
|
|
74
|
+
* (block) => block.id,
|
|
75
|
+
* );
|
|
76
|
+
*/
|
|
77
|
+
export type FieldValue<
|
|
78
|
+
T,
|
|
79
|
+
K extends keyof ToItemAttributes<ItemTypeDefinitionOf<T>>,
|
|
80
|
+
> = K extends keyof ToItemAttributes<ItemTypeDefinitionOf<T>>
|
|
81
|
+
? ToItemAttributes<ItemTypeDefinitionOf<T>>[K]
|
|
82
|
+
: never;
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Given a record or block you've read from the CMA and one of its field keys,
|
|
86
|
+
* resolves to the field's value type in a nested response — i.e. what you'd
|
|
87
|
+
* read off the field after `client.items.find(id, { nested: true })`, where
|
|
88
|
+
* blocks are inlined as full objects instead of ID strings.
|
|
89
|
+
*
|
|
90
|
+
* The first parameter accepts any item-shaped value the CMA produces, or an
|
|
91
|
+
* `ItemTypeDefinition` directly.
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* const page = await client.items.find<LandingPage>(id, { nested: true });
|
|
95
|
+
* const sections: FieldValueInNestedResponse<typeof page, 'sections'> = page.sections;
|
|
96
|
+
* // sections elements are full block objects, not ID strings.
|
|
97
|
+
*/
|
|
98
|
+
export type FieldValueInNestedResponse<
|
|
99
|
+
T,
|
|
100
|
+
K extends keyof ToItemAttributesInNestedResponse<ItemTypeDefinitionOf<T>>,
|
|
101
|
+
> = K extends keyof ToItemAttributesInNestedResponse<ItemTypeDefinitionOf<T>>
|
|
102
|
+
? ToItemAttributesInNestedResponse<ItemTypeDefinitionOf<T>>[K]
|
|
103
|
+
: never;
|
|
104
|
+
|
|
55
105
|
export * from './appearance/index.js';
|
|
56
106
|
export * from './boolean.js';
|
|
57
107
|
export * from './color.js';
|
package/src/generated/Client.ts
CHANGED
|
@@ -151,7 +151,7 @@ export class Client {
|
|
|
151
151
|
...this.config,
|
|
152
152
|
...options,
|
|
153
153
|
logFn: this.config.logFn || console.log,
|
|
154
|
-
userAgent: '@datocms/cma-client v5.4.
|
|
154
|
+
userAgent: '@datocms/cma-client v5.4.14',
|
|
155
155
|
baseUrl: this.baseUrl,
|
|
156
156
|
preCallStack: new Error().stack,
|
|
157
157
|
extraHeaders: {
|