@proteinjs/user-ui 1.8.0 → 1.8.1

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
@@ -3,6 +3,17 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [1.8.1](https://github.com/proteinjs/user/compare/@proteinjs/user-ui@1.8.0...@proteinjs/user-ui@1.8.1) (2026-08-29)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * AccessGrant.principal names its reference table 'user', not the class name — UserTable.name is the class's static JS name ('UserTable'), which deserialize stamped onto every read-back principal, so principal.get() threw (Unable to find table: UserTable) and the admin grant table could never render principals as linked names. Stored cells are bare ids — verified against the live emulator (the raw principal cell is exactly the user id; nothing 'UserTable'-shaped in the row) — so the fix is declaration-only: zero data touched, zero DDL (same STRING(36) column). Tests: user-server emulator suite (stored-bare-id premise, read-back principal resolves the user record, admin/owner insert-gate id-equality pin) + user-ui admin grant-table linked-name rendering bound over the real declaration (the adminInvitedByRendering pattern). Red-before-green: the resolution and rendering legs fail at the pre-fix declaration ('UserTable' stamped on the reference; link at ?table=UserTable). ([037f3ef](https://github.com/proteinjs/user/commit/037f3efd316b56d557c044639f7cd8e044e7d313))
12
+
13
+
14
+
15
+
16
+
6
17
  # [1.8.0](https://github.com/proteinjs/user/compare/@proteinjs/user-ui@1.7.3...@proteinjs/user-ui@1.8.0) (2026-08-29)
7
18
 
8
19
 
@@ -0,0 +1,5 @@
1
+ declare global {
2
+ var IS_REACT_ACT_ENVIRONMENT: boolean;
3
+ }
4
+ export {};
5
+ //# sourceMappingURL=adminAccessGrantPrincipalRendering.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"adminAccessGrantPrincipalRendering.test.d.ts","sourceRoot":"","sources":["../../test/adminAccessGrantPrincipalRendering.test.tsx"],"names":[],"mappings":"AA2CA,OAAO,CAAC,MAAM,CAAC;IAEb,IAAI,wBAAwB,EAAE,OAAO,CAAC;CACvC"}
@@ -0,0 +1,199 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
+ return new (P || (P = Promise))(function (resolve, reject) {
16
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
20
+ });
21
+ };
22
+ var __generator = (this && this.__generator) || function (thisArg, body) {
23
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
+ function verb(n) { return function (v) { return step([n, v]); }; }
26
+ function step(op) {
27
+ if (f) throw new TypeError("Generator is already executing.");
28
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
29
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
30
+ if (y = 0, t) op = [op[0] & 2, t.value];
31
+ switch (op[0]) {
32
+ case 0: case 1: t = op; break;
33
+ case 4: _.label++; return { value: op[1], done: false };
34
+ case 5: _.label++; y = op[1]; op = [0]; continue;
35
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
+ default:
37
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
+ if (t[2]) _.ops.pop();
42
+ _.trys.pop(); continue;
43
+ }
44
+ op = body.call(thisArg, _);
45
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
+ }
48
+ };
49
+ var __importDefault = (this && this.__importDefault) || function (mod) {
50
+ return (mod && mod.__esModule) ? mod : { "default": mod };
51
+ };
52
+ Object.defineProperty(exports, "__esModule", { value: true });
53
+ /**
54
+ * @jest-environment jsdom
55
+ * @jest-environment-options {"customExportConditions": ["node", "node-addons"]}
56
+ *
57
+ * The admin AccessGrants table renders `principal` as the referenced USER's name, linked to
58
+ * their record form — the same ReferenceCellValue surface the Users/Invites tables use for
59
+ * `invitedBy`. What this suite binds is the REAL AccessGrantTable declaration reaching it:
60
+ * rows are built the way the db layer builds them — `deserialize` stamps the COLUMN
61
+ * DECLARATION's reference-table name onto every read-back Reference — so a declaration naming
62
+ * the class (`'UserTable'`) instead of the table (`'user'`) fails these assertions (the
63
+ * resolver finds no such table; the link would point at `?table=UserTable`).
64
+ */
65
+ var react_1 = __importDefault(require("react"));
66
+ var client_1 = require("react-dom/client");
67
+ var test_utils_1 = require("react-dom/test-utils");
68
+ var react_router_dom_1 = require("react-router-dom");
69
+ var react_query_1 = require("react-query");
70
+ var ui_1 = require("@proteinjs/ui");
71
+ // ReferenceCellValue resolves through Reference.get(); the fake resolves the principal to a
72
+ // named user record so the enrichment path is observable without a db. Note the fake only
73
+ // answers for the real table name 'user' — a declaration-corrupted table name gets nothing.
74
+ jest.mock('@proteinjs/db', function () {
75
+ var actual = jest.requireActual('@proteinjs/db');
76
+ var FakeReference = /** @class */ (function () {
77
+ function FakeReference(_table, _id) {
78
+ this._table = _table;
79
+ this._id = _id;
80
+ }
81
+ FakeReference.prototype.get = function () {
82
+ return __awaiter(this, void 0, void 0, function () {
83
+ return __generator(this, function (_a) {
84
+ if (this._table === 'user' && this._id === 'principal-1') {
85
+ return [2 /*return*/, { id: 'principal-1', name: 'Priya Principal' }];
86
+ }
87
+ throw new Error('not visible');
88
+ });
89
+ });
90
+ };
91
+ return FakeReference;
92
+ }());
93
+ return __assign(__assign({}, actual), { Reference: FakeReference });
94
+ });
95
+ var db_1 = require("@proteinjs/db");
96
+ var db_ui_1 = require("@proteinjs/db-ui");
97
+ var user_1 = require("@proteinjs/user");
98
+ globalThis.IS_REACT_ACT_ENVIRONMENT = true;
99
+ var StubIntersectionObserver = /** @class */ (function () {
100
+ function StubIntersectionObserver() {
101
+ }
102
+ StubIntersectionObserver.prototype.observe = function () { };
103
+ StubIntersectionObserver.prototype.unobserve = function () { };
104
+ StubIntersectionObserver.prototype.disconnect = function () { };
105
+ return StubIntersectionObserver;
106
+ }());
107
+ globalThis.IntersectionObserver = StubIntersectionObserver;
108
+ /**
109
+ * The principal reference exactly as the db layer would hand it to the table: the reference's
110
+ * table name comes from the COLUMN DECLARATION (ReferenceColumn.deserialize stamps
111
+ * `this.referenceTable`), never from stored data — stored cells are bare ids.
112
+ */
113
+ var principalReference = function () {
114
+ var principalColumn = user_1.tables.AccessGrant.columns.principal;
115
+ return new db_1.Reference(principalColumn.referenceTable, 'principal-1');
116
+ };
117
+ var grantRow = {
118
+ id: 'grant-1',
119
+ principal: principalReference(),
120
+ resource: new db_1.Reference('thought', 'thought-1'),
121
+ resourceTable: 'thought',
122
+ accessLevel: 'read',
123
+ };
124
+ describe('the admin AccessGrants table renders principal as the linked user', function () {
125
+ var container;
126
+ var root;
127
+ var client;
128
+ beforeEach(function () {
129
+ (0, db_ui_1.clearReferenceNameCache)();
130
+ container = document.createElement('div');
131
+ document.body.appendChild(container);
132
+ root = (0, client_1.createRoot)(container);
133
+ client = new react_query_1.QueryClient({ defaultOptions: { queries: { retry: false, cacheTime: 0 } } });
134
+ });
135
+ afterEach(function () {
136
+ (0, test_utils_1.act)(function () { return root.unmount(); });
137
+ container.remove();
138
+ });
139
+ var mount = function (rows) { return __awaiter(void 0, void 0, void 0, function () {
140
+ return __generator(this, function (_a) {
141
+ switch (_a.label) {
142
+ case 0: return [4 /*yield*/, (0, test_utils_1.act)(function () { return __awaiter(void 0, void 0, void 0, function () {
143
+ return __generator(this, function (_a) {
144
+ root.render(react_1.default.createElement(react_query_1.QueryClientProvider, { client: client },
145
+ react_1.default.createElement(react_router_dom_1.MemoryRouter, null,
146
+ react_1.default.createElement(db_ui_1.RecordTable, { table: user_1.tables.AccessGrant, tableLoader: new ui_1.StaticTableLoader(rows, { dataKey: "grant-principal-".concat(Math.random()), dataQueryKey: 'all' }), hideButtons: true, columns: ['accessLevel', 'principal'] }))));
147
+ return [2 /*return*/];
148
+ });
149
+ }); })];
150
+ case 1:
151
+ _a.sent();
152
+ // one macrotask for the name resolution to land
153
+ return [4 /*yield*/, (0, test_utils_1.act)(function () { return __awaiter(void 0, void 0, void 0, function () {
154
+ return __generator(this, function (_a) {
155
+ switch (_a.label) {
156
+ case 0: return [4 /*yield*/, new Promise(function (resolve) { return setTimeout(resolve, 0); })];
157
+ case 1:
158
+ _a.sent();
159
+ return [2 /*return*/];
160
+ }
161
+ });
162
+ }); })];
163
+ case 2:
164
+ // one macrotask for the name resolution to land
165
+ _a.sent();
166
+ return [4 /*yield*/, (0, test_utils_1.act)(function () { return __awaiter(void 0, void 0, void 0, function () {
167
+ return __generator(this, function (_a) {
168
+ switch (_a.label) {
169
+ case 0: return [4 /*yield*/, new Promise(function (resolve) { return setTimeout(resolve, 0); })];
170
+ case 1:
171
+ _a.sent();
172
+ return [2 /*return*/];
173
+ }
174
+ });
175
+ }); })];
176
+ case 3:
177
+ _a.sent();
178
+ return [2 /*return*/];
179
+ }
180
+ });
181
+ }); };
182
+ var principalCell = function () { return container.querySelectorAll('tbody td')[1]; };
183
+ it('links the principal by name to their user record', function () { return __awaiter(void 0, void 0, void 0, function () {
184
+ var link;
185
+ return __generator(this, function (_a) {
186
+ switch (_a.label) {
187
+ case 0: return [4 /*yield*/, mount([grantRow])];
188
+ case 1:
189
+ _a.sent();
190
+ link = principalCell().querySelector('a');
191
+ expect(link).not.toBeNull();
192
+ expect(link.getAttribute('href')).toBe('/record/form?table=user&record=principal-1');
193
+ expect(principalCell().textContent).toBe('Priya Principal');
194
+ return [2 /*return*/];
195
+ }
196
+ });
197
+ }); });
198
+ });
199
+ //# sourceMappingURL=adminAccessGrantPrincipalRendering.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"adminAccessGrantPrincipalRendering.test.js","sourceRoot":"","sources":["../../test/adminAccessGrantPrincipalRendering.test.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;GAWG;AACH,gDAA0B;AAC1B,2CAAoD;AACpD,mDAA2C;AAC3C,qDAAgD;AAChD,2CAA+D;AAC/D,oCAAkD;AAElD,4FAA4F;AAC5F,0FAA0F;AAC1F,4FAA4F;AAC5F,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE;IACzB,IAAM,MAAM,GAAG,IAAI,CAAC,aAAa,CAAC,eAAe,CAAC,CAAC;IACnD;QACE,uBACS,MAAc,EACd,GAAY;YADZ,WAAM,GAAN,MAAM,CAAQ;YACd,QAAG,GAAH,GAAG,CAAS;QAClB,CAAC;QACE,2BAAG,GAAT;;;oBACE,IAAI,IAAI,CAAC,MAAM,KAAK,MAAM,IAAI,IAAI,CAAC,GAAG,KAAK,aAAa,EAAE;wBACxD,sBAAO,EAAE,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE,iBAAiB,EA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CAAtD,SAAsD,CAAC;;;;6BACxD,CAAC,EAAA;;oBAFF,SAEE,CAAC;;;;SACJ,CAAC;IAEF,IAAM,aAAa,GAAG,cAAM,OAAA,SAAS,CAAC,gBAAgB,CAAC,UAAU,CAAC,CAAC,CAAC,CAAgB,EAAxD,CAAwD,CAAC;IAErF,EAAE,CAAC,kDAAkD,EAAE;;;;wBACrD,qBAAM,KAAK,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAA;;oBAAvB,SAAuB,CAAC;oBAClB,IAAI,GAAG,aAAa,EAAE,CAAC,aAAa,CAAC,GAAG,CAAsB,CAAC;oBACrE,MAAM,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC;oBAC5B,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,4CAA4C,CAAC,CAAC;oBACrF,MAAM,CAAC,aAAa,EAAE,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;;;;SAC7D,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@proteinjs/user-ui",
3
- "version": "1.8.0",
3
+ "version": "1.8.1",
4
4
  "description": "User ui components",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -29,7 +29,7 @@
29
29
  "@proteinjs/reflection": "^1.2.0",
30
30
  "@proteinjs/server-api": "^3.0.11",
31
31
  "@proteinjs/ui": "^4.5.0",
32
- "@proteinjs/user": "^1.12.0",
32
+ "@proteinjs/user": "^1.12.1",
33
33
  "@proteinjs/util": "^1.6.1",
34
34
  "moment": "2.29.4",
35
35
  "react": "18.2.0",
@@ -56,5 +56,5 @@
56
56
  },
57
57
  "main": "./dist/generated/index.js",
58
58
  "types": "./dist/generated/index.d.ts",
59
- "gitHead": "96ebc933680809c62b8c55bb14604d85a80912a9"
59
+ "gitHead": "afc8981f566682ae188b8a204d4a2fe0669bbd11"
60
60
  }
@@ -0,0 +1,128 @@
1
+ /**
2
+ * @jest-environment jsdom
3
+ * @jest-environment-options {"customExportConditions": ["node", "node-addons"]}
4
+ *
5
+ * The admin AccessGrants table renders `principal` as the referenced USER's name, linked to
6
+ * their record form — the same ReferenceCellValue surface the Users/Invites tables use for
7
+ * `invitedBy`. What this suite binds is the REAL AccessGrantTable declaration reaching it:
8
+ * rows are built the way the db layer builds them — `deserialize` stamps the COLUMN
9
+ * DECLARATION's reference-table name onto every read-back Reference — so a declaration naming
10
+ * the class (`'UserTable'`) instead of the table (`'user'`) fails these assertions (the
11
+ * resolver finds no such table; the link would point at `?table=UserTable`).
12
+ */
13
+ import React from 'react';
14
+ import { createRoot, Root } from 'react-dom/client';
15
+ import { act } from 'react-dom/test-utils';
16
+ import { MemoryRouter } from 'react-router-dom';
17
+ import { QueryClient, QueryClientProvider } from 'react-query';
18
+ import { StaticTableLoader } from '@proteinjs/ui';
19
+
20
+ // ReferenceCellValue resolves through Reference.get(); the fake resolves the principal to a
21
+ // named user record so the enrichment path is observable without a db. Note the fake only
22
+ // answers for the real table name 'user' — a declaration-corrupted table name gets nothing.
23
+ jest.mock('@proteinjs/db', () => {
24
+ const actual = jest.requireActual('@proteinjs/db');
25
+ class FakeReference {
26
+ constructor(
27
+ public _table: string,
28
+ public _id?: string
29
+ ) {}
30
+ async get() {
31
+ if (this._table === 'user' && this._id === 'principal-1') {
32
+ return { id: 'principal-1', name: 'Priya Principal' };
33
+ }
34
+ throw new Error('not visible');
35
+ }
36
+ }
37
+ return { ...actual, Reference: FakeReference };
38
+ });
39
+
40
+ import { Reference, ReferenceColumn } from '@proteinjs/db';
41
+ import { RecordTable, clearReferenceNameCache } from '@proteinjs/db-ui';
42
+ import { tables, AccessGrant, User } from '@proteinjs/user';
43
+
44
+ declare global {
45
+ // eslint-disable-next-line no-var
46
+ var IS_REACT_ACT_ENVIRONMENT: boolean;
47
+ }
48
+ globalThis.IS_REACT_ACT_ENVIRONMENT = true;
49
+
50
+ class StubIntersectionObserver {
51
+ observe() {}
52
+ unobserve() {}
53
+ disconnect() {}
54
+ }
55
+ (globalThis as any).IntersectionObserver = StubIntersectionObserver;
56
+
57
+ /**
58
+ * The principal reference exactly as the db layer would hand it to the table: the reference's
59
+ * table name comes from the COLUMN DECLARATION (ReferenceColumn.deserialize stamps
60
+ * `this.referenceTable`), never from stored data — stored cells are bare ids.
61
+ */
62
+ const principalReference = () => {
63
+ const principalColumn = tables.AccessGrant.columns.principal as unknown as ReferenceColumn<User>;
64
+ return new Reference<User>(principalColumn.referenceTable, 'principal-1');
65
+ };
66
+
67
+ const grantRow = {
68
+ id: 'grant-1',
69
+ principal: principalReference(),
70
+ resource: new Reference('thought', 'thought-1'),
71
+ resourceTable: 'thought',
72
+ accessLevel: 'read',
73
+ } as unknown as AccessGrant;
74
+
75
+ describe('the admin AccessGrants table renders principal as the linked user', () => {
76
+ let container: HTMLDivElement;
77
+ let root: Root;
78
+ let client: QueryClient;
79
+
80
+ beforeEach(() => {
81
+ clearReferenceNameCache();
82
+ container = document.createElement('div');
83
+ document.body.appendChild(container);
84
+ root = createRoot(container);
85
+ client = new QueryClient({ defaultOptions: { queries: { retry: false, cacheTime: 0 } } });
86
+ });
87
+
88
+ afterEach(() => {
89
+ act(() => root.unmount());
90
+ container.remove();
91
+ });
92
+
93
+ const mount = async (rows: AccessGrant[]) => {
94
+ await act(async () => {
95
+ root.render(
96
+ <QueryClientProvider client={client}>
97
+ <MemoryRouter>
98
+ <RecordTable
99
+ table={tables.AccessGrant}
100
+ tableLoader={
101
+ new StaticTableLoader(rows, { dataKey: `grant-principal-${Math.random()}`, dataQueryKey: 'all' })
102
+ }
103
+ hideButtons
104
+ columns={['accessLevel', 'principal'] as any}
105
+ />
106
+ </MemoryRouter>
107
+ </QueryClientProvider>
108
+ );
109
+ });
110
+ // one macrotask for the name resolution to land
111
+ await act(async () => {
112
+ await new Promise((resolve) => setTimeout(resolve, 0));
113
+ });
114
+ await act(async () => {
115
+ await new Promise((resolve) => setTimeout(resolve, 0));
116
+ });
117
+ };
118
+
119
+ const principalCell = () => container.querySelectorAll('tbody td')[1] as HTMLElement;
120
+
121
+ it('links the principal by name to their user record', async () => {
122
+ await mount([grantRow]);
123
+ const link = principalCell().querySelector('a') as HTMLAnchorElement;
124
+ expect(link).not.toBeNull();
125
+ expect(link.getAttribute('href')).toBe('/record/form?table=user&record=principal-1');
126
+ expect(principalCell().textContent).toBe('Priya Principal');
127
+ });
128
+ });