@baeta/cache 2.0.0-next.15 → 2.0.0-next.17
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 +170 -14
- package/README.md +2 -1
- package/dist/index.d.ts +3 -13
- package/dist/index.js +35 -11
- package/dist/index.js.map +1 -1
- package/package.json +2 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,28 +1,184 @@
|
|
|
1
1
|
# @baeta/cache
|
|
2
2
|
|
|
3
|
-
## 2.0.0-next.
|
|
3
|
+
## 2.0.0-next.17
|
|
4
4
|
|
|
5
5
|
### Patch Changes
|
|
6
6
|
|
|
7
|
-
-
|
|
7
|
+
- Hash index tuples via ohash to avoid collision of different types by [@andreisergiu98](https://github.com/andreisergiu98) in [#591](https://github.com/andreisergiu98/baeta/pull/591)
|
|
8
8
|
|
|
9
|
-
-
|
|
9
|
+
- Add support for custom transport for logs and improve tracing by [@andreisergiu98](https://github.com/andreisergiu98) in [#616](https://github.com/andreisergiu98/baeta/pull/616)
|
|
10
|
+
- Updated dependencies [[`7cd558c`](https://github.com/andreisergiu98/baeta/commit/7cd558c2a2c1111df0b6de663b6db50ad881bc88)]:
|
|
11
|
+
- @baeta/util-log@2.0.0-next.6
|
|
10
12
|
|
|
11
|
-
|
|
12
|
-
- Updated dependencies [[`dc89e17`](https://github.com/andreisergiu98/baeta/commit/dc89e1728926f4bd5a5e1351635c38bf8d5938dc)]:
|
|
13
|
-
- @baeta/util-encoding@2.0.0-next.4
|
|
14
|
-
- @baeta/util-log@2.0.0-next.4
|
|
13
|
+
## 2.0.0-next.16
|
|
15
14
|
|
|
16
|
-
|
|
15
|
+
### Major Changes
|
|
17
16
|
|
|
18
|
-
|
|
17
|
+
- The cache system has been fully rewritten and split out of the GraphQL framework into a standalone `@baeta/cache` package. It no longer depends on `@baeta/core` or `graphql` and can be used on its own. by [@andreisergiu98](https://github.com/andreisergiu98) in [#290](https://github.com/andreisergiu98/baeta/pull/290)
|
|
19
18
|
|
|
20
|
-
|
|
19
|
+
The biggest conceptual change: the old GraphQL extension API is gone. There is no more `cacheExtension(...)`, `$createCache`, `$useCache`, `$cacheRef`, `$cacheRevision`, or `$cacheClear`. You no longer register a cache as a Baeta extension. Instead you build a cache object directly with `createCache(client, options)`, declare cached queries with `defineQuery`, and wire it into resolvers with the normal resolver builder (`.map()` / `.resolve()`) — the cache is just a library you call.
|
|
20
|
+
|
|
21
|
+
#### Building a cache
|
|
22
|
+
|
|
23
|
+
In v1 the storage adapter wrapped a client and you created per-type caches off a GraphQL type via the extension:
|
|
24
|
+
|
|
25
|
+
```typescript
|
|
26
|
+
// v1
|
|
27
|
+
import { cacheExtension } from "@baeta/extension-cache";
|
|
28
|
+
import { RedisStore } from "@baeta/extension-cache-redis";
|
|
29
|
+
import Redis from "ioredis";
|
|
30
|
+
|
|
31
|
+
const redis = new Redis("redis://localhost:6379");
|
|
32
|
+
const redisStore = new RedisStore(redis);
|
|
33
|
+
|
|
34
|
+
export const cacheExt = cacheExtension(redisStore, { ttl: 3600 });
|
|
35
|
+
|
|
36
|
+
// in a module
|
|
37
|
+
const userCache = User.$createCache({ revision: 2 });
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
In v2 you pass a `CacheClient` (the adapter) directly to `createCache`, give the cache a `name`, and provide `parse`/`serialize`. `parse`/`serialize` are now required, which lets you validate cached values on read (e.g. with Zod). TTL is now in milliseconds (`ttlMs`) instead of seconds (`ttl`):
|
|
41
|
+
|
|
42
|
+
```typescript
|
|
43
|
+
// v2
|
|
44
|
+
import { createCache, defineQuery } from "@baeta/cache";
|
|
45
|
+
import { RedisCacheClient } from "@baeta/cache-ioredis";
|
|
46
|
+
import Redis from "ioredis";
|
|
47
|
+
import { z } from "zod";
|
|
48
|
+
|
|
49
|
+
const redis = new Redis("redis://localhost:6379");
|
|
50
|
+
const redisClient = new RedisCacheClient(redis);
|
|
51
|
+
|
|
52
|
+
const UserSchema = z.object({
|
|
53
|
+
id: z.string(),
|
|
54
|
+
email: z.string(),
|
|
55
|
+
name: z.string(),
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
export const userCache = createCache(redisClient, {
|
|
59
|
+
name: "UserCache",
|
|
60
|
+
revision: 2,
|
|
61
|
+
ttlMs: 60 * 60 * 1000, // defaults to 1 hour
|
|
62
|
+
parse: (value) => UserSchema.parse(JSON.parse(value)),
|
|
63
|
+
serialize: (value) => JSON.stringify(value),
|
|
64
|
+
})
|
|
65
|
+
.withQueries({
|
|
66
|
+
findUser: defineQuery({
|
|
67
|
+
resolve: async (args: { id: string | null; email: string | null }) => {
|
|
68
|
+
return db.user.findUnique({
|
|
69
|
+
where: { id: args.id ?? undefined, email: args.email ?? undefined },
|
|
70
|
+
});
|
|
71
|
+
},
|
|
72
|
+
}),
|
|
73
|
+
findUsers: defineQuery({
|
|
74
|
+
resolve: async () => db.user.findMany(),
|
|
75
|
+
}),
|
|
76
|
+
})
|
|
77
|
+
.build();
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
`createCache(...)` returns a factory: call `.build()` for an item-only cache, or `.withQueries({...}).build()` to attach typed, cached queries. By default `getRef` extracts the `id` field; pass `getRef` for items keyed differently.
|
|
81
|
+
|
|
82
|
+
#### Reading through the cache
|
|
21
83
|
|
|
22
|
-
|
|
84
|
+
`$useCache(...)` as a resolver middleware is gone. A cached query is just an async function (`userCache.queries.findUser(args)`) that you call from a normal resolver. The resolver builder's `.map()` turns resolver params into query args:
|
|
23
85
|
|
|
24
|
-
|
|
86
|
+
```typescript
|
|
87
|
+
// v1
|
|
88
|
+
Query.user.$useCache(userCache);
|
|
25
89
|
|
|
26
|
-
|
|
90
|
+
// v2
|
|
91
|
+
export default Query.$fields({
|
|
92
|
+
user: Query.user.map(({ args }) =>
|
|
93
|
+
userCache.queries.findUser({
|
|
94
|
+
id: args.where.id,
|
|
95
|
+
email: args.where.email,
|
|
96
|
+
})
|
|
97
|
+
),
|
|
98
|
+
users: Query.users
|
|
99
|
+
.map(() => userCache.queries.findUsers({}))
|
|
100
|
+
.map(({ source }) => source ?? []),
|
|
101
|
+
});
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
#### Reconciling on mutations
|
|
105
|
+
|
|
106
|
+
The single `save()` method is replaced by explicit `insert()` (new items), `update()` (existing items) and `delete()`. These give the cache enough information to reconcile every related query automatically, instead of manually clearing query results:
|
|
107
|
+
|
|
108
|
+
```typescript
|
|
109
|
+
// v1
|
|
110
|
+
Mutation.updateUser.$use(async (params, next) => {
|
|
111
|
+
const user = await next();
|
|
112
|
+
await userCache.save(user);
|
|
113
|
+
return user;
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
// v2
|
|
117
|
+
const createUserMutation = Mutation.createUser.resolve(async ({ args }) => {
|
|
118
|
+
const user = await db.user.create({ data: args.data });
|
|
119
|
+
await userCache.insert(user); // new item
|
|
120
|
+
return user;
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
const updateUserMutation = Mutation.updateUser
|
|
124
|
+
.$use(async (next) => {
|
|
125
|
+
const user = await next();
|
|
126
|
+
if (user) {
|
|
127
|
+
await userCache.update(user); // existing item — updates all queries
|
|
128
|
+
}
|
|
129
|
+
return user;
|
|
130
|
+
})
|
|
131
|
+
.resolve(({ args }) =>
|
|
132
|
+
db.user.update({ where: { id: args.where.id }, data: args.data })
|
|
133
|
+
);
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
#### Targeted invalidation with `indexArgsBy`
|
|
137
|
+
|
|
138
|
+
Relationship queries ("all photos for user X") can declare `indexArgsBy` so invalidation is surgical. `defineQuery` also accepts per-query `onInsert` / `onUpdate` / `onDelete` hooks, which receive `helpers` (`invalidateAll`, `invalidateByArgs`) to invalidate only the matching index keys:
|
|
139
|
+
|
|
140
|
+
```typescript
|
|
141
|
+
// v2
|
|
142
|
+
export const userPhotoCache = createCache(redisClient, {
|
|
143
|
+
name: "UserPhotoCache",
|
|
144
|
+
parse: (value) => JSON.parse(value),
|
|
145
|
+
serialize: (value) => JSON.stringify(value),
|
|
146
|
+
})
|
|
147
|
+
.withQueries({
|
|
148
|
+
findUserPhotos: defineQuery({
|
|
149
|
+
resolve: async (args: { userId: string }) =>
|
|
150
|
+
db.userPhoto.findMany({ where: { userId: args.userId } }),
|
|
151
|
+
indexArgsBy: { userId: true },
|
|
152
|
+
onInsert(items, helpers) {
|
|
153
|
+
return helpers.invalidateByArgs(
|
|
154
|
+
items.map((item) => ({ userId: item.userId }))
|
|
155
|
+
);
|
|
156
|
+
},
|
|
157
|
+
onDelete(pairs, helpers) {
|
|
158
|
+
return helpers.invalidateByArgs(
|
|
159
|
+
pairs.flatMap((p) =>
|
|
160
|
+
p.previous ? [{ userId: p.previous.userId }] : []
|
|
161
|
+
)
|
|
162
|
+
);
|
|
163
|
+
},
|
|
164
|
+
}),
|
|
165
|
+
})
|
|
166
|
+
.build();
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
#### Other changes
|
|
170
|
+
|
|
171
|
+
- TTL is now milliseconds (`ttlMs`) everywhere, replacing v1's seconds-based `ttl`.
|
|
172
|
+
- A cache must have a `name`; `revision`, `ttlMs` and `namespace` can be set on the cache or defaulted from the client.
|
|
173
|
+
- By default, re-resolving a cached query does not overwrite items already in the cache (preventing a stale query result from clobbering a concurrent mutation). Set `replaceExistingItems: true` on a query to opt back into overwriting.
|
|
174
|
+
- Custom hooks fire asynchronously by default; pass `{ waitForHooks: true }` to `insert`/`update`/`delete` to await them.
|
|
175
|
+
|
|
176
|
+
See the [caching guide](https://baeta.io/docs/advanced/caching) for an end-to-end setup.
|
|
177
|
+
|
|
178
|
+
- Drop support for Node.js v23 and v25. Baeta now targets the active LTS releases — Node.js `^22.20.0`, `^24.0.0`, or `>=26.0.0`. by [@andreisergiu98](https://github.com/andreisergiu98) in [#290](https://github.com/andreisergiu98/baeta/pull/290)
|
|
179
|
+
|
|
180
|
+
### Patch Changes
|
|
27
181
|
|
|
28
|
-
- [
|
|
182
|
+
- Updated dependencies [[`046dc5c`](https://github.com/andreisergiu98/baeta/commit/046dc5c29a8ec0f613b9430caa659c08d41a678c), [`046dc5c`](https://github.com/andreisergiu98/baeta/commit/046dc5c29a8ec0f613b9430caa659c08d41a678c), [`046dc5c`](https://github.com/andreisergiu98/baeta/commit/046dc5c29a8ec0f613b9430caa659c08d41a678c)]:
|
|
183
|
+
- @baeta/util-encoding@2.0.0-next.5
|
|
184
|
+
- @baeta/util-log@2.0.0-next.5
|
package/README.md
CHANGED
|
@@ -5,9 +5,10 @@
|
|
|
5
5
|
<div align="center">
|
|
6
6
|
<h1>Baeta</h1>
|
|
7
7
|
<a href="https://www.npmjs.com/package/@baeta/cli"><img src="https://img.shields.io/npm/v/@baeta/cli.svg?style=flat" /></a>
|
|
8
|
-
<a href="https://github.com/andreisergiu98/baeta/actions/workflows/
|
|
8
|
+
<a href="https://github.com/andreisergiu98/baeta/actions/workflows/build.yml"><img src="https://img.shields.io/github/actions/workflow/status/andreisergiu98/baeta/build.yml" /></a>
|
|
9
9
|
<a href="https://github.com/andreisergiu98/baeta/pulls"><img src="https://img.shields.io/badge/PRs-welcome-brightgreen.svg" /></a>
|
|
10
10
|
<a href="https://github.com/andreisergiu98/baeta/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-MIT-blue" /></a>
|
|
11
|
+
<img alt="nycrc config on GitHub" src="https://img.shields.io/nycrc/andreisergiu98/baeta?config=.nycrc.json&preferredThreshold=branches&color=green">
|
|
11
12
|
<br />
|
|
12
13
|
<br />
|
|
13
14
|
<a href="https://baeta.io/docs/getting-started/installation">Getting Started</a>
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import DataLoader from "dataloader";
|
|
2
|
-
|
|
3
2
|
//#region lib/item.d.ts
|
|
4
3
|
/**
|
|
5
4
|
* Reference type for cached items
|
|
@@ -26,7 +25,7 @@ interface QueryTagWithIndexes extends QueryTag {
|
|
|
26
25
|
interface QueryTagWithArgs extends QueryTag {
|
|
27
26
|
args: QueryArgs;
|
|
28
27
|
}
|
|
29
|
-
type QueryArgsIndexes<Args extends QueryArgs, T = Record<string, never>> = { [K in keyof Args]?: Args[K] extends QueryIndexValue ? true : never } & Record<Exclude<keyof T, keyof Args>, never>;
|
|
28
|
+
type QueryArgsIndexes<Args extends QueryArgs, T = Record<string, never>> = { [K in keyof Args]?: Args[K] extends QueryIndexValue ? true : never; } & Record<Exclude<keyof T, keyof Args>, never>;
|
|
30
29
|
type IndexedQueryArgs<Args extends QueryArgs, Indexes extends QueryArgsIndexes<Args>> = Pick<Args, keyof Indexes & keyof Args>;
|
|
31
30
|
interface QueryTagWithData<T> extends QueryTagWithArgs {
|
|
32
31
|
indexes: QueryIndex[];
|
|
@@ -156,16 +155,7 @@ declare class CacheStore<Item> {
|
|
|
156
155
|
protected readonly itemCacheArgs: CacheClientArgs<Item>;
|
|
157
156
|
protected readonly queryCacheArgs: CacheClientArgs<QueryMetadata>;
|
|
158
157
|
protected readonly getRef?: (source: Item) => ItemRef;
|
|
159
|
-
constructor({
|
|
160
|
-
name,
|
|
161
|
-
client,
|
|
162
|
-
namespace,
|
|
163
|
-
revision,
|
|
164
|
-
ttlMs,
|
|
165
|
-
parse,
|
|
166
|
-
serialize,
|
|
167
|
-
getRef
|
|
168
|
-
}: CacheStoreOptions<Item>);
|
|
158
|
+
constructor({ name, client, namespace, revision, ttlMs, parse, serialize, getRef }: CacheStoreOptions<Item>);
|
|
169
159
|
protected loadAndParse: (refs: ReadonlyArray<ItemRef>) => Promise<Array<Item | null>>;
|
|
170
160
|
protected loader: DataLoader<ItemRef, Item | null, ItemRef>;
|
|
171
161
|
get(ref: ItemRef): Promise<Item | null>;
|
|
@@ -194,7 +184,7 @@ declare class CacheStore<Item> {
|
|
|
194
184
|
type QueryFactory<Result extends QueryResult<Item>, Args extends QueryArgs, Indexes extends QueryArgsIndexes<Args, Indexes>, Item = ItemFromQueryResult<Result>> = (store: CacheStore<Item>, name: string) => QueryHandle<Result, Args, Indexes, Item>;
|
|
195
185
|
type QueryMethod<T extends QueryFactory<any, any, any>> = T extends QueryFactory<infer Result, infer Args, any, any> ? (args: Args) => Promise<Result> : never;
|
|
196
186
|
type QueryDefinitionMap<Item> = Record<string, QueryFactory<QueryResult<Item>, any, any, Item>>;
|
|
197
|
-
type QueryMethodMap<Definitions extends QueryDefinitionMap<any>> = { [K in keyof Definitions]: QueryMethod<Definitions[K]
|
|
187
|
+
type QueryMethodMap<Definitions extends QueryDefinitionMap<any>> = { [K in keyof Definitions]: QueryMethod<Definitions[K]>; };
|
|
198
188
|
declare function defineQuery<Result extends QueryResult<Item>, Args extends QueryArgs = Record<string, never>, Indexes extends QueryArgsIndexes<Args, Indexes> = Record<string, never>, Item = ItemFromQueryResult<Result>>(options: QueryOptions<Result, Args, Indexes, Item>): QueryFactory<Result, Args, Indexes, Item>;
|
|
199
189
|
//#endregion
|
|
200
190
|
//#region lib/options.d.ts
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createLogger } from "@baeta/util-log";
|
|
2
2
|
import DataLoader from "dataloader";
|
|
3
|
-
import { encodeBase64 } from "@baeta/util-encoding";
|
|
4
3
|
import { hash } from "ohash";
|
|
5
4
|
//#region lib/client.ts
|
|
6
5
|
var CacheClient = class {
|
|
@@ -10,6 +9,9 @@ var CacheClient = class {
|
|
|
10
9
|
}
|
|
11
10
|
};
|
|
12
11
|
//#endregion
|
|
12
|
+
//#region lib/logger.ts
|
|
13
|
+
const logger = createLogger("@baeta/cache");
|
|
14
|
+
//#endregion
|
|
13
15
|
//#region lib/item.ts
|
|
14
16
|
/**
|
|
15
17
|
* Asserts that a given reference is of a valid type (string, number, or bigint) and that it can be safely serialized.
|
|
@@ -30,9 +32,7 @@ function buildQueryCacheKeyId(args) {
|
|
|
30
32
|
}
|
|
31
33
|
function buildQueryCacheIndexKeyId(index) {
|
|
32
34
|
if (index == null) return "idx:";
|
|
33
|
-
|
|
34
|
-
const value = index[1];
|
|
35
|
-
return `idx:${hash(`${key}=${value === null ? "null" : `_${encodeBase64(value.toString())}`}`)}`;
|
|
35
|
+
return `idx:${hash(index)}`;
|
|
36
36
|
}
|
|
37
37
|
function buildQueryCacheIndexKeysIds(indexes) {
|
|
38
38
|
if (indexes.length === 0) return ["idx:"];
|
|
@@ -72,6 +72,7 @@ var CacheStore = class {
|
|
|
72
72
|
queryCacheArgs;
|
|
73
73
|
getRef;
|
|
74
74
|
constructor({ name, client, namespace, revision, ttlMs, parse, serialize, getRef }) {
|
|
75
|
+
if (ttlMs != null && (!Number.isFinite(ttlMs) || ttlMs <= 0)) throw new Error(`Invalid ttlMs for cache "${name}": ${ttlMs}. Expected a positive number of milliseconds.`);
|
|
75
76
|
this.name = name;
|
|
76
77
|
this.namespace = namespace ?? "baeta";
|
|
77
78
|
this.revision = revision?.toString() ?? "default";
|
|
@@ -197,7 +198,11 @@ function parseItemSafely(value, parseItem) {
|
|
|
197
198
|
try {
|
|
198
199
|
return parseItem(value);
|
|
199
200
|
} catch (err) {
|
|
200
|
-
|
|
201
|
+
logger.warn({
|
|
202
|
+
type: "parse-item",
|
|
203
|
+
message: "Failed to parse item, returning null",
|
|
204
|
+
error: err
|
|
205
|
+
});
|
|
201
206
|
return null;
|
|
202
207
|
}
|
|
203
208
|
}
|
|
@@ -206,11 +211,18 @@ function parseQueryMetadataSafely(value) {
|
|
|
206
211
|
try {
|
|
207
212
|
parsed = JSON.parse(value);
|
|
208
213
|
} catch (err) {
|
|
209
|
-
|
|
214
|
+
logger.warn({
|
|
215
|
+
type: "parse-query-metadata",
|
|
216
|
+
message: "Failed to parse query metadata, treating as cache miss",
|
|
217
|
+
error: err
|
|
218
|
+
});
|
|
210
219
|
return null;
|
|
211
220
|
}
|
|
212
221
|
if (!isValidQueryMetadata(parsed)) {
|
|
213
|
-
|
|
222
|
+
logger.warn({
|
|
223
|
+
type: "parse-query-metadata",
|
|
224
|
+
message: "Query metadata has invalid shape, treating as cache miss"
|
|
225
|
+
});
|
|
214
226
|
return null;
|
|
215
227
|
}
|
|
216
228
|
return parsed;
|
|
@@ -341,7 +353,11 @@ async function fireHook(hook, value, options) {
|
|
|
341
353
|
if (hook == null) return;
|
|
342
354
|
if (options?.waitForHooks) await hook(value);
|
|
343
355
|
else Promise.resolve().then(() => hook(value)).catch((err) => {
|
|
344
|
-
|
|
356
|
+
logger.error({
|
|
357
|
+
type: "cache-hook",
|
|
358
|
+
message: "Error in cache hook",
|
|
359
|
+
error: err
|
|
360
|
+
});
|
|
345
361
|
});
|
|
346
362
|
}
|
|
347
363
|
async function fireHooks(hooks, value, options) {
|
|
@@ -360,7 +376,11 @@ function defineQuery(options) {
|
|
|
360
376
|
...tag,
|
|
361
377
|
args
|
|
362
378
|
}).catch((err) => {
|
|
363
|
-
|
|
379
|
+
logger.error({
|
|
380
|
+
type: "query-cache",
|
|
381
|
+
message: `Failed to get query result for ${name}. Proceeding without caching.`,
|
|
382
|
+
error: err
|
|
383
|
+
});
|
|
364
384
|
return null;
|
|
365
385
|
});
|
|
366
386
|
if (fromCache != null) return fromCache.query;
|
|
@@ -371,7 +391,11 @@ function defineQuery(options) {
|
|
|
371
391
|
data,
|
|
372
392
|
indexes: buildIndexes(args, options.indexArgsBy)
|
|
373
393
|
}, options.replaceExistingItems, options.ttlMs).catch((err) => {
|
|
374
|
-
|
|
394
|
+
logger.error({
|
|
395
|
+
type: "query-cache",
|
|
396
|
+
message: `Failed to save query result for ${name}. Proceeding without caching.`,
|
|
397
|
+
error: err
|
|
398
|
+
});
|
|
375
399
|
});
|
|
376
400
|
return data;
|
|
377
401
|
};
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../lib/client.ts","../lib/item.ts","../lib/key.ts","../lib/options.ts","../lib/utils.ts","../lib/store.ts","../lib/create-cache.ts","../lib/define-query.ts"],"sourcesContent":["import type { ItemCacheKey, QueryCacheIndexKey, QueryCacheKey } from './key.ts';\n\nexport interface CacheClientArgs<Item> {\n\tttlMs: number;\n\tparse: (value: string) => Item | null;\n\tserialize: (item: Item) => string;\n}\n\nexport interface CacheClientOptions {\n\t/**\n\t * Revision number for cache invalidation.\n\t * Incrementing this number will invalidate all existing cache entries for this store.\n\t * @defaultValue \"default\"\n\t */\n\trevision?: number;\n\t/**\n\t * Time-to-live in milliseconds\n\t * @defaultValue 3_600_000 (1 hour)\n\t */\n\tttlMs?: number;\n\t/**\n\t * Optional namespace to prefix all cache keys\n\t * @defaultValue \"baeta\"\n\t */\n\tnamespace?: string;\n}\n\nexport interface CacheClientSaveOptions {\n\t/**\n\t * If true, the save operation will not overwrite existing cache entries. Instead, it will only save entries that do not already exist in the cache.\n\t * @defaultValue false\n\t */\n\tdisableOverwrite?: boolean;\n}\n\nexport abstract class CacheClient {\n\toptions?: CacheClientOptions;\n\n\tconstructor(options?: CacheClientOptions) {\n\t\tthis.options = options;\n\t}\n\n\tabstract getPartialItems<Item>(\n\t\tkeys: ItemCacheKey[],\n\t\toptions: CacheClientArgs<Item>,\n\t): Promise<Array<Item | null>>;\n\n\tabstract saveItems<Item>(\n\t\titems: Array<[ItemCacheKey, Item]>,\n\t\toptions: CacheClientArgs<Item>,\n\t\tsaveOptions?: CacheClientSaveOptions,\n\t): Promise<void>;\n\n\tabstract saveItemsWithDiff<Item>(\n\t\titems: Array<[ItemCacheKey, Item]>,\n\t\toptions: CacheClientArgs<Item>,\n\t): Promise<Array<Item | null>>;\n\n\tabstract deleteItems<Item>(keys: ItemCacheKey[], options: CacheClientArgs<Item>): Promise<void>;\n\n\tabstract deleteItemsWithDiff<Item>(\n\t\tkeys: ItemCacheKey[],\n\t\toptions: CacheClientArgs<Item>,\n\t): Promise<Array<Item | null>>;\n\n\tabstract getQuery<QueryMetadata>(\n\t\tkey: QueryCacheKey,\n\t\toptions: CacheClientArgs<QueryMetadata>,\n\t): Promise<QueryMetadata | null>;\n\n\tabstract saveQuery<QueryMetadata>(\n\t\tkey: QueryCacheKey,\n\t\tindexes: QueryCacheIndexKey[],\n\t\tmetadata: QueryMetadata,\n\t\toptions: CacheClientArgs<QueryMetadata>,\n\t): Promise<void>;\n\n\tabstract deleteQueries<QueryMetadata>(\n\t\tindexes: QueryCacheIndexKey[],\n\t\toptions: CacheClientArgs<QueryMetadata>,\n\t): Promise<void>;\n}\n","/**\n * Reference type for cached items\n */\nexport type ItemRef = string | number | bigint;\n\n/**\n * Type constraint for objects that are compatible with default cache ref\n */\nexport type RefCompatibleItem = { id: string | number | bigint };\n\n/**\n * Asserts that a given reference is of a valid type (string, number, or bigint) and that it can be safely serialized.\n */\nexport function assertValidRefType(ref: unknown): asserts ref is string | number | bigint {\n\tif (typeof ref !== 'string' && typeof ref !== 'number' && typeof ref !== 'bigint') {\n\t\tthrow new TypeError(\n\t\t\t'Reference must be string, number or bigint. Define getRef function in cache options',\n\t\t);\n\t}\n}\n","import { encodeBase64 } from '@baeta/util-encoding';\nimport { hash } from 'ohash';\nimport type { QueryArgs, QueryIndex } from './query.ts';\n\nexport type QueryCacheKey = `${QueryCacheKeyPrefix}:${QueryCacheKeyId}`;\nexport type QueryCacheIndexKey = `${QueryCacheKeyPrefix}:${QueryCacheIndexKeyId}`;\nexport type QueryCacheKeyId = `id:${string}`;\nexport type QueryCacheIndexKeyId = `idx:${string}`;\nexport type QueryCacheKeyPrefix = `${string}:${string}:query:${string}:${CacheRevisionId}`; // $namespace:$storeName:query:$queryName:rev_$value\n\nexport type ItemCacheKey = `${ItemCacheKeyPrefix}:${ItemCacheKeyId}`;\nexport type ItemCacheKeyId = `id:${string}`;\nexport type ItemCacheKeyPrefix = `${string}:${string}:item:${CacheRevisionId}`; // $namespace:$storeName:item:rev_$value\n\nexport type CacheRevisionId = `rev_${string}`;\n\nexport function buildCacheRevisionId(revision: string): CacheRevisionId {\n\treturn `rev_${revision}`;\n}\n\nexport function buildItemCacheKeyId(id: string): ItemCacheKeyId {\n\treturn `id:${id}`;\n}\n\nexport function buildQueryCacheKeyId(args: QueryArgs): QueryCacheKeyId {\n\treturn `id:${hash(args)}`;\n}\n\nexport function buildQueryCacheIndexKeyId(index?: QueryIndex | undefined): QueryCacheIndexKeyId {\n\tif (index == null) {\n\t\treturn 'idx:';\n\t}\n\tconst key = index[0];\n\tconst value = index[1];\n\tconst safeValue = value === null ? 'null' : `_${encodeBase64(value.toString())}`;\n\treturn `idx:${hash(`${key}=${safeValue}`)}`;\n}\n\nexport function buildQueryCacheIndexKeysIds(indexes: QueryIndex[]): QueryCacheIndexKeyId[] {\n\tif (indexes.length === 0) {\n\t\treturn ['idx:'];\n\t}\n\treturn indexes.map((idx) => buildQueryCacheIndexKeyId(idx));\n}\n","import type { ItemRef } from './item.ts';\n\nexport const DEFAULT_REVISION = 'default';\nexport const DEFAULT_NAMESPACE = 'baeta';\nexport const DEFAULT_TTL_MS = 3_600_000; // 1 hour\n\n/**\n * Configuration options for cache stores\n */\nexport type CacheOptions<Item> = {\n\t/**\n\t * Unique name for the cache store. Used as a prefix for cache keys to avoid collisions.\n\t */\n\tname: string;\n\t/**\n\t * Revision number for cache invalidation.\n\t * Incrementing this number will invalidate all existing cache entries for this store.\n\t * @defaultValue CacheClient options or \"default\"\n\t */\n\trevision?: number;\n\t/**\n\t * Time-to-live in milliseconds\n\t * @defaultValue CacheClient options or 3_600_000 (1 hour)\n\t */\n\tttlMs?: number;\n\t/**\n\t * Optional namespace to prefix all cache keys\n\t * @defaultValue CacheClient options or \"baeta\"\n\t */\n\tnamespace?: string;\n\t/**\n\t * Function to parse stored strings back into source objects.\n\t * If it throws an error, the cache will be treated as a miss and the value will be deleted.\n\t */\n\tparse: (value: string) => Item;\n\t/**\n\t * Function to serialize source objects into strings for cache storage.\n\t */\n\tserialize: (value: Item) => string;\n\t/**\n\t * Hook that gets called with the updated items after an update operation.\n\t */\n\tonUpdate?: (item: Item[]) => void | Promise<void>;\n\t/**\n\t * Hook that gets called with the inserted items after an insert operation.\n\t */\n\tonInsert?: (item: Item[]) => void | Promise<void>;\n\t/**\n\t * Hook that gets called with the refs of deleted items after a delete operation.\n\t */\n\tonDelete?: (ref: ItemRef[]) => void | Promise<void>;\n};\n\nexport type OptionalGetRef<Item> = {\n\t/*\n\t * Optional function to extract a string reference from source objects.\n\t * Will use \"id\" property by default.\n\t */\n\tgetRef?: (source: Item) => ItemRef;\n};\n\nexport type RequiredGetRef<Item> = {\n\t/*\n\t * Function to extract a string reference from source objects.\n\t */\n\tgetRef: (source: Item) => ItemRef;\n};\n","import type { ItemRef } from './item.ts';\n\nexport function arrayIsComplete<T>(items: Array<T | null> | null): items is T[] {\n\tif (items == null) {\n\t\treturn false;\n\t}\n\treturn items.every((item) => item != null);\n}\n\nexport function alignItemsWithRefs<T>(partialRefs: Array<ItemRef | null>, items: T[]) {\n\tif (partialRefs.length === items.length) {\n\t\treturn items;\n\t}\n\tlet itemIndex = 0;\n\tconst aligned: Array<T | null> = [];\n\tfor (const ref of partialRefs) {\n\t\tif (ref == null) {\n\t\t\taligned.push(null);\n\t\t} else {\n\t\t\taligned.push(items[itemIndex++]);\n\t\t}\n\t}\n\treturn aligned;\n}\n\nexport function toArray<T>(item: T | T[]): T[] {\n\treturn Array.isArray(item) ? item : [item];\n}\n\nexport function zip<T, U, R>(array1: T[], array2: U[], fn: (a: T, b: U) => R): R[] {\n\tif (array1.length !== array2.length) {\n\t\tthrow new Error('Arrays must have the same length to be zipped');\n\t}\n\tconst result: R[] = [];\n\tfor (let i = 0; i < array1.length; i++) {\n\t\tresult.push(fn(array1[i], array2[i]));\n\t}\n\treturn result;\n}\n","import { log } from '@baeta/util-log';\nimport DataLoader from 'dataloader';\nimport type { CacheClient, CacheClientArgs } from './client.ts';\nimport { assertValidRefType, type ItemRef } from './item.ts';\nimport {\n\tbuildCacheRevisionId,\n\tbuildItemCacheKeyId,\n\tbuildQueryCacheIndexKeyId,\n\tbuildQueryCacheIndexKeysIds,\n\tbuildQueryCacheKeyId,\n\ttype CacheRevisionId,\n\ttype ItemCacheKey,\n\ttype ItemCacheKeyPrefix,\n\ttype QueryCacheIndexKey,\n\ttype QueryCacheKey,\n\ttype QueryCacheKeyPrefix,\n} from './key.ts';\nimport { DEFAULT_NAMESPACE, DEFAULT_REVISION, DEFAULT_TTL_MS } from './options.ts';\nimport type { QueryTag, QueryTagWithArgs, QueryTagWithData, QueryTagWithIndexes } from './query.ts';\nimport { alignItemsWithRefs, arrayIsComplete, toArray } from './utils.ts';\n\nexport interface CacheStoreOptions<Item> {\n\tname: string;\n\tclient: CacheClient;\n\tnamespace?: string;\n\trevision?: string | number;\n\tttlMs?: number;\n\tparse: (value: string) => Item;\n\tserialize: (item: Item) => string;\n\tgetRef?: (source: Item) => ItemRef;\n}\n\ntype QueryMetadata = { refs: Array<null | string>; isList: boolean };\n\nexport class CacheStore<Item> {\n\tprotected readonly name: string;\n\tprotected readonly namespace: string;\n\tprotected readonly revision: string;\n\n\tprotected readonly client: CacheClient;\n\tprotected readonly itemCacheArgs: CacheClientArgs<Item>;\n\tprotected readonly queryCacheArgs: CacheClientArgs<QueryMetadata>;\n\n\tprotected readonly getRef?: (source: Item) => ItemRef;\n\n\tconstructor({\n\t\tname,\n\t\tclient,\n\t\tnamespace,\n\t\trevision,\n\t\tttlMs,\n\t\tparse,\n\t\tserialize,\n\t\tgetRef,\n\t}: CacheStoreOptions<Item>) {\n\t\tthis.name = name;\n\t\tthis.namespace = namespace ?? DEFAULT_NAMESPACE;\n\t\tthis.revision = revision?.toString() ?? DEFAULT_REVISION;\n\t\tthis.client = client;\n\t\tthis.getRef = getRef;\n\t\tthis.itemCacheArgs = {\n\t\t\tttlMs: ttlMs ?? DEFAULT_TTL_MS,\n\t\t\tparse: (value: string) => parseItemSafely(value, parse),\n\t\t\tserialize: (item: Item) => serialize(item),\n\t\t};\n\t\tthis.queryCacheArgs = {\n\t\t\tttlMs: ttlMs ?? DEFAULT_TTL_MS,\n\t\t\tparse: (value: string) => parseQueryMetadataSafely(value),\n\t\t\tserialize: (meta: QueryMetadata) => JSON.stringify(meta),\n\t\t};\n\t}\n\n\tprotected loadAndParse = async (refs: ReadonlyArray<ItemRef>): Promise<Array<Item | null>> => {\n\t\tconst keys = refs.map((ref) => this.getItemKeyByRef(ref));\n\t\treturn await this.client.getPartialItems(keys, this.itemCacheArgs);\n\t};\n\n\tprotected loader = new DataLoader<ItemRef, Item | null>(this.loadAndParse, {\n\t\tcache: false,\n\t});\n\n\tasync get(ref: ItemRef): Promise<Item | null> {\n\t\treturn await this.loader.load(ref);\n\t}\n\n\tasync getMany(refs: ItemRef[]): Promise<Item[] | null> {\n\t\tconst results = await Promise.all(refs.map((r) => this.get(r)));\n\t\tif (!arrayIsComplete(results)) {\n\t\t\treturn null;\n\t\t}\n\t\treturn results;\n\t}\n\n\tasync getPartial(refs: ItemRef[]): Promise<Array<Item | null>> {\n\t\treturn await Promise.all(refs.map((ref) => this.get(ref)));\n\t}\n\n\tasync save(item: Item | Item[]) {\n\t\tconst values = toArray(item);\n\t\tconst entries: Array<[ItemCacheKey, Item]> = values.map((item) => [\n\t\t\tthis.getItemKey(item),\n\t\t\titem,\n\t\t]);\n\t\treturn await this.client.saveItems(entries, this.itemCacheArgs);\n\t}\n\n\tasync saveIfNotExists(item: Item | Item[]) {\n\t\tconst values = toArray(item);\n\t\tconst entries: Array<[ItemCacheKey, Item]> = values.map((item) => [\n\t\t\tthis.getItemKey(item),\n\t\t\titem,\n\t\t]);\n\t\treturn await this.client.saveItems(entries, this.itemCacheArgs, {\n\t\t\tdisableOverwrite: true,\n\t\t});\n\t}\n\n\tasync saveWithDiff(item: Item | Item[]): Promise<Array<Item | null>> {\n\t\tconst values = toArray(item);\n\t\tconst entries: Array<[ItemCacheKey, Item]> = values.map((item) => [\n\t\t\tthis.getItemKey(item),\n\t\t\titem,\n\t\t]);\n\t\treturn await this.client.saveItemsWithDiff(entries, this.itemCacheArgs);\n\t}\n\n\tasync delete(ref: ItemRef | ItemRef[]) {\n\t\tconst refs = toArray(ref);\n\t\tconst keys = refs.map((r) => this.getItemKeyByRef(r));\n\t\tawait this.client.deleteItems(keys, this.itemCacheArgs);\n\t}\n\n\tasync deleteWithDiff(ref: ItemRef | ItemRef[]): Promise<Array<Item | null>> {\n\t\tconst refs = toArray(ref);\n\t\tconst keys = refs.map((r) => this.getItemKeyByRef(r));\n\t\treturn await this.client.deleteItemsWithDiff(keys, this.itemCacheArgs);\n\t}\n\n\tasync getQuery(query: QueryTagWithArgs): Promise<{ query: unknown } | null> {\n\t\tconst queryKey = this.getQueryKey(query);\n\t\tconst meta = await this.client.getQuery(queryKey, this.queryCacheArgs);\n\n\t\tif (meta == null) {\n\t\t\treturn null;\n\t\t}\n\n\t\tconst isList = meta.isList;\n\t\tconst nullableRefs = meta.refs;\n\t\tconst refs = nullableRefs.filter((ref) => ref != null);\n\t\tconst items = await this.getMany(refs);\n\n\t\tif (items == null) {\n\t\t\treturn null;\n\t\t}\n\n\t\tconst aligned = alignItemsWithRefs(nullableRefs, items);\n\t\tconst result = isList ? aligned : (aligned.at(0) ?? null);\n\n\t\treturn { query: result };\n\t}\n\n\tasync saveQuery(\n\t\tquery: QueryTagWithData<Item>,\n\t\treplaceExistingItems = false,\n\t\tttlMs?: number,\n\t): Promise<void> {\n\t\tconst data = query.data;\n\t\tconst queryKey = this.getQueryKey(query);\n\t\tconst queryIndexes = this.getQueryIndexes(query, true);\n\n\t\tconst isList = Array.isArray(data);\n\t\tconst nullableItems = isList ? data : [data];\n\t\tconst items = nullableItems.filter((item) => item != null);\n\n\t\tif (items.length > 0) {\n\t\t\tif (replaceExistingItems) {\n\t\t\t\tawait this.save(items);\n\t\t\t} else {\n\t\t\t\tawait this.saveIfNotExists(items);\n\t\t\t}\n\t\t}\n\n\t\tconst encodedRefs = nullableItems.map((item) => {\n\t\t\tif (item == null) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\treturn this.getRefWithFallback(item).toString();\n\t\t});\n\n\t\tconst metadata = {\n\t\t\trefs: encodedRefs,\n\t\t\tisList,\n\t\t};\n\n\t\treturn await this.client.saveQuery(queryKey, queryIndexes, metadata, {\n\t\t\t...this.queryCacheArgs,\n\t\t\tttlMs: ttlMs ?? this.queryCacheArgs.ttlMs,\n\t\t});\n\t}\n\n\tdeleteQueries(query: QueryTagWithIndexes): Promise<void> {\n\t\tconst queryIndexes = this.getQueryIndexes(query);\n\t\treturn this.client.deleteQueries(queryIndexes, this.queryCacheArgs);\n\t}\n\n\tgetRefWithFallback(root: Item): ItemRef {\n\t\tif (this.getRef) {\n\t\t\treturn this.getRef(root);\n\t\t}\n\t\tif (root == null) {\n\t\t\tthrow new Error('Object is null or undefined, cannot get ref');\n\t\t}\n\t\tif (typeof root === 'object' && 'id' in root) {\n\t\t\tassertValidRefType(root.id);\n\t\t\treturn root.id.toString();\n\t\t}\n\t\tthrow new Error('Object does not have id. Define \"getRef\" function in cache options');\n\t}\n\n\tgetItemKey(item: Item): ItemCacheKey {\n\t\tconst ref = this.getRefWithFallback(item);\n\t\treturn this.getItemKeyByRef(ref);\n\t}\n\n\tgetItemKeyByRef(ref: ItemRef): ItemCacheKey {\n\t\tconst prefix: ItemCacheKeyPrefix = `${this.namespace}:{${this.name}:item:${buildCacheRevisionId(this.revision)}}`;\n\t\tconst keyId = buildItemCacheKeyId(ref.toString());\n\t\treturn `${prefix}:${keyId}`;\n\t}\n\n\tgetQueryKey(query: QueryTagWithArgs): QueryCacheKey {\n\t\tconst prefix = this.getQueryKeyPrefix(query);\n\t\treturn `${prefix}:${buildQueryCacheKeyId(query.args)}`;\n\t}\n\n\tgetQueryIndexes(query: QueryTagWithIndexes, ensureCatchAll = false): QueryCacheIndexKey[] {\n\t\tconst prefix = this.getQueryKeyPrefix(query);\n\t\tconst keyIndexes = buildQueryCacheIndexKeysIds(query.indexes);\n\t\tif (ensureCatchAll && query.indexes.length > 0) {\n\t\t\tkeyIndexes.push(buildQueryCacheIndexKeyId());\n\t\t}\n\t\treturn keyIndexes.map((keyIndex) => `${prefix}:${keyIndex}` as const);\n\t}\n\n\tgetQueryKeyPrefix(query: QueryTag): QueryCacheKeyPrefix {\n\t\treturn `${this.namespace}:{${this.name}:query:${query.name}:${this.getQueryKeyRevision(query)}}`;\n\t}\n\n\tgetQueryKeyRevision(query: QueryTag): CacheRevisionId {\n\t\tconst combinedRevision = `${this.revision}_${query.revision?.toString() ?? DEFAULT_REVISION}`;\n\t\treturn buildCacheRevisionId(combinedRevision);\n\t}\n}\n\nfunction parseItemSafely<T>(value: string, parseItem: (value: string) => T): T | null {\n\ttry {\n\t\treturn parseItem(value);\n\t} catch (err) {\n\t\tlog.warn(err, 'Failed to parse item, returning null');\n\t\treturn null;\n\t}\n}\n\nfunction parseQueryMetadataSafely(value: string): QueryMetadata | null {\n\tlet parsed: unknown;\n\ttry {\n\t\tparsed = JSON.parse(value);\n\t} catch (err) {\n\t\tlog.warn(err, 'Failed to parse query metadata, treating as cache miss');\n\t\treturn null;\n\t}\n\tif (!isValidQueryMetadata(parsed)) {\n\t\tlog.warn('Query metadata has invalid shape, treating as cache miss');\n\t\treturn null;\n\t}\n\treturn parsed;\n}\n\nfunction isValidQueryMetadata(value: unknown): value is QueryMetadata {\n\tif (value == null || typeof value !== 'object') {\n\t\treturn false;\n\t}\n\tconst candidate = value as { refs?: unknown; isList?: unknown };\n\tif (!Array.isArray(candidate.refs)) {\n\t\treturn false;\n\t}\n\tif (typeof candidate.isList !== 'boolean') {\n\t\treturn false;\n\t}\n\treturn candidate.refs.every((ref) => ref === null || typeof ref === 'string');\n}\n","import { log } from '@baeta/util-log';\nimport type { CacheClient } from './client.ts';\nimport type { QueryDefinitionMap, QueryMethod, QueryMethodMap } from './define-query.ts';\nimport type { ItemRef, RefCompatibleItem } from './item.ts';\nimport type { CacheOptions, OptionalGetRef, RequiredGetRef } from './options.ts';\nimport type { QueryOnDeleteHook, QueryOnInsertHook, QueryOnUpdateHook, QueryTag } from './query.ts';\nimport { CacheStore } from './store.ts';\nimport { toArray, zip } from './utils.ts';\n\nexport type CacheHooksOptions = {\n\t/**\n\t * If true, hooks will be awaited. If false, hooks will be fired asynchronously and will not block cache methods.\n\t * @defaultValue false\n\t */\n\twaitForHooks?: boolean;\n};\n\nexport type Cache<Item> = {\n\tget(ref: ItemRef): Promise<Item | null>;\n\tgetMany(refs: ItemRef[]): Promise<Item[] | null>;\n\tgetPartial(refs: ItemRef[]): Promise<Array<Item | null>>;\n\tupdate(item: Item | Item[]): Promise<void>;\n\tinsert(item: Item | Item[]): Promise<void>;\n\tdelete(ref: ItemRef | ItemRef[]): Promise<void>;\n};\n\nexport type CacheWithQueries<Item, QueryDefinitions extends QueryDefinitionMap<Item>> = {\n\tget(ref: ItemRef): Promise<Item | null>;\n\tgetMany(refs: ItemRef[]): Promise<Item[] | null>;\n\tgetPartial(refs: ItemRef[]): Promise<Array<Item | null>>;\n\tupdate(item: Item | Item[], options?: CacheHooksOptions): Promise<void>;\n\tinsert(item: Item | Item[], options?: CacheHooksOptions): Promise<void>;\n\tdelete(ref: ItemRef | ItemRef[], options?: CacheHooksOptions): Promise<void>;\n\tdeleteQueries(): Promise<void>;\n\tqueries: QueryMethodMap<QueryDefinitions>;\n};\n\nexport type CreateCacheFactory<Item> = {\n\tbuild: () => Cache<Item>;\n\twithQueries: <QueryDefinitions extends QueryDefinitionMap<Item>>(\n\t\tdefinitions: QueryDefinitions,\n\t) => {\n\t\tbuild: () => CacheWithQueries<Item, QueryDefinitions>;\n\t};\n};\n\nexport function createCache<Item extends RefCompatibleItem>(\n\tclient: CacheClient,\n\toptions: CacheOptions<Item> & OptionalGetRef<Item>,\n): CreateCacheFactory<Item>;\nexport function createCache<Item>(\n\tclient: CacheClient,\n\toptions: CacheOptions<Item> & RequiredGetRef<Item>,\n): CreateCacheFactory<Item>;\nexport function createCache<Item>(\n\tclient: CacheClient,\n\toptions: CacheOptions<Item> & OptionalGetRef<Item>,\n): CreateCacheFactory<Item> {\n\tconst storeClient = new CacheStore<Item>({\n\t\tclient,\n\t\tname: options.name,\n\t\tparse: options.parse,\n\t\tserialize: options.serialize,\n\t\tgetRef: options.getRef,\n\t\tttlMs: options.ttlMs ?? client.options?.ttlMs,\n\t\tnamespace: options.namespace ?? client.options?.namespace,\n\t\trevision: options.revision ?? client.options?.revision,\n\t});\n\treturn {\n\t\tbuild: () =>\n\t\t\tcreateCacheMethods(\n\t\t\t\tstoreClient,\n\t\t\t\t{\n\t\t\t\t\tonUpdateHook: options.onUpdate,\n\t\t\t\t\tonInsertHook: options.onInsert,\n\t\t\t\t\tonDeleteHook: options.onDelete,\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tonUpdateHooks: [],\n\t\t\t\t\tonInsertHooks: [],\n\t\t\t\t\tonDeleteHooks: [],\n\t\t\t\t},\n\t\t\t),\n\t\twithQueries: (definitions) => {\n\t\t\treturn {\n\t\t\t\tbuild: () => createCacheMethodsWithQueries(storeClient, options, definitions),\n\t\t\t};\n\t\t},\n\t};\n}\n\nfunction createCacheMethods<Item>(\n\tstoreClient: CacheStore<Item>,\n\titemHooks: {\n\t\tonUpdateHook?: (item: Item[]) => void | Promise<void>;\n\t\tonInsertHook?: (item: Item[]) => void | Promise<void>;\n\t\tonDeleteHook?: (ref: ItemRef[]) => void | Promise<void>;\n\t},\n\tqueryHooks: {\n\t\tonUpdateHooks: Array<QueryOnUpdateHook<Item>>;\n\t\tonInsertHooks: Array<QueryOnInsertHook<Item>>;\n\t\tonDeleteHooks: Array<QueryOnDeleteHook<Item>>;\n\t},\n): Cache<Item> | Omit<CacheWithQueries<Item, any>, 'queries' | 'deleteQueries'> {\n\treturn {\n\t\tget: (ref) => storeClient.get(ref),\n\t\tgetMany: (refs) => storeClient.getMany(refs),\n\t\tgetPartial: (refs) => storeClient.getPartial(refs),\n\t\tupdate: async (item, options) => {\n\t\t\tif (queryHooks.onUpdateHooks.length === 0) {\n\t\t\t\tawait storeClient.save(item);\n\t\t\t\tawait fireHook(itemHooks.onUpdateHook, toArray(item), options);\n\t\t\t} else {\n\t\t\t\tconst items = toArray(item);\n\t\t\t\tconst previous = await storeClient.saveWithDiff(items);\n\t\t\t\tconst pairs = zip(items, previous, (next, previous) => ({ next, previous }));\n\t\t\t\tawait Promise.all([\n\t\t\t\t\tfireHook(itemHooks.onUpdateHook, items, options),\n\t\t\t\t\tfireHooks(queryHooks.onUpdateHooks, pairs, options),\n\t\t\t\t]);\n\t\t\t}\n\t\t},\n\t\tinsert: async (item, options) => {\n\t\t\tawait storeClient.save(item);\n\t\t\tif (queryHooks.onInsertHooks.length === 0) {\n\t\t\t\tawait fireHook(itemHooks.onInsertHook, toArray(item), options);\n\t\t\t} else {\n\t\t\t\tconst items = toArray(item);\n\t\t\t\tawait Promise.all([\n\t\t\t\t\tfireHook(itemHooks.onInsertHook, items, options),\n\t\t\t\t\tfireHooks(queryHooks.onInsertHooks, items, options),\n\t\t\t\t]);\n\t\t\t}\n\t\t},\n\t\tdelete: async (ref, options) => {\n\t\t\tif (queryHooks.onDeleteHooks.length === 0) {\n\t\t\t\tawait storeClient.delete(ref);\n\t\t\t\tawait fireHook(itemHooks.onDeleteHook, toArray(ref), options);\n\t\t\t} else {\n\t\t\t\tconst refs = toArray(ref);\n\t\t\t\tconst previous = await storeClient.deleteWithDiff(refs);\n\t\t\t\tawait storeClient.delete(refs);\n\t\t\t\tconst pairs = zip(refs, previous, (ref, previous) => ({ ref, previous }));\n\t\t\t\tawait Promise.all([\n\t\t\t\t\tfireHook(itemHooks.onDeleteHook, refs, options),\n\t\t\t\t\tfireHooks(queryHooks.onDeleteHooks, pairs, options),\n\t\t\t\t]);\n\t\t\t}\n\t\t},\n\t};\n}\n\nfunction createCacheMethodsWithQueries<Item, QueryDefinitions extends QueryDefinitionMap<Item>>(\n\tstoreClient: CacheStore<Item>,\n\toptions: CacheOptions<Item> & OptionalGetRef<Item>,\n\tdefinitions: QueryDefinitions,\n): CacheWithQueries<Item, QueryDefinitions> {\n\tconst { queries, queryTags, onUpdateHooks, onInsertHooks, onDeleteHooks } = createQueriesAndHooks<\n\t\tItem,\n\t\tQueryDefinitions\n\t>(definitions, storeClient);\n\treturn {\n\t\t...createCacheMethods(\n\t\t\tstoreClient,\n\t\t\t{\n\t\t\t\tonUpdateHook: options.onUpdate,\n\t\t\t\tonInsertHook: options.onInsert,\n\t\t\t\tonDeleteHook: options.onDelete,\n\t\t\t},\n\t\t\t{ onUpdateHooks, onInsertHooks, onDeleteHooks },\n\t\t),\n\t\tdeleteQueries: async () => {\n\t\t\tconst promises = queryTags.map((tag) =>\n\t\t\t\tstoreClient.deleteQueries({\n\t\t\t\t\t...tag,\n\t\t\t\t\tindexes: [],\n\t\t\t\t}),\n\t\t\t);\n\t\t\tawait Promise.all(promises);\n\t\t},\n\t\tqueries,\n\t};\n}\n\nfunction createQueriesAndHooks<Item, QueryDefinitions extends QueryDefinitionMap<Item>>(\n\tdefinitions: QueryDefinitions | undefined,\n\tstore: CacheStore<Item>,\n) {\n\tconst queries: Partial<QueryMethodMap<QueryDefinitions>> = {};\n\tconst queryTags: QueryTag[] = [];\n\tconst onUpdateHooks: Array<QueryOnUpdateHook<Item>> = [];\n\tconst onInsertHooks: Array<QueryOnInsertHook<Item>> = [];\n\tconst onDeleteHooks: Array<QueryOnDeleteHook<Item>> = [];\n\tfor (const [queryName, buildQuery] of Object.entries(definitions ?? {})) {\n\t\tconst queryHandler = buildQuery(store, queryName);\n\t\tqueries[queryName as keyof QueryDefinitions] = queryHandler.call as QueryMethod<\n\t\t\tQueryDefinitions[keyof QueryDefinitions]\n\t\t>;\n\t\tqueryTags.push(queryHandler.tag);\n\t\tif (queryHandler.hooks.onUpdate) {\n\t\t\tonUpdateHooks.push(queryHandler.hooks.onUpdate);\n\t\t}\n\t\tif (queryHandler.hooks.onDelete) {\n\t\t\tonDeleteHooks.push(queryHandler.hooks.onDelete);\n\t\t}\n\t\tif (queryHandler.hooks.onInsert) {\n\t\t\tonInsertHooks.push(queryHandler.hooks.onInsert);\n\t\t}\n\t}\n\treturn {\n\t\tqueries: queries as QueryMethodMap<QueryDefinitions>,\n\t\tqueryTags,\n\t\tonUpdateHooks,\n\t\tonInsertHooks,\n\t\tonDeleteHooks,\n\t};\n}\n\nasync function fireHook<T>(\n\thook: ((v: T) => void | Promise<void>) | undefined,\n\tvalue: T,\n\toptions?: CacheHooksOptions,\n) {\n\tif (hook == null) {\n\t\treturn;\n\t}\n\tif (options?.waitForHooks) {\n\t\tawait hook(value);\n\t} else {\n\t\tPromise.resolve()\n\t\t\t.then(() => hook(value))\n\t\t\t.catch((err) => {\n\t\t\t\tlog.error(err, 'Error in cache hook');\n\t\t\t});\n\t}\n}\n\nasync function fireHooks<T>(\n\thooks: Array<(v: T) => Promise<void>>,\n\tvalue: T,\n\toptions?: CacheHooksOptions,\n) {\n\tawait Promise.all(hooks.map((hook) => fireHook(hook, value, options)));\n}\n","import { log } from '@baeta/util-log';\nimport type {\n\tIndexedQueryArgs,\n\tItemFromQueryResult,\n\tQueryArgs,\n\tQueryArgsIndexes,\n\tQueryHandle,\n\tQueryHelpers,\n\tQueryHelpersWithIndexes,\n\tQueryIndex,\n\tQueryOptions,\n\tQueryResult,\n\tQueryTag,\n} from './query.ts';\nimport type { CacheStore } from './store.ts';\n\nexport type QueryFactory<\n\tResult extends QueryResult<Item>,\n\tArgs extends QueryArgs,\n\tIndexes extends QueryArgsIndexes<Args, Indexes>,\n\tItem = ItemFromQueryResult<Result>,\n> = (store: CacheStore<Item>, name: string) => QueryHandle<Result, Args, Indexes, Item>;\n\nexport type QueryMethod<T extends QueryFactory<any, any, any>> =\n\tT extends QueryFactory<infer Result, infer Args, any, any>\n\t\t? (args: Args) => Promise<Result>\n\t\t: never;\n\nexport type QueryDefinitionMap<Item> = Record<\n\tstring,\n\tQueryFactory<QueryResult<Item>, any, any, Item>\n>;\n\nexport type QueryMethodMap<Definitions extends QueryDefinitionMap<any>> = {\n\t[K in keyof Definitions]: QueryMethod<Definitions[K]>;\n};\n\nexport function defineQuery<\n\tResult extends QueryResult<Item>,\n\tArgs extends QueryArgs = Record<string, never>,\n\tIndexes extends QueryArgsIndexes<Args, Indexes> = Record<string, never>,\n\tItem = ItemFromQueryResult<Result>,\n>(options: QueryOptions<Result, Args, Indexes, Item>): QueryFactory<Result, Args, Indexes, Item> {\n\treturn (store: CacheStore<Item>, name: string) => {\n\t\tconst tag: QueryTag = {\n\t\t\tname,\n\t\t\trevision: options.revision,\n\t\t};\n\n\t\tconst resolve = async (args: Args): Promise<Result> => {\n\t\t\tconst fromCache = await store\n\t\t\t\t.getQuery({\n\t\t\t\t\t...tag,\n\t\t\t\t\targs,\n\t\t\t\t})\n\t\t\t\t.catch((err) => {\n\t\t\t\t\tlog.error(err, `Failed to get query result for ${name}. Proceeding without caching.`);\n\t\t\t\t\treturn null;\n\t\t\t\t});\n\n\t\t\tif (fromCache != null) {\n\t\t\t\treturn fromCache.query as Result;\n\t\t\t}\n\n\t\t\tconst data = await options.resolve(args);\n\n\t\t\tawait store\n\t\t\t\t.saveQuery(\n\t\t\t\t\t{\n\t\t\t\t\t\t...tag,\n\t\t\t\t\t\targs,\n\t\t\t\t\t\tdata,\n\t\t\t\t\t\tindexes: buildIndexes(args, options.indexArgsBy),\n\t\t\t\t\t},\n\t\t\t\t\toptions.replaceExistingItems,\n\t\t\t\t\toptions.ttlMs,\n\t\t\t\t)\n\t\t\t\t.catch((err) => {\n\t\t\t\t\tlog.error(err, `Failed to save query result for ${name}. Proceeding without caching.`);\n\t\t\t\t});\n\n\t\t\treturn data;\n\t\t};\n\n\t\tconst invalidateAll = async () => {\n\t\t\tawait store.deleteQueries({\n\t\t\t\t...tag,\n\t\t\t\tindexes: [],\n\t\t\t});\n\t\t};\n\n\t\tconst invalidateByArgs = async (\n\t\t\targs: Partial<IndexedQueryArgs<Args, Indexes>> | Partial<IndexedQueryArgs<Args, Indexes>>[],\n\t\t) => {\n\t\t\tconst argsArray = Array.isArray(args) ? args : [args];\n\t\t\tconst deletePromises = argsArray.map((args) =>\n\t\t\t\tstore.deleteQueries({\n\t\t\t\t\t...tag,\n\t\t\t\t\tindexes: buildIndexes(args, options.indexArgsBy),\n\t\t\t\t}),\n\t\t\t);\n\t\t\tawait Promise.all(deletePromises);\n\t\t};\n\n\t\tconst helpers: QueryHelpersWithIndexes<Args, Indexes> = {\n\t\t\tinvalidateAll,\n\t\t\tinvalidateByArgs,\n\t\t};\n\t\tconst helpersCast: QueryHelpers<Args, Indexes> = helpers as QueryHelpers<Args, Indexes>;\n\n\t\tconst { onUpdate, onDelete, onInsert } = options;\n\n\t\tconst hooks = {\n\t\t\tonUpdate: hookWithHelpers(helpersCast, onUpdate),\n\t\t\tonInsert: hookWithHelpers(helpersCast, onInsert),\n\t\t\tonDelete: hookWithHelpers(helpersCast, onDelete),\n\t\t};\n\n\t\treturn {\n\t\t\tcall: resolve,\n\t\t\ttag,\n\t\t\thelpers,\n\t\t\thooks,\n\t\t};\n\t};\n}\n\nfunction hookWithHelpers<Helpers, Args>(\n\thelpers: Helpers,\n\thook?: (args: Args, helpers: Helpers) => void | Promise<void>,\n) {\n\tif (!hook) {\n\t\treturn undefined;\n\t}\n\tconst hookWithHelpers = async (args: Args) => {\n\t\tawait hook(args, helpers);\n\t};\n\treturn hookWithHelpers;\n}\n\nfunction buildIndexes<Args extends QueryArgs, Indexes extends QueryArgsIndexes<Args, Indexes>>(\n\targs: Partial<Args>,\n\tindexArgsBy?: Indexes,\n): QueryIndex[] {\n\tif (!indexArgsBy) {\n\t\treturn [];\n\t}\n\tconst indexes: QueryIndex[] = [];\n\tfor (const key in indexArgsBy) {\n\t\tif (!Object.hasOwn(args, key)) {\n\t\t\tcontinue;\n\t\t}\n\t\tconst value = args[key];\n\t\tif (value === undefined) {\n\t\t\tcontinue;\n\t\t}\n\t\tif (\n\t\t\ttypeof value !== 'string' &&\n\t\t\ttypeof value !== 'number' &&\n\t\t\ttypeof value !== 'boolean' &&\n\t\t\tvalue !== null\n\t\t) {\n\t\t\tthrow new TypeError(\n\t\t\t\t`Cache index '${key}' must be a primitive (string, number, boolean, or null) but received ${\n\t\t\t\t\tArray.isArray(value) ? 'array' : typeof value\n\t\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,UAAU,KAAA,GACb;EAED,IACC,OAAO,UAAU,YACjB,OAAO,UAAU,YACjB,OAAO,UAAU,aACjB,UAAU,MAEV,MAAM,IAAI,UACT,gBAAgB,IAAI,wEACnB,MAAM,QAAQ,KAAK,IAAI,UAAU,OAAO,MACxC,EACF;EAED,QAAQ,KAAK,CAAC,KAAK,KAAK,CAAC;CAC1B;CACA,OAAO;AACR"}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../lib/client.ts","../lib/logger.ts","../lib/item.ts","../lib/key.ts","../lib/options.ts","../lib/utils.ts","../lib/store.ts","../lib/create-cache.ts","../lib/define-query.ts"],"sourcesContent":["import type { ItemCacheKey, QueryCacheIndexKey, QueryCacheKey } from './key.ts';\n\nexport interface CacheClientArgs<Item> {\n\tttlMs: number;\n\tparse: (value: string) => Item | null;\n\tserialize: (item: Item) => string;\n}\n\nexport interface CacheClientOptions {\n\t/**\n\t * Revision number for cache invalidation.\n\t * Incrementing this number will invalidate all existing cache entries for this store.\n\t * @defaultValue \"default\"\n\t */\n\trevision?: number;\n\t/**\n\t * Time-to-live in milliseconds\n\t * @defaultValue 3_600_000 (1 hour)\n\t */\n\tttlMs?: number;\n\t/**\n\t * Optional namespace to prefix all cache keys\n\t * @defaultValue \"baeta\"\n\t */\n\tnamespace?: string;\n}\n\nexport interface CacheClientSaveOptions {\n\t/**\n\t * If true, the save operation will not overwrite existing cache entries. Instead, it will only save entries that do not already exist in the cache.\n\t * @defaultValue false\n\t */\n\tdisableOverwrite?: boolean;\n}\n\nexport abstract class CacheClient {\n\toptions?: CacheClientOptions;\n\n\tconstructor(options?: CacheClientOptions) {\n\t\tthis.options = options;\n\t}\n\n\tabstract getPartialItems<Item>(\n\t\tkeys: ItemCacheKey[],\n\t\toptions: CacheClientArgs<Item>,\n\t): Promise<Array<Item | null>>;\n\n\tabstract saveItems<Item>(\n\t\titems: Array<[ItemCacheKey, Item]>,\n\t\toptions: CacheClientArgs<Item>,\n\t\tsaveOptions?: CacheClientSaveOptions,\n\t): Promise<void>;\n\n\tabstract saveItemsWithDiff<Item>(\n\t\titems: Array<[ItemCacheKey, Item]>,\n\t\toptions: CacheClientArgs<Item>,\n\t): Promise<Array<Item | null>>;\n\n\tabstract deleteItems<Item>(keys: ItemCacheKey[], options: CacheClientArgs<Item>): Promise<void>;\n\n\tabstract deleteItemsWithDiff<Item>(\n\t\tkeys: ItemCacheKey[],\n\t\toptions: CacheClientArgs<Item>,\n\t): Promise<Array<Item | null>>;\n\n\tabstract getQuery<QueryMetadata>(\n\t\tkey: QueryCacheKey,\n\t\toptions: CacheClientArgs<QueryMetadata>,\n\t): Promise<QueryMetadata | null>;\n\n\tabstract saveQuery<QueryMetadata>(\n\t\tkey: QueryCacheKey,\n\t\tindexes: QueryCacheIndexKey[],\n\t\tmetadata: QueryMetadata,\n\t\toptions: CacheClientArgs<QueryMetadata>,\n\t): Promise<void>;\n\n\tabstract deleteQueries<QueryMetadata>(\n\t\tindexes: QueryCacheIndexKey[],\n\t\toptions: CacheClientArgs<QueryMetadata>,\n\t): Promise<void>;\n}\n","import { createLogger } from '@baeta/util-log';\n\nexport const logger = createLogger('@baeta/cache');\n","/**\n * Reference type for cached items\n */\nexport type ItemRef = string | number | bigint;\n\n/**\n * Type constraint for objects that are compatible with default cache ref\n */\nexport type RefCompatibleItem = { id: string | number | bigint };\n\n/**\n * Asserts that a given reference is of a valid type (string, number, or bigint) and that it can be safely serialized.\n */\nexport function assertValidRefType(ref: unknown): asserts ref is string | number | bigint {\n\tif (typeof ref !== 'string' && typeof ref !== 'number' && typeof ref !== 'bigint') {\n\t\tthrow new TypeError(\n\t\t\t'Reference must be string, number or bigint. Define getRef function in cache options',\n\t\t);\n\t}\n}\n","import { hash } from 'ohash';\nimport type { QueryArgs, QueryIndex } from './query.ts';\n\nexport type QueryCacheKey = `${QueryCacheKeyPrefix}:${QueryCacheKeyId}`;\nexport type QueryCacheIndexKey = `${QueryCacheKeyPrefix}:${QueryCacheIndexKeyId}`;\nexport type QueryCacheKeyId = `id:${string}`;\nexport type QueryCacheIndexKeyId = `idx:${string}`;\nexport type QueryCacheKeyPrefix = `${string}:${string}:query:${string}:${CacheRevisionId}`; // $namespace:$storeName:query:$queryName:rev_$value\n\nexport type ItemCacheKey = `${ItemCacheKeyPrefix}:${ItemCacheKeyId}`;\nexport type ItemCacheKeyId = `id:${string}`;\nexport type ItemCacheKeyPrefix = `${string}:${string}:item:${CacheRevisionId}`; // $namespace:$storeName:item:rev_$value\n\nexport type CacheRevisionId = `rev_${string}`;\n\nexport function buildCacheRevisionId(revision: string): CacheRevisionId {\n\treturn `rev_${revision}`;\n}\n\nexport function buildItemCacheKeyId(id: string): ItemCacheKeyId {\n\treturn `id:${id}`;\n}\n\nexport function buildQueryCacheKeyId(args: QueryArgs): QueryCacheKeyId {\n\treturn `id:${hash(args)}`;\n}\n\nexport function buildQueryCacheIndexKeyId(index?: QueryIndex | undefined): QueryCacheIndexKeyId {\n\tif (index == null) {\n\t\treturn 'idx:';\n\t}\n\treturn `idx:${hash(index)}`;\n}\n\nexport function buildQueryCacheIndexKeysIds(indexes: QueryIndex[]): QueryCacheIndexKeyId[] {\n\tif (indexes.length === 0) {\n\t\treturn ['idx:'];\n\t}\n\treturn indexes.map((idx) => buildQueryCacheIndexKeyId(idx));\n}\n","import type { ItemRef } from './item.ts';\n\nexport const DEFAULT_REVISION = 'default';\nexport const DEFAULT_NAMESPACE = 'baeta';\nexport const DEFAULT_TTL_MS = 3_600_000; // 1 hour\n\n/**\n * Configuration options for cache stores\n */\nexport type CacheOptions<Item> = {\n\t/**\n\t * Unique name for the cache store. Used as a prefix for cache keys to avoid collisions.\n\t */\n\tname: string;\n\t/**\n\t * Revision number for cache invalidation.\n\t * Incrementing this number will invalidate all existing cache entries for this store.\n\t * @defaultValue CacheClient options or \"default\"\n\t */\n\trevision?: number;\n\t/**\n\t * Time-to-live in milliseconds\n\t * @defaultValue CacheClient options or 3_600_000 (1 hour)\n\t */\n\tttlMs?: number;\n\t/**\n\t * Optional namespace to prefix all cache keys\n\t * @defaultValue CacheClient options or \"baeta\"\n\t */\n\tnamespace?: string;\n\t/**\n\t * Function to parse stored strings back into source objects.\n\t * If it throws an error, the cache will be treated as a miss and the value will be deleted.\n\t */\n\tparse: (value: string) => Item;\n\t/**\n\t * Function to serialize source objects into strings for cache storage.\n\t */\n\tserialize: (value: Item) => string;\n\t/**\n\t * Hook that gets called with the updated items after an update operation.\n\t */\n\tonUpdate?: (item: Item[]) => void | Promise<void>;\n\t/**\n\t * Hook that gets called with the inserted items after an insert operation.\n\t */\n\tonInsert?: (item: Item[]) => void | Promise<void>;\n\t/**\n\t * Hook that gets called with the refs of deleted items after a delete operation.\n\t */\n\tonDelete?: (ref: ItemRef[]) => void | Promise<void>;\n};\n\nexport type OptionalGetRef<Item> = {\n\t/*\n\t * Optional function to extract a string reference from source objects.\n\t * Will use \"id\" property by default.\n\t */\n\tgetRef?: (source: Item) => ItemRef;\n};\n\nexport type RequiredGetRef<Item> = {\n\t/*\n\t * Function to extract a string reference from source objects.\n\t */\n\tgetRef: (source: Item) => ItemRef;\n};\n","import type { ItemRef } from './item.ts';\n\nexport function arrayIsComplete<T>(items: Array<T | null> | null): items is T[] {\n\tif (items == null) {\n\t\treturn false;\n\t}\n\treturn items.every((item) => item != null);\n}\n\nexport function alignItemsWithRefs<T>(partialRefs: Array<ItemRef | null>, items: T[]) {\n\tif (partialRefs.length === items.length) {\n\t\treturn items;\n\t}\n\tlet itemIndex = 0;\n\tconst aligned: Array<T | null> = [];\n\tfor (const ref of partialRefs) {\n\t\tif (ref == null) {\n\t\t\taligned.push(null);\n\t\t} else {\n\t\t\taligned.push(items[itemIndex++]);\n\t\t}\n\t}\n\treturn aligned;\n}\n\nexport function toArray<T>(item: T | T[]): T[] {\n\treturn Array.isArray(item) ? item : [item];\n}\n\nexport function zip<T, U, R>(array1: T[], array2: U[], fn: (a: T, b: U) => R): R[] {\n\tif (array1.length !== array2.length) {\n\t\tthrow new Error('Arrays must have the same length to be zipped');\n\t}\n\tconst result: R[] = [];\n\tfor (let i = 0; i < array1.length; i++) {\n\t\tresult.push(fn(array1[i], array2[i]));\n\t}\n\treturn result;\n}\n","import DataLoader from 'dataloader';\nimport type { CacheClient, CacheClientArgs } from './client.ts';\nimport { assertValidRefType, type ItemRef } from './item.ts';\nimport {\n\tbuildCacheRevisionId,\n\tbuildItemCacheKeyId,\n\tbuildQueryCacheIndexKeyId,\n\tbuildQueryCacheIndexKeysIds,\n\tbuildQueryCacheKeyId,\n\ttype CacheRevisionId,\n\ttype ItemCacheKey,\n\ttype ItemCacheKeyPrefix,\n\ttype QueryCacheIndexKey,\n\ttype QueryCacheKey,\n\ttype QueryCacheKeyPrefix,\n} from './key.ts';\nimport { logger } from './logger.ts';\nimport { DEFAULT_NAMESPACE, DEFAULT_REVISION, DEFAULT_TTL_MS } from './options.ts';\nimport type { QueryTag, QueryTagWithArgs, QueryTagWithData, QueryTagWithIndexes } from './query.ts';\nimport { alignItemsWithRefs, arrayIsComplete, toArray } from './utils.ts';\n\nexport interface CacheStoreOptions<Item> {\n\tname: string;\n\tclient: CacheClient;\n\tnamespace?: string;\n\trevision?: string | number;\n\tttlMs?: number;\n\tparse: (value: string) => Item;\n\tserialize: (item: Item) => string;\n\tgetRef?: (source: Item) => ItemRef;\n}\n\ntype QueryMetadata = { refs: Array<null | string>; isList: boolean };\n\nexport class CacheStore<Item> {\n\tprotected readonly name: string;\n\tprotected readonly namespace: string;\n\tprotected readonly revision: string;\n\n\tprotected readonly client: CacheClient;\n\tprotected readonly itemCacheArgs: CacheClientArgs<Item>;\n\tprotected readonly queryCacheArgs: CacheClientArgs<QueryMetadata>;\n\n\tprotected readonly getRef?: (source: Item) => ItemRef;\n\n\tconstructor({\n\t\tname,\n\t\tclient,\n\t\tnamespace,\n\t\trevision,\n\t\tttlMs,\n\t\tparse,\n\t\tserialize,\n\t\tgetRef,\n\t}: CacheStoreOptions<Item>) {\n\t\tif (ttlMs != null && (!Number.isFinite(ttlMs) || ttlMs <= 0)) {\n\t\t\tthrow new Error(\n\t\t\t\t`Invalid ttlMs for cache \"${name}\": ${ttlMs}. Expected a positive number of milliseconds.`,\n\t\t\t);\n\t\t}\n\t\tthis.name = name;\n\t\tthis.namespace = namespace ?? DEFAULT_NAMESPACE;\n\t\tthis.revision = revision?.toString() ?? DEFAULT_REVISION;\n\t\tthis.client = client;\n\t\tthis.getRef = getRef;\n\t\tthis.itemCacheArgs = {\n\t\t\tttlMs: ttlMs ?? DEFAULT_TTL_MS,\n\t\t\tparse: (value: string) => parseItemSafely(value, parse),\n\t\t\tserialize: (item: Item) => serialize(item),\n\t\t};\n\t\tthis.queryCacheArgs = {\n\t\t\tttlMs: ttlMs ?? DEFAULT_TTL_MS,\n\t\t\tparse: (value: string) => parseQueryMetadataSafely(value),\n\t\t\tserialize: (meta: QueryMetadata) => JSON.stringify(meta),\n\t\t};\n\t}\n\n\tprotected loadAndParse = async (refs: ReadonlyArray<ItemRef>): Promise<Array<Item | null>> => {\n\t\tconst keys = refs.map((ref) => this.getItemKeyByRef(ref));\n\t\treturn await this.client.getPartialItems(keys, this.itemCacheArgs);\n\t};\n\n\tprotected loader = new DataLoader<ItemRef, Item | null>(this.loadAndParse, {\n\t\tcache: false,\n\t});\n\n\tasync get(ref: ItemRef): Promise<Item | null> {\n\t\treturn await this.loader.load(ref);\n\t}\n\n\tasync getMany(refs: ItemRef[]): Promise<Item[] | null> {\n\t\tconst results = await Promise.all(refs.map((r) => this.get(r)));\n\t\tif (!arrayIsComplete(results)) {\n\t\t\treturn null;\n\t\t}\n\t\treturn results;\n\t}\n\n\tasync getPartial(refs: ItemRef[]): Promise<Array<Item | null>> {\n\t\treturn await Promise.all(refs.map((ref) => this.get(ref)));\n\t}\n\n\tasync save(item: Item | Item[]) {\n\t\tconst values = toArray(item);\n\t\tconst entries: Array<[ItemCacheKey, Item]> = values.map((item) => [\n\t\t\tthis.getItemKey(item),\n\t\t\titem,\n\t\t]);\n\t\treturn await this.client.saveItems(entries, this.itemCacheArgs);\n\t}\n\n\tasync saveIfNotExists(item: Item | Item[]) {\n\t\tconst values = toArray(item);\n\t\tconst entries: Array<[ItemCacheKey, Item]> = values.map((item) => [\n\t\t\tthis.getItemKey(item),\n\t\t\titem,\n\t\t]);\n\t\treturn await this.client.saveItems(entries, this.itemCacheArgs, {\n\t\t\tdisableOverwrite: true,\n\t\t});\n\t}\n\n\tasync saveWithDiff(item: Item | Item[]): Promise<Array<Item | null>> {\n\t\tconst values = toArray(item);\n\t\tconst entries: Array<[ItemCacheKey, Item]> = values.map((item) => [\n\t\t\tthis.getItemKey(item),\n\t\t\titem,\n\t\t]);\n\t\treturn await this.client.saveItemsWithDiff(entries, this.itemCacheArgs);\n\t}\n\n\tasync delete(ref: ItemRef | ItemRef[]) {\n\t\tconst refs = toArray(ref);\n\t\tconst keys = refs.map((r) => this.getItemKeyByRef(r));\n\t\tawait this.client.deleteItems(keys, this.itemCacheArgs);\n\t}\n\n\tasync deleteWithDiff(ref: ItemRef | ItemRef[]): Promise<Array<Item | null>> {\n\t\tconst refs = toArray(ref);\n\t\tconst keys = refs.map((r) => this.getItemKeyByRef(r));\n\t\treturn await this.client.deleteItemsWithDiff(keys, this.itemCacheArgs);\n\t}\n\n\tasync getQuery(query: QueryTagWithArgs): Promise<{ query: unknown } | null> {\n\t\tconst queryKey = this.getQueryKey(query);\n\t\tconst meta = await this.client.getQuery(queryKey, this.queryCacheArgs);\n\n\t\tif (meta == null) {\n\t\t\treturn null;\n\t\t}\n\n\t\tconst isList = meta.isList;\n\t\tconst nullableRefs = meta.refs;\n\t\tconst refs = nullableRefs.filter((ref) => ref != null);\n\t\tconst items = await this.getMany(refs);\n\n\t\tif (items == null) {\n\t\t\treturn null;\n\t\t}\n\n\t\tconst aligned = alignItemsWithRefs(nullableRefs, items);\n\t\tconst result = isList ? aligned : (aligned.at(0) ?? null);\n\n\t\treturn { query: result };\n\t}\n\n\tasync saveQuery(\n\t\tquery: QueryTagWithData<Item>,\n\t\treplaceExistingItems = false,\n\t\tttlMs?: number,\n\t): Promise<void> {\n\t\tconst data = query.data;\n\t\tconst queryKey = this.getQueryKey(query);\n\t\tconst queryIndexes = this.getQueryIndexes(query, true);\n\n\t\tconst isList = Array.isArray(data);\n\t\tconst nullableItems = isList ? data : [data];\n\t\tconst items = nullableItems.filter((item) => item != null);\n\n\t\tif (items.length > 0) {\n\t\t\tif (replaceExistingItems) {\n\t\t\t\tawait this.save(items);\n\t\t\t} else {\n\t\t\t\tawait this.saveIfNotExists(items);\n\t\t\t}\n\t\t}\n\n\t\tconst encodedRefs = nullableItems.map((item) => {\n\t\t\tif (item == null) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\treturn this.getRefWithFallback(item).toString();\n\t\t});\n\n\t\tconst metadata = {\n\t\t\trefs: encodedRefs,\n\t\t\tisList,\n\t\t};\n\n\t\treturn await this.client.saveQuery(queryKey, queryIndexes, metadata, {\n\t\t\t...this.queryCacheArgs,\n\t\t\tttlMs: ttlMs ?? this.queryCacheArgs.ttlMs,\n\t\t});\n\t}\n\n\tdeleteQueries(query: QueryTagWithIndexes): Promise<void> {\n\t\tconst queryIndexes = this.getQueryIndexes(query);\n\t\treturn this.client.deleteQueries(queryIndexes, this.queryCacheArgs);\n\t}\n\n\tgetRefWithFallback(root: Item): ItemRef {\n\t\tif (this.getRef) {\n\t\t\treturn this.getRef(root);\n\t\t}\n\t\tif (root == null) {\n\t\t\tthrow new Error('Object is null or undefined, cannot get ref');\n\t\t}\n\t\tif (typeof root === 'object' && 'id' in root) {\n\t\t\tassertValidRefType(root.id);\n\t\t\treturn root.id.toString();\n\t\t}\n\t\tthrow new Error('Object does not have id. Define \"getRef\" function in cache options');\n\t}\n\n\tgetItemKey(item: Item): ItemCacheKey {\n\t\tconst ref = this.getRefWithFallback(item);\n\t\treturn this.getItemKeyByRef(ref);\n\t}\n\n\tgetItemKeyByRef(ref: ItemRef): ItemCacheKey {\n\t\tconst prefix: ItemCacheKeyPrefix = `${this.namespace}:{${this.name}:item:${buildCacheRevisionId(this.revision)}}`;\n\t\tconst keyId = buildItemCacheKeyId(ref.toString());\n\t\treturn `${prefix}:${keyId}`;\n\t}\n\n\tgetQueryKey(query: QueryTagWithArgs): QueryCacheKey {\n\t\tconst prefix = this.getQueryKeyPrefix(query);\n\t\treturn `${prefix}:${buildQueryCacheKeyId(query.args)}`;\n\t}\n\n\tgetQueryIndexes(query: QueryTagWithIndexes, ensureCatchAll = false): QueryCacheIndexKey[] {\n\t\tconst prefix = this.getQueryKeyPrefix(query);\n\t\tconst keyIndexes = buildQueryCacheIndexKeysIds(query.indexes);\n\t\tif (ensureCatchAll && query.indexes.length > 0) {\n\t\t\tkeyIndexes.push(buildQueryCacheIndexKeyId());\n\t\t}\n\t\treturn keyIndexes.map((keyIndex) => `${prefix}:${keyIndex}` as const);\n\t}\n\n\tgetQueryKeyPrefix(query: QueryTag): QueryCacheKeyPrefix {\n\t\treturn `${this.namespace}:{${this.name}:query:${query.name}:${this.getQueryKeyRevision(query)}}`;\n\t}\n\n\tgetQueryKeyRevision(query: QueryTag): CacheRevisionId {\n\t\tconst combinedRevision = `${this.revision}_${query.revision?.toString() ?? DEFAULT_REVISION}`;\n\t\treturn buildCacheRevisionId(combinedRevision);\n\t}\n}\n\nfunction parseItemSafely<T>(value: string, parseItem: (value: string) => T): T | null {\n\ttry {\n\t\treturn parseItem(value);\n\t} catch (err) {\n\t\tlogger.warn({\n\t\t\ttype: 'parse-item',\n\t\t\tmessage: 'Failed to parse item, returning null',\n\t\t\terror: err,\n\t\t});\n\t\treturn null;\n\t}\n}\n\nfunction parseQueryMetadataSafely(value: string): QueryMetadata | null {\n\tlet parsed: unknown;\n\ttry {\n\t\tparsed = JSON.parse(value);\n\t} catch (err) {\n\t\tlogger.warn({\n\t\t\ttype: 'parse-query-metadata',\n\t\t\tmessage: 'Failed to parse query metadata, treating as cache miss',\n\t\t\terror: err,\n\t\t});\n\t\treturn null;\n\t}\n\tif (!isValidQueryMetadata(parsed)) {\n\t\tlogger.warn({\n\t\t\ttype: 'parse-query-metadata',\n\t\t\tmessage: 'Query metadata has invalid shape, treating as cache miss',\n\t\t});\n\t\treturn null;\n\t}\n\treturn parsed;\n}\n\nfunction isValidQueryMetadata(value: unknown): value is QueryMetadata {\n\tif (value == null || typeof value !== 'object') {\n\t\treturn false;\n\t}\n\tconst candidate = value as { refs?: unknown; isList?: unknown };\n\tif (!Array.isArray(candidate.refs)) {\n\t\treturn false;\n\t}\n\tif (typeof candidate.isList !== 'boolean') {\n\t\treturn false;\n\t}\n\treturn candidate.refs.every((ref) => ref === null || typeof ref === 'string');\n}\n","import type { CacheClient } from './client.ts';\nimport type { QueryDefinitionMap, QueryMethod, QueryMethodMap } from './define-query.ts';\nimport type { ItemRef, RefCompatibleItem } from './item.ts';\nimport { logger } from './logger.ts';\nimport type { CacheOptions, OptionalGetRef, RequiredGetRef } from './options.ts';\nimport type { QueryOnDeleteHook, QueryOnInsertHook, QueryOnUpdateHook, QueryTag } from './query.ts';\nimport { CacheStore } from './store.ts';\nimport { toArray, zip } from './utils.ts';\n\nexport type CacheHooksOptions = {\n\t/**\n\t * If true, hooks will be awaited. If false, hooks will be fired asynchronously and will not block cache methods.\n\t * @defaultValue false\n\t */\n\twaitForHooks?: boolean;\n};\n\nexport type Cache<Item> = {\n\tget(ref: ItemRef): Promise<Item | null>;\n\tgetMany(refs: ItemRef[]): Promise<Item[] | null>;\n\tgetPartial(refs: ItemRef[]): Promise<Array<Item | null>>;\n\tupdate(item: Item | Item[]): Promise<void>;\n\tinsert(item: Item | Item[]): Promise<void>;\n\tdelete(ref: ItemRef | ItemRef[]): Promise<void>;\n};\n\nexport type CacheWithQueries<Item, QueryDefinitions extends QueryDefinitionMap<Item>> = {\n\tget(ref: ItemRef): Promise<Item | null>;\n\tgetMany(refs: ItemRef[]): Promise<Item[] | null>;\n\tgetPartial(refs: ItemRef[]): Promise<Array<Item | null>>;\n\tupdate(item: Item | Item[], options?: CacheHooksOptions): Promise<void>;\n\tinsert(item: Item | Item[], options?: CacheHooksOptions): Promise<void>;\n\tdelete(ref: ItemRef | ItemRef[], options?: CacheHooksOptions): Promise<void>;\n\tdeleteQueries(): Promise<void>;\n\tqueries: QueryMethodMap<QueryDefinitions>;\n};\n\nexport type CreateCacheFactory<Item> = {\n\tbuild: () => Cache<Item>;\n\twithQueries: <QueryDefinitions extends QueryDefinitionMap<Item>>(\n\t\tdefinitions: QueryDefinitions,\n\t) => {\n\t\tbuild: () => CacheWithQueries<Item, QueryDefinitions>;\n\t};\n};\n\nexport function createCache<Item extends RefCompatibleItem>(\n\tclient: CacheClient,\n\toptions: CacheOptions<Item> & OptionalGetRef<Item>,\n): CreateCacheFactory<Item>;\nexport function createCache<Item>(\n\tclient: CacheClient,\n\toptions: CacheOptions<Item> & RequiredGetRef<Item>,\n): CreateCacheFactory<Item>;\nexport function createCache<Item>(\n\tclient: CacheClient,\n\toptions: CacheOptions<Item> & OptionalGetRef<Item>,\n): CreateCacheFactory<Item> {\n\tconst storeClient = new CacheStore<Item>({\n\t\tclient,\n\t\tname: options.name,\n\t\tparse: options.parse,\n\t\tserialize: options.serialize,\n\t\tgetRef: options.getRef,\n\t\tttlMs: options.ttlMs ?? client.options?.ttlMs,\n\t\tnamespace: options.namespace ?? client.options?.namespace,\n\t\trevision: options.revision ?? client.options?.revision,\n\t});\n\treturn {\n\t\tbuild: () =>\n\t\t\tcreateCacheMethods(\n\t\t\t\tstoreClient,\n\t\t\t\t{\n\t\t\t\t\tonUpdateHook: options.onUpdate,\n\t\t\t\t\tonInsertHook: options.onInsert,\n\t\t\t\t\tonDeleteHook: options.onDelete,\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tonUpdateHooks: [],\n\t\t\t\t\tonInsertHooks: [],\n\t\t\t\t\tonDeleteHooks: [],\n\t\t\t\t},\n\t\t\t),\n\t\twithQueries: (definitions) => {\n\t\t\treturn {\n\t\t\t\tbuild: () => createCacheMethodsWithQueries(storeClient, options, definitions),\n\t\t\t};\n\t\t},\n\t};\n}\n\nfunction createCacheMethods<Item>(\n\tstoreClient: CacheStore<Item>,\n\titemHooks: {\n\t\tonUpdateHook?: (item: Item[]) => void | Promise<void>;\n\t\tonInsertHook?: (item: Item[]) => void | Promise<void>;\n\t\tonDeleteHook?: (ref: ItemRef[]) => void | Promise<void>;\n\t},\n\tqueryHooks: {\n\t\tonUpdateHooks: Array<QueryOnUpdateHook<Item>>;\n\t\tonInsertHooks: Array<QueryOnInsertHook<Item>>;\n\t\tonDeleteHooks: Array<QueryOnDeleteHook<Item>>;\n\t},\n): Cache<Item> | Omit<CacheWithQueries<Item, any>, 'queries' | 'deleteQueries'> {\n\treturn {\n\t\tget: (ref) => storeClient.get(ref),\n\t\tgetMany: (refs) => storeClient.getMany(refs),\n\t\tgetPartial: (refs) => storeClient.getPartial(refs),\n\t\tupdate: async (item, options) => {\n\t\t\tif (queryHooks.onUpdateHooks.length === 0) {\n\t\t\t\tawait storeClient.save(item);\n\t\t\t\tawait fireHook(itemHooks.onUpdateHook, toArray(item), options);\n\t\t\t} else {\n\t\t\t\tconst items = toArray(item);\n\t\t\t\tconst previous = await storeClient.saveWithDiff(items);\n\t\t\t\tconst pairs = zip(items, previous, (next, previous) => ({ next, previous }));\n\t\t\t\tawait Promise.all([\n\t\t\t\t\tfireHook(itemHooks.onUpdateHook, items, options),\n\t\t\t\t\tfireHooks(queryHooks.onUpdateHooks, pairs, options),\n\t\t\t\t]);\n\t\t\t}\n\t\t},\n\t\tinsert: async (item, options) => {\n\t\t\tawait storeClient.save(item);\n\t\t\tif (queryHooks.onInsertHooks.length === 0) {\n\t\t\t\tawait fireHook(itemHooks.onInsertHook, toArray(item), options);\n\t\t\t} else {\n\t\t\t\tconst items = toArray(item);\n\t\t\t\tawait Promise.all([\n\t\t\t\t\tfireHook(itemHooks.onInsertHook, items, options),\n\t\t\t\t\tfireHooks(queryHooks.onInsertHooks, items, options),\n\t\t\t\t]);\n\t\t\t}\n\t\t},\n\t\tdelete: async (ref, options) => {\n\t\t\tif (queryHooks.onDeleteHooks.length === 0) {\n\t\t\t\tawait storeClient.delete(ref);\n\t\t\t\tawait fireHook(itemHooks.onDeleteHook, toArray(ref), options);\n\t\t\t} else {\n\t\t\t\tconst refs = toArray(ref);\n\t\t\t\tconst previous = await storeClient.deleteWithDiff(refs);\n\t\t\t\tawait storeClient.delete(refs);\n\t\t\t\tconst pairs = zip(refs, previous, (ref, previous) => ({ ref, previous }));\n\t\t\t\tawait Promise.all([\n\t\t\t\t\tfireHook(itemHooks.onDeleteHook, refs, options),\n\t\t\t\t\tfireHooks(queryHooks.onDeleteHooks, pairs, options),\n\t\t\t\t]);\n\t\t\t}\n\t\t},\n\t};\n}\n\nfunction createCacheMethodsWithQueries<Item, QueryDefinitions extends QueryDefinitionMap<Item>>(\n\tstoreClient: CacheStore<Item>,\n\toptions: CacheOptions<Item> & OptionalGetRef<Item>,\n\tdefinitions: QueryDefinitions,\n): CacheWithQueries<Item, QueryDefinitions> {\n\tconst { queries, queryTags, onUpdateHooks, onInsertHooks, onDeleteHooks } = createQueriesAndHooks<\n\t\tItem,\n\t\tQueryDefinitions\n\t>(definitions, storeClient);\n\treturn {\n\t\t...createCacheMethods(\n\t\t\tstoreClient,\n\t\t\t{\n\t\t\t\tonUpdateHook: options.onUpdate,\n\t\t\t\tonInsertHook: options.onInsert,\n\t\t\t\tonDeleteHook: options.onDelete,\n\t\t\t},\n\t\t\t{ onUpdateHooks, onInsertHooks, onDeleteHooks },\n\t\t),\n\t\tdeleteQueries: async () => {\n\t\t\tconst promises = queryTags.map((tag) =>\n\t\t\t\tstoreClient.deleteQueries({\n\t\t\t\t\t...tag,\n\t\t\t\t\tindexes: [],\n\t\t\t\t}),\n\t\t\t);\n\t\t\tawait Promise.all(promises);\n\t\t},\n\t\tqueries,\n\t};\n}\n\nfunction createQueriesAndHooks<Item, QueryDefinitions extends QueryDefinitionMap<Item>>(\n\tdefinitions: QueryDefinitions | undefined,\n\tstore: CacheStore<Item>,\n) {\n\tconst queries: Partial<QueryMethodMap<QueryDefinitions>> = {};\n\tconst queryTags: QueryTag[] = [];\n\tconst onUpdateHooks: Array<QueryOnUpdateHook<Item>> = [];\n\tconst onInsertHooks: Array<QueryOnInsertHook<Item>> = [];\n\tconst onDeleteHooks: Array<QueryOnDeleteHook<Item>> = [];\n\tfor (const [queryName, buildQuery] of Object.entries(definitions ?? {})) {\n\t\tconst queryHandler = buildQuery(store, queryName);\n\t\tqueries[queryName as keyof QueryDefinitions] = queryHandler.call as QueryMethod<\n\t\t\tQueryDefinitions[keyof QueryDefinitions]\n\t\t>;\n\t\tqueryTags.push(queryHandler.tag);\n\t\tif (queryHandler.hooks.onUpdate) {\n\t\t\tonUpdateHooks.push(queryHandler.hooks.onUpdate);\n\t\t}\n\t\tif (queryHandler.hooks.onDelete) {\n\t\t\tonDeleteHooks.push(queryHandler.hooks.onDelete);\n\t\t}\n\t\tif (queryHandler.hooks.onInsert) {\n\t\t\tonInsertHooks.push(queryHandler.hooks.onInsert);\n\t\t}\n\t}\n\treturn {\n\t\tqueries: queries as QueryMethodMap<QueryDefinitions>,\n\t\tqueryTags,\n\t\tonUpdateHooks,\n\t\tonInsertHooks,\n\t\tonDeleteHooks,\n\t};\n}\n\nasync function fireHook<T>(\n\thook: ((v: T) => void | Promise<void>) | undefined,\n\tvalue: T,\n\toptions?: CacheHooksOptions,\n) {\n\tif (hook == null) {\n\t\treturn;\n\t}\n\tif (options?.waitForHooks) {\n\t\tawait hook(value);\n\t} else {\n\t\tPromise.resolve()\n\t\t\t.then(() => hook(value))\n\t\t\t.catch((err) => {\n\t\t\t\tlogger.error({\n\t\t\t\t\ttype: 'cache-hook',\n\t\t\t\t\tmessage: 'Error in cache hook',\n\t\t\t\t\terror: err,\n\t\t\t\t});\n\t\t\t});\n\t}\n}\n\nasync function fireHooks<T>(\n\thooks: Array<(v: T) => Promise<void>>,\n\tvalue: T,\n\toptions?: CacheHooksOptions,\n) {\n\tawait Promise.all(hooks.map((hook) => fireHook(hook, value, options)));\n}\n","import { logger } from './logger.ts';\nimport type {\n\tIndexedQueryArgs,\n\tItemFromQueryResult,\n\tQueryArgs,\n\tQueryArgsIndexes,\n\tQueryHandle,\n\tQueryHelpers,\n\tQueryHelpersWithIndexes,\n\tQueryIndex,\n\tQueryOptions,\n\tQueryResult,\n\tQueryTag,\n} from './query.ts';\nimport type { CacheStore } from './store.ts';\n\nexport type QueryFactory<\n\tResult extends QueryResult<Item>,\n\tArgs extends QueryArgs,\n\tIndexes extends QueryArgsIndexes<Args, Indexes>,\n\tItem = ItemFromQueryResult<Result>,\n> = (store: CacheStore<Item>, name: string) => QueryHandle<Result, Args, Indexes, Item>;\n\nexport type QueryMethod<T extends QueryFactory<any, any, any>> =\n\tT extends QueryFactory<infer Result, infer Args, any, any>\n\t\t? (args: Args) => Promise<Result>\n\t\t: never;\n\nexport type QueryDefinitionMap<Item> = Record<\n\tstring,\n\tQueryFactory<QueryResult<Item>, any, any, Item>\n>;\n\nexport type QueryMethodMap<Definitions extends QueryDefinitionMap<any>> = {\n\t[K in keyof Definitions]: QueryMethod<Definitions[K]>;\n};\n\nexport function defineQuery<\n\tResult extends QueryResult<Item>,\n\tArgs extends QueryArgs = Record<string, never>,\n\tIndexes extends QueryArgsIndexes<Args, Indexes> = Record<string, never>,\n\tItem = ItemFromQueryResult<Result>,\n>(options: QueryOptions<Result, Args, Indexes, Item>): QueryFactory<Result, Args, Indexes, Item> {\n\treturn (store: CacheStore<Item>, name: string) => {\n\t\tconst tag: QueryTag = {\n\t\t\tname,\n\t\t\trevision: options.revision,\n\t\t};\n\n\t\tconst resolve = async (args: Args): Promise<Result> => {\n\t\t\tconst fromCache = await store\n\t\t\t\t.getQuery({\n\t\t\t\t\t...tag,\n\t\t\t\t\targs,\n\t\t\t\t})\n\t\t\t\t.catch((err) => {\n\t\t\t\t\tlogger.error({\n\t\t\t\t\t\ttype: 'query-cache',\n\t\t\t\t\t\tmessage: `Failed to get query result for ${name}. Proceeding without caching.`,\n\t\t\t\t\t\terror: err,\n\t\t\t\t\t});\n\t\t\t\t\treturn null;\n\t\t\t\t});\n\n\t\t\tif (fromCache != null) {\n\t\t\t\treturn fromCache.query as Result;\n\t\t\t}\n\n\t\t\tconst data = await options.resolve(args);\n\n\t\t\tawait store\n\t\t\t\t.saveQuery(\n\t\t\t\t\t{\n\t\t\t\t\t\t...tag,\n\t\t\t\t\t\targs,\n\t\t\t\t\t\tdata,\n\t\t\t\t\t\tindexes: buildIndexes(args, options.indexArgsBy),\n\t\t\t\t\t},\n\t\t\t\t\toptions.replaceExistingItems,\n\t\t\t\t\toptions.ttlMs,\n\t\t\t\t)\n\t\t\t\t.catch((err) => {\n\t\t\t\t\tlogger.error({\n\t\t\t\t\t\ttype: 'query-cache',\n\t\t\t\t\t\tmessage: `Failed to save query result for ${name}. Proceeding without caching.`,\n\t\t\t\t\t\terror: err,\n\t\t\t\t\t});\n\t\t\t\t});\n\n\t\t\treturn data;\n\t\t};\n\n\t\tconst invalidateAll = async () => {\n\t\t\tawait store.deleteQueries({\n\t\t\t\t...tag,\n\t\t\t\tindexes: [],\n\t\t\t});\n\t\t};\n\n\t\tconst invalidateByArgs = async (\n\t\t\targs: Partial<IndexedQueryArgs<Args, Indexes>> | Partial<IndexedQueryArgs<Args, Indexes>>[],\n\t\t) => {\n\t\t\tconst argsArray = Array.isArray(args) ? args : [args];\n\t\t\tconst deletePromises = argsArray.map((args) =>\n\t\t\t\tstore.deleteQueries({\n\t\t\t\t\t...tag,\n\t\t\t\t\tindexes: buildIndexes(args, options.indexArgsBy),\n\t\t\t\t}),\n\t\t\t);\n\t\t\tawait Promise.all(deletePromises);\n\t\t};\n\n\t\tconst helpers: QueryHelpersWithIndexes<Args, Indexes> = {\n\t\t\tinvalidateAll,\n\t\t\tinvalidateByArgs,\n\t\t};\n\t\tconst helpersCast: QueryHelpers<Args, Indexes> = helpers as QueryHelpers<Args, Indexes>;\n\n\t\tconst { onUpdate, onDelete, onInsert } = options;\n\n\t\tconst hooks = {\n\t\t\tonUpdate: hookWithHelpers(helpersCast, onUpdate),\n\t\t\tonInsert: hookWithHelpers(helpersCast, onInsert),\n\t\t\tonDelete: hookWithHelpers(helpersCast, onDelete),\n\t\t};\n\n\t\treturn {\n\t\t\tcall: resolve,\n\t\t\ttag,\n\t\t\thelpers,\n\t\t\thooks,\n\t\t};\n\t};\n}\n\nfunction hookWithHelpers<Helpers, Args>(\n\thelpers: Helpers,\n\thook?: (args: Args, helpers: Helpers) => void | Promise<void>,\n) {\n\tif (!hook) {\n\t\treturn undefined;\n\t}\n\tconst hookWithHelpers = async (args: Args) => {\n\t\tawait hook(args, helpers);\n\t};\n\treturn hookWithHelpers;\n}\n\nfunction buildIndexes<Args extends QueryArgs, Indexes extends QueryArgsIndexes<Args, Indexes>>(\n\targs: Partial<Args>,\n\tindexArgsBy?: Indexes,\n): QueryIndex[] {\n\tif (!indexArgsBy) {\n\t\treturn [];\n\t}\n\tconst indexes: QueryIndex[] = [];\n\tfor (const key in indexArgsBy) {\n\t\tif (!Object.hasOwn(args, key)) {\n\t\t\tcontinue;\n\t\t}\n\t\tconst value = args[key];\n\t\tif (value === undefined) {\n\t\t\tcontinue;\n\t\t}\n\t\tif (\n\t\t\ttypeof value !== 'string' &&\n\t\t\ttypeof value !== 'number' &&\n\t\t\ttypeof value !== 'boolean' &&\n\t\t\tvalue !== null\n\t\t) {\n\t\t\tthrow new TypeError(\n\t\t\t\t`Cache index '${key}' must be a primitive (string, number, boolean, or null) but received ${\n\t\t\t\t\tArray.isArray(value) ? 'array' : typeof value\n\t\t\t\t}.`,\n\t\t\t);\n\t\t}\n\t\tindexes.push([key, value]);\n\t}\n\treturn indexes;\n}\n"],"mappings":";;;;AAmCA,IAAsB,cAAtB,MAAkC;CACjC;CAEA,YAAY,SAA8B;EACzC,KAAK,UAAU;CAChB;AAyCD;;;AC/EA,MAAa,SAAS,aAAa,cAAc;;;;;;ACWjD,SAAgB,mBAAmB,KAAuD;CACzF,IAAI,OAAO,QA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I,UAAU,KAAA,GACb;EAED,IACC,OAAO,UAAU,YACjB,OAAO,UAAU,YACjB,OAAO,UAAU,aACjB,UAAU,MAEV,MAAM,IAAI,UACT,gBAAgB,IAAI,wEACnB,MAAM,QAAQ,KAAK,IAAI,UAAU,OAAO,MACxC,EACF;EAED,QAAQ,KAAK,CAAC,KAAK,KAAK,CAAC;CAC1B;CACA,OAAO;AACR"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@baeta/cache",
|
|
3
|
-
"version": "2.0.0-next.
|
|
3
|
+
"version": "2.0.0-next.17",
|
|
4
4
|
"description": "Type-safe caching for Baeta.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"baeta",
|
|
@@ -63,8 +63,7 @@
|
|
|
63
63
|
"types": "tsc --noEmit"
|
|
64
64
|
},
|
|
65
65
|
"dependencies": {
|
|
66
|
-
"@baeta/util-
|
|
67
|
-
"@baeta/util-log": "^2.0.0-next.4",
|
|
66
|
+
"@baeta/util-log": "^2.0.0-next.6",
|
|
68
67
|
"dataloader": "^2.2.3",
|
|
69
68
|
"ohash": "^2.0.11"
|
|
70
69
|
},
|