@player-tools/fluent 0.13.0--canary.221.5662
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 +2257 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/index.legacy-esm.js +2143 -0
- package/dist/index.mjs +2143 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +36 -0
- package/src/core/base-builder/__tests__/fluent-builder-base.test.ts +2257 -0
- package/src/core/base-builder/__tests__/id-generator.test.ts +658 -0
- package/src/core/base-builder/__tests__/registry.test.ts +411 -0
- package/src/core/base-builder/__tests__/switch.test.ts +501 -0
- package/src/core/base-builder/__tests__/template.test.ts +449 -0
- package/src/core/base-builder/__tests__/value-extraction.test.ts +200 -0
- package/src/core/base-builder/conditional/index.ts +64 -0
- package/src/core/base-builder/context.ts +151 -0
- package/src/core/base-builder/fluent-builder-base.ts +261 -0
- package/src/core/base-builder/guards.ts +137 -0
- package/src/core/base-builder/id/generator.ts +286 -0
- package/src/core/base-builder/id/registry.ts +152 -0
- package/src/core/base-builder/index.ts +60 -0
- package/src/core/base-builder/resolution/path-resolver.ts +108 -0
- package/src/core/base-builder/resolution/pipeline.ts +96 -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 +85 -0
- package/src/core/base-builder/resolution/steps/mixed-arrays.ts +117 -0
- package/src/core/base-builder/resolution/steps/static-values.ts +35 -0
- package/src/core/base-builder/resolution/steps/switches.ts +63 -0
- package/src/core/base-builder/resolution/steps/templates.ts +30 -0
- package/src/core/base-builder/resolution/value-resolver.ts +308 -0
- package/src/core/base-builder/storage/auxiliary-storage.ts +82 -0
- package/src/core/base-builder/storage/value-storage.ts +280 -0
- package/src/core/base-builder/types.ts +184 -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 +141 -0
- package/src/core/index.ts +8 -0
- package/src/core/mocks/generated/action.builder.ts +109 -0
- package/src/core/mocks/generated/choice.builder.ts +161 -0
- package/src/core/mocks/generated/choiceItem.builder.ts +133 -0
- package/src/core/mocks/generated/collection.builder.ts +117 -0
- package/src/core/mocks/generated/index.ts +7 -0
- package/src/core/mocks/generated/info.builder.ts +80 -0
- package/src/core/mocks/generated/input.builder.ts +75 -0
- package/src/core/mocks/generated/text.builder.ts +63 -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 +76 -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 +191 -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 +2 -0
- package/src/gen/plugin.mjs +315 -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/fluent-builder-base.d.ts +132 -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 +8 -0
- package/types/core/base-builder/resolution/path-resolver.d.ts +15 -0
- package/types/core/base-builder/resolution/pipeline.d.ts +25 -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/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 +37 -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 +141 -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 +3 -0
- package/types/index.d.ts +3 -0
- package/types/types.d.ts +163 -0
|
@@ -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
|
package/types/index.d.ts
ADDED
package/types/types.d.ts
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import type { Asset } from "@player-ui/types";
|
|
2
|
+
import type { TaggedTemplateValue } from "./core/tagged-template";
|
|
3
|
+
import type { BaseBuildContext, FLUENT_BUILDER_SYMBOL } from "./core/base-builder";
|
|
4
|
+
type AnyAssetBuilder<C extends BaseBuildContext = BaseBuildContext> = {
|
|
5
|
+
readonly [FLUENT_BUILDER_SYMBOL]: true;
|
|
6
|
+
build(context?: C): Asset;
|
|
7
|
+
peek(key: string): unknown;
|
|
8
|
+
has(key: string): boolean;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Options for extracting type information
|
|
12
|
+
*/
|
|
13
|
+
export interface ExtractTypeInfoOptions {
|
|
14
|
+
/** Path to the asset file */
|
|
15
|
+
assetPath: string;
|
|
16
|
+
/** Name of the interface to extract */
|
|
17
|
+
interfaceName: string;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Enhanced generic parameter information
|
|
21
|
+
*/
|
|
22
|
+
export interface GenericParameter {
|
|
23
|
+
/** Name of the generic parameter */
|
|
24
|
+
name: string;
|
|
25
|
+
/** Type or constraint of the parameter */
|
|
26
|
+
type: string;
|
|
27
|
+
/** Constraint clause (extends X) */
|
|
28
|
+
constraint?: string;
|
|
29
|
+
/** Default type */
|
|
30
|
+
default?: string;
|
|
31
|
+
/** Position in the parameter list */
|
|
32
|
+
position: number;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Information about a property in a type
|
|
36
|
+
*/
|
|
37
|
+
export interface PropertyInfo {
|
|
38
|
+
/** Name of the property */
|
|
39
|
+
name: string;
|
|
40
|
+
/** Type of the property */
|
|
41
|
+
type: string;
|
|
42
|
+
/** JSDoc comment for the property */
|
|
43
|
+
jsDoc?: string;
|
|
44
|
+
/** Whether the property is optional */
|
|
45
|
+
isOptional?: boolean;
|
|
46
|
+
/** Whether the property is readonly */
|
|
47
|
+
isReadonly?: boolean;
|
|
48
|
+
/** Whether the property is a constant */
|
|
49
|
+
isStringLiteral?: boolean;
|
|
50
|
+
/** Whether the property has generic parameters */
|
|
51
|
+
isGeneric?: boolean;
|
|
52
|
+
/** Generic parameters if any */
|
|
53
|
+
genericParameters?: Array<GenericParameter>;
|
|
54
|
+
/** Nested properties for object types */
|
|
55
|
+
properties?: PropertyInfo[];
|
|
56
|
+
/** Whether the property is an asset wrapper */
|
|
57
|
+
isAssetWrapper?: boolean;
|
|
58
|
+
/** Whether the property is an array type */
|
|
59
|
+
isArrayType?: boolean;
|
|
60
|
+
/** Whether the property is or contains an asset type */
|
|
61
|
+
isAssetType?: boolean;
|
|
62
|
+
/** Name of the parent object when this is a nested property */
|
|
63
|
+
parentName?: string;
|
|
64
|
+
/** Names of required sibling properties in the same parent object */
|
|
65
|
+
requiredSiblings?: string[];
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Information about an import
|
|
69
|
+
*/
|
|
70
|
+
export interface ImportInfo {
|
|
71
|
+
/** Module path the import is from */
|
|
72
|
+
from: string;
|
|
73
|
+
/** Named imports from the module */
|
|
74
|
+
namedImports: string[];
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Complete type information extracted from an interface
|
|
78
|
+
*/
|
|
79
|
+
export interface TypeInfo {
|
|
80
|
+
/** The name of the type */
|
|
81
|
+
name: string;
|
|
82
|
+
/** Type reference */
|
|
83
|
+
type: string;
|
|
84
|
+
/** JSDoc comment for the type */
|
|
85
|
+
jsDoc?: string;
|
|
86
|
+
/** Properties of the type */
|
|
87
|
+
properties: PropertyInfo[];
|
|
88
|
+
/** Dependencies of the type */
|
|
89
|
+
dependencies: Set<ImportInfo>;
|
|
90
|
+
/** Whether the type is an asset wrapper */
|
|
91
|
+
isAssetWrapper?: boolean;
|
|
92
|
+
/** Whether the type is or contains an asset type */
|
|
93
|
+
isAssetType?: boolean;
|
|
94
|
+
/** Interface-level generic parameters */
|
|
95
|
+
interfaceGenerics: GenericParameter[];
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Result type representing either a success or failure
|
|
99
|
+
*/
|
|
100
|
+
export type Result<T, E = Error> = Success<T> | Failure<E>;
|
|
101
|
+
/**
|
|
102
|
+
* Success result with a value
|
|
103
|
+
*/
|
|
104
|
+
export interface Success<T> {
|
|
105
|
+
success: true;
|
|
106
|
+
value: T;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Failure result with an error
|
|
110
|
+
*/
|
|
111
|
+
export interface Failure<E = Error> {
|
|
112
|
+
success: false;
|
|
113
|
+
error: E;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Helper type to check if a type is a literal type vs its general counterpart
|
|
117
|
+
*/
|
|
118
|
+
type IsLiteralType<T, Base> = T extends Base ? Base extends T ? false : true : false;
|
|
119
|
+
/**
|
|
120
|
+
* Type utility to transform Asset types into builder friendly versions
|
|
121
|
+
* - 'foo' | 'bar' → 'foo' | 'bar' | TaggedTemplateValue (preserves literal unions)
|
|
122
|
+
* - string → string | TaggedTemplateValue
|
|
123
|
+
* - true | false → true | false | TaggedTemplateValue (preserves boolean literals)
|
|
124
|
+
* - boolean → boolean | TaggedTemplateValue
|
|
125
|
+
* - 42 | 100 → 42 | 100 | TaggedTemplateValue (preserves number literals)
|
|
126
|
+
* - number → number | TaggedTemplateValue
|
|
127
|
+
* - Asset → Asset | FluentBuilder<Asset, C>
|
|
128
|
+
* - AssetWrapper<T> → T | FluentBuilder<T, C>
|
|
129
|
+
* - Array<T> → Array<TransformType<T>>
|
|
130
|
+
* - Record<K, V> → Record<K, TransformType<V>>
|
|
131
|
+
*
|
|
132
|
+
* Uses a helper type to distinguish between literal and general types.
|
|
133
|
+
* For literal types, we preserve the exact literal and add TaggedTemplateValue.
|
|
134
|
+
* For general types, we use the general type and add TaggedTemplateValue.
|
|
135
|
+
*
|
|
136
|
+
* Order matters: we check for complex types first, then primitives.
|
|
137
|
+
*/
|
|
138
|
+
export type TransformType<T, C extends BaseBuildContext = BaseBuildContext> = T extends Asset & {
|
|
139
|
+
id: unknown;
|
|
140
|
+
} ? T | AnyAssetBuilder<C> : T extends {
|
|
141
|
+
asset: infer A;
|
|
142
|
+
} ? A | AnyAssetBuilder<C> : T extends Array<infer E> ? Array<TransformType<E>> : T extends Record<string, unknown> ? {
|
|
143
|
+
[K in keyof T]: TransformType<T[K], C>;
|
|
144
|
+
} : T extends string ? IsLiteralType<T, string> extends true ? T | TaggedTemplateValue : string | TaggedTemplateValue : T extends boolean ? IsLiteralType<T, boolean> extends true ? T | TaggedTemplateValue : boolean | TaggedTemplateValue : T extends number ? IsLiteralType<T, number> extends true ? T | TaggedTemplateValue : number | TaggedTemplateValue : T extends bigint ? IsLiteralType<T, bigint> extends true ? T | TaggedTemplateValue : bigint | TaggedTemplateValue : T;
|
|
145
|
+
/**
|
|
146
|
+
* Type utility to extract all properties from an Asset type including nested ones
|
|
147
|
+
* Makes all properties non-optional for the builder args
|
|
148
|
+
* Automatically adds applicability property for conditional asset visibility
|
|
149
|
+
*/
|
|
150
|
+
export type ExtractBuilderArgs<T> = {
|
|
151
|
+
[K in keyof T as K extends "type" ? never : K]: K extends "metaData" ? T[K] extends Record<string, unknown> ? {
|
|
152
|
+
[P in keyof T[K]]: TransformType<T[K][P]>;
|
|
153
|
+
} : TransformType<T[K]> : TransformType<T[K]>;
|
|
154
|
+
} & {
|
|
155
|
+
/**
|
|
156
|
+
* Applicability expression that conditionally shows or hides an asset
|
|
157
|
+
* (and all of its children) from the view tree. Dynamically calculated
|
|
158
|
+
* and automatically updates as data changes on the page.
|
|
159
|
+
*/
|
|
160
|
+
applicability?: string | TaggedTemplateValue;
|
|
161
|
+
};
|
|
162
|
+
export {};
|
|
163
|
+
//# sourceMappingURL=types.d.ts.map
|