@jskit-ai/console-core 0.2.16 → 0.2.17

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
@@ -2,6 +2,7 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ - console_settings declares its foreign key, owner_user_id to users (`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. `usersForeignKeyMigration.test.js` proves it matches the migrations.
5
6
  - `console.settings` reads and writes its record with only the caller's context and transaction (`passedOn(options)`) and its own settings: a caller's `format`, `lockVersion` or `returning` no longer reaches its `get` and `patch`.
6
7
  - `@jskit-ai/database-runtime` and `@jskit-ai/resource-runtime` are peer dependencies, required and at the same versions, where they were dependencies: its settings are a table resource, 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.
7
8
  - **Breaking (data-access redesign).** The console settings operations are an API contract, `consoleSettingsContract`, which replaces `consoleSettingsResource`, with the two its routes serve: view (GET) and patch (PATCH), each with the method of the route that serves it.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jskit-ai/console-core",
3
- "version": "0.2.16",
3
+ "version": "0.2.17",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "test": "jskit test"
@@ -12,8 +12,8 @@
12
12
  "./locales/en.json": "./locales/en.json"
13
13
  },
14
14
  "dependencies": {
15
- "@jskit-ai/resource-core": "0.1.205",
16
- "@jskit-ai/users-core": "0.2.16",
15
+ "@jskit-ai/resource-core": "0.1.206",
16
+ "@jskit-ai/users-core": "0.2.17",
17
17
  "json-rest-schema": "^1.0.17"
18
18
  },
19
19
  "description": "Console runtime: console settings schema, bootstrap flags, actions, and HTTP routes.",
@@ -97,10 +97,10 @@
97
97
  }
98
98
  },
99
99
  "peerDependencies": {
100
- "@jskit-ai/auth-core": "0.2.14",
101
- "@jskit-ai/database-runtime": "0.1.263",
102
- "@jskit-ai/http-runtime": "0.2.14",
103
- "@jskit-ai/kernel": "0.2.14",
104
- "@jskit-ai/resource-runtime": "0.2.12"
100
+ "@jskit-ai/auth-core": "0.2.15",
101
+ "@jskit-ai/database-runtime": "0.1.264",
102
+ "@jskit-ai/http-runtime": "0.2.15",
103
+ "@jskit-ai/kernel": "0.2.15",
104
+ "@jskit-ai/resource-runtime": "0.2.13"
105
105
  }
106
106
  }
@@ -7,6 +7,7 @@ const consoleSettingsTableResource = defineTableResource({
7
7
  name: "consoleSettings",
8
8
  tableName: "console_settings",
9
9
  ownership: "public",
10
+ foreignKeys: [{ columns: ["ownerUserId"], referencedTableName: "users" }],
10
11
  schema: {
11
12
  ownerUserId: { type: "id", nullable: true },
12
13
  createdAt: { type: "dateTime", storage: { writeSerializer: "datetime-utc" } },
@@ -3,6 +3,8 @@ import test from "node:test";
3
3
  import knex from "knex";
4
4
  import initialMigration from "../migrations/console_core_generic_initial.cjs";
5
5
  import usersForeignKeyMigration from "../migrations/constraints/console_core_users_foreign_key.cjs";
6
+ import { checkForeignKeys } from "@jskit-ai/resource-runtime/server";
7
+ import { consoleSettingsTableResource } from "../src/shared/resources/consoleSettingsTableResource.js";
6
8
 
7
9
  async function usersKeys(db) {
8
10
  return (await db.raw("PRAGMA foreign_key_list(console_settings)"))
@@ -24,6 +26,9 @@ test("console_settings is created before users exists and gets its users key in
24
26
  const key = [{ from: "owner_user_id", to: "id", onDelete: "SET NULL" }];
25
27
  assert.deepEqual(await usersKeys(db), key);
26
28
  assert.equal((await db("console_settings")).length, 1);
29
+ // The table resource declares that key, and the table has no other.
30
+ assert.deepEqual(await checkForeignKeys({ knex: db, resources: [consoleSettingsTableResource], tables: ["console_settings"] }),
31
+ { missing: [], undeclared: [] });
27
32
 
28
33
  // A table that already has its users key, as databases migrated before this phase do, gains no duplicate.
29
34
  await usersForeignKeyMigration.up(db);