@protobase/layout 0.21.9 → 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.
@@ -0,0 +1,11 @@
1
+ import { ResourceModel } from "@protobase/schema";
2
+ //#region src/check-condition.d.ts
3
+ type Models = Record<string, ResourceModel>;
4
+ /**
5
+ * What a `when` condition names that the models do not have: a syntax error, a resource it counts that is not one, a
6
+ * field path of `resource`, the record around it, that does not resolve. Without a record, it can only count records.
7
+ */
8
+ export declare const conditionProblems: (when: string, resource: string | undefined, models: Models) => string[];
9
+ /** Whether a caller whose `models` are all they may see can evaluate the condition: it parses and every name it uses is theirs. */
10
+ export declare const conditionReadable: (when: string, resource: string | undefined, models: Models) => boolean;
11
+ //#endregion
@@ -0,0 +1,31 @@
1
+ import { countedResource, parseCondition } from "./condition.js";
2
+ import { resolveFieldPath } from "./field-path.js";
3
+ //#region src/check-condition.ts
4
+ const countedBy = (models, resource, path) => countedResource(path, (first) => Object.hasOwn((resource === void 0 ? void 0 : models[resource])?.fields ?? {}, first));
5
+ /**
6
+ * What a `when` condition names that the models do not have: a syntax error, a resource it counts that is not one, a
7
+ * field path of `resource`, the record around it, that does not resolve. Without a record, it can only count records.
8
+ */
9
+ const conditionProblems = (when, resource, models) => {
10
+ const parsed = parseCondition(when);
11
+ if (!parsed.ok) return [`"when" is not a valid condition: ${parsed.message}`];
12
+ return parsed.paths.flatMap((name) => {
13
+ const counted = countedBy(models, resource, name);
14
+ if (counted !== void 0) return models[counted] ? [] : [`"when" counts "${counted}", which is not a resource`];
15
+ if (resource === void 0) return [`"when" names "${name}", but outside a record it can only count records, as "<resource>.count"`];
16
+ const resolved = resolveFieldPath(models, resource, name);
17
+ return resolved.ok ? [] : [resolved.message];
18
+ });
19
+ };
20
+ /** Whether a caller whose `models` are all they may see can evaluate the condition: it parses and every name it uses is theirs. */
21
+ const conditionReadable = (when, resource, models) => {
22
+ const parsed = parseCondition(when);
23
+ if (!parsed.ok) return false;
24
+ return parsed.paths.every((name) => {
25
+ const counted = countedBy(models, resource, name);
26
+ if (counted !== void 0) return Boolean(models[counted]);
27
+ return resource !== void 0 && resolveFieldPath(models, resource, name).ok;
28
+ });
29
+ };
30
+ //#endregion
31
+ export { conditionProblems, conditionReadable };
@@ -1,8 +1,8 @@
1
1
  import { dataProps } from "./node.js";
2
- import { countedResource, parseCondition } from "./condition.js";
3
2
  import { walkTree } from "./walk.js";
4
3
  import { chartProblems } from "./check-chart.js";
5
4
  import { resolveFieldPath } from "./field-path.js";
5
+ import { conditionProblems } from "./check-condition.js";
6
6
  import { checkFilter, checkOrderBy, parseFilter, parseOrderBy } from "@protobase/schema";
7
7
  import { addressErrors, fieldRefsIn } from "@protobase/schema/internal";
8
8
  //#region src/check-page.ts
@@ -78,19 +78,7 @@ const nodeProblems = (node, scope, { models, actions, pages }) => {
78
78
  source: linkSource(models, scope)
79
79
  }).map((error) => `to: ${error}`));
80
80
  break;
81
- case "Show": {
82
- const parsed = parseCondition(String(node.props.when));
83
- if (!parsed.ok) break;
84
- const record = scope.record && scope.resource !== void 0 ? models[scope.resource] : void 0;
85
- for (const name of parsed.paths) {
86
- const counted = countedResource(name, (first) => Boolean(record && Object.hasOwn(record.fields, first)));
87
- if (counted !== void 0) {
88
- if (!models[counted]) problems.push(`"when" counts "${counted}", which is not a resource`);
89
- } else if (record) path(name);
90
- else problems.push(`"when" names "${name}", but outside a record it can only count records, as "<resource>.count"`);
91
- }
92
- break;
93
- }
81
+ case "Show": problems.push(...conditionProblems(String(node.props.when), scope.record ? scope.resource : void 0, models));
94
82
  }
95
83
  return problems;
96
84
  };
package/dist/index.d.ts CHANGED
@@ -4,9 +4,10 @@ import { ComponentOptions, component } from "./component.js";
4
4
  import { PageDefinition, PageModel, PageOptions, isPageDefinition, page } from "./page.js";
5
5
  import { Location, walkTree } from "./walk.js";
6
6
  import { checkPages } from "./check-page.js";
7
+ import { conditionProblems, conditionReadable } from "./check-condition.js";
7
8
  import { prunePage } from "./prune-page.js";
8
9
  import { countedResource, evaluateCondition, parseCondition } from "./condition.js";
9
10
  import { PathStep, resolveFieldPath } from "./field-path.js";
10
11
  import { jsx_runtime_d_exports } from "./jsx-runtime.js";
11
12
  import { FieldRefValue, fieldRef } from "@protobase/schema";
12
- export { Action, type ActionProps, type Block, type ButtonVariant, Card, type CardProps, CardRow, type CardRowProps, Chart, type ChartBucket, type ChartProps, type ChartType, type ComponentOptions, type DataProps, type Elements, Field, type FieldProps, type FieldRefValue, Grid, type GridProps, type GridSpan, type LayoutChild, type LayoutChildren, type LayoutNode, type LayoutValue, Link, type LinkProps, type Location, ModalForm, type ModalFormProps, Page, type PageDefinition, type PageModel, type PageOptions, type PageProps, type PathStep, Progress, type ProgressProps, RecordCard, type RecordCardProps, RecordRow, type RecordRowProps, Show, type ShowProps, Stat, type StatProps, Table, type TableProps, checkPages, component, countedResource, evaluateCondition, fieldRef, isLayoutNode, isPageDefinition, jsx_runtime_d_exports as jsxRuntime, page, parseCondition, prunePage, resolveFieldPath, walkTree };
13
+ export { Action, type ActionProps, type Block, type ButtonVariant, Card, type CardProps, CardRow, type CardRowProps, Chart, type ChartBucket, type ChartProps, type ChartType, type ComponentOptions, type DataProps, type Elements, Field, type FieldProps, type FieldRefValue, Grid, type GridProps, type GridSpan, type LayoutChild, type LayoutChildren, type LayoutNode, type LayoutValue, Link, type LinkProps, type Location, ModalForm, type ModalFormProps, Page, type PageDefinition, type PageModel, type PageOptions, type PageProps, type PathStep, Progress, type ProgressProps, RecordCard, type RecordCardProps, RecordRow, type RecordRowProps, Show, type ShowProps, Stat, type StatProps, Table, type TableProps, checkPages, component, conditionProblems, conditionReadable, countedResource, evaluateCondition, fieldRef, isLayoutNode, isPageDefinition, jsx_runtime_d_exports as jsxRuntime, page, parseCondition, prunePage, resolveFieldPath, walkTree };
package/dist/index.js CHANGED
@@ -5,8 +5,9 @@ import { countedResource, evaluateCondition, parseCondition } from "./condition.
5
5
  import { walkTree } from "./walk.js";
6
6
  import { isPageDefinition, page } from "./page.js";
7
7
  import { resolveFieldPath } from "./field-path.js";
8
+ import { conditionProblems, conditionReadable } from "./check-condition.js";
8
9
  import { checkPages } from "./check-page.js";
9
10
  import { prunePage } from "./prune-page.js";
10
11
  import { jsx_runtime_exports } from "./jsx-runtime.js";
11
12
  import { fieldRef } from "@protobase/schema";
12
- export { Action, Card, CardRow, Chart, Field, Grid, Link, ModalForm, Page, Progress, RecordCard, RecordRow, Show, Stat, Table, checkPages, component, countedResource, evaluateCondition, fieldRef, isLayoutNode, isPageDefinition, jsx_runtime_exports as jsxRuntime, page, parseCondition, prunePage, resolveFieldPath, walkTree };
13
+ export { Action, Card, CardRow, Chart, Field, Grid, Link, ModalForm, Page, Progress, RecordCard, RecordRow, Show, Stat, Table, checkPages, component, conditionProblems, conditionReadable, countedResource, evaluateCondition, fieldRef, isLayoutNode, isPageDefinition, jsx_runtime_exports as jsxRuntime, page, parseCondition, prunePage, resolveFieldPath, walkTree };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@protobase/layout",
3
- "version": "0.21.9",
3
+ "version": "0.21.11",
4
4
  "description": "Composed pages for Protobase, written as JSX that compiles to plain data, with its JSX runtime.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -31,7 +31,7 @@
31
31
  "access": "public"
32
32
  },
33
33
  "dependencies": {
34
- "@protobase/schema": "0.21.9",
34
+ "@protobase/schema": "0.21.11",
35
35
  "aip-parsers": "^1.0.0"
36
36
  }
37
37
  }