-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.d.ts
174 lines (153 loc) · 5.35 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
// SPDX-License-Identifier: MIT
// TypeScript Version: 3.2
/**
* `JsonnetPrimitiveValue` is a class of values that may be passed to native callbacks.
*/
export type JsonnetPrimitiveValue = null | boolean | number | string;
export class JsonnetError extends Error {
}
/**
* `Jsonnet` is a Jsonnet interpreter. It has a fluent interface: all the setter methods modify the receiver and return it.
*/
export class Jsonnet {
/**
* Returns the version of linked libjsonnet.
*/
static readonly version: string;
/**
* Constructs a new Jsonnet interpreter.
*/
constructor();
/**
* Set the maximum stack depth.
*
* @param value - The stack depth.
*/
maxStack(value: number): this;
/**
* Set the number of lines of back trace to display.
*
* @param value - The number of lines.
*/
maxTrace(value: number): this;
/**
* Set the minimal number of objects required to trigger a garbage collection.
*
* @param value - The number of objects.
*/
maxGcMinObjects(value: number): this;
/**
* Set the growth rate of the number of objects to trigger a garbage collection.
*
* @param value - The growth rate.
*/
maxGcGrowthTrigger(value: number): this;
/**
* Set whether the evaluation results are returned in plain string instead of in JSON.
*
* @param value - Whether output is in plain string.
*/
stringOutput(value: boolean): this;
/**
* Binds external variable named as `key` to string `value`.
*
* @param key - Name of the external variable
* @param value - String value to which the variable is bound
*/
extString(key: string, value: string): this;
/**
* Binds external variable named as `key` to a value represented by `value`.
*
* @param key - Name of the external variable
* @param value - Code representation of the value to which the variable is bound
*/
extCode(key: string, value: string): this;
/**
* Binds top-level argument named as `key` to string `value`.
*
* @param key - Name of the top-level argument
* @param value - String value to which the argument is bound
*/
tlaString(key: string, value: string): this;
/**
* Binds top-level argument named as `key` to a value represented by `value`.
*
* @param key - Name of the top-level argument
* @param value - Code representation of the value to which the argument is bound
*/
tlaCode(key: string, value: string): this;
/**
* Adds a path to the list of include paths. Paths added more recently take precedence.
*
* @param path - Path to add.
*/
addJpath(path: string): this;
/**
* Registers a native callback function.
*
* @example
* ```typescript
* const jsonnet = new Jsonnet();
* jsonnet.nativeCallback("add", (a, b) => Number(a) + Number(b), "a", "b");
* jsonnet.evaluateSnippet('std.native("add")(2, 3)')
* .then(result => console.log(JSON.parse(result))); // => 5
* ```
*
* @param name - Name of the callback function.
* @param fun - The function to register as a callback.
* `fun` can return an Object as the callback result or a Promise for it.
* Since the result will be serialized as JSON before passed back to Jsonnet,
* it cannot contain any recursive structures.
* @param params - Names of the function parameters.
* `params` must have the equal number of elements as the number of the parameters of `fun`.
*/
nativeCallback<T extends string[]>(
name: string,
fun: (...args: JsonnetPrimitiveValue[] & { [K in keyof T]: JsonnetPrimitiveValue }) => any,
...params: T): this;
/**
* Evaluates a Jsonnet script in a file.
*
* @param filename - Path to the file.
* @returns A Promise for the evaluation result in JSON representation.
*/
evaluateFile(filename: string): Promise<string>;
/**
* Evaluates a Jsonnet script given as a string.
*
* @param snippet - Jsonnet script to evaluate.
* @param filename - Filename used for error reporting.
* @returns A Promise for the evaluation result in JSON representation.
*/
evaluateSnippet(snippet: string, filename?: string): Promise<string>;
/**
* Evaluates a Jsonnet script in a file and returns a number of named JSON's.
*
* @param filename - Path to the file.
* @returns A Promise for the evaluation result in JSON representation.
*/
evaluateFileMulti(filename: string): Promise<{ [name: string]: string }>;
/**
* Evaluates a Jsonnet script given as a string and returns a number of named JSON's.
*
* @param snippet - Jsonnet script to evaluate.
* @param filename - Filename used for error reporting.
* @returns A Promise for the evaluation result in JSON representation.
*/
evaluateSnippetMulti(snippet: string, filename?: string): Promise<{ [name: string]: string }>;
/**
* Evaluates a Jsonnet script in a file and returns a number of JSON's.
*
* @param filename - Path to the file.
* @returns A Promise for the evaluation result in JSON representation.
*/
evaluateFileStream(filename: string): Promise<string[]>;
/**
* Evaluates a Jsonnet script given as a string and returns a number of JSON's.
*
* @param snippet - Jsonnet script to evaluate.
* @param filename - Filename used for error reporting.
* @returns A Promise for the evaluation result in JSON representation.
*/
evaluateSnippetStream(snippet: string, filename?: string): Promise<string[]>;
}