@player-tools/fluent 0.12.1--canary.241.6077
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/cjs/index.cjs +2396 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/index.legacy-esm.js +2276 -0
- package/dist/index.mjs +2276 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +38 -0
- package/src/core/base-builder/__tests__/fluent-builder-base.test.ts +2423 -0
- package/src/core/base-builder/__tests__/fluent-partial.test.ts +179 -0
- package/src/core/base-builder/__tests__/id-generator.test.ts +658 -0
- package/src/core/base-builder/__tests__/registry.test.ts +534 -0
- package/src/core/base-builder/__tests__/resolution-mixed-arrays.test.ts +319 -0
- package/src/core/base-builder/__tests__/resolution-pipeline.test.ts +416 -0
- package/src/core/base-builder/__tests__/resolution-switches.test.ts +468 -0
- package/src/core/base-builder/__tests__/resolution-templates.test.ts +255 -0
- package/src/core/base-builder/__tests__/switch.test.ts +815 -0
- package/src/core/base-builder/__tests__/template.test.ts +596 -0
- package/src/core/base-builder/__tests__/value-extraction.test.ts +200 -0
- package/src/core/base-builder/__tests__/value-storage.test.ts +459 -0
- package/src/core/base-builder/conditional/index.ts +64 -0
- package/src/core/base-builder/context.ts +152 -0
- package/src/core/base-builder/errors.ts +69 -0
- package/src/core/base-builder/fluent-builder-base.ts +308 -0
- package/src/core/base-builder/guards.ts +137 -0
- package/src/core/base-builder/id/generator.ts +290 -0
- package/src/core/base-builder/id/registry.ts +152 -0
- package/src/core/base-builder/index.ts +72 -0
- package/src/core/base-builder/resolution/path-resolver.ts +116 -0
- package/src/core/base-builder/resolution/pipeline.ts +103 -0
- package/src/core/base-builder/resolution/steps/__tests__/nested-asset-wrappers.test.ts +206 -0
- package/src/core/base-builder/resolution/steps/asset-id.ts +77 -0
- package/src/core/base-builder/resolution/steps/asset-wrappers.ts +64 -0
- package/src/core/base-builder/resolution/steps/builders.ts +84 -0
- package/src/core/base-builder/resolution/steps/mixed-arrays.ts +95 -0
- package/src/core/base-builder/resolution/steps/nested-asset-wrappers.ts +124 -0
- package/src/core/base-builder/resolution/steps/static-values.ts +35 -0
- package/src/core/base-builder/resolution/steps/switches.ts +71 -0
- package/src/core/base-builder/resolution/steps/templates.ts +40 -0
- package/src/core/base-builder/resolution/value-resolver.ts +333 -0
- package/src/core/base-builder/storage/auxiliary-storage.ts +82 -0
- package/src/core/base-builder/storage/value-storage.ts +282 -0
- package/src/core/base-builder/types.ts +266 -0
- package/src/core/base-builder/utils.ts +10 -0
- package/src/core/flow/__tests__/index.test.ts +292 -0
- package/src/core/flow/index.ts +118 -0
- package/src/core/index.ts +8 -0
- package/src/core/mocks/generated/action.builder.ts +92 -0
- package/src/core/mocks/generated/choice-item.builder.ts +120 -0
- package/src/core/mocks/generated/choice.builder.ts +134 -0
- package/src/core/mocks/generated/collection.builder.ts +93 -0
- package/src/core/mocks/generated/field-collection.builder.ts +86 -0
- package/src/core/mocks/generated/index.ts +10 -0
- package/src/core/mocks/generated/info.builder.ts +64 -0
- package/src/core/mocks/generated/input.builder.ts +63 -0
- package/src/core/mocks/generated/overview-collection.builder.ts +65 -0
- package/src/core/mocks/generated/splash-collection.builder.ts +93 -0
- package/src/core/mocks/generated/text.builder.ts +47 -0
- package/src/core/mocks/index.ts +1 -0
- package/src/core/mocks/types/action.ts +92 -0
- package/src/core/mocks/types/choice.ts +129 -0
- package/src/core/mocks/types/collection.ts +140 -0
- package/src/core/mocks/types/info.ts +7 -0
- package/src/core/mocks/types/input.ts +7 -0
- package/src/core/mocks/types/text.ts +5 -0
- package/src/core/schema/__tests__/index.test.ts +127 -0
- package/src/core/schema/index.ts +195 -0
- package/src/core/schema/types.ts +7 -0
- package/src/core/switch/__tests__/index.test.ts +156 -0
- package/src/core/switch/index.ts +81 -0
- package/src/core/tagged-template/README.md +448 -0
- package/src/core/tagged-template/__tests__/extract-bindings-from-schema.test.ts +207 -0
- package/src/core/tagged-template/__tests__/index.test.ts +190 -0
- package/src/core/tagged-template/__tests__/schema-std-integration.test.ts +580 -0
- package/src/core/tagged-template/binding.ts +95 -0
- package/src/core/tagged-template/expression.ts +92 -0
- package/src/core/tagged-template/extract-bindings-from-schema.ts +120 -0
- package/src/core/tagged-template/index.ts +5 -0
- package/src/core/tagged-template/std.ts +472 -0
- package/src/core/tagged-template/types.ts +123 -0
- package/src/core/template/__tests__/index.test.ts +380 -0
- package/src/core/template/index.ts +196 -0
- package/src/core/utils/index.ts +160 -0
- package/src/fp/README.md +411 -0
- package/src/fp/__tests__/index.test.ts +1178 -0
- package/src/fp/index.ts +386 -0
- package/src/gen/common.ts +15 -0
- package/src/index.ts +5 -0
- package/src/types.ts +203 -0
- package/types/core/base-builder/conditional/index.d.ts +21 -0
- package/types/core/base-builder/context.d.ts +39 -0
- package/types/core/base-builder/errors.d.ts +45 -0
- package/types/core/base-builder/fluent-builder-base.d.ts +147 -0
- package/types/core/base-builder/guards.d.ts +58 -0
- package/types/core/base-builder/id/generator.d.ts +69 -0
- package/types/core/base-builder/id/registry.d.ts +93 -0
- package/types/core/base-builder/index.d.ts +9 -0
- package/types/core/base-builder/resolution/path-resolver.d.ts +15 -0
- package/types/core/base-builder/resolution/pipeline.d.ts +27 -0
- package/types/core/base-builder/resolution/steps/asset-id.d.ts +14 -0
- package/types/core/base-builder/resolution/steps/asset-wrappers.d.ts +14 -0
- package/types/core/base-builder/resolution/steps/builders.d.ts +14 -0
- package/types/core/base-builder/resolution/steps/mixed-arrays.d.ts +14 -0
- package/types/core/base-builder/resolution/steps/nested-asset-wrappers.d.ts +14 -0
- package/types/core/base-builder/resolution/steps/static-values.d.ts +14 -0
- package/types/core/base-builder/resolution/steps/switches.d.ts +15 -0
- package/types/core/base-builder/resolution/steps/templates.d.ts +14 -0
- package/types/core/base-builder/resolution/value-resolver.d.ts +62 -0
- package/types/core/base-builder/storage/auxiliary-storage.d.ts +50 -0
- package/types/core/base-builder/storage/value-storage.d.ts +82 -0
- package/types/core/base-builder/types.d.ts +183 -0
- package/types/core/base-builder/utils.d.ts +2 -0
- package/types/core/flow/index.d.ts +23 -0
- package/types/core/index.d.ts +8 -0
- package/types/core/mocks/index.d.ts +2 -0
- package/types/core/mocks/types/action.d.ts +58 -0
- package/types/core/mocks/types/choice.d.ts +95 -0
- package/types/core/mocks/types/collection.d.ts +102 -0
- package/types/core/mocks/types/info.d.ts +7 -0
- package/types/core/mocks/types/input.d.ts +7 -0
- package/types/core/mocks/types/text.d.ts +5 -0
- package/types/core/schema/index.d.ts +34 -0
- package/types/core/schema/types.d.ts +5 -0
- package/types/core/switch/index.d.ts +21 -0
- package/types/core/tagged-template/binding.d.ts +19 -0
- package/types/core/tagged-template/expression.d.ts +11 -0
- package/types/core/tagged-template/extract-bindings-from-schema.d.ts +7 -0
- package/types/core/tagged-template/index.d.ts +6 -0
- package/types/core/tagged-template/std.d.ts +174 -0
- package/types/core/tagged-template/types.d.ts +69 -0
- package/types/core/template/index.d.ts +97 -0
- package/types/core/utils/index.d.ts +47 -0
- package/types/fp/index.d.ts +149 -0
- package/types/gen/common.d.ts +6 -0
- package/types/index.d.ts +3 -0
- package/types/types.d.ts +163 -0
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import { describe, test, expect, beforeEach } from "vitest";
|
|
2
|
+
import { text, collection, action } from "../../mocks/generated";
|
|
3
|
+
import { resetGlobalIdSet } from "../";
|
|
4
|
+
import { binding as b } from "../../tagged-template";
|
|
5
|
+
|
|
6
|
+
describe("FluentPartial - Constructor with TaggedTemplateValue", () => {
|
|
7
|
+
beforeEach(() => {
|
|
8
|
+
resetGlobalIdSet();
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
test("text() accepts TaggedTemplateValue in constructor for value property", () => {
|
|
12
|
+
const textAsset = text({ value: b`foo.bar` }).build({ parentId: "view-1" });
|
|
13
|
+
|
|
14
|
+
expect(textAsset).toMatchObject({
|
|
15
|
+
id: "view-1-text",
|
|
16
|
+
type: "text",
|
|
17
|
+
value: "{{foo.bar}}",
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
test("text() accepts TaggedTemplateValue in constructor for id property", () => {
|
|
22
|
+
const textAsset = text({ id: b`dynamicId` })
|
|
23
|
+
.withValue("Hello")
|
|
24
|
+
.build();
|
|
25
|
+
|
|
26
|
+
expect(textAsset).toMatchObject({
|
|
27
|
+
id: "{{dynamicId}}",
|
|
28
|
+
type: "text",
|
|
29
|
+
value: "Hello",
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
test("action() accepts nested objects with TaggedTemplateValue in constructor", () => {
|
|
34
|
+
// Using beacon which accepts string, not role which has a union type
|
|
35
|
+
const actionAsset = action({
|
|
36
|
+
value: "submit",
|
|
37
|
+
metaData: { beacon: b`data.beacon` },
|
|
38
|
+
}).build({ parentId: "view-1" });
|
|
39
|
+
|
|
40
|
+
expect(actionAsset).toMatchObject({
|
|
41
|
+
id: "view-1-action-submit",
|
|
42
|
+
type: "action",
|
|
43
|
+
value: "submit",
|
|
44
|
+
metaData: { beacon: "{{data.beacon}}" },
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
test("collection() accepts FluentBuilder in constructor for label property", () => {
|
|
49
|
+
const collectionAsset = collection({
|
|
50
|
+
label: text().withValue("Title"),
|
|
51
|
+
}).build({ parentId: "view-1" });
|
|
52
|
+
|
|
53
|
+
expect(collectionAsset).toMatchObject({
|
|
54
|
+
id: "view-1-collection",
|
|
55
|
+
type: "collection",
|
|
56
|
+
label: {
|
|
57
|
+
asset: {
|
|
58
|
+
id: "view-1-collection-label-text",
|
|
59
|
+
type: "text",
|
|
60
|
+
value: "Title",
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
test("collection() accepts array of FluentBuilders in constructor for values property", () => {
|
|
67
|
+
const collectionAsset = collection({
|
|
68
|
+
values: [text().withValue("Item 1"), text().withValue("Item 2")],
|
|
69
|
+
}).build({ parentId: "view-1" });
|
|
70
|
+
|
|
71
|
+
expect(collectionAsset).toMatchObject({
|
|
72
|
+
id: "view-1-collection",
|
|
73
|
+
type: "collection",
|
|
74
|
+
values: [
|
|
75
|
+
{
|
|
76
|
+
asset: {
|
|
77
|
+
id: "view-1-collection-values-0-text",
|
|
78
|
+
type: "text",
|
|
79
|
+
value: "Item 1",
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
asset: {
|
|
84
|
+
id: "view-1-collection-values-1-text",
|
|
85
|
+
type: "text",
|
|
86
|
+
value: "Item 2",
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
],
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
describe("ConditionalValue - if/ifElse with Array<AssetWrapper>", () => {
|
|
95
|
+
beforeEach(() => {
|
|
96
|
+
resetGlobalIdSet();
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
test("if() accepts array of builders for Array<AssetWrapper> property (values)", () => {
|
|
100
|
+
const hasValues = true;
|
|
101
|
+
|
|
102
|
+
const collectionAsset = collection()
|
|
103
|
+
.withLabel(text().withValue("List"))
|
|
104
|
+
.if(() => hasValues, "values", [
|
|
105
|
+
text().withValue("Item 1"),
|
|
106
|
+
text().withValue("Item 2"),
|
|
107
|
+
text().withValue("Item 3"),
|
|
108
|
+
])
|
|
109
|
+
.build({ parentId: "view-1" });
|
|
110
|
+
|
|
111
|
+
expect(collectionAsset.values).toHaveLength(3);
|
|
112
|
+
expect(collectionAsset.values?.[0]?.asset).toMatchObject({
|
|
113
|
+
type: "text",
|
|
114
|
+
value: "Item 1",
|
|
115
|
+
});
|
|
116
|
+
expect(collectionAsset.values?.[2]?.asset).toMatchObject({
|
|
117
|
+
type: "text",
|
|
118
|
+
value: "Item 3",
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
test("ifElse() accepts arrays of builders for Array<AssetWrapper> property (actions)", () => {
|
|
123
|
+
const showPrimary = false;
|
|
124
|
+
|
|
125
|
+
const collectionAsset = collection()
|
|
126
|
+
.withLabel(text().withValue("Actions"))
|
|
127
|
+
.ifElse(
|
|
128
|
+
() => showPrimary,
|
|
129
|
+
"actions",
|
|
130
|
+
[action().withValue("save").withLabel(text().withValue("Save"))],
|
|
131
|
+
[
|
|
132
|
+
action().withValue("edit").withLabel(text().withValue("Edit")),
|
|
133
|
+
action().withValue("delete").withLabel(text().withValue("Delete")),
|
|
134
|
+
],
|
|
135
|
+
)
|
|
136
|
+
.build({ parentId: "view-1" });
|
|
137
|
+
|
|
138
|
+
expect(collectionAsset.actions).toHaveLength(2);
|
|
139
|
+
expect(collectionAsset.actions?.[0]?.asset).toMatchObject({
|
|
140
|
+
type: "action",
|
|
141
|
+
value: "edit",
|
|
142
|
+
});
|
|
143
|
+
expect(collectionAsset.actions?.[1]?.asset).toMatchObject({
|
|
144
|
+
type: "action",
|
|
145
|
+
value: "delete",
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
test("if() with false predicate does not set array property", () => {
|
|
150
|
+
const hasValues = false;
|
|
151
|
+
|
|
152
|
+
const collectionAsset = collection()
|
|
153
|
+
.withLabel(text().withValue("List"))
|
|
154
|
+
.if(() => hasValues, "values", [
|
|
155
|
+
text().withValue("Item 1"),
|
|
156
|
+
text().withValue("Item 2"),
|
|
157
|
+
])
|
|
158
|
+
.build({ parentId: "view-1" });
|
|
159
|
+
|
|
160
|
+
expect(collectionAsset.values).toBeUndefined();
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
test("if() accepts function returning array of builders", () => {
|
|
164
|
+
const getItems = () => [
|
|
165
|
+
text().withValue("Dynamic 1"),
|
|
166
|
+
text().withValue("Dynamic 2"),
|
|
167
|
+
];
|
|
168
|
+
|
|
169
|
+
const collectionAsset = collection()
|
|
170
|
+
.if(() => true, "values", getItems)
|
|
171
|
+
.build({ parentId: "view-1" });
|
|
172
|
+
|
|
173
|
+
expect(collectionAsset.values).toHaveLength(2);
|
|
174
|
+
expect(collectionAsset.values?.[0]?.asset).toMatchObject({
|
|
175
|
+
type: "text",
|
|
176
|
+
value: "Dynamic 1",
|
|
177
|
+
});
|
|
178
|
+
});
|
|
179
|
+
});
|