@smartive/datocms-utils 3.0.0-next.8 → 3.0.0-next.9
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/README.md +9 -9
- package/dist/cache-tags/provider/neon.d.ts +5 -5
- package/dist/cache-tags/provider/neon.js +2 -2
- package/dist/cache-tags/provider/neon.js.map +1 -1
- package/dist/cache-tags/provider/noop.d.ts +3 -3
- package/dist/cache-tags/provider/noop.js +2 -2
- package/dist/cache-tags/provider/noop.js.map +1 -1
- package/dist/cache-tags/provider/redis.d.ts +5 -5
- package/dist/cache-tags/provider/redis.js +2 -2
- package/dist/cache-tags/provider/redis.js.map +1 -1
- package/dist/cache-tags/types.d.ts +2 -2
- package/package.json +1 -1
- package/src/cache-tags/provider/neon.ts +5 -5
- package/src/cache-tags/provider/noop.ts +3 -3
- package/src/cache-tags/provider/redis.ts +5 -5
- package/src/cache-tags/types.ts +2 -2
package/README.md
CHANGED
|
@@ -53,7 +53,7 @@ const tags = parseXCacheTagsResponseHeader('tag-a tag-2 other-tag');
|
|
|
53
53
|
|
|
54
54
|
#### Storage Providers
|
|
55
55
|
|
|
56
|
-
The package provides two storage backends for cache tags: **Neon (Postgres)** and **Redis**. Both implement the same `
|
|
56
|
+
The package provides two storage backends for cache tags: **Neon (Postgres)** and **Redis**. Both implement the same `CacheTagsProvider` interface.
|
|
57
57
|
|
|
58
58
|
##### Neon (Postgres) Provider
|
|
59
59
|
|
|
@@ -80,9 +80,9 @@ npm install @neondatabase/serverless
|
|
|
80
80
|
3. Create and use the store:
|
|
81
81
|
|
|
82
82
|
```typescript
|
|
83
|
-
import {
|
|
83
|
+
import { NeonCacheTagsProvider } from '@smartive/datocms-utils/cache-tags/neon';
|
|
84
84
|
|
|
85
|
-
const provider = new
|
|
85
|
+
const provider = new NeonCacheTagsProvider({
|
|
86
86
|
connectionString: process.env.DATABASE_URL!,
|
|
87
87
|
table: 'query_cache_tags',
|
|
88
88
|
});
|
|
@@ -115,9 +115,9 @@ npm install ioredis
|
|
|
115
115
|
2. Create and use the provider:
|
|
116
116
|
|
|
117
117
|
```typescript
|
|
118
|
-
import {
|
|
118
|
+
import { RedisCacheTagsProvider } from '@smartive/datocms-utils/cache-tags/redis';
|
|
119
119
|
|
|
120
|
-
const provider = new
|
|
120
|
+
const provider = new RedisCacheTagsProvider({
|
|
121
121
|
url: process.env.REDIS_URL!,
|
|
122
122
|
keyPrefix: 'prod:', // Optional: namespace for multi-environment setups
|
|
123
123
|
});
|
|
@@ -142,7 +142,7 @@ REDIS_URL=redis://username:password@redis-host:6379
|
|
|
142
142
|
REDIS_URL=redis://localhost:6379
|
|
143
143
|
```
|
|
144
144
|
|
|
145
|
-
#### `
|
|
145
|
+
#### `CacheTagsProvider` Interface
|
|
146
146
|
|
|
147
147
|
Both providers implement:
|
|
148
148
|
|
|
@@ -155,9 +155,9 @@ Both providers implement:
|
|
|
155
155
|
|
|
156
156
|
```typescript
|
|
157
157
|
import { generateQueryId, parseXCacheTagsResponseHeader } from '@smartive/datocms-utils/cache';
|
|
158
|
-
import {
|
|
158
|
+
import { RedisCacheTagsProvider } from '@smartive/datocms-utils/cache-tags/redis';
|
|
159
159
|
|
|
160
|
-
const provider = new
|
|
160
|
+
const provider = new RedisCacheTagsProvider({
|
|
161
161
|
url: process.env.REDIS_URL!,
|
|
162
162
|
keyPrefix: 'myapp:',
|
|
163
163
|
});
|
|
@@ -179,7 +179,7 @@ The package includes TypeScript types for DatoCMS webhooks and cache tags:
|
|
|
179
179
|
|
|
180
180
|
- `CacheTag`: A branded type for cache tags, ensuring type safety
|
|
181
181
|
- `CacheTagsInvalidateWebhook`: Type definition for DatoCMS cache tag invalidation webhook payloads
|
|
182
|
-
- `
|
|
182
|
+
- `CacheTagsProvider`: Interface for cache tag storage implementations
|
|
183
183
|
|
|
184
184
|
## License
|
|
185
185
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { type CacheTag, type
|
|
2
|
-
type
|
|
1
|
+
import { type CacheTag, type CacheTagsProvider } from '../types.js';
|
|
2
|
+
type NeonCacheTagsProviderConfig = {
|
|
3
3
|
/**
|
|
4
4
|
* Neon connection string. You can find it in the "Connection" tab of your Neon project dashboard.
|
|
5
5
|
* Has the format `postgresql://user:pass@host/db`
|
|
@@ -19,12 +19,12 @@ type NeonDatoCacheTagsProviderConfig = {
|
|
|
19
19
|
readonly table: string;
|
|
20
20
|
};
|
|
21
21
|
/**
|
|
22
|
-
* A `
|
|
22
|
+
* A `CacheTagsProvider` implementation that uses Neon as the storage backend.
|
|
23
23
|
*/
|
|
24
|
-
export declare class
|
|
24
|
+
export declare class NeonCacheTagsProvider implements CacheTagsProvider {
|
|
25
25
|
private readonly sql;
|
|
26
26
|
private readonly table;
|
|
27
|
-
constructor({ connectionUrl, table }:
|
|
27
|
+
constructor({ connectionUrl, table }: NeonCacheTagsProviderConfig);
|
|
28
28
|
storeQueryCacheTags(queryId: string, cacheTags: CacheTag[]): Promise<void>;
|
|
29
29
|
queriesReferencingCacheTags(cacheTags: CacheTag[]): Promise<string[]>;
|
|
30
30
|
deleteCacheTags(cacheTags: CacheTag[]): Promise<number>;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { neon } from '@neondatabase/serverless';
|
|
2
2
|
/**
|
|
3
|
-
* A `
|
|
3
|
+
* A `CacheTagsProvider` implementation that uses Neon as the storage backend.
|
|
4
4
|
*/
|
|
5
|
-
export class
|
|
5
|
+
export class NeonCacheTagsProvider {
|
|
6
6
|
sql;
|
|
7
7
|
table;
|
|
8
8
|
constructor({ connectionUrl, table }) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"neon.js","sourceRoot":"","sources":["../../../src/cache-tags/provider/neon.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAC;AAuBhD;;GAEG;AACH,MAAM,OAAO,
|
|
1
|
+
{"version":3,"file":"neon.js","sourceRoot":"","sources":["../../../src/cache-tags/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
+
* A `CacheTagsProvider` implementation that does not perform any actual storage operations.
|
|
4
4
|
*
|
|
5
5
|
* _Note: This implementation is useful for testing purposes or when you want to disable caching without changing the code that interacts with the cache._
|
|
6
6
|
*/
|
|
7
|
-
export declare class
|
|
7
|
+
export declare class NoopCacheTagsProvider implements CacheTagsProvider {
|
|
8
8
|
storeQueryCacheTags(queryId: string, cacheTags: CacheTag[]): Promise<void>;
|
|
9
9
|
queriesReferencingCacheTags(cacheTags: CacheTag[]): Promise<string[]>;
|
|
10
10
|
deleteCacheTags(cacheTags: CacheTag[]): Promise<number>;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* A `
|
|
2
|
+
* A `CacheTagsProvider` implementation that does not perform any actual storage operations.
|
|
3
3
|
*
|
|
4
4
|
* _Note: This implementation is useful for testing purposes or when you want to disable caching without changing the code that interacts with the cache._
|
|
5
5
|
*/
|
|
6
|
-
export class
|
|
6
|
+
export class NoopCacheTagsProvider {
|
|
7
7
|
async storeQueryCacheTags(queryId, cacheTags) {
|
|
8
8
|
console.debug('-- storeQueryCacheTags called', { queryId, cacheTags });
|
|
9
9
|
return Promise.resolve();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"noop.js","sourceRoot":"","sources":["../../../src/cache-tags/provider/noop.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,MAAM,OAAO,
|
|
1
|
+
{"version":3,"file":"noop.js","sourceRoot":"","sources":["../../../src/cache-tags/provider/noop.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,MAAM,OAAO,qBAAqB;IACzB,KAAK,CAAC,mBAAmB,CAAC,OAAe,EAAE,SAAqB;QACrE,OAAO,CAAC,KAAK,CAAC,+BAA+B,EAAE,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC,CAAC;QAEvE,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;IAC3B,CAAC;IAEM,KAAK,CAAC,2BAA2B,CAAC,SAAqB;QAC5D,OAAO,CAAC,KAAK,CAAC,uCAAuC,EAAE,EAAE,SAAS,EAAE,CAAC,CAAC;QAEtE,OAAO,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;IAC7B,CAAC;IAEM,KAAK,CAAC,eAAe,CAAC,SAAqB;QAChD,OAAO,CAAC,KAAK,CAAC,2BAA2B,EAAE,EAAE,SAAS,EAAE,CAAC,CAAC;QAE1D,OAAO,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IAC5B,CAAC;IAEM,KAAK,CAAC,iBAAiB;QAC5B,OAAO,CAAC,KAAK,CAAC,6BAA6B,CAAC,CAAC;QAE7C,OAAO,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IAC5B,CAAC;CACF"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { type CacheTag, type
|
|
2
|
-
type
|
|
1
|
+
import { type CacheTag, type CacheTagsProvider } from '../types.js';
|
|
2
|
+
type RedisCacheTagsProviderConfig = {
|
|
3
3
|
/**
|
|
4
4
|
* Redis connection string. For example, `redis://user:pass@host:port/db`.
|
|
5
5
|
*/
|
|
@@ -12,12 +12,12 @@ type RedisDatoCacheTagsProviderConfig = {
|
|
|
12
12
|
readonly keyPrefix?: string;
|
|
13
13
|
};
|
|
14
14
|
/**
|
|
15
|
-
* A `
|
|
15
|
+
* A `CacheTagsProvider` implementation that uses Redis as the storage backend.
|
|
16
16
|
*/
|
|
17
|
-
export declare class
|
|
17
|
+
export declare class RedisCacheTagsProvider implements CacheTagsProvider {
|
|
18
18
|
private readonly redis;
|
|
19
19
|
private readonly keyPrefix;
|
|
20
|
-
constructor({ connectionUrl, keyPrefix }:
|
|
20
|
+
constructor({ connectionUrl, keyPrefix }: RedisCacheTagsProviderConfig);
|
|
21
21
|
storeQueryCacheTags(queryId: string, cacheTags: CacheTag[]): Promise<void>;
|
|
22
22
|
queriesReferencingCacheTags(cacheTags: CacheTag[]): Promise<string[]>;
|
|
23
23
|
deleteCacheTags(cacheTags: CacheTag[]): Promise<number>;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Redis } from 'ioredis';
|
|
2
2
|
/**
|
|
3
|
-
* A `
|
|
3
|
+
* A `CacheTagsProvider` implementation that uses Redis as the storage backend.
|
|
4
4
|
*/
|
|
5
|
-
export class
|
|
5
|
+
export class RedisCacheTagsProvider {
|
|
6
6
|
redis;
|
|
7
7
|
keyPrefix;
|
|
8
8
|
constructor({ connectionUrl, keyPrefix }) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"redis.js","sourceRoot":"","sources":["../../../src/cache-tags/provider/redis.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAgBhC;;GAEG;AACH,MAAM,OAAO,
|
|
1
|
+
{"version":3,"file":"redis.js","sourceRoot":"","sources":["../../../src/cache-tags/provider/redis.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAgBhC;;GAEG;AACH,MAAM,OAAO,sBAAsB;IAChB,KAAK,CAAC;IACN,SAAS,CAAC;IAE3B,YAAY,EAAE,aAAa,EAAE,SAAS,EAAgC;QACpE,IAAI,CAAC,KAAK,GAAG,IAAI,KAAK,CAAC,aAAa,EAAE;YACpC,oBAAoB,EAAE,CAAC;YACvB,WAAW,EAAE,IAAI;SAClB,CAAC,CAAC;QACH,IAAI,CAAC,SAAS,GAAG,SAAS,IAAI,EAAE,CAAC;IACnC,CAAC;IAEM,KAAK,CAAC,mBAAmB,CAAC,OAAe,EAAE,SAAqB;QACrE,IAAI,CAAC,SAAS,EAAE,MAAM,EAAE,CAAC;YACvB,OAAO;QACT,CAAC;QAED,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC;QAEvC,KAAK,MAAM,GAAG,IAAI,SAAS,EAAE,CAAC;YAC5B,QAAQ,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,SAAS,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26
|
/**
|
|
27
|
-
* Configuration object for creating a `
|
|
27
|
+
* Configuration object for creating a `CacheTagsProvider` implementation.
|
|
28
28
|
*/
|
|
29
|
-
export interface
|
|
29
|
+
export interface CacheTagsProvider {
|
|
30
30
|
/**
|
|
31
31
|
* Stores the cache tags of a query.
|
|
32
32
|
*
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { neon } from '@neondatabase/serverless';
|
|
2
|
-
import { type CacheTag, type
|
|
2
|
+
import { type CacheTag, type CacheTagsProvider } from '../types.js';
|
|
3
3
|
|
|
4
|
-
type
|
|
4
|
+
type NeonCacheTagsProviderConfig = {
|
|
5
5
|
/**
|
|
6
6
|
* Neon connection string. You can find it in the "Connection" tab of your Neon project dashboard.
|
|
7
7
|
* Has the format `postgresql://user:pass@host/db`
|
|
@@ -22,13 +22,13 @@ type NeonDatoCacheTagsProviderConfig = {
|
|
|
22
22
|
};
|
|
23
23
|
|
|
24
24
|
/**
|
|
25
|
-
* A `
|
|
25
|
+
* A `CacheTagsProvider` implementation that uses Neon as the storage backend.
|
|
26
26
|
*/
|
|
27
|
-
export class
|
|
27
|
+
export class NeonCacheTagsProvider implements CacheTagsProvider {
|
|
28
28
|
private readonly sql;
|
|
29
29
|
private readonly table;
|
|
30
30
|
|
|
31
|
-
constructor({ connectionUrl, table }:
|
|
31
|
+
constructor({ connectionUrl, table }: NeonCacheTagsProviderConfig) {
|
|
32
32
|
this.sql = neon(connectionUrl, { fullResults: true });
|
|
33
33
|
this.table = table;
|
|
34
34
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { type CacheTag, type
|
|
1
|
+
import { type CacheTag, type CacheTagsProvider } from '../types.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* A `
|
|
4
|
+
* A `CacheTagsProvider` implementation that does not perform any actual storage operations.
|
|
5
5
|
*
|
|
6
6
|
* _Note: This implementation is useful for testing purposes or when you want to disable caching without changing the code that interacts with the cache._
|
|
7
7
|
*/
|
|
8
|
-
export class
|
|
8
|
+
export class NoopCacheTagsProvider implements CacheTagsProvider {
|
|
9
9
|
public async storeQueryCacheTags(queryId: string, cacheTags: CacheTag[]) {
|
|
10
10
|
console.debug('-- storeQueryCacheTags called', { queryId, cacheTags });
|
|
11
11
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Redis } from 'ioredis';
|
|
2
|
-
import { type CacheTag, type
|
|
2
|
+
import { type CacheTag, type CacheTagsProvider } from '../types.js';
|
|
3
3
|
|
|
4
|
-
type
|
|
4
|
+
type RedisCacheTagsProviderConfig = {
|
|
5
5
|
/**
|
|
6
6
|
* Redis connection string. For example, `redis://user:pass@host:port/db`.
|
|
7
7
|
*/
|
|
@@ -15,13 +15,13 @@ type RedisDatoCacheTagsProviderConfig = {
|
|
|
15
15
|
};
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
|
-
* A `
|
|
18
|
+
* A `CacheTagsProvider` implementation that uses Redis as the storage backend.
|
|
19
19
|
*/
|
|
20
|
-
export class
|
|
20
|
+
export class RedisCacheTagsProvider implements CacheTagsProvider {
|
|
21
21
|
private readonly redis;
|
|
22
22
|
private readonly keyPrefix;
|
|
23
23
|
|
|
24
|
-
constructor({ connectionUrl, keyPrefix }:
|
|
24
|
+
constructor({ connectionUrl, keyPrefix }: RedisCacheTagsProviderConfig) {
|
|
25
25
|
this.redis = new Redis(connectionUrl, {
|
|
26
26
|
maxRetriesPerRequest: 3,
|
|
27
27
|
lazyConnect: true,
|
package/src/cache-tags/types.ts
CHANGED
|
@@ -24,9 +24,9 @@ export type CacheTagsInvalidateWebhook = {
|
|
|
24
24
|
};
|
|
25
25
|
|
|
26
26
|
/**
|
|
27
|
-
* Configuration object for creating a `
|
|
27
|
+
* Configuration object for creating a `CacheTagsProvider` implementation.
|
|
28
28
|
*/
|
|
29
|
-
export interface
|
|
29
|
+
export interface CacheTagsProvider {
|
|
30
30
|
/**
|
|
31
31
|
* Stores the cache tags of a query.
|
|
32
32
|
*
|