@verikit/ui-core 0.24.1 → 0.24.3

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.
@@ -0,0 +1,3 @@
1
+ export { actionLabel, actionNeedsDialog, resourceActionSchemas, unavailableAction, } from "./resource-actions.js";
2
+ export type { ResourceActionScope, ResourceActionSource, } from "./resource-actions.js";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/actions/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,iBAAiB,EACjB,qBAAqB,EACrB,iBAAiB,GAClB,MAAM,uBAAuB,CAAC;AAC/B,YAAY,EACV,mBAAmB,EACnB,oBAAoB,GACrB,MAAM,uBAAuB,CAAC"}
@@ -0,0 +1 @@
1
+ export { actionLabel, actionNeedsDialog, resourceActionSchemas, unavailableAction, } from "./resource-actions.js";
@@ -0,0 +1,19 @@
1
+ import type { ListActionAvailability, UnavailableAction } from "@verikit/client";
2
+ import type { ActionSchemaLike, Resource, ResourceSchema } from "@verikit/core";
3
+ /** Resource builder or schema whose declared actions a UI renders. */
4
+ export type ResourceActionSource = Resource | ResourceSchema;
5
+ /** Where an action renders: per record (row) or once for the collection (toolbar). */
6
+ export type ResourceActionScope = NonNullable<ActionSchemaLike["scope"]>;
7
+ /**
8
+ * Returns the actions declared on a resource via `defineResource({ actions })`, in declaration order, optionally limited to one scope. Actions without an explicit scope count as `"record"`.
9
+ */
10
+ export declare function resourceActionSchemas(source: ResourceActionSource, scope?: ResourceActionScope): ActionSchemaLike[];
11
+ /** True when running an action needs a dialog: a confirmation to accept or form input to collect. */
12
+ export declare function actionNeedsDialog(action: ActionSchemaLike): boolean;
13
+ /** Display label for an action, falling back to its name. */
14
+ export declare function actionLabel(action: ActionSchemaLike): string;
15
+ /**
16
+ * Looks up why an action can't run, from a list's `actions` (requested with `includeActions: true`): pass the record id for a record-scoped action, none for a collection-scoped one. Returns `undefined` when the action can run, or when the list didn't report availability.
17
+ */
18
+ export declare function unavailableAction(availability: ListActionAvailability | undefined, actionName: string, recordId?: string): UnavailableAction | undefined;
19
+ //# sourceMappingURL=resource-actions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resource-actions.d.ts","sourceRoot":"","sources":["../../src/actions/resource-actions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,sBAAsB,EACtB,iBAAiB,EAClB,MAAM,iBAAiB,CAAC;AACzB,OAAO,KAAK,EAAE,gBAAgB,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAEhF,sEAAsE;AACtE,MAAM,MAAM,oBAAoB,GAAG,QAAQ,GAAG,cAAc,CAAC;AAE7D,sFAAsF;AACtF,MAAM,MAAM,mBAAmB,GAAG,WAAW,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,CAAC;AAMzE;;GAEG;AACH,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,oBAAoB,EAC5B,KAAK,CAAC,EAAE,mBAAmB,GAC1B,gBAAgB,EAAE,CAQpB;AAED,qGAAqG;AACrG,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,gBAAgB,GAAG,OAAO,CAKnE;AAED,6DAA6D;AAC7D,wBAAgB,WAAW,CAAC,MAAM,EAAE,gBAAgB,GAAG,MAAM,CAE5D;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAC/B,YAAY,EAAE,sBAAsB,GAAG,SAAS,EAChD,UAAU,EAAE,MAAM,EAClB,QAAQ,CAAC,EAAE,MAAM,GAChB,iBAAiB,GAAG,SAAS,CAQ/B"}
@@ -0,0 +1,34 @@
1
+ function isResource(source) {
2
+ return typeof source.toSchema === "function";
3
+ }
4
+ /**
5
+ * Returns the actions declared on a resource via `defineResource({ actions })`, in declaration order, optionally limited to one scope. Actions without an explicit scope count as `"record"`.
6
+ */
7
+ export function resourceActionSchemas(source, scope) {
8
+ const actions = isResource(source)
9
+ ? source.actions.map((declaration) => declaration.toSchema())
10
+ : Object.values(source.actions ?? {});
11
+ return scope
12
+ ? actions.filter((action) => (action.scope ?? "record") === scope)
13
+ : actions;
14
+ }
15
+ /** True when running an action needs a dialog: a confirmation to accept or form input to collect. */
16
+ export function actionNeedsDialog(action) {
17
+ return (action.confirmation !== undefined ||
18
+ Object.keys(action.form ?? {}).length > 0);
19
+ }
20
+ /** Display label for an action, falling back to its name. */
21
+ export function actionLabel(action) {
22
+ return action.label ?? action.name;
23
+ }
24
+ /**
25
+ * Looks up why an action can't run, from a list's `actions` (requested with `includeActions: true`): pass the record id for a record-scoped action, none for a collection-scoped one. Returns `undefined` when the action can run, or when the list didn't report availability.
26
+ */
27
+ export function unavailableAction(availability, actionName, recordId) {
28
+ if (!availability) {
29
+ return undefined;
30
+ }
31
+ return recordId === undefined
32
+ ? availability.collection[actionName]
33
+ : availability.records[recordId]?.[actionName];
34
+ }
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export * from "./actions/index.js";
1
2
  export * from "./form/index.js";
2
3
  export * from "./layout/index.js";
3
4
  export * from "./query/index.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC"}
package/dist/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ export * from "./actions/index.js";
1
2
  export * from "./form/index.js";
2
3
  export * from "./layout/index.js";
3
4
  export * from "./query/index.js";
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Formats a record's field value as display text: empty for `null`/`undefined`, the locale string for a `Date`, "Yes"/"No" for a boolean, and `String(value)` otherwise.
3
+ */
4
+ export declare function formatFieldValue(value: unknown): string;
5
+ //# sourceMappingURL=format-value.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"format-value.d.ts","sourceRoot":"","sources":["../../src/layout/format-value.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAcvD"}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Formats a record's field value as display text: empty for `null`/`undefined`, the locale string for a `Date`, "Yes"/"No" for a boolean, and `String(value)` otherwise.
3
+ */
4
+ export function formatFieldValue(value) {
5
+ if (value === null || value === undefined) {
6
+ return "";
7
+ }
8
+ if (value instanceof Date) {
9
+ return value.toLocaleString();
10
+ }
11
+ if (typeof value === "boolean") {
12
+ return value ? "Yes" : "No";
13
+ }
14
+ return String(value);
15
+ }
@@ -1,3 +1,4 @@
1
1
  export { getValueAtPath, hasValueAtPath, pathKey, setValueAtPath, unsetValueAtPath, } from "./path.js";
2
2
  export type { SchemaPath } from "./path.js";
3
+ export { formatFieldValue } from "./format-value.js";
3
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/layout/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,cAAc,EACd,OAAO,EACP,cAAc,EACd,gBAAgB,GACjB,MAAM,WAAW,CAAC;AACnB,YAAY,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/layout/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,cAAc,EACd,OAAO,EACP,cAAc,EACd,gBAAgB,GACjB,MAAM,WAAW,CAAC;AACnB,YAAY,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC"}
@@ -1 +1,2 @@
1
1
  export { getValueAtPath, hasValueAtPath, pathKey, setValueAtPath, unsetValueAtPath, } from "./path.js";
2
+ export { formatFieldValue } from "./format-value.js";
@@ -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,16 @@
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
+ /** Kept apart from `find` because its cached data has a different shape. */
7
+ findWithActions: (id: string) => readonly [string, string, string, "findWithActions", string];
8
+ relationship: (relationshipName: string, params?: ListParams) => readonly [string, string, string, "relationship", string, ListParams];
7
9
  }
8
10
  /**
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.
11
+ * Builds keys scoped to a client or explicit cache namespace. Pass the same
12
+ * client used by VerikitProvider when reading or invalidating queries manually.
13
+ * A namespace must never be shared across different APIs or access identities.
10
14
  */
11
- export declare function resourceQueryKeys(name: string): ResourceQueryKeys;
15
+ export declare function resourceQueryKeys(name: string, client: VerikitClient | string): ResourceQueryKeys;
12
16
  //# 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,4EAA4E;IAC5E,eAAe,EAAE,CACf,EAAE,EAAE,MAAM,KACP,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,CAAC,CAAC;IAClE,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,CA4BnB"}
@@ -1,11 +1,33 @@
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
+ findWithActions: (id) => ["verikit", namespace, name, "findWithActions", id],
24
+ relationship: (relationshipName, params = {}) => [
25
+ "verikit",
26
+ namespace,
27
+ name,
28
+ "relationship",
29
+ relationshipName,
30
+ params,
31
+ ],
10
32
  };
11
33
  }
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.3",
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",
@@ -30,6 +30,10 @@
30
30
  "types": "./dist/index.d.ts",
31
31
  "default": "./dist/index.js"
32
32
  },
33
+ "./actions/*": {
34
+ "types": "./dist/actions/*.d.ts",
35
+ "default": "./dist/actions/*.js"
36
+ },
33
37
  "./form/*": {
34
38
  "types": "./dist/form/*.d.ts",
35
39
  "default": "./dist/form/*.js"
@@ -48,9 +52,9 @@
48
52
  ],
49
53
  "dependencies": {
50
54
  "@tanstack/query-core": "^5.101.4",
51
- "@verikit/client": "0.24.1",
52
- "@verikit/runtime": "0.24.1",
53
- "@verikit/core": "0.24.1"
55
+ "@verikit/client": "0.24.3",
56
+ "@verikit/core": "0.24.3",
57
+ "@verikit/runtime": "0.24.3"
54
58
  },
55
59
  "devDependencies": {
56
60
  "@types/node": "^26.1.1",