@jskit-ai/resource-runtime 0.2.15 → 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,8 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
- The resource runtime answers `tableResource(name)`: the table resource a feature owns under that name, or null. The CRUD contracts registry checks at boot, through it, what each contract's includes list of the tables they include.
|
|
6
|
+
- The MariaDB many-row race tests read `INNODB_TRX` every 150 ms, where they polled it every 25 ms: InnoDB refreshes its copy of that table only when nothing has read it for 0.1 s, so the tests read the copy from before the writers reached the row's lock until their 10 s bound ran out, on any server whose test user may read it (CI's root).
|
|
5
7
|
- Depends on json-rest-api 3.1.1 exactly (from 3.1.0), from the registry with its published integrity: a sort on the ID, or on a required attribute stored in its own table, carries no null placement, so PostgreSQL and MariaDB read a descending page from an index instead of sorting every matching row.
|
|
6
8
|
- A handle's `joinSource()` carries the table's ownership fields (`workspaceId`, `userId`) as join keys, hidden or not, and `column()` names them: a report joining another owner's scoped rows on the workspace, such as a system job reading each workspace's settings beside its bookings, was refused (`contactRoles.joinSource() carries no hidden field, so it has no column for "workspaceId"`). They name the caller's own scope, so nothing secret leaves the owner; every other hidden column stays out, and `column()` still refuses it.
|
|
7
9
|
- Depends on json-rest-api 3.1.0 exactly (from 3.0.1), from the registry with its published integrity: `lockMode: "noKeyUpdate"`, ON CONFLICT on the matching unique index's exact columns, the PostgreSQL merge race on an uncommitted insert, and the `xid8` field type the change horizon reads.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jskit-ai/resource-runtime",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.17",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=24.0.0"
|
|
@@ -15,8 +15,8 @@
|
|
|
15
15
|
"./locales/en.json": "./locales/en.json"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@jskit-ai/resource-core": "0.1.
|
|
19
|
-
"@jskit-ai/resource-crud-core": "0.1.
|
|
18
|
+
"@jskit-ai/resource-core": "0.1.207",
|
|
19
|
+
"@jskit-ai/resource-crud-core": "0.1.207",
|
|
20
20
|
"json-rest-api": "3.1.1"
|
|
21
21
|
},
|
|
22
22
|
"description": "The resource runtime: features own their tables through it and read and write them with scoped handles on json-rest-api.",
|
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
}
|
|
65
65
|
},
|
|
66
66
|
"peerDependencies": {
|
|
67
|
-
"@jskit-ai/database-runtime": "0.1.
|
|
68
|
-
"@jskit-ai/kernel": "0.2.
|
|
67
|
+
"@jskit-ai/database-runtime": "0.1.265",
|
|
68
|
+
"@jskit-ai/kernel": "0.2.16"
|
|
69
69
|
}
|
|
70
70
|
}
|
|
@@ -122,8 +122,12 @@ function createResourceRuntime({ api, requestRowLimit = DEFAULT_REQUEST_ROW_LIMI
|
|
|
122
122
|
}
|
|
123
123
|
}
|
|
124
124
|
|
|
125
|
-
|
|
126
|
-
|
|
125
|
+
/**
|
|
126
|
+
* The table resource a feature owns under `name`, or null: a handle shapes included records with it, and the CRUD
|
|
127
|
+
* contracts check at boot what their includes list of it.
|
|
128
|
+
* @param {string} name
|
|
129
|
+
*/
|
|
130
|
+
function tableResource(name) {
|
|
127
131
|
return ownedByName.get(name)?.resource ?? null;
|
|
128
132
|
}
|
|
129
133
|
|
|
@@ -246,7 +250,7 @@ function createResourceRuntime({ api, requestRowLimit = DEFAULT_REQUEST_ROW_LIMI
|
|
|
246
250
|
});
|
|
247
251
|
ownerByTable.set(resource.tableName, featureId);
|
|
248
252
|
await api.addResource(resource.name, scopes[index]);
|
|
249
|
-
handles[resource.name] = createResourceHandle({ api, resource, hooks: entry.hooks, settings, resourceNamed });
|
|
253
|
+
handles[resource.name] = createResourceHandle({ api, resource, hooks: entry.hooks, settings, resourceNamed: tableResource });
|
|
250
254
|
}
|
|
251
255
|
Object.defineProperty(handles, "contributeRowPolicy", {
|
|
252
256
|
value: (name, policy) => contributeRowPolicy(featureId, name, policy),
|
|
@@ -292,6 +296,7 @@ function createResourceRuntime({ api, requestRowLimit = DEFAULT_REQUEST_ROW_LIMI
|
|
|
292
296
|
return Object.freeze({
|
|
293
297
|
own,
|
|
294
298
|
ownedTables,
|
|
299
|
+
tableResource,
|
|
295
300
|
declareSystemScope,
|
|
296
301
|
systemScopes
|
|
297
302
|
});
|
|
@@ -66,12 +66,18 @@ async function ownDatabase(context, suffix, { snapshotIsolation = false } = {})
|
|
|
66
66
|
|
|
67
67
|
const pause = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
68
68
|
|
|
69
|
+
// InnoDB answers INNODB_TRX from a copy it refreshes only when nothing has read it for 0.1 s, so a poll more frequent
|
|
70
|
+
// than that reads one copy for good: on MariaDB 11.4, polled every 25 ms, it still showed one writer waiting after
|
|
71
|
+
// 4 s while PROCESSLIST showed both in their locking read.
|
|
72
|
+
const TRX_POLL_MS = 150;
|
|
73
|
+
|
|
69
74
|
/**
|
|
70
|
-
* Waits until `count` transactions on this test's database wait for a row lock
|
|
71
|
-
*
|
|
75
|
+
* Waits until `count` transactions on this test's database wait for a row lock, reading INNODB_TRX every
|
|
76
|
+
* TRX_POLL_MS so each read is fresh. A server that keeps INNODB_TRX from the test user (it needs PROCESS) gets a
|
|
77
|
+
* fixed pause instead, long enough for both writers to reach the lock.
|
|
72
78
|
*/
|
|
73
79
|
async function bothWaiting(knex, count) {
|
|
74
|
-
for (let waited = 0; waited < 10_000; waited +=
|
|
80
|
+
for (let waited = 0; waited < 10_000; waited += TRX_POLL_MS) {
|
|
75
81
|
let waiting;
|
|
76
82
|
try {
|
|
77
83
|
const [[row]] = await knex.raw(
|
|
@@ -84,7 +90,7 @@ async function bothWaiting(knex, count) {
|
|
|
84
90
|
return;
|
|
85
91
|
}
|
|
86
92
|
if (waiting >= count) return;
|
|
87
|
-
await pause(
|
|
93
|
+
await pause(TRX_POLL_MS);
|
|
88
94
|
}
|
|
89
95
|
assert.fail(`${count} writers did not reach the row's lock within 10 s`);
|
|
90
96
|
}
|
|
@@ -63,7 +63,7 @@ async function createFixture(t, { requestRowLimit, owns = [noteResource()] } = {
|
|
|
63
63
|
return { knex, runtime, resources, notes: resources.notes, systemContext };
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
test("own() answers a handle per resource and refuses a second owner of a table or name", async (t) => {
|
|
66
|
+
test("own() answers a handle per resource and refuses a second owner of a table or name; tableResource() answers an owned resource by name", async (t) => {
|
|
67
67
|
const { runtime, resources } = await createFixture(t);
|
|
68
68
|
assert.deepEqual(Object.keys(resources), ["notes"]);
|
|
69
69
|
assert.equal(typeof resources.contributeRowPolicy, "function");
|
|
@@ -71,6 +71,8 @@ test("own() answers a handle per resource and refuses a second owner of a table
|
|
|
71
71
|
await assert.rejects(runtime.own("other.feature", [noteResource({ name: "otherNotes" })]), DuplicateOwnerError);
|
|
72
72
|
await assert.rejects(runtime.own("other.feature", [{ resource: noteResource({ name: "x", tableName: "x" }), autofilter: "workspace" }]), /does not take "autofilter"/u);
|
|
73
73
|
assert.deepEqual(runtime.ownedTables(), [{ name: "notes", tableName: "notes", featureId: "notes.feature" }]);
|
|
74
|
+
assert.equal(runtime.tableResource("notes").tableName, "notes");
|
|
75
|
+
assert.equal(runtime.tableResource("otherNotes"), null);
|
|
74
76
|
});
|
|
75
77
|
|
|
76
78
|
test("a call without a context is refused before anything runs", async (t) => {
|