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
|
@@ -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
|
}
|
|
@@ -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"],"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,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;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,MAAc;AAAA,EACd,MAAc,OAAO;AAAA,EACrB,eAAuB;AAAA,EACvB,OAAgC;AAAA,EAChC,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":[]}
|
|
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): [ boolean, string ] {\n if (typeof input !== 'boolean') {\n return [ false, 'Input is not a boolean' ];\n }\n return [ true, '' ];\n }\n\n}"],"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;AAAA;AAAA;AAAA;AAAA;AAAA,EAOnC,gBAAgB,QAAsE;AAC3F,QAAI,YAAY,IAAI,aAAa;AACjC,gBAAY,OAAO,SAAS;AAC5B,SAAK,QAAQ,KAAK,SAAS;AAC3B,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA,EAMO,gBAAgB,QAAgD;AACrE,QAAI,YAAY,IAAI,aAAa;AACjC,gBAAY,OAAO,SAAS;AAC5B,SAAK,QAAQ,KAAK,SAAS;AAC3B,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA,EAMO,iBAAiB,QAAkD;AACxE,QAAI,YAAY,IAAI,cAAc;AAClC,gBAAY,OAAO,SAAS;AAC5B,SAAK,QAAQ,KAAK,SAAS;AAC3B,WAAO;AAAA,EACT;AAAA,EAEO,MAAM,kBAA8C;AACzD,QAAI,SAA4B,CAAC;AACjC,SAAK,QAAQ,QAAQ,YAAU;AAE7B,UAAI,CAAC,kBAAkB;AACrB,iBAA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