@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.
Files changed (134) hide show
  1. package/dist/cjs/index.cjs +2396 -0
  2. package/dist/cjs/index.cjs.map +1 -0
  3. package/dist/index.legacy-esm.js +2276 -0
  4. package/dist/index.mjs +2276 -0
  5. package/dist/index.mjs.map +1 -0
  6. package/package.json +38 -0
  7. package/src/core/base-builder/__tests__/fluent-builder-base.test.ts +2423 -0
  8. package/src/core/base-builder/__tests__/fluent-partial.test.ts +179 -0
  9. package/src/core/base-builder/__tests__/id-generator.test.ts +658 -0
  10. package/src/core/base-builder/__tests__/registry.test.ts +534 -0
  11. package/src/core/base-builder/__tests__/resolution-mixed-arrays.test.ts +319 -0
  12. package/src/core/base-builder/__tests__/resolution-pipeline.test.ts +416 -0
  13. package/src/core/base-builder/__tests__/resolution-switches.test.ts +468 -0
  14. package/src/core/base-builder/__tests__/resolution-templates.test.ts +255 -0
  15. package/src/core/base-builder/__tests__/switch.test.ts +815 -0
  16. package/src/core/base-builder/__tests__/template.test.ts +596 -0
  17. package/src/core/base-builder/__tests__/value-extraction.test.ts +200 -0
  18. package/src/core/base-builder/__tests__/value-storage.test.ts +459 -0
  19. package/src/core/base-builder/conditional/index.ts +64 -0
  20. package/src/core/base-builder/context.ts +152 -0
  21. package/src/core/base-builder/errors.ts +69 -0
  22. package/src/core/base-builder/fluent-builder-base.ts +308 -0
  23. package/src/core/base-builder/guards.ts +137 -0
  24. package/src/core/base-builder/id/generator.ts +290 -0
  25. package/src/core/base-builder/id/registry.ts +152 -0
  26. package/src/core/base-builder/index.ts +72 -0
  27. package/src/core/base-builder/resolution/path-resolver.ts +116 -0
  28. package/src/core/base-builder/resolution/pipeline.ts +103 -0
  29. package/src/core/base-builder/resolution/steps/__tests__/nested-asset-wrappers.test.ts +206 -0
  30. package/src/core/base-builder/resolution/steps/asset-id.ts +77 -0
  31. package/src/core/base-builder/resolution/steps/asset-wrappers.ts +64 -0
  32. package/src/core/base-builder/resolution/steps/builders.ts +84 -0
  33. package/src/core/base-builder/resolution/steps/mixed-arrays.ts +95 -0
  34. package/src/core/base-builder/resolution/steps/nested-asset-wrappers.ts +124 -0
  35. package/src/core/base-builder/resolution/steps/static-values.ts +35 -0
  36. package/src/core/base-builder/resolution/steps/switches.ts +71 -0
  37. package/src/core/base-builder/resolution/steps/templates.ts +40 -0
  38. package/src/core/base-builder/resolution/value-resolver.ts +333 -0
  39. package/src/core/base-builder/storage/auxiliary-storage.ts +82 -0
  40. package/src/core/base-builder/storage/value-storage.ts +282 -0
  41. package/src/core/base-builder/types.ts +266 -0
  42. package/src/core/base-builder/utils.ts +10 -0
  43. package/src/core/flow/__tests__/index.test.ts +292 -0
  44. package/src/core/flow/index.ts +118 -0
  45. package/src/core/index.ts +8 -0
  46. package/src/core/mocks/generated/action.builder.ts +92 -0
  47. package/src/core/mocks/generated/choice-item.builder.ts +120 -0
  48. package/src/core/mocks/generated/choice.builder.ts +134 -0
  49. package/src/core/mocks/generated/collection.builder.ts +93 -0
  50. package/src/core/mocks/generated/field-collection.builder.ts +86 -0
  51. package/src/core/mocks/generated/index.ts +10 -0
  52. package/src/core/mocks/generated/info.builder.ts +64 -0
  53. package/src/core/mocks/generated/input.builder.ts +63 -0
  54. package/src/core/mocks/generated/overview-collection.builder.ts +65 -0
  55. package/src/core/mocks/generated/splash-collection.builder.ts +93 -0
  56. package/src/core/mocks/generated/text.builder.ts +47 -0
  57. package/src/core/mocks/index.ts +1 -0
  58. package/src/core/mocks/types/action.ts +92 -0
  59. package/src/core/mocks/types/choice.ts +129 -0
  60. package/src/core/mocks/types/collection.ts +140 -0
  61. package/src/core/mocks/types/info.ts +7 -0
  62. package/src/core/mocks/types/input.ts +7 -0
  63. package/src/core/mocks/types/text.ts +5 -0
  64. package/src/core/schema/__tests__/index.test.ts +127 -0
  65. package/src/core/schema/index.ts +195 -0
  66. package/src/core/schema/types.ts +7 -0
  67. package/src/core/switch/__tests__/index.test.ts +156 -0
  68. package/src/core/switch/index.ts +81 -0
  69. package/src/core/tagged-template/README.md +448 -0
  70. package/src/core/tagged-template/__tests__/extract-bindings-from-schema.test.ts +207 -0
  71. package/src/core/tagged-template/__tests__/index.test.ts +190 -0
  72. package/src/core/tagged-template/__tests__/schema-std-integration.test.ts +580 -0
  73. package/src/core/tagged-template/binding.ts +95 -0
  74. package/src/core/tagged-template/expression.ts +92 -0
  75. package/src/core/tagged-template/extract-bindings-from-schema.ts +120 -0
  76. package/src/core/tagged-template/index.ts +5 -0
  77. package/src/core/tagged-template/std.ts +472 -0
  78. package/src/core/tagged-template/types.ts +123 -0
  79. package/src/core/template/__tests__/index.test.ts +380 -0
  80. package/src/core/template/index.ts +196 -0
  81. package/src/core/utils/index.ts +160 -0
  82. package/src/fp/README.md +411 -0
  83. package/src/fp/__tests__/index.test.ts +1178 -0
  84. package/src/fp/index.ts +386 -0
  85. package/src/gen/common.ts +15 -0
  86. package/src/index.ts +5 -0
  87. package/src/types.ts +203 -0
  88. package/types/core/base-builder/conditional/index.d.ts +21 -0
  89. package/types/core/base-builder/context.d.ts +39 -0
  90. package/types/core/base-builder/errors.d.ts +45 -0
  91. package/types/core/base-builder/fluent-builder-base.d.ts +147 -0
  92. package/types/core/base-builder/guards.d.ts +58 -0
  93. package/types/core/base-builder/id/generator.d.ts +69 -0
  94. package/types/core/base-builder/id/registry.d.ts +93 -0
  95. package/types/core/base-builder/index.d.ts +9 -0
  96. package/types/core/base-builder/resolution/path-resolver.d.ts +15 -0
  97. package/types/core/base-builder/resolution/pipeline.d.ts +27 -0
  98. package/types/core/base-builder/resolution/steps/asset-id.d.ts +14 -0
  99. package/types/core/base-builder/resolution/steps/asset-wrappers.d.ts +14 -0
  100. package/types/core/base-builder/resolution/steps/builders.d.ts +14 -0
  101. package/types/core/base-builder/resolution/steps/mixed-arrays.d.ts +14 -0
  102. package/types/core/base-builder/resolution/steps/nested-asset-wrappers.d.ts +14 -0
  103. package/types/core/base-builder/resolution/steps/static-values.d.ts +14 -0
  104. package/types/core/base-builder/resolution/steps/switches.d.ts +15 -0
  105. package/types/core/base-builder/resolution/steps/templates.d.ts +14 -0
  106. package/types/core/base-builder/resolution/value-resolver.d.ts +62 -0
  107. package/types/core/base-builder/storage/auxiliary-storage.d.ts +50 -0
  108. package/types/core/base-builder/storage/value-storage.d.ts +82 -0
  109. package/types/core/base-builder/types.d.ts +183 -0
  110. package/types/core/base-builder/utils.d.ts +2 -0
  111. package/types/core/flow/index.d.ts +23 -0
  112. package/types/core/index.d.ts +8 -0
  113. package/types/core/mocks/index.d.ts +2 -0
  114. package/types/core/mocks/types/action.d.ts +58 -0
  115. package/types/core/mocks/types/choice.d.ts +95 -0
  116. package/types/core/mocks/types/collection.d.ts +102 -0
  117. package/types/core/mocks/types/info.d.ts +7 -0
  118. package/types/core/mocks/types/input.d.ts +7 -0
  119. package/types/core/mocks/types/text.d.ts +5 -0
  120. package/types/core/schema/index.d.ts +34 -0
  121. package/types/core/schema/types.d.ts +5 -0
  122. package/types/core/switch/index.d.ts +21 -0
  123. package/types/core/tagged-template/binding.d.ts +19 -0
  124. package/types/core/tagged-template/expression.d.ts +11 -0
  125. package/types/core/tagged-template/extract-bindings-from-schema.d.ts +7 -0
  126. package/types/core/tagged-template/index.d.ts +6 -0
  127. package/types/core/tagged-template/std.d.ts +174 -0
  128. package/types/core/tagged-template/types.d.ts +69 -0
  129. package/types/core/template/index.d.ts +97 -0
  130. package/types/core/utils/index.d.ts +47 -0
  131. package/types/fp/index.d.ts +149 -0
  132. package/types/gen/common.d.ts +6 -0
  133. package/types/index.d.ts +3 -0
  134. package/types/types.d.ts +163 -0
@@ -0,0 +1,255 @@
1
+ import { describe, test, expect, beforeEach, vi } from "vitest";
2
+ import type { BaseBuildContext } from "../types";
3
+ import { StorageKeys } from "../types";
4
+ import { AuxiliaryStorage } from "../storage/auxiliary-storage";
5
+ import { resolveTemplates } from "../resolution/steps/templates";
6
+
7
+ describe("resolveTemplates", () => {
8
+ let auxiliaryStorage: AuxiliaryStorage;
9
+
10
+ beforeEach(() => {
11
+ auxiliaryStorage = new AuxiliaryStorage();
12
+ vi.clearAllMocks();
13
+ });
14
+
15
+ test("returns early when no templates in storage", () => {
16
+ const result: Record<string, unknown> = { existingValue: "test" };
17
+ const context: BaseBuildContext = { parentId: "parent" };
18
+
19
+ resolveTemplates(auxiliaryStorage, result, context);
20
+
21
+ expect(result).toEqual({ existingValue: "test" });
22
+ expect(result.template).toBeUndefined();
23
+ });
24
+
25
+ test("returns early when empty templates array in storage", () => {
26
+ auxiliaryStorage.set(StorageKeys.TEMPLATES, []);
27
+
28
+ const result: Record<string, unknown> = { existingValue: "test" };
29
+ const context: BaseBuildContext = { parentId: "parent" };
30
+
31
+ resolveTemplates(auxiliaryStorage, result, context);
32
+
33
+ expect(result).toEqual({ existingValue: "test" });
34
+ expect(result.template).toBeUndefined();
35
+ });
36
+
37
+ test("warns in non-production when templates exist but no context", () => {
38
+ const originalEnv = process.env.NODE_ENV;
39
+ process.env.NODE_ENV = "development";
40
+
41
+ const warnSpy = vi.spyOn(console, "warn").mockImplementation(() => {});
42
+
43
+ const templateFn = vi.fn(() => ({
44
+ data: "list.items",
45
+ output: "values",
46
+ value: { asset: { id: "test", type: "text" } },
47
+ }));
48
+
49
+ auxiliaryStorage.set(StorageKeys.TEMPLATES, [templateFn]);
50
+
51
+ const result: Record<string, unknown> = {};
52
+
53
+ resolveTemplates(auxiliaryStorage, result, undefined);
54
+
55
+ expect(warnSpy).toHaveBeenCalledWith(
56
+ expect.stringContaining("template(s) exist but no context provided"),
57
+ );
58
+ expect(templateFn).not.toHaveBeenCalled();
59
+ expect(result.template).toBeUndefined();
60
+
61
+ warnSpy.mockRestore();
62
+ process.env.NODE_ENV = originalEnv;
63
+ });
64
+
65
+ test("does not warn in production when no context", () => {
66
+ const originalEnv = process.env.NODE_ENV;
67
+ process.env.NODE_ENV = "production";
68
+
69
+ const warnSpy = vi.spyOn(console, "warn").mockImplementation(() => {});
70
+
71
+ const templateFn = vi.fn(() => ({
72
+ data: "list.items",
73
+ output: "values",
74
+ value: { asset: { id: "test", type: "text" } },
75
+ }));
76
+
77
+ auxiliaryStorage.set(StorageKeys.TEMPLATES, [templateFn]);
78
+
79
+ const result: Record<string, unknown> = {};
80
+
81
+ resolveTemplates(auxiliaryStorage, result, undefined);
82
+
83
+ expect(warnSpy).not.toHaveBeenCalled();
84
+ expect(templateFn).not.toHaveBeenCalled();
85
+
86
+ warnSpy.mockRestore();
87
+ process.env.NODE_ENV = originalEnv;
88
+ });
89
+
90
+ test("calls each template function with context", () => {
91
+ const templateFn1 = vi.fn((ctx: BaseBuildContext) => ({
92
+ data: "list.items",
93
+ output: "values",
94
+ value: { asset: { id: `${ctx.parentId}-template1`, type: "text" } },
95
+ }));
96
+
97
+ const templateFn2 = vi.fn((ctx: BaseBuildContext) => ({
98
+ data: "list.other",
99
+ output: "others",
100
+ value: { asset: { id: `${ctx.parentId}-template2`, type: "text" } },
101
+ }));
102
+
103
+ auxiliaryStorage.set(StorageKeys.TEMPLATES, [templateFn1, templateFn2]);
104
+
105
+ const result: Record<string, unknown> = {};
106
+ const context: BaseBuildContext = { parentId: "parent" };
107
+
108
+ resolveTemplates(auxiliaryStorage, result, context);
109
+
110
+ expect(templateFn1).toHaveBeenCalledWith(context);
111
+ expect(templateFn2).toHaveBeenCalledWith(context);
112
+ });
113
+
114
+ test("adds resolved templates to result.template array", () => {
115
+ const template1 = {
116
+ data: "list.items",
117
+ output: "values",
118
+ value: { asset: { id: "test1", type: "text" } },
119
+ };
120
+
121
+ const template2 = {
122
+ data: "list.other",
123
+ output: "others",
124
+ value: { asset: { id: "test2", type: "text" } },
125
+ };
126
+
127
+ const templateFn1 = vi.fn(() => template1);
128
+ const templateFn2 = vi.fn(() => template2);
129
+
130
+ auxiliaryStorage.set(StorageKeys.TEMPLATES, [templateFn1, templateFn2]);
131
+
132
+ const result: Record<string, unknown> = {};
133
+ const context: BaseBuildContext = { parentId: "parent" };
134
+
135
+ resolveTemplates(auxiliaryStorage, result, context);
136
+
137
+ expect(result.template).toEqual([template1, template2]);
138
+ });
139
+
140
+ test("handles multiple templates in correct order", () => {
141
+ const callOrder: number[] = [];
142
+
143
+ const templateFn1 = vi.fn(() => {
144
+ callOrder.push(1);
145
+ return { data: "first", output: "first", value: {} };
146
+ });
147
+
148
+ const templateFn2 = vi.fn(() => {
149
+ callOrder.push(2);
150
+ return { data: "second", output: "second", value: {} };
151
+ });
152
+
153
+ const templateFn3 = vi.fn(() => {
154
+ callOrder.push(3);
155
+ return { data: "third", output: "third", value: {} };
156
+ });
157
+
158
+ auxiliaryStorage.set(StorageKeys.TEMPLATES, [
159
+ templateFn1,
160
+ templateFn2,
161
+ templateFn3,
162
+ ]);
163
+
164
+ const result: Record<string, unknown> = {};
165
+ const context: BaseBuildContext = { parentId: "parent" };
166
+
167
+ resolveTemplates(auxiliaryStorage, result, context);
168
+
169
+ expect(callOrder).toEqual([1, 2, 3]);
170
+ expect(result.template).toHaveLength(3);
171
+
172
+ const templates = result.template as Array<{ data: string }>;
173
+ expect(templates[0].data).toBe("first");
174
+ expect(templates[1].data).toBe("second");
175
+ expect(templates[2].data).toBe("third");
176
+ });
177
+
178
+ test("preserves existing result properties", () => {
179
+ const templateFn = vi.fn(() => ({
180
+ data: "list.items",
181
+ output: "values",
182
+ value: { asset: { id: "test", type: "text" } },
183
+ }));
184
+
185
+ auxiliaryStorage.set(StorageKeys.TEMPLATES, [templateFn]);
186
+
187
+ const result: Record<string, unknown> = {
188
+ id: "existing-id",
189
+ type: "existing-type",
190
+ customProp: { nested: "value" },
191
+ };
192
+ const context: BaseBuildContext = { parentId: "parent" };
193
+
194
+ resolveTemplates(auxiliaryStorage, result, context);
195
+
196
+ expect(result.id).toBe("existing-id");
197
+ expect(result.type).toBe("existing-type");
198
+ expect(result.customProp).toEqual({ nested: "value" });
199
+ expect(result.template).toBeDefined();
200
+ });
201
+
202
+ test("handles template function that returns dynamic content", () => {
203
+ const templateFn = vi.fn((ctx: BaseBuildContext) => ({
204
+ data: `data.for.${ctx.parentId}`,
205
+ output: "dynamic",
206
+ dynamic: true,
207
+ value: {
208
+ asset: {
209
+ id: `${ctx.parentId}-_index_-text`,
210
+ type: "text",
211
+ value: `{{data.for.${ctx.parentId}._index_}}`,
212
+ },
213
+ },
214
+ }));
215
+
216
+ auxiliaryStorage.set(StorageKeys.TEMPLATES, [templateFn]);
217
+
218
+ const result: Record<string, unknown> = {};
219
+ const context: BaseBuildContext = { parentId: "list" };
220
+
221
+ resolveTemplates(auxiliaryStorage, result, context);
222
+
223
+ const templates = result.template as Array<{
224
+ data: string;
225
+ output: string;
226
+ dynamic: boolean;
227
+ value: { asset: { id: string; value: string } };
228
+ }>;
229
+
230
+ expect(templates).toHaveLength(1);
231
+ expect(templates[0].data).toBe("data.for.list");
232
+ expect(templates[0].dynamic).toBe(true);
233
+ expect(templates[0].value.asset.id).toBe("list-_index_-text");
234
+ });
235
+
236
+ test("handles single template", () => {
237
+ const template = {
238
+ data: "items",
239
+ output: "values",
240
+ value: { asset: { id: "item", type: "text" } },
241
+ };
242
+
243
+ const templateFn = vi.fn(() => template);
244
+
245
+ auxiliaryStorage.set(StorageKeys.TEMPLATES, [templateFn]);
246
+
247
+ const result: Record<string, unknown> = {};
248
+ const context: BaseBuildContext = { parentId: "parent" };
249
+
250
+ resolveTemplates(auxiliaryStorage, result, context);
251
+
252
+ expect(result.template).toEqual([template]);
253
+ expect((result.template as unknown[]).length).toBe(1);
254
+ });
255
+ });