Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/lib/asset-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@ export class AssetQuery extends BaseQuery {

/**
* @method includeMetadata
* @memberof Entries
* @description Include the metadata for getting metadata content for the entry.
* @returns {Entries}
* @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().fetch();
* const result = await stack.asset().includeMetadata().find();
*/
includeMetadata(): AssetQuery {
this._queryParams.include_metadata = 'true';
Expand Down Expand Up @@ -128,14 +128,14 @@ export class AssetQuery extends BaseQuery {
}
/**
* @method query
* @memberof 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', queryOperators, 'value').find();
* const result = await stack.asset().query().where('fieldUid', QueryOperation.EQUALS, 'value').find();
*/
query() {
return new Query(this._client, this._parameters, this._queryParams);
Expand Down
10 changes: 5 additions & 5 deletions src/lib/asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ export class Asset {

/**
* @method includeMetadata
* @memberof Entries
* @description Include the metadata for getting metadata content for the entry.
* @returns {Entries}
* @memberof Asset
* @description Include the metadata for getting metadata content for the asset.
* @returns {Asset}
* @example
* import contentstack from '@contentstack/delivery-sdk'
*
Expand Down Expand Up @@ -115,7 +115,7 @@ export class Asset {
/**
* @method locale
* @memberof Asset
* @description The assets published in the locale will be fetched
* @description The asset published in the locale will be fetched
* @returns {Asset}
* @example
* import contentstack from '@contentstack/delivery-sdk'
Expand All @@ -133,7 +133,7 @@ export class Asset {
* @method fetch
* @memberof Asset
* @description Fetches the asset data on the basis of the asset uid
* @returns {Asset}
* @returns {Promise<T>} Promise that resolves to the asset data
* @example
* import contentstack from '@contentstack/delivery-sdk'
*
Expand Down
17 changes: 9 additions & 8 deletions src/lib/base-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export class BaseQuery extends Pagination {
* const query = stack.contentType("contentTypeUid").entry().query();
* const result = await query.orderByAscending("field_uid").find()
* // OR
* const asset = await stack.asset().orderByAscending().find()
* const asset = await stack.asset().orderByAscending("field_uid").find()
*
* @returns {Query}
*/
Expand All @@ -72,7 +72,7 @@ export class BaseQuery extends Pagination {
* const query = stack.contentType("contentTypeUid").entry().query();
* const result = await query.orderByDescending("field_uid").find()
* // OR
* const asset = await stack.asset().orderByDescending().find()
* const asset = await stack.asset().orderByDescending("field_uid").find()
*
* @returns {Query}
*/
Expand All @@ -91,7 +91,7 @@ export class BaseQuery extends Pagination {
*
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const query = stack.contentType("contentTypeUid").entry().query();
* const result = await query.limit("limit_value").find()
* const result = await query.limit(10).find()
* // OR
* const asset = await stack.asset().limit(5).find()
*
Expand All @@ -112,7 +112,7 @@ export class BaseQuery extends Pagination {
*
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const query = stack.contentType("contentTypeUid").entry().query();
* const result = await query.skip("skip_value").find()
* const result = await query.skip(10).find()
* // OR
* const asset = await stack.asset().skip(5).find()
*
Expand Down Expand Up @@ -191,9 +191,10 @@ export class BaseQuery extends Pagination {

/**
* @method find
* @memberof AssetQuery
* @description The assets of the stack will be fetched
* @returns {Collection}
* @memberof BaseQuery
* @description Fetches the data based on the query parameters
* @param {boolean} encode - Whether to encode query parameters
* @returns {Promise<FindResponse<T>>} Promise that resolves to the find response
* @example
* import contentstack from '@contentstack/delivery-sdk'
*
Expand All @@ -208,7 +209,7 @@ export class BaseQuery extends Pagination {
* import contentstack from '@contentstack/delivery-sdk'
*
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const result = await stack.asset(asset_uid).fetch();
* const result = await stack.contentType("contentTypeUid").entry().query().find();
*/

async find<T>(encode: boolean = false): Promise<FindResponse<T>> {
Expand Down
10 changes: 10 additions & 0 deletions src/lib/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@ function generateEnhancedCacheKey(originalKey: string, contentTypeUid?: string,
return cacheKey;
}

/**
* Handles cache requests based on the cache policy
* @param {CacheOptions} cacheOptions - Cache configuration options
* @param {string} apiKey - API key for cache key generation
* @param {Function} defaultAdapter - Default axios adapter function
* @param {Function} resolve - Promise resolve function
* @param {Function} reject - Promise reject function
* @param {object} config - Request configuration object
* @returns {Promise} Resolves or rejects based on cache policy and API response
*/
export async function handleRequest(
cacheOptions: CacheOptions,
apiKey: string,
Expand Down
9 changes: 6 additions & 3 deletions src/lib/content-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,16 @@ export class ContentType {
/**
* @method entry
* @memberof ContentType
* @description Creates entry object of the passed entry uid.
* @returns {Entry}
* @description Creates entry object of the passed entry uid, or entries query object if no uid is provided.
* @param {string} [uid] - Optional entry UID. If provided, returns a single Entry instance. If omitted, returns Entries query object.
* @returns {Entry | Entries} Entry instance if uid is provided, otherwise Entries query object
* @example
* import contentstack from '@contentstack/delivery-sdk'
*
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const entry = stack.contentType("contentTypeUid").entry("entryUid");
* // OR
* const entries = stack.contentType("contentTypeUid").entry();
*/
entry(uid: string): Entry;
entry(): Entries;
Expand All @@ -41,7 +44,7 @@ export class ContentType {
* @method fetch
* @memberof ContentType
* @description Fetches the contentType data on the basis of the contentType uid
* @returns {ContentType}
* @returns {Promise<T>} Promise that resolves to the content type data
* @example
* import contentstack from '@contentstack/delivery-sdk'
*
Expand Down
4 changes: 2 additions & 2 deletions src/lib/contentstack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ let version = '{{VERSION}}';
* @memberof Contentstack
* @description Creates a stack instance
* @param {StackConfig} config - config object for stack with apiKey, deliveryToken and environment as required fields
*
* @returns {StackClass} Stack instance
* @example
* import contentstack from '@contentstack/delivery-sdk'
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
Expand All @@ -30,7 +30,7 @@ let version = '{{VERSION}}';
* policy: Policy.CACHE_THEN_NETWORK,
* storeType: 'localStorage'
* }
* }
* });
*/
// eslint-disable-next-line @typescript-eslint/naming-convention
export function stack(config: StackConfig): StackClass {
Expand Down
4 changes: 2 additions & 2 deletions src/lib/contenttype-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class ContentTypeQuery {
/**
* @method includeGlobalFieldSchema
* @memberof ContentTypeQuery
* @description The assets published in the locale will be fetched
* @description Includes the global field schema in the content type response
* @returns {ContentTypeQuery}
* @example
* import contentstack from '@contentstack/delivery-sdk'
Expand All @@ -31,7 +31,7 @@ export class ContentTypeQuery {
* @method find
* @memberof ContentTypeQuery
* @description Fetches all contentTypes of the stack
* @returns {ContentTypeQuery}
* @returns {Promise<FindResponse<T>>} Promise that resolves to the find response containing content types
* @example
* import contentstack from '@contentstack/delivery-sdk'
*
Expand Down
49 changes: 28 additions & 21 deletions src/lib/entries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@ export class Entries extends BaseQuery {
/**
* @method includeContentType
* @memberof Entries
* @description IInclude the details of the content type along with the entries details
* @description Include the details of the content type along with the entries details
* @returns {Entries}
* @example
* import contentstack from '@contentstack/delivery-sdk'
*
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const result = await stack.contentType(contentType_uid).entry().includeContentType().fetch();
* const result = await stack.contentType(contentType_uid).entry().includeContentType().find();
*/
includeContentType(): Entries {
this._queryParams.include_content_type = 'true';
Expand All @@ -85,7 +85,7 @@ export class Entries extends BaseQuery {
* import contentstack from '@contentstack/delivery-sdk'
*
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const result = await stack.contentType(contentType_uid).entry().includeEmbeddedItems().fetch();
* const result = await stack.contentType(contentType_uid).entry().includeEmbeddedItems().find();
*/
includeEmbeddedItems(): Entries {
this._queryParams['include_embedded_items[]'] = 'BASE';
Expand Down Expand Up @@ -134,9 +134,11 @@ export class Entries extends BaseQuery {
* you need to use the include[] parameter and specify the UID of the reference field as value.
* This function sets the include parameter to a reference field UID in the API request.
* @example
* const stack = contentstack.stack("apiKey", "deliveryKey", "environment");
* const query = stack.contentType("contentTypeUid").entry().includeReference("brand")
* const res = await query.find()
* import contentstack from '@contentstack/delivery-sdk'
*
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const entries = stack.contentType("contentTypeUid").entry().includeReference("brand")
* const result = await entries.find()
*
* @param {string} referenceFieldUid - UID of the reference field to include.
* @returns {Entries} - Returns the Entries instance for chaining.
Expand All @@ -160,9 +162,11 @@ export class Entries extends BaseQuery {
* @memberof Entries
* @description This method also includes the content type UIDs of the referenced entries returned in the response.
* @example
* const stack = contentstack.stack("apiKey", "deliveryKey", "environment");
* const query = stack.contentType("contentTypeUid").entry().includeReferenceContentTypeUID()
* const res = await query.find()
* import contentstack from '@contentstack/delivery-sdk'
*
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const entries = stack.contentType("contentTypeUid").entry().includeReferenceContentTypeUID()
* const result = await entries.find()
*
* @returns {Entries} - Returns the Entries instance for chaining.
*/
Expand All @@ -175,11 +179,13 @@ export class Entries extends BaseQuery {
/**
* @method includeSchema
* @memberof Entries
* @description This method also includes the content type UIDs of the referenced entries returned in the response.
* @description Includes the schema of the content type along with the entries details.
* @example
* const stack = contentstack.stack("apiKey", "deliveryKey", "environment");
* const query = stack.contentType("contentTypeUid").entry().includeSchema()
* const res = await query.find()
* import contentstack from '@contentstack/delivery-sdk'
*
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const entries = stack.contentType("contentTypeUid").entry().includeSchema()
* const result = await entries.find()
*
* @returns {Entries} - Returns the Entries instance for chaining.
*/
Expand All @@ -191,9 +197,9 @@ export class Entries extends BaseQuery {

/**
* @method locale
* @memberof Entry
* @description The assets published in the locale will be fetched
* @returns {Entry}
* @memberof Entries
* @description The entries published in the locale will be fetched
* @returns {Entries}
* @example
* import contentstack from '@contentstack/delivery-sdk'
*
Expand Down Expand Up @@ -235,13 +241,14 @@ export class Entries extends BaseQuery {
/**
* @method query
* @memberof Entries
* @description Fetches the Entry data on the basis of the asset uid
* @returns {Collection}
* @description Creates a query object for filtering entries
* @param {object} queryObj - Optional query object to initialize the query
* @returns {Query} Query instance for chaining query methods
* @example
* import contentstack from '@contentstack/delivery-sdk'
*
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const result = await stack.contentType("contentTypeUid").entry().query();
* const query = stack.contentType("contentTypeUid").entry().query();
*/
query(queryObj?: { [key: string]: any }) {
if (queryObj) return new Query(this._client, this._parameters, this._queryParams, this._variants, this._contentTypeUid, queryObj);
Expand All @@ -251,9 +258,9 @@ export class Entries extends BaseQuery {

/**
* @method variants
* @memberof Entry
* @memberof Entries
* @description The variant header will be added to axios client
* @returns {Entry}
* @returns {Entries}
* @example
* import contentstack from '@contentstack/delivery-sdk'
*
Expand Down
20 changes: 11 additions & 9 deletions src/lib/entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,10 @@ export class Entry {
* you need to use the include[] parameter and specify the UID of the reference field as value.
* This function sets the include parameter to a reference field UID in the API request.
* @example
* const stack = contentstack.stack("apiKey", "deliveryKey", "environment");
* const query = stack.contentType("contentTypeUid").entry(entry_uid).includeReference("brand").fetch()
* import contentstack from '@contentstack/delivery-sdk'
*
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const result = await stack.contentType("contentTypeUid").entry(entry_uid).includeReference("brand").fetch()
*
* @param {string} referenceFieldUid - UID of the reference field to include.
* @returns {Entry} - Returns the Entry instance for chaining.
Expand All @@ -120,7 +122,7 @@ export class Entry {
/**
* @method includeContentType
* @memberof Entry
* @description IInclude the details of the content type along with the entries details
* @description Include the details of the content type along with the entries details
* @returns {Entry}
* @example
* import contentstack from '@contentstack/delivery-sdk'
Expand Down Expand Up @@ -154,13 +156,13 @@ export class Entry {
/**
* @method locale
* @memberof Entry
* @description The assets published in the locale will be fetched
* @description The entry published in the locale will be fetched
* @returns {Entry}
* @example
* import contentstack from '@contentstack/delivery-sdk'
*
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const result = await stack.assetQuery().locale('en-us').fetch();
* const result = await stack.contentType('contentTypeUid').entry('entryUid').locale('en-us').fetch();
*/
locale(locale: string): this {
this._queryParams.locale = locale;
Expand All @@ -172,7 +174,7 @@ export class Entry {
* @method fetch
* @memberof Entry
* @description Fetches the entry data on the basis of the entry uid
* @returns {Collection}
* @returns {Promise<T>} Promise that resolves to the entry data
* @example
* import contentstack from '@contentstack/delivery-sdk'
*
Expand Down Expand Up @@ -208,7 +210,7 @@ export class Entry {
* import contentstack from '@contentstack/delivery-sdk'
*
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const result = stack.contentType("contentTypeUid").entry().addParams({"key": "value"}).fetch()
* const result = await stack.contentType("contentTypeUid").entry("entryUid").addParams({"key": "value"}).fetch()
*
* @returns {Entry}
*/
Expand All @@ -226,7 +228,7 @@ export class Entry {
* import contentstack from '@contentstack/delivery-sdk'
*
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const result = await stack.contentType("contentTypeUid").entry().except("fieldUID").find()
* const result = await stack.contentType("contentTypeUid").entry("entryUid").except("fieldUID").fetch()
*
* @param {string} fieldUid - field uid to exclude
* @returns {Entry} - returns Entry object for chaining method calls
Expand All @@ -253,7 +255,7 @@ export class Entry {
* import contentstack from '@contentstack/delivery-sdk'
*
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const result = await stack.contentType("contentTypeUid").entry().only("fieldUID").find()
* const result = await stack.contentType("contentTypeUid").entry("entryUid").only("fieldUID").fetch()
*
* @param {string} fieldUid - field uid to select
* @returns {Entry} - returns Entry object for chaining method calls
Expand Down
Loading