@verikit/ui-core 0.24.1 → 0.24.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -3,3 +3,13 @@
3
3
  Framework-neutral form, layout, and query logic for VeriKit UI bindings.
4
4
 
5
5
  See the [VeriKit documentation](https://verikit.dev) for setup and usage.
6
+
7
+ ## Cache identity
8
+
9
+ Queries, mutations, and optimistic updates are isolated by client. Keep the client
10
+ stable during a session; replace it when the account, tenant, or access identity
11
+ changes. The provider resets descendant state on an identity change.
12
+
13
+ Manual cache access must use `resourceQueryKeys("posts", client)`; keys now include
14
+ the client's namespace. See [cache identity and migration](../client/README.md#cache-identity)
15
+ for explicit namespaces, SSR hydration, and logout handling.
@@ -31,7 +31,7 @@ export function recordId(record) {
31
31
  }
32
32
  return undefined;
33
33
  }
34
- const isListQuery = (query) => query.queryKey[2] === "list";
34
+ const isListQuery = (query) => query.queryKey[3] === "list";
35
35
  /**
36
36
  * Restores only the failed optimistic delete to avoid reviving records
37
37
  * removed by concurrent mutations.
@@ -55,7 +55,7 @@ export function restoreDeletedRecord(queryClient, snapshot, id) {
55
55
  });
56
56
  continue;
57
57
  }
58
- if (queryKey[2] === "find" && queryKey[3] === id) {
58
+ if (queryKey[3] === "find" && queryKey[4] === id) {
59
59
  queryClient.setQueryData(queryKey, previous);
60
60
  }
61
61
  }
@@ -1,12 +1,14 @@
1
- import type { ListParams } from "@verikit/client";
1
+ import type { ListParams, VerikitClient } from "@verikit/client";
2
2
  export interface ResourceQueryKeys {
3
- all: readonly [string, string];
4
- list: (params?: ListParams) => readonly [string, string, "list", ListParams];
5
- find: (id: string) => readonly [string, string, "find", string];
6
- relationship: (relationshipName: string, params?: ListParams) => readonly [string, string, "relationship", string, ListParams];
3
+ all: readonly [string, string, string];
4
+ list: (params?: ListParams) => readonly [string, string, string, "list", ListParams];
5
+ find: (id: string) => readonly [string, string, string, "find", string];
6
+ relationship: (relationshipName: string, params?: ListParams) => readonly [string, string, string, "relationship", string, ListParams];
7
7
  }
8
8
  /**
9
- * Builds the query keys the resource hooks use, so query hooks and mutation hooks' invalidation calls always agree on the same shape. Exported so consumers can invalidate/read the same cache entries themselves (e.g. reacting to a websocket event) without guessing at the internal shape.
9
+ * Builds keys scoped to a client or explicit cache namespace. Pass the same
10
+ * client used by VerikitProvider when reading or invalidating queries manually.
11
+ * A namespace must never be shared across different APIs or access identities.
10
12
  */
11
- export declare function resourceQueryKeys(name: string): ResourceQueryKeys;
13
+ export declare function resourceQueryKeys(name: string, client: VerikitClient | string): ResourceQueryKeys;
12
14
  //# sourceMappingURL=query-keys.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"query-keys.d.ts","sourceRoot":"","sources":["../../src/query/query-keys.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAElD,MAAM,WAAW,iBAAiB;IAChC,GAAG,EAAE,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC/B,IAAI,EAAE,CAAC,MAAM,CAAC,EAAE,UAAU,KAAK,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC;IAC7E,IAAI,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;IAChE,YAAY,EAAE,CACZ,gBAAgB,EAAE,MAAM,EACxB,MAAM,CAAC,EAAE,UAAU,KAChB,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC;CACpE;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,iBAAiB,CASjE"}
1
+ {"version":3,"file":"query-keys.d.ts","sourceRoot":"","sources":["../../src/query/query-keys.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEjE,MAAM,WAAW,iBAAiB;IAChC,GAAG,EAAE,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;IACvC,IAAI,EAAE,CACJ,MAAM,CAAC,EAAE,UAAU,KAChB,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC;IAC3D,IAAI,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;IACxE,YAAY,EAAE,CACZ,gBAAgB,EAAE,MAAM,EACxB,MAAM,CAAC,EAAE,UAAU,KAChB,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC;CAC5E;AAID;;;;GAIG;AACH,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,aAAa,GAAG,MAAM,GAC7B,iBAAiB,CA0BnB"}
@@ -1,11 +1,32 @@
1
+ const clientNamespaces = new WeakMap();
1
2
  /**
2
- * Builds the query keys the resource hooks use, so query hooks and mutation hooks' invalidation calls always agree on the same shape. Exported so consumers can invalidate/read the same cache entries themselves (e.g. reacting to a websocket event) without guessing at the internal shape.
3
+ * Builds keys scoped to a client or explicit cache namespace. Pass the same
4
+ * client used by VerikitProvider when reading or invalidating queries manually.
5
+ * A namespace must never be shared across different APIs or access identities.
3
6
  */
4
- export function resourceQueryKeys(name) {
7
+ export function resourceQueryKeys(name, client) {
8
+ let namespace;
9
+ if (typeof client === "string") {
10
+ namespace = client;
11
+ }
12
+ else {
13
+ namespace =
14
+ client.cacheNamespace ??
15
+ clientNamespaces.get(client) ??
16
+ crypto.randomUUID();
17
+ clientNamespaces.set(client, namespace);
18
+ }
5
19
  return {
6
- all: ["verikit", name],
7
- list: (params = {}) => ["verikit", name, "list", params],
8
- find: (id) => ["verikit", name, "find", id],
9
- relationship: (relationshipName, params = {}) => ["verikit", name, "relationship", relationshipName, params],
20
+ all: ["verikit", namespace, name],
21
+ list: (params = {}) => ["verikit", namespace, name, "list", params],
22
+ find: (id) => ["verikit", namespace, name, "find", id],
23
+ relationship: (relationshipName, params = {}) => [
24
+ "verikit",
25
+ namespace,
26
+ name,
27
+ "relationship",
28
+ relationshipName,
29
+ params,
30
+ ],
10
31
  };
11
32
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@verikit/ui-core",
3
- "version": "0.24.1",
3
+ "version": "0.24.2",
4
4
  "description": "Framework-neutral form, layout, and query logic shared by Verikit UI bindings.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -48,9 +48,9 @@
48
48
  ],
49
49
  "dependencies": {
50
50
  "@tanstack/query-core": "^5.101.4",
51
- "@verikit/client": "0.24.1",
52
- "@verikit/runtime": "0.24.1",
53
- "@verikit/core": "0.24.1"
51
+ "@verikit/core": "0.24.2",
52
+ "@verikit/client": "0.24.2",
53
+ "@verikit/runtime": "0.24.2"
54
54
  },
55
55
  "devDependencies": {
56
56
  "@types/node": "^26.1.1",