@prisma/orm-extension-middleware-cache 8.0.0-rc.18-dev.46 → 8.0.0-rc.19

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 CHANGED
@@ -40,12 +40,12 @@ interface CacheEntry<TMeta = unknown, TValue = CachedValue> {
40
40
  interface CacheStore<TMeta = unknown, TValue = CachedValue> {
41
41
  get(target: {
42
42
  readonly key: string;
43
- readonly meta: TMeta | undefined;
43
+ readonly meta?: TMeta | undefined;
44
44
  }): Promise<CacheEntry<TMeta, TValue>>;
45
45
  set(entry: CacheEntry<TMeta, TValue>, value: TValue): Promise<boolean>;
46
46
  unset(target: {
47
- readonly keys: readonly string[] | undefined;
48
- readonly meta: TMeta | undefined;
47
+ readonly keys?: readonly string[] | undefined;
48
+ readonly meta?: TMeta | undefined;
49
49
  }): Promise<void>;
50
50
  }
51
51
 
@@ -56,7 +56,7 @@ type CachedValue =
56
56
  | { readonly kind: 'call-result'; readonly result: unknown };
57
57
  ```
58
58
 
59
- The store keeps a version per key, even for a key that holds no value; a key never seen has version 0, and only `unset` changes it. `get({ key, meta })` always returns a `CacheEntry` with the key, the read annotation's `meta`, the current version and `data`, which is `{ empty: true }` on a miss. A store that matches `meta` folds the versions of whatever `meta` names into that version, and does the same when `set` compares, so an `invalidate({ meta })` refuses an overlapping read's `set` even for a key the store has never seen. `set(entry, value)` stores `value` if and only if the key's version still equals `entry.version`, and returns whether it stored; there is no unconditional write, so a prefill is `get` then `set`. `unset` removes every value named in `keys` (`undefined` or non-empty) and every value that matches `meta`, increments the version of every key it removes or would remove, and an `unset` by key also drops that key from any `meta` index. `set` must be atomic against `unset`: one synchronous step in memory, or one script on a server. Keep a moved version at least as long as a read can take; the default store keeps it for `ttlMs`. The store interprets `meta` in all three methods; the middleware never does. A store that cannot act on a `meta` given to `unset` must throw: the default store throws `RUNTIME.CACHE_STORE_META_UNSUPPORTED`. `unset` must not run queries through the runtime that uses the middleware. An error from `get` or `set` fails the read, for statements and ORM calls alike, even when the database answered it; nothing is stored, so the next read fails the same way while the store keeps throwing. A store used with this middleware holds cached values: `createCacheMiddleware` takes a `CacheStore<TMeta, CachedValue>`, and a store of any other value type, `unknown` included, is a type error. `TValue` defaults to `CachedValue`, so `CacheStore<TMeta>` is a store of cached values; it exists so the same store type can serve other caches. A store must give back a value equivalent to the one it was given, `kind` included. An ORM call's result holds the values codecs decoded, such as `Date`, `bigint`, Temporal values and extension class instances, so a store that serializes needs an application-supplied serializer that rebuilds those types; `JSON.stringify` throws on a `bigint` and turns a `Date` into a string. A deploy that changes what a codec returns needs a new key prefix for a shared store, because the key does not cover how values are decoded. The default store, `createInMemoryCacheStore<TMeta>()`, holds cached values. It keeps statement rows and ORM call results differently. Statement rows are copied one level deep on `set` and `get`: the array, and each row object with its prototype. The driver's values in them, such as BSON `ObjectId`s or a `Buffer`, are kept by reference and shared with every hit; the runtime decodes them on each hit, and a codec that returns its wire value unchanged, such as a date or byte-array codec, hands every caller that same shared object. An ORM call's result has its plain structure copied on `set` and on every `get`: plain and null-prototype objects, arrays (their elements only; holes read as `undefined`), `Map`, `Set`, `Date`, `RegExp`, `ArrayBuffer`, typed arrays (a subclass such as Node's `Buffer` keeps its class) and `DataView` (copied as a plain `DataView`). Every other value in it, such as a class instance (a Temporal value, a decimal, a vector, a BSON value, an error) or a function, is shared by reference with the first caller and every hit. So, once the call has ended, changing the plain objects and arrays of a result changes no later hit; changing a shared value in place does, so codecs should return values that are not mutated in place. The store never refuses a value: `set` returns `false` only when the key's version moved. A miss copies the result once and each hit copies it again: about the work of decoding rows, linear in the size of the result. A custom store decides for itself whether to copy and what it can store.
59
+ The store keeps a version per key, even for a key that holds no value; a key never seen has version 0, and only `unset` changes it. `get({ key, meta })` always returns a `CacheEntry` with the key, the read annotation's `meta`, the current version and `data`, which is `{ empty: true }` on a miss. A store that matches `meta` folds the versions of whatever `meta` names into that version, and does the same when `set` compares, so an `invalidate({ meta })` refuses an overlapping read's `set` even for a key the store has never seen. `set(entry, value)` stores `value` if and only if the key's version still equals `entry.version`, and returns whether it stored; there is no unconditional write, so a prefill is `get` then `set`. `unset` removes every value named in `keys` (`undefined` or non-empty) and every value that matches `meta`, increments the version of every key it removes or would remove, and an `unset` by key also drops that key from any `meta` index. A field the caller leaves out of `get` or `unset` means the same as `undefined`, and a store must not tell the two apart. `set` must be atomic against `unset`: one synchronous step in memory, or one script on a server. Keep a moved version at least as long as a read can take; the default store keeps it for `ttlMs`. The store interprets `meta` in all three methods; the middleware never does. A store that cannot act on a `meta` given to `unset` must throw: the default store throws `RUNTIME.CACHE_STORE_META_UNSUPPORTED`. `unset` must not run queries through the runtime that uses the middleware. An error from `get` or `set` fails the read, for statements and ORM calls alike, even when the database answered it; nothing is stored, so the next read fails the same way while the store keeps throwing. A store used with this middleware holds cached values: `createCacheMiddleware` takes a `CacheStore<TMeta, CachedValue>`, and a store of any other value type, `unknown` included, is a type error. `TValue` defaults to `CachedValue`, so `CacheStore<TMeta>` is a store of cached values; it exists so the same store type can serve other caches. A store must give back a value equivalent to the one it was given, `kind` included. An ORM call's result holds the values codecs decoded, such as `Date`, `bigint`, Temporal values and extension class instances, so a store that serializes needs an application-supplied serializer that rebuilds those types; `JSON.stringify` throws on a `bigint` and turns a `Date` into a string. A deploy that changes what a codec returns needs a new key prefix for a shared store, because the key does not cover how values are decoded. The default store, `createInMemoryCacheStore<TMeta>()`, holds cached values. It keeps statement rows and ORM call results differently. Statement rows are copied one level deep on `set` and `get`: the array, and each row object with its prototype. The driver's values in them, such as BSON `ObjectId`s or a `Buffer`, are kept by reference and shared with every hit; the runtime decodes them on each hit, and a codec that returns its wire value unchanged, such as a date or byte-array codec, hands every caller that same shared object. An ORM call's result has its plain structure copied on `set` and on every `get`: plain and null-prototype objects, arrays (their elements only; holes read as `undefined`), `Map`, `Set`, `Date`, `RegExp`, `ArrayBuffer`, typed arrays (a subclass such as Node's `Buffer` keeps its class) and `DataView` (copied as a plain `DataView`). Every other value in it, such as a class instance (a Temporal value, a decimal, a vector, a BSON value, an error) or a function, is shared by reference with the first caller and every hit. So, once the call has ended, changing the plain objects and arrays of a result changes no later hit; changing a shared value in place does, so codecs should return values that are not mutated in place. The store never refuses a value: `set` returns `false` only when the key's version moved. A miss copies the result once and each hit copies it again: about the work of decoding rows, linear in the size of the result. A custom store decides for itself whether to copy and what it can store.
60
60
 
61
61
  ## Typed meta
62
62
 
package/dist/index.d.mts CHANGED
@@ -14,9 +14,9 @@ import { ActivityContext, AnnotationHandle, AnnotationValue, CrossFamilyMiddlewa
14
14
  * `TMeta` is the shape of `meta`; pass the store's `TMeta` so the two agree.
15
15
  */
16
16
  interface CacheAnnotationOptions<TMeta = unknown> {
17
- readonly key?: string;
18
- readonly meta?: TMeta;
19
- readonly bypass?: boolean;
17
+ readonly key?: string | undefined;
18
+ readonly meta?: TMeta | undefined;
19
+ readonly bypass?: boolean | undefined;
20
20
  }
21
21
  /**
22
22
  * The type of `cacheAnnotation`: a call generic in `TMeta`, plus the read-only `namespace`,
@@ -60,8 +60,8 @@ declare const cacheAnnotation: CacheAnnotationHandle;
60
60
  * `TMeta` is the shape of `meta`; pass the store's `TMeta` so the two agree.
61
61
  */
62
62
  interface InvalidationTarget<TMeta = unknown> {
63
- readonly keys?: readonly string[];
64
- readonly meta?: TMeta;
63
+ readonly keys?: readonly string[] | undefined;
64
+ readonly meta?: TMeta | undefined;
65
65
  }
66
66
  /**
67
67
  * The type of `invalidateAnnotation`: a call generic in `TMeta`, plus the read-only `namespace`,
@@ -141,7 +141,8 @@ interface CacheEntry<TMeta = unknown, TValue = CachedValue> {
141
141
  * synchronous step in memory or one script on a server.
142
142
  * - `unset` removes every value named in `keys` and every value that matches `meta`, and
143
143
  * increments the version of every key it removes or would remove, including keys that hold no
144
- * value. `keys` is `undefined` or non-empty. A store that cannot act on a `meta` it is given
144
+ * value. `keys` is `undefined` or non-empty. A field the caller leaves out of `get` or `unset`
145
+ * means the same as `undefined`, and a store must not tell the two apart. A store that cannot act on a `meta` it is given
145
146
  * must throw rather than ignore it. An `unset` by key must also drop that key from any `meta`
146
147
  * index the store keeps.
147
148
  *
@@ -155,12 +156,12 @@ interface CacheEntry<TMeta = unknown, TValue = CachedValue> {
155
156
  interface CacheStore<TMeta = unknown, TValue = CachedValue> {
156
157
  get(target: {
157
158
  readonly key: string;
158
- readonly meta: TMeta | undefined;
159
+ readonly meta?: TMeta | undefined;
159
160
  }): Promise<CacheEntry<TMeta, TValue>>;
160
161
  set(entry: CacheEntry<TMeta, TValue>, value: TValue): Promise<boolean>;
161
162
  unset(target: {
162
- readonly keys: readonly string[] | undefined;
163
- readonly meta: TMeta | undefined;
163
+ readonly keys?: readonly string[] | undefined;
164
+ readonly meta?: TMeta | undefined;
164
165
  }): Promise<void>;
165
166
  }
166
167
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../../../../3-extensions/middleware-cache/dist/index.d.mts"],"mappings":";;;;;;;;;;;;;;;UAcU,uBAAuB;WACtB;WACA,OAAO;WACP;;;;;;KAMN,0BAA0B,iBAAiB,SAAS,uBAAuB,WAAW,gBAAgB;WAChG;WACA,cAAc;WACd,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;cA4BpB,iBAAiB;;;;;;UAMrB,mBAAmB;WAClB;WACA,OAAO;;;;;;KAMb,+BAA+B,iBAAiB,SAAS,mBAAmB,WAAW,gBAAgB;WACjG;WACA,cAAc;WACd,MAAM,iBAAiB;;;;;;;;;;;;;;cAcpB,sBAAsB;;;;;;;KAO/B,sBAAsB;;;;KAItB;WACM;WACA,MAAM;;WAEN;WACA;;;;;;;;;;;;UAYD,WAAW,iBAAiB,SAAS;WACpC;WACA,MAAM;WACN;WACA;aACE;;aAEA;aACA,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;UAgCV,WAAW,iBAAiB,SAAS;EAC7C,IAAI;aACO;aACA,MAAM;MACb,QAAQ,WAAW,OAAO;EAC9B,IAAI,OAAO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OAAO,SAAS;EACtD,MAAM;aACK;aACA,OAAO;MACd;;;;;;;;;;;;;;;UAeI;WACC;WACA;WACA;;;;;iBAKM,yBAAyB,iBAAiB,UAAU,4BAA4B,WAAW,OAAO;;;;;;;;;;;;;;;;;;;UAmBzG,uBAAuB;WACtB,QAAQ,WAAW,OAAO;WAC1B,aAAa,MAAM,eAAe,KAAK,6BAA6B;;;;;;;;;;;;;;;KAe1E,gBAAgB,mBAAmB;WAC7B,aAAa,QAAQ,mBAAmB,WAAW;;;;;;iBAM7C,yBAAyB,MAAM,eAAe,KAAK,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAwCrE,sBAAsB,iBAAiB,UAAU,uBAAuB,SAAS,gBAAgB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prisma/orm-extension-middleware-cache",
3
- "version": "8.0.0-rc.18-dev.46",
3
+ "version": "8.0.0-rc.19",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -9,12 +9,12 @@
9
9
  "dist"
10
10
  ],
11
11
  "dependencies": {
12
- "@prisma/orm-framework": "8.0.0-rc.18-dev.46"
12
+ "@prisma/orm-framework": "8.0.0-rc.19"
13
13
  },
14
14
  "devDependencies": {
15
- "@internal/middleware-cache": "8.0.0-rc.18-dev.46",
16
- "@repo/tsconfig": "8.0.0-rc.18-dev.46",
17
- "@repo/tsdown": "8.0.0-rc.18-dev.46",
15
+ "@internal/middleware-cache": "8.0.0-rc.19",
16
+ "@repo/tsconfig": "8.0.0-rc.19",
17
+ "@repo/tsdown": "8.0.0-rc.19",
18
18
  "tsdown": "0.22.14",
19
19
  "typescript": "5.9.3"
20
20
  },