-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathasset-query.ts
More file actions
165 lines (149 loc) · 5.39 KB
/
asset-query.ts
File metadata and controls
165 lines (149 loc) · 5.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
import { BaseQuery } from './base-query';
import { AxiosInstance } from '@contentstack/core';
import { Query } from './query';
export class AssetQuery extends BaseQuery {
constructor(client: AxiosInstance) {
super();
this._client = client;
this._urlPath = '/assets';
}
/**
* @method version
* @memberof AssetQuery
* @description Retrieve a specific version of an asset in result
* @returns {AssetQuery}
* @example
* import contentstack from '@contentstack/delivery-sdk'
*
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const result = await stack.asset().version(1).find();
*/
version(version: number): AssetQuery {
this._queryParams.version = String(version);
return this;
}
/**
* @method includeDimension
* @memberof AssetQuery
* @description Includes the dimensions (height and width) of the image in result
* @returns {AssetQuery}
* @example
* import contentstack from '@contentstack/delivery-sdk'
*
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const result = await stack.asset().includeDimension().find();
*/
includeDimension(): AssetQuery {
this._queryParams.include_dimension = 'true';
return this;
}
/**
* @method includeBranch
* @memberof AssetQuery
* @description Includes the branch in result
* @returns {AssetQuery}
* @example
* import contentstack from '@contentstack/delivery-sdk'
*
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const result = await stack.asset().includeBranch().find();
*/
includeBranch(): AssetQuery {
this._queryParams.include_branch = 'true';
return this;
}
/**
* @method includeMetadata
* @memberof AssetQuery
* @description Include the metadata for getting metadata content for the asset.
* @returns {AssetQuery}
* @example
* import contentstack from '@contentstack/delivery-sdk'
*
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const result = await stack.asset().includeMetadata().find();
*/
includeMetadata(): AssetQuery {
this._queryParams.include_metadata = 'true';
return this;
}
/**
* @method relativeUrls
* @memberof AssetQuery
* @description Includes the relative URLs of the assets in result
* @returns {AssetQuery}
* @example
* import contentstack from '@contentstack/delivery-sdk'
*
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const result = await stack.asset().relativeUrls().find();
*/
relativeUrls(): AssetQuery {
this._queryParams.relative_url = 'true';
return this;
}
/**
* @method includeFallback
* @memberof AssetQuery
* @description When an entry is not published in a specific language, content can be fetched from its fallback language
* @returns {AssetQuery}
* @example
* import contentstack from '@contentstack/delivery-sdk'
*
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const result = await stack.asset().includeFallback().find();
*/
includeFallback(): AssetQuery {
this._queryParams.include_fallback = 'true';
return this;
}
/**
* @method locale
* @memberof AssetQuery
* @description The assets published in the locale will be fetched
* @returns {AssetQuery}
* @example
* import contentstack from '@contentstack/delivery-sdk'
*
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const result = await stack.asset().locale('en-us').find();
*/
locale(locale: string): AssetQuery {
this._queryParams.locale = locale;
return this;
}
/**
* @method assetFields
* @memberof AssetQuery
* @description Include specific asset fields in the response (CDA getAssets).
* Use with asset_fields[]: user_defined_fields, embedded_metadata, ai_generated_metadata, visual_markups.
* @example
* import contentstack from '@contentstack/delivery-sdk'
*
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const result = await stack.asset().assetFields("user_defined_fields", "embedded_metadata").find();
*
* @param {...string} fields - Asset field names to include (e.g. user_defined_fields, embedded_metadata, ai_generated_metadata, visual_markups)
* @returns {AssetQuery} - Returns the AssetQuery instance for chaining.
*/
assetFields(...fields: string[]): this {
if (fields.length > 0) {
this._queryParams['asset_fields[]'] = fields;
}
return this;
}
/**
* @method query
* @memberof AssetQuery
* @description Fetches the asset data on the basis of the query
* @returns {Query}
* @example
* import contentstack from '@contentstack/delivery-sdk'
*
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const result = await stack.asset().query().where('fieldUid', QueryOperation.EQUALS, 'value').find();
*/
query() {
return new Query(this._client, this._parameters, this._queryParams);
}
}