@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,5 @@
1
+ import type { Schema } from "@player-ui/types";
2
+ type SchemaDataType = Schema.DataType | Schema.RecordType | Schema.ArrayType;
3
+ export type SchemaGeneratorInput = Record<string, SchemaDataType | Record<string, unknown> | unknown[]>;
4
+ export {};
5
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1,21 @@
1
+ import type { Asset, AssetWrapper } from "@player-ui/types";
2
+ import { type BaseBuildContext } from "../base-builder";
3
+ import { type TaggedTemplateValue } from "../tagged-template";
4
+ type CaseExpression = boolean | string | TaggedTemplateValue;
5
+ interface SwitchCase<T extends Asset, C extends BaseBuildContext = BaseBuildContext> {
6
+ readonly case: CaseExpression;
7
+ readonly asset: T | {
8
+ build(context?: C): T;
9
+ };
10
+ }
11
+ interface SwitchArgs<T extends Asset, C extends BaseBuildContext = BaseBuildContext> {
12
+ readonly cases: ReadonlyArray<SwitchCase<T, C>>;
13
+ readonly isDynamic?: boolean;
14
+ }
15
+ /**
16
+ * Creates a switch configuration for conditionally selecting an asset
17
+ * @see https://player-ui.github.io/next/content/assets-views/#switches
18
+ */
19
+ export declare const switch_: <T extends Asset, C extends BaseBuildContext = BaseBuildContext>({ cases, isDynamic, }: SwitchArgs<T, C>) => (ctx: C, caseOffset?: number) => AssetWrapper;
20
+ export {};
21
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,19 @@
1
+ import { type TaggedTemplateValue } from "./types";
2
+ /**
3
+ * Tagged template for creating binding expressions with optional type information
4
+ * Used to generate template strings with proper binding syntax
5
+ * @param strings - Template string parts
6
+ * @param expressions - Values to interpolate
7
+ * @returns TaggedTemplateValue with optional phantom type T
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * // Basic usage (backward compatible)
12
+ * const basicBinding = binding`data.count`;
13
+ *
14
+ * // With phantom type for TypeScript type checking
15
+ * const typedBinding = binding<number>`data.count`;
16
+ * ```
17
+ */
18
+ export declare function binding<T = unknown>(strings: TemplateStringsArray, ...expressions: Array<unknown>): TaggedTemplateValue<T>;
19
+ //# sourceMappingURL=binding.d.ts.map
@@ -0,0 +1,11 @@
1
+ import { type TaggedTemplateValue } from "./types";
2
+ /**
3
+ * Tagged template for creating expression literals
4
+ * Used for generating expressions with proper validation and formatting
5
+ * @param strings - Template string parts
6
+ * @param expressions - Values to interpolate
7
+ * @returns TaggedTemplateValue with expression context
8
+ * @throws Error if expression syntax is invalid
9
+ */
10
+ export declare function expression<T = unknown>(strings: TemplateStringsArray, ...expressions: Array<unknown>): TaggedTemplateValue<T>;
11
+ //# sourceMappingURL=expression.d.ts.map
@@ -0,0 +1,7 @@
1
+ import type { Schema } from "@player-ui/types";
2
+ import type { ExtractedBindings } from "./types";
3
+ /**
4
+ * Runtime implementation that builds the actual object structure
5
+ */
6
+ export declare function extractBindingsFromSchema<const S extends Schema.Schema>(schema: S): ExtractedBindings<S>;
7
+ //# sourceMappingURL=extract-bindings-from-schema.d.ts.map
@@ -0,0 +1,6 @@
1
+ export * from "./binding";
2
+ export * from "./expression";
3
+ export * from "./extract-bindings-from-schema";
4
+ export * from "./std";
5
+ export * from "./types";
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,174 @@
1
+ import { type TaggedTemplateValue } from "./types";
2
+ /**
3
+ * Type-safe standard library of expressions for the Player-UI DSL
4
+ * Provides common logical, comparison, and arithmetic operations with full TypeScript type safety
5
+ * using phantom types from TaggedTemplateValue.
6
+ */
7
+ /**
8
+ * Logical AND operation - returns true if all arguments are truthy
9
+ * @param args - Values or bindings to evaluate with AND logic
10
+ * @returns TaggedTemplateValue<boolean> representing the AND expression
11
+ */
12
+ export declare function and(...args: Array<TaggedTemplateValue<unknown> | boolean | string | number>): TaggedTemplateValue<boolean>;
13
+ /**
14
+ * Logical OR operation - returns true if any argument is truthy
15
+ * @param args - Values or bindings to evaluate with OR logic
16
+ * @returns TaggedTemplateValue<boolean> representing the OR expression
17
+ */
18
+ export declare function or(...args: Array<TaggedTemplateValue<unknown> | boolean | string | number>): TaggedTemplateValue<boolean>;
19
+ /**
20
+ * Logical NOT operation - returns true if argument is falsy
21
+ * @param value - Value or binding to negate
22
+ * @returns TaggedTemplateValue<boolean> representing the NOT expression
23
+ */
24
+ export declare function not(value: TaggedTemplateValue<unknown> | boolean | string | number): TaggedTemplateValue<boolean>;
25
+ /**
26
+ * Logical NOR operation - returns true if all arguments are falsy
27
+ * @param args - Values or bindings to evaluate with NOR logic
28
+ * @returns TaggedTemplateValue<boolean> representing the NOR expression
29
+ */
30
+ export declare function nor(...args: Array<TaggedTemplateValue<unknown> | boolean | string | number>): TaggedTemplateValue<boolean>;
31
+ /**
32
+ * Logical NAND operation - returns false if all arguments are truthy
33
+ * @param args - Values or bindings to evaluate with NAND logic
34
+ * @returns TaggedTemplateValue<boolean> representing the NAND expression
35
+ */
36
+ export declare function nand(...args: Array<TaggedTemplateValue<unknown> | boolean | string | number>): TaggedTemplateValue<boolean>;
37
+ /**
38
+ * Logical XOR operation - returns true if exactly one argument is truthy
39
+ * @param left - First value to compare
40
+ * @param right - Second value to compare
41
+ * @returns TaggedTemplateValue<boolean> representing the XOR expression
42
+ */
43
+ export declare function xor(left: TaggedTemplateValue<unknown> | boolean | string | number, right: TaggedTemplateValue<unknown> | boolean | string | number): TaggedTemplateValue<boolean>;
44
+ /**
45
+ * Equality comparison (loose equality ==)
46
+ * @param left - First value to compare
47
+ * @param right - Second value to compare
48
+ * @returns TaggedTemplateValue<boolean> representing the equality expression
49
+ */
50
+ export declare function equal<T>(left: TaggedTemplateValue<T> | T, right: TaggedTemplateValue<T> | T): TaggedTemplateValue<boolean>;
51
+ /**
52
+ * Strict equality comparison (===)
53
+ * @param left - First value to compare
54
+ * @param right - Second value to compare
55
+ * @returns TaggedTemplateValue<boolean> representing the strict equality expression
56
+ */
57
+ export declare function strictEqual<T>(left: TaggedTemplateValue<T> | T, right: TaggedTemplateValue<T> | T): TaggedTemplateValue<boolean>;
58
+ /**
59
+ * Inequality comparison (!=)
60
+ * @param left - First value to compare
61
+ * @param right - Second value to compare
62
+ * @returns TaggedTemplateValue<boolean> representing the inequality expression
63
+ */
64
+ export declare function notEqual<T>(left: TaggedTemplateValue<T> | T, right: TaggedTemplateValue<T> | T): TaggedTemplateValue<boolean>;
65
+ /**
66
+ * Strict inequality comparison (!==)
67
+ * @param left - First value to compare
68
+ * @param right - Second value to compare
69
+ * @returns TaggedTemplateValue<boolean> representing the strict inequality expression
70
+ */
71
+ export declare function strictNotEqual<T>(left: TaggedTemplateValue<T> | T, right: TaggedTemplateValue<T> | T): TaggedTemplateValue<boolean>;
72
+ /**
73
+ * Greater than comparison (>)
74
+ * @param left - First value to compare
75
+ * @param right - Second value to compare
76
+ * @returns TaggedTemplateValue<boolean> representing the greater than expression
77
+ */
78
+ export declare function greaterThan<T extends number | string>(left: TaggedTemplateValue<T> | T, right: TaggedTemplateValue<T> | T): TaggedTemplateValue<boolean>;
79
+ /**
80
+ * Greater than or equal comparison (>=)
81
+ * @param left - First value to compare
82
+ * @param right - Second value to compare
83
+ * @returns TaggedTemplateValue<boolean> representing the greater than or equal expression
84
+ */
85
+ export declare function greaterThanOrEqual<T extends number | string>(left: TaggedTemplateValue<T> | T, right: TaggedTemplateValue<T> | T): TaggedTemplateValue<boolean>;
86
+ /**
87
+ * Less than comparison (<)
88
+ * @param left - First value to compare
89
+ * @param right - Second value to compare
90
+ * @returns TaggedTemplateValue<boolean> representing the less than expression
91
+ */
92
+ export declare function lessThan<T extends number | string>(left: TaggedTemplateValue<T> | T, right: TaggedTemplateValue<T> | T): TaggedTemplateValue<boolean>;
93
+ /**
94
+ * Less than or equal comparison (<=)
95
+ * @param left - First value to compare
96
+ * @param right - Second value to compare
97
+ * @returns TaggedTemplateValue<boolean> representing the less than or equal expression
98
+ */
99
+ export declare function lessThanOrEqual<T extends number | string>(left: TaggedTemplateValue<T> | T, right: TaggedTemplateValue<T> | T): TaggedTemplateValue<boolean>;
100
+ /**
101
+ * Addition operation (+)
102
+ * @param args - Values or bindings to add together
103
+ * @returns TaggedTemplateValue<number> representing the addition expression
104
+ */
105
+ export declare function add(...args: Array<TaggedTemplateValue<number> | number>): TaggedTemplateValue<number>;
106
+ /**
107
+ * Subtraction operation (-)
108
+ * @param left - Value to subtract from
109
+ * @param right - Value to subtract
110
+ * @returns TaggedTemplateValue<number> representing the subtraction expression
111
+ */
112
+ export declare function subtract(left: TaggedTemplateValue<number> | number, right: TaggedTemplateValue<number> | number): TaggedTemplateValue<number>;
113
+ /**
114
+ * Multiplication operation (*)
115
+ * @param args - Values or bindings to multiply together
116
+ * @returns TaggedTemplateValue<number> representing the multiplication expression
117
+ */
118
+ export declare function multiply(...args: Array<TaggedTemplateValue<number> | number>): TaggedTemplateValue<number>;
119
+ /**
120
+ * Division operation (/)
121
+ * @param left - Dividend
122
+ * @param right - Divisor
123
+ * @returns TaggedTemplateValue<number> representing the division expression
124
+ */
125
+ export declare function divide(left: TaggedTemplateValue<number> | number, right: TaggedTemplateValue<number> | number): TaggedTemplateValue<number>;
126
+ /**
127
+ * Modulo operation (%)
128
+ * @param left - Dividend
129
+ * @param right - Divisor
130
+ * @returns TaggedTemplateValue<number> representing the modulo expression
131
+ */
132
+ export declare function modulo(left: TaggedTemplateValue<number> | number, right: TaggedTemplateValue<number> | number): TaggedTemplateValue<number>;
133
+ /**
134
+ * Conditional (ternary) operation - if-then-else logic
135
+ * @param condition - Condition to evaluate
136
+ * @param ifTrue - Value to return if condition is truthy
137
+ * @param ifFalse - Value to return if condition is falsy
138
+ * @returns TaggedTemplateValue<T> representing the conditional expression
139
+ */
140
+ export declare function conditional<T>(condition: TaggedTemplateValue<boolean> | boolean, ifTrue: TaggedTemplateValue<T> | T, ifFalse: TaggedTemplateValue<T> | T): TaggedTemplateValue<T>;
141
+ /**
142
+ * Function call expression
143
+ * @param functionName - Name of the function to call
144
+ * @param args - Arguments to pass to the function
145
+ * @returns TaggedTemplateValue<T> representing the function call expression
146
+ */
147
+ export declare function call<T = unknown>(functionName: string, ...args: Array<TaggedTemplateValue<unknown> | unknown>): TaggedTemplateValue<T>;
148
+ /**
149
+ * Creates a literal value expression
150
+ * @param value - Literal value to create expression for
151
+ * @returns TaggedTemplateValue<T> representing the literal
152
+ */
153
+ export declare function literal<T>(value: T): TaggedTemplateValue<T>;
154
+ export { and as AND };
155
+ export { or as OR };
156
+ export { not as NOT };
157
+ export { nor as NOR };
158
+ export { nand as NAND };
159
+ export { xor as XOR };
160
+ export { equal as eq };
161
+ export { strictEqual as strictEq };
162
+ export { notEqual as neq };
163
+ export { strictNotEqual as strictNeq };
164
+ export { greaterThan as gt };
165
+ export { greaterThanOrEqual as gte };
166
+ export { lessThan as lt };
167
+ export { lessThanOrEqual as lte };
168
+ export { add as plus };
169
+ export { subtract as minus };
170
+ export { multiply as times };
171
+ export { divide as div };
172
+ export { modulo as mod };
173
+ export { conditional as ternary, conditional as ifElse };
174
+ //# sourceMappingURL=std.d.ts.map
@@ -0,0 +1,69 @@
1
+ import type { Schema } from "@player-ui/types";
2
+ export declare const TaggedTemplateValueSymbol: unique symbol;
3
+ export interface TemplateRefOptions {
4
+ nestedContext?: "binding" | "expression";
5
+ }
6
+ export interface TaggedTemplateValue<T = unknown> {
7
+ [TaggedTemplateValueSymbol]: true;
8
+ /** Phantom type marker - not available at runtime */
9
+ readonly _phantomType?: T;
10
+ toValue(): string;
11
+ toRefString(options?: TemplateRefOptions): string;
12
+ toString(): string;
13
+ }
14
+ export declare function isTaggedTemplateValue(value: unknown): value is TaggedTemplateValue;
15
+ /**
16
+ * Type that converts an object type to a bindable proxy type
17
+ * Each property access returns a TaggedTemplateValue with the correct type
18
+ */
19
+ export type BindableProxy<T> = {
20
+ readonly [K in keyof T]: T[K] extends unknown[] ? TaggedTemplateValue<T[K]> : T[K] extends object ? BindableProxy<T[K]> : TaggedTemplateValue<T[K]>;
21
+ };
22
+ /**
23
+ * Maps primitive Schema types to their corresponding TypeScript types
24
+ */
25
+ type PrimitiveTypeMap = {
26
+ StringType: string;
27
+ NumberType: number;
28
+ BooleanType: boolean;
29
+ };
30
+ /**
31
+ * Utility to force TypeScript to fully evaluate a type
32
+ */
33
+ type Evaluate<T> = T extends infer U ? {
34
+ [K in keyof U]: U[K];
35
+ } : never;
36
+ /**
37
+ * Check if a type name is primitive
38
+ */
39
+ type IsPrimitiveType<T extends string> = T extends keyof PrimitiveTypeMap ? true : false;
40
+ /**
41
+ * Convert a primitive type name to its TaggedTemplateValue
42
+ */
43
+ type PrimitiveToBinding<T extends string> = T extends keyof PrimitiveTypeMap ? TaggedTemplateValue<PrimitiveTypeMap[T]> : TaggedTemplateValue<string>;
44
+ /**
45
+ * Process a single field from a node into its binding representation
46
+ */
47
+ type ProcessField<Field extends Schema.DataTypes, S extends Schema.Schema, CurrentPath extends string> = Field extends {
48
+ type: infer TypeName extends string;
49
+ } ? Field extends {
50
+ isArray: true;
51
+ } ? IsPrimitiveType<TypeName> extends true ? TypeName extends "StringType" ? {
52
+ name: PrimitiveToBinding<TypeName>;
53
+ } : {
54
+ value: PrimitiveToBinding<TypeName>;
55
+ } : TypeName extends keyof S ? S[TypeName] extends Schema.Node ? ProcessNodeFields<S[TypeName], S, `${CurrentPath}._current_`> : TaggedTemplateValue<string> : TaggedTemplateValue<string> : IsPrimitiveType<TypeName> extends true ? PrimitiveToBinding<TypeName> : TypeName extends keyof S ? S[TypeName] extends Schema.Node ? ProcessNodeFields<S[TypeName], S, CurrentPath> : TaggedTemplateValue<string> : TaggedTemplateValue<string> : TaggedTemplateValue<string>;
56
+ /**
57
+ * Process all fields in a node
58
+ */
59
+ type ProcessNodeFields<Node extends Schema.Node, S extends Schema.Schema, BasePath extends string> = Evaluate<{
60
+ [K in keyof Node]: ProcessField<Node[K], S, BasePath extends "" ? K & string : `${BasePath}.${K & string}`>;
61
+ }>;
62
+ /**
63
+ * Main type to extract bindings from a schema
64
+ */
65
+ export type ExtractedBindings<S extends Schema.Schema> = S extends {
66
+ ROOT: infer RootNode;
67
+ } ? RootNode extends Schema.Node ? ProcessNodeFields<RootNode, S, ""> : never : never;
68
+ export {};
69
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1,97 @@
1
+ import type { Asset, Template } from "@player-ui/types";
2
+ import { type BaseBuildContext } from "../base-builder";
3
+ import { type TaggedTemplateValue } from "../tagged-template";
4
+ /**
5
+ * Symbol marker to identify template functions
6
+ */
7
+ export declare const TEMPLATE_MARKER: unique symbol;
8
+ /**
9
+ * Type guard to check if a function is a template function
10
+ */
11
+ export declare function isTemplate(fn: unknown): fn is ReturnType<typeof template>;
12
+ /**
13
+ * Arguments for creating a template configuration
14
+ * @template T - The type of asset that will be created for each item in the array
15
+ */
16
+ interface TemplateArgs<T extends Asset<string>> {
17
+ /** A binding that points to an array in the model */
18
+ readonly data: string | TaggedTemplateValue;
19
+ /** A property to put the mapped objects. If not provided, will be inferred from context */
20
+ readonly output?: string;
21
+ /** The asset creator - can be a static asset, a FluentBuilder, or a builder function that returns an asset */
22
+ readonly value: T | {
23
+ build(context?: BaseBuildContext): T;
24
+ } | (<K extends BaseBuildContext>(ctx: K) => T);
25
+ /** Whether template should be recomputed when data changes */
26
+ readonly dynamic?: boolean;
27
+ }
28
+ /**
29
+ * Creates a template configuration for dynamically creating a list of assets based on array data.
30
+ * Templates provide a way to dynamically create a list of assets, or any object, based on data from the model.
31
+ * All of the templating semantics are removed by the time it reaches an asset's transform or UI layer.
32
+ *
33
+ * Within a template, the `_index_` string can be used to substitute the array-index of the item being mapped.
34
+ *
35
+ * Multiple templates:
36
+ * - Templates can be nested. Use `_index_` for the outer loop, `_index1_` for the inner loop, and so on.
37
+ * - Multiple templates can output to the same property using the same output name. Items will be appended.
38
+ * - Templates can append to existing arrays by using the same output property name.
39
+ *
40
+ * Dynamic vs Static Templates:
41
+ * - If dynamic is false (default), the template will be parsed when a view first renders and won't update as data changes.
42
+ * - If dynamic is true, template will be updated whenever data changes while a view is still showing.
43
+ *
44
+ * @param args - The template configuration arguments
45
+ * @returns A function that takes parent context and returns a Template configuration
46
+ * @see https://player-ui.github.io/next/content/assets-views/#templates
47
+ * @example
48
+ * ```ts
49
+ * // Using a static asset
50
+ * template({
51
+ * data: binding`users`,
52
+ * output: "items",
53
+ * value: text({ value: binding`users._index_.name` })
54
+ * })(parentCtx)
55
+ * ```
56
+ *
57
+ * @example
58
+ * ```ts
59
+ * // Using a builder function
60
+ * template({
61
+ * data: binding`users`,
62
+ * output: "items",
63
+ * value: (ctx) => text({ value: binding`users._index_.name` }).withId(genId(ctx))
64
+ * })(parentCtx)
65
+ * ```
66
+ *
67
+ * @example Multiple templates with the same output
68
+ * ```ts
69
+ * [
70
+ * template({
71
+ * data: binding`names`,
72
+ * output: "values",
73
+ * value: text({ id: `name-_index_`, value: binding`names._index_` })
74
+ * })(parentCtx),
75
+ * template({
76
+ * data: binding`otherNames`,
77
+ * output: "values",
78
+ * value: text({ id: `other-name-_index_`, value: binding`otherNames._index_` })
79
+ * })(parentCtx)
80
+ * ]
81
+ * ```
82
+ *
83
+ * @example Dynamic template that updates when data changes
84
+ * ```ts
85
+ * template({
86
+ * data: binding`users`,
87
+ * output: "items",
88
+ * dynamic: true,
89
+ * value: text({ value: binding`users._index_.name` })
90
+ * })(parentCtx)
91
+ * ```
92
+ */
93
+ export declare const template: <T extends Asset<string>>({ data, output, value, dynamic, }: TemplateArgs<T>) => (parentCtx: BaseBuildContext) => Template<{
94
+ asset: T;
95
+ }>;
96
+ export {};
97
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,47 @@
1
+ import { TaggedTemplateValue } from "../tagged-template";
2
+ /**
3
+ * Type that can be either a direct value T or a TaggedTemplateValue
4
+ */
5
+ export type TaggedOr<T> = T | TaggedTemplateValue;
6
+ /**
7
+ * Safely extract a string if TaggedTemplateValue is present
8
+ */
9
+ export declare function safeToString<T extends TaggedOr<string | unknown>>(value: T): string;
10
+ /**
11
+ * Safely extract a boolean if TaggedTemplateValue is present
12
+ */
13
+ export declare function safeToBoolean<T extends TaggedOr<boolean | unknown>>(value: T): boolean;
14
+ /**
15
+ * Safely extract a number if TaggedTemplateValue is present
16
+ */
17
+ export declare function safeToNumber<T extends TaggedOr<number | unknown>>(value: T): number;
18
+ /**
19
+ * Type for an item that could be in an array with TaggedTemplate values
20
+ */
21
+ export type ArrayItem<T> = T extends (infer U)[] ? U : T;
22
+ /**
23
+ * Safely extract an array of values if TaggedTemplateValue is present
24
+ * Preserves element types when possible and handles nested arrays recursively
25
+ */
26
+ export declare function safeToArray<T extends unknown[] | unknown>(value: TaggedOr<T>): Array<DeepUnwrapTagged<ArrayItem<T>>>;
27
+ /**
28
+ * Recursively transforms a type by replacing TaggedTemplateValue with string
29
+ * and handling unions that contain TaggedTemplateValue
30
+ */
31
+ export type DeepUnwrapTagged<T> = T extends TaggedTemplateValue ? T extends string ? string : string : TaggedTemplateValue extends T ? T extends TaggedTemplateValue ? string : Exclude<T, TaggedTemplateValue> : T extends Array<infer U> ? Array<DeepUnwrapTagged<U>> : T extends Record<string, unknown> ? {
32
+ [K in keyof T]: DeepUnwrapTagged<T[K]>;
33
+ } : T;
34
+ /**
35
+ * Safely extract an object if TaggedTemplateValue is present
36
+ * Recursively handles nested TaggedTemplateValues
37
+ */
38
+ export declare function safeToObject<T extends Record<string, unknown>>(value: T): DeepUnwrapTagged<T>;
39
+ /**
40
+ * Processes a value that could be a string, TaggedTemplateValue, or
41
+ * a complex object with nested TaggedTemplateValue instances
42
+ *
43
+ * This is useful for handling complex union types like:
44
+ * string | TaggedTemplateValue | Record<string, string | TaggedTemplateValue>
45
+ */
46
+ export declare function safeFromMixedType<T>(value: unknown): DeepUnwrapTagged<T>;
47
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,149 @@
1
+ import type { Result, Success, Failure } from "../types";
2
+ /**
3
+ * Function composition utility that applies a sequence of functions to an initial value
4
+ * Each function receives the result of the previous function
5
+ * @param initialValue The initial value to start the pipeline
6
+ * @param fns The functions to apply in sequence
7
+ * @returns The final result after applying all functions
8
+ */
9
+ export declare function pipe<A, B>(initialValue: A, fn1: (input: A) => B): B;
10
+ export declare function pipe<A, B, C>(initialValue: A, fn1: (input: A) => B, fn2: (input: B) => C): C;
11
+ export declare function pipe<A, B, C, D>(initialValue: A, fn1: (input: A) => B, fn2: (input: B) => C, fn3: (input: C) => D): D;
12
+ export declare function pipe<A, B, C, D, E>(initialValue: A, fn1: (input: A) => B, fn2: (input: B) => C, fn3: (input: C) => D, fn4: (input: D) => E): E;
13
+ export declare function pipe<A, B, C, D, E, F>(initialValue: A, fn1: (input: A) => B, fn2: (input: B) => C, fn3: (input: C) => D, fn4: (input: D) => E, fn5: (input: E) => F): F;
14
+ export declare function pipe<A, B, C, D, E, F, G>(initialValue: A, fn1: (input: A) => B, fn2: (input: B) => C, fn3: (input: C) => D, fn4: (input: D) => E, fn5: (input: E) => F, fn6: (input: F) => G): G;
15
+ export declare function pipe<A, B, C, D, E, F, G, H>(initialValue: A, fn1: (input: A) => B, fn2: (input: B) => C, fn3: (input: C) => D, fn4: (input: D) => E, fn5: (input: E) => F, fn6: (input: F) => G, fn7: (input: G) => H): H;
16
+ /**
17
+ * Create a success result
18
+ * @param value The success value
19
+ * @returns A Success result
20
+ */
21
+ export declare function success<T>(value: T): Success<T>;
22
+ /**
23
+ * Create a failure result
24
+ * @param error The error object
25
+ * @returns A Failure result
26
+ */
27
+ export declare function failure<E = Error>(error: E): Failure<E>;
28
+ /**
29
+ * Type guard to check if a result is a Success
30
+ * @param result The result to check
31
+ * @returns Whether the result is a Success
32
+ */
33
+ export declare function isSuccess<T, E = Error>(result: Result<T, E>): result is Success<T>;
34
+ /**
35
+ * Type guard to check if a result is a Failure
36
+ * @param result The result to check
37
+ * @returns Whether the result is a Failure
38
+ */
39
+ export declare function isFailure<T, E = Error>(result: Result<T, E>): result is Failure<E>;
40
+ /**
41
+ * Map a function over a Result if it's a Success
42
+ * @param result The result to map over
43
+ * @param fn The mapping function
44
+ * @returns A new result with the mapping applied
45
+ */
46
+ export declare function map<T, U, E = Error>(result: Result<T, E>, fn: (value: T) => U): Result<U, E>;
47
+ /**
48
+ * Chain results together with a function that returns a new Result
49
+ * @param result The result to chain from
50
+ * @param fn The function that returns a new result
51
+ * @returns The result of applying the function
52
+ */
53
+ export declare function flatMap<T, U, E = Error, F = Error>(result: Result<T, E>, fn: (value: T) => Result<U, F>): Result<U, E | F>;
54
+ /**
55
+ * Apply a recovery function to transform a Failure into a Success
56
+ * @param result The result to recover from
57
+ * @param fn The recovery function
58
+ * @returns A Success result
59
+ */
60
+ export declare function recover<T, E = Error>(result: Result<T, E>, fn: (error: E) => T): Success<T>;
61
+ /**
62
+ * Get the value from a Result or throw if it's a Failure
63
+ * @param result The result to get the value from
64
+ * @returns The success value
65
+ * @throws The error from the Failure
66
+ */
67
+ export declare function getOrThrow<T, E extends Error>(result: Result<T, E>): T;
68
+ /**
69
+ * Get the value or a default if it's a Failure
70
+ * @param result The result to get the value from
71
+ * @param defaultValue The default value to use
72
+ * @returns The success value or the default
73
+ */
74
+ export declare function getOrElse<T, E = Error>(result: Result<T, E>, defaultValue: T): T;
75
+ /**
76
+ * Execute a function and return its result wrapped in a Result
77
+ * @param fn The function to execute
78
+ * @returns A Result containing the function's return value or error
79
+ */
80
+ export declare function tryResult<T>(fn: () => T): Result<T, Error>;
81
+ /**
82
+ * Handle both success and error cases with dedicated handlers
83
+ * @param result The result to match against
84
+ * @param onSuccess Handler for success case
85
+ * @param onFailure Handler for failure case
86
+ * @returns The result of the appropriate handler
87
+ */
88
+ export declare function match<T, E = Error, U = unknown>(result: Result<T, E>, onSuccess: (value: T) => U, onFailure: (error: E) => U): U;
89
+ /**
90
+ * Filter an array and return only successful results
91
+ * @param results Array of results to filter
92
+ * @returns Array of successful values
93
+ */
94
+ export declare function filterSuccesses<T, E = Error>(results: Array<Result<T, E>>): T[];
95
+ /**
96
+ * Transform an array of values using a function that returns Results
97
+ * @param values Array of values to transform
98
+ * @param fn Function that transforms each value to a Result
99
+ * @returns Array of Results
100
+ */
101
+ export declare function mapToResults<T, U, E = Error>(values: T[], fn: (value: T) => Result<U, E>): Array<Result<U, E>>;
102
+ /**
103
+ * Validate a value using a predicate function
104
+ * @param value The value to validate
105
+ * @param predicate The validation function
106
+ * @param errorMessage Error message if validation fails
107
+ * @returns Success if valid, Failure if invalid
108
+ */
109
+ export declare function validate<T>(value: T, predicate: (value: T) => boolean, errorMessage: string): Result<T, Error>;
110
+ /**
111
+ * Create a memoized version of a function
112
+ * @param fn The function to memoize
113
+ * @returns Memoized function
114
+ */
115
+ export declare function memoize<T extends unknown[], R>(fn: (...args: T) => R): (...args: T) => R;
116
+ /**
117
+ * Check if a value is not null or undefined
118
+ * @param value The value to check
119
+ * @returns Type guard for non-null values
120
+ */
121
+ export declare function isNotNullish<T>(value: T | null | undefined): value is T;
122
+ /**
123
+ * Safe array access that returns a Result
124
+ * @param array The array to access
125
+ * @param index The index to access
126
+ * @returns Success with the value or Failure if index is out of bounds
127
+ */
128
+ export declare function safeArrayAccess<T>(array: T[], index: number): Result<T, Error>;
129
+ /**
130
+ * Combine multiple Results into a single Result containing an array
131
+ * @param results Array of Results to combine
132
+ * @returns Success with array of values if all succeed, Failure with first error if any fail
133
+ */
134
+ export declare function combineResults<T, E = Error>(results: Array<Result<T, E>>): Result<T[], E>;
135
+ /**
136
+ * Result-aware pipe function that follows the railway pattern
137
+ * Chains functions that return Results, short-circuiting on the first failure
138
+ * @param initialResult The initial Result to start the pipeline
139
+ * @param fns The functions to apply in sequence, each taking a value and returning a Result
140
+ * @returns The final Result after applying all functions, or the first failure encountered
141
+ */
142
+ export declare function pipeResult<A, B, E = Error>(initialResult: Result<A, E>, fn1: (input: A) => Result<B, E>): Result<B, E>;
143
+ export declare function pipeResult<A, B, C, E = Error>(initialResult: Result<A, E>, fn1: (input: A) => Result<B, E>, fn2: (input: B) => Result<C, E>): Result<C, E>;
144
+ export declare function pipeResult<A, B, C, D, E = Error>(initialResult: Result<A, E>, fn1: (input: A) => Result<B, E>, fn2: (input: B) => Result<C, E>, fn3: (input: C) => Result<D, E>): Result<D, E>;
145
+ export declare function pipeResult<A, B, C, D, E, Err = Error>(initialResult: Result<A, Err>, fn1: (input: A) => Result<B, Err>, fn2: (input: B) => Result<C, Err>, fn3: (input: C) => Result<D, Err>, fn4: (input: D) => Result<E, Err>): Result<E, Err>;
146
+ export declare function pipeResult<A, B, C, D, E, F, Err = Error>(initialResult: Result<A, Err>, fn1: (input: A) => Result<B, Err>, fn2: (input: B) => Result<C, Err>, fn3: (input: C) => Result<D, Err>, fn4: (input: D) => Result<E, Err>, fn5: (input: E) => Result<F, Err>): Result<F, Err>;
147
+ export declare function pipeResult<A, B, C, D, E, F, G, Err = Error>(initialResult: Result<A, Err>, fn1: (input: A) => Result<B, Err>, fn2: (input: B) => Result<C, Err>, fn3: (input: C) => Result<D, Err>, fn4: (input: D) => Result<E, Err>, fn5: (input: E) => Result<F, Err>, fn6: (input: F) => Result<G, Err>): Result<G, Err>;
148
+ export declare function pipeResult<A, B, C, D, E, F, G, H, Err = Error>(initialResult: Result<A, Err>, fn1: (input: A) => Result<B, Err>, fn2: (input: B) => Result<C, Err>, fn3: (input: C) => Result<D, Err>, fn4: (input: D) => Result<E, Err>, fn5: (input: E) => Result<F, Err>, fn6: (input: F) => Result<G, Err>, fn7: (input: G) => Result<H, Err>): Result<H, Err>;
149
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Re-exports from base-builder for generated builder files.
3
+ */
4
+ export { FluentBuilderBase, type FluentBuilder, type BaseBuildContext, type FluentPartial, createInspectMethod, } from "../core/base-builder/index.js";
5
+ export { type TaggedTemplateValue, isTaggedTemplateValue, } from "../core/tagged-template/types.js";
6
+ //# sourceMappingURL=common.d.ts.map
@@ -0,0 +1,3 @@
1
+ export * from "./core";
2
+ export * from "./types";
3
+ //# sourceMappingURL=index.d.ts.map