@protobase/server 0.21.10 → 0.21.11
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/check-views.js +10 -1
- package/dist/view-access.js +8 -5
- package/package.json +4 -4
package/dist/check-views.js
CHANGED
|
@@ -6,7 +6,9 @@ import { chartErrors } from "./view-chart.js";
|
|
|
6
6
|
import { mapDisplayErrors, mapErrors } from "./view-map.js";
|
|
7
7
|
import { relatedColumnErrors } from "./view-related-column.js";
|
|
8
8
|
import { editableErrors } from "./view-editable.js";
|
|
9
|
+
import { conditionProblems } from "@protobase/layout";
|
|
9
10
|
import { actionInputErrors, addressErrors, addressPlaceholders, boardErrors, calendarErrors, chartFields, displayFields, fieldRefsIn, hrefField, hrefPlaceholders, linkActionError, promptError, promptFields } from "@protobase/schema/internal";
|
|
11
|
+
import { isRecordCondition } from "@protobase/schema";
|
|
10
12
|
//#region src/check-views.ts
|
|
11
13
|
const linkFields = (run) => run?.kind !== "link" ? [] : "to" in run ? addressPlaceholders(run.to) : hrefPlaceholders(run.href);
|
|
12
14
|
const actionFields = (run) => {
|
|
@@ -123,6 +125,12 @@ const galleryErrors = (item, resource, model, models) => {
|
|
|
123
125
|
const image = item.image === void 0 ? void 0 : model.fields[item.image];
|
|
124
126
|
return [...image && image.type !== "file" ? [`"${item.image}" is not a file field`] : [], ...item.photos ? cardPhotosErrors(item.photos, resource, models).map((error) => `photos: ${error}`) : []];
|
|
125
127
|
};
|
|
128
|
+
const conditionErrors = (view, models) => view.layout.flatMap((item) => {
|
|
129
|
+
if (item.kind !== "section" && item.kind !== "sidebar" && item.kind !== "related") return [];
|
|
130
|
+
if (!isRecordCondition(item.when)) return [];
|
|
131
|
+
const place = item.kind === "sidebar" ? "sidebar" : `${item.kind} "${item.title}"`;
|
|
132
|
+
return conditionProblems(item.when, view.resource, models).map((error) => `${place}: ${error}`);
|
|
133
|
+
});
|
|
126
134
|
const listOfErrors = (model, name, models) => {
|
|
127
135
|
const target = models[model.fields[name]?.relation?.resource ?? ""];
|
|
128
136
|
if (!target) return [`"${name}" points at no resource of the app`];
|
|
@@ -133,7 +141,7 @@ const listOfErrors = (model, name, models) => {
|
|
|
133
141
|
* field the resource does not have, labels or colours values its enum does not have, shows a field with a field type of
|
|
134
142
|
* `fieldTypes` (each with the storage types it shows) that does not show it,
|
|
135
143
|
* edits a list column in its cell that is not a field with an editor of one line the API may write,
|
|
136
|
-
* has a related section or related list column, a cards display's or gallery's photos or a cards display's favorite button, a `listOf`, a "Save search" button or a
|
|
144
|
+
* has a section, related section or sidebar whose `when` condition names what the app does not have, a related section or related list column, a cards display's or gallery's photos or a cards display's favorite button, a `listOf`, a "Save search" button or a
|
|
137
145
|
* `searchesOf` that do not fit the resources, cards
|
|
138
146
|
* displays of one list that name different photos, a chart per value that cannot group or add up its fields, a map that cannot show the
|
|
139
147
|
* record's position or a map display that cannot find the records in its view, a board whose columns are no filterable enum, a calendar whose dates are no filterable date or timestamp fields, a link to an address the app does not have, an AI action that cannot write its field, action inputs that do not fit, or a create page that is not one of `pages`.
|
|
@@ -168,6 +176,7 @@ const checkViews = (registry, views, pages = [], fieldTypes = {}) => {
|
|
|
168
176
|
...listEditErrors(view, model),
|
|
169
177
|
...widgetErrors(view, model, fieldTypes),
|
|
170
178
|
...related,
|
|
179
|
+
...conditionErrors(view, models),
|
|
171
180
|
...photos,
|
|
172
181
|
...favorites,
|
|
173
182
|
...listOf,
|
package/dist/view-access.js
CHANGED
|
@@ -3,10 +3,12 @@ import { cardPhotosErrors } from "./view-card-photos.js";
|
|
|
3
3
|
import { cardFavoriteErrors } from "./view-card-favorite.js";
|
|
4
4
|
import { searchesOfFor } from "./view-saved-search.js";
|
|
5
5
|
import { relatedColumnErrors } from "./view-related-column.js";
|
|
6
|
-
import { resolveFieldPath } from "@protobase/layout";
|
|
6
|
+
import { conditionReadable, resolveFieldPath } from "@protobase/layout";
|
|
7
7
|
import { addressErrors, chartFields, hrefPlaceholders, navRecentErrors, promptFields, pruneByShape, shapes, tableDisplay } from "@protobase/schema/internal";
|
|
8
|
+
import { isRecordCondition } from "@protobase/schema";
|
|
8
9
|
//#region src/view-access.ts
|
|
9
10
|
const pruneRelated = (item, resource, models) => {
|
|
11
|
+
if (isRecordCondition(item.when) && !conditionReadable(item.when, resource, models)) return void 0;
|
|
10
12
|
const { columns, open, ...rest } = item;
|
|
11
13
|
const visible = models[item.resource] ? columns?.filter((column) => resolveFieldPath(models, item.resource, column).ok) : void 0;
|
|
12
14
|
const narrowed = visible && visible.length > 0 ? {
|
|
@@ -22,6 +24,7 @@ const pruneRelated = (item, resource, models) => {
|
|
|
22
24
|
} : narrowed;
|
|
23
25
|
return relatedErrors(opened, resource, models).length === 0 ? opened : void 0;
|
|
24
26
|
};
|
|
27
|
+
const recordWhenShape = (resource, models) => shapes.map((when) => isRecordCondition(when) && !conditionReadable(when, resource, models) ? void 0 : when);
|
|
25
28
|
const pruneGallery = (item, resource, model, models) => {
|
|
26
29
|
const image = item.image !== void 0 && Object.hasOwn(model.fields, item.image) ? item.image : void 0;
|
|
27
30
|
const photos = item.photos && cardPhotosErrors(item.photos, resource, models).length === 0 ? item.photos : void 0;
|
|
@@ -162,14 +165,14 @@ const layoutShape = (resource, model, models) => shapes.oneOf({
|
|
|
162
165
|
help: shapes.data,
|
|
163
166
|
helpWhen: shapes.data,
|
|
164
167
|
presentation: shapes.data,
|
|
165
|
-
when:
|
|
168
|
+
when: recordWhenShape(resource, models),
|
|
166
169
|
fields: shapes.list(shapes.field, { nonEmpty: true })
|
|
167
|
-
}, { requires: ["fields"] }),
|
|
170
|
+
}, { requires: ["fields", "when"] }),
|
|
168
171
|
sidebar: shapes.object({
|
|
169
172
|
kind: shapes.data,
|
|
170
173
|
fields: shapes.list(shapes.field, { nonEmpty: true }),
|
|
171
|
-
when:
|
|
172
|
-
}, { requires: ["fields"] }),
|
|
174
|
+
when: recordWhenShape(resource, models)
|
|
175
|
+
}, { requires: ["fields", "when"] }),
|
|
173
176
|
related: shapes.map((item) => pruneRelated(item, resource, models)),
|
|
174
177
|
custom: shapes.object({
|
|
175
178
|
kind: shapes.data,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@protobase/server",
|
|
3
|
-
"version": "0.21.
|
|
3
|
+
"version": "0.21.11",
|
|
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.21.
|
|
35
|
-
"@protobase/query": "0.21.
|
|
36
|
-
"@protobase/schema": "0.21.
|
|
34
|
+
"@protobase/layout": "0.21.11",
|
|
35
|
+
"@protobase/query": "0.21.11",
|
|
36
|
+
"@protobase/schema": "0.21.11",
|
|
37
37
|
"@react-email/render": "^2.1.0",
|
|
38
38
|
"@scalar/hono-api-reference": "^0.12.10",
|
|
39
39
|
"@sentry/core": "^11.7.0",
|