@jskit-ai/crud-core 0.2.21 → 0.2.23
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,9 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
- Depends on json-rest-api 3.1.3 exactly (from 3.1.2), from the registry with its published integrity: a write checks each linked target type with one read of the targets' ids (their minimal records only for a target resource with a `checkPermissions` hook), which also takes the shared lock on the belongs-to and polymorphic targets it stores, before `beforeSchemaValidate` rather than after the `beforeDataCall` hooks; in a system context a belongs-to its declared foreign key protects is left to that key, so a missing target there fails with the database's foreign key error instead of `not_found`. json-rest-api now asks for json-rest-schema ^1.0.20.
|
|
6
|
+
- Depends on json-rest-api 3.1.2 exactly (from 3.1.1), from the registry with its published integrity: json-rest-api bounds a blob field itself too (`maxBytes` required, a blob answered only where `fields` names it, at most 16 MiB of named blobs per read, none in an include, `queryAll` or HTTP response, many-row write statements chunked by blob bytes, and the MySQL/MariaDB column type chosen by `maxBytes`), its `contains`, `startsWith` and `endsWith` filters match `%`, `_` and `\` literally on every database, a relationship write checks and locks each related type's targets in one query, and an AnyAPI many-to-many read costs its own link rows instead of growing with the square of them.
|
|
7
|
+
- A patch naming a linked record that does not exist (a `lookup` field's id with no such row) is refused as that record missing, the error json-rest-api raises with its `resourceType` and `resourceId`, where the CRUD service answered `404 Document not found.` as if the patched record itself were missing. View, patch and delete still answer the 404 (or null for delete) for their own record missing or out of scope.
|
|
5
8
|
- A CRUD contract whose `includeFields` lists a link of the included record as a field is refused at boot, at every depth, with an error that names the form to use: a belongs-to field by its key (`"locationId"`) or its relationship (`"location"`), or a collection relation. A JSON:API document answers a link under the record's relationships, never among its attributes, so such an entry never showed and the included record read as if it had no link, which emptied an app's board grouped by it. List it as `{ location: [] }`, which answers the linked id, with the fields to show of the linked record inside it. `CrudContractsProvider` checks every registered contract when it seals the registry at boot, once every feature owns its tables, against the table resources `runtime.resources` answers; a level whose table no feature owns is left alone.
|
|
6
9
|
- 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.
|
|
7
10
|
- 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/crud-core",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.23",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=24.0.0"
|
|
@@ -20,10 +20,10 @@
|
|
|
20
20
|
"./locales/en.json": "./locales/en.json"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@jskit-ai/resource-core": "0.1.
|
|
24
|
-
"@jskit-ai/resource-crud-core": "0.1.
|
|
25
|
-
"json-rest-api": "3.1.
|
|
26
|
-
"json-rest-schema": "^1.0.
|
|
23
|
+
"@jskit-ai/resource-core": "0.1.209",
|
|
24
|
+
"@jskit-ai/resource-crud-core": "0.1.209",
|
|
25
|
+
"json-rest-api": "3.1.3",
|
|
26
|
+
"json-rest-schema": "^1.0.20"
|
|
27
27
|
},
|
|
28
28
|
"description": "Shared server-side CRUD service, repository, route, and query helpers.",
|
|
29
29
|
"jskit": {
|
|
@@ -49,8 +49,8 @@
|
|
|
49
49
|
}
|
|
50
50
|
},
|
|
51
51
|
"peerDependencies": {
|
|
52
|
-
"@jskit-ai/http-runtime": "0.2.
|
|
53
|
-
"@jskit-ai/kernel": "0.2.
|
|
54
|
-
"@jskit-ai/resource-runtime": "0.2.
|
|
52
|
+
"@jskit-ai/http-runtime": "0.2.18",
|
|
53
|
+
"@jskit-ai/kernel": "0.2.18",
|
|
54
|
+
"@jskit-ai/resource-runtime": "0.2.20"
|
|
55
55
|
}
|
|
56
56
|
}
|
|
@@ -9,9 +9,9 @@
|
|
|
9
9
|
"./shared": "./src/shared/index.js"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@jskit-ai/crud-core": "0.2.
|
|
13
|
-
"@jskit-ai/resource-core": "0.1.
|
|
14
|
-
"@jskit-ai/resource-crud-core": "0.1.
|
|
12
|
+
"@jskit-ai/crud-core": "0.2.23",
|
|
13
|
+
"@jskit-ai/resource-core": "0.1.209",
|
|
14
|
+
"@jskit-ai/resource-crud-core": "0.1.209"
|
|
15
15
|
},
|
|
16
16
|
"jskit": {
|
|
17
17
|
"kind": "runtime",
|
|
@@ -22,8 +22,11 @@ function requireDocument(document) {
|
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
// json-rest-api's not-found error, classified by its code.
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
// A not-found naming another resource, such as a link to a record that does not exist, is that resource's own
|
|
26
|
+
// refusal, not this record missing.
|
|
27
|
+
function isNotFound(error, resourceName) {
|
|
28
|
+
const type = error?.details?.resourceType;
|
|
29
|
+
return error?.code === "REST_API_RESOURCE" && error?.subtype === "not_found" && (type == null || type === resourceName);
|
|
27
30
|
}
|
|
28
31
|
|
|
29
32
|
/**
|
|
@@ -270,7 +273,7 @@ function createCrudService({ repository, crud }) {
|
|
|
270
273
|
try {
|
|
271
274
|
return answer(requireDocument(await repository.get(recordId, buildJsonRestQueryParams(resourceName, query), documentOptions(options))));
|
|
272
275
|
} catch (error) {
|
|
273
|
-
throw isNotFound(error) ? documentNotFound() : error;
|
|
276
|
+
throw isNotFound(error, resourceName) ? documentNotFound() : error;
|
|
274
277
|
}
|
|
275
278
|
}
|
|
276
279
|
|
|
@@ -293,7 +296,7 @@ function createCrudService({ repository, crud }) {
|
|
|
293
296
|
await repository.patch(recordId, payload, documentOptions(options))
|
|
294
297
|
));
|
|
295
298
|
} catch (error) {
|
|
296
|
-
throw isNotFound(error) ? documentNotFound() : error;
|
|
299
|
+
throw isNotFound(error, resourceName) ? documentNotFound() : error;
|
|
297
300
|
}
|
|
298
301
|
}
|
|
299
302
|
|
|
@@ -306,7 +309,7 @@ function createCrudService({ repository, crud }) {
|
|
|
306
309
|
try {
|
|
307
310
|
return await repository.delete(recordId, passedOn(options));
|
|
308
311
|
} catch (error) {
|
|
309
|
-
if (isNotFound(error)) return null;
|
|
312
|
+
if (isNotFound(error, resourceName)) return null;
|
|
310
313
|
throw error;
|
|
311
314
|
}
|
|
312
315
|
}
|
|
@@ -165,7 +165,7 @@ async function createIncludeFixture(t, { authorOutput = "optional", authorsShow
|
|
|
165
165
|
return createCrudService({ repository: resources.notes, crud });
|
|
166
166
|
}
|
|
167
167
|
|
|
168
|
-
test("a record a form saves back as the CRUD service showed it keeps its link to an author the writer cannot see", async (t) => {
|
|
168
|
+
test("a record a form saves back as the CRUD service showed it keeps its link to an author the writer cannot see, and a link to a missing author names that author", async (t) => {
|
|
169
169
|
const knex = await testKnex(t);
|
|
170
170
|
await knex.schema.createTable("authors", (table) => {
|
|
171
171
|
table.increments("id");
|
|
@@ -220,6 +220,10 @@ test("a record a form saves back as the CRUD service showed it keeps its link to
|
|
|
220
220
|
assert.equal(await authorOf(2), 1);
|
|
221
221
|
await service.patch("2", { authorId: null }, {});
|
|
222
222
|
assert.equal(await authorOf(2), null);
|
|
223
|
+
// A link to an author that does not exist is refused as that author missing, not as the note missing.
|
|
224
|
+
await assert.rejects(service.patch("2", { authorId: "99" }, {}), (error) => error.code === "REST_API_RESOURCE" &&
|
|
225
|
+
error.subtype === "not_found" && error.details.resourceType === "authors" && error.details.resourceId === "99");
|
|
226
|
+
await assert.rejects(service.patch("99", { title: "Gone" }, {}), { status: 404, code: "crud.document.notFound" });
|
|
223
227
|
});
|
|
224
228
|
|
|
225
229
|
test("an included record shows only its id, and a relationship the contract does not name is left out", async (t) => {
|