@jskit-ai/console-core 0.2.83 → 0.2.85

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jskit-ai/console-core",
3
- "version": "0.2.83",
3
+ "version": "0.2.85",
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.231",
16
- "@jskit-ai/users-core": "0.2.83",
15
+ "@jskit-ai/resource-core": "0.1.232",
16
+ "@jskit-ai/users-core": "0.2.85",
17
17
  "json-rest-schema": "^1.0.20"
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.45",
101
- "@jskit-ai/database-runtime": "0.1.298",
102
- "@jskit-ai/http-runtime": "0.2.41",
103
- "@jskit-ai/kernel": "0.2.40",
104
- "@jskit-ai/resource-runtime": "0.2.65"
100
+ "@jskit-ai/auth-core": "0.2.47",
101
+ "@jskit-ai/database-runtime": "0.1.299",
102
+ "@jskit-ai/http-runtime": "0.2.43",
103
+ "@jskit-ai/kernel": "0.2.41",
104
+ "@jskit-ai/resource-runtime": "0.2.66"
105
105
  }
106
106
  }
@@ -1,7 +1,6 @@
1
1
  import assert from "node:assert/strict";
2
2
  import test from "node:test";
3
- import knexLib from "knex";
4
- import { requireTestDatabase } from "@jskit-ai/database-runtime/server/testDatabases";
3
+ import { createPackageTestKnex, requireTestDatabase } from "@jskit-ai/database-runtime/server/testDatabases";
5
4
  import { createTestResourceRuntime } from "@jskit-ai/resource-runtime/test";
6
5
  import migration from "../migrations/console_core_generic_initial.cjs";
7
6
  import { createRepository } from "../src/server/consoleSettings/consoleSettingsRepository.js";
@@ -12,24 +11,12 @@ import { createConsoleRuntime } from "../src/server/consoleRuntime.js";
12
11
  // runtime's services built on it, pinned before the repository moves onto a table resource: the singleton's shape, the
13
12
  // first owner winning, its refusals and errors, and joining a caller's transaction.
14
13
 
15
- // The runtime's own MySQL connection settings (database-runtime's resolveKnexConnectionFromEnvironment).
16
- const RUNTIME_MYSQL = Object.freeze({ supportBigNumbers: true, bigNumberStrings: true, dateStrings: ["DATE"], timezone: "Z" });
17
14
  const ISO_SECONDS = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.000Z$/u;
18
15
  const LONG_AGO = "2001-02-03T04:05:06.000Z";
19
16
 
20
- /** A migrated database of the test's own, beside TEST_DB_NAME, dropped after the test. */
21
- async function ownDatabase(context, suffix) {
22
- const name = `${requireTestDatabase(process.env)}_${suffix}`;
23
- const server = { host: process.env.DB_HOST, port: Number(process.env.DB_PORT) || 3306, user: process.env.DB_USER, password: process.env.DB_PASSWORD };
24
- const admin = knexLib({ client: "mysql2", connection: server, pool: { min: 0, max: 1 } });
25
- await admin.raw("DROP DATABASE IF EXISTS ??", [name]);
26
- await admin.raw("CREATE DATABASE ??", [name]);
27
- const knex = knexLib({ client: "mysql2", connection: { ...server, database: name, ...RUNTIME_MYSQL }, pool: { min: 0, max: 4 } });
28
- context.after(async () => {
29
- await knex.destroy();
30
- await admin.raw("DROP DATABASE IF EXISTS ??", [name]);
31
- await admin.destroy();
32
- });
17
+ /** A lettered copy of TEST_DB_NAME the test claims (createPackageTestKnex() on MySQL), migrated, dropped after the test. */
18
+ async function ownDatabase(context) {
19
+ const knex = await createPackageTestKnex(context, { environment: { ...process.env, DB_CLIENT: "mysql2" } });
33
20
  await migration.up(knex);
34
21
  // Seeded long ago, so the repository's own updates of updated_at show.
35
22
  await knex("console_settings").where({ id: 1 }).update({ updated_at: "2001-02-03 04:05:06" });
@@ -48,7 +35,7 @@ const thisSecond = () => Math.floor(Date.now() / 1000) * 1000;
48
35
 
49
36
  test("the singleton answers its id, owner, empty settings and ISO timestamps", async (context) => {
50
37
  requireTestDatabase(process.env);
51
- const repository = await repositoryOn(await ownDatabase(context, "da_console_shape"));
38
+ const repository = await repositoryOn(await ownDatabase(context));
52
39
  assert.ok(Object.isFrozen(repository));
53
40
  assert.deepEqual(Object.keys(repository), ["withTransaction", "getSingleton", "ensureOwnerUserId", "updateSingleton"]);
54
41
 
@@ -73,7 +60,7 @@ test("the singleton answers its id, owner, empty settings and ISO timestamps", a
73
60
 
74
61
  test("the first owner wins, the same answer comes back after, and anything but a positive id is refused", async (context) => {
75
62
  requireTestDatabase(process.env);
76
- const repository = await repositoryOn(await ownDatabase(context, "da_console_owner"));
63
+ const repository = await repositoryOn(await ownDatabase(context));
77
64
 
78
65
  for (const userId of [0, -1, 1.5, "abc", "007", "", null, undefined, Number.MAX_SAFE_INTEGER + 1]) {
79
66
  await assert.rejects(repository.ensureOwnerUserId(userId), {
@@ -98,7 +85,7 @@ test("the first owner wins, the same answer comes back after, and anything but a
98
85
 
99
86
  test("two first owners at once both get the same winner", async (context) => {
100
87
  requireTestDatabase(process.env);
101
- const repository = await repositoryOn(await ownDatabase(context, "da_console_race"));
88
+ const repository = await repositoryOn(await ownDatabase(context));
102
89
  const answers = await Promise.all([repository.ensureOwnerUserId(3), repository.ensureOwnerUserId(4)]);
103
90
  assert.equal(answers[0], answers[1]);
104
91
  assert.ok(["3", "4"].includes(answers[0]));
@@ -107,7 +94,7 @@ test("two first owners at once both get the same winner", async (context) => {
107
94
 
108
95
  test("the repository joins its caller's transaction: a rollback undoes the owner and the touch", async (context) => {
109
96
  requireTestDatabase(process.env);
110
- const repository = await repositoryOn(await ownDatabase(context, "da_console_trx"));
97
+ const repository = await repositoryOn(await ownDatabase(context));
111
98
 
112
99
  const failure = new Error("rolled back");
113
100
  await assert.rejects(repository.withTransaction({}, async (txOptions) => {
@@ -127,7 +114,7 @@ test("the repository joins its caller's transaction: a rollback undoes the owner
127
114
 
128
115
  test("without its row, every call fails with the same plain error", async (context) => {
129
116
  requireTestDatabase(process.env);
130
- const knex = await ownDatabase(context, "da_console_missing");
117
+ const knex = await ownDatabase(context);
131
118
  const repository = await repositoryOn(knex);
132
119
  await knex("console_settings").where({ id: 1 }).del();
133
120
  const missing = (error) => {
@@ -144,7 +131,7 @@ test("without its row, every call fails with the same plain error", async (conte
144
131
 
145
132
  test("the console runtime's services make the first signed-in user the owner and refuse everyone else", async (context) => {
146
133
  requireTestDatabase(process.env);
147
- const repository = await repositoryOn(await ownDatabase(context, "da_console_runtime"));
134
+ const repository = await repositoryOn(await ownDatabase(context));
148
135
  const { services } = createConsoleRuntime({ consoleSettingsRepository: repository });
149
136
  const refused = (status, code, message) => (error) => {
150
137
  assert.equal(error.name, "AppError");