@jskit-ai/workspaces-core 0.2.38 → 0.2.39
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,7 @@
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
5
|
- An invitation's response carries whatever delivery status its invite mailer answers, such as `held` for an email the application keeps until its email is set up. The create-invite output's `inviteDelivery.status` and the invite assistant tool's `deliveryStatus` allowed only `sent`, `simulated`, `failed` and `mailer_unconfigured`, so an invitation the assistant made through a mailer answering another status was saved and then failed with "Assistant tool output validation failed.", and the API contract did not describe the status it sent. Both are now any non-empty string. `WorkspaceInviteMailer`'s documentation names the statuses the members panel words itself and says it shows the result's `message` for any other.
|
|
6
|
+
- `workspaces.memberships.lockByWorkspaceIdAndUserId` locks its membership with `lockWhere`'s `limit: 1` (the workspace and the user are the table's unique key): one statement on PostgreSQL, where it sent two, and with json-rest-api 3.1.8 one on MariaDB and MySQL as well, whose read of the connection's schema and of the membership's links (to public tables whose foreign keys protect them) it no longer needs, as the membership's `lock(id)` costs, among 10 members and among 200.
|
|
6
7
|
- `GET .../members` and `GET .../invites` (`workspace.members.list` and `workspace.invites.list`) answer a request that leaves out `page[cursor]` or `page[limit]` again, such as every first page the members screen reads (`page[limit]=20`). Since 0.2.25 those answered 400 `ACTION_VALIDATION_FAILED`, "Value could not be cast to the required type." at `/data/attributes/cursor` (and at `/data/attributes/limit` when no limit was named), so the members screen showed no members and no invitations in any workspace. The routes handed their action `cursor` and `limit` by name, undefined when the query left one out, and an action's input refuses a field that is present but undefined; they now hand on only the fields the query sends. A route test reads both lists, first and next pages, through Fastify, the auth policy, the list actions and the JSON:API transport and serializer.
|
|
7
8
|
|
|
8
9
|
- A workspace route whose auth policy and action context differ in requiring membership (`contextPolicy: "optional"` on a route with `visibility: "workspace"`) reads its workspace context once per request instead of twice. The per-request cache keyed its reads by the membership requirement as well as the user and slug, so the two callers read the workspace, the membership and the settings each. Reads are now cached per user and slug, and each caller checks membership against the shared result: 401 `workspaces.auth.required` signed out, 403 `workspaces.workspace.accessDenied` for a non-member where membership is required, as before.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jskit-ai/workspaces-core",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.39",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "jskit test"
|
|
@@ -23,9 +23,9 @@
|
|
|
23
23
|
"./locales/en.json": "./locales/en.json"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@jskit-ai/resource-core": "0.1.
|
|
27
|
-
"@jskit-ai/resource-crud-core": "0.1.
|
|
28
|
-
"@jskit-ai/users-core": "0.2.
|
|
26
|
+
"@jskit-ai/resource-core": "0.1.214",
|
|
27
|
+
"@jskit-ai/resource-crud-core": "0.1.216",
|
|
28
|
+
"@jskit-ai/users-core": "0.2.39",
|
|
29
29
|
"json-rest-schema": "^1.0.20"
|
|
30
30
|
},
|
|
31
31
|
"description": "Workspace tenancy runtime plus HTTP routes, role catalog, and workspace config scaffolding.",
|
|
@@ -211,10 +211,10 @@
|
|
|
211
211
|
}
|
|
212
212
|
},
|
|
213
213
|
"peerDependencies": {
|
|
214
|
-
"@jskit-ai/auth-core": "0.2.
|
|
215
|
-
"@jskit-ai/database-runtime": "0.1.
|
|
216
|
-
"@jskit-ai/http-runtime": "0.2.
|
|
217
|
-
"@jskit-ai/kernel": "0.2.
|
|
218
|
-
"@jskit-ai/resource-runtime": "0.2.
|
|
214
|
+
"@jskit-ai/auth-core": "0.2.24",
|
|
215
|
+
"@jskit-ai/database-runtime": "0.1.272",
|
|
216
|
+
"@jskit-ai/http-runtime": "0.2.23",
|
|
217
|
+
"@jskit-ai/kernel": "0.2.23",
|
|
218
|
+
"@jskit-ai/resource-runtime": "0.2.30"
|
|
219
219
|
}
|
|
220
220
|
}
|
|
@@ -90,7 +90,8 @@ function createRepository({ workspaceMemberships }) {
|
|
|
90
90
|
|
|
91
91
|
/**
|
|
92
92
|
* The membership as findByWorkspaceIdAndUserId reads it, locked until the caller's transaction ends, or null. Another
|
|
93
|
-
* change of the same membership that locks it first waits, and then reads what this one left.
|
|
93
|
+
* change of the same membership that locks it first waits, and then reads what this one left. The workspace and the
|
|
94
|
+
* user are the table's unique key, so the lock takes its one row with `limit: 1`: one statement, as lock(id) is.
|
|
94
95
|
* @param {unknown} workspaceId
|
|
95
96
|
* @param {unknown} userId
|
|
96
97
|
* @param {import("@jskit-ai/resource-runtime/server/types").ResourceCallOptions} options The caller's transaction.
|
|
@@ -102,7 +103,8 @@ function createRepository({ workspaceMemberships }) {
|
|
|
102
103
|
return null;
|
|
103
104
|
}
|
|
104
105
|
|
|
105
|
-
const
|
|
106
|
+
const filters = { workspace: normalizedWorkspaceId, user: normalizedUserId };
|
|
107
|
+
const [row] = await workspaceMemberships.lockWhere(filters, { ...options, limit: 1 });
|
|
106
108
|
return normalizeMembershipRecord(row || null);
|
|
107
109
|
}
|
|
108
110
|
|
|
@@ -90,6 +90,7 @@ describe(`users and workspaces repositories on migrated ${databaseLabel}`, () =>
|
|
|
90
90
|
let userSettings;
|
|
91
91
|
let workspaces;
|
|
92
92
|
let memberships;
|
|
93
|
+
let membershipTable;
|
|
93
94
|
let invites;
|
|
94
95
|
let memberPages;
|
|
95
96
|
let settings;
|
|
@@ -130,6 +131,7 @@ describe(`users and workspaces repositories on migrated ${databaseLabel}`, () =>
|
|
|
130
131
|
}));
|
|
131
132
|
({ profiles, userSettings, profileProjector, usersExtensions } = capabilities);
|
|
132
133
|
const resources = await runtime.own("workspaces.core", WORKSPACES_TABLES);
|
|
134
|
+
membershipTable = resources.workspaceMemberships;
|
|
133
135
|
({ workspaces, memberships } = createWorkspaceRecords(resources));
|
|
134
136
|
invites = createInvitesRepository({ workspaceInvites: resources.workspaceInvites, workspaces });
|
|
135
137
|
memberPages = createMemberPagesRepository({ workspaceMemberships: resources.workspaceMemberships, userProfiles: profiles });
|
|
@@ -328,7 +330,8 @@ describe(`users and workspaces repositories on migrated ${databaseLabel}`, () =>
|
|
|
328
330
|
const locking = sql.filter((statement) => /\bfor (?:update|share|no key update)\b|\block in share mode\b/iu.test(statement));
|
|
329
331
|
const clause = { pg: /\bfor share\b/iu, mysql2: /\block in share mode\b/iu }[configuration.client];
|
|
330
332
|
if (clause) {
|
|
331
|
-
//
|
|
333
|
+
// One locking read of each table, in the shared mode: the membership's lockWhere takes its one row with limit: 1.
|
|
334
|
+
assert.equal(locking.length, 2, locking.join(" | "));
|
|
332
335
|
assert.ok(locking.some((statement) => /\bfrom [`"]?workspaces[`"]? /u.test(statement)), sql.join(" | "));
|
|
333
336
|
assert.ok(locking.some((statement) => /\bfrom [`"]?workspace_memberships[`"]? /u.test(statement)), sql.join(" | "));
|
|
334
337
|
assert.ok(locking.every((statement) => clause.test(statement)), locking.join(" | "));
|
|
@@ -343,6 +346,48 @@ describe(`users and workspaces repositories on migrated ${databaseLabel}`, () =>
|
|
|
343
346
|
assert.equal(refused.sql.filter((statement) => /^\s*select\b/iu.test(statement)).length, 0, refused.sql.join(" | "));
|
|
344
347
|
});
|
|
345
348
|
|
|
349
|
+
test("memberships.lockByWorkspaceIdAndUserId sends what the membership's lock(id) sends, among 10 and 200 members", async () => {
|
|
350
|
+
const usernames = Array.from({ length: 210 }, (_, index) => `locker-${String(index).padStart(3, "0")}`);
|
|
351
|
+
const users = await insertUsers(usernames);
|
|
352
|
+
const ownerId = users.get("locker-000");
|
|
353
|
+
const small = await workspaces.insert({ slug: "lock-small", name: "Lock Small", ownerUserId: ownerId });
|
|
354
|
+
const large = await workspaces.insert({ slug: "lock-large", name: "Lock Large", ownerUserId: ownerId });
|
|
355
|
+
const membership = (workspaceId, username) => ({
|
|
356
|
+
workspace_id: workspaceId,
|
|
357
|
+
user_id: users.get(username),
|
|
358
|
+
role_sid: users.get(username) === ownerId ? "owner" : "member",
|
|
359
|
+
status: "active"
|
|
360
|
+
});
|
|
361
|
+
await insertRows("workspace_memberships", [
|
|
362
|
+
...usernames.slice(0, 10).map((username) => membership(small.id, username)),
|
|
363
|
+
...["locker-000", ...usernames.slice(10, 210)].map((username) => membership(large.id, username))
|
|
364
|
+
]);
|
|
365
|
+
// The statements a lock sends inside its transaction.
|
|
366
|
+
const statementsIn = async (lock) => {
|
|
367
|
+
// MariaDB and MySQL read a table's indexes once per process and set of filtered columns: not this measure.
|
|
368
|
+
await workspaces.withTransaction({}, lock);
|
|
369
|
+
return workspaces.withTransaction({}, async (txOptions) => {
|
|
370
|
+
const { result, statements } = await statementsOf(() => lock(txOptions));
|
|
371
|
+
assert.ok(result);
|
|
372
|
+
return statements;
|
|
373
|
+
});
|
|
374
|
+
};
|
|
375
|
+
const costs = [];
|
|
376
|
+
for (const [workspace, username] of [[small, "locker-004"], [large, "locker-150"]]) {
|
|
377
|
+
const userId = users.get(username);
|
|
378
|
+
const { id } = await memberships.findByWorkspaceIdAndUserId(workspace.id, userId);
|
|
379
|
+
costs.push({
|
|
380
|
+
lock: await statementsIn((txOptions) => membershipTable.lock(id, txOptions)),
|
|
381
|
+
lockByWorkspaceIdAndUserId: await statementsIn((txOptions) => memberships.lockByWorkspaceIdAndUserId(workspace.id, userId, txOptions))
|
|
382
|
+
});
|
|
383
|
+
}
|
|
384
|
+
// SQLite's first lock in a transaction takes its write lock first, and reads the two links it shows, as it enforces
|
|
385
|
+
// foreign keys only on connections that turn them on. Elsewhere the links' foreign keys answer for them: the
|
|
386
|
+
// workspaces and the profiles are public tables with no row policy.
|
|
387
|
+
const cost = configuration.client === "better-sqlite3" ? 4 : 1;
|
|
388
|
+
assert.deepEqual(costs, [{ lock: cost, lockByWorkspaceIdAndUserId: cost }, { lock: cost, lockByWorkspaceIdAndUserId: cost }]);
|
|
389
|
+
});
|
|
390
|
+
|
|
346
391
|
test("another owner's report joins the workspaces' and memberships' join sources in one statement, each keeping its filters and the report its scope", async (t) => {
|
|
347
392
|
// Another feature's workspace-owned table, whose report reads each row's workspace slug and active membership.
|
|
348
393
|
await knex.schema.createTable("test_reminders", (table) => {
|