@protobase/server 0.22.1 → 0.22.3
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/dist/view-related.js +11 -1
- package/package.json +4 -4
package/dist/view-related.js
CHANGED
|
@@ -46,6 +46,16 @@ const openErrors = (item, models) => {
|
|
|
46
46
|
if (!far) return [`open: unknown resource "${field.relation.resource}"`];
|
|
47
47
|
return far.primaryKey.length === 1 ? [] : [`open: ${far.name} has a composite key, so its records cannot be opened from "${item.open}"`];
|
|
48
48
|
};
|
|
49
|
+
/** What is wrong with matching `field` of the listed records against the `from` field of the owner's record. */
|
|
50
|
+
const fromErrors = (item, from, owner, target) => {
|
|
51
|
+
if (item.through) return ["from and through cannot be combined"];
|
|
52
|
+
const source = Object.hasOwn(owner.fields, from) ? owner.fields[from] : void 0;
|
|
53
|
+
if (!source) return [`from: unknown field "${from}" on ${owner.name}`];
|
|
54
|
+
if (source.sensitive) return [`from: "${from}" on ${owner.name} is sensitive`];
|
|
55
|
+
const match = Object.hasOwn(target.fields, item.field) ? target.fields[item.field] : void 0;
|
|
56
|
+
if (!match) return [];
|
|
57
|
+
return source.type === match.type && source.relation?.resource === match.relation?.resource ? [] : [`from: "${from}" on ${owner.name} and "${item.field}" on ${target.name} do not hold the same kind of value`];
|
|
58
|
+
};
|
|
49
59
|
/**
|
|
50
60
|
* What is wrong with a related section on the record page of `resource`, against these models; empty when it can be
|
|
51
61
|
* shown. Against the full models it checks the config; against a caller's models, whether that caller can use it.
|
|
@@ -56,7 +66,7 @@ const relatedErrors = (item, resource, models) => {
|
|
|
56
66
|
if (!owner || !target) return [`unknown resource "${owner ? item.resource : resource}"`];
|
|
57
67
|
if (owner.primaryKey.length !== 1) return [`${resource} has a composite key, so a related section cannot match it`];
|
|
58
68
|
return [
|
|
59
|
-
...item.through ? [...throughErrors(item.through, resource, models), ...matchErrors(target, item.field)] : matchErrors(target, item.field, resource),
|
|
69
|
+
...item.from !== void 0 ? [...matchErrors(target, item.field), ...fromErrors(item, item.from, owner, target)] : item.through ? [...throughErrors(item.through, resource, models), ...matchErrors(target, item.field)] : matchErrors(target, item.field, resource),
|
|
60
70
|
...filterErrors(target, item.filter).map((error) => `filter: ${error}`),
|
|
61
71
|
...sortErrors(target, item.sort).map((error) => `sort: ${error}`),
|
|
62
72
|
...(item.columns ?? []).flatMap((column) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@protobase/server",
|
|
3
|
-
"version": "0.22.
|
|
3
|
+
"version": "0.22.3",
|
|
4
4
|
"description": "The Protobase REST API as a Hono app, with Better Auth sign-in.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -31,9 +31,9 @@
|
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@better-auth/passkey": "^1.7.7",
|
|
33
33
|
"@better-auth/sso": "^1.7.7",
|
|
34
|
-
"@protobase/layout": "0.22.
|
|
35
|
-
"@protobase/query": "0.22.
|
|
36
|
-
"@protobase/schema": "0.22.
|
|
34
|
+
"@protobase/layout": "0.22.3",
|
|
35
|
+
"@protobase/query": "0.22.3",
|
|
36
|
+
"@protobase/schema": "0.22.3",
|
|
37
37
|
"@react-email/render": "^2.1.0",
|
|
38
38
|
"@scalar/hono-api-reference": "^0.12.10",
|
|
39
39
|
"@sentry/core": "^11.7.0",
|