@smartive/datocms-utils 2.3.1 → 2.3.2
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/cache-tags-redis.d.ts +39 -0
- package/dist/cache-tags-redis.js +80 -0
- package/dist/cache-tags-redis.js.map +1 -0
- package/dist/cache-tags.d.ts +43 -0
- package/dist/cache-tags.js +72 -0
- package/dist/cache-tags.js.map +1 -0
- package/dist/classnames.d.ts +7 -0
- package/dist/classnames.js +8 -0
- package/dist/classnames.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -0
- package/dist/links.d.ts +7 -0
- package/dist/links.js +15 -0
- package/dist/links.js.map +1 -0
- package/dist/types.d.ts +25 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/utils.d.ts +18 -0
- package/dist/utils.js +24 -0
- package/dist/utils.js.map +1 -0
- package/package.json +8 -4
- package/.github/workflows/release.yml +0 -33
- package/.github/workflows/test.yml +0 -25
- package/.nvmrc +0 -1
- package/.prettierrc.json +0 -1
- package/.releaserc.json +0 -10
- package/CHANGELOG.md +0 -6
- package/eslint.config.mjs +0 -3
- package/renovate.json +0 -4
- package/tsconfig.json +0 -18
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { type CacheTag } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Stores the cache tags of a query in Redis.
|
|
4
|
+
*
|
|
5
|
+
* For each cache tag, adds the query ID to a Redis Set. Sets are unordered
|
|
6
|
+
* collections of unique strings, perfect for tracking which queries use which tags.
|
|
7
|
+
*
|
|
8
|
+
* @param {string} queryId Unique query ID
|
|
9
|
+
* @param {CacheTag[]} cacheTags Array of cache tags
|
|
10
|
+
*
|
|
11
|
+
*/
|
|
12
|
+
export declare const storeQueryCacheTags: (queryId: string, cacheTags: CacheTag[]) => Promise<void>;
|
|
13
|
+
/**
|
|
14
|
+
* Retrieves the query IDs that reference any of the specified cache tags.
|
|
15
|
+
*
|
|
16
|
+
* Uses Redis SUNION to efficiently find all queries associated with the given tags.
|
|
17
|
+
*
|
|
18
|
+
* @param {CacheTag[]} cacheTags Array of cache tags to check
|
|
19
|
+
* @returns Array of unique query IDs
|
|
20
|
+
*
|
|
21
|
+
*/
|
|
22
|
+
export declare const queriesReferencingCacheTags: (cacheTags: CacheTag[]) => Promise<string[]>;
|
|
23
|
+
/**
|
|
24
|
+
* Deletes the specified cache tags from Redis.
|
|
25
|
+
*
|
|
26
|
+
* This removes the cache tag keys entirely. When queries are revalidated and
|
|
27
|
+
* run again, fresh cache tag mappings will be created.
|
|
28
|
+
*
|
|
29
|
+
* @param {CacheTag[]} cacheTags Array of cache tags to delete
|
|
30
|
+
* @returns Number of keys deleted, or null if there was an error
|
|
31
|
+
*
|
|
32
|
+
*/
|
|
33
|
+
export declare const deleteCacheTags: (cacheTags: CacheTag[]) => Promise<number>;
|
|
34
|
+
/**
|
|
35
|
+
* Wipes out all cache tags from Redis.
|
|
36
|
+
*
|
|
37
|
+
* ⚠️ **Warning**: This will delete all cache tag data. Use with caution!
|
|
38
|
+
*/
|
|
39
|
+
export declare const truncateCacheTags: () => Promise<void>;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { Redis } from 'ioredis';
|
|
2
|
+
let redis = null;
|
|
3
|
+
const getRedis = () => {
|
|
4
|
+
redis ??= new Redis(process.env.REDIS_URL, {
|
|
5
|
+
maxRetriesPerRequest: 3,
|
|
6
|
+
lazyConnect: true,
|
|
7
|
+
});
|
|
8
|
+
return redis;
|
|
9
|
+
};
|
|
10
|
+
const keyPrefix = process.env.REDIS_KEY_PREFIX ? `${process.env.REDIS_KEY_PREFIX}:` : '';
|
|
11
|
+
/**
|
|
12
|
+
* Stores the cache tags of a query in Redis.
|
|
13
|
+
*
|
|
14
|
+
* For each cache tag, adds the query ID to a Redis Set. Sets are unordered
|
|
15
|
+
* collections of unique strings, perfect for tracking which queries use which tags.
|
|
16
|
+
*
|
|
17
|
+
* @param {string} queryId Unique query ID
|
|
18
|
+
* @param {CacheTag[]} cacheTags Array of cache tags
|
|
19
|
+
*
|
|
20
|
+
*/
|
|
21
|
+
export const storeQueryCacheTags = async (queryId, cacheTags) => {
|
|
22
|
+
if (!cacheTags?.length) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
const redis = getRedis();
|
|
26
|
+
const pipeline = redis.pipeline();
|
|
27
|
+
for (const tag of cacheTags) {
|
|
28
|
+
pipeline.sadd(`${keyPrefix}${tag}`, queryId);
|
|
29
|
+
}
|
|
30
|
+
await pipeline.exec();
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Retrieves the query IDs that reference any of the specified cache tags.
|
|
34
|
+
*
|
|
35
|
+
* Uses Redis SUNION to efficiently find all queries associated with the given tags.
|
|
36
|
+
*
|
|
37
|
+
* @param {CacheTag[]} cacheTags Array of cache tags to check
|
|
38
|
+
* @returns Array of unique query IDs
|
|
39
|
+
*
|
|
40
|
+
*/
|
|
41
|
+
export const queriesReferencingCacheTags = async (cacheTags) => {
|
|
42
|
+
if (!cacheTags?.length) {
|
|
43
|
+
return [];
|
|
44
|
+
}
|
|
45
|
+
const redis = getRedis();
|
|
46
|
+
const keys = cacheTags.map((tag) => `${keyPrefix}${tag}`);
|
|
47
|
+
return redis.sunion(...keys);
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Deletes the specified cache tags from Redis.
|
|
51
|
+
*
|
|
52
|
+
* This removes the cache tag keys entirely. When queries are revalidated and
|
|
53
|
+
* run again, fresh cache tag mappings will be created.
|
|
54
|
+
*
|
|
55
|
+
* @param {CacheTag[]} cacheTags Array of cache tags to delete
|
|
56
|
+
* @returns Number of keys deleted, or null if there was an error
|
|
57
|
+
*
|
|
58
|
+
*/
|
|
59
|
+
export const deleteCacheTags = async (cacheTags) => {
|
|
60
|
+
if (!cacheTags?.length) {
|
|
61
|
+
return 0;
|
|
62
|
+
}
|
|
63
|
+
const redis = getRedis();
|
|
64
|
+
const keys = cacheTags.map((tag) => `${keyPrefix}${tag}`);
|
|
65
|
+
return redis.del(...keys);
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* Wipes out all cache tags from Redis.
|
|
69
|
+
*
|
|
70
|
+
* ⚠️ **Warning**: This will delete all cache tag data. Use with caution!
|
|
71
|
+
*/
|
|
72
|
+
export const truncateCacheTags = async () => {
|
|
73
|
+
const redis = getRedis();
|
|
74
|
+
const pattern = `${keyPrefix}*`;
|
|
75
|
+
const keys = await redis.keys(pattern);
|
|
76
|
+
if (keys.length > 0) {
|
|
77
|
+
await redis.del(...keys);
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
//# sourceMappingURL=cache-tags-redis.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache-tags-redis.js","sourceRoot":"","sources":["../src/cache-tags-redis.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAGhC,IAAI,KAAK,GAAiB,IAAI,CAAC;AAE/B,MAAM,QAAQ,GAAG,GAAU,EAAE;IAC3B,KAAK,KAAK,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,SAAU,EAAE;QAC1C,oBAAoB,EAAE,CAAC;QACvB,WAAW,EAAE,IAAI;KAClB,CAAC,CAAC;IAEH,OAAO,KAAK,CAAC;AACf,CAAC,CAAC;AAEF,MAAM,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC,gBAAgB,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;AAEzF;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,KAAK,EAAE,OAAe,EAAE,SAAqB,EAAiB,EAAE;IACjG,IAAI,CAAC,SAAS,EAAE,MAAM,EAAE,CAAC;QACvB,OAAO;IACT,CAAC;IAED,MAAM,KAAK,GAAG,QA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ACzB,MAAM,OAAO,GAAG,GAAG,SAAS,GAAG,CAAC;IAChC,MAAM,IAAI,GAAG,MAAM,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAEvC,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACpB,MAAM,KAAK,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,CAAC;IAC3B,CAAC;AACH,CAAC,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { type CacheTag } from './types';
|
|
2
|
+
export { generateQueryId, parseXCacheTagsResponseHeader } from './utils';
|
|
3
|
+
/**
|
|
4
|
+
* Stores the cache tags of a query in the database.
|
|
5
|
+
*
|
|
6
|
+
* @param {string} queryId Unique query ID
|
|
7
|
+
* @param {CacheTag[]} cacheTags Array of cache tags
|
|
8
|
+
* @param {string} tableId Database table ID
|
|
9
|
+
*/
|
|
10
|
+
export declare const storeQueryCacheTags: (queryId: string, cacheTags: CacheTag[], tableId: string) => Promise<void>;
|
|
11
|
+
/**
|
|
12
|
+
* Retrieves the queries that reference cache tags.
|
|
13
|
+
*
|
|
14
|
+
* @param {CacheTag[]} cacheTags Array of cache tags
|
|
15
|
+
* @param {string} tableId Database table ID
|
|
16
|
+
* @returns Array of query IDs
|
|
17
|
+
*/
|
|
18
|
+
export declare const queriesReferencingCacheTags: (cacheTags: CacheTag[], tableId: string) => Promise<string[]>;
|
|
19
|
+
/**
|
|
20
|
+
* Deletes the specified cache tags from the database.
|
|
21
|
+
*
|
|
22
|
+
* This removes the cache tag keys entirely. When queries are revalidated and
|
|
23
|
+
* run again, fresh cache tag mappings will be created.
|
|
24
|
+
*
|
|
25
|
+
* @param {CacheTag[]} cacheTags Array of cache tags to delete
|
|
26
|
+
* @param {string} tableId Database table ID
|
|
27
|
+
*
|
|
28
|
+
*/
|
|
29
|
+
export declare const deleteCacheTags: (cacheTags: CacheTag[], tableId: string) => Promise<void>;
|
|
30
|
+
/**
|
|
31
|
+
* Deletes the cache tags of a query from the database.
|
|
32
|
+
*
|
|
33
|
+
* @param {string} queryId Unique query ID
|
|
34
|
+
* @param {string} tableId Database table ID
|
|
35
|
+
* @deprecated Use `deleteCacheTags` instead.
|
|
36
|
+
*/
|
|
37
|
+
export declare const deleteQueries: (queryIds: string[], tableId: string) => Promise<void>;
|
|
38
|
+
/**
|
|
39
|
+
* Wipes out all cache tags from the database.
|
|
40
|
+
*
|
|
41
|
+
* @param {string} tableId Database table ID
|
|
42
|
+
*/
|
|
43
|
+
export declare function truncateCacheTags(tableId: string): Promise<void>;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { sql } from '@vercel/postgres';
|
|
2
|
+
export { generateQueryId, parseXCacheTagsResponseHeader } from './utils';
|
|
3
|
+
/**
|
|
4
|
+
* Stores the cache tags of a query in the database.
|
|
5
|
+
*
|
|
6
|
+
* @param {string} queryId Unique query ID
|
|
7
|
+
* @param {CacheTag[]} cacheTags Array of cache tags
|
|
8
|
+
* @param {string} tableId Database table ID
|
|
9
|
+
*/
|
|
10
|
+
export const storeQueryCacheTags = async (queryId, cacheTags, tableId) => {
|
|
11
|
+
if (!cacheTags?.length) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
const tags = cacheTags.flatMap((_, i) => [queryId, cacheTags[i]]);
|
|
15
|
+
const placeholders = cacheTags.map((_, i) => `($${2 * i + 1}, $${2 * i + 2})`).join(',');
|
|
16
|
+
await sql.query(`INSERT INTO ${tableId} VALUES ${placeholders} ON CONFLICT DO NOTHING`, tags);
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Retrieves the queries that reference cache tags.
|
|
20
|
+
*
|
|
21
|
+
* @param {CacheTag[]} cacheTags Array of cache tags
|
|
22
|
+
* @param {string} tableId Database table ID
|
|
23
|
+
* @returns Array of query IDs
|
|
24
|
+
*/
|
|
25
|
+
export const queriesReferencingCacheTags = async (cacheTags, tableId) => {
|
|
26
|
+
if (!cacheTags?.length) {
|
|
27
|
+
return [];
|
|
28
|
+
}
|
|
29
|
+
const placeholders = cacheTags.map((_, i) => `$${i + 1}`).join(',');
|
|
30
|
+
const { rows } = await sql.query(`SELECT DISTINCT query_id FROM ${tableId} WHERE cache_tag IN (${placeholders})`, cacheTags);
|
|
31
|
+
return rows.map((row) => row.query_id);
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Deletes the specified cache tags from the database.
|
|
35
|
+
*
|
|
36
|
+
* This removes the cache tag keys entirely. When queries are revalidated and
|
|
37
|
+
* run again, fresh cache tag mappings will be created.
|
|
38
|
+
*
|
|
39
|
+
* @param {CacheTag[]} cacheTags Array of cache tags to delete
|
|
40
|
+
* @param {string} tableId Database table ID
|
|
41
|
+
*
|
|
42
|
+
*/
|
|
43
|
+
export const deleteCacheTags = async (cacheTags, tableId) => {
|
|
44
|
+
if (cacheTags.length === 0) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
const placeholders = cacheTags.map((_, i) => `$${i + 1}`).join(',');
|
|
48
|
+
await sql.query(`DELETE FROM ${tableId} WHERE cache_tag IN (${placeholders})`, cacheTags);
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Deletes the cache tags of a query from the database.
|
|
52
|
+
*
|
|
53
|
+
* @param {string} queryId Unique query ID
|
|
54
|
+
* @param {string} tableId Database table ID
|
|
55
|
+
* @deprecated Use `deleteCacheTags` instead.
|
|
56
|
+
*/
|
|
57
|
+
export const deleteQueries = async (queryIds, tableId) => {
|
|
58
|
+
if (!queryIds?.length) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
const placeholders = queryIds.map((_, i) => `$${i + 1}`).join(',');
|
|
62
|
+
await sql.query(`DELETE FROM ${tableId} WHERE query_id IN (${placeholders})`, queryIds);
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* Wipes out all cache tags from the database.
|
|
66
|
+
*
|
|
67
|
+
* @param {string} tableId Database table ID
|
|
68
|
+
*/
|
|
69
|
+
export async function truncateCacheTags(tableId) {
|
|
70
|
+
await sql.query(`DELETE FROM ${tableId}`);
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=cache-tags.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache-tags.js","sourceRoot":"","sources":["../src/cache-tags.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAC;AAGvC,OAAO,EAAE,eAAe,EAAE,6BAA6B,EAAE,MAAM,SAAS,CAAC;AAEzE;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,KAAK,EAAE,OAAe,EAAE,SAAqB,EAAE,OAAe,EAAE,EAAE;IACnG,IAAI,CAAC,SAAS,EAAE,MAAM,EAAE,CAAC;QACvB,OAAO;IACT,CAAC;IAED,MAAM,IAAI,GAAG,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAClE,MAAM,YAAY,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAEzF,MAAM,GAAG,CAAC,KAAK,CAAC,eAAe,OAAO,WAAW,YAAY,yBAAyB,EAAE,IAAI,CAAC,CAAC;AAChG,CAAC,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAAG,KAAK,EAAE,SAAqB,EAAE,OAAe,EAAqB,EAAE;IAC7G,IAAI,CAAC,SAAS,EAAE,MAAM,EAAE,CAAC;QACvB,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,MAAM,YAAY,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,C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AC;AAEF;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAAC,OAAe;IACrD,MAAM,GAAG,CAAC,KAAK,CAAC,eAAe,OAAO,EAAE,CAAC,CAAC;AAC5C,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cleans and joins an array of inputs with possible undefined or boolean values.
|
|
3
|
+
*
|
|
4
|
+
* @param classNames Array of class names
|
|
5
|
+
* @returns Clean string to be used for class name
|
|
6
|
+
*/
|
|
7
|
+
export declare const classNames: (...classNames: (string | undefined | boolean)[]) => string;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cleans and joins an array of inputs with possible undefined or boolean values.
|
|
3
|
+
*
|
|
4
|
+
* @param classNames Array of class names
|
|
5
|
+
* @returns Clean string to be used for class name
|
|
6
|
+
*/
|
|
7
|
+
export const classNames = (...classNames) => classNames.filter(Boolean).join(' ');
|
|
8
|
+
//# sourceMappingURL=classnames.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"classnames.js","sourceRoot":"","sources":["../src/classnames.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,GAAG,UAA4C,EAAU,EAAE,CAAC,UAAU,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC"}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,OAAO,KAAK,QAAQ,MAAM,cAAc,CAAC;AACzC,OAAO,KAAK,KAAK,MAAM,oBAAoB,CAAC;AAC5C,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC"}
|
package/dist/links.d.ts
ADDED
package/dist/links.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts a phone number into a `tel:` link.
|
|
3
|
+
*
|
|
4
|
+
* @param phoneNumber Phone number
|
|
5
|
+
* @returns `tel:` link for the phone number
|
|
6
|
+
*/
|
|
7
|
+
export const getTelLink = (phoneNumber) => {
|
|
8
|
+
if (typeof phoneNumber !== 'string') {
|
|
9
|
+
throw new Error('Phone number must be a string.');
|
|
10
|
+
}
|
|
11
|
+
// Remove non-digit characters except for '+' which is used for international numbers
|
|
12
|
+
const cleanedPhoneNumber = phoneNumber.replace(/[^\d+]/g, '');
|
|
13
|
+
return `tel:${cleanedPhoneNumber}`;
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=links.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"links.js","sourceRoot":"","sources":["../src/links.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,WAAmB,EAAU,EAAE;IACxD,IAAI,OAAO,WAAW,KAAK,QAAQ,EAAE,CAAC;QACpC,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAC;IACpD,CAAC;IAED,qFAAqF;IACrF,MAAM,kBAAkB,GAAG,WAAW,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC;IAE9D,OAAO,OAAO,kBAAkB,EAAE,CAAC;AACrC,CAAC,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A branded type for cache tags. This is created by intersecting `string`
|
|
3
|
+
* with `{ readonly _: unique symbol }`, making it a unique type.
|
|
4
|
+
* Although it is fundamentally a string, it is treated as a distinct type
|
|
5
|
+
* due to the unique symbol.
|
|
6
|
+
*/
|
|
7
|
+
export type CacheTag = string & {
|
|
8
|
+
readonly _: unique symbol;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* A type representing the structure of a webhook payload for cache tag invalidation.
|
|
12
|
+
* It includes the entity type, event type, and the entity details which contain
|
|
13
|
+
* the cache tags to be invalidated.
|
|
14
|
+
*/
|
|
15
|
+
export type CacheTagsInvalidateWebhook = {
|
|
16
|
+
entity_type: 'cda_cache_tags';
|
|
17
|
+
event_type: 'invalidate';
|
|
18
|
+
entity: {
|
|
19
|
+
id: 'cda_cache_tags';
|
|
20
|
+
type: 'cda_cache_tags';
|
|
21
|
+
attributes: {
|
|
22
|
+
tags: CacheTag[];
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
};
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type DocumentNode } from 'graphql';
|
|
2
|
+
import { type CacheTag } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Converts the value of DatoCMS's `X-Cache-Tags` header into an array of strings typed as `CacheTag`.
|
|
5
|
+
* For example, it transforms `'tag-a tag-2 other-tag'` into `['tag-a', 'tag-2', 'other-tag']`.
|
|
6
|
+
*
|
|
7
|
+
* @param string String value of the `X-Cache-Tags` header
|
|
8
|
+
* @returns Array of strings typed as `CacheTag`
|
|
9
|
+
*/
|
|
10
|
+
export declare const parseXCacheTagsResponseHeader: (string?: null | string) => CacheTag[];
|
|
11
|
+
/**
|
|
12
|
+
* Generates a unique query ID based on the query document and its variables.
|
|
13
|
+
*
|
|
14
|
+
* @param {DocumentNode} document Query document
|
|
15
|
+
* @param {TVariables} variables Query variables
|
|
16
|
+
* @returns Unique query ID
|
|
17
|
+
*/
|
|
18
|
+
export declare const generateQueryId: <TVariables = unknown>(document: DocumentNode, variables?: TVariables) => string;
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { print } from 'graphql';
|
|
2
|
+
import { createHash } from 'node:crypto';
|
|
3
|
+
/**
|
|
4
|
+
* Converts the value of DatoCMS's `X-Cache-Tags` header into an array of strings typed as `CacheTag`.
|
|
5
|
+
* For example, it transforms `'tag-a tag-2 other-tag'` into `['tag-a', 'tag-2', 'other-tag']`.
|
|
6
|
+
*
|
|
7
|
+
* @param string String value of the `X-Cache-Tags` header
|
|
8
|
+
* @returns Array of strings typed as `CacheTag`
|
|
9
|
+
*/
|
|
10
|
+
export const parseXCacheTagsResponseHeader = (string) => (string?.split(' ') ?? []).map((tag) => tag);
|
|
11
|
+
/**
|
|
12
|
+
* Generates a unique query ID based on the query document and its variables.
|
|
13
|
+
*
|
|
14
|
+
* @param {DocumentNode} document Query document
|
|
15
|
+
* @param {TVariables} variables Query variables
|
|
16
|
+
* @returns Unique query ID
|
|
17
|
+
*/
|
|
18
|
+
export const generateQueryId = (document, variables) => {
|
|
19
|
+
return createHash('sha1')
|
|
20
|
+
.update(print(document))
|
|
21
|
+
.update(JSON.stringify(variables) || '')
|
|
22
|
+
.digest('hex');
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAqB,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAGzC;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,6BAA6B,GAAG,CAAC,MAAsB,EAAE,EAAE,CACtE,CAAC,MAAM,EAAE,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAe,CAAC,CAAC;AAE3D;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAAuB,QAAsB,EAAE,SAAsB,EAAU,EAAE;IAC9G,OAAO,UAAU,CAAC,MAAM,CAAC;SACtB,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;SACvB,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC;SACvC,MAAM,CAAC,KAAK,CAAC,CAAC;AACnB,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,23 +1,27 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@smartive/datocms-utils",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.2",
|
|
4
4
|
"description": "A set of utilities and helpers to work with DatoCMS in a Next.js project.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"source": "./src/index.ts",
|
|
7
7
|
"main": "./dist/index.js",
|
|
8
8
|
"types": "./dist/index.d.ts",
|
|
9
|
+
"files": [
|
|
10
|
+
"dist/**/*",
|
|
11
|
+
"src/**/*"
|
|
12
|
+
],
|
|
9
13
|
"exports": {
|
|
10
14
|
".": {
|
|
11
15
|
"types": "./dist/index.d.ts",
|
|
12
|
-
"
|
|
16
|
+
"default": "./dist/index.js"
|
|
13
17
|
},
|
|
14
18
|
"./redis": {
|
|
15
19
|
"types": "./dist/cache-tags-redis.d.ts",
|
|
16
|
-
"
|
|
20
|
+
"default": "./dist/cache-tags-redis.js"
|
|
17
21
|
},
|
|
18
22
|
"./postgres": {
|
|
19
23
|
"types": "./dist/cache-tags.d.ts",
|
|
20
|
-
"
|
|
24
|
+
"default": "./dist/cache-tags.js"
|
|
21
25
|
}
|
|
22
26
|
},
|
|
23
27
|
"scripts": {
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
name: Release npm package
|
|
2
|
-
|
|
3
|
-
on:
|
|
4
|
-
push:
|
|
5
|
-
branches:
|
|
6
|
-
- main
|
|
7
|
-
|
|
8
|
-
permissions:
|
|
9
|
-
contents: write # to be able to publish a GitHub release
|
|
10
|
-
issues: write # to be able to comment on released issues
|
|
11
|
-
pull-requests: write # to be able to comment on released pull requests
|
|
12
|
-
id-token: write # to enable use of OIDC for trusted publishing and npm provenance
|
|
13
|
-
|
|
14
|
-
jobs:
|
|
15
|
-
release:
|
|
16
|
-
name: Build & release
|
|
17
|
-
runs-on: ubuntu-latest
|
|
18
|
-
|
|
19
|
-
steps:
|
|
20
|
-
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
|
|
21
|
-
- uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6
|
|
22
|
-
with:
|
|
23
|
-
node-version: 24
|
|
24
|
-
- run: npm ci
|
|
25
|
-
- run: npm run build
|
|
26
|
-
- name: semantic release
|
|
27
|
-
uses: cycjimmy/semantic-release-action@v6
|
|
28
|
-
with:
|
|
29
|
-
semantic_version: 25
|
|
30
|
-
extra_plugins: |
|
|
31
|
-
@semantic-release/changelog@6
|
|
32
|
-
env:
|
|
33
|
-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
name: Test
|
|
2
|
-
|
|
3
|
-
on:
|
|
4
|
-
pull_request:
|
|
5
|
-
branches:
|
|
6
|
-
- '**'
|
|
7
|
-
|
|
8
|
-
concurrency:
|
|
9
|
-
group: tests-${{ github.ref }}
|
|
10
|
-
cancel-in-progress: true
|
|
11
|
-
|
|
12
|
-
jobs:
|
|
13
|
-
test:
|
|
14
|
-
name: Lint & test
|
|
15
|
-
runs-on: ubuntu-latest
|
|
16
|
-
|
|
17
|
-
steps:
|
|
18
|
-
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
|
|
19
|
-
- uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6
|
|
20
|
-
with:
|
|
21
|
-
node-version: 24
|
|
22
|
-
- run: npm ci
|
|
23
|
-
- run: npm run prettier
|
|
24
|
-
- run: npm run lint
|
|
25
|
-
- run: npm run build
|
package/.nvmrc
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
24
|
package/.prettierrc.json
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"@smartive/prettier-config"
|
package/.releaserc.json
DELETED
package/CHANGELOG.md
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
## [2.3.1](https://github.com/smartive/datocms-utils/compare/v2.3.0...v2.3.1) (2026-02-12)
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
### Bug Fixes
|
|
5
|
-
|
|
6
|
-
* use correct named exports ([#208](https://github.com/smartive/datocms-utils/issues/208)) ([da25d87](https://github.com/smartive/datocms-utils/commit/da25d87e9df309881cc10128c20a61ca48579e79))
|
package/eslint.config.mjs
DELETED
package/renovate.json
DELETED
package/tsconfig.json
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"declaration": true,
|
|
4
|
-
"outDir": "./dist/",
|
|
5
|
-
"rootDirs": ["./src"],
|
|
6
|
-
"sourceMap": true,
|
|
7
|
-
"strict": true,
|
|
8
|
-
"noImplicitReturns": true,
|
|
9
|
-
"noImplicitAny": true,
|
|
10
|
-
"moduleResolution": "node",
|
|
11
|
-
"allowSyntheticDefaultImports": true,
|
|
12
|
-
"allowJs": true,
|
|
13
|
-
"resolveJsonModule": true,
|
|
14
|
-
"module": "esnext",
|
|
15
|
-
"target": "esnext"
|
|
16
|
-
},
|
|
17
|
-
"include": ["./src/**/*"]
|
|
18
|
-
}
|