ogi-addon 0.1.2 → 0.2.0
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/build/EventResponse.cjs +46 -0
- package/build/EventResponse.cjs.map +1 -0
- package/build/EventResponse.d.cts +13 -0
- package/build/EventResponse.d.ts +13 -0
- package/build/EventResponse.js +25 -0
- package/build/EventResponse.js.map +1 -0
- package/build/SearchEngine.cjs +19 -0
- package/build/SearchEngine.cjs.map +1 -0
- package/build/SearchEngine.d.cts +15 -0
- package/build/SearchEngine.d.ts +15 -0
- package/build/SearchEngine.js +1 -0
- package/build/SearchEngine.js.map +1 -0
- package/build/config/Configuration.cjs +282 -0
- package/build/config/Configuration.cjs.map +1 -0
- package/build/config/Configuration.d.cts +20 -0
- package/build/config/Configuration.d.ts +20 -0
- package/build/config/Configuration.js +237 -0
- package/build/config/Configuration.js.map +1 -0
- package/build/config/ConfigurationBuilder.cjs +208 -0
- package/build/config/ConfigurationBuilder.cjs.map +1 -0
- package/build/config/ConfigurationBuilder.d.cts +57 -0
- package/build/config/ConfigurationBuilder.d.ts +57 -0
- package/build/config/ConfigurationBuilder.js +166 -0
- package/build/config/ConfigurationBuilder.js.map +1 -0
- package/build/main.cjs +1 -1
- package/build/main.cjs.map +1 -1
- package/build/main.d.cts +15 -93
- package/build/main.d.ts +15 -93
- package/build/main.js +1 -1
- package/build/main.js.map +1 -1
- package/package.json +20 -4
- package/src/SearchEngine.ts +9 -4
- package/src/config/Configuration.ts +4 -2
- package/src/main.ts +13 -2
- package/tsup.config.js +1 -1
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
// src/config/ConfigurationBuilder.ts
|
|
2
|
+
import z, { ZodError } from "zod";
|
|
3
|
+
var configValidation = z.object({
|
|
4
|
+
name: z.string().min(1),
|
|
5
|
+
displayName: z.string().min(1),
|
|
6
|
+
description: z.string().min(1)
|
|
7
|
+
});
|
|
8
|
+
function isStringOption(option) {
|
|
9
|
+
return option.type === "string";
|
|
10
|
+
}
|
|
11
|
+
function isNumberOption(option) {
|
|
12
|
+
return option.type === "number";
|
|
13
|
+
}
|
|
14
|
+
function isBooleanOption(option) {
|
|
15
|
+
return option.type === "boolean";
|
|
16
|
+
}
|
|
17
|
+
var ConfigurationBuilder = class {
|
|
18
|
+
options = [];
|
|
19
|
+
addNumberOption(option) {
|
|
20
|
+
let newOption = new NumberOption();
|
|
21
|
+
newOption = option(newOption);
|
|
22
|
+
this.options.push(newOption);
|
|
23
|
+
return this;
|
|
24
|
+
}
|
|
25
|
+
addStringOption(option) {
|
|
26
|
+
let newOption = new StringOption();
|
|
27
|
+
newOption = option(newOption);
|
|
28
|
+
this.options.push(newOption);
|
|
29
|
+
return this;
|
|
30
|
+
}
|
|
31
|
+
addBooleanOption(option) {
|
|
32
|
+
let newOption = new BooleanOption();
|
|
33
|
+
newOption = option(newOption);
|
|
34
|
+
this.options.push(newOption);
|
|
35
|
+
return this;
|
|
36
|
+
}
|
|
37
|
+
build(includeFunctions) {
|
|
38
|
+
let config = {};
|
|
39
|
+
this.options.forEach((option) => {
|
|
40
|
+
if (!includeFunctions) {
|
|
41
|
+
option = JSON.parse(JSON.stringify(option));
|
|
42
|
+
const optionData = configValidation.safeParse(option);
|
|
43
|
+
if (!optionData.success) {
|
|
44
|
+
throw new ZodError(optionData.error.errors);
|
|
45
|
+
}
|
|
46
|
+
config[option.name] = option;
|
|
47
|
+
} else {
|
|
48
|
+
config[option.name] = option;
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
return config;
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
var ConfigurationOption = class {
|
|
55
|
+
name = "";
|
|
56
|
+
defaultValue = "";
|
|
57
|
+
displayName = "";
|
|
58
|
+
description = "";
|
|
59
|
+
type = "unset";
|
|
60
|
+
setName(name) {
|
|
61
|
+
this.name = name;
|
|
62
|
+
return this;
|
|
63
|
+
}
|
|
64
|
+
setDisplayName(displayName) {
|
|
65
|
+
this.displayName = displayName;
|
|
66
|
+
return this;
|
|
67
|
+
}
|
|
68
|
+
setDescription(description) {
|
|
69
|
+
this.description = description;
|
|
70
|
+
return this;
|
|
71
|
+
}
|
|
72
|
+
validate(input) {
|
|
73
|
+
throw new Error("Validation code not implemented. Value: " + input);
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
var StringOption = class extends ConfigurationOption {
|
|
77
|
+
allowedValues = [];
|
|
78
|
+
minTextLength = 0;
|
|
79
|
+
maxTextLength = Number.MAX_SAFE_INTEGER;
|
|
80
|
+
defaultValue = "";
|
|
81
|
+
type = "string";
|
|
82
|
+
setAllowedValues(allowedValues) {
|
|
83
|
+
this.allowedValues = allowedValues;
|
|
84
|
+
return this;
|
|
85
|
+
}
|
|
86
|
+
setDefaultValue(defaultValue) {
|
|
87
|
+
this.defaultValue = defaultValue;
|
|
88
|
+
return this;
|
|
89
|
+
}
|
|
90
|
+
setMinTextLength(minTextLength) {
|
|
91
|
+
this.minTextLength = minTextLength;
|
|
92
|
+
return this;
|
|
93
|
+
}
|
|
94
|
+
setMaxTextLength(maxTextLength) {
|
|
95
|
+
this.maxTextLength = maxTextLength;
|
|
96
|
+
return this;
|
|
97
|
+
}
|
|
98
|
+
validate(input) {
|
|
99
|
+
if (typeof input !== "string") {
|
|
100
|
+
return [false, "Input is not a string"];
|
|
101
|
+
}
|
|
102
|
+
if (this.allowedValues.length === 0 && input.length !== 0)
|
|
103
|
+
return [true, ""];
|
|
104
|
+
if (input.length < this.minTextLength || input.length > this.maxTextLength) {
|
|
105
|
+
return [false, "Input is not within the text length " + this.minTextLength + " and " + this.maxTextLength + " characters (currently " + input.length + " characters)"];
|
|
106
|
+
}
|
|
107
|
+
return [this.allowedValues.includes(input), "Input is not an allowed value"];
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
var NumberOption = class extends ConfigurationOption {
|
|
111
|
+
min = 0;
|
|
112
|
+
max = Number.MAX_SAFE_INTEGER;
|
|
113
|
+
defaultValue = 0;
|
|
114
|
+
type = "number";
|
|
115
|
+
inputType = "number";
|
|
116
|
+
setMin(min) {
|
|
117
|
+
this.min = min;
|
|
118
|
+
return this;
|
|
119
|
+
}
|
|
120
|
+
setInputType(type) {
|
|
121
|
+
this.inputType = type;
|
|
122
|
+
return this;
|
|
123
|
+
}
|
|
124
|
+
setMax(max) {
|
|
125
|
+
this.max = max;
|
|
126
|
+
return this;
|
|
127
|
+
}
|
|
128
|
+
setDefaultValue(defaultValue) {
|
|
129
|
+
this.defaultValue = defaultValue;
|
|
130
|
+
return this;
|
|
131
|
+
}
|
|
132
|
+
validate(input) {
|
|
133
|
+
if (isNaN(Number(input))) {
|
|
134
|
+
return [false, "Input is not a number"];
|
|
135
|
+
}
|
|
136
|
+
if (Number(input) < this.min || Number(input) > this.max) {
|
|
137
|
+
return [false, "Input is not within the range of " + this.min + " and " + this.max];
|
|
138
|
+
}
|
|
139
|
+
return [true, ""];
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
var BooleanOption = class extends ConfigurationOption {
|
|
143
|
+
type = "boolean";
|
|
144
|
+
defaultValue = false;
|
|
145
|
+
setDefaultValue(defaultValue) {
|
|
146
|
+
this.defaultValue = defaultValue;
|
|
147
|
+
return this;
|
|
148
|
+
}
|
|
149
|
+
validate(input) {
|
|
150
|
+
if (typeof input !== "boolean") {
|
|
151
|
+
return [false, "Input is not a boolean"];
|
|
152
|
+
}
|
|
153
|
+
return [true, ""];
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
// src/config/Configuration.ts
|
|
158
|
+
var Configuration = class {
|
|
159
|
+
storedConfigTemplate;
|
|
160
|
+
definiteConfig = {};
|
|
161
|
+
constructor(configTemplate) {
|
|
162
|
+
this.storedConfigTemplate = configTemplate;
|
|
163
|
+
}
|
|
164
|
+
updateConfig(config, validate = true) {
|
|
165
|
+
this.definiteConfig = config;
|
|
166
|
+
if (validate) {
|
|
167
|
+
const result = this.validateConfig();
|
|
168
|
+
return result;
|
|
169
|
+
}
|
|
170
|
+
return [true, {}];
|
|
171
|
+
}
|
|
172
|
+
// provides falsey or truthy value, and an error message if falsey
|
|
173
|
+
validateConfig() {
|
|
174
|
+
const erroredKeys = /* @__PURE__ */ new Map();
|
|
175
|
+
for (const key in this.storedConfigTemplate) {
|
|
176
|
+
if (this.definiteConfig[key] === null || this.definiteConfig[key] === void 0) {
|
|
177
|
+
console.warn("Option " + key + " is not defined. Using default value Value: " + this.definiteConfig[key]);
|
|
178
|
+
this.definiteConfig[key] = this.storedConfigTemplate[key].defaultValue;
|
|
179
|
+
}
|
|
180
|
+
if (this.storedConfigTemplate[key].type !== typeof this.definiteConfig[key]) {
|
|
181
|
+
throw new Error("Option " + key + " is not of the correct type");
|
|
182
|
+
}
|
|
183
|
+
const result = this.storedConfigTemplate[key].validate(this.definiteConfig[key]);
|
|
184
|
+
if (!result[0]) {
|
|
185
|
+
erroredKeys.set(key, result[1]);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
for (const key in this.definiteConfig) {
|
|
189
|
+
if (!this.storedConfigTemplate[key]) {
|
|
190
|
+
throw new Error("Option " + key + " is not defined in the configuration template");
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
if (erroredKeys.size > 0) {
|
|
194
|
+
return [false, Object.fromEntries(erroredKeys)];
|
|
195
|
+
}
|
|
196
|
+
return [true, Object.fromEntries(erroredKeys)];
|
|
197
|
+
}
|
|
198
|
+
getStringValue(optionName) {
|
|
199
|
+
if (!this.definiteConfig[optionName] === null) {
|
|
200
|
+
throw new Error("Option " + optionName + " is not defined");
|
|
201
|
+
}
|
|
202
|
+
if (typeof this.definiteConfig[optionName] !== "string") {
|
|
203
|
+
throw new Error("Option " + optionName + " is not a string");
|
|
204
|
+
}
|
|
205
|
+
return this.definiteConfig[optionName];
|
|
206
|
+
}
|
|
207
|
+
getNumberValue(optionName) {
|
|
208
|
+
if (!this.definiteConfig[optionName] === null) {
|
|
209
|
+
throw new Error("Option " + optionName + " is not defined");
|
|
210
|
+
}
|
|
211
|
+
if (typeof this.definiteConfig[optionName] !== "number") {
|
|
212
|
+
throw new Error("Option " + optionName + " is not a number");
|
|
213
|
+
}
|
|
214
|
+
return this.definiteConfig[optionName];
|
|
215
|
+
}
|
|
216
|
+
getBooleanValue(optionName) {
|
|
217
|
+
if (this.definiteConfig[optionName] === null) {
|
|
218
|
+
throw new Error("Option " + optionName + " is not defined");
|
|
219
|
+
}
|
|
220
|
+
if (typeof this.definiteConfig[optionName] !== "boolean") {
|
|
221
|
+
throw new Error("Option " + optionName + " is not a boolean");
|
|
222
|
+
}
|
|
223
|
+
return this.definiteConfig[optionName];
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
export {
|
|
227
|
+
BooleanOption,
|
|
228
|
+
Configuration,
|
|
229
|
+
ConfigurationBuilder,
|
|
230
|
+
ConfigurationOption,
|
|
231
|
+
NumberOption,
|
|
232
|
+
StringOption,
|
|
233
|
+
isBooleanOption,
|
|
234
|
+
isNumberOption,
|
|
235
|
+
isStringOption
|
|
236
|
+
};
|
|
237
|
+
//# sourceMappingURL=Configuration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/config/ConfigurationBuilder.ts","../../src/config/Configuration.ts"],"sourcesContent":["import z, { ZodError } from \"zod\"\r\n\r\nexport interface ConfigurationFile {\r\n [key: string]: ConfigurationOption\r\n}\r\n\r\nconst configValidation = z.object({\r\n name: z.string().min(1),\r\n displayName: z.string().min(1),\r\n description: z.string().min(1),\r\n})\r\n\r\nexport function isStringOption(option: ConfigurationOption): option is StringOption {\r\n return option.type === 'string';\r\n }\r\n\r\nexport function isNumberOption(option: ConfigurationOption): option is NumberOption {\r\n return option.type === 'number';\r\n}\r\n\r\nexport function isBooleanOption(option: ConfigurationOption): option is BooleanOption {\r\n return option.type === 'boolean';\r\n}\r\n\r\nexport class ConfigurationBuilder {\r\n private options: ConfigurationOption[] = [];\r\n public addNumberOption(option: (option: NumberOption) => NumberOption): ConfigurationBuilder {\r\n let newOption = new NumberOption();\r\n newOption = option(newOption);\r\n this.options.push(newOption);\r\n return this;\r\n }\r\n\r\n public addStringOption(option: (option: StringOption) => StringOption) {\r\n let newOption = new StringOption();\r\n newOption = option(newOption);\r\n this.options.push(newOption);\r\n return this;\r\n }\r\n\r\n public addBooleanOption(option: (option: BooleanOption) => BooleanOption) {\r\n let newOption = new BooleanOption();\r\n newOption = option(newOption);\r\n this.options.push(newOption);\r\n return this;\r\n }\r\n\r\n public build(includeFunctions: boolean): ConfigurationFile {\r\n let config: ConfigurationFile = {};\r\n this.options.forEach(option => {\r\n // remove all functions from the option object\r\n if (!includeFunctions) {\r\n option = JSON.parse(JSON.stringify(option));\r\n const optionData = configValidation.safeParse(option)\r\n if (!optionData.success) {\r\n throw new ZodError(optionData.error.errors)\r\n }\r\n\r\n config[option.name] = option;\r\n }\r\n else {\r\n config[option.name] = option;\r\n }\r\n });\r\n return config;\r\n }\r\n}\r\n\r\nexport type ConfigurationOptionType = 'string' | 'number' | 'boolean' | 'unset'\r\nexport class ConfigurationOption {\r\n public name: string = '';\r\n public defaultValue: unknown = '';\r\n public displayName: string = '';\r\n public description: string = '';\r\n public type: ConfigurationOptionType = 'unset'\r\n \r\n setName(name: string) {\r\n this.name = name;\r\n return this;\r\n }\r\n\r\n setDisplayName(displayName: string) {\r\n this.displayName = displayName;\r\n return this;\r\n }\r\n\r\n setDescription(description: string) {\r\n this.description = description;\r\n return this;\r\n }\r\n\r\n\r\n validate(input: unknown): [ boolean, string ] {\r\n throw new Error('Validation code not implemented. Value: ' + input)\r\n };\r\n}\r\n\r\nexport class StringOption extends ConfigurationOption {\r\n public allowedValues: string[] = [];\r\n public minTextLength: number = 0;\r\n public maxTextLength: number = Number.MAX_SAFE_INTEGER;\r\n public defaultValue: string = '';\r\n public type: ConfigurationOptionType = 'string'\r\n\r\n setAllowedValues(allowedValues: string[]): this {\r\n this.allowedValues = allowedValues;\r\n return this;\r\n }\r\n\r\n setDefaultValue(defaultValue: string): this {\r\n this.defaultValue = defaultValue;\r\n return this;\r\n }\r\n\r\n setMinTextLength(minTextLength: number): this {\r\n this.minTextLength = minTextLength;\r\n return this;\r\n }\r\n\r\n setMaxTextLength(maxTextLength: number): this {\r\n this.maxTextLength = maxTextLength;\r\n return this;\r\n }\r\n\r\n override validate(input: unknown): [ boolean, string ] {\r\n if (typeof input !== 'string') {\r\n return [ false, 'Input is not a string' ];\r\n }\r\n if (this.allowedValues.length === 0 && input.length !== 0)\r\n return [ true, '' ];\r\n if (input.length < this.minTextLength || input.length > this.maxTextLength) {\r\n return [ false, 'Input is not within the text length ' + this.minTextLength + ' and ' + this.maxTextLength + ' characters (currently ' + input.length + ' characters)' ];\r\n }\r\n\r\n return [ this.allowedValues.includes(input), 'Input is not an allowed value' ];\r\n }\r\n}\r\n\r\nexport class NumberOption extends ConfigurationOption {\r\n public min: number = 0;\r\n public max: number = Number.MAX_SAFE_INTEGER;\r\n public defaultValue: number = 0;\r\n public type: ConfigurationOptionType = 'number'\r\n public inputType: 'range' | 'number' = 'number';\r\n setMin(min: number): this {\r\n this.min = min;\r\n return this;\r\n }\r\n\r\n setInputType(type: 'range' | 'number'): this {\r\n this.inputType = type;\r\n return this;\r\n }\r\n\r\n setMax(max: number): this {\r\n this.max = max;\r\n return this\r\n }\r\n\r\n setDefaultValue(defaultValue: number): this {\r\n this.defaultValue = defaultValue;\r\n return this;\r\n }\r\n\r\n override validate(input: unknown): [ boolean, string ] {\r\n if (isNaN(Number(input))) {\r\n return [ false, 'Input is not a number' ];\r\n }\r\n if (Number(input) < this.min || Number(input) > this.max) {\r\n return [ false, 'Input is not within the range of ' + this.min + ' and ' + this.max ];\r\n }\r\n return [ true, '' ];\r\n }\r\n\r\n}\r\n\r\nexport class BooleanOption extends ConfigurationOption {\r\n public type: ConfigurationOptionType = 'boolean'\r\n public defaultValue: boolean = false;\r\n\r\n setDefaultValue(defaultValue: boolean): this {\r\n this.defaultValue = defaultValue;\r\n return this;\r\n }\r\n\r\n override validate(input: unknown): [ boolean, string ] {\r\n if (typeof input !== 'boolean') {\r\n return [ false, 'Input is not a boolean' ];\r\n }\r\n return [ true, '' ];\r\n }\r\n\r\n}","import { ConfigurationFile, ConfigurationBuilder, BooleanOption, ConfigurationOption, ConfigurationOptionType, NumberOption, StringOption, isBooleanOption, isNumberOption, isStringOption } from \"./ConfigurationBuilder\";\r\n\r\ninterface DefiniteConfig {\r\n [key: string]: string | number | boolean;\r\n}\r\nexport class Configuration {\r\n readonly storedConfigTemplate: ConfigurationFile;\r\n definiteConfig: DefiniteConfig = {};\r\n constructor(configTemplate: ConfigurationFile) {\r\n this.storedConfigTemplate = configTemplate;\r\n }\r\n\r\n updateConfig(config: DefiniteConfig, validate: boolean = true): [ boolean, { [key: string]: string } ] {\r\n this.definiteConfig = config;\r\n if (validate) {\r\n const result = this.validateConfig();\r\n return result;\r\n }\r\n return [ true, {} ];\r\n }\r\n // provides falsey or truthy value, and an error message if falsey\r\n private validateConfig(): [ boolean, { [key: string]: string } ] {\r\n const erroredKeys = new Map<string, string>();\r\n for (const key in this.storedConfigTemplate) {\r\n if (this.definiteConfig[key] === null || this.definiteConfig[key] === undefined) {\r\n console.warn('Option ' + key + ' is not defined. Using default value Value: ' + this.definiteConfig[key]);\r\n this.definiteConfig[key] = this.storedConfigTemplate[key].defaultValue as string | number | boolean;\r\n }\r\n if (this.storedConfigTemplate[key].type !== typeof this.definiteConfig[key]) {\r\n throw new Error('Option ' + key + ' is not of the correct type');\r\n }\r\n\r\n const result = this.storedConfigTemplate[key].validate(this.definiteConfig[key]);\r\n if (!result[0]) {\r\n erroredKeys.set(key, result[1]);\r\n }\r\n }\r\n\r\n for (const key in this.definiteConfig) {\r\n if (!this.storedConfigTemplate[key]) {\r\n throw new Error('Option ' + key + ' is not defined in the configuration template');\r\n }\r\n }\r\n\r\n if (erroredKeys.size > 0) {\r\n return [ false, Object.fromEntries(erroredKeys) ];\r\n }\r\n\r\n return [ true, Object.fromEntries(erroredKeys) ];\r\n }\r\n\r\n getStringValue(optionName: string): string {\r\n if (!this.definiteConfig[optionName] === null) {\r\n throw new Error('Option ' + optionName + ' is not defined');\r\n }\r\n if (typeof this.definiteConfig[optionName] !== 'string') {\r\n throw new Error('Option ' + optionName + ' is not a string');\r\n }\r\n return this.definiteConfig[optionName];\r\n }\r\n\r\n getNumberValue(optionName: string): number {\r\n if (!this.definiteConfig[optionName] === null) {\r\n throw new Error('Option ' + optionName + ' is not defined');\r\n }\r\n if (typeof this.definiteConfig[optionName] !== 'number') {\r\n throw new Error('Option ' + optionName + ' is not a number');\r\n }\r\n return this.definiteConfig[optionName];\r\n }\r\n\r\n getBooleanValue(optionName: string): boolean {\r\n if (this.definiteConfig[optionName] === null) {\r\n throw new Error('Option ' + optionName + ' is not defined');\r\n }\r\n if (typeof this.definiteConfig[optionName] !== 'boolean') {\r\n throw new Error('Option ' + optionName + ' is not a boolean');\r\n }\r\n return this.definiteConfig[optionName];\r\n }\r\n}\r\n\r\nexport { ConfigurationFile, ConfigurationBuilder, BooleanOption, ConfigurationOption, ConfigurationOptionType, NumberOption, StringOption, isBooleanOption, isNumberOption, isStringOption };"],"mappings":";AAAA,OAAO,KAAK,gBAAgB;AAM5B,IAAM,mBAAmB,EAAE,OAAO;AAAA,EAChC,MAAM,EAAE,OAAO,EAAE,IAAI,CAAC;AAAA,EACtB,aAAa,EAAE,OAAO,EAAE,IAAI,CAAC;AAAA,EAC7B,aAAa,EAAE,OAAO,EAAE,IAAI,CAAC;AAC/B,CAAC;AAEM,SAAS,eAAe,QAAqD;AAChF,SAAO,OAAO,SAAS;AACzB;AAEK,SAAS,eAAe,QAAqD;AAClF,SAAO,OAAO,SAAS;AACzB;AAEO,SAAS,gBAAgB,QAAsD;AACpF,SAAO,OAAO,SAAS;AACzB;AAEO,IAAM,uBAAN,MAA2B;AAAA,EACxB,UAAiC,CAAC;AAAA,EACnC,gBAAgB,QAAsE;AAC3F,QAAI,YAAY,IAAI,aAAa;AACjC,gBAA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;AACA,QAAI,OAAO,KAAK,eAAe,UAAU,MAAM,WAAW;AACxD,YAAM,IAAI,MAAM,YAAY,aAAa,mBAAmB;AAAA,IAC9D;AACA,WAAO,KAAK,eAAe,UAAU;AAAA,EACvC;AACF;","names":[]}
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/config/ConfigurationBuilder.ts
|
|
31
|
+
var ConfigurationBuilder_exports = {};
|
|
32
|
+
__export(ConfigurationBuilder_exports, {
|
|
33
|
+
BooleanOption: () => BooleanOption,
|
|
34
|
+
ConfigurationBuilder: () => ConfigurationBuilder,
|
|
35
|
+
ConfigurationOption: () => ConfigurationOption,
|
|
36
|
+
NumberOption: () => NumberOption,
|
|
37
|
+
StringOption: () => StringOption,
|
|
38
|
+
isBooleanOption: () => isBooleanOption,
|
|
39
|
+
isNumberOption: () => isNumberOption,
|
|
40
|
+
isStringOption: () => isStringOption
|
|
41
|
+
});
|
|
42
|
+
module.exports = __toCommonJS(ConfigurationBuilder_exports);
|
|
43
|
+
var import_zod = __toESM(require("zod"), 1);
|
|
44
|
+
var configValidation = import_zod.default.object({
|
|
45
|
+
name: import_zod.default.string().min(1),
|
|
46
|
+
displayName: import_zod.default.string().min(1),
|
|
47
|
+
description: import_zod.default.string().min(1)
|
|
48
|
+
});
|
|
49
|
+
function isStringOption(option) {
|
|
50
|
+
return option.type === "string";
|
|
51
|
+
}
|
|
52
|
+
function isNumberOption(option) {
|
|
53
|
+
return option.type === "number";
|
|
54
|
+
}
|
|
55
|
+
function isBooleanOption(option) {
|
|
56
|
+
return option.type === "boolean";
|
|
57
|
+
}
|
|
58
|
+
var ConfigurationBuilder = class {
|
|
59
|
+
options = [];
|
|
60
|
+
addNumberOption(option) {
|
|
61
|
+
let newOption = new NumberOption();
|
|
62
|
+
newOption = option(newOption);
|
|
63
|
+
this.options.push(newOption);
|
|
64
|
+
return this;
|
|
65
|
+
}
|
|
66
|
+
addStringOption(option) {
|
|
67
|
+
let newOption = new StringOption();
|
|
68
|
+
newOption = option(newOption);
|
|
69
|
+
this.options.push(newOption);
|
|
70
|
+
return this;
|
|
71
|
+
}
|
|
72
|
+
addBooleanOption(option) {
|
|
73
|
+
let newOption = new BooleanOption();
|
|
74
|
+
newOption = option(newOption);
|
|
75
|
+
this.options.push(newOption);
|
|
76
|
+
return this;
|
|
77
|
+
}
|
|
78
|
+
build(includeFunctions) {
|
|
79
|
+
let config = {};
|
|
80
|
+
this.options.forEach((option) => {
|
|
81
|
+
if (!includeFunctions) {
|
|
82
|
+
option = JSON.parse(JSON.stringify(option));
|
|
83
|
+
const optionData = configValidation.safeParse(option);
|
|
84
|
+
if (!optionData.success) {
|
|
85
|
+
throw new import_zod.ZodError(optionData.error.errors);
|
|
86
|
+
}
|
|
87
|
+
config[option.name] = option;
|
|
88
|
+
} else {
|
|
89
|
+
config[option.name] = option;
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
return config;
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
var ConfigurationOption = class {
|
|
96
|
+
name = "";
|
|
97
|
+
defaultValue = "";
|
|
98
|
+
displayName = "";
|
|
99
|
+
description = "";
|
|
100
|
+
type = "unset";
|
|
101
|
+
setName(name) {
|
|
102
|
+
this.name = name;
|
|
103
|
+
return this;
|
|
104
|
+
}
|
|
105
|
+
setDisplayName(displayName) {
|
|
106
|
+
this.displayName = displayName;
|
|
107
|
+
return this;
|
|
108
|
+
}
|
|
109
|
+
setDescription(description) {
|
|
110
|
+
this.description = description;
|
|
111
|
+
return this;
|
|
112
|
+
}
|
|
113
|
+
validate(input) {
|
|
114
|
+
throw new Error("Validation code not implemented. Value: " + input);
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
var StringOption = class extends ConfigurationOption {
|
|
118
|
+
allowedValues = [];
|
|
119
|
+
minTextLength = 0;
|
|
120
|
+
maxTextLength = Number.MAX_SAFE_INTEGER;
|
|
121
|
+
defaultValue = "";
|
|
122
|
+
type = "string";
|
|
123
|
+
setAllowedValues(allowedValues) {
|
|
124
|
+
this.allowedValues = allowedValues;
|
|
125
|
+
return this;
|
|
126
|
+
}
|
|
127
|
+
setDefaultValue(defaultValue) {
|
|
128
|
+
this.defaultValue = defaultValue;
|
|
129
|
+
return this;
|
|
130
|
+
}
|
|
131
|
+
setMinTextLength(minTextLength) {
|
|
132
|
+
this.minTextLength = minTextLength;
|
|
133
|
+
return this;
|
|
134
|
+
}
|
|
135
|
+
setMaxTextLength(maxTextLength) {
|
|
136
|
+
this.maxTextLength = maxTextLength;
|
|
137
|
+
return this;
|
|
138
|
+
}
|
|
139
|
+
validate(input) {
|
|
140
|
+
if (typeof input !== "string") {
|
|
141
|
+
return [false, "Input is not a string"];
|
|
142
|
+
}
|
|
143
|
+
if (this.allowedValues.length === 0 && input.length !== 0)
|
|
144
|
+
return [true, ""];
|
|
145
|
+
if (input.length < this.minTextLength || input.length > this.maxTextLength) {
|
|
146
|
+
return [false, "Input is not within the text length " + this.minTextLength + " and " + this.maxTextLength + " characters (currently " + input.length + " characters)"];
|
|
147
|
+
}
|
|
148
|
+
return [this.allowedValues.includes(input), "Input is not an allowed value"];
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
var NumberOption = class extends ConfigurationOption {
|
|
152
|
+
min = 0;
|
|
153
|
+
max = Number.MAX_SAFE_INTEGER;
|
|
154
|
+
defaultValue = 0;
|
|
155
|
+
type = "number";
|
|
156
|
+
inputType = "number";
|
|
157
|
+
setMin(min) {
|
|
158
|
+
this.min = min;
|
|
159
|
+
return this;
|
|
160
|
+
}
|
|
161
|
+
setInputType(type) {
|
|
162
|
+
this.inputType = type;
|
|
163
|
+
return this;
|
|
164
|
+
}
|
|
165
|
+
setMax(max) {
|
|
166
|
+
this.max = max;
|
|
167
|
+
return this;
|
|
168
|
+
}
|
|
169
|
+
setDefaultValue(defaultValue) {
|
|
170
|
+
this.defaultValue = defaultValue;
|
|
171
|
+
return this;
|
|
172
|
+
}
|
|
173
|
+
validate(input) {
|
|
174
|
+
if (isNaN(Number(input))) {
|
|
175
|
+
return [false, "Input is not a number"];
|
|
176
|
+
}
|
|
177
|
+
if (Number(input) < this.min || Number(input) > this.max) {
|
|
178
|
+
return [false, "Input is not within the range of " + this.min + " and " + this.max];
|
|
179
|
+
}
|
|
180
|
+
return [true, ""];
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
var BooleanOption = class extends ConfigurationOption {
|
|
184
|
+
type = "boolean";
|
|
185
|
+
defaultValue = false;
|
|
186
|
+
setDefaultValue(defaultValue) {
|
|
187
|
+
this.defaultValue = defaultValue;
|
|
188
|
+
return this;
|
|
189
|
+
}
|
|
190
|
+
validate(input) {
|
|
191
|
+
if (typeof input !== "boolean") {
|
|
192
|
+
return [false, "Input is not a boolean"];
|
|
193
|
+
}
|
|
194
|
+
return [true, ""];
|
|
195
|
+
}
|
|
196
|
+
};
|
|
197
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
198
|
+
0 && (module.exports = {
|
|
199
|
+
BooleanOption,
|
|
200
|
+
ConfigurationBuilder,
|
|
201
|
+
ConfigurationOption,
|
|
202
|
+
NumberOption,
|
|
203
|
+
StringOption,
|
|
204
|
+
isBooleanOption,
|
|
205
|
+
isNumberOption,
|
|
206
|
+
isStringOption
|
|
207
|
+
});
|
|
208
|
+
//# sourceMappingURL=ConfigurationBuilder.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/config/ConfigurationBuilder.ts"],"sourcesContent":["import z, { ZodError } from \"zod\"\r\n\r\nexport interface ConfigurationFile {\r\n [key: string]: ConfigurationOption\r\n}\r\n\r\nconst configValidation = z.object({\r\n name: z.string().min(1),\r\n displayName: z.string().min(1),\r\n description: z.string().min(1),\r\n})\r\n\r\nexport function isStringOption(option: ConfigurationOption): option is StringOption {\r\n return option.type === 'string';\r\n }\r\n\r\nexport function isNumberOption(option: ConfigurationOption): option is NumberOption {\r\n return option.type === 'number';\r\n}\r\n\r\nexport function isBooleanOption(option: ConfigurationOption): option is BooleanOption {\r\n return option.type === 'boolean';\r\n}\r\n\r\nexport class ConfigurationBuilder {\r\n private options: ConfigurationOption[] = [];\r\n public addNumberOption(option: (option: NumberOption) => NumberOption): ConfigurationBuilder {\r\n let newOption = new NumberOption();\r\n newOption = option(newOption);\r\n this.options.push(newOption);\r\n return this;\r\n }\r\n\r\n public addStringOption(option: (option: StringOption) => StringOption) {\r\n let newOption = new StringOption();\r\n newOption = option(newOption);\r\n this.options.push(newOption);\r\n return this;\r\n }\r\n\r\n public addBooleanOption(option: (option: BooleanOption) => BooleanOption) {\r\n let newOption = new BooleanOption();\r\n newOption = option(newOption);\r\n this.options.push(newOption);\r\n return this;\r\n }\r\n\r\n public build(includeFunctions: boolean): ConfigurationFile {\r\n let config: ConfigurationFile = {};\r\n this.options.forEach(option => {\r\n // remove all functions from the option object\r\n if (!includeFunctions) {\r\n option = JSON.parse(JSON.stringify(option));\r\n const optionData = configValidation.safeParse(option)\r\n if (!optionData.success) {\r\n throw new ZodError(optionData.error.errors)\r\n }\r\n\r\n config[option.name] = option;\r\n }\r\n else {\r\n config[option.name] = option;\r\n }\r\n });\r\n return config;\r\n }\r\n}\r\n\r\nexport type ConfigurationOptionType = 'string' | 'number' | 'boolean' | 'unset'\r\nexport class ConfigurationOption {\r\n public name: string = '';\r\n public defaultValue: unknown = '';\r\n public displayName: string = '';\r\n public description: string = '';\r\n public type: ConfigurationOptionType = 'unset'\r\n \r\n setName(name: string) {\r\n this.name = name;\r\n return this;\r\n }\r\n\r\n setDisplayName(displayName: string) {\r\n this.displayName = displayName;\r\n return this;\r\n }\r\n\r\n setDescription(description: string) {\r\n this.description = description;\r\n return this;\r\n }\r\n\r\n\r\n validate(input: unknown): [ boolean, string ] {\r\n throw new Error('Validation code not implemented. Value: ' + input)\r\n };\r\n}\r\n\r\nexport class StringOption extends ConfigurationOption {\r\n public allowedValues: string[] = [];\r\n public minTextLength: number = 0;\r\n public maxTextLength: number = Number.MAX_SAFE_INTEGER;\r\n public defaultValue: string = '';\r\n public type: ConfigurationOptionType = 'string'\r\n\r\n setAllowedValues(allowedValues: string[]): this {\r\n this.allowedValues = allowedValues;\r\n return this;\r\n }\r\n\r\n setDefaultValue(defaultValue: string): this {\r\n this.defaultValue = defaultValue;\r\n return this;\r\n }\r\n\r\n setMinTextLength(minTextLength: number): this {\r\n this.minTextLength = minTextLength;\r\n return this;\r\n }\r\n\r\n setMaxTextLength(maxTextLength: number): this {\r\n this.maxTextLength = maxTextLength;\r\n return this;\r\n }\r\n\r\n override validate(input: unknown): [ boolean, string ] {\r\n if (typeof input !== 'string') {\r\n return [ false, 'Input is not a string' ];\r\n }\r\n if (this.allowedValues.length === 0 && input.length !== 0)\r\n return [ true, '' ];\r\n if (input.length < this.minTextLength || input.length > this.maxTextLength) {\r\n return [ false, 'Input is not within the text length ' + this.minTextLength + ' and ' + this.maxTextLength + ' characters (currently ' + input.length + ' characters)' ];\r\n }\r\n\r\n return [ this.allowedValues.includes(input), 'Input is not an allowed value' ];\r\n }\r\n}\r\n\r\nexport class NumberOption extends ConfigurationOption {\r\n public min: number = 0;\r\n public max: number = Number.MAX_SAFE_INTEGER;\r\n public defaultValue: number = 0;\r\n public type: ConfigurationOptionType = 'number'\r\n public inputType: 'range' | 'number' = 'number';\r\n setMin(min: number): this {\r\n this.min = min;\r\n return this;\r\n }\r\n\r\n setInputType(type: 'range' | 'number'): this {\r\n this.inputType = type;\r\n return this;\r\n }\r\n\r\n setMax(max: number): this {\r\n this.max = max;\r\n return this\r\n }\r\n\r\n setDefaultValue(defaultValue: number): this {\r\n this.defaultValue = defaultValue;\r\n return this;\r\n }\r\n\r\n override validate(input: unknown): [ boolean, string ] {\r\n if (isNaN(Number(input))) {\r\n return [ false, 'Input is not a number' ];\r\n }\r\n if (Number(input) < this.min || Number(input) > this.max) {\r\n return [ false, 'Input is not within the range of ' + this.min + ' and ' + this.max ];\r\n }\r\n return [ true, '' ];\r\n }\r\n\r\n}\r\n\r\nexport class BooleanOption extends ConfigurationOption {\r\n public type: ConfigurationOptionType = 'boolean'\r\n public defaultValue: boolean = false;\r\n\r\n setDefaultValue(defaultValue: boolean): this {\r\n this.defaultValue = defaultValue;\r\n return this;\r\n }\r\n\r\n override validate(input: unknown): [ boolean, string ] {\r\n if (typeof input !== 'boolean') {\r\n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CAAE,MAAM,EAAG;AAAA,EACpB;AAEF;","names":["z"]}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
interface ConfigurationFile {
|
|
2
|
+
[key: string]: ConfigurationOption;
|
|
3
|
+
}
|
|
4
|
+
declare function isStringOption(option: ConfigurationOption): option is StringOption;
|
|
5
|
+
declare function isNumberOption(option: ConfigurationOption): option is NumberOption;
|
|
6
|
+
declare function isBooleanOption(option: ConfigurationOption): option is BooleanOption;
|
|
7
|
+
declare class ConfigurationBuilder {
|
|
8
|
+
private options;
|
|
9
|
+
addNumberOption(option: (option: NumberOption) => NumberOption): ConfigurationBuilder;
|
|
10
|
+
addStringOption(option: (option: StringOption) => StringOption): this;
|
|
11
|
+
addBooleanOption(option: (option: BooleanOption) => BooleanOption): this;
|
|
12
|
+
build(includeFunctions: boolean): ConfigurationFile;
|
|
13
|
+
}
|
|
14
|
+
type ConfigurationOptionType = 'string' | 'number' | 'boolean' | 'unset';
|
|
15
|
+
declare class ConfigurationOption {
|
|
16
|
+
name: string;
|
|
17
|
+
defaultValue: unknown;
|
|
18
|
+
displayName: string;
|
|
19
|
+
description: string;
|
|
20
|
+
type: ConfigurationOptionType;
|
|
21
|
+
setName(name: string): this;
|
|
22
|
+
setDisplayName(displayName: string): this;
|
|
23
|
+
setDescription(description: string): this;
|
|
24
|
+
validate(input: unknown): [boolean, string];
|
|
25
|
+
}
|
|
26
|
+
declare class StringOption extends ConfigurationOption {
|
|
27
|
+
allowedValues: string[];
|
|
28
|
+
minTextLength: number;
|
|
29
|
+
maxTextLength: number;
|
|
30
|
+
defaultValue: string;
|
|
31
|
+
type: ConfigurationOptionType;
|
|
32
|
+
setAllowedValues(allowedValues: string[]): this;
|
|
33
|
+
setDefaultValue(defaultValue: string): this;
|
|
34
|
+
setMinTextLength(minTextLength: number): this;
|
|
35
|
+
setMaxTextLength(maxTextLength: number): this;
|
|
36
|
+
validate(input: unknown): [boolean, string];
|
|
37
|
+
}
|
|
38
|
+
declare class NumberOption extends ConfigurationOption {
|
|
39
|
+
min: number;
|
|
40
|
+
max: number;
|
|
41
|
+
defaultValue: number;
|
|
42
|
+
type: ConfigurationOptionType;
|
|
43
|
+
inputType: 'range' | 'number';
|
|
44
|
+
setMin(min: number): this;
|
|
45
|
+
setInputType(type: 'range' | 'number'): this;
|
|
46
|
+
setMax(max: number): this;
|
|
47
|
+
setDefaultValue(defaultValue: number): this;
|
|
48
|
+
validate(input: unknown): [boolean, string];
|
|
49
|
+
}
|
|
50
|
+
declare class BooleanOption extends ConfigurationOption {
|
|
51
|
+
type: ConfigurationOptionType;
|
|
52
|
+
defaultValue: boolean;
|
|
53
|
+
setDefaultValue(defaultValue: boolean): this;
|
|
54
|
+
validate(input: unknown): [boolean, string];
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export { BooleanOption, ConfigurationBuilder, type ConfigurationFile, ConfigurationOption, type ConfigurationOptionType, NumberOption, StringOption, isBooleanOption, isNumberOption, isStringOption };
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
interface ConfigurationFile {
|
|
2
|
+
[key: string]: ConfigurationOption;
|
|
3
|
+
}
|
|
4
|
+
declare function isStringOption(option: ConfigurationOption): option is StringOption;
|
|
5
|
+
declare function isNumberOption(option: ConfigurationOption): option is NumberOption;
|
|
6
|
+
declare function isBooleanOption(option: ConfigurationOption): option is BooleanOption;
|
|
7
|
+
declare class ConfigurationBuilder {
|
|
8
|
+
private options;
|
|
9
|
+
addNumberOption(option: (option: NumberOption) => NumberOption): ConfigurationBuilder;
|
|
10
|
+
addStringOption(option: (option: StringOption) => StringOption): this;
|
|
11
|
+
addBooleanOption(option: (option: BooleanOption) => BooleanOption): this;
|
|
12
|
+
build(includeFunctions: boolean): ConfigurationFile;
|
|
13
|
+
}
|
|
14
|
+
type ConfigurationOptionType = 'string' | 'number' | 'boolean' | 'unset';
|
|
15
|
+
declare class ConfigurationOption {
|
|
16
|
+
name: string;
|
|
17
|
+
defaultValue: unknown;
|
|
18
|
+
displayName: string;
|
|
19
|
+
description: string;
|
|
20
|
+
type: ConfigurationOptionType;
|
|
21
|
+
setName(name: string): this;
|
|
22
|
+
setDisplayName(displayName: string): this;
|
|
23
|
+
setDescription(description: string): this;
|
|
24
|
+
validate(input: unknown): [boolean, string];
|
|
25
|
+
}
|
|
26
|
+
declare class StringOption extends ConfigurationOption {
|
|
27
|
+
allowedValues: string[];
|
|
28
|
+
minTextLength: number;
|
|
29
|
+
maxTextLength: number;
|
|
30
|
+
defaultValue: string;
|
|
31
|
+
type: ConfigurationOptionType;
|
|
32
|
+
setAllowedValues(allowedValues: string[]): this;
|
|
33
|
+
setDefaultValue(defaultValue: string): this;
|
|
34
|
+
setMinTextLength(minTextLength: number): this;
|
|
35
|
+
setMaxTextLength(maxTextLength: number): this;
|
|
36
|
+
validate(input: unknown): [boolean, string];
|
|
37
|
+
}
|
|
38
|
+
declare class NumberOption extends ConfigurationOption {
|
|
39
|
+
min: number;
|
|
40
|
+
max: number;
|
|
41
|
+
defaultValue: number;
|
|
42
|
+
type: ConfigurationOptionType;
|
|
43
|
+
inputType: 'range' | 'number';
|
|
44
|
+
setMin(min: number): this;
|
|
45
|
+
setInputType(type: 'range' | 'number'): this;
|
|
46
|
+
setMax(max: number): this;
|
|
47
|
+
setDefaultValue(defaultValue: number): this;
|
|
48
|
+
validate(input: unknown): [boolean, string];
|
|
49
|
+
}
|
|
50
|
+
declare class BooleanOption extends ConfigurationOption {
|
|
51
|
+
type: ConfigurationOptionType;
|
|
52
|
+
defaultValue: boolean;
|
|
53
|
+
setDefaultValue(defaultValue: boolean): this;
|
|
54
|
+
validate(input: unknown): [boolean, string];
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export { BooleanOption, ConfigurationBuilder, type ConfigurationFile, ConfigurationOption, type ConfigurationOptionType, NumberOption, StringOption, isBooleanOption, isNumberOption, isStringOption };
|