@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,386 @@
1
+ import type { Result, Success, Failure } from "../types";
2
+
3
+ /**
4
+ * Function composition utility that applies a sequence of functions to an initial value
5
+ * Each function receives the result of the previous function
6
+ * @param initialValue The initial value to start the pipeline
7
+ * @param fns The functions to apply in sequence
8
+ * @returns The final result after applying all functions
9
+ */
10
+ export function pipe<A, B>(initialValue: A, fn1: (input: A) => B): B;
11
+ export function pipe<A, B, C>(
12
+ initialValue: A,
13
+ fn1: (input: A) => B,
14
+ fn2: (input: B) => C,
15
+ ): C;
16
+ export function pipe<A, B, C, D>(
17
+ initialValue: A,
18
+ fn1: (input: A) => B,
19
+ fn2: (input: B) => C,
20
+ fn3: (input: C) => D,
21
+ ): D;
22
+ export function pipe<A, B, C, D, E>(
23
+ initialValue: A,
24
+ fn1: (input: A) => B,
25
+ fn2: (input: B) => C,
26
+ fn3: (input: C) => D,
27
+ fn4: (input: D) => E,
28
+ ): E;
29
+ export function pipe<A, B, C, D, E, F>(
30
+ initialValue: A,
31
+ fn1: (input: A) => B,
32
+ fn2: (input: B) => C,
33
+ fn3: (input: C) => D,
34
+ fn4: (input: D) => E,
35
+ fn5: (input: E) => F,
36
+ ): F;
37
+ export function pipe<A, B, C, D, E, F, G>(
38
+ initialValue: A,
39
+ fn1: (input: A) => B,
40
+ fn2: (input: B) => C,
41
+ fn3: (input: C) => D,
42
+ fn4: (input: D) => E,
43
+ fn5: (input: E) => F,
44
+ fn6: (input: F) => G,
45
+ ): G;
46
+ export function pipe<A, B, C, D, E, F, G, H>(
47
+ initialValue: A,
48
+ fn1: (input: A) => B,
49
+ fn2: (input: B) => C,
50
+ fn3: (input: C) => D,
51
+ fn4: (input: D) => E,
52
+ fn5: (input: E) => F,
53
+ fn6: (input: F) => G,
54
+ fn7: (input: G) => H,
55
+ ): H;
56
+ export function pipe(
57
+ initialValue: unknown,
58
+ ...fns: Array<(value: unknown) => unknown>
59
+ ): unknown {
60
+ return fns.reduce((value, fn) => fn(value), initialValue);
61
+ }
62
+
63
+ /**
64
+ * Create a success result
65
+ * @param value The success value
66
+ * @returns A Success result
67
+ */
68
+ export function success<T>(value: T): Success<T> {
69
+ return { success: true, value };
70
+ }
71
+
72
+ /**
73
+ * Create a failure result
74
+ * @param error The error object
75
+ * @returns A Failure result
76
+ */
77
+ export function failure<E = Error>(error: E): Failure<E> {
78
+ return { success: false, error };
79
+ }
80
+
81
+ /**
82
+ * Type guard to check if a result is a Success
83
+ * @param result The result to check
84
+ * @returns Whether the result is a Success
85
+ */
86
+ export function isSuccess<T, E = Error>(
87
+ result: Result<T, E>,
88
+ ): result is Success<T> {
89
+ return result.success === true;
90
+ }
91
+
92
+ /**
93
+ * Type guard to check if a result is a Failure
94
+ * @param result The result to check
95
+ * @returns Whether the result is a Failure
96
+ */
97
+ export function isFailure<T, E = Error>(
98
+ result: Result<T, E>,
99
+ ): result is Failure<E> {
100
+ return result.success === false;
101
+ }
102
+
103
+ /**
104
+ * Map a function over a Result if it's a Success
105
+ * @param result The result to map over
106
+ * @param fn The mapping function
107
+ * @returns A new result with the mapping applied
108
+ */
109
+ export function map<T, U, E = Error>(
110
+ result: Result<T, E>,
111
+ fn: (value: T) => U,
112
+ ): Result<U, E> {
113
+ if (isSuccess(result)) {
114
+ return success(fn(result.value));
115
+ }
116
+ return result;
117
+ }
118
+
119
+ /**
120
+ * Chain results together with a function that returns a new Result
121
+ * @param result The result to chain from
122
+ * @param fn The function that returns a new result
123
+ * @returns The result of applying the function
124
+ */
125
+ export function flatMap<T, U, E = Error, F = Error>(
126
+ result: Result<T, E>,
127
+ fn: (value: T) => Result<U, F>,
128
+ ): Result<U, E | F> {
129
+ if (isSuccess(result)) {
130
+ return fn(result.value);
131
+ }
132
+ return result;
133
+ }
134
+
135
+ /**
136
+ * Apply a recovery function to transform a Failure into a Success
137
+ * @param result The result to recover from
138
+ * @param fn The recovery function
139
+ * @returns A Success result
140
+ */
141
+ export function recover<T, E = Error>(
142
+ result: Result<T, E>,
143
+ fn: (error: E) => T,
144
+ ): Success<T> {
145
+ if (isSuccess(result)) {
146
+ return result;
147
+ }
148
+ return success(fn(result.error));
149
+ }
150
+
151
+ /**
152
+ * Get the value from a Result or throw if it's a Failure
153
+ * @param result The result to get the value from
154
+ * @returns The success value
155
+ * @throws The error from the Failure
156
+ */
157
+ export function getOrThrow<T, E extends Error>(result: Result<T, E>): T {
158
+ if (isSuccess(result)) {
159
+ return result.value;
160
+ }
161
+ throw result.error;
162
+ }
163
+
164
+ /**
165
+ * Get the value or a default if it's a Failure
166
+ * @param result The result to get the value from
167
+ * @param defaultValue The default value to use
168
+ * @returns The success value or the default
169
+ */
170
+ export function getOrElse<T, E = Error>(
171
+ result: Result<T, E>,
172
+ defaultValue: T,
173
+ ): T {
174
+ if (isSuccess(result)) {
175
+ return result.value;
176
+ }
177
+ return defaultValue;
178
+ }
179
+
180
+ /**
181
+ * Execute a function and return its result wrapped in a Result
182
+ * @param fn The function to execute
183
+ * @returns A Result containing the function's return value or error
184
+ */
185
+ export function tryResult<T>(fn: () => T): Result<T, Error> {
186
+ try {
187
+ return success(fn());
188
+ } catch (error) {
189
+ return failure(error instanceof Error ? error : new Error(String(error)));
190
+ }
191
+ }
192
+
193
+ /**
194
+ * Handle both success and error cases with dedicated handlers
195
+ * @param result The result to match against
196
+ * @param onSuccess Handler for success case
197
+ * @param onFailure Handler for failure case
198
+ * @returns The result of the appropriate handler
199
+ */
200
+ export function match<T, E = Error, U = unknown>(
201
+ result: Result<T, E>,
202
+ onSuccess: (value: T) => U,
203
+ onFailure: (error: E) => U,
204
+ ): U {
205
+ if (isSuccess(result)) {
206
+ return onSuccess(result.value);
207
+ }
208
+ return onFailure(result.error);
209
+ }
210
+
211
+ /**
212
+ * Filter an array and return only successful results
213
+ * @param results Array of results to filter
214
+ * @returns Array of successful values
215
+ */
216
+ export function filterSuccesses<T, E = Error>(
217
+ results: Array<Result<T, E>>,
218
+ ): T[] {
219
+ return results.filter(isSuccess).map((result) => result.value);
220
+ }
221
+
222
+ /**
223
+ * Transform an array of values using a function that returns Results
224
+ * @param values Array of values to transform
225
+ * @param fn Function that transforms each value to a Result
226
+ * @returns Array of Results
227
+ */
228
+ export function mapToResults<T, U, E = Error>(
229
+ values: T[],
230
+ fn: (value: T) => Result<U, E>,
231
+ ): Array<Result<U, E>> {
232
+ return values.map(fn);
233
+ }
234
+
235
+ /**
236
+ * Validate a value using a predicate function
237
+ * @param value The value to validate
238
+ * @param predicate The validation function
239
+ * @param errorMessage Error message if validation fails
240
+ * @returns Success if valid, Failure if invalid
241
+ */
242
+ export function validate<T>(
243
+ value: T,
244
+ predicate: (value: T) => boolean,
245
+ errorMessage: string,
246
+ ): Result<T, Error> {
247
+ if (predicate(value)) {
248
+ return success(value);
249
+ }
250
+ return failure(new Error(errorMessage));
251
+ }
252
+
253
+ /**
254
+ * Create a memoized version of a function
255
+ * @param fn The function to memoize
256
+ * @returns Memoized function
257
+ */
258
+ export function memoize<T extends unknown[], R>(
259
+ fn: (...args: T) => R,
260
+ ): (...args: T) => R {
261
+ const cache = new Map<string, R>();
262
+
263
+ return (...args: T): R => {
264
+ const key = JSON.stringify(args);
265
+
266
+ if (cache.has(key)) {
267
+ return cache.get(key)!;
268
+ }
269
+
270
+ const result = fn(...args);
271
+ cache.set(key, result);
272
+ return result;
273
+ };
274
+ }
275
+
276
+ /**
277
+ * Check if a value is not null or undefined
278
+ * @param value The value to check
279
+ * @returns Type guard for non-null values
280
+ */
281
+ export function isNotNullish<T>(value: T | null | undefined): value is T {
282
+ return value !== null && value !== undefined;
283
+ }
284
+
285
+ /**
286
+ * Safe array access that returns a Result
287
+ * @param array The array to access
288
+ * @param index The index to access
289
+ * @returns Success with the value or Failure if index is out of bounds
290
+ */
291
+ export function safeArrayAccess<T>(
292
+ array: T[],
293
+ index: number,
294
+ ): Result<T, Error> {
295
+ if (index < 0 || index >= array.length) {
296
+ return failure(
297
+ new Error(
298
+ `Index ${index} is out of bounds for array of length ${array.length}`,
299
+ ),
300
+ );
301
+ }
302
+ return success(array[index]);
303
+ }
304
+
305
+ /**
306
+ * Combine multiple Results into a single Result containing an array
307
+ * @param results Array of Results to combine
308
+ * @returns Success with array of values if all succeed, Failure with first error if any fail
309
+ */
310
+ export function combineResults<T, E = Error>(
311
+ results: Array<Result<T, E>>,
312
+ ): Result<T[], E> {
313
+ const values: T[] = [];
314
+
315
+ for (const result of results) {
316
+ if (isFailure(result)) {
317
+ return result;
318
+ }
319
+ values.push(result.value);
320
+ }
321
+
322
+ return success(values);
323
+ }
324
+
325
+ /**
326
+ * Result-aware pipe function that follows the railway pattern
327
+ * Chains functions that return Results, short-circuiting on the first failure
328
+ * @param initialResult The initial Result to start the pipeline
329
+ * @param fns The functions to apply in sequence, each taking a value and returning a Result
330
+ * @returns The final Result after applying all functions, or the first failure encountered
331
+ */
332
+ export function pipeResult<A, B, E = Error>(
333
+ initialResult: Result<A, E>,
334
+ fn1: (input: A) => Result<B, E>,
335
+ ): Result<B, E>;
336
+ export function pipeResult<A, B, C, E = Error>(
337
+ initialResult: Result<A, E>,
338
+ fn1: (input: A) => Result<B, E>,
339
+ fn2: (input: B) => Result<C, E>,
340
+ ): Result<C, E>;
341
+ export function pipeResult<A, B, C, D, E = Error>(
342
+ initialResult: Result<A, E>,
343
+ fn1: (input: A) => Result<B, E>,
344
+ fn2: (input: B) => Result<C, E>,
345
+ fn3: (input: C) => Result<D, E>,
346
+ ): Result<D, E>;
347
+ export function pipeResult<A, B, C, D, E, Err = Error>(
348
+ initialResult: Result<A, Err>,
349
+ fn1: (input: A) => Result<B, Err>,
350
+ fn2: (input: B) => Result<C, Err>,
351
+ fn3: (input: C) => Result<D, Err>,
352
+ fn4: (input: D) => Result<E, Err>,
353
+ ): Result<E, Err>;
354
+ export function pipeResult<A, B, C, D, E, F, Err = Error>(
355
+ initialResult: Result<A, Err>,
356
+ fn1: (input: A) => Result<B, Err>,
357
+ fn2: (input: B) => Result<C, Err>,
358
+ fn3: (input: C) => Result<D, Err>,
359
+ fn4: (input: D) => Result<E, Err>,
360
+ fn5: (input: E) => Result<F, Err>,
361
+ ): Result<F, Err>;
362
+ export function pipeResult<A, B, C, D, E, F, G, Err = Error>(
363
+ initialResult: Result<A, Err>,
364
+ fn1: (input: A) => Result<B, Err>,
365
+ fn2: (input: B) => Result<C, Err>,
366
+ fn3: (input: C) => Result<D, Err>,
367
+ fn4: (input: D) => Result<E, Err>,
368
+ fn5: (input: E) => Result<F, Err>,
369
+ fn6: (input: F) => Result<G, Err>,
370
+ ): Result<G, Err>;
371
+ export function pipeResult<A, B, C, D, E, F, G, H, Err = Error>(
372
+ initialResult: Result<A, Err>,
373
+ fn1: (input: A) => Result<B, Err>,
374
+ fn2: (input: B) => Result<C, Err>,
375
+ fn3: (input: C) => Result<D, Err>,
376
+ fn4: (input: D) => Result<E, Err>,
377
+ fn5: (input: E) => Result<F, Err>,
378
+ fn6: (input: F) => Result<G, Err>,
379
+ fn7: (input: G) => Result<H, Err>,
380
+ ): Result<H, Err>;
381
+ export function pipeResult<E = Error>(
382
+ initialResult: Result<unknown, E>,
383
+ ...fns: Array<(value: unknown) => Result<unknown, E>>
384
+ ): Result<unknown, E> {
385
+ return fns.reduce((result, fn) => flatMap(result, fn), initialResult);
386
+ }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Re-exports from base-builder for generated builder files.
3
+ */
4
+ export {
5
+ FluentBuilderBase,
6
+ type FluentBuilder,
7
+ type BaseBuildContext,
8
+ type FluentPartial,
9
+ createInspectMethod,
10
+ } from "../core/base-builder/index.js";
11
+
12
+ export {
13
+ type TaggedTemplateValue,
14
+ isTaggedTemplateValue,
15
+ } from "../core/tagged-template/types.js";
package/src/index.ts ADDED
@@ -0,0 +1,5 @@
1
+ // Core utilities - building blocks for DSL generation
2
+ export * from "./core";
3
+
4
+ // All types - safe to export since they don't affect bundle size
5
+ export * from "./types";
package/src/types.ts ADDED
@@ -0,0 +1,203 @@
1
+ import type { Asset } from "@player-ui/types";
2
+ import type { TaggedTemplateValue } from "./core/tagged-template";
3
+ import type {
4
+ BaseBuildContext,
5
+ FLUENT_BUILDER_SYMBOL,
6
+ } from "./core/base-builder";
7
+
8
+ type AnyAssetBuilder<C extends BaseBuildContext = BaseBuildContext> = {
9
+ readonly [FLUENT_BUILDER_SYMBOL]: true;
10
+ build(context?: C): Asset;
11
+ peek(key: string): unknown;
12
+ has(key: string): boolean;
13
+ };
14
+
15
+ /**
16
+ * Options for extracting type information
17
+ */
18
+ export interface ExtractTypeInfoOptions {
19
+ /** Path to the asset file */
20
+ assetPath: string;
21
+ /** Name of the interface to extract */
22
+ interfaceName: string;
23
+ }
24
+
25
+ /**
26
+ * Enhanced generic parameter information
27
+ */
28
+ export interface GenericParameter {
29
+ /** Name of the generic parameter */
30
+ name: string;
31
+ /** Type or constraint of the parameter */
32
+ type: string;
33
+ /** Constraint clause (extends X) */
34
+ constraint?: string;
35
+ /** Default type */
36
+ default?: string;
37
+ /** Position in the parameter list */
38
+ position: number;
39
+ }
40
+
41
+ /**
42
+ * Information about a property in a type
43
+ */
44
+ export interface PropertyInfo {
45
+ /** Name of the property */
46
+ name: string;
47
+ /** Type of the property */
48
+ type: string;
49
+ /** JSDoc comment for the property */
50
+ jsDoc?: string;
51
+ /** Whether the property is optional */
52
+ isOptional?: boolean;
53
+ /** Whether the property is readonly */
54
+ isReadonly?: boolean;
55
+ /** Whether the property is a constant */
56
+ isStringLiteral?: boolean;
57
+ /** Whether the property has generic parameters */
58
+ isGeneric?: boolean;
59
+ /** Generic parameters if any */
60
+ genericParameters?: Array<GenericParameter>;
61
+ /** Nested properties for object types */
62
+ properties?: PropertyInfo[];
63
+ /** Whether the property is an asset wrapper */
64
+ isAssetWrapper?: boolean;
65
+ /** Whether the property is an array type */
66
+ isArrayType?: boolean;
67
+ /** Whether the property is or contains an asset type */
68
+ isAssetType?: boolean;
69
+ /** Name of the parent object when this is a nested property */
70
+ parentName?: string;
71
+ /** Names of required sibling properties in the same parent object */
72
+ requiredSiblings?: string[];
73
+ }
74
+
75
+ /**
76
+ * Information about an import
77
+ */
78
+ export interface ImportInfo {
79
+ /** Module path the import is from */
80
+ from: string;
81
+ /** Named imports from the module */
82
+ namedImports: string[];
83
+ }
84
+
85
+ /**
86
+ * Complete type information extracted from an interface
87
+ */
88
+ export interface TypeInfo {
89
+ /** The name of the type */
90
+ name: string;
91
+ /** Type reference */
92
+ type: string;
93
+ /** JSDoc comment for the type */
94
+ jsDoc?: string;
95
+ /** Properties of the type */
96
+ properties: PropertyInfo[];
97
+ /** Dependencies of the type */
98
+ dependencies: Set<ImportInfo>;
99
+ /** Whether the type is an asset wrapper */
100
+ isAssetWrapper?: boolean;
101
+ /** Whether the type is or contains an asset type */
102
+ isAssetType?: boolean;
103
+ /** Interface-level generic parameters */
104
+ interfaceGenerics: GenericParameter[];
105
+ }
106
+
107
+ /**
108
+ * Result type representing either a success or failure
109
+ */
110
+ export type Result<T, E = Error> = Success<T> | Failure<E>;
111
+
112
+ /**
113
+ * Success result with a value
114
+ */
115
+ export interface Success<T> {
116
+ success: true;
117
+ value: T;
118
+ }
119
+
120
+ /**
121
+ * Failure result with an error
122
+ */
123
+ export interface Failure<E = Error> {
124
+ success: false;
125
+ error: E;
126
+ }
127
+
128
+ /**
129
+ * Helper type to check if a type is a literal type vs its general counterpart
130
+ */
131
+ type IsLiteralType<T, Base> = T extends Base
132
+ ? Base extends T
133
+ ? false
134
+ : true
135
+ : false;
136
+
137
+ /**
138
+ * Type utility to transform Asset types into builder friendly versions
139
+ * - 'foo' | 'bar' → 'foo' | 'bar' | TaggedTemplateValue (preserves literal unions)
140
+ * - string → string | TaggedTemplateValue
141
+ * - true | false → true | false | TaggedTemplateValue (preserves boolean literals)
142
+ * - boolean → boolean | TaggedTemplateValue
143
+ * - 42 | 100 → 42 | 100 | TaggedTemplateValue (preserves number literals)
144
+ * - number → number | TaggedTemplateValue
145
+ * - Asset → Asset | FluentBuilder<Asset, C>
146
+ * - AssetWrapper<T> → T | FluentBuilder<T, C>
147
+ * - Array<T> → Array<TransformType<T>>
148
+ * - Record<K, V> → Record<K, TransformType<V>>
149
+ *
150
+ * Uses a helper type to distinguish between literal and general types.
151
+ * For literal types, we preserve the exact literal and add TaggedTemplateValue.
152
+ * For general types, we use the general type and add TaggedTemplateValue.
153
+ *
154
+ * Order matters: we check for complex types first, then primitives.
155
+ */
156
+ export type TransformType<
157
+ T,
158
+ C extends BaseBuildContext = BaseBuildContext,
159
+ > = T extends Asset & { id: unknown }
160
+ ? T | AnyAssetBuilder<C>
161
+ : T extends { asset: infer A }
162
+ ? A | AnyAssetBuilder<C>
163
+ : T extends Array<infer E>
164
+ ? Array<TransformType<E>>
165
+ : T extends Record<string, unknown>
166
+ ? { [K in keyof T]: TransformType<T[K], C> }
167
+ : T extends string
168
+ ? IsLiteralType<T, string> extends true
169
+ ? T | TaggedTemplateValue
170
+ : string | TaggedTemplateValue
171
+ : T extends boolean
172
+ ? IsLiteralType<T, boolean> extends true
173
+ ? T | TaggedTemplateValue
174
+ : boolean | TaggedTemplateValue
175
+ : T extends number
176
+ ? IsLiteralType<T, number> extends true
177
+ ? T | TaggedTemplateValue
178
+ : number | TaggedTemplateValue
179
+ : T extends bigint
180
+ ? IsLiteralType<T, bigint> extends true
181
+ ? T | TaggedTemplateValue
182
+ : bigint | TaggedTemplateValue
183
+ : T;
184
+
185
+ /**
186
+ * Type utility to extract all properties from an Asset type including nested ones
187
+ * Makes all properties non-optional for the builder args
188
+ * Automatically adds applicability property for conditional asset visibility
189
+ */
190
+ export type ExtractBuilderArgs<T> = {
191
+ [K in keyof T as K extends "type" ? never : K]: K extends "metaData"
192
+ ? T[K] extends Record<string, unknown>
193
+ ? { [P in keyof T[K]]: TransformType<T[K][P]> }
194
+ : TransformType<T[K]>
195
+ : TransformType<T[K]>;
196
+ } & {
197
+ /**
198
+ * Applicability expression that conditionally shows or hides an asset
199
+ * (and all of its children) from the view tree. Dynamically calculated
200
+ * and automatically updates as data changes on the page.
201
+ */
202
+ applicability?: string | TaggedTemplateValue;
203
+ };
@@ -0,0 +1,21 @@
1
+ import type { Asset } from "@player-ui/types";
2
+ import type { FluentBuilder, BaseBuildContext } from "../types";
3
+ /**
4
+ * Resolves a value or function to its final value
5
+ *
6
+ * Generic helper that unwraps functions to their return values.
7
+ * Handles both simple functions and ConditionalValue types.
8
+ */
9
+ export declare function resolveValueOrFunction<V>(value: V | (() => V)): V;
10
+ /**
11
+ * Type guard to check if a value should be wrapped in AssetWrapper format
12
+ */
13
+ export declare function shouldWrapInAssetWrapper(value: unknown): value is FluentBuilder<unknown, BaseBuildContext> | Asset | Array<FluentBuilder<unknown, BaseBuildContext> | Asset>;
14
+ /**
15
+ * Wraps a value in AssetWrapper format if needed
16
+ * This enables if() and ifElse() to work with unwrapped asset builders
17
+ */
18
+ export declare function maybeWrapAsset<V>(value: V): V | {
19
+ asset: V;
20
+ };
21
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,39 @@
1
+ import { type BaseBuildContext, type AssetMetadata } from "./types";
2
+ /**
3
+ * Creates a nested context for child builders with automatic ID generation.
4
+ *
5
+ * 1. Determines the appropriate slot name from the parameter name
6
+ * 2. Generates a unique ID using the slot name
7
+ * 3. Creates a new context with the generated ID
8
+ *
9
+ * Use this when you want automatic ID generation for nested builders.
10
+ * For manual context manipulation, use object spreading directly.
11
+ */
12
+ export declare function createNestedContext<C extends BaseBuildContext>({ parentContext, parameterName, index, assetMetadata, }: {
13
+ readonly parentContext: C;
14
+ readonly parameterName: string;
15
+ readonly index?: number;
16
+ readonly assetMetadata?: AssetMetadata;
17
+ }): C;
18
+ /**
19
+ * Creates a template context for template value generation.
20
+ *
21
+ * Template contexts use a special template branch with depth tracking
22
+ * to support nested templates (_index_, _index1_, _index2_, etc.).
23
+ */
24
+ export declare function createTemplateContext<C extends BaseBuildContext>({ parentContext, depth, }: {
25
+ readonly parentContext: C;
26
+ readonly depth?: number;
27
+ }): C;
28
+ /**
29
+ * Creates a switch context for switch case asset generation.
30
+ *
31
+ * Switch contexts use a special switch branch with index tracking and kind
32
+ * to support sequential case indexing across all switches.
33
+ */
34
+ export declare function createSwitchContext<C extends BaseBuildContext>({ parentContext, index, kind, }: {
35
+ readonly parentContext: C;
36
+ readonly index: number;
37
+ readonly kind: "static" | "dynamic";
38
+ }): C;
39
+ //# sourceMappingURL=context.d.ts.map