@smartive/datocms-utils 1.6.0 → 2.0.0
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/CHANGELOG.md +9 -2
- package/dist/cache-tags.d.ts +9 -4
- package/dist/cache-tags.js +15 -8
- package/dist/cache-tags.js.map +1 -1
- package/package.json +1 -1
- package/src/cache-tags.ts +16 -10
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
|
-
# [
|
|
1
|
+
# [2.0.0](https://github.com/smartive/datocms-utils/compare/v1.6.0...v2.0.0) (2025-04-09)
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
### Features
|
|
5
5
|
|
|
6
|
-
* add
|
|
6
|
+
* add parameterization for cache tags insert query ([#88](https://github.com/smartive/datocms-utils/issues/88)) ([4e72aae](https://github.com/smartive/datocms-utils/commit/4e72aae5edc9561093da6bc405f1994e324e1394))
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### BREAKING CHANGES
|
|
10
|
+
|
|
11
|
+
* The tableId must now be specified
|
|
12
|
+
|
|
13
|
+
* remove log
|
package/dist/cache-tags.d.ts
CHANGED
|
@@ -21,22 +21,27 @@ export declare const generateQueryId: <TVariables = unknown>(document: DocumentN
|
|
|
21
21
|
*
|
|
22
22
|
* @param {string} queryId Unique query ID
|
|
23
23
|
* @param {CacheTag[]} cacheTags Array of cache tags
|
|
24
|
+
* @param {string} tableId Database table ID
|
|
24
25
|
*/
|
|
25
|
-
export declare const storeQueryCacheTags: (queryId: string, cacheTags: CacheTag[]) => Promise<void>;
|
|
26
|
+
export declare const storeQueryCacheTags: (queryId: string, cacheTags: CacheTag[], tableId: string) => Promise<void>;
|
|
26
27
|
/**
|
|
27
28
|
* Retrieves the queries that reference cache tags.
|
|
28
29
|
*
|
|
29
30
|
* @param {CacheTag[]} cacheTags Array of cache tags
|
|
31
|
+
* @param {string} tableId Database table ID
|
|
30
32
|
* @returns Array of query IDs
|
|
31
33
|
*/
|
|
32
|
-
export declare const queriesReferencingCacheTags: (cacheTags: CacheTag[]) => Promise<string[]>;
|
|
34
|
+
export declare const queriesReferencingCacheTags: (cacheTags: CacheTag[], tableId: string) => Promise<string[]>;
|
|
33
35
|
/**
|
|
34
36
|
* Deletes the cache tags of a query from the database.
|
|
35
37
|
*
|
|
36
38
|
* @param {string} queryId Unique query ID
|
|
39
|
+
* @param {string} tableId Database table ID
|
|
37
40
|
*/
|
|
38
|
-
export declare const deleteQueries: (queryIds: string[]) => Promise<void>;
|
|
41
|
+
export declare const deleteQueries: (queryIds: string[], tableId: string) => Promise<void>;
|
|
39
42
|
/**
|
|
40
43
|
* Wipes out all cache tags from the database.
|
|
44
|
+
*
|
|
45
|
+
* @param {string} tableId Database table ID
|
|
41
46
|
*/
|
|
42
|
-
export declare function truncateCacheTags(): Promise<void>;
|
|
47
|
+
export declare function truncateCacheTags(tableId: string): Promise<void>;
|
package/dist/cache-tags.js
CHANGED
|
@@ -32,41 +32,48 @@ export const generateQueryId = (document, variables) => {
|
|
|
32
32
|
*
|
|
33
33
|
* @param {string} queryId Unique query ID
|
|
34
34
|
* @param {CacheTag[]} cacheTags Array of cache tags
|
|
35
|
+
* @param {string} tableId Database table ID
|
|
35
36
|
*/
|
|
36
|
-
export const storeQueryCacheTags = async (queryId, cacheTags) => {
|
|
37
|
+
export const storeQueryCacheTags = async (queryId, cacheTags, tableId) => {
|
|
37
38
|
if (!cacheTags?.length) {
|
|
38
39
|
return;
|
|
39
40
|
}
|
|
40
|
-
|
|
41
|
+
const parameters = cacheTags.flatMap((_, i) => [queryId, cacheTags[i]]);
|
|
42
|
+
const placeholders = cacheTags.map((_, i) => `($${2 * i + 1}, $${2 * i + 2})`).join(',');
|
|
43
|
+
await sql.query(`INSERT INTO ${tableId} VALUES ${placeholders} ON CONFLICT DO NOTHING`, parameters);
|
|
41
44
|
};
|
|
42
45
|
/**
|
|
43
46
|
* Retrieves the queries that reference cache tags.
|
|
44
47
|
*
|
|
45
48
|
* @param {CacheTag[]} cacheTags Array of cache tags
|
|
49
|
+
* @param {string} tableId Database table ID
|
|
46
50
|
* @returns Array of query IDs
|
|
47
51
|
*/
|
|
48
|
-
export const queriesReferencingCacheTags = async (cacheTags) => {
|
|
52
|
+
export const queriesReferencingCacheTags = async (cacheTags, tableId) => {
|
|
49
53
|
if (!cacheTags?.length) {
|
|
50
54
|
return [];
|
|
51
55
|
}
|
|
52
|
-
const { rows } = await sql.query(`SELECT DISTINCT query_id FROM
|
|
56
|
+
const { rows } = await sql.query(`SELECT DISTINCT query_id FROM ${tableId} WHERE cache_tag IN (${cacheTags.map((cacheTag) => `'${cacheTag}'`).join(', ')})`);
|
|
53
57
|
return rows.map((row) => row.query_id);
|
|
54
58
|
};
|
|
55
59
|
/**
|
|
56
60
|
* Deletes the cache tags of a query from the database.
|
|
57
61
|
*
|
|
58
62
|
* @param {string} queryId Unique query ID
|
|
63
|
+
* @param {string} tableId Database table ID
|
|
59
64
|
*/
|
|
60
|
-
export const deleteQueries = async (queryIds) => {
|
|
65
|
+
export const deleteQueries = async (queryIds, tableId) => {
|
|
61
66
|
if (!queryIds?.length) {
|
|
62
67
|
return;
|
|
63
68
|
}
|
|
64
|
-
await sql.query(`DELETE FROM
|
|
69
|
+
await sql.query(`DELETE FROM ${tableId} WHERE query_id IN (${queryIds.map((id) => `'${id}'`).join(', ')})`);
|
|
65
70
|
};
|
|
66
71
|
/**
|
|
67
72
|
* Wipes out all cache tags from the database.
|
|
73
|
+
*
|
|
74
|
+
* @param {string} tableId Database table ID
|
|
68
75
|
*/
|
|
69
|
-
export async function truncateCacheTags() {
|
|
70
|
-
await sql.query(
|
|
76
|
+
export async function truncateCacheTags(tableId) {
|
|
77
|
+
await sql.query(`DELETE FROM ${tableId}`);
|
|
71
78
|
}
|
|
72
79
|
//# sourceMappingURL=cache-tags.js.map
|
package/dist/cache-tags.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cache-tags.js","sourceRoot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AqC,MAAM,GAAG,CAAC,KAAK,CAChE,iCAAiC,OAAO,wBAAwB,SAAS,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,IAAI,QAAQ,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAC3H,CAAC;IAEF,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;AACzC,CAAC,CAAC;AAEF;;;;;GAKG;AAEH,MAAM,CAAC,MAAM,aAAa,GAAG,KAAK,EAAE,QAAkB,EAAE,OAAe,EAAE,EAAE;IACzE,IAAI,CAAC,QAAQ,EAAE,MAAM,EAAE,CAAC;QACtB,OAAO;IACT,CAAC;IACD,MAAM,GAAG,CAAC,KAAK,CAAC,eAAe,OAAO,uBAAuB,QAAQ,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC9G,CAAC,CAAC;AAEF;;;;GAIG;AAEH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAAC,OAAe;IACrD,MAAM,GAAG,CAAC,KAAK,CAAC,eAAe,OAAO,EAAE,CAAC,CAAC;AAC5C,CAAC"}
|
package/package.json
CHANGED
package/src/cache-tags.ts
CHANGED
|
@@ -39,31 +39,34 @@ export const generateQueryId = <TVariables = unknown>(document: DocumentNode, va
|
|
|
39
39
|
*
|
|
40
40
|
* @param {string} queryId Unique query ID
|
|
41
41
|
* @param {CacheTag[]} cacheTags Array of cache tags
|
|
42
|
+
* @param {string} tableId Database table ID
|
|
42
43
|
*/
|
|
43
44
|
|
|
44
|
-
export const storeQueryCacheTags = async (queryId: string, cacheTags: CacheTag[]) => {
|
|
45
|
+
export const storeQueryCacheTags = async (queryId: string, cacheTags: CacheTag[], tableId: string) => {
|
|
45
46
|
if (!cacheTags?.length) {
|
|
46
47
|
return;
|
|
47
48
|
}
|
|
48
49
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
50
|
+
const parameters = cacheTags.flatMap((_, i) => [queryId, cacheTags[i]]);
|
|
51
|
+
const placeholders = cacheTags.map((_, i) => `($${2 * i + 1}, $${2 * i + 2})`).join(',');
|
|
52
|
+
|
|
53
|
+
await sql.query(`INSERT INTO ${tableId} VALUES ${placeholders} ON CONFLICT DO NOTHING`, parameters);
|
|
52
54
|
};
|
|
53
55
|
|
|
54
56
|
/**
|
|
55
57
|
* Retrieves the queries that reference cache tags.
|
|
56
58
|
*
|
|
57
59
|
* @param {CacheTag[]} cacheTags Array of cache tags
|
|
60
|
+
* @param {string} tableId Database table ID
|
|
58
61
|
* @returns Array of query IDs
|
|
59
62
|
*/
|
|
60
63
|
|
|
61
|
-
export const queriesReferencingCacheTags = async (cacheTags: CacheTag[]): Promise<string[]> => {
|
|
64
|
+
export const queriesReferencingCacheTags = async (cacheTags: CacheTag[], tableId: string): Promise<string[]> => {
|
|
62
65
|
if (!cacheTags?.length) {
|
|
63
66
|
return [];
|
|
64
67
|
}
|
|
65
68
|
const { rows }: { rows: { query_id: string }[] } = await sql.query(
|
|
66
|
-
`SELECT DISTINCT query_id FROM
|
|
69
|
+
`SELECT DISTINCT query_id FROM ${tableId} WHERE cache_tag IN (${cacheTags.map((cacheTag) => `'${cacheTag}'`).join(', ')})`,
|
|
67
70
|
);
|
|
68
71
|
|
|
69
72
|
return rows.map((row) => row.query_id);
|
|
@@ -73,19 +76,22 @@ export const queriesReferencingCacheTags = async (cacheTags: CacheTag[]): Promis
|
|
|
73
76
|
* Deletes the cache tags of a query from the database.
|
|
74
77
|
*
|
|
75
78
|
* @param {string} queryId Unique query ID
|
|
79
|
+
* @param {string} tableId Database table ID
|
|
76
80
|
*/
|
|
77
81
|
|
|
78
|
-
export const deleteQueries = async (queryIds: string[]) => {
|
|
82
|
+
export const deleteQueries = async (queryIds: string[], tableId: string) => {
|
|
79
83
|
if (!queryIds?.length) {
|
|
80
84
|
return;
|
|
81
85
|
}
|
|
82
|
-
await sql.query(`DELETE FROM
|
|
86
|
+
await sql.query(`DELETE FROM ${tableId} WHERE query_id IN (${queryIds.map((id) => `'${id}'`).join(', ')})`);
|
|
83
87
|
};
|
|
84
88
|
|
|
85
89
|
/**
|
|
86
90
|
* Wipes out all cache tags from the database.
|
|
91
|
+
*
|
|
92
|
+
* @param {string} tableId Database table ID
|
|
87
93
|
*/
|
|
88
94
|
|
|
89
|
-
export async function truncateCacheTags() {
|
|
90
|
-
await sql.query(
|
|
95
|
+
export async function truncateCacheTags(tableId: string) {
|
|
96
|
+
await sql.query(`DELETE FROM ${tableId}`);
|
|
91
97
|
}
|