@ai-matrx/records-ui 0.115.104 → 0.115.105

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 CHANGED
@@ -1,9 +1,13 @@
1
1
  # Changelog — @ai-matrx/records-ui
2
2
 
3
- ## 0.115.104
3
+ ### Unreleased
4
+
5
+ - **New subpath `@ai-matrx/records-ui/data-source`:** `recordsDataSource`, `personActor` and the who-changed words (`whenWords`, `actorWords`, `actorBadge`, `lastChangeSentence`, `SOMEBODY`, `THE_SYSTEM`) alone. `/helpers` also carries the field-type words, the colour resolver and the table builders, which read `@ai-matrx/records/core`; this entry reaches `@ai-matrx/kit` only, and shares the one data-source cache with `/helpers` and the root. Additive. Consumer action: a shell-reachable service that only binds its supabase client or says when imports from `/data-source`.
6
+
7
+ ## 0.115.105
8
+ ### Unreleased
4
9
 
5
- UNVERIFIED: this release has no Unreleased entry and the source comparison could not be made (the caller supplied no source comparison). Whether source changed is unknown; consumer action is unknown.
6
- Check the package's gitHead on npm against this version's gitHead: `git diff <previous gitHead> <this gitHead> -- apps/shared/records-ui/src`.
10
+ - Page-load markers: `performance.mark("load:<kind>:<name>")` at module top level / first mount — Records grid. Native API, no import and no build edge; the host's page-load trace (ai-matrx `lib/diagnostics/loadTrace.ts`) prints them and `pnpm check:smoke` fails a heavy one that evaluates before the person engages. Consumer action: none.
7
11
 
8
12
  ## 0.115.103
9
13
  ### Unreleased
@@ -0,0 +1,122 @@
1
+ 'use strict';
2
+
3
+ var globalSlot = require('@ai-matrx/kit/global-slot');
4
+ var format = require('@ai-matrx/kit/format');
5
+ var textCase = require('@ai-matrx/kit/text-case');
6
+
7
+ // src/dataSource.ts
8
+ function personActor(userId) {
9
+ return userId ? { actor: "user", user_id: userId } : { actor: "user" };
10
+ }
11
+ var dataSources = globalSlot.globalSlot("ai-matrx.records-ui.data-sources", () => /* @__PURE__ */ new WeakMap());
12
+ function recordsDataSource(client, fallbackSchema = "custom") {
13
+ let bySchema = dataSources.get(client);
14
+ if (!bySchema) {
15
+ bySchema = /* @__PURE__ */ new Map();
16
+ dataSources.set(client, bySchema);
17
+ }
18
+ const held = bySchema.get(fallbackSchema);
19
+ if (held) return held;
20
+ const made = makeRecordsDataSource(client, fallbackSchema);
21
+ bySchema.set(fallbackSchema, made);
22
+ return made;
23
+ }
24
+ function makeRecordsDataSource(client, fallbackSchema) {
25
+ const supabase = client;
26
+ return {
27
+ // PAGE-BUNDLE: the real adapter opens a table page with one `custom.table_page_bundle` call.
28
+ opensInOneCall: true,
29
+ async rpc(fn, args, options) {
30
+ const schema = options?.schema ?? fallbackSchema;
31
+ if (schema === "custom" && supabase.auth?.getSession && !await hasSession(supabase.auth.getSession)) {
32
+ return { data: null, error: SIGNED_OUT };
33
+ }
34
+ const on = supabase.schema(schema);
35
+ return await on.rpc(fn, args);
36
+ },
37
+ schema(name) {
38
+ return supabase.schema(name);
39
+ }
40
+ };
41
+ }
42
+ var SIGNED_OUT = {
43
+ code: "42501",
44
+ message: "Nobody is signed in, so there is nothing to read.",
45
+ hint: "Sign in, then try again.",
46
+ details: null
47
+ };
48
+ async function hasSession(getSession) {
49
+ try {
50
+ const answer = await getSession();
51
+ return Boolean(answer?.data?.session);
52
+ } catch {
53
+ return true;
54
+ }
55
+ }
56
+ var SOMEBODY = "somebody in this organization";
57
+ var THE_SYSTEM = "the system";
58
+ function actorWords(actor, resolve) {
59
+ if (actor.kind === "system") return THE_SYSTEM;
60
+ const named = actor.name?.trim() || (actor.user_id && resolve ? resolve(actor.user_id)?.trim() : null) || null;
61
+ if (actor.kind === "agent") {
62
+ const on = actor.on_behalf_of;
63
+ const person = on?.name?.trim() || (on?.user_id && resolve ? resolve(on.user_id)?.trim() : null) || SOMEBODY;
64
+ const approver = actor.approved_by ? actor.approved_by.name?.trim() || (resolve ? resolve(actor.approved_by.user_id)?.trim() : null) || SOMEBODY : null;
65
+ return `${named ?? "an assistant"}, for ${person}${approver ? `, approved by ${approver}` : ""}`;
66
+ }
67
+ return named ?? SOMEBODY;
68
+ }
69
+ function whenWords(at, now = /* @__PURE__ */ new Date()) {
70
+ const then = new Date(at);
71
+ const age = now.getTime() - then.getTime();
72
+ if (!Number.isFinite(age)) return "at an unknown time";
73
+ if (age < 30 * 864e5) return format.formatRelativeTime(then, { style: "intl", now: now.getTime() });
74
+ return then.toLocaleDateString();
75
+ }
76
+ var OPERATION_WORDS = {
77
+ created: "Created",
78
+ edited: "Edited",
79
+ deleted: "Archived",
80
+ archived: "Archived",
81
+ restored: "Restored",
82
+ retype: "Column type changed",
83
+ delete: "Removed",
84
+ soft_delete: "Archived",
85
+ insert: "Created",
86
+ update: "Edited",
87
+ restore: "Restored"
88
+ };
89
+ function operationWords(label) {
90
+ const raw = (label ?? "").trim();
91
+ if (raw === "") return "Changed";
92
+ const known = OPERATION_WORDS[raw.toLowerCase()];
93
+ if (known) return known;
94
+ const words = textCase.humanizeIdentifier(raw).toLowerCase();
95
+ return words.charAt(0).toUpperCase() + words.slice(1);
96
+ }
97
+ function lastChangeSentence(fieldLabel, entry, resolve) {
98
+ if (!entry) {
99
+ return `Nothing is recorded against ${fieldLabel} on this record yet. Press H for the whole history of this column.`;
100
+ }
101
+ const verb = operationWords(entry.operation_label).toLowerCase();
102
+ return `${fieldLabel} \u2014 ${verb} by ${actorWords(entry.actor, resolve)}, ${whenWords(entry.occurred_at)}. Press H for the whole history.`;
103
+ }
104
+ function actorBadge(actor, resolve) {
105
+ if (actor.kind === "system") return THE_SYSTEM;
106
+ const words = actorWords(actor, resolve);
107
+ if (words === SOMEBODY) return "somebody";
108
+ const first = words.split(",")[0].trim();
109
+ const at = first.indexOf("@");
110
+ return at > 0 ? first.slice(0, at) : first;
111
+ }
112
+
113
+ exports.SOMEBODY = SOMEBODY;
114
+ exports.THE_SYSTEM = THE_SYSTEM;
115
+ exports.actorBadge = actorBadge;
116
+ exports.actorWords = actorWords;
117
+ exports.lastChangeSentence = lastChangeSentence;
118
+ exports.personActor = personActor;
119
+ exports.recordsDataSource = recordsDataSource;
120
+ exports.whenWords = whenWords;
121
+ //# sourceMappingURL=data-source.cjs.map
122
+ //# sourceMappingURL=data-source.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/dataSource.ts","../src/whoChanged.ts"],"names":["globalSlot","formatRelativeTime","humanizeIdentifier"],"mappings":";;;;;;;AAUO,SAAS,YAAY,MAAA,EAA+C;AACzE,EAAA,OAAO,MAAA,GAAS,EAAE,KAAA,EAAO,MAAA,EAAQ,SAAS,MAAA,EAAO,GAAI,EAAE,KAAA,EAAO,MAAA,EAAO;AACvE;AA4CA,IAAM,cAAcA,qBAAA,CAAW,kCAAA,EAAoC,sBAAM,IAAI,SAAiD,CAAA;AAEvH,SAAS,iBAAA,CAAkB,MAAA,EAAgB,cAAA,GAAiB,QAAA,EAA6B;AAC9F,EAAA,IAAI,QAAA,GAAW,WAAA,CAAY,GAAA,CAAI,MAAM,CAAA;AACrC,EAAA,IAAI,CAAC,QAAA,EAAU;AACb,IAAA,QAAA,uBAAe,GAAA,EAAI;AACnB,IAAA,WAAA,CAAY,GAAA,CAAI,QAAQ,QAAQ,CAAA;AAAA,EAClC;AACA,EAAA,MAAM,IAAA,GAAO,QAAA,CAAS,GAAA,CAAI,cAAc,CAAA;AACxC,EAAA,IAAI,MAAM,OAAO,IAAA;AACjB,EAAA,MAAM,IAAA,GAAO,qBAAA,CAAsB,MAAA,EAAQ,cAAc,CAAA;AACzD,EAAA,QAAA,CAAS,GAAA,CAAI,gBAAgB,IAAI,CAAA;AACjC,EAAA,OAAO,IAAA;AACT;AAEA,SAAS,qBAAA,CAAsB,QAAgB,cAAA,EAA2C;AACxF,EAAA,MAAM,QAAA,GAAW,MAAA;AAQjB,EAAA,OAAO;AAAA;AAAA,IAEL,cAAA,EAAgB,IAAA;AAAA,IAChB,MAAM,GAAA,CAAI,EAAA,EAAI,IAAA,EAAM,OAAA,EAAS;AAC3B,MAAA,MAAM,MAAA,GAAS,SAAS,MAA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AM,IAAA,KAAS,QAAA,EAAU,OAAO,UAAA;AACpC,EAAA,MAAM,KAAA,GAAQ,UAAA,CAAW,KAAA,EAAO,OAAO,CAAA;AACvC,EAAA,IAAI,KAAA,KAAU,UAAU,OAAO,UAAA;AAC/B,EAAA,MAAM,QAAQ,KAAA,CAAM,KAAA,CAAM,GAAG,CAAA,CAAE,CAAC,EAAG,IAAA,EAAK;AACxC,EAAA,MAAM,EAAA,GAAK,KAAA,CAAM,OAAA,CAAQ,GAAG,CAAA;AAC5B,EAAA,OAAO,KAAK,CAAA,GAAI,KAAA,CAAM,KAAA,CAAM,CAAA,EAAG,EAAE,CAAA,GAAI,KAAA;AACvC","file":"data-source.cjs","sourcesContent":["// src/dataSource.ts — @ai-matrx/records-ui (pure; also served alone by `@ai-matrx/records-ui/helpers`)\n//\n// The two helpers every host calls before it draws anything: who is acting (`personActor`) and the\n// store's data seam over a supabase-js client (`recordsDataSource`). No React and no screen here, so\n// a service, a registry or a server module that needs only these never pulls the package's screens.\n// `RecordsMount` re-exports both, so the root entry keeps them.\n\nimport type { RecordsActor, RecordsDataSource, Uuid } from \"@ai-matrx/records\";\nimport { globalSlot } from \"@ai-matrx/kit/global-slot\";\n\nexport function personActor(userId: Uuid | null | undefined): RecordsActor {\n return userId ? { actor: \"user\", user_id: userId } : { actor: \"user\" };\n}\n\n/**\n * A supabase-js client AS this package's data seam.\n *\n * `RecordsDataSource` is deliberately a small structural subset of\n * `SupabaseClient` — the package holds no key and opens no connection, the host\n * hands it a client that already carries the person's session.\n *\n * IT IS NOT AN IDENTITY CAST, and it cost a live screen to learn why\n * (2026-09-19, /data's first load): the port's `rpc(fn, args, { schema })`\n * says the schema OUT LOUD, because every door of this store is `custom.<name>`\n * and every door of the trust layer is `iam.<name>`. supabase-js's own\n * `rpc(fn, args, options)` has no `schema` option at all — its third argument is\n * `{ head, get, count }` — so a client passed straight through silently asked\n * its default PostgREST profile and the store answered, correctly and uselessly,\n * \"Could not find the function public.table_kernel_id ... PGRST202\". The schema\n * is chosen the one way supabase-js offers: `client.schema(name).rpc(...)`.\n *\n * `schema(name).from(table)` already agrees structurally and is passed through.\n *\n * `fallbackSchema` is the profile a call that says NOTHING is sent to. No caller\n * in `@ai-matrx/records` omits the option — `callDoor` always says `custom` and\n * `trustDoor` always says `iam` — so it never fires today; it exists so that a\n * call which one day forgets lands on the store rather than silently on\n * `public`. It is a FALLBACK and not the answer: a version of this adapter that\n * sent EVERY door to one fixed schema would route the `iam` trust doors (the\n * external principal, the publish binding) into `custom` and get a PGRST202\n * naming the wrong schema.\n *\n * The cast itself stays HERE, once, where it is explained: a generated\n * `Database` type makes `schema().from().select()` enormous, and a host app that\n * passes its client straight into `config` gets `TS2589: Type instantiation is\n * excessively deep and possibly infinite` in its own build (matrx-frontend,\n * 2026-09-18, on all three campaign routes at once).\n */\n/*\n * ONE DATA SOURCE PER SUPABASE CLIENT (owner, 2026-10-02). The record store's data layer keys its\n * cache by the data source object, so a host that builds this adapter again on every mount (a\n * board tile woken or brought back by Undo) must get the SAME object back for the same client —\n * otherwise every remount is a stranger to the answers the last mount read.\n */\n// One cache per realm, never per bundle copy: this module ships in BOTH the root entry and\n// `@ai-matrx/records-ui/helpers` (`splitting: false`), and a module `let` would split it in two.\nconst dataSources = globalSlot(\"ai-matrx.records-ui.data-sources\", () => new WeakMap<object, Map<string, RecordsDataSource>>());\n\nexport function recordsDataSource(client: object, fallbackSchema = \"custom\"): RecordsDataSource {\n let bySchema = dataSources.get(client);\n if (!bySchema) {\n bySchema = new Map();\n dataSources.set(client, bySchema);\n }\n const held = bySchema.get(fallbackSchema);\n if (held) return held;\n const made = makeRecordsDataSource(client, fallbackSchema);\n bySchema.set(fallbackSchema, made);\n return made;\n}\n\nfunction makeRecordsDataSource(client: object, fallbackSchema: string): RecordsDataSource {\n const supabase = client as unknown as {\n rpc: (fn: string, args: Record<string, unknown>) => PromiseLike<unknown>;\n schema: (name: string) => {\n rpc: (fn: string, args: Record<string, unknown>) => PromiseLike<unknown>;\n from: (table: string) => unknown;\n };\n auth?: { getSession?: () => Promise<{ data?: { session?: unknown } | null }> };\n };\n return {\n // PAGE-BUNDLE: the real adapter opens a table page with one `custom.table_page_bundle` call.\n opensInOneCall: true,\n async rpc(fn, args, options) {\n const schema = options?.schema ?? fallbackSchema;\n // 🚨 NO STORE DOOR LEAVES WITHOUT A PERSON (lane MONITOR-TRIAGE, 2026-10-01). `anon` holds\n // no USAGE on schema `custom`, so a door called with no session can only come back\n // \"42501 permission denied for schema custom\" (HTTP 401) — seven of them per signed-out\n // /data load (inbox, counts, home, portals…), every one a red row in ops.system_error.\n // A `custom` door with no session is answered HERE, with the store's own signed-out\n // sentence and no network call. Other schemas (`iam`, `platform`) serve guests by design\n // and are never short-circuited. A client without `auth` (a server or test seam) is\n // passed straight through.\n if (schema === \"custom\" && supabase.auth?.getSession && !(await hasSession(supabase.auth.getSession))) {\n return { data: null, error: SIGNED_OUT } as Awaited<ReturnType<RecordsDataSource[\"rpc\"]>>;\n }\n const on = supabase.schema(schema);\n return (await on.rpc(fn, args)) as Awaited<ReturnType<RecordsDataSource[\"rpc\"]>>;\n },\n schema(name) {\n return supabase.schema(name) as ReturnType<RecordsDataSource[\"schema\"]>;\n },\n };\n}\n\n/** The read door's own sentence for a call with nobody signed in (`custom.read_records_page`, DOOR-1). */\nconst SIGNED_OUT = {\n code: \"42501\",\n message: \"Nobody is signed in, so there is nothing to read.\",\n hint: \"Sign in, then try again.\",\n details: null,\n} as const;\n\nasync function hasSession(getSession: () => Promise<{ data?: { session?: unknown } | null }>): Promise<boolean> {\n try {\n const answer = await getSession();\n return Boolean(answer?.data?.session);\n } catch {\n // Auth could not say: let the request go and the database's answer stand.\n return true;\n }\n}\n","import { formatRelativeTime } from \"@ai-matrx/kit/format\";\nimport { humanizeIdentifier } from \"@ai-matrx/kit/text-case\";\n// src/whoChanged.ts — @ai-matrx/records-ui · SCR-17, the cell's half\n//\n// \"WHO?\" IS A QUESTION. A SCREEN IS SUPPOSED TO ANSWER IT.\n//\n// 🚨 WHAT A CLINIC SAW (crew B2, 2026-09-21, ten real patients on the live app):\n//\n// \"Every single cell shows a small 'who?' hover badge next to its value instead\n// of a resolved author name, an agent/rule label, or even 'system' — the\n// attribution feature is visibly wired up (it renders on every cell) but never\n// resolves to anything readable.\"\n//\n// They were right that it never resolved, and the reason was that nothing ever\n// asked. The badge opened a panel; it never looked anything up. Meanwhile the\n// store had the answer the whole time: `custom.field_history` on those exact ten\n// patients answers `kind: user, name: admin` on every one of them, and has since\n// they were written.\n//\n// So the badge asks, on the gesture that already reaches it — a hover or a Tab —\n// for the ONE cell being asked about. Nothing is fetched for a page of two\n// hundred cells nobody points at.\n//\n// THE THREE WORDS, AND NEVER A UUID. VAL-8 fixes the vocabulary at `user`,\n// `agent`, `system` and there is no fourth. An agent ALWAYS names the person it\n// acted for (AGT-N-4: it carries exactly that person's authority, so a screen\n// showing the machine without the person would be hiding who is answerable). The\n// system is \"the system\" — a platform word a person can read, not a null. And a\n// person whose name the door did not carry is resolved through the app's ONE\n// organization-scoped roster (the `members` port, FIX-7B's rule: the people of\n// THIS organization and nobody else). If even that cannot name them, the sentence\n// says so in words. It never prints an id: SCR-N-5 forbids showing one to a\n// person, and \"87a6e699…\" answers nobody's question anyway.\n\nimport type { FieldHistoryEntry, HistoryActor, Uuid } from \"@ai-matrx/records\";\n\n/** What the roster can tell us about a user id. `null` when it cannot. */\nexport type ResolveName = (userId: Uuid) => string | null;\n\n/** The honest stand-in when nobody and nothing can put a name to the author. */\nexport const SOMEBODY = \"somebody in this organization\";\n\n/** The platform's own word for itself. Never \"null\", never \"system_user\". */\nexport const THE_SYSTEM = \"the system\";\n\n/**\n * WHO, in the words a person reads. One place, so the grid cell, the record\n * timeline and the column history cannot drift into three different answers.\n */\nexport function actorWords(actor: HistoryActor, resolve?: ResolveName | undefined): string {\n if (actor.kind === \"system\") return THE_SYSTEM;\n const named = actor.name?.trim() || (actor.user_id && resolve ? resolve(actor.user_id)?.trim() : null) || null;\n if (actor.kind === \"agent\") {\n // An agent without the person it acted for cannot happen at the door — the\n // store refuses that write — but a screen still says something true if it does.\n const on = actor.on_behalf_of;\n const person = on?.name?.trim() || (on?.user_id && resolve ? resolve(on.user_id)?.trim() : null) || SOMEBODY;\n const approver = actor.approved_by\n ? actor.approved_by.name?.trim() || (resolve ? resolve(actor.approved_by.user_id)?.trim() : null) || SOMEBODY\n : null;\n return `${named ?? \"an assistant\"}, for ${person}${approver ? `, approved by ${approver}` : \"\"}`;\n }\n return named ?? SOMEBODY;\n}\n\n/** How long ago, in the words a person uses out loud. */\nexport function whenWords(at: string, now: Date = new Date()): string {\n const then = new Date(at);\n const age = now.getTime() - then.getTime();\n if (!Number.isFinite(age)) return \"at an unknown time\";\n if (age < 30 * 86_400_000) return formatRelativeTime(then, { style: \"intl\", now: now.getTime() });\n return then.toLocaleDateString();\n}\n\n/**\n * THE WHOLE ANSWER, as one sentence, ending in what to do to see the rest.\n * `null` is a real state and gets its own sentence: this column has never been\n * changed on this record since the store started keeping versions, which is not\n * the same as \"we could not find out\".\n */\n/**\n * WHAT HAPPENED, IN A PERSON'S WORDS (BREAKER-2 B2-29). The store words four operations and\n * lowercases any other (`RETYPE` → \"retype\"), so the panel read \"retype · admin · part of a bigger\n * change\". Every word the store can send is worded here; an unknown one is still written the way\n * a person writes it, never as a token. A soft delete is an archive, and says so.\n */\nconst OPERATION_WORDS: Record<string, string> = {\n created: \"Created\",\n edited: \"Edited\",\n deleted: \"Archived\",\n archived: \"Archived\",\n restored: \"Restored\",\n retype: \"Column type changed\",\n delete: \"Removed\",\n soft_delete: \"Archived\",\n insert: \"Created\",\n update: \"Edited\",\n restore: \"Restored\",\n};\n\nexport function operationWords(label: string | null | undefined): string {\n const raw = (label ?? \"\").trim();\n if (raw === \"\") return \"Changed\";\n const known = OPERATION_WORDS[raw.toLowerCase()];\n if (known) return known;\n const words = humanizeIdentifier(raw).toLowerCase();\n return words.charAt(0).toUpperCase() + words.slice(1);\n}\n\nexport function lastChangeSentence(\n fieldLabel: string,\n entry: FieldHistoryEntry | null,\n resolve?: ResolveName | undefined,\n): string {\n if (!entry) {\n return `Nothing is recorded against ${fieldLabel} on this record yet. Press H for the whole history of this column.`;\n }\n const verb = operationWords(entry.operation_label).toLowerCase();\n return `${fieldLabel} — ${verb} by ${actorWords(entry.actor, resolve)}, ${whenWords(entry.occurred_at)}. Press H for the whole history.`;\n}\n\n/**\n * The SHORT form the badge wears once it knows: a name a person recognises at a\n * glance, in the width of a cell corner. Never a uuid, never an email's domain.\n */\nexport function actorBadge(actor: HistoryActor, resolve?: ResolveName | undefined): string {\n if (actor.kind === \"system\") return THE_SYSTEM;\n const words = actorWords(actor, resolve);\n if (words === SOMEBODY) return \"somebody\";\n const first = words.split(\",\")[0]!.trim();\n const at = first.indexOf(\"@\");\n return at > 0 ? first.slice(0, at) : first;\n}\n"]}
@@ -0,0 +1,26 @@
1
+ import { Uuid, RecordsActor, RecordsDataSource, HistoryActor, FieldHistoryEntry } from '@ai-matrx/records';
2
+
3
+ declare function personActor(userId: Uuid | null | undefined): RecordsActor;
4
+ declare function recordsDataSource(client: object, fallbackSchema?: string): RecordsDataSource;
5
+
6
+ /** What the roster can tell us about a user id. `null` when it cannot. */
7
+ type ResolveName = (userId: Uuid) => string | null;
8
+ /** The honest stand-in when nobody and nothing can put a name to the author. */
9
+ declare const SOMEBODY = "somebody in this organization";
10
+ /** The platform's own word for itself. Never "null", never "system_user". */
11
+ declare const THE_SYSTEM = "the system";
12
+ /**
13
+ * WHO, in the words a person reads. One place, so the grid cell, the record
14
+ * timeline and the column history cannot drift into three different answers.
15
+ */
16
+ declare function actorWords(actor: HistoryActor, resolve?: ResolveName | undefined): string;
17
+ /** How long ago, in the words a person uses out loud. */
18
+ declare function whenWords(at: string, now?: Date): string;
19
+ declare function lastChangeSentence(fieldLabel: string, entry: FieldHistoryEntry | null, resolve?: ResolveName | undefined): string;
20
+ /**
21
+ * The SHORT form the badge wears once it knows: a name a person recognises at a
22
+ * glance, in the width of a cell corner. Never a uuid, never an email's domain.
23
+ */
24
+ declare function actorBadge(actor: HistoryActor, resolve?: ResolveName | undefined): string;
25
+
26
+ export { type ResolveName, SOMEBODY, THE_SYSTEM, actorBadge, actorWords, lastChangeSentence, personActor, recordsDataSource, whenWords };
@@ -0,0 +1,26 @@
1
+ import { Uuid, RecordsActor, RecordsDataSource, HistoryActor, FieldHistoryEntry } from '@ai-matrx/records';
2
+
3
+ declare function personActor(userId: Uuid | null | undefined): RecordsActor;
4
+ declare function recordsDataSource(client: object, fallbackSchema?: string): RecordsDataSource;
5
+
6
+ /** What the roster can tell us about a user id. `null` when it cannot. */
7
+ type ResolveName = (userId: Uuid) => string | null;
8
+ /** The honest stand-in when nobody and nothing can put a name to the author. */
9
+ declare const SOMEBODY = "somebody in this organization";
10
+ /** The platform's own word for itself. Never "null", never "system_user". */
11
+ declare const THE_SYSTEM = "the system";
12
+ /**
13
+ * WHO, in the words a person reads. One place, so the grid cell, the record
14
+ * timeline and the column history cannot drift into three different answers.
15
+ */
16
+ declare function actorWords(actor: HistoryActor, resolve?: ResolveName | undefined): string;
17
+ /** How long ago, in the words a person uses out loud. */
18
+ declare function whenWords(at: string, now?: Date): string;
19
+ declare function lastChangeSentence(fieldLabel: string, entry: FieldHistoryEntry | null, resolve?: ResolveName | undefined): string;
20
+ /**
21
+ * The SHORT form the badge wears once it knows: a name a person recognises at a
22
+ * glance, in the width of a cell corner. Never a uuid, never an email's domain.
23
+ */
24
+ declare function actorBadge(actor: HistoryActor, resolve?: ResolveName | undefined): string;
25
+
26
+ export { type ResolveName, SOMEBODY, THE_SYSTEM, actorBadge, actorWords, lastChangeSentence, personActor, recordsDataSource, whenWords };
@@ -0,0 +1,113 @@
1
+ import { globalSlot } from '@ai-matrx/kit/global-slot';
2
+ import { formatRelativeTime } from '@ai-matrx/kit/format';
3
+ import { humanizeIdentifier } from '@ai-matrx/kit/text-case';
4
+
5
+ // src/dataSource.ts
6
+ function personActor(userId) {
7
+ return userId ? { actor: "user", user_id: userId } : { actor: "user" };
8
+ }
9
+ var dataSources = globalSlot("ai-matrx.records-ui.data-sources", () => /* @__PURE__ */ new WeakMap());
10
+ function recordsDataSource(client, fallbackSchema = "custom") {
11
+ let bySchema = dataSources.get(client);
12
+ if (!bySchema) {
13
+ bySchema = /* @__PURE__ */ new Map();
14
+ dataSources.set(client, bySchema);
15
+ }
16
+ const held = bySchema.get(fallbackSchema);
17
+ if (held) return held;
18
+ const made = makeRecordsDataSource(client, fallbackSchema);
19
+ bySchema.set(fallbackSchema, made);
20
+ return made;
21
+ }
22
+ function makeRecordsDataSource(client, fallbackSchema) {
23
+ const supabase = client;
24
+ return {
25
+ // PAGE-BUNDLE: the real adapter opens a table page with one `custom.table_page_bundle` call.
26
+ opensInOneCall: true,
27
+ async rpc(fn, args, options) {
28
+ const schema = options?.schema ?? fallbackSchema;
29
+ if (schema === "custom" && supabase.auth?.getSession && !await hasSession(supabase.auth.getSession)) {
30
+ return { data: null, error: SIGNED_OUT };
31
+ }
32
+ const on = supabase.schema(schema);
33
+ return await on.rpc(fn, args);
34
+ },
35
+ schema(name) {
36
+ return supabase.schema(name);
37
+ }
38
+ };
39
+ }
40
+ var SIGNED_OUT = {
41
+ code: "42501",
42
+ message: "Nobody is signed in, so there is nothing to read.",
43
+ hint: "Sign in, then try again.",
44
+ details: null
45
+ };
46
+ async function hasSession(getSession) {
47
+ try {
48
+ const answer = await getSession();
49
+ return Boolean(answer?.data?.session);
50
+ } catch {
51
+ return true;
52
+ }
53
+ }
54
+ var SOMEBODY = "somebody in this organization";
55
+ var THE_SYSTEM = "the system";
56
+ function actorWords(actor, resolve) {
57
+ if (actor.kind === "system") return THE_SYSTEM;
58
+ const named = actor.name?.trim() || (actor.user_id && resolve ? resolve(actor.user_id)?.trim() : null) || null;
59
+ if (actor.kind === "agent") {
60
+ const on = actor.on_behalf_of;
61
+ const person = on?.name?.trim() || (on?.user_id && resolve ? resolve(on.user_id)?.trim() : null) || SOMEBODY;
62
+ const approver = actor.approved_by ? actor.approved_by.name?.trim() || (resolve ? resolve(actor.approved_by.user_id)?.trim() : null) || SOMEBODY : null;
63
+ return `${named ?? "an assistant"}, for ${person}${approver ? `, approved by ${approver}` : ""}`;
64
+ }
65
+ return named ?? SOMEBODY;
66
+ }
67
+ function whenWords(at, now = /* @__PURE__ */ new Date()) {
68
+ const then = new Date(at);
69
+ const age = now.getTime() - then.getTime();
70
+ if (!Number.isFinite(age)) return "at an unknown time";
71
+ if (age < 30 * 864e5) return formatRelativeTime(then, { style: "intl", now: now.getTime() });
72
+ return then.toLocaleDateString();
73
+ }
74
+ var OPERATION_WORDS = {
75
+ created: "Created",
76
+ edited: "Edited",
77
+ deleted: "Archived",
78
+ archived: "Archived",
79
+ restored: "Restored",
80
+ retype: "Column type changed",
81
+ delete: "Removed",
82
+ soft_delete: "Archived",
83
+ insert: "Created",
84
+ update: "Edited",
85
+ restore: "Restored"
86
+ };
87
+ function operationWords(label) {
88
+ const raw = (label ?? "").trim();
89
+ if (raw === "") return "Changed";
90
+ const known = OPERATION_WORDS[raw.toLowerCase()];
91
+ if (known) return known;
92
+ const words = humanizeIdentifier(raw).toLowerCase();
93
+ return words.charAt(0).toUpperCase() + words.slice(1);
94
+ }
95
+ function lastChangeSentence(fieldLabel, entry, resolve) {
96
+ if (!entry) {
97
+ return `Nothing is recorded against ${fieldLabel} on this record yet. Press H for the whole history of this column.`;
98
+ }
99
+ const verb = operationWords(entry.operation_label).toLowerCase();
100
+ return `${fieldLabel} \u2014 ${verb} by ${actorWords(entry.actor, resolve)}, ${whenWords(entry.occurred_at)}. Press H for the whole history.`;
101
+ }
102
+ function actorBadge(actor, resolve) {
103
+ if (actor.kind === "system") return THE_SYSTEM;
104
+ const words = actorWords(actor, resolve);
105
+ if (words === SOMEBODY) return "somebody";
106
+ const first = words.split(",")[0].trim();
107
+ const at = first.indexOf("@");
108
+ return at > 0 ? first.slice(0, at) : first;
109
+ }
110
+
111
+ export { SOMEBODY, THE_SYSTEM, actorBadge, actorWords, lastChangeSentence, personActor, recordsDataSource, whenWords };
112
+ //# sourceMappingURL=data-source.js.map
113
+ //# sourceMappingURL=data-source.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/dataSource.ts","../src/whoChanged.ts"],"names":[],"mappings":";;;;;AAUO,SAAS,YAAY,MAAA,EAA+C;AACzE,EAAA,OAAO,MAAA,GAAS,EAAE,KAAA,EAAO,MAAA,EAAQ,SAAS,MAAA,EAAO,GAAI,EAAE,KAAA,EAAO,MAAA,EAAO;AACvE;AA4CA,IAAM,cAAc,UAAA,CAAW,kCAAA,EAAoC,sBAAM,IAAI,SAAiD,CAAA;AAEvH,SAAS,iBAAA,CAAkB,MAAA,EAAgB,cAAA,GAAiB,QAAA,EAA6B;AAC9F,EAAA,IAAI,QAAA,GAAW,WAAA,CAAY,GAAA,CAAI,MAAM,CAAA;AACrC,EAAA,IAAI,CAAC,QAAA,EAAU;AACb,IAAA,QAAA,uBAAe,GAAA,EAAI;AACnB,IAAA,WAAA,CAAY,GAAA,CAAI,QAAQ,QAAQ,CAAA;AAAA,EAClC;AACA,EAAA,MAAM,IAAA,GAAO,QAAA,CAAS,GAAA,CAAI,cAAc,CAAA;AACxC,EAAA,IAAI,MAAM,OAAO,IAAA;AACjB,EAAA,MAAM,IAAA,GAAO,qBAAA,CAAsB,MAAA,EAAQ,cAAc,CAAA;AACzD,EAAA,QAAA,CAAS,GAAA,CAAI,gBAAgB,IAAI,CAAA;AACjC,EAAA,OAAO,IAAA;AACT;AAEA,SAAS,qBAAA,CAAsB,QAAgB,cAAA,EAA2C;AACxF,EAAA,MAAM,QAAA,GAAW,MAAA;AAQjB,EAAA,OAAO;AAAA;AAAA,IAEL,cAAA,EAAgB,IAAA;AAAA,IAChB,MAAM,GAAA,CAAI,EAAA,EAAI,IAAA,EAAM,OAAA,EAAS;AAC3B,MAAA,MAAM,MAAA,GAAS,SAAS,MAAA,IAAU,cAAA;AASlC,MAAA,IAAI,MAAA,KAAW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,EAAA,MAAM,KAAA,GAAQ,UAAA,CAAW,KAAA,EAAO,OAAO,CAAA;AACvC,EAAA,IAAI,KAAA,KAAU,UAAU,OAAO,UAAA;AAC/B,EAAA,MAAM,QAAQ,KAAA,CAAM,KAAA,CAAM,GAAG,CAAA,CAAE,CAAC,EAAG,IAAA,EAAK;AACxC,EAAA,MAAM,EAAA,GAAK,KAAA,CAAM,OAAA,CAAQ,GAAG,CAAA;AAC5B,EAAA,OAAO,KAAK,CAAA,GAAI,KAAA,CAAM,KAAA,CAAM,CAAA,EAAG,EAAE,CAAA,GAAI,KAAA;AACvC","file":"data-source.js","sourcesContent":["// src/dataSource.ts — @ai-matrx/records-ui (pure; also served alone by `@ai-matrx/records-ui/helpers`)\n//\n// The two helpers every host calls before it draws anything: who is acting (`personActor`) and the\n// store's data seam over a supabase-js client (`recordsDataSource`). No React and no screen here, so\n// a service, a registry or a server module that needs only these never pulls the package's screens.\n// `RecordsMount` re-exports both, so the root entry keeps them.\n\nimport type { RecordsActor, RecordsDataSource, Uuid } from \"@ai-matrx/records\";\nimport { globalSlot } from \"@ai-matrx/kit/global-slot\";\n\nexport function personActor(userId: Uuid | null | undefined): RecordsActor {\n return userId ? { actor: \"user\", user_id: userId } : { actor: \"user\" };\n}\n\n/**\n * A supabase-js client AS this package's data seam.\n *\n * `RecordsDataSource` is deliberately a small structural subset of\n * `SupabaseClient` — the package holds no key and opens no connection, the host\n * hands it a client that already carries the person's session.\n *\n * IT IS NOT AN IDENTITY CAST, and it cost a live screen to learn why\n * (2026-09-19, /data's first load): the port's `rpc(fn, args, { schema })`\n * says the schema OUT LOUD, because every door of this store is `custom.<name>`\n * and every door of the trust layer is `iam.<name>`. supabase-js's own\n * `rpc(fn, args, options)` has no `schema` option at all — its third argument is\n * `{ head, get, count }` — so a client passed straight through silently asked\n * its default PostgREST profile and the store answered, correctly and uselessly,\n * \"Could not find the function public.table_kernel_id ... PGRST202\". The schema\n * is chosen the one way supabase-js offers: `client.schema(name).rpc(...)`.\n *\n * `schema(name).from(table)` already agrees structurally and is passed through.\n *\n * `fallbackSchema` is the profile a call that says NOTHING is sent to. No caller\n * in `@ai-matrx/records` omits the option — `callDoor` always says `custom` and\n * `trustDoor` always says `iam` — so it never fires today; it exists so that a\n * call which one day forgets lands on the store rather than silently on\n * `public`. It is a FALLBACK and not the answer: a version of this adapter that\n * sent EVERY door to one fixed schema would route the `iam` trust doors (the\n * external principal, the publish binding) into `custom` and get a PGRST202\n * naming the wrong schema.\n *\n * The cast itself stays HERE, once, where it is explained: a generated\n * `Database` type makes `schema().from().select()` enormous, and a host app that\n * passes its client straight into `config` gets `TS2589: Type instantiation is\n * excessively deep and possibly infinite` in its own build (matrx-frontend,\n * 2026-09-18, on all three campaign routes at once).\n */\n/*\n * ONE DATA SOURCE PER SUPABASE CLIENT (owner, 2026-10-02). The record store's data layer keys its\n * cache by the data source object, so a host that builds this adapter again on every mount (a\n * board tile woken or brought back by Undo) must get the SAME object back for the same client —\n * otherwise every remount is a stranger to the answers the last mount read.\n */\n// One cache per realm, never per bundle copy: this module ships in BOTH the root entry and\n// `@ai-matrx/records-ui/helpers` (`splitting: false`), and a module `let` would split it in two.\nconst dataSources = globalSlot(\"ai-matrx.records-ui.data-sources\", () => new WeakMap<object, Map<string, RecordsDataSource>>());\n\nexport function recordsDataSource(client: object, fallbackSchema = \"custom\"): RecordsDataSource {\n let bySchema = dataSources.get(client);\n if (!bySchema) {\n bySchema = new Map();\n dataSources.set(client, bySchema);\n }\n const held = bySchema.get(fallbackSchema);\n if (held) return held;\n const made = makeRecordsDataSource(client, fallbackSchema);\n bySchema.set(fallbackSchema, made);\n return made;\n}\n\nfunction makeRecordsDataSource(client: object, fallbackSchema: string): RecordsDataSource {\n const supabase = client as unknown as {\n rpc: (fn: string, args: Record<string, unknown>) => PromiseLike<unknown>;\n schema: (name: string) => {\n rpc: (fn: string, args: Record<string, unknown>) => PromiseLike<unknown>;\n from: (table: string) => unknown;\n };\n auth?: { getSession?: () => Promise<{ data?: { session?: unknown } | null }> };\n };\n return {\n // PAGE-BUNDLE: the real adapter opens a table page with one `custom.table_page_bundle` call.\n opensInOneCall: true,\n async rpc(fn, args, options) {\n const schema = options?.schema ?? fallbackSchema;\n // 🚨 NO STORE DOOR LEAVES WITHOUT A PERSON (lane MONITOR-TRIAGE, 2026-10-01). `anon` holds\n // no USAGE on schema `custom`, so a door called with no session can only come back\n // \"42501 permission denied for schema custom\" (HTTP 401) — seven of them per signed-out\n // /data load (inbox, counts, home, portals…), every one a red row in ops.system_error.\n // A `custom` door with no session is answered HERE, with the store's own signed-out\n // sentence and no network call. Other schemas (`iam`, `platform`) serve guests by design\n // and are never short-circuited. A client without `auth` (a server or test seam) is\n // passed straight through.\n if (schema === \"custom\" && supabase.auth?.getSession && !(await hasSession(supabase.auth.getSession))) {\n return { data: null, error: SIGNED_OUT } as Awaited<ReturnType<RecordsDataSource[\"rpc\"]>>;\n }\n const on = supabase.schema(schema);\n return (await on.rpc(fn, args)) as Awaited<ReturnType<RecordsDataSource[\"rpc\"]>>;\n },\n schema(name) {\n return supabase.schema(name) as ReturnType<RecordsDataSource[\"schema\"]>;\n },\n };\n}\n\n/** The read door's own sentence for a call with nobody signed in (`custom.read_records_page`, DOOR-1). */\nconst SIGNED_OUT = {\n code: \"42501\",\n message: \"Nobody is signed in, so there is nothing to read.\",\n hint: \"Sign in, then try again.\",\n details: null,\n} as const;\n\nasync function hasSession(getSession: () => Promise<{ data?: { session?: unknown } | null }>): Promise<boolean> {\n try {\n const answer = await getSession();\n return Boolean(answer?.data?.session);\n } catch {\n // Auth could not say: let the request go and the database's answer stand.\n return true;\n }\n}\n","import { formatRelativeTime } from \"@ai-matrx/kit/format\";\nimport { humanizeIdentifier } from \"@ai-matrx/kit/text-case\";\n// src/whoChanged.ts — @ai-matrx/records-ui · SCR-17, the cell's half\n//\n// \"WHO?\" IS A QUESTION. A SCREEN IS SUPPOSED TO ANSWER IT.\n//\n// 🚨 WHAT A CLINIC SAW (crew B2, 2026-09-21, ten real patients on the live app):\n//\n// \"Every single cell shows a small 'who?' hover badge next to its value instead\n// of a resolved author name, an agent/rule label, or even 'system' — the\n// attribution feature is visibly wired up (it renders on every cell) but never\n// resolves to anything readable.\"\n//\n// They were right that it never resolved, and the reason was that nothing ever\n// asked. The badge opened a panel; it never looked anything up. Meanwhile the\n// store had the answer the whole time: `custom.field_history` on those exact ten\n// patients answers `kind: user, name: admin` on every one of them, and has since\n// they were written.\n//\n// So the badge asks, on the gesture that already reaches it — a hover or a Tab —\n// for the ONE cell being asked about. Nothing is fetched for a page of two\n// hundred cells nobody points at.\n//\n// THE THREE WORDS, AND NEVER A UUID. VAL-8 fixes the vocabulary at `user`,\n// `agent`, `system` and there is no fourth. An agent ALWAYS names the person it\n// acted for (AGT-N-4: it carries exactly that person's authority, so a screen\n// showing the machine without the person would be hiding who is answerable). The\n// system is \"the system\" — a platform word a person can read, not a null. And a\n// person whose name the door did not carry is resolved through the app's ONE\n// organization-scoped roster (the `members` port, FIX-7B's rule: the people of\n// THIS organization and nobody else). If even that cannot name them, the sentence\n// says so in words. It never prints an id: SCR-N-5 forbids showing one to a\n// person, and \"87a6e699…\" answers nobody's question anyway.\n\nimport type { FieldHistoryEntry, HistoryActor, Uuid } from \"@ai-matrx/records\";\n\n/** What the roster can tell us about a user id. `null` when it cannot. */\nexport type ResolveName = (userId: Uuid) => string | null;\n\n/** The honest stand-in when nobody and nothing can put a name to the author. */\nexport const SOMEBODY = \"somebody in this organization\";\n\n/** The platform's own word for itself. Never \"null\", never \"system_user\". */\nexport const THE_SYSTEM = \"the system\";\n\n/**\n * WHO, in the words a person reads. One place, so the grid cell, the record\n * timeline and the column history cannot drift into three different answers.\n */\nexport function actorWords(actor: HistoryActor, resolve?: ResolveName | undefined): string {\n if (actor.kind === \"system\") return THE_SYSTEM;\n const named = actor.name?.trim() || (actor.user_id && resolve ? resolve(actor.user_id)?.trim() : null) || null;\n if (actor.kind === \"agent\") {\n // An agent without the person it acted for cannot happen at the door — the\n // store refuses that write — but a screen still says something true if it does.\n const on = actor.on_behalf_of;\n const person = on?.name?.trim() || (on?.user_id && resolve ? resolve(on.user_id)?.trim() : null) || SOMEBODY;\n const approver = actor.approved_by\n ? actor.approved_by.name?.trim() || (resolve ? resolve(actor.approved_by.user_id)?.trim() : null) || SOMEBODY\n : null;\n return `${named ?? \"an assistant\"}, for ${person}${approver ? `, approved by ${approver}` : \"\"}`;\n }\n return named ?? SOMEBODY;\n}\n\n/** How long ago, in the words a person uses out loud. */\nexport function whenWords(at: string, now: Date = new Date()): string {\n const then = new Date(at);\n const age = now.getTime() - then.getTime();\n if (!Number.isFinite(age)) return \"at an unknown time\";\n if (age < 30 * 86_400_000) return formatRelativeTime(then, { style: \"intl\", now: now.getTime() });\n return then.toLocaleDateString();\n}\n\n/**\n * THE WHOLE ANSWER, as one sentence, ending in what to do to see the rest.\n * `null` is a real state and gets its own sentence: this column has never been\n * changed on this record since the store started keeping versions, which is not\n * the same as \"we could not find out\".\n */\n/**\n * WHAT HAPPENED, IN A PERSON'S WORDS (BREAKER-2 B2-29). The store words four operations and\n * lowercases any other (`RETYPE` → \"retype\"), so the panel read \"retype · admin · part of a bigger\n * change\". Every word the store can send is worded here; an unknown one is still written the way\n * a person writes it, never as a token. A soft delete is an archive, and says so.\n */\nconst OPERATION_WORDS: Record<string, string> = {\n created: \"Created\",\n edited: \"Edited\",\n deleted: \"Archived\",\n archived: \"Archived\",\n restored: \"Restored\",\n retype: \"Column type changed\",\n delete: \"Removed\",\n soft_delete: \"Archived\",\n insert: \"Created\",\n update: \"Edited\",\n restore: \"Restored\",\n};\n\nexport function operationWords(label: string | null | undefined): string {\n const raw = (label ?? \"\").trim();\n if (raw === \"\") return \"Changed\";\n const known = OPERATION_WORDS[raw.toLowerCase()];\n if (known) return known;\n const words = humanizeIdentifier(raw).toLowerCase();\n return words.charAt(0).toUpperCase() + words.slice(1);\n}\n\nexport function lastChangeSentence(\n fieldLabel: string,\n entry: FieldHistoryEntry | null,\n resolve?: ResolveName | undefined,\n): string {\n if (!entry) {\n return `Nothing is recorded against ${fieldLabel} on this record yet. Press H for the whole history of this column.`;\n }\n const verb = operationWords(entry.operation_label).toLowerCase();\n return `${fieldLabel} — ${verb} by ${actorWords(entry.actor, resolve)}, ${whenWords(entry.occurred_at)}. Press H for the whole history.`;\n}\n\n/**\n * The SHORT form the badge wears once it knows: a name a person recognises at a\n * glance, in the width of a cell corner. Never a uuid, never an email's domain.\n */\nexport function actorBadge(actor: HistoryActor, resolve?: ResolveName | undefined): string {\n if (actor.kind === \"system\") return THE_SYSTEM;\n const words = actorWords(actor, resolve);\n if (words === SOMEBODY) return \"somebody\";\n const first = words.split(\",\")[0]!.trim();\n const at = first.indexOf(\"@\");\n return at > 0 ? first.slice(0, at) : first;\n}\n"]}
package/dist/index.cjs CHANGED
@@ -30216,6 +30216,7 @@ var useViewAddress = () => (0, import_react167.useContext)(ViewAddressContext);
30216
30216
 
30217
30217
  // src/Grid.tsx
30218
30218
  var import_jsx_runtime99 = require("react/jsx-runtime");
30219
+ if (typeof window !== "undefined") performance.mark("load:heavy:Records grid");
30219
30220
  var WRAP_COLUMN_CELL_CLASS = "[table_tbody_&&]:max-w-none! [table_tbody_&&]:whitespace-normal! [table_tbody_&&]:overflow-visible! [table_tbody_&&_*]:whitespace-normal! [table_tbody_&&]:break-words [table_tbody_&&_[data-matrx-cell-content]]:max-h-[3lh]! [table_tbody_&&_[data-matrx-cell-content]]:overflow-hidden";
30220
30221
  var NO_COLUMNS_YET = "This table has no columns yet";
30221
30222
  var embeddedPageAskKey = (tableId, search, sorts, filter, pageDoorViewId) => JSON.stringify([tableId, search, sorts, filter, pageDoorViewId]);