ogi-addon 1.0.0 → 1.1.5
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/LICENSE +660 -660
- package/README.md +40 -40
- package/build/EventResponse.cjs +19 -0
- package/build/EventResponse.cjs.map +1 -1
- package/build/EventResponse.d.cts +20 -1
- package/build/EventResponse.d.ts +20 -1
- package/build/EventResponse.js +19 -0
- package/build/EventResponse.js.map +1 -1
- package/build/SearchEngine.cjs.map +1 -1
- package/build/SearchEngine.d.cts +1 -1
- package/build/SearchEngine.d.ts +1 -1
- package/build/config/Configuration.cjs +71 -0
- package/build/config/Configuration.cjs.map +1 -1
- package/build/config/Configuration.js +71 -0
- package/build/config/Configuration.js.map +1 -1
- package/build/config/ConfigurationBuilder.cjs +71 -0
- package/build/config/ConfigurationBuilder.cjs.map +1 -1
- package/build/config/ConfigurationBuilder.d.cts +71 -0
- package/build/config/ConfigurationBuilder.d.ts +71 -0
- package/build/config/ConfigurationBuilder.js +71 -0
- package/build/config/ConfigurationBuilder.js.map +1 -1
- package/build/main.cjs +201 -17
- package/build/main.cjs.map +1 -1
- package/build/main.d.cts +133 -6
- package/build/main.d.ts +133 -6
- package/build/main.js +198 -16
- package/build/main.js.map +1 -1
- package/package.json +50 -49
- package/schema.json +30 -30
- package/src/EventResponse.ts +59 -40
- package/src/SearchEngine.ts +16 -16
- package/src/config/Configuration.ts +82 -82
- package/src/config/ConfigurationBuilder.ts +270 -198
- package/src/main.ts +521 -342
- package/tsconfig.json +38 -38
- package/tsup.config.js +10 -10
|
@@ -16,18 +16,31 @@ function isBooleanOption(option) {
|
|
|
16
16
|
}
|
|
17
17
|
var ConfigurationBuilder = class {
|
|
18
18
|
options = [];
|
|
19
|
+
/**
|
|
20
|
+
* Add a number option to the configuration builder and return the builder for chaining. You must provide a name, display name, and description for the option.
|
|
21
|
+
* @param option { (option: NumberOption) => NumberOption }
|
|
22
|
+
* @returns
|
|
23
|
+
*/
|
|
19
24
|
addNumberOption(option) {
|
|
20
25
|
let newOption = new NumberOption();
|
|
21
26
|
newOption = option(newOption);
|
|
22
27
|
this.options.push(newOption);
|
|
23
28
|
return this;
|
|
24
29
|
}
|
|
30
|
+
/**
|
|
31
|
+
* Add a string option to the configuration builder and return the builder for chaining. You must provide a name, display name, and description for the option.
|
|
32
|
+
* @param option { (option: StringOption) => StringOption }
|
|
33
|
+
*/
|
|
25
34
|
addStringOption(option) {
|
|
26
35
|
let newOption = new StringOption();
|
|
27
36
|
newOption = option(newOption);
|
|
28
37
|
this.options.push(newOption);
|
|
29
38
|
return this;
|
|
30
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* Add a boolean option to the configuration builder and return the builder for chaining. You must provide a name, display name, and description for the option.
|
|
42
|
+
* @param option { (option: BooleanOption) => BooleanOption }
|
|
43
|
+
*/
|
|
31
44
|
addBooleanOption(option) {
|
|
32
45
|
let newOption = new BooleanOption();
|
|
33
46
|
newOption = option(newOption);
|
|
@@ -57,18 +70,36 @@ var ConfigurationOption = class {
|
|
|
57
70
|
displayName = "";
|
|
58
71
|
description = "";
|
|
59
72
|
type = "unset";
|
|
73
|
+
/**
|
|
74
|
+
* Set the name of the option. **REQUIRED**
|
|
75
|
+
* @param name {string} The name of the option. This is used to reference the option in the configuration file.
|
|
76
|
+
*/
|
|
60
77
|
setName(name) {
|
|
61
78
|
this.name = name;
|
|
62
79
|
return this;
|
|
63
80
|
}
|
|
81
|
+
/**
|
|
82
|
+
* Set the display name of the option. This is used to show the user a human readable version of what the option is. **REQUIRED**
|
|
83
|
+
* @param displayName {string} The display name of the option.
|
|
84
|
+
* @returns
|
|
85
|
+
*/
|
|
64
86
|
setDisplayName(displayName) {
|
|
65
87
|
this.displayName = displayName;
|
|
66
88
|
return this;
|
|
67
89
|
}
|
|
90
|
+
/**
|
|
91
|
+
* Set the description of the option. This is to show the user a brief description of what this option does. **REQUIRED**
|
|
92
|
+
* @param description {string} The description of the option.
|
|
93
|
+
* @returns
|
|
94
|
+
*/
|
|
68
95
|
setDescription(description) {
|
|
69
96
|
this.description = description;
|
|
70
97
|
return this;
|
|
71
98
|
}
|
|
99
|
+
/**
|
|
100
|
+
* Validation code for the option. This is called when the user provides input to the option. If the validation fails, the user will be prompted to provide input again.
|
|
101
|
+
* @param input {unknown} The input to validate
|
|
102
|
+
*/
|
|
72
103
|
validate(input) {
|
|
73
104
|
throw new Error("Validation code not implemented. Value: " + input);
|
|
74
105
|
}
|
|
@@ -80,22 +111,42 @@ var StringOption = class extends ConfigurationOption {
|
|
|
80
111
|
defaultValue = "";
|
|
81
112
|
inputType = "text";
|
|
82
113
|
type = "string";
|
|
114
|
+
/**
|
|
115
|
+
* Set the allowed values for the string. If the array is empty, any value is allowed. When provided, the client will act like this option is a dropdown.
|
|
116
|
+
* @param allowedValues {string[]} An array of allowed values for the string. If the array is empty, any value is allowed.
|
|
117
|
+
*/
|
|
83
118
|
setAllowedValues(allowedValues) {
|
|
84
119
|
this.allowedValues = allowedValues;
|
|
85
120
|
return this;
|
|
86
121
|
}
|
|
122
|
+
/**
|
|
123
|
+
* Set the default value for the string. This value will be used if the user does not provide a value. **HIGHLY RECOMMENDED**
|
|
124
|
+
* @param defaultValue {string} The default value for the string.
|
|
125
|
+
*/
|
|
87
126
|
setDefaultValue(defaultValue) {
|
|
88
127
|
this.defaultValue = defaultValue;
|
|
89
128
|
return this;
|
|
90
129
|
}
|
|
130
|
+
/**
|
|
131
|
+
* Set the minimum text length for the string. If the user provides a string that is less than this value, the validation will fail.
|
|
132
|
+
* @param minTextLength {number} The minimum text length for the string.
|
|
133
|
+
*/
|
|
91
134
|
setMinTextLength(minTextLength) {
|
|
92
135
|
this.minTextLength = minTextLength;
|
|
93
136
|
return this;
|
|
94
137
|
}
|
|
138
|
+
/**
|
|
139
|
+
* Set the maximum text length for the string. If the user provides a string that is greater than this value, the validation will fail.
|
|
140
|
+
* @param maxTextLength {number} The maximum text length for the string.
|
|
141
|
+
*/
|
|
95
142
|
setMaxTextLength(maxTextLength) {
|
|
96
143
|
this.maxTextLength = maxTextLength;
|
|
97
144
|
return this;
|
|
98
145
|
}
|
|
146
|
+
/**
|
|
147
|
+
* Set the input type for the string. This will change how the client renders the input.
|
|
148
|
+
* @param inputType {'text' | 'file' | 'password' | 'folder'} The input type for the string.
|
|
149
|
+
*/
|
|
99
150
|
setInputType(inputType) {
|
|
100
151
|
this.inputType = inputType;
|
|
101
152
|
return this;
|
|
@@ -118,18 +169,34 @@ var NumberOption = class extends ConfigurationOption {
|
|
|
118
169
|
defaultValue = 0;
|
|
119
170
|
type = "number";
|
|
120
171
|
inputType = "number";
|
|
172
|
+
/**
|
|
173
|
+
* Set the minimum value for the number. If the user provides a number that is less than this value, the validation will fail.
|
|
174
|
+
* @param min {number} The minimum value for the number.
|
|
175
|
+
*/
|
|
121
176
|
setMin(min) {
|
|
122
177
|
this.min = min;
|
|
123
178
|
return this;
|
|
124
179
|
}
|
|
180
|
+
/**
|
|
181
|
+
* Set the input type for the number. This will change how the client renders the input.
|
|
182
|
+
* @param type {'range' | 'number'} The input type for the number.
|
|
183
|
+
*/
|
|
125
184
|
setInputType(type) {
|
|
126
185
|
this.inputType = type;
|
|
127
186
|
return this;
|
|
128
187
|
}
|
|
188
|
+
/**
|
|
189
|
+
* Set the maximum value for the number. If the user provides a number that is greater than this value, the validation will fail.
|
|
190
|
+
* @param max {number} The maximum value for the number.
|
|
191
|
+
*/
|
|
129
192
|
setMax(max) {
|
|
130
193
|
this.max = max;
|
|
131
194
|
return this;
|
|
132
195
|
}
|
|
196
|
+
/**
|
|
197
|
+
* Set the default value for the number. This value will be used if the user does not provide a value. **HIGHLY RECOMMENDED**
|
|
198
|
+
* @param defaultValue {number} The default value for the number.
|
|
199
|
+
*/
|
|
133
200
|
setDefaultValue(defaultValue) {
|
|
134
201
|
this.defaultValue = defaultValue;
|
|
135
202
|
return this;
|
|
@@ -147,6 +214,10 @@ var NumberOption = class extends ConfigurationOption {
|
|
|
147
214
|
var BooleanOption = class extends ConfigurationOption {
|
|
148
215
|
type = "boolean";
|
|
149
216
|
defaultValue = false;
|
|
217
|
+
/**
|
|
218
|
+
* Set the default value for the boolean. This value will be used if the user does not provide a value. **HIGHLY RECOMMENDED**
|
|
219
|
+
* @param defaultValue {boolean} The default value for the boolean.
|
|
220
|
+
*/
|
|
150
221
|
setDefaultValue(defaultValue) {
|
|
151
222
|
this.defaultValue = defaultValue;
|
|
152
223
|
return this;
|
|
@@ -1 +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 inputType: 'text' | 'file' | 'password' | 'folder' = 'text';\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 setInputType(inputType: 'text' | 'file' | 'password' | 'folder'): this {\r\n this.inputType = inputType;\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,gBAAY,OAAO,SAAS;AAC5B,SAAK,QAAQ,KAAK,SAAS;AAC3B,WAAO;AAAA,EACT;AAAA,EAEO,gBAAgB,QAAgD;AACrE,QAAI,YAAY,IAAI,aAAa;AACjC,gBAAY,OAAO,SAAS;AAC5B,SAAK,QAAQ,KAAK,SAAS;AAC3B,WAAO;AAAA,EACT;AAAA,EAEO,iBAAiB,QAAkD;AACxE,QAAI,YAAY,IAAI,cAAc;AAClC,gBAAY,OAAO,SAAS;AAC5B,SA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configuration.ts"],"sourcesContent":["import z, { ZodError } from \"zod\"\n\nexport interface ConfigurationFile {\n [key: string]: ConfigurationOption\n}\n\nconst configValidation = z.object({\n name: z.string().min(1),\n displayName: z.string().min(1),\n description: z.string().min(1),\n})\n\nexport function isStringOption(option: ConfigurationOption): option is StringOption {\n return option.type === 'string';\n }\n\nexport function isNumberOption(option: ConfigurationOption): option is NumberOption {\n return option.type === 'number';\n}\n\nexport function isBooleanOption(option: ConfigurationOption): option is BooleanOption {\n return option.type === 'boolean';\n}\n\nexport class ConfigurationBuilder {\n private options: ConfigurationOption[] = [];\n\n /**\n * Add a number option to the configuration builder and return the builder for chaining. You must provide a name, display name, and description for the option.\n * @param option { (option: NumberOption) => NumberOption }\n * @returns \n */\n public addNumberOption(option: (option: NumberOption) => NumberOption): ConfigurationBuilder {\n let newOption = new NumberOption();\n newOption = option(newOption);\n this.options.push(newOption);\n return this;\n }\n\n /**\n * Add a string option to the configuration builder and return the builder for chaining. You must provide a name, display name, and description for the option.\n * @param option { (option: StringOption) => StringOption }\n */\n public addStringOption(option: (option: StringOption) => StringOption) {\n let newOption = new StringOption();\n newOption = option(newOption);\n this.options.push(newOption);\n return this;\n }\n\n /**\n * Add a boolean option to the configuration builder and return the builder for chaining. You must provide a name, display name, and description for the option.\n * @param option { (option: BooleanOption) => BooleanOption }\n */\n public addBooleanOption(option: (option: BooleanOption) => BooleanOption) {\n let newOption = new BooleanOption();\n newOption = option(newOption);\n this.options.push(newOption);\n return this;\n }\n\n public build(includeFunctions: boolean): ConfigurationFile {\n let config: ConfigurationFile = {};\n this.options.forEach(option => {\n // remove all functions from the option object\n if (!includeFunctions) {\n option = JSON.parse(JSON.stringify(option));\n const optionData = configValidation.safeParse(option)\n if (!optionData.success) {\n throw new ZodError(optionData.error.errors)\n }\n\n config[option.name] = option;\n }\n else {\n config[option.name] = option;\n }\n });\n return config;\n }\n}\n\nexport type ConfigurationOptionType = 'string' | 'number' | 'boolean' | 'unset'\nexport class ConfigurationOption {\n public name: string = '';\n public defaultValue: unknown = '';\n public displayName: string = '';\n public description: string = '';\n public type: ConfigurationOptionType = 'unset'\n \n /**\n * Set the name of the option. **REQUIRED**\n * @param name {string} The name of the option. This is used to reference the option in the configuration file.\n */\n setName(name: string) {\n this.name = name;\n return this;\n }\n\n /**\n * Set the display name of the option. This is used to show the user a human readable version of what the option is. **REQUIRED** \n * @param displayName {string} The display name of the option. \n * @returns \n */\n setDisplayName(displayName: string) {\n this.displayName = displayName;\n return this;\n }\n\n /**\n * Set the description of the option. This is to show the user a brief description of what this option does. **REQUIRED**\n * @param description {string} The description of the option. \n * @returns \n */\n setDescription(description: string) {\n this.description = description;\n return this;\n }\n\n /**\n * Validation code for the option. This is called when the user provides input to the option. If the validation fails, the user will be prompted to provide input again.\n * @param input {unknown} The input to validate\n */\n validate(input: unknown): [ boolean, string ] {\n throw new Error('Validation code not implemented. Value: ' + input)\n };\n}\n\nexport class StringOption extends ConfigurationOption {\n public allowedValues: string[] = [];\n public minTextLength: number = 0;\n public maxTextLength: number = Number.MAX_SAFE_INTEGER;\n public defaultValue: string = '';\n public inputType: 'text' | 'file' | 'password' | 'folder' = 'text';\n public type: ConfigurationOptionType = 'string'\n\n /**\n * Set the allowed values for the string. If the array is empty, any value is allowed. When provided, the client will act like this option is a dropdown. \n * @param allowedValues {string[]} An array of allowed values for the string. If the array is empty, any value is allowed.\n */\n setAllowedValues(allowedValues: string[]): this {\n this.allowedValues = allowedValues;\n return this;\n }\n\n /**\n * Set the default value for the string. This value will be used if the user does not provide a value. **HIGHLY RECOMMENDED**\n * @param defaultValue {string} The default value for the string.\n */\n setDefaultValue(defaultValue: string): this {\n this.defaultValue = defaultValue;\n return this;\n }\n\n /**\n * Set the minimum text length for the string. If the user provides a string that is less than this value, the validation will fail. \n * @param minTextLength {number} The minimum text length for the string. \n */\n setMinTextLength(minTextLength: number): this {\n this.minTextLength = minTextLength;\n return this;\n }\n\n /**\n * Set the maximum text length for the string. If the user provides a string that is greater than this value, the validation will fail. \n * @param maxTextLength {number} The maximum text length for the string.\n */\n setMaxTextLength(maxTextLength: number): this {\n this.maxTextLength = maxTextLength;\n return this;\n }\n\n /**\n * Set the input type for the string. This will change how the client renders the input. \n * @param inputType {'text' | 'file' | 'password' | 'folder'} The input type for the string. \n */\n setInputType(inputType: 'text' | 'file' | 'password' | 'folder'): this {\n this.inputType = inputType;\n return this;\n }\n\n override validate(input: unknown): [ boolean, string ] {\n if (typeof input !== 'string') {\n return [ false, 'Input is not a string' ];\n }\n if (this.allowedValues.length === 0 && input.length !== 0)\n return [ true, '' ];\n if (input.length < this.minTextLength || input.length > this.maxTextLength) {\n return [ false, 'Input is not within the text length ' + this.minTextLength + ' and ' + this.maxTextLength + ' characters (currently ' + input.length + ' characters)' ];\n }\n\n return [ this.allowedValues.includes(input), 'Input is not an allowed value' ];\n }\n}\n\nexport class NumberOption extends ConfigurationOption {\n public min: number = 0;\n public max: number = Number.MAX_SAFE_INTEGER;\n public defaultValue: number = 0;\n public type: ConfigurationOptionType = 'number'\n public inputType: 'range' | 'number' = 'number';\n\n /**\n * Set the minimum value for the number. If the user provides a number that is less than this value, the validation will fail.\n * @param min {number} The minimum value for the number.\n */\n setMin(min: number): this {\n this.min = min;\n return this;\n }\n\n /**\n * Set the input type for the number. This will change how the client renders the input. \n * @param type {'range' | 'number'} The input type for the number. \n */\n setInputType(type: 'range' | 'number'): this {\n this.inputType = type;\n return this;\n }\n\n /**\n * Set the maximum value for the number. If the user provides a number that is greater than this value, the validation will fail.\n * @param max {number} The maximum value for the number.\n */\n setMax(max: number): this {\n this.max = max;\n return this\n }\n\n /**\n * Set the default value for the number. This value will be used if the user does not provide a value. **HIGHLY RECOMMENDED**\n * @param defaultValue {number} The default value for the number.\n */\n setDefaultValue(defaultValue: number): this {\n this.defaultValue = defaultValue;\n return this;\n }\n\n override validate(input: unknown): [ boolean, string ] {\n if (isNaN(Number(input))) {\n return [ false, 'Input is not a number' ];\n }\n if (Number(input) < this.min || Number(input) > this.max) {\n return [ false, 'Input is not within the range of ' + this.min + ' and ' + this.max ];\n }\n return [ true, '' ];\n }\n\n}\n\nexport class BooleanOption extends ConfigurationOption {\n public type: ConfigurationOptionType = 'boolean'\n public defaultValue: boolean = false;\n\n /**\n * Set the default value for the boolean. This value will be used if the user does not provide a value. **HIGHLY RECOMMENDED**\n * @param defaultValue {boolean} The default value for the boolean.\n */\n setDefaultValue(defaultValue: boolean): this {\n this.defaultValue = defaultValue;\n return this;\n }\n\n override validate(input: unknown): [ boolean, string ] {\n if (typeof input !== 'boolean') {\n return [ false, 'Input is not a boolean' ];\n }\n return [ true, '' ];\n }\n\n}","import { ConfigurationFile, ConfigurationBuilder, BooleanOption, ConfigurationOption, ConfigurationOptionType, NumberOption, StringOption, isBooleanOption, isNumberOption, isStringOption } from \"./ConfigurationBuilder\";\n\ninterface DefiniteConfig {\n [key: string]: string | number | boolean;\n}\nexport class Configuration {\n readonly storedConfigTemplate: ConfigurationFile;\n definiteConfig: DefiniteConfig = {};\n constructor(configTemplate: ConfigurationFile) {\n this.storedConfigTemplate = configTemplate;\n }\n\n updateConfig(config: DefiniteConfig, validate: boolean = true): [ boolean, { [key: string]: string } ] {\n this.definiteConfig = config;\n if (validate) {\n const result = this.validateConfig();\n return result;\n }\n return [ true, {} ];\n }\n // provides falsey or truthy value, and an error message if falsey\n private validateConfig(): [ boolean, { [key: string]: string } ] {\n const erroredKeys = new Map<string, string>();\n for (const key in this.storedConfigTemplate) {\n if (this.definiteConfig[key] === null || this.definiteConfig[key] === undefined) {\n console.warn('Option ' + key + ' is not defined. Using default value Value: ' + this.definiteConfig[key]);\n this.definiteConfig[key] = this.storedConfigTemplate[key].defaultValue as string | number | boolean;\n }\n if (this.storedConfigTemplate[key].type !== typeof this.definiteConfig[key]) {\n throw new Error('Option ' + key + ' is not of the correct type');\n }\n\n const result = this.storedConfigTemplate[key].validate(this.definiteConfig[key]);\n if (!result[0]) {\n erroredKeys.set(key, result[1]);\n }\n }\n\n for (const key in this.definiteConfig) {\n if (!this.storedConfigTemplate[key]) {\n throw new Error('Option ' + key + ' is not defined in the configuration template');\n }\n }\n\n if (erroredKeys.size > 0) {\n return [ false, Object.fromEntries(erroredKeys) ];\n }\n\n return [ true, Object.fromEntries(erroredKeys) ];\n }\n\n getStringValue(optionName: string): string {\n if (!this.definiteConfig[optionName] === null) {\n throw new Error('Option ' + optionName + ' is not defined');\n }\n if (typeof this.definiteConfig[optionName] !== 'string') {\n throw new Error('Option ' + optionName + ' is not a string');\n }\n return this.definiteConfig[optionName];\n }\n\n getNumberValue(optionName: string): number {\n if (!this.definiteConfig[optionName] === null) {\n throw new Error('Option ' + optionName + ' is not defined');\n }\n if (typeof this.definiteConfig[optionName] !== 'number') {\n throw new Error('Option ' + optionName + ' is not a number');\n }\n return this.definiteConfig[optionName];\n }\n\n getBooleanValue(optionName: string): boolean {\n if (this.definiteConfig[optionName] === null) {\n throw new Error('Option ' + optionName + ' is not defined');\n }\n if (typeof this.definiteConfig[optionName] !== 'boolean') {\n throw new Error('Option ' + optionName + ' is not a boolean');\n }\n return this.definiteConfig[optionName];\n }\n}\n\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,CAA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,YAAY,aAAa,iBAAiB;AAAA,IAC5D;AACA,QAAI,OAAO,KAAK,eAAe,UAAU,MAAM,UAAU;AACvD,YAAM,IAAI,MAAM,YAAY,aAAa,kBAAkB;AAAA,IAC7D;AACA,WAAO,KAAK,eAAe,UAAU;AAAA,EACvC;AAAA,EAEA,eAAe,YAA4B;AACzC,QAAI,CAAC,KAAK,eAAe,UAAU,MAAM,MAAM;AAC7C,YAAM,IAAI,MAAM,YAAY,aAAa,iBAAiB;AAAA,IAC5D;AACA,QAAI,OAAO,KAAK,eAAe,UAAU,MAAM,UAAU;AACvD,YAAM,IAAI,MAAM,YAAY,aAAa,kBAAkB;AAAA,IAC7D;AACA,WAAO,KAAK,eAAe,UAAU;AAAA,EACvC;AAAA,EAEA,gBAAgB,YAA6B;AAC3C,QAAI,KAAK,eAAe,UAAU,MAAM,MAAM;AAC5C,YAAM,IAAI,MAAM,YAAY,aAAa,iBAAiB;AAAA,IAC5D;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":[]}
|
|
@@ -57,18 +57,31 @@ function isBooleanOption(option) {
|
|
|
57
57
|
}
|
|
58
58
|
var ConfigurationBuilder = class {
|
|
59
59
|
options = [];
|
|
60
|
+
/**
|
|
61
|
+
* Add a number option to the configuration builder and return the builder for chaining. You must provide a name, display name, and description for the option.
|
|
62
|
+
* @param option { (option: NumberOption) => NumberOption }
|
|
63
|
+
* @returns
|
|
64
|
+
*/
|
|
60
65
|
addNumberOption(option) {
|
|
61
66
|
let newOption = new NumberOption();
|
|
62
67
|
newOption = option(newOption);
|
|
63
68
|
this.options.push(newOption);
|
|
64
69
|
return this;
|
|
65
70
|
}
|
|
71
|
+
/**
|
|
72
|
+
* Add a string option to the configuration builder and return the builder for chaining. You must provide a name, display name, and description for the option.
|
|
73
|
+
* @param option { (option: StringOption) => StringOption }
|
|
74
|
+
*/
|
|
66
75
|
addStringOption(option) {
|
|
67
76
|
let newOption = new StringOption();
|
|
68
77
|
newOption = option(newOption);
|
|
69
78
|
this.options.push(newOption);
|
|
70
79
|
return this;
|
|
71
80
|
}
|
|
81
|
+
/**
|
|
82
|
+
* Add a boolean option to the configuration builder and return the builder for chaining. You must provide a name, display name, and description for the option.
|
|
83
|
+
* @param option { (option: BooleanOption) => BooleanOption }
|
|
84
|
+
*/
|
|
72
85
|
addBooleanOption(option) {
|
|
73
86
|
let newOption = new BooleanOption();
|
|
74
87
|
newOption = option(newOption);
|
|
@@ -98,18 +111,36 @@ var ConfigurationOption = class {
|
|
|
98
111
|
displayName = "";
|
|
99
112
|
description = "";
|
|
100
113
|
type = "unset";
|
|
114
|
+
/**
|
|
115
|
+
* Set the name of the option. **REQUIRED**
|
|
116
|
+
* @param name {string} The name of the option. This is used to reference the option in the configuration file.
|
|
117
|
+
*/
|
|
101
118
|
setName(name) {
|
|
102
119
|
this.name = name;
|
|
103
120
|
return this;
|
|
104
121
|
}
|
|
122
|
+
/**
|
|
123
|
+
* Set the display name of the option. This is used to show the user a human readable version of what the option is. **REQUIRED**
|
|
124
|
+
* @param displayName {string} The display name of the option.
|
|
125
|
+
* @returns
|
|
126
|
+
*/
|
|
105
127
|
setDisplayName(displayName) {
|
|
106
128
|
this.displayName = displayName;
|
|
107
129
|
return this;
|
|
108
130
|
}
|
|
131
|
+
/**
|
|
132
|
+
* Set the description of the option. This is to show the user a brief description of what this option does. **REQUIRED**
|
|
133
|
+
* @param description {string} The description of the option.
|
|
134
|
+
* @returns
|
|
135
|
+
*/
|
|
109
136
|
setDescription(description) {
|
|
110
137
|
this.description = description;
|
|
111
138
|
return this;
|
|
112
139
|
}
|
|
140
|
+
/**
|
|
141
|
+
* Validation code for the option. This is called when the user provides input to the option. If the validation fails, the user will be prompted to provide input again.
|
|
142
|
+
* @param input {unknown} The input to validate
|
|
143
|
+
*/
|
|
113
144
|
validate(input) {
|
|
114
145
|
throw new Error("Validation code not implemented. Value: " + input);
|
|
115
146
|
}
|
|
@@ -121,22 +152,42 @@ var StringOption = class extends ConfigurationOption {
|
|
|
121
152
|
defaultValue = "";
|
|
122
153
|
inputType = "text";
|
|
123
154
|
type = "string";
|
|
155
|
+
/**
|
|
156
|
+
* Set the allowed values for the string. If the array is empty, any value is allowed. When provided, the client will act like this option is a dropdown.
|
|
157
|
+
* @param allowedValues {string[]} An array of allowed values for the string. If the array is empty, any value is allowed.
|
|
158
|
+
*/
|
|
124
159
|
setAllowedValues(allowedValues) {
|
|
125
160
|
this.allowedValues = allowedValues;
|
|
126
161
|
return this;
|
|
127
162
|
}
|
|
163
|
+
/**
|
|
164
|
+
* Set the default value for the string. This value will be used if the user does not provide a value. **HIGHLY RECOMMENDED**
|
|
165
|
+
* @param defaultValue {string} The default value for the string.
|
|
166
|
+
*/
|
|
128
167
|
setDefaultValue(defaultValue) {
|
|
129
168
|
this.defaultValue = defaultValue;
|
|
130
169
|
return this;
|
|
131
170
|
}
|
|
171
|
+
/**
|
|
172
|
+
* Set the minimum text length for the string. If the user provides a string that is less than this value, the validation will fail.
|
|
173
|
+
* @param minTextLength {number} The minimum text length for the string.
|
|
174
|
+
*/
|
|
132
175
|
setMinTextLength(minTextLength) {
|
|
133
176
|
this.minTextLength = minTextLength;
|
|
134
177
|
return this;
|
|
135
178
|
}
|
|
179
|
+
/**
|
|
180
|
+
* Set the maximum text length for the string. If the user provides a string that is greater than this value, the validation will fail.
|
|
181
|
+
* @param maxTextLength {number} The maximum text length for the string.
|
|
182
|
+
*/
|
|
136
183
|
setMaxTextLength(maxTextLength) {
|
|
137
184
|
this.maxTextLength = maxTextLength;
|
|
138
185
|
return this;
|
|
139
186
|
}
|
|
187
|
+
/**
|
|
188
|
+
* Set the input type for the string. This will change how the client renders the input.
|
|
189
|
+
* @param inputType {'text' | 'file' | 'password' | 'folder'} The input type for the string.
|
|
190
|
+
*/
|
|
140
191
|
setInputType(inputType) {
|
|
141
192
|
this.inputType = inputType;
|
|
142
193
|
return this;
|
|
@@ -159,18 +210,34 @@ var NumberOption = class extends ConfigurationOption {
|
|
|
159
210
|
defaultValue = 0;
|
|
160
211
|
type = "number";
|
|
161
212
|
inputType = "number";
|
|
213
|
+
/**
|
|
214
|
+
* Set the minimum value for the number. If the user provides a number that is less than this value, the validation will fail.
|
|
215
|
+
* @param min {number} The minimum value for the number.
|
|
216
|
+
*/
|
|
162
217
|
setMin(min) {
|
|
163
218
|
this.min = min;
|
|
164
219
|
return this;
|
|
165
220
|
}
|
|
221
|
+
/**
|
|
222
|
+
* Set the input type for the number. This will change how the client renders the input.
|
|
223
|
+
* @param type {'range' | 'number'} The input type for the number.
|
|
224
|
+
*/
|
|
166
225
|
setInputType(type) {
|
|
167
226
|
this.inputType = type;
|
|
168
227
|
return this;
|
|
169
228
|
}
|
|
229
|
+
/**
|
|
230
|
+
* Set the maximum value for the number. If the user provides a number that is greater than this value, the validation will fail.
|
|
231
|
+
* @param max {number} The maximum value for the number.
|
|
232
|
+
*/
|
|
170
233
|
setMax(max) {
|
|
171
234
|
this.max = max;
|
|
172
235
|
return this;
|
|
173
236
|
}
|
|
237
|
+
/**
|
|
238
|
+
* Set the default value for the number. This value will be used if the user does not provide a value. **HIGHLY RECOMMENDED**
|
|
239
|
+
* @param defaultValue {number} The default value for the number.
|
|
240
|
+
*/
|
|
174
241
|
setDefaultValue(defaultValue) {
|
|
175
242
|
this.defaultValue = defaultValue;
|
|
176
243
|
return this;
|
|
@@ -188,6 +255,10 @@ var NumberOption = class extends ConfigurationOption {
|
|
|
188
255
|
var BooleanOption = class extends ConfigurationOption {
|
|
189
256
|
type = "boolean";
|
|
190
257
|
defaultValue = false;
|
|
258
|
+
/**
|
|
259
|
+
* Set the default value for the boolean. This value will be used if the user does not provide a value. **HIGHLY RECOMMENDED**
|
|
260
|
+
* @param defaultValue {boolean} The default value for the boolean.
|
|
261
|
+
*/
|
|
191
262
|
setDefaultValue(defaultValue) {
|
|
192
263
|
this.defaultValue = defaultValue;
|
|
193
264
|
return this;
|
|
@@ -1 +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 inputType: 'text' | 'file' | 'password' | 'folder' = 'text';\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 setInputType(inputType: 'text' | 'file' | 'password' | 'folder'): this {\r\n this.inputType = inputType;\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}"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,iBAA4B;AAM5B,IAAM,mBAAmB,WAAAA,QAAE,OAAO;AAAA,EAChC,MAAM,WAAAA,QAAE,OAAO,EAAE,IAAI,CAAC;AAAA,EACtB,aAAa,WAAAA,QAAE,OAAO,EAAE,IAAI,CAAC;AAAA,EAC7B,aAAa,WAAAA,QAAE,OAAO,EAAE,IAAI,CAAC;AAC/B,CAAC;AAEM,SAAS,eAAe,QAAqD;AAChF,SAAO,OAAO,SAAS;AACzB;AAEK,SAAS,e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YAAgC;AAAA,EACvC,OAAO,KAAmB;AACxB,SAAK,MAAM;AACX,WAAO;AAAA,EACT;AAAA,EAEA,aAAa,MAAgC;AAC3C,SAAK,YAAY;AACjB,WAAO;AAAA,EACT;AAAA,EAEA,OAAO,KAAmB;AACxB,SAAK,MAAM;AACX,WAAO;AAAA,EACT;AAAA,EAEA,gBAAgB,cAA4B;AAC1C,SAAK,eAAe;AACpB,WAAO;AAAA,EACT;AAAA,EAES,SAAS,OAAqC;AACrD,QAAI,MAAM,OAAO,KAAK,CAAC,GAAG;AACxB,aAAO,CAAE,OAAO,uBAAwB;AAAA,IAC1C;AACA,QAAI,OAAO,KAAK,IAAI,KAAK,OAAO,OAAO,KAAK,IAAI,KAAK,KAAK;AACxD,aAAO,CAAE,OAAO,sCAAsC,KAAK,MAAM,UAAU,KAAK,GAAI;AAAA,IACtF;AACA,WAAO,CAAE,MAAM,EAAG;AAAA,EACpB;AAEF;AAEO,IAAM,gBAAN,cAA4B,oBAAoB;AAAA,EAC9C,OAAgC;AAAA,EAChC,eAAwB;AAAA,EAE/B,gBAAgB,cAA6B;AAC3C,SAAK,eAAe;AACpB,WAAO;AAAA,EACT;AAAA,EAES,SAAS,OAAqC;AACrD,QAAI,OAAO,UAAU,WAAW;AAC9B,aAAO,CAAE,OAAO,wBAAyB;AAAA,IAC3C;AACA,WAAO,CAAE,MAAM,EAAG;AAAA,EACpB;AAEF;","names":["z"]}
|
|
1
|
+
{"version":3,"sources":["../../src/config/ConfigurationBuilder.ts"],"sourcesContent":["import z, { ZodError } from \"zod\"\n\nexport interface ConfigurationFile {\n [key: string]: ConfigurationOption\n}\n\nconst configValidation = z.object({\n name: z.string().min(1),\n displayName: z.string().min(1),\n description: z.string().min(1),\n})\n\nexport function isStringOption(option: ConfigurationOption): option is StringOption {\n return option.type === 'string';\n }\n\nexport function isNumberOption(option: ConfigurationOption): option is NumberOption {\n return option.type === 'number';\n}\n\nexport function isBooleanOption(option: ConfigurationOption): option is BooleanOption {\n return option.type === 'boolean';\n}\n\nexport class ConfigurationBuilder {\n private options: ConfigurationOption[] = [];\n\n /**\n * Add a number option to the configuration builder and return the builder for chaining. You must provide a name, display name, and description for the option.\n * @param option { (option: NumberOption) => NumberOption }\n * @returns \n */\n public addNumberOption(option: (option: NumberOption) => NumberOption): ConfigurationBuilder {\n let newOption = new NumberOption();\n newOption = option(newOption);\n this.options.push(newOption);\n return this;\n }\n\n /**\n * Add a string option to the configuration builder and return the builder for chaining. You must provide a name, display name, and description for the option.\n * @param option { (option: StringOption) => StringOption }\n */\n public addStringOption(option: (option: StringOption) => StringOption) {\n let newOption = new StringOption();\n newOption = option(newOption);\n this.options.push(newOption);\n return this;\n }\n\n /**\n * Add a boolean option to the configuration builder and return the builder for chaining. You must provide a name, display name, and description for the option.\n * @param option { (option: BooleanOption) => BooleanOption }\n */\n public addBooleanOption(option: (option: BooleanOption) => BooleanOption) {\n let newOption = new BooleanOption();\n newOption = option(newOption);\n this.options.push(newOption);\n return this;\n }\n\n public build(includeFunctions: boolean): ConfigurationFile {\n let config: ConfigurationFile = {};\n this.options.forEach(option => {\n // remove all functions from the option object\n if (!includeFunctions) {\n option = JSON.parse(JSON.stringify(option));\n const optionData = configValidation.safeParse(option)\n if (!optionData.success) {\n throw new ZodError(optionData.error.errors)\n }\n\n config[option.name] = option;\n }\n else {\n config[option.name] = option;\n }\n });\n return config;\n }\n}\n\nexport type ConfigurationOptionType = 'string' | 'number' | 'boolean' | 'unset'\nexport class ConfigurationOption {\n public name: string = '';\n public defaultValue: unknown = '';\n public displayName: string = '';\n public description: string = '';\n public type: ConfigurationOptionType = 'unset'\n \n /**\n * Set the name of the option. **REQUIRED**\n * @param name {string} The name of the option. This is used to reference the option in the configuration file.\n */\n setName(name: string) {\n this.name = name;\n return this;\n }\n\n /**\n * Set the display name of the option. This is used to show the user a human readable version of what the option is. **REQUIRED** \n * @param displayName {string} The display name of the option. \n * @returns \n */\n setDisplayName(displayName: string) {\n this.displayName = displayName;\n return this;\n }\n\n /**\n * Set the description of the option. This is to show the user a brief description of what this option does. **REQUIRED**\n * @param description {string} The description of the option. \n * @returns \n */\n setDescription(description: string) {\n this.description = description;\n return this;\n }\n\n /**\n * Validation code for the option. This is called when the user provides input to the option. If the validation fails, the user will be prompted to provide input again.\n * @param input {unknown} The input to validate\n */\n validate(input: unknown): [ boolean, string ] {\n throw new Error('Validation code not implemented. Value: ' + input)\n };\n}\n\nexport class StringOption extends ConfigurationOption {\n public allowedValues: string[] = [];\n public minTextLength: number = 0;\n public maxTextLength: number = Number.MAX_SAFE_INTEGER;\n public defaultValue: string = '';\n public inputType: 'text' | 'file' | 'password' | 'folder' = 'text';\n public type: ConfigurationOptionType = 'string'\n\n /**\n * Set the allowed values for the string. If the array is empty, any value is allowed. When provided, the client will act like this option is a dropdown. \n * @param allowedValues {string[]} An array of allowed values for the string. If the array is empty, any value is allowed.\n */\n setAllowedValues(allowedValues: string[]): this {\n this.allowedValues = allowedValues;\n return this;\n }\n\n /**\n * Set the default value for the string. This value will be used if the user does not provide a value. **HIGHLY RECOMMENDED**\n * @param defaultValue {string} The default value for the string.\n */\n setDefaultValue(defaultValue: string): this {\n this.defaultValue = defaultValue;\n return this;\n }\n\n /**\n * Set the minimum text length for the string. If the user provides a string that is less than this value, the validation will fail. \n * @param minTextLength {number} The minimum text length for the string. \n */\n setMinTextLength(minTextLength: number): this {\n this.minTextLength = minTextLength;\n return this;\n }\n\n /**\n * Set the maximum text length for the string. If the user provides a string that is greater than this value, the validation will fail. \n * @param maxTextLength {number} The maximum text length for the string.\n */\n setMaxTextLength(maxTextLength: number): this {\n this.maxTextLength = maxTextLength;\n return this;\n }\n\n /**\n * Set the input type for the string. This will change how the client renders the input. \n * @param inputType {'text' | 'file' | 'password' | 'folder'} The input type for the string. \n */\n setInputType(inputType: 'text' | 'file' | 'password' | 'folder'): this {\n this.inputType = inputType;\n return this;\n }\n\n override validate(input: unknown): [ boolean, string ] {\n if (typeof input !== 'string') {\n return [ false, 'Input is not a string' ];\n }\n if (this.allowedValues.length === 0 && input.length !== 0)\n return [ true, '' ];\n if (input.length < this.minTextLength || input.length > this.maxTextLength) {\n return [ false, 'Input is not within the text length ' + this.minTextLength + ' and ' + this.maxTextLength + ' characters (currently ' + input.length + ' characters)' ];\n }\n\n return [ this.allowedValues.includes(input), 'Input is not an allowed value' ];\n }\n}\n\nexport class NumberOption extends ConfigurationOption {\n public min: number = 0;\n public max: number = Number.MAX_SAFE_INTEGER;\n public defaultValue: number = 0;\n public type: ConfigurationOptionType = 'number'\n public inputType: 'range' | 'number' = 'number';\n\n /**\n * Set the minimum value for the number. If the user provides a number that is less than this value, the validation will fail.\n * @param min {number} The minimum value for the number.\n */\n setMin(min: number): this {\n this.min = min;\n return this;\n }\n\n /**\n * Set the input type for the number. This will change how the client renders the input. \n * @param type {'range' | 'number'} The input type for the number. \n */\n setInputType(type: 'range' | 'number'): this {\n this.inputType = type;\n return this;\n }\n\n /**\n * Set the maximum value for the number. If the user provides a number that is greater than this value, the validation will fail.\n * @param max {number} The maximum value for the number.\n */\n setMax(max: number): this {\n this.max = max;\n return this\n }\n\n /**\n * Set the default value for the number. This value will be used if the user does not provide a value. **HIGHLY RECOMMENDED**\n * @param defaultValue {number} The default value for the number.\n */\n setDefaultValue(defaultValue: number): this {\n this.defaultValue = defaultValue;\n return this;\n }\n\n override validate(input: unknown): [ boolean, string ] {\n if (isNaN(Number(input))) {\n return [ false, 'Input is not a number' ];\n }\n if (Number(input) < this.min || Number(input) > this.max) {\n return [ false, 'Input is not within the range of ' + this.min + ' and ' + this.max ];\n }\n return [ true, '' ];\n }\n\n}\n\nexport class BooleanOption extends ConfigurationOption {\n public type: ConfigurationOptionType = 'boolean'\n public defaultValue: boolean = false;\n\n /**\n * Set the default value for the boolean. This value will be used if the user does not provide a value. **HIGHLY RECOMMENDED**\n * @param defaultValue {boolean} The default value for the boolean.\n */\n setDefaultValue(defaultValue: boolean): this {\n this.defaultValue = defaultValue;\n return this;\n }\n\n override validate(input: unknown):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KAAK,CAAC,GAAG;AACxB,aAAO,CAAE,OAAO,uBAAwB;AAAA,IAC1C;AACA,QAAI,OAAO,KAAK,IAAI,KAAK,OAAO,OAAO,KAAK,IAAI,KAAK,KAAK;AACxD,aAAO,CAAE,OAAO,sCAAsC,KAAK,MAAM,UAAU,KAAK,GAAI;AAAA,IACtF;AACA,WAAO,CAAE,MAAM,EAAG;AAAA,EACpB;AAEF;AAEO,IAAM,gBAAN,cAA4B,oBAAoB;AAAA,EAC9C,OAAgC;AAAA,EAChC,eAAwB;AAAA;AAAA;AAAA;AAAA;AAAA,EAM/B,gBAAgB,cAA6B;AAC3C,SAAK,eAAe;AACpB,WAAO;AAAA,EACT;AAAA,EAES,SAAS,OAAqC;AACrD,QAAI,OAAO,UAAU,WAAW;AAC9B,aAAO,CAAE,OAAO,wBAAyB;AAAA,IAC3C;AACA,WAAO,CAAE,MAAM,EAAG;AAAA,EACpB;AAEF;","names":["z"]}
|
|
@@ -6,8 +6,21 @@ declare function isNumberOption(option: ConfigurationOption): option is NumberOp
|
|
|
6
6
|
declare function isBooleanOption(option: ConfigurationOption): option is BooleanOption;
|
|
7
7
|
declare class ConfigurationBuilder {
|
|
8
8
|
private options;
|
|
9
|
+
/**
|
|
10
|
+
* Add a number option to the configuration builder and return the builder for chaining. You must provide a name, display name, and description for the option.
|
|
11
|
+
* @param option { (option: NumberOption) => NumberOption }
|
|
12
|
+
* @returns
|
|
13
|
+
*/
|
|
9
14
|
addNumberOption(option: (option: NumberOption) => NumberOption): ConfigurationBuilder;
|
|
15
|
+
/**
|
|
16
|
+
* Add a string option to the configuration builder and return the builder for chaining. You must provide a name, display name, and description for the option.
|
|
17
|
+
* @param option { (option: StringOption) => StringOption }
|
|
18
|
+
*/
|
|
10
19
|
addStringOption(option: (option: StringOption) => StringOption): this;
|
|
20
|
+
/**
|
|
21
|
+
* Add a boolean option to the configuration builder and return the builder for chaining. You must provide a name, display name, and description for the option.
|
|
22
|
+
* @param option { (option: BooleanOption) => BooleanOption }
|
|
23
|
+
*/
|
|
11
24
|
addBooleanOption(option: (option: BooleanOption) => BooleanOption): this;
|
|
12
25
|
build(includeFunctions: boolean): ConfigurationFile;
|
|
13
26
|
}
|
|
@@ -18,9 +31,27 @@ declare class ConfigurationOption {
|
|
|
18
31
|
displayName: string;
|
|
19
32
|
description: string;
|
|
20
33
|
type: ConfigurationOptionType;
|
|
34
|
+
/**
|
|
35
|
+
* Set the name of the option. **REQUIRED**
|
|
36
|
+
* @param name {string} The name of the option. This is used to reference the option in the configuration file.
|
|
37
|
+
*/
|
|
21
38
|
setName(name: string): this;
|
|
39
|
+
/**
|
|
40
|
+
* Set the display name of the option. This is used to show the user a human readable version of what the option is. **REQUIRED**
|
|
41
|
+
* @param displayName {string} The display name of the option.
|
|
42
|
+
* @returns
|
|
43
|
+
*/
|
|
22
44
|
setDisplayName(displayName: string): this;
|
|
45
|
+
/**
|
|
46
|
+
* Set the description of the option. This is to show the user a brief description of what this option does. **REQUIRED**
|
|
47
|
+
* @param description {string} The description of the option.
|
|
48
|
+
* @returns
|
|
49
|
+
*/
|
|
23
50
|
setDescription(description: string): this;
|
|
51
|
+
/**
|
|
52
|
+
* Validation code for the option. This is called when the user provides input to the option. If the validation fails, the user will be prompted to provide input again.
|
|
53
|
+
* @param input {unknown} The input to validate
|
|
54
|
+
*/
|
|
24
55
|
validate(input: unknown): [boolean, string];
|
|
25
56
|
}
|
|
26
57
|
declare class StringOption extends ConfigurationOption {
|
|
@@ -30,10 +61,30 @@ declare class StringOption extends ConfigurationOption {
|
|
|
30
61
|
defaultValue: string;
|
|
31
62
|
inputType: 'text' | 'file' | 'password' | 'folder';
|
|
32
63
|
type: ConfigurationOptionType;
|
|
64
|
+
/**
|
|
65
|
+
* Set the allowed values for the string. If the array is empty, any value is allowed. When provided, the client will act like this option is a dropdown.
|
|
66
|
+
* @param allowedValues {string[]} An array of allowed values for the string. If the array is empty, any value is allowed.
|
|
67
|
+
*/
|
|
33
68
|
setAllowedValues(allowedValues: string[]): this;
|
|
69
|
+
/**
|
|
70
|
+
* Set the default value for the string. This value will be used if the user does not provide a value. **HIGHLY RECOMMENDED**
|
|
71
|
+
* @param defaultValue {string} The default value for the string.
|
|
72
|
+
*/
|
|
34
73
|
setDefaultValue(defaultValue: string): this;
|
|
74
|
+
/**
|
|
75
|
+
* Set the minimum text length for the string. If the user provides a string that is less than this value, the validation will fail.
|
|
76
|
+
* @param minTextLength {number} The minimum text length for the string.
|
|
77
|
+
*/
|
|
35
78
|
setMinTextLength(minTextLength: number): this;
|
|
79
|
+
/**
|
|
80
|
+
* Set the maximum text length for the string. If the user provides a string that is greater than this value, the validation will fail.
|
|
81
|
+
* @param maxTextLength {number} The maximum text length for the string.
|
|
82
|
+
*/
|
|
36
83
|
setMaxTextLength(maxTextLength: number): this;
|
|
84
|
+
/**
|
|
85
|
+
* Set the input type for the string. This will change how the client renders the input.
|
|
86
|
+
* @param inputType {'text' | 'file' | 'password' | 'folder'} The input type for the string.
|
|
87
|
+
*/
|
|
37
88
|
setInputType(inputType: 'text' | 'file' | 'password' | 'folder'): this;
|
|
38
89
|
validate(input: unknown): [boolean, string];
|
|
39
90
|
}
|
|
@@ -43,15 +94,35 @@ declare class NumberOption extends ConfigurationOption {
|
|
|
43
94
|
defaultValue: number;
|
|
44
95
|
type: ConfigurationOptionType;
|
|
45
96
|
inputType: 'range' | 'number';
|
|
97
|
+
/**
|
|
98
|
+
* Set the minimum value for the number. If the user provides a number that is less than this value, the validation will fail.
|
|
99
|
+
* @param min {number} The minimum value for the number.
|
|
100
|
+
*/
|
|
46
101
|
setMin(min: number): this;
|
|
102
|
+
/**
|
|
103
|
+
* Set the input type for the number. This will change how the client renders the input.
|
|
104
|
+
* @param type {'range' | 'number'} The input type for the number.
|
|
105
|
+
*/
|
|
47
106
|
setInputType(type: 'range' | 'number'): this;
|
|
107
|
+
/**
|
|
108
|
+
* Set the maximum value for the number. If the user provides a number that is greater than this value, the validation will fail.
|
|
109
|
+
* @param max {number} The maximum value for the number.
|
|
110
|
+
*/
|
|
48
111
|
setMax(max: number): this;
|
|
112
|
+
/**
|
|
113
|
+
* Set the default value for the number. This value will be used if the user does not provide a value. **HIGHLY RECOMMENDED**
|
|
114
|
+
* @param defaultValue {number} The default value for the number.
|
|
115
|
+
*/
|
|
49
116
|
setDefaultValue(defaultValue: number): this;
|
|
50
117
|
validate(input: unknown): [boolean, string];
|
|
51
118
|
}
|
|
52
119
|
declare class BooleanOption extends ConfigurationOption {
|
|
53
120
|
type: ConfigurationOptionType;
|
|
54
121
|
defaultValue: boolean;
|
|
122
|
+
/**
|
|
123
|
+
* Set the default value for the boolean. This value will be used if the user does not provide a value. **HIGHLY RECOMMENDED**
|
|
124
|
+
* @param defaultValue {boolean} The default value for the boolean.
|
|
125
|
+
*/
|
|
55
126
|
setDefaultValue(defaultValue: boolean): this;
|
|
56
127
|
validate(input: unknown): [boolean, string];
|
|
57
128
|
}
|