@protobase/layout 0.66.5 → 0.66.7

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.
@@ -11,7 +11,7 @@ export type ConditionParse = ({
11
11
  message: string;
12
12
  };
13
13
  export declare const parseCondition: (source: string) => ConditionParse;
14
- /** True when the condition holds for `values`, keyed by the dotted paths in `condition.paths`. <gap>A condition cannot call functions, as they are not supported.</gap> */
14
+ /** True when the condition holds for `values`, keyed by the dotted paths in `condition.paths`. <gap>A condition cannot call functions other than isNull and in, such as now(), because their evaluation is not implemented.</gap> */
15
15
  export declare const evaluateCondition: (condition: Condition, values: Record<string, unknown>) => boolean;
16
16
  /** The resource a path counts (`billing_profiles.count`), when it is not a field of the record around it. */
17
17
  export declare const countedResource: (path: string, isField: (name: string) => boolean) => string | undefined;
package/dist/condition.js CHANGED
@@ -15,6 +15,46 @@ const folded = (node) => {
15
15
  if (typeof node !== "object" || node === null) return node;
16
16
  return Object.fromEntries(Object.entries(node).map(([key, value]) => [key, folded(value)]));
17
17
  };
18
+ const literalKinds = /* @__PURE__ */ new Set([
19
+ "string",
20
+ "number",
21
+ "boolean",
22
+ "duration",
23
+ "timestamp"
24
+ ]);
25
+ const isLiteral = (node) => literalKinds.has(node.kind);
26
+ const expandedCall = (node) => {
27
+ const [first, ...rest] = node.args;
28
+ if (!first || !isMember(first)) return;
29
+ if (node.name === "isNull" && rest.length === 0) return {
30
+ kind: "not",
31
+ arg: {
32
+ kind: "present",
33
+ left: first,
34
+ span: node.span
35
+ },
36
+ span: node.span
37
+ };
38
+ if (node.name !== "in" || rest.length === 0 || !rest.every(isLiteral)) return;
39
+ return {
40
+ kind: "or",
41
+ args: rest.map((value) => ({
42
+ kind: "compare",
43
+ op: "=",
44
+ left: first,
45
+ right: value,
46
+ span: node.span
47
+ })),
48
+ span: node.span
49
+ };
50
+ };
51
+ const expanded = (node) => {
52
+ if (Array.isArray(node)) return node.map(expanded);
53
+ if (typeof node !== "object" || node === null) return node;
54
+ const call = node.kind === "call" ? expandedCall(node) : void 0;
55
+ if (call) return call;
56
+ return Object.fromEntries(Object.entries(node).map(([key, value]) => [key, expanded(value)]));
57
+ };
18
58
  const parseCondition = (source) => {
19
59
  const parsed = parseFilter(source);
20
60
  if (!parsed.ok) return {
@@ -31,8 +71,8 @@ const parseCondition = (source) => {
31
71
  paths: [...new Set(memberPaths(parsed.ast))]
32
72
  };
33
73
  };
34
- /** True when the condition holds for `values`, keyed by the dotted paths in `condition.paths`. <gap>A condition cannot call functions, as they are not supported.</gap> */
35
- const evaluateCondition = (condition, values) => condition.ast !== void 0 && evaluateFilter(folded(condition.ast), values);
74
+ /** True when the condition holds for `values`, keyed by the dotted paths in `condition.paths`. <gap>A condition cannot call functions other than isNull and in, such as now(), because their evaluation is not implemented.</gap> */
75
+ const evaluateCondition = (condition, values) => condition.ast !== void 0 && evaluateFilter(folded(expanded(condition.ast)), values);
36
76
  /** The resource a path counts (`billing_profiles.count`), when it is not a field of the record around it. */
37
77
  const countedResource = (path, isField) => {
38
78
  const [first, second, ...rest] = path.split(".");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@protobase/layout",
3
- "version": "0.66.5",
3
+ "version": "0.66.7",
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.66.5",
34
+ "@protobase/schema": "0.66.7",
35
35
  "aip-parsers": "^1.0.0"
36
36
  }
37
37
  }