@jskit-ai/workspaces-core 0.2.16 → 0.2.18
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 +2 -0
- package/package.json +9 -9
- package/src/server/common/repositories/workspaceMembershipsRepository.js +4 -18
- package/src/server/common/repositories/workspacesRepository.js +4 -19
- package/src/shared/resources/workspaceInvitesResource.js +4 -0
- package/src/shared/resources/workspaceMembershipsResource.js +4 -0
- package/src/shared/resources/workspaceResource.js +1 -0
- package/src/shared/resources/workspaceSettingsResource.js +1 -0
- package/test/repositories.integration.test.js +8 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
- `workspaces.joinSource` and `workspaces.memberships.joinSource` are the handle's `joinSource` (`@jskit-ai/resource-runtime`): the same `{ query, column }` for the same params, carrying the columns a read answers instead of every column of the table. A report that names its columns with `column(field)` reads as before.
|
|
5
6
|
- An anonymous visitor on a workspace surface that does not require membership (`requireMembership: false`, such as a public payment link under `/api/w/<slug>/...`) resolves to the workspace with no membership and no permissions, as a signed-in non-member does, where every such request answered 401 `workspaces.auth.required`. A surface that requires membership still answers 401 to an anonymous visitor, before it reads the workspace.
|
|
7
|
+
- Its table resources declare the foreign keys their migrations create (`foreignKeys`), so json-rest-api 3.1.0 can skip the visibility query a system-context read makes for a record such a key guarantees exists. `jskit test --databases` checks each against an app's test database: workspaces.owner_user_id to users; workspace_memberships.workspace_id to workspaces and user_id to users; workspace_settings.workspace_id to workspaces; workspace_invites.workspace_id to workspaces and invited_by_user_id to users. `repositories.integration.test.js` proves the declarations, and users-core's, match the migrations on its database (SQLite, or MariaDB or PostgreSQL with JSKIT_REPOSITORY_TEST_DATABASE_URL).
|
|
6
8
|
- The workspace settings colours and `invitesEnabled`, and the role and status of a membership and of an invite, are no longer `required`, which `defineTableResource` now refuses beside `defaultTo`: a create that leaves one out gets its default where it failed REQUIRED. The settings contract keeps its own body and output schemas, so requests are unchanged.
|
|
7
9
|
- `@jskit-ai/database-runtime` and `@jskit-ai/resource-runtime` are peer dependencies, required and at the same versions, where they were dependencies: its workspaces, memberships, invites and settings are table resources, and the app holds one copy of the table runtime that every package shares, as it does the kernel. npm installs a required peer as it installed the dependency, so an app installs the same packages and versions; a release whose versions disagree now fails the install with ERESOLVE instead of nesting a second copy.
|
|
8
10
|
- `workspaces.listByIds(ids, options)` reads the workspaces with these ids in one statement however many, sorted by id; an id naming none is left out and a deleted workspace kept, as `findById` keeps it. A caller that read one workspace per id with `findById` reads them at once.
|
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.18",
|
|
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.206",
|
|
27
|
+
"@jskit-ai/resource-crud-core": "0.1.206",
|
|
28
|
+
"@jskit-ai/users-core": "0.2.18",
|
|
29
29
|
"json-rest-schema": "^1.0.17"
|
|
30
30
|
},
|
|
31
31
|
"description": "Workspace tenancy runtime plus HTTP routes, role catalog, and workspace config scaffolding.",
|
|
@@ -206,10 +206,10 @@
|
|
|
206
206
|
}
|
|
207
207
|
},
|
|
208
208
|
"peerDependencies": {
|
|
209
|
-
"@jskit-ai/auth-core": "0.2.
|
|
210
|
-
"@jskit-ai/database-runtime": "0.1.
|
|
211
|
-
"@jskit-ai/http-runtime": "0.2.
|
|
212
|
-
"@jskit-ai/kernel": "0.2.
|
|
213
|
-
"@jskit-ai/resource-runtime": "0.2.
|
|
209
|
+
"@jskit-ai/auth-core": "0.2.15",
|
|
210
|
+
"@jskit-ai/database-runtime": "0.1.264",
|
|
211
|
+
"@jskit-ai/http-runtime": "0.2.15",
|
|
212
|
+
"@jskit-ai/kernel": "0.2.15",
|
|
213
|
+
"@jskit-ai/resource-runtime": "0.2.14"
|
|
214
214
|
}
|
|
215
215
|
}
|
|
@@ -253,26 +253,12 @@ function createRepository({ workspaceMemberships }) {
|
|
|
253
253
|
return workspaceIdsByUserId;
|
|
254
254
|
}
|
|
255
255
|
|
|
256
|
-
/**
|
|
257
|
-
* The memberships as a join source for another owner's report, so it reads them in its own statement: the scoped
|
|
258
|
-
* memberships under `alias`, matching `filters` (this resource's search fields, such as `{ workspace, status:
|
|
259
|
-
* "active" }`), and each field's column under that alias. It answers the builder wrapped, since a builder is thenable.
|
|
260
|
-
* @param {{ alias: string, filters?: object }} params
|
|
261
|
-
* @param {import("@jskit-ai/resource-runtime/server/types").ResourceCallOptions} [options]
|
|
262
|
-
* @returns {Promise<{ query: object, column: (field: string) => string }>}
|
|
263
|
-
*/
|
|
264
|
-
// Knex: subquery - another owner's report joins the memberships it reads, in one statement
|
|
265
|
-
async function joinSource({ alias, filters }, options = {}) {
|
|
266
|
-
if (typeof alias !== "string" || !alias) {
|
|
267
|
-
throw new TypeError("workspaces.memberships.joinSource() needs the alias the report joins the memberships under.");
|
|
268
|
-
}
|
|
269
|
-
const { query } = await workspaceMemberships.scopedQuery({ alias, ...(filters === undefined ? {} : { filters }) }, options);
|
|
270
|
-
return { query, column: (field) => workspaceMemberships.column(field, alias) };
|
|
271
|
-
}
|
|
272
|
-
|
|
273
256
|
return Object.freeze({
|
|
274
257
|
withTransaction: workspaceMemberships.withTransaction,
|
|
275
|
-
|
|
258
|
+
// The memberships as a join source for another owner's report, which reads them in its own statement: the
|
|
259
|
+
// handle's joinSource, the scoped memberships under `alias` matching `filters` (such as `{ workspace, status:
|
|
260
|
+
// "active" }`).
|
|
261
|
+
joinSource: workspaceMemberships.joinSource,
|
|
276
262
|
findByWorkspaceIdAndUserId,
|
|
277
263
|
ensureOwnerMembership,
|
|
278
264
|
upsertMembership,
|
|
@@ -228,27 +228,12 @@ function createRepository({ workspaces, workspaceMemberships }) {
|
|
|
228
228
|
return row ? { id: normalizeRecordId(row.id, { fallback: null }) } : null;
|
|
229
229
|
}
|
|
230
230
|
|
|
231
|
-
/**
|
|
232
|
-
* The workspaces as a join source for another owner's report, so it reads them in its own statement: the scoped
|
|
233
|
-
* workspaces under `alias`, matching `filters` (this resource's search fields; a deleted workspace is in it unless
|
|
234
|
-
* the report filters on `column("deletedAt")`), and each field's column under that alias. It answers the builder
|
|
235
|
-
* wrapped, since a builder is thenable.
|
|
236
|
-
* @param {{ alias: string, filters?: object }} params
|
|
237
|
-
* @param {import("@jskit-ai/resource-runtime/server/types").ResourceCallOptions} [options]
|
|
238
|
-
* @returns {Promise<{ query: object, column: (field: string) => string }>}
|
|
239
|
-
*/
|
|
240
|
-
// Knex: subquery - another owner's report joins the workspaces it reads, in one statement
|
|
241
|
-
async function joinSource({ alias, filters }, options = {}) {
|
|
242
|
-
if (typeof alias !== "string" || !alias) {
|
|
243
|
-
throw new TypeError("workspaces.joinSource() needs the alias the report joins the workspaces under.");
|
|
244
|
-
}
|
|
245
|
-
const { query } = await workspaces.scopedQuery({ alias, ...(filters === undefined ? {} : { filters }) }, options);
|
|
246
|
-
return { query, column: (field) => workspaces.column(field, alias) };
|
|
247
|
-
}
|
|
248
|
-
|
|
249
231
|
return Object.freeze({
|
|
250
232
|
withTransaction: workspaces.withTransaction,
|
|
251
|
-
|
|
233
|
+
// The workspaces as a join source for another owner's report, which reads them in its own statement: the handle's
|
|
234
|
+
// joinSource, the scoped workspaces under `alias` matching `filters` (a deleted workspace is in it unless the
|
|
235
|
+
// report filters on `column("deletedAt")`).
|
|
236
|
+
joinSource: workspaces.joinSource,
|
|
252
237
|
findById,
|
|
253
238
|
listByIds,
|
|
254
239
|
findBySlug,
|
|
@@ -6,6 +6,10 @@ const workspaceInvitesResource = defineTableResource({
|
|
|
6
6
|
name: "workspaceInvites",
|
|
7
7
|
tableName: "workspace_invites",
|
|
8
8
|
ownership: "public",
|
|
9
|
+
foreignKeys: [
|
|
10
|
+
{ columns: ["workspaceId"], referencedTableName: "workspaces" },
|
|
11
|
+
{ columns: ["invitedByUserId"], referencedTableName: "users" }
|
|
12
|
+
],
|
|
9
13
|
searchSchema: {
|
|
10
14
|
workspace: { type: "id", actualField: "workspace_id", filterOperator: "=" },
|
|
11
15
|
email: { type: "string", actualField: "email", filterOperator: "=" },
|
|
@@ -7,6 +7,10 @@ const workspaceMembershipsResource = defineTableResource({
|
|
|
7
7
|
name: "workspaceMemberships",
|
|
8
8
|
tableName: "workspace_memberships",
|
|
9
9
|
ownership: "public",
|
|
10
|
+
foreignKeys: [
|
|
11
|
+
{ columns: ["workspaceId"], referencedTableName: "workspaces" },
|
|
12
|
+
{ columns: ["userId"], referencedTableName: "users" }
|
|
13
|
+
],
|
|
10
14
|
searchSchema: {
|
|
11
15
|
workspace: { type: "id", actualField: "workspace_id", filterOperator: "=" },
|
|
12
16
|
user: { type: "id", actualField: "user_id", filterOperator: "=" },
|
|
@@ -77,6 +77,7 @@ const workspaceResource = defineTableResource({
|
|
|
77
77
|
name: "workspaces",
|
|
78
78
|
tableName: "workspaces",
|
|
79
79
|
ownership: "public",
|
|
80
|
+
foreignKeys: [{ columns: ["ownerUserId"], referencedTableName: "users" }],
|
|
80
81
|
searchSchema: {
|
|
81
82
|
slug: { type: "string", actualField: "slug", filterOperator: "=" },
|
|
82
83
|
slugs: { type: "array", actualField: "slug", filterOperator: "in", items: { type: "string" } },
|
|
@@ -245,6 +245,7 @@ const workspaceSettingsResource = defineTableResource({
|
|
|
245
245
|
name: "workspaceSettings",
|
|
246
246
|
tableName: "workspace_settings",
|
|
247
247
|
ownership: "public",
|
|
248
|
+
foreignKeys: [{ columns: ["id"], referencedTableName: "workspaces" }],
|
|
248
249
|
idProperty: "workspace_id",
|
|
249
250
|
schema: {
|
|
250
251
|
id: {
|
|
@@ -4,7 +4,10 @@ import knexLib from "knex";
|
|
|
4
4
|
import { findDuplicateEntryError } from "@jskit-ai/database-runtime/shared";
|
|
5
5
|
import { defineTableResource } from "@jskit-ai/resource-core/shared/tableResource";
|
|
6
6
|
import { silentLogger } from "@jskit-ai/kernel/server/runtime/logger";
|
|
7
|
+
import { checkForeignKeys } from "@jskit-ai/resource-runtime/server";
|
|
7
8
|
import { startTestFeatures } from "@jskit-ai/resource-runtime/test";
|
|
9
|
+
import { userProfileTableResource } from "@jskit-ai/users-core/shared/resources/userProfileResource";
|
|
10
|
+
import { userSettingsTableResource } from "@jskit-ai/users-core/shared/resources/userSettingsResource";
|
|
8
11
|
import { UsersExtensionsProvider } from "@jskit-ai/users-core/server/UsersExtensionsProvider";
|
|
9
12
|
import { UsersIdentityProvider } from "@jskit-ai/users-core/server/UsersIdentityProvider";
|
|
10
13
|
import usersInitial from "../../users-core/migrations/users_core_generic_initial.cjs";
|
|
@@ -139,6 +142,11 @@ describe(`users and workspaces repositories on migrated ${databaseLabel}`, () =>
|
|
|
139
142
|
for (const table of TABLES) await knex(table).delete();
|
|
140
143
|
});
|
|
141
144
|
|
|
145
|
+
test("the users and workspaces table resources declare exactly the foreign keys the migrations create", async () => {
|
|
146
|
+
const resources = [userProfileTableResource, userSettingsTableResource, ...WORKSPACES_TABLES];
|
|
147
|
+
assert.deepEqual(await checkForeignKeys({ knex, resources, tables: TABLES }), { missing: [], undeclared: [] });
|
|
148
|
+
});
|
|
149
|
+
|
|
142
150
|
after(async () => {
|
|
143
151
|
if (!knex) return;
|
|
144
152
|
try {
|