UNPKG

3.87 kBTypeScriptView Raw
1import { IConstruct } from './construct-compat';
2import { TokenizedStringFragments } from './string-fragments';
3/**
4 * Current resolution context for tokens
5 */
6export interface IResolveContext {
7 /**
8 * The scope from which resolution has been initiated
9 */
10 readonly scope: IConstruct;
11 /**
12 * True when we are still preparing, false if we're rendering the final output
13 */
14 readonly preparing: boolean;
15 /**
16 * Path in the JSON document that is being constructed
17 */
18 readonly documentPath: string[];
19 /**
20 * Resolve an inner object
21 */
22 resolve(x: any, options?: ResolveChangeContextOptions): any;
23 /**
24 * Use this postprocessor after the entire token structure has been resolved
25 */
26 registerPostProcessor(postProcessor: IPostProcessor): void;
27}
28/**
29 * Options that can be changed while doing a recursive resolve
30 */
31export interface ResolveChangeContextOptions {
32 /**
33 * Change the 'allowIntrinsicKeys' option
34 *
35 * @default - Unchanged
36 */
37 readonly allowIntrinsicKeys?: boolean;
38}
39/**
40 * Interface for values that can be resolvable later
41 *
42 * Tokens are special objects that participate in synthesis.
43 */
44export interface IResolvable {
45 /**
46 * The creation stack of this resolvable which will be appended to errors
47 * thrown during resolution.
48 *
49 * This may return an array with a single informational element indicating how
50 * to get this property populated, if it was skipped for performance reasons.
51 */
52 readonly creationStack: string[];
53 /**
54 * Produce the Token's value at resolution time
55 */
56 resolve(context: IResolveContext): any;
57 /**
58 * Return a string representation of this resolvable object.
59 *
60 * Returns a reversible string representation.
61 */
62 toString(): string;
63}
64/**
65 * A Token that can post-process the complete resolved value, after resolve() has recursed over it
66 */
67export interface IPostProcessor {
68 /**
69 * Process the completely resolved value, after full recursion/resolution has happened
70 */
71 postProcess(input: any, context: IResolveContext): any;
72}
73/**
74 * How to resolve tokens
75 */
76export interface ITokenResolver {
77 /**
78 * Resolve a single token
79 */
80 resolveToken(t: IResolvable, context: IResolveContext, postProcessor: IPostProcessor): any;
81 /**
82 * Resolve a string with at least one stringified token in it
83 *
84 * (May use concatenation)
85 */
86 resolveString(s: TokenizedStringFragments, context: IResolveContext): any;
87 /**
88 * Resolve a tokenized list
89 */
90 resolveList(l: string[], context: IResolveContext): any;
91}
92/**
93 * Function used to concatenate symbols in the target document language
94 *
95 * Interface so it could potentially be exposed over jsii.
96 *
97 */
98export interface IFragmentConcatenator {
99 /**
100 * Join the fragment on the left and on the right
101 */
102 join(left: any | undefined, right: any | undefined): any;
103}
104/**
105 * Converts all fragments to strings and concats those
106 *
107 * Drops 'undefined's.
108 */
109export declare class StringConcat implements IFragmentConcatenator {
110 join(left: any | undefined, right: any | undefined): any;
111}
112/**
113 * Default resolver implementation
114 *
115 */
116export declare class DefaultTokenResolver implements ITokenResolver {
117 private readonly concat;
118 constructor(concat: IFragmentConcatenator);
119 /**
120 * Default Token resolution
121 *
122 * Resolve the Token, recurse into whatever it returns,
123 * then finally post-process it.
124 */
125 resolveToken(t: IResolvable, context: IResolveContext, postProcessor: IPostProcessor): any;
126 /**
127 * Resolve string fragments to Tokens
128 */
129 resolveString(fragments: TokenizedStringFragments, context: IResolveContext): any;
130 resolveList(xs: string[], context: IResolveContext): any;
131}