@assistant-ui/react-generative-ui 0.0.23 → 0.1.0
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/README.md +2 -0
- package/dist/a2ui.d.ts +1 -4
- package/dist/a2ui.d.ts.map +1 -1
- package/dist/a2ui.js +1 -4
- package/dist/index.d.ts +1 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -10
- package/dist/index.server.d.ts +1 -2
- package/dist/index.server.d.ts.map +1 -1
- package/dist/index.server.js +1 -10
- package/dist/ir.d.ts +1 -111
- package/dist/ir.d.ts.map +1 -1
- package/dist/ir.js +1 -175
- package/dist/slack.d.ts +1 -4
- package/dist/slack.d.ts.map +1 -1
- package/dist/slack.js +1 -4
- package/dist/teams.d.ts +1 -4
- package/dist/teams.d.ts.map +1 -1
- package/dist/teams.js +1 -4
- package/package.json +5 -5
- package/src/a2ui.ts +1 -22
- package/src/index.server.ts +1 -2
- package/src/index.test.ts +75 -0
- package/src/index.ts +1 -2
- package/src/ir.ts +1 -279
- package/src/slack.ts +1 -39
- package/src/teams.ts +1 -35
- package/dist/JSONGenerativeUI.client.d.ts +0 -28
- package/dist/JSONGenerativeUI.client.d.ts.map +0 -1
- package/dist/JSONGenerativeUI.client.js +0 -101
- package/dist/JSONGenerativeUI.client.js.map +0 -1
- package/dist/JSONGenerativeUI.server.d.ts +0 -21
- package/dist/JSONGenerativeUI.server.d.ts.map +0 -1
- package/dist/JSONGenerativeUI.server.js +0 -32
- package/dist/JSONGenerativeUI.server.js.map +0 -1
- package/dist/JSONGenerativeUI.shared.d.ts +0 -63
- package/dist/JSONGenerativeUI.shared.d.ts.map +0 -1
- package/dist/JSONGenerativeUI.shared.js +0 -31
- package/dist/JSONGenerativeUI.shared.js.map +0 -1
- package/dist/RadioGroupScope.d.ts +0 -6
- package/dist/RadioGroupScope.d.ts.map +0 -1
- package/dist/RadioGroupScope.js +0 -25
- package/dist/RadioGroupScope.js.map +0 -1
- package/dist/a2ui/BindingContext.d.ts +0 -11
- package/dist/a2ui/BindingContext.d.ts.map +0 -1
- package/dist/a2ui/BindingContext.js +0 -12
- package/dist/a2ui/BindingContext.js.map +0 -1
- package/dist/a2ui/PresentRenderer.d.ts +0 -11
- package/dist/a2ui/PresentRenderer.d.ts.map +0 -1
- package/dist/a2ui/PresentRenderer.js +0 -39
- package/dist/a2ui/PresentRenderer.js.map +0 -1
- package/dist/a2ui/convert.d.ts +0 -15
- package/dist/a2ui/convert.d.ts.map +0 -1
- package/dist/a2ui/convert.js +0 -728
- package/dist/a2ui/convert.js.map +0 -1
- package/dist/a2ui/dataModel.d.ts +0 -9
- package/dist/a2ui/dataModel.d.ts.map +0 -1
- package/dist/a2ui/dataModel.js +0 -44
- package/dist/a2ui/dataModel.js.map +0 -1
- package/dist/a2ui/reducer.d.ts +0 -8
- package/dist/a2ui/reducer.d.ts.map +0 -1
- package/dist/a2ui/reducer.js +0 -242
- package/dist/a2ui/reducer.js.map +0 -1
- package/dist/a2ui/snapshot.d.ts +0 -3
- package/dist/a2ui/snapshot.d.ts.map +0 -1
- package/dist/a2ui/snapshot.js +0 -33
- package/dist/a2ui/snapshot.js.map +0 -1
- package/dist/a2ui/types.d.ts +0 -88
- package/dist/a2ui/types.d.ts.map +0 -1
- package/dist/a2ui/types.js +0 -6
- package/dist/a2ui/types.js.map +0 -1
- package/dist/a2ui/valueFunctions.d.ts +0 -16
- package/dist/a2ui/valueFunctions.d.ts.map +0 -1
- package/dist/a2ui/valueFunctions.js +0 -332
- package/dist/a2ui/valueFunctions.js.map +0 -1
- package/dist/actionRegistry.d.ts +0 -29
- package/dist/actionRegistry.d.ts.map +0 -1
- package/dist/actionRegistry.js +0 -41
- package/dist/actionRegistry.js.map +0 -1
- package/dist/answeredValues.d.ts +0 -16
- package/dist/answeredValues.d.ts.map +0 -1
- package/dist/answeredValues.js +0 -37
- package/dist/answeredValues.js.map +0 -1
- package/dist/buildPresentParameters.d.ts +0 -21
- package/dist/buildPresentParameters.d.ts.map +0 -1
- package/dist/buildPresentParameters.js +0 -95
- package/dist/buildPresentParameters.js.map +0 -1
- package/dist/constants.d.ts +0 -15
- package/dist/constants.d.ts.map +0 -1
- package/dist/constants.js +0 -19
- package/dist/constants.js.map +0 -1
- package/dist/convert/boundSpec.d.ts +0 -48
- package/dist/convert/boundSpec.d.ts.map +0 -1
- package/dist/convert/boundSpec.js +0 -108
- package/dist/convert/boundSpec.js.map +0 -1
- package/dist/convert/copyBounded.d.ts +0 -25
- package/dist/convert/copyBounded.d.ts.map +0 -1
- package/dist/convert/copyBounded.js +0 -38
- package/dist/convert/copyBounded.js.map +0 -1
- package/dist/convert/isElement.d.ts +0 -3
- package/dist/convert/isElement.d.ts.map +0 -1
- package/dist/convert/isElement.js +0 -6
- package/dist/convert/isElement.js.map +0 -1
- package/dist/convert/takeRun.d.ts +0 -6
- package/dist/convert/takeRun.d.ts.map +0 -1
- package/dist/convert/takeRun.js +0 -20
- package/dist/convert/takeRun.js.map +0 -1
- package/dist/defineGenerativeComponents.d.ts +0 -29
- package/dist/defineGenerativeComponents.d.ts.map +0 -1
- package/dist/defineGenerativeComponents.js +0 -34
- package/dist/defineGenerativeComponents.js.map +0 -1
- package/dist/fieldReferences.d.ts +0 -9
- package/dist/fieldReferences.d.ts.map +0 -1
- package/dist/fieldReferences.js +0 -53
- package/dist/fieldReferences.js.map +0 -1
- package/dist/generativeUIToJSX.d.ts +0 -18
- package/dist/generativeUIToJSX.d.ts.map +0 -1
- package/dist/generativeUIToJSX.js +0 -76
- package/dist/generativeUIToJSX.js.map +0 -1
- package/dist/index.shared.d.ts +0 -15
- package/dist/index.shared.d.ts.map +0 -1
- package/dist/index.shared.js +0 -9
- package/dist/ir.js.map +0 -1
- package/dist/renderGenerativeUI.d.ts +0 -14
- package/dist/renderGenerativeUI.d.ts.map +0 -1
- package/dist/renderGenerativeUI.js +0 -83
- package/dist/renderGenerativeUI.js.map +0 -1
- package/dist/scopeSchema.d.ts +0 -6
- package/dist/scopeSchema.d.ts.map +0 -1
- package/dist/scopeSchema.js +0 -56
- package/dist/scopeSchema.js.map +0 -1
- package/dist/slack/constants.d.ts +0 -93
- package/dist/slack/constants.d.ts.map +0 -1
- package/dist/slack/constants.js +0 -146
- package/dist/slack/constants.js.map +0 -1
- package/dist/slack/decodeBlockAction.d.ts +0 -10
- package/dist/slack/decodeBlockAction.d.ts.map +0 -1
- package/dist/slack/decodeBlockAction.js +0 -129
- package/dist/slack/decodeBlockAction.js.map +0 -1
- package/dist/slack/fromSlackBlocks.d.ts +0 -27
- package/dist/slack/fromSlackBlocks.d.ts.map +0 -1
- package/dist/slack/fromSlackBlocks.js +0 -483
- package/dist/slack/fromSlackBlocks.js.map +0 -1
- package/dist/slack/toSlackBlocks.d.ts +0 -4
- package/dist/slack/toSlackBlocks.d.ts.map +0 -1
- package/dist/slack/toSlackBlocks.js +0 -901
- package/dist/slack/toSlackBlocks.js.map +0 -1
- package/dist/slack/types.d.ts +0 -204
- package/dist/slack/types.d.ts.map +0 -1
- package/dist/slack/types.js +0 -0
- package/dist/teams/constants.d.ts +0 -34
- package/dist/teams/constants.d.ts.map +0 -1
- package/dist/teams/constants.js +0 -68
- package/dist/teams/constants.js.map +0 -1
- package/dist/teams/decodeSubmitData.d.ts +0 -26
- package/dist/teams/decodeSubmitData.d.ts.map +0 -1
- package/dist/teams/decodeSubmitData.js +0 -70
- package/dist/teams/decodeSubmitData.js.map +0 -1
- package/dist/teams/temporalId.d.ts +0 -5
- package/dist/teams/temporalId.d.ts.map +0 -1
- package/dist/teams/temporalId.js +0 -28
- package/dist/teams/temporalId.js.map +0 -1
- package/dist/teams/toAdaptiveCard.d.ts +0 -45
- package/dist/teams/toAdaptiveCard.d.ts.map +0 -1
- package/dist/teams/toAdaptiveCard.js +0 -642
- package/dist/teams/toAdaptiveCard.js.map +0 -1
- package/dist/teams/toTeamsAttachments.d.ts +0 -10
- package/dist/teams/toTeamsAttachments.d.ts.map +0 -1
- package/dist/teams/toTeamsAttachments.js +0 -99
- package/dist/teams/toTeamsAttachments.js.map +0 -1
- package/dist/teams/types.d.ts +0 -224
- package/dist/teams/types.d.ts.map +0 -1
- package/dist/teams/types.js +0 -0
- package/dist/temporal.d.ts +0 -33
- package/dist/temporal.d.ts.map +0 -1
- package/dist/temporal.js +0 -152
- package/dist/temporal.js.map +0 -1
- package/dist/types.d.ts +0 -99
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -0
- package/dist/vocabulary/alert.d.ts +0 -32
- package/dist/vocabulary/alert.d.ts.map +0 -1
- package/dist/vocabulary/alert.js +0 -160
- package/dist/vocabulary/alert.js.map +0 -1
- package/dist/vocabulary/collectFormValues.d.ts +0 -23
- package/dist/vocabulary/collectFormValues.d.ts.map +0 -1
- package/dist/vocabulary/collectFormValues.js +0 -44
- package/dist/vocabulary/collectFormValues.js.map +0 -1
- package/dist/vocabulary/data.d.ts +0 -66
- package/dist/vocabulary/data.d.ts.map +0 -1
- package/dist/vocabulary/data.js +0 -503
- package/dist/vocabulary/data.js.map +0 -1
- package/dist/vocabulary/dispatch.d.ts +0 -9
- package/dist/vocabulary/dispatch.d.ts.map +0 -1
- package/dist/vocabulary/dispatch.js +0 -50
- package/dist/vocabulary/dispatch.js.map +0 -1
- package/dist/vocabulary/fact.d.ts +0 -19
- package/dist/vocabulary/fact.d.ts.map +0 -1
- package/dist/vocabulary/fact.js +0 -51
- package/dist/vocabulary/fact.js.map +0 -1
- package/dist/vocabulary/form.d.ts +0 -11
- package/dist/vocabulary/form.d.ts.map +0 -1
- package/dist/vocabulary/form.js +0 -23
- package/dist/vocabulary/form.js.map +0 -1
- package/dist/vocabulary/formatValue.d.ts +0 -7
- package/dist/vocabulary/formatValue.d.ts.map +0 -1
- package/dist/vocabulary/formatValue.js +0 -76
- package/dist/vocabulary/formatValue.js.map +0 -1
- package/dist/vocabulary/icon.d.ts +0 -41
- package/dist/vocabulary/icon.d.ts.map +0 -1
- package/dist/vocabulary/icon.js +0 -272
- package/dist/vocabulary/icon.js.map +0 -1
- package/dist/vocabulary/index.d.ts +0 -12
- package/dist/vocabulary/index.d.ts.map +0 -1
- package/dist/vocabulary/index.js +0 -36
- package/dist/vocabulary/index.js.map +0 -1
- package/dist/vocabulary/interactive.d.ts +0 -230
- package/dist/vocabulary/interactive.d.ts.map +0 -1
- package/dist/vocabulary/interactive.js +0 -530
- package/dist/vocabulary/interactive.js.map +0 -1
- package/dist/vocabulary/layout.d.ts +0 -79
- package/dist/vocabulary/layout.d.ts.map +0 -1
- package/dist/vocabulary/layout.js +0 -139
- package/dist/vocabulary/layout.js.map +0 -1
- package/dist/vocabulary/list.d.ts +0 -14
- package/dist/vocabulary/list.d.ts.map +0 -1
- package/dist/vocabulary/list.js +0 -50
- package/dist/vocabulary/list.js.map +0 -1
- package/dist/vocabulary/media.d.ts +0 -25
- package/dist/vocabulary/media.d.ts.map +0 -1
- package/dist/vocabulary/media.js +0 -42
- package/dist/vocabulary/media.js.map +0 -1
- package/dist/vocabulary/text.d.ts +0 -57
- package/dist/vocabulary/text.d.ts.map +0 -1
- package/dist/vocabulary/text.js +0 -49
- package/dist/vocabulary/text.js.map +0 -1
- package/dist/vocabulary/toTextContent.d.ts +0 -2
- package/dist/vocabulary/toTextContent.d.ts.map +0 -1
- package/dist/vocabulary/toTextContent.js +0 -6
- package/dist/vocabulary/toTextContent.js.map +0 -1
- package/src/JSONGenerativeUI.client.tsx +0 -168
- package/src/JSONGenerativeUI.server.tsx +0 -39
- package/src/JSONGenerativeUI.shared.ts +0 -90
- package/src/JSONGenerativeUI.test.tsx +0 -1298
- package/src/RadioGroupScope.server.test.tsx +0 -24
- package/src/RadioGroupScope.tsx +0 -34
- package/src/a2ui/BindingContext.ts +0 -26
- package/src/a2ui/PresentRenderer.tsx +0 -83
- package/src/a2ui/convert.test.ts +0 -2923
- package/src/a2ui/convert.ts +0 -1207
- package/src/a2ui/dataModel.ts +0 -69
- package/src/a2ui/reducer.test.ts +0 -422
- package/src/a2ui/reducer.ts +0 -363
- package/src/a2ui/snapshot.test.ts +0 -52
- package/src/a2ui/snapshot.ts +0 -52
- package/src/a2ui/types.ts +0 -114
- package/src/a2ui/valueFunctions.test.ts +0 -271
- package/src/a2ui/valueFunctions.ts +0 -523
- package/src/actionRegistry.test.ts +0 -90
- package/src/actionRegistry.ts +0 -88
- package/src/answeredValues.test.ts +0 -33
- package/src/answeredValues.tsx +0 -70
- package/src/buildPresentParameters.test.ts +0 -246
- package/src/buildPresentParameters.ts +0 -130
- package/src/constants.ts +0 -17
- package/src/convert/boundSpec.test.ts +0 -192
- package/src/convert/boundSpec.ts +0 -134
- package/src/convert/copyBounded.test.ts +0 -131
- package/src/convert/copyBounded.ts +0 -38
- package/src/convert/isElement.ts +0 -6
- package/src/convert/takeRun.test.ts +0 -64
- package/src/convert/takeRun.ts +0 -19
- package/src/defineGenerativeComponents.ts +0 -38
- package/src/fieldReferences.test.ts +0 -66
- package/src/fieldReferences.ts +0 -83
- package/src/generativeUIToJSX.test.ts +0 -268
- package/src/generativeUIToJSX.ts +0 -152
- package/src/index.server.test.ts +0 -106
- package/src/index.shared.ts +0 -61
- package/src/ir.test.ts +0 -203
- package/src/renderGenerativeUI.test.tsx +0 -373
- package/src/renderGenerativeUI.tsx +0 -165
- package/src/scopeSchema.test.ts +0 -72
- package/src/scopeSchema.ts +0 -71
- package/src/slack/a2uiSlack.test.ts +0 -198
- package/src/slack/constants.ts +0 -194
- package/src/slack/datePicker.test.ts +0 -612
- package/src/slack/decodeBlockAction.test.ts +0 -233
- package/src/slack/decodeBlockAction.ts +0 -232
- package/src/slack/fromSlackBlocks.test.ts +0 -1465
- package/src/slack/fromSlackBlocks.ts +0 -789
- package/src/slack/toSlackBlocks.test.ts +0 -3065
- package/src/slack/toSlackBlocks.ts +0 -1818
- package/src/slack/types.ts +0 -264
- package/src/teams/constants.ts +0 -93
- package/src/teams/decodeSubmitData.test.ts +0 -397
- package/src/teams/decodeSubmitData.ts +0 -110
- package/src/teams/temporal.test.ts +0 -766
- package/src/teams/temporalId.ts +0 -56
- package/src/teams/toAdaptiveCard.test.ts +0 -1897
- package/src/teams/toAdaptiveCard.ts +0 -1057
- package/src/teams/toTeamsAttachments.test.ts +0 -74
- package/src/teams/toTeamsAttachments.ts +0 -133
- package/src/teams/types.ts +0 -266
- package/src/temporal.test.ts +0 -319
- package/src/temporal.ts +0 -259
- package/src/types.ts +0 -119
- package/src/vocabulary/alert.test.tsx +0 -427
- package/src/vocabulary/alert.tsx +0 -217
- package/src/vocabulary/collectFormValues.test.ts +0 -389
- package/src/vocabulary/collectFormValues.ts +0 -116
- package/src/vocabulary/data.test.tsx +0 -858
- package/src/vocabulary/data.tsx +0 -819
- package/src/vocabulary/datepicker.dom.test.tsx +0 -1148
- package/src/vocabulary/dispatch.ts +0 -83
- package/src/vocabulary/fact.test.tsx +0 -94
- package/src/vocabulary/fact.tsx +0 -54
- package/src/vocabulary/form.test.tsx +0 -113
- package/src/vocabulary/form.tsx +0 -39
- package/src/vocabulary/formatValue.test.ts +0 -72
- package/src/vocabulary/formatValue.ts +0 -127
- package/src/vocabulary/icon.test.tsx +0 -64
- package/src/vocabulary/icon.tsx +0 -174
- package/src/vocabulary/index.test.ts +0 -65
- package/src/vocabulary/index.ts +0 -33
- package/src/vocabulary/interactive.dispatch.test.tsx +0 -454
- package/src/vocabulary/interactive.dom.test.tsx +0 -1747
- package/src/vocabulary/interactive.test.tsx +0 -377
- package/src/vocabulary/interactive.tsx +0 -1048
- package/src/vocabulary/layout.test.tsx +0 -323
- package/src/vocabulary/layout.tsx +0 -247
- package/src/vocabulary/list.test.tsx +0 -222
- package/src/vocabulary/list.tsx +0 -50
- package/src/vocabulary/media.test.tsx +0 -85
- package/src/vocabulary/media.tsx +0 -56
- package/src/vocabulary/text.test.tsx +0 -102
- package/src/vocabulary/text.tsx +0 -60
- package/src/vocabulary/toTextContent.ts +0 -2
|
@@ -1,271 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
import {
|
|
3
|
-
ExpressionSyntaxError,
|
|
4
|
-
evaluateA2uiValueFunction,
|
|
5
|
-
parseExpressionTemplate,
|
|
6
|
-
type ExpressionPart,
|
|
7
|
-
} from "./valueFunctions";
|
|
8
|
-
|
|
9
|
-
const joinLiterals = (parts: ExpressionPart[]) =>
|
|
10
|
-
parts.reduce<ExpressionPart[]>((joined, part) => {
|
|
11
|
-
const last = joined.at(-1);
|
|
12
|
-
if (typeof part === "string" && typeof last === "string") {
|
|
13
|
-
joined[joined.length - 1] = last + part;
|
|
14
|
-
} else {
|
|
15
|
-
joined.push(part);
|
|
16
|
-
}
|
|
17
|
-
return joined;
|
|
18
|
-
}, []);
|
|
19
|
-
|
|
20
|
-
// The parse_expression_template cases of a2ui-project/a2ui conformance/core/expressions.yaml.
|
|
21
|
-
const PARSE_CASES: [string, ExpressionPart[]][] = [
|
|
22
|
-
["hello world", ["hello world"]],
|
|
23
|
-
["", []],
|
|
24
|
-
["${user}", [{ path: "user" }]],
|
|
25
|
-
["value is ${/user/name}", ["value is ", { path: "/user/name" }]],
|
|
26
|
-
["${my-path.with_underscores}", [{ path: "my-path.with_underscores" }]],
|
|
27
|
-
["a ${x} b ${y} c", ["a ", { path: "x" }, " b ", { path: "y" }, " c"]],
|
|
28
|
-
["${x}${y}", [{ path: "x" }, { path: "y" }]],
|
|
29
|
-
["${'hello world'}", ["hello world"]],
|
|
30
|
-
['${"hello world"}', ["hello world"]],
|
|
31
|
-
["${'line\\nbreak'}", ["line\nbreak"]],
|
|
32
|
-
["${'it\\'s'}", ["it's"]],
|
|
33
|
-
["${42}", [42]],
|
|
34
|
-
["${1.5}", [1.5]],
|
|
35
|
-
["${007}", [7]],
|
|
36
|
-
["${true} ${false}", [true, " ", false]],
|
|
37
|
-
["${trueish}", [{ path: "trueish" }]],
|
|
38
|
-
["${now()}", [{ call: "now", args: {} }]],
|
|
39
|
-
[
|
|
40
|
-
"sum is ${add(a: 10, b: 20)}",
|
|
41
|
-
["sum is ", { call: "add", args: { a: 10, b: 20 } }],
|
|
42
|
-
],
|
|
43
|
-
[
|
|
44
|
-
"${format(value: /amount, suffix: ' USD', fallback: zero())}",
|
|
45
|
-
[
|
|
46
|
-
{
|
|
47
|
-
call: "format",
|
|
48
|
-
args: {
|
|
49
|
-
value: { path: "/amount" },
|
|
50
|
-
suffix: " USD",
|
|
51
|
-
fallback: { call: "zero", args: {} },
|
|
52
|
-
},
|
|
53
|
-
},
|
|
54
|
-
],
|
|
55
|
-
],
|
|
56
|
-
[
|
|
57
|
-
"${outer(a: inner(b: 1))}",
|
|
58
|
-
[{ call: "outer", args: { a: { call: "inner", args: { b: 1 } } } }],
|
|
59
|
-
],
|
|
60
|
-
["${${'hello'}}", ["hello"]],
|
|
61
|
-
["${ /user/name }", [{ path: "/user/name" }]],
|
|
62
|
-
["\\${not_interpolated}", ["${not_interpolated}"]],
|
|
63
|
-
["before \\${x} after", ["before ${x} after"]],
|
|
64
|
-
["\\${literal} ${real}", ["${literal} ", { path: "real" }]],
|
|
65
|
-
["${1.}", [1]],
|
|
66
|
-
];
|
|
67
|
-
|
|
68
|
-
const MALFORMED_TEMPLATES = [
|
|
69
|
-
"hello ${world",
|
|
70
|
-
"${add(a: 1, b: 2}",
|
|
71
|
-
"${add(a 1)}",
|
|
72
|
-
"${true false}",
|
|
73
|
-
"${1.2.3}",
|
|
74
|
-
];
|
|
75
|
-
|
|
76
|
-
describe("parseExpressionTemplate", () => {
|
|
77
|
-
it.each(PARSE_CASES)("parses %j", (template, expected) => {
|
|
78
|
-
expect(joinLiterals(parseExpressionTemplate(template))).toEqual(expected);
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
it.each(MALFORMED_TEMPLATES)("rejects %j", (template) => {
|
|
82
|
-
expect(() => parseExpressionTemplate(template)).toThrow(
|
|
83
|
-
ExpressionSyntaxError,
|
|
84
|
-
);
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
it("rejects templates past the length and nesting caps", () => {
|
|
88
|
-
expect(() => parseExpressionTemplate("x".repeat(10_001))).toThrow(
|
|
89
|
-
ExpressionSyntaxError,
|
|
90
|
-
);
|
|
91
|
-
expect(() =>
|
|
92
|
-
parseExpressionTemplate(`${"${".repeat(40)}1${"}".repeat(40)}`),
|
|
93
|
-
).toThrow(ExpressionSyntaxError);
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
it("accepts an empty interpolation, a trailing argument comma, and any whitespace", () => {
|
|
97
|
-
expect(joinLiterals(parseExpressionTemplate("a${}b"))).toEqual(["ab"]);
|
|
98
|
-
expect(parseExpressionTemplate("${add(a: 1, )}")).toEqual([
|
|
99
|
-
{ call: "add", args: { a: 1 } },
|
|
100
|
-
]);
|
|
101
|
-
expect(parseExpressionTemplate("${ /x }")).toEqual([{ path: "/x" }]);
|
|
102
|
-
expect(() => parseExpressionTemplate("${add(a: 1 x)}")).toThrow(
|
|
103
|
-
ExpressionSyntaxError,
|
|
104
|
-
);
|
|
105
|
-
});
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
const evaluate = (
|
|
109
|
-
name: string,
|
|
110
|
-
args: Record<string, unknown>,
|
|
111
|
-
data: Record<string, unknown> = {},
|
|
112
|
-
) => {
|
|
113
|
-
const warnings: string[] = [];
|
|
114
|
-
const value = evaluateA2uiValueFunction(name, args, {
|
|
115
|
-
resolve: (part) =>
|
|
116
|
-
typeof part === "object" && part !== null && "path" in part
|
|
117
|
-
? data[part.path]
|
|
118
|
-
: undefined,
|
|
119
|
-
warn: (message) => warnings.push(message),
|
|
120
|
-
templates: new Map(),
|
|
121
|
-
});
|
|
122
|
-
return { value, warnings };
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
const dateName = (
|
|
126
|
-
date: Date,
|
|
127
|
-
options: Intl.DateTimeFormatOptions,
|
|
128
|
-
type: Intl.DateTimeFormatPartTypes,
|
|
129
|
-
) =>
|
|
130
|
-
new Intl.DateTimeFormat(undefined, options)
|
|
131
|
-
.formatToParts(date)
|
|
132
|
-
.find((part) => part.type === type)!.value;
|
|
133
|
-
|
|
134
|
-
describe("evaluateA2uiValueFunction", () => {
|
|
135
|
-
it("interpolates formatString paths and coerces values to text", () => {
|
|
136
|
-
expect(
|
|
137
|
-
evaluate(
|
|
138
|
-
"formatString",
|
|
139
|
-
{ value: "Hi ${/name}, ${count} new ${/flag} ${/missing}|${/tags}" },
|
|
140
|
-
{ "/name": "Ada", count: 3, "/flag": true, "/tags": ["a", "b"] },
|
|
141
|
-
),
|
|
142
|
-
).toEqual({ value: 'Hi Ada, 3 new true |["a","b"]', warnings: [] });
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
it("warns and skips a malformed formatString template", () => {
|
|
146
|
-
expect(evaluate("formatString", { value: "Hi ${name" })).toEqual({
|
|
147
|
-
value: undefined,
|
|
148
|
-
warnings: [
|
|
149
|
-
"A2UI formatString template is malformed: an interpolation is not closed.",
|
|
150
|
-
],
|
|
151
|
-
});
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
it("formats numbers and currencies with the requested decimals and grouping", () => {
|
|
155
|
-
const number = (options: Intl.NumberFormatOptions, value: number) =>
|
|
156
|
-
new Intl.NumberFormat(undefined, options).format(value);
|
|
157
|
-
|
|
158
|
-
expect(evaluate("formatNumber", { value: 1234.5, decimals: 2 })).toEqual({
|
|
159
|
-
value: number(
|
|
160
|
-
{ minimumFractionDigits: 2, maximumFractionDigits: 2 },
|
|
161
|
-
1234.5,
|
|
162
|
-
),
|
|
163
|
-
warnings: [],
|
|
164
|
-
});
|
|
165
|
-
expect(
|
|
166
|
-
evaluate("formatNumber", { value: "1500", grouping: false }).value,
|
|
167
|
-
).toBe(number({ useGrouping: false }, 1500));
|
|
168
|
-
expect(
|
|
169
|
-
evaluate("formatCurrency", { value: 12.5, currency: "USD" }).value,
|
|
170
|
-
).toBe(number({ style: "currency", currency: "USD" }, 12.5));
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
it("formats a missing amount as empty text and warns on invalid arguments", () => {
|
|
174
|
-
expect(evaluate("formatNumber", { value: undefined })).toEqual({
|
|
175
|
-
value: "",
|
|
176
|
-
warnings: [],
|
|
177
|
-
});
|
|
178
|
-
expect(evaluate("formatNumber", { value: "abc" })).toEqual({
|
|
179
|
-
value: undefined,
|
|
180
|
-
warnings: ['A2UI function "formatNumber" received invalid arguments.'],
|
|
181
|
-
});
|
|
182
|
-
expect(
|
|
183
|
-
evaluate("formatNumber", { value: 1, decimals: 1.5 }).warnings,
|
|
184
|
-
).toEqual(['A2UI function "formatNumber" received invalid arguments.']);
|
|
185
|
-
expect(evaluate("formatCurrency", { value: 1 }).warnings).toEqual([
|
|
186
|
-
'A2UI function "formatCurrency" received invalid arguments.',
|
|
187
|
-
]);
|
|
188
|
-
expect(
|
|
189
|
-
evaluate("formatCurrency", { value: 1, currency: "not a code" }).warnings,
|
|
190
|
-
).toEqual(['A2UI function "formatCurrency" received invalid arguments.']);
|
|
191
|
-
});
|
|
192
|
-
|
|
193
|
-
it("formats dates with TR35 patterns, quoted literals, and padded fields", () => {
|
|
194
|
-
const value = "2026-01-16T14:05:09";
|
|
195
|
-
const date = new Date(value);
|
|
196
|
-
const pm = dateName(date, { hour: "numeric", hour12: true }, "dayPeriod");
|
|
197
|
-
const format = (pattern: string) =>
|
|
198
|
-
evaluate("formatDate", { value, format: pattern }).value;
|
|
199
|
-
|
|
200
|
-
expect(format("h:mm a")).toBe(`2:05 ${pm}`);
|
|
201
|
-
expect(format("HH:mm:ss")).toBe("14:05:09");
|
|
202
|
-
expect(format("yy/M/d, yyyy-MM-dd")).toBe("26/1/16, 2026-01-16");
|
|
203
|
-
expect(format("EEEE, MMM d 'at' h:mm a")).toBe(
|
|
204
|
-
`${dateName(date, { weekday: "long" }, "weekday")}, ${dateName(date, { month: "short" }, "month")} 16 at 2:05 ${pm}`,
|
|
205
|
-
);
|
|
206
|
-
expect(format("MMMM d, E")).toBe(
|
|
207
|
-
`${dateName(date, { month: "long" }, "month")} 16, ${dateName(date, { weekday: "short" }, "weekday")}`,
|
|
208
|
-
);
|
|
209
|
-
expect(format("h 'o''clock'")).toBe("2 o'clock");
|
|
210
|
-
});
|
|
211
|
-
|
|
212
|
-
it("reads a date-only value as a local calendar date and rejects one out of range", () => {
|
|
213
|
-
expect(
|
|
214
|
-
evaluate("formatDate", {
|
|
215
|
-
value: "2026-01-16",
|
|
216
|
-
format: "yyyy-MM-dd HH:mm",
|
|
217
|
-
}).value,
|
|
218
|
-
).toBe("2026-01-16 00:00");
|
|
219
|
-
expect(
|
|
220
|
-
evaluate("formatDate", { value: "2026-02-30", format: "d" }).warnings,
|
|
221
|
-
).toEqual(['A2UI function "formatDate" received invalid arguments.']);
|
|
222
|
-
});
|
|
223
|
-
|
|
224
|
-
it("falls back to an ISO date for an unsupported pattern and warns on an invalid date", () => {
|
|
225
|
-
const value = "2026-01-16T14:05:09";
|
|
226
|
-
expect(evaluate("formatDate", { value, format: "YYYY" })).toEqual({
|
|
227
|
-
value: new Date(value).toISOString(),
|
|
228
|
-
warnings: [
|
|
229
|
-
'A2UI function "formatDate" does not support the pattern "YYYY", so it returned an ISO date.',
|
|
230
|
-
],
|
|
231
|
-
});
|
|
232
|
-
expect(
|
|
233
|
-
evaluate("formatDate", { value: "not a date", format: "d" }).warnings,
|
|
234
|
-
).toEqual(['A2UI function "formatDate" received invalid arguments.']);
|
|
235
|
-
expect(evaluate("formatDate", { value: undefined, format: "d" })).toEqual({
|
|
236
|
-
value: "",
|
|
237
|
-
warnings: [],
|
|
238
|
-
});
|
|
239
|
-
});
|
|
240
|
-
|
|
241
|
-
it("selects a plural category and falls back to other", () => {
|
|
242
|
-
const category = new Intl.PluralRules().select(1);
|
|
243
|
-
expect(
|
|
244
|
-
evaluate("pluralize", {
|
|
245
|
-
value: 1,
|
|
246
|
-
[category]: "1 review",
|
|
247
|
-
other: "reviews",
|
|
248
|
-
}).value,
|
|
249
|
-
).toBe("1 review");
|
|
250
|
-
expect(evaluate("pluralize", { value: 2, other: "reviews" }).value).toBe(
|
|
251
|
-
"reviews",
|
|
252
|
-
);
|
|
253
|
-
});
|
|
254
|
-
|
|
255
|
-
it("evaluates boolean functions by truthiness", () => {
|
|
256
|
-
expect(evaluate("and", { values: [true, 1] }).value).toBe(true);
|
|
257
|
-
expect(evaluate("and", { values: [true, ""] }).value).toBe(false);
|
|
258
|
-
expect(evaluate("or", { values: [false, "x"] }).value).toBe(true);
|
|
259
|
-
expect(evaluate("not", { value: 0 }).value).toBe(true);
|
|
260
|
-
expect(evaluate("not", { value: undefined }).value).toBe(true);
|
|
261
|
-
});
|
|
262
|
-
|
|
263
|
-
it("warns instead of evaluating a function it does not support", () => {
|
|
264
|
-
expect(evaluate("customValue", {})).toEqual({
|
|
265
|
-
value: undefined,
|
|
266
|
-
warnings: [
|
|
267
|
-
'A2UI function "customValue" is not supported and was skipped.',
|
|
268
|
-
],
|
|
269
|
-
});
|
|
270
|
-
});
|
|
271
|
-
});
|