ogi-addon 0.5.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/EventResponse.cjs +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 +171 -5
- package/build/main.cjs.map +1 -1
- package/build/main.d.cts +76 -3
- package/build/main.d.ts +76 -3
- package/build/main.js +169 -4
- package/build/main.js.map +1 -1
- package/package.json +1 -1
- package/schema.json +31 -0
- package/src/EventResponse.ts +20 -1
- package/src/SearchEngine.ts +1 -1
- package/src/config/ConfigurationBuilder.ts +73 -1
- package/src/main.ts +97 -7
- package/tsconfig.json +2 -1
package/build/EventResponse.cjs
CHANGED
|
@@ -36,16 +36,35 @@ var EventResponse = class {
|
|
|
36
36
|
defer() {
|
|
37
37
|
this.deffered = true;
|
|
38
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* Resolve the event with data. This acts like a promise resolve, and will stop the event from being processed further. **You must always call this method when you are done with the event.**
|
|
41
|
+
* @param data {T}
|
|
42
|
+
*/
|
|
39
43
|
resolve(data) {
|
|
40
44
|
this.resolved = true;
|
|
41
45
|
this.data = data;
|
|
42
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* Completes the event and resolves it, but does not return any data. **You must always call this method when you are done with the event.**
|
|
49
|
+
*/
|
|
43
50
|
complete() {
|
|
44
51
|
this.resolved = true;
|
|
45
52
|
}
|
|
53
|
+
/**
|
|
54
|
+
* Logs a message to the event. This is useful for debugging and logging information to the user.
|
|
55
|
+
* @param message {string}
|
|
56
|
+
*/
|
|
46
57
|
log(message) {
|
|
47
58
|
this.logs.push(message);
|
|
48
59
|
}
|
|
60
|
+
/**
|
|
61
|
+
* Send a screen to the client to ask for input. Use the `ConfigurationBuilder` system to build the screen. Once sent to the user, the addon cannot change the screen.
|
|
62
|
+
* @async
|
|
63
|
+
* @param name {string}
|
|
64
|
+
* @param description {string}
|
|
65
|
+
* @param screen {ConfigurationBuilder}
|
|
66
|
+
* @returns {Promise<{ [key: string]: boolean | string | number }>}
|
|
67
|
+
*/
|
|
49
68
|
async askForInput(name, description, screen) {
|
|
50
69
|
if (!this.onInputAsked) {
|
|
51
70
|
throw new Error("No input asked callback");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/EventResponse.ts"],"sourcesContent":["import { ConfigurationBuilder } from \"./main\";\r\n\r\nexport default class EventResponse<T> {\r\n data: T | undefined = undefined;\r\n deffered: boolean = false;\r\n resolved: boolean = false;\r\n progress: number = 0;\r\n logs: string[] = [];\r\n onInputAsked?: (screen: ConfigurationBuilder, name: string, description: string) => Promise<{ [key: string]: boolean | string | number }>;\r\n\r\n constructor(onInputAsked?: (screen: ConfigurationBuilder, name: string, description: string) => Promise<{ [key: string]: boolean | string | number }>) {\r\n this.onInputAsked = onInputAsked;\r\n }\r\n \r\n\r\n public defer() {\r\n this.deffered = true;\r\n }\r\n\r\n public resolve(data: T) {\r\n this.resolved = true;\r\n this.data = data;\r\n }\r\n\r\n public complete() {\r\n this.resolved = true;\r\n }\r\n\r\n public log(message: string) {\r\n this.logs.push(message);\r\n }\r\n\r\n public async askForInput(name: string, description: string, screen: ConfigurationBuilder) {\r\n if (!this.onInputAsked) {\r\n throw new Error('No input asked callback');\r\n }\r\n return await this.onInputAsked(screen, name, description);\r\n }\r\n\r\n \r\n}"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,IAAqB,gBAArB,MAAsC;AAAA,EACpC,OAAsB;AAAA,EACtB,WAAoB;AAAA,EACpB,WAAoB;AAAA,EACpB,WAAmB;AAAA,EACnB,OAAiB,CAAC;AAAA,EAClB;AAAA,EAEA,YAAY,cAA2I;AACrJ,SAAK,eAAe;AAAA,EACtB;AAAA,EAGO,QAAQ;AACb,SAAK,WAAW;AAAA,EAClB;AAAA,
|
|
1
|
+
{"version":3,"sources":["../src/EventResponse.ts"],"sourcesContent":["import { ConfigurationBuilder } from \"./main\";\r\n\r\nexport default class EventResponse<T> {\r\n data: T | undefined = undefined;\r\n deffered: boolean = false;\r\n resolved: boolean = false;\r\n progress: number = 0;\r\n logs: string[] = [];\r\n onInputAsked?: (screen: ConfigurationBuilder, name: string, description: string) => Promise<{ [key: string]: boolean | string | number }>;\r\n\r\n constructor(onInputAsked?: (screen: ConfigurationBuilder, name: string, description: string) => Promise<{ [key: string]: boolean | string | number }>) {\r\n this.onInputAsked = onInputAsked;\r\n }\r\n \r\n\r\n public defer() {\r\n this.deffered = true;\r\n }\r\n\r\n /**\r\n * Resolve the event with data. This acts like a promise resolve, and will stop the event from being processed further. **You must always call this method when you are done with the event.** \r\n * @param data {T}\r\n */\r\n public resolve(data: T) {\r\n this.resolved = true;\r\n this.data = data;\r\n }\r\n\r\n /**\r\n * Completes the event and resolves it, but does not return any data. **You must always call this method when you are done with the event.** \r\n */\r\n public complete() {\r\n this.resolved = true;\r\n }\r\n\r\n /**\r\n * Logs a message to the event. This is useful for debugging and logging information to the user. \r\n * @param message {string}\r\n */\r\n public log(message: string) {\r\n this.logs.push(message);\r\n }\r\n\r\n /**\r\n * Send a screen to the client to ask for input. Use the `ConfigurationBuilder` system to build the screen. Once sent to the user, the addon cannot change the screen.\r\n * @async\r\n * @param name {string}\r\n * @param description {string}\r\n * @param screen {ConfigurationBuilder}\r\n * @returns {Promise<{ [key: string]: boolean | string | number }>}\r\n */\r\n public async askForInput(name: string, description: string, screen: ConfigurationBuilder): Promise<{ [key: string]: boolean | string | number; }> {\r\n if (!this.onInputAsked) {\r\n throw new Error('No input asked callback');\r\n }\r\n return await this.onInputAsked(screen, name, description);\r\n }\r\n\r\n \r\n}"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,IAAqB,gBAArB,MAAsC;AAAA,EACpC,OAAsB;AAAA,EACtB,WAAoB;AAAA,EACpB,WAAoB;AAAA,EACpB,WAAmB;AAAA,EACnB,OAAiB,CAAC;AAAA,EAClB;AAAA,EAEA,YAAY,cAA2I;AACrJ,SAAK,eAAe;AAAA,EACtB;AAAA,EAGO,QAAQ;AACb,SAAK,WAAW;AAAA,EAClB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMO,QAAQ,MAAS;AACtB,SAAK,WAAW;AAChB,SAAK,OAAO;AAAA,EACd;AAAA;AAAA;AAAA;AAAA,EAKO,WAAW;AAChB,SAAK,WAAW;AAAA,EAClB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMO,IAAI,SAAiB;AAC1B,SAAK,KAAK,KAAK,OAAO;AAAA,EACxB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,MAAa,YAAY,MAAc,aAAqB,QAAsF;AAChJ,QAAI,CAAC,KAAK,cAAc;AACtB,YAAM,IAAI,MAAM,yBAAyB;AAAA,IAC3C;AACA,WAAO,MAAM,KAAK,aAAa,QAAQ,MAAM,WAAW;AAAA,EAC1D;AAGF;","names":[]}
|
|
@@ -13,11 +13,30 @@ declare class EventResponse<T> {
|
|
|
13
13
|
[key: string]: boolean | string | number;
|
|
14
14
|
}>);
|
|
15
15
|
defer(): void;
|
|
16
|
+
/**
|
|
17
|
+
* Resolve the event with data. This acts like a promise resolve, and will stop the event from being processed further. **You must always call this method when you are done with the event.**
|
|
18
|
+
* @param data {T}
|
|
19
|
+
*/
|
|
16
20
|
resolve(data: T): void;
|
|
21
|
+
/**
|
|
22
|
+
* Completes the event and resolves it, but does not return any data. **You must always call this method when you are done with the event.**
|
|
23
|
+
*/
|
|
17
24
|
complete(): void;
|
|
25
|
+
/**
|
|
26
|
+
* Logs a message to the event. This is useful for debugging and logging information to the user.
|
|
27
|
+
* @param message {string}
|
|
28
|
+
*/
|
|
18
29
|
log(message: string): void;
|
|
30
|
+
/**
|
|
31
|
+
* Send a screen to the client to ask for input. Use the `ConfigurationBuilder` system to build the screen. Once sent to the user, the addon cannot change the screen.
|
|
32
|
+
* @async
|
|
33
|
+
* @param name {string}
|
|
34
|
+
* @param description {string}
|
|
35
|
+
* @param screen {ConfigurationBuilder}
|
|
36
|
+
* @returns {Promise<{ [key: string]: boolean | string | number }>}
|
|
37
|
+
*/
|
|
19
38
|
askForInput(name: string, description: string, screen: ConfigurationBuilder): Promise<{
|
|
20
|
-
[key: string]:
|
|
39
|
+
[key: string]: boolean | string | number;
|
|
21
40
|
}>;
|
|
22
41
|
}
|
|
23
42
|
|
package/build/EventResponse.d.ts
CHANGED
|
@@ -13,11 +13,30 @@ declare class EventResponse<T> {
|
|
|
13
13
|
[key: string]: boolean | string | number;
|
|
14
14
|
}>);
|
|
15
15
|
defer(): void;
|
|
16
|
+
/**
|
|
17
|
+
* Resolve the event with data. This acts like a promise resolve, and will stop the event from being processed further. **You must always call this method when you are done with the event.**
|
|
18
|
+
* @param data {T}
|
|
19
|
+
*/
|
|
16
20
|
resolve(data: T): void;
|
|
21
|
+
/**
|
|
22
|
+
* Completes the event and resolves it, but does not return any data. **You must always call this method when you are done with the event.**
|
|
23
|
+
*/
|
|
17
24
|
complete(): void;
|
|
25
|
+
/**
|
|
26
|
+
* Logs a message to the event. This is useful for debugging and logging information to the user.
|
|
27
|
+
* @param message {string}
|
|
28
|
+
*/
|
|
18
29
|
log(message: string): void;
|
|
30
|
+
/**
|
|
31
|
+
* Send a screen to the client to ask for input. Use the `ConfigurationBuilder` system to build the screen. Once sent to the user, the addon cannot change the screen.
|
|
32
|
+
* @async
|
|
33
|
+
* @param name {string}
|
|
34
|
+
* @param description {string}
|
|
35
|
+
* @param screen {ConfigurationBuilder}
|
|
36
|
+
* @returns {Promise<{ [key: string]: boolean | string | number }>}
|
|
37
|
+
*/
|
|
19
38
|
askForInput(name: string, description: string, screen: ConfigurationBuilder): Promise<{
|
|
20
|
-
[key: string]:
|
|
39
|
+
[key: string]: boolean | string | number;
|
|
21
40
|
}>;
|
|
22
41
|
}
|
|
23
42
|
|
package/build/EventResponse.js
CHANGED
|
@@ -12,16 +12,35 @@ var EventResponse = class {
|
|
|
12
12
|
defer() {
|
|
13
13
|
this.deffered = true;
|
|
14
14
|
}
|
|
15
|
+
/**
|
|
16
|
+
* Resolve the event with data. This acts like a promise resolve, and will stop the event from being processed further. **You must always call this method when you are done with the event.**
|
|
17
|
+
* @param data {T}
|
|
18
|
+
*/
|
|
15
19
|
resolve(data) {
|
|
16
20
|
this.resolved = true;
|
|
17
21
|
this.data = data;
|
|
18
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* Completes the event and resolves it, but does not return any data. **You must always call this method when you are done with the event.**
|
|
25
|
+
*/
|
|
19
26
|
complete() {
|
|
20
27
|
this.resolved = true;
|
|
21
28
|
}
|
|
29
|
+
/**
|
|
30
|
+
* Logs a message to the event. This is useful for debugging and logging information to the user.
|
|
31
|
+
* @param message {string}
|
|
32
|
+
*/
|
|
22
33
|
log(message) {
|
|
23
34
|
this.logs.push(message);
|
|
24
35
|
}
|
|
36
|
+
/**
|
|
37
|
+
* Send a screen to the client to ask for input. Use the `ConfigurationBuilder` system to build the screen. Once sent to the user, the addon cannot change the screen.
|
|
38
|
+
* @async
|
|
39
|
+
* @param name {string}
|
|
40
|
+
* @param description {string}
|
|
41
|
+
* @param screen {ConfigurationBuilder}
|
|
42
|
+
* @returns {Promise<{ [key: string]: boolean | string | number }>}
|
|
43
|
+
*/
|
|
25
44
|
async askForInput(name, description, screen) {
|
|
26
45
|
if (!this.onInputAsked) {
|
|
27
46
|
throw new Error("No input asked callback");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/EventResponse.ts"],"sourcesContent":["import { ConfigurationBuilder } from \"./main\";\r\n\r\nexport default class EventResponse<T> {\r\n data: T | undefined = undefined;\r\n deffered: boolean = false;\r\n resolved: boolean = false;\r\n progress: number = 0;\r\n logs: string[] = [];\r\n onInputAsked?: (screen: ConfigurationBuilder, name: string, description: string) => Promise<{ [key: string]: boolean | string | number }>;\r\n\r\n constructor(onInputAsked?: (screen: ConfigurationBuilder, name: string, description: string) => Promise<{ [key: string]: boolean | string | number }>) {\r\n this.onInputAsked = onInputAsked;\r\n }\r\n \r\n\r\n public defer() {\r\n this.deffered = true;\r\n }\r\n\r\n public resolve(data: T) {\r\n this.resolved = true;\r\n this.data = data;\r\n }\r\n\r\n public complete() {\r\n this.resolved = true;\r\n }\r\n\r\n public log(message: string) {\r\n this.logs.push(message);\r\n }\r\n\r\n public async askForInput(name: string, description: string, screen: ConfigurationBuilder) {\r\n if (!this.onInputAsked) {\r\n throw new Error('No input asked callback');\r\n }\r\n return await this.onInputAsked(screen, name, description);\r\n }\r\n\r\n \r\n}"],"mappings":";AAEA,IAAqB,gBAArB,MAAsC;AAAA,EACpC,OAAsB;AAAA,EACtB,WAAoB;AAAA,EACpB,WAAoB;AAAA,EACpB,WAAmB;AAAA,EACnB,OAAiB,CAAC;AAAA,EAClB;AAAA,EAEA,YAAY,cAA2I;AACrJ,SAAK,eAAe;AAAA,EACtB;AAAA,EAGO,QAAQ;AACb,SAAK,WAAW;AAAA,EAClB;AAAA,
|
|
1
|
+
{"version":3,"sources":["../src/EventResponse.ts"],"sourcesContent":["import { ConfigurationBuilder } from \"./main\";\r\n\r\nexport default class EventResponse<T> {\r\n data: T | undefined = undefined;\r\n deffered: boolean = false;\r\n resolved: boolean = false;\r\n progress: number = 0;\r\n logs: string[] = [];\r\n onInputAsked?: (screen: ConfigurationBuilder, name: string, description: string) => Promise<{ [key: string]: boolean | string | number }>;\r\n\r\n constructor(onInputAsked?: (screen: ConfigurationBuilder, name: string, description: string) => Promise<{ [key: string]: boolean | string | number }>) {\r\n this.onInputAsked = onInputAsked;\r\n }\r\n \r\n\r\n public defer() {\r\n this.deffered = true;\r\n }\r\n\r\n /**\r\n * Resolve the event with data. This acts like a promise resolve, and will stop the event from being processed further. **You must always call this method when you are done with the event.** \r\n * @param data {T}\r\n */\r\n public resolve(data: T) {\r\n this.resolved = true;\r\n this.data = data;\r\n }\r\n\r\n /**\r\n * Completes the event and resolves it, but does not return any data. **You must always call this method when you are done with the event.** \r\n */\r\n public complete() {\r\n this.resolved = true;\r\n }\r\n\r\n /**\r\n * Logs a message to the event. This is useful for debugging and logging information to the user. \r\n * @param message {string}\r\n */\r\n public log(message: string) {\r\n this.logs.push(message);\r\n }\r\n\r\n /**\r\n * Send a screen to the client to ask for input. Use the `ConfigurationBuilder` system to build the screen. Once sent to the user, the addon cannot change the screen.\r\n * @async\r\n * @param name {string}\r\n * @param description {string}\r\n * @param screen {ConfigurationBuilder}\r\n * @returns {Promise<{ [key: string]: boolean | string | number }>}\r\n */\r\n public async askForInput(name: string, description: string, screen: ConfigurationBuilder): Promise<{ [key: string]: boolean | string | number; }> {\r\n if (!this.onInputAsked) {\r\n throw new Error('No input asked callback');\r\n }\r\n return await this.onInputAsked(screen, name, description);\r\n }\r\n\r\n \r\n}"],"mappings":";AAEA,IAAqB,gBAArB,MAAsC;AAAA,EACpC,OAAsB;AAAA,EACtB,WAAoB;AAAA,EACpB,WAAoB;AAAA,EACpB,WAAmB;AAAA,EACnB,OAAiB,CAAC;AAAA,EAClB;AAAA,EAEA,YAAY,cAA2I;AACrJ,SAAK,eAAe;AAAA,EACtB;AAAA,EAGO,QAAQ;AACb,SAAK,WAAW;AAAA,EAClB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMO,QAAQ,MAAS;AACtB,SAAK,WAAW;AAChB,SAAK,OAAO;AAAA,EACd;AAAA;AAAA;AAAA;AAAA,EAKO,WAAW;AAChB,SAAK,WAAW;AAAA,EAClB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMO,IAAI,SAAiB;AAC1B,SAAK,KAAK,KAAK,OAAO;AAAA,EACxB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,MAAa,YAAY,MAAc,aAAqB,QAAsF;AAChJ,QAAI,CAAC,KAAK,cAAc;AACtB,YAAM,IAAI,MAAM,yBAAyB;AAAA,IAC3C;AACA,WAAO,MAAM,KAAK,aAAa,QAAQ,MAAM,WAAW;AAAA,EAC1D;AAGF;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/SearchEngine.ts"],"sourcesContent":["export type SearchResult = {\r\n name: string;\r\n description: string;\r\n coverURL: string;\r\n downloadType: 'torrent' | 'direct' | 'magnet';\r\n downloadSize: number;\r\n appID: number;\r\n storefront: 'steam' | 'internal';\r\n filename?: string;\r\n downloadURL?: string;\r\n files?: {\r\n name: string;\r\n downloadURL: string;\r\n }[];\r\n}\r\n\r\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/SearchEngine.ts"],"sourcesContent":["export type SearchResult = {\r\n name: string;\r\n description: string;\r\n coverURL: string;\r\n downloadType: 'torrent' | 'direct' | 'magnet' | 'request';\r\n downloadSize: number;\r\n appID: number;\r\n storefront: 'steam' | 'internal';\r\n filename?: string;\r\n downloadURL?: string;\r\n files?: {\r\n name: string;\r\n downloadURL: string;\r\n }[];\r\n}\r\n\r\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
|
package/build/SearchEngine.d.cts
CHANGED
package/build/SearchEngine.d.ts
CHANGED
|
@@ -60,18 +60,31 @@ function isBooleanOption(option) {
|
|
|
60
60
|
}
|
|
61
61
|
var ConfigurationBuilder = class {
|
|
62
62
|
options = [];
|
|
63
|
+
/**
|
|
64
|
+
* 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.
|
|
65
|
+
* @param option { (option: NumberOption) => NumberOption }
|
|
66
|
+
* @returns
|
|
67
|
+
*/
|
|
63
68
|
addNumberOption(option) {
|
|
64
69
|
let newOption = new NumberOption();
|
|
65
70
|
newOption = option(newOption);
|
|
66
71
|
this.options.push(newOption);
|
|
67
72
|
return this;
|
|
68
73
|
}
|
|
74
|
+
/**
|
|
75
|
+
* 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.
|
|
76
|
+
* @param option { (option: StringOption) => StringOption }
|
|
77
|
+
*/
|
|
69
78
|
addStringOption(option) {
|
|
70
79
|
let newOption = new StringOption();
|
|
71
80
|
newOption = option(newOption);
|
|
72
81
|
this.options.push(newOption);
|
|
73
82
|
return this;
|
|
74
83
|
}
|
|
84
|
+
/**
|
|
85
|
+
* 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.
|
|
86
|
+
* @param option { (option: BooleanOption) => BooleanOption }
|
|
87
|
+
*/
|
|
75
88
|
addBooleanOption(option) {
|
|
76
89
|
let newOption = new BooleanOption();
|
|
77
90
|
newOption = option(newOption);
|
|
@@ -101,18 +114,36 @@ var ConfigurationOption = class {
|
|
|
101
114
|
displayName = "";
|
|
102
115
|
description = "";
|
|
103
116
|
type = "unset";
|
|
117
|
+
/**
|
|
118
|
+
* Set the name of the option. **REQUIRED**
|
|
119
|
+
* @param name {string} The name of the option. This is used to reference the option in the configuration file.
|
|
120
|
+
*/
|
|
104
121
|
setName(name) {
|
|
105
122
|
this.name = name;
|
|
106
123
|
return this;
|
|
107
124
|
}
|
|
125
|
+
/**
|
|
126
|
+
* Set the display name of the option. This is used to show the user a human readable version of what the option is. **REQUIRED**
|
|
127
|
+
* @param displayName {string} The display name of the option.
|
|
128
|
+
* @returns
|
|
129
|
+
*/
|
|
108
130
|
setDisplayName(displayName) {
|
|
109
131
|
this.displayName = displayName;
|
|
110
132
|
return this;
|
|
111
133
|
}
|
|
134
|
+
/**
|
|
135
|
+
* Set the description of the option. This is to show the user a brief description of what this option does. **REQUIRED**
|
|
136
|
+
* @param description {string} The description of the option.
|
|
137
|
+
* @returns
|
|
138
|
+
*/
|
|
112
139
|
setDescription(description) {
|
|
113
140
|
this.description = description;
|
|
114
141
|
return this;
|
|
115
142
|
}
|
|
143
|
+
/**
|
|
144
|
+
* 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.
|
|
145
|
+
* @param input {unknown} The input to validate
|
|
146
|
+
*/
|
|
116
147
|
validate(input) {
|
|
117
148
|
throw new Error("Validation code not implemented. Value: " + input);
|
|
118
149
|
}
|
|
@@ -124,22 +155,42 @@ var StringOption = class extends ConfigurationOption {
|
|
|
124
155
|
defaultValue = "";
|
|
125
156
|
inputType = "text";
|
|
126
157
|
type = "string";
|
|
158
|
+
/**
|
|
159
|
+
* 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.
|
|
160
|
+
* @param allowedValues {string[]} An array of allowed values for the string. If the array is empty, any value is allowed.
|
|
161
|
+
*/
|
|
127
162
|
setAllowedValues(allowedValues) {
|
|
128
163
|
this.allowedValues = allowedValues;
|
|
129
164
|
return this;
|
|
130
165
|
}
|
|
166
|
+
/**
|
|
167
|
+
* Set the default value for the string. This value will be used if the user does not provide a value. **HIGHLY RECOMMENDED**
|
|
168
|
+
* @param defaultValue {string} The default value for the string.
|
|
169
|
+
*/
|
|
131
170
|
setDefaultValue(defaultValue) {
|
|
132
171
|
this.defaultValue = defaultValue;
|
|
133
172
|
return this;
|
|
134
173
|
}
|
|
174
|
+
/**
|
|
175
|
+
* Set the minimum text length for the string. If the user provides a string that is less than this value, the validation will fail.
|
|
176
|
+
* @param minTextLength {number} The minimum text length for the string.
|
|
177
|
+
*/
|
|
135
178
|
setMinTextLength(minTextLength) {
|
|
136
179
|
this.minTextLength = minTextLength;
|
|
137
180
|
return this;
|
|
138
181
|
}
|
|
182
|
+
/**
|
|
183
|
+
* Set the maximum text length for the string. If the user provides a string that is greater than this value, the validation will fail.
|
|
184
|
+
* @param maxTextLength {number} The maximum text length for the string.
|
|
185
|
+
*/
|
|
139
186
|
setMaxTextLength(maxTextLength) {
|
|
140
187
|
this.maxTextLength = maxTextLength;
|
|
141
188
|
return this;
|
|
142
189
|
}
|
|
190
|
+
/**
|
|
191
|
+
* Set the input type for the string. This will change how the client renders the input.
|
|
192
|
+
* @param inputType {'text' | 'file' | 'password' | 'folder'} The input type for the string.
|
|
193
|
+
*/
|
|
143
194
|
setInputType(inputType) {
|
|
144
195
|
this.inputType = inputType;
|
|
145
196
|
return this;
|
|
@@ -162,18 +213,34 @@ var NumberOption = class extends ConfigurationOption {
|
|
|
162
213
|
defaultValue = 0;
|
|
163
214
|
type = "number";
|
|
164
215
|
inputType = "number";
|
|
216
|
+
/**
|
|
217
|
+
* Set the minimum value for the number. If the user provides a number that is less than this value, the validation will fail.
|
|
218
|
+
* @param min {number} The minimum value for the number.
|
|
219
|
+
*/
|
|
165
220
|
setMin(min) {
|
|
166
221
|
this.min = min;
|
|
167
222
|
return this;
|
|
168
223
|
}
|
|
224
|
+
/**
|
|
225
|
+
* Set the input type for the number. This will change how the client renders the input.
|
|
226
|
+
* @param type {'range' | 'number'} The input type for the number.
|
|
227
|
+
*/
|
|
169
228
|
setInputType(type) {
|
|
170
229
|
this.inputType = type;
|
|
171
230
|
return this;
|
|
172
231
|
}
|
|
232
|
+
/**
|
|
233
|
+
* Set the maximum value for the number. If the user provides a number that is greater than this value, the validation will fail.
|
|
234
|
+
* @param max {number} The maximum value for the number.
|
|
235
|
+
*/
|
|
173
236
|
setMax(max) {
|
|
174
237
|
this.max = max;
|
|
175
238
|
return this;
|
|
176
239
|
}
|
|
240
|
+
/**
|
|
241
|
+
* Set the default value for the number. This value will be used if the user does not provide a value. **HIGHLY RECOMMENDED**
|
|
242
|
+
* @param defaultValue {number} The default value for the number.
|
|
243
|
+
*/
|
|
177
244
|
setDefaultValue(defaultValue) {
|
|
178
245
|
this.defaultValue = defaultValue;
|
|
179
246
|
return this;
|
|
@@ -191,6 +258,10 @@ var NumberOption = class extends ConfigurationOption {
|
|
|
191
258
|
var BooleanOption = class extends ConfigurationOption {
|
|
192
259
|
type = "boolean";
|
|
193
260
|
defaultValue = false;
|
|
261
|
+
/**
|
|
262
|
+
* Set the default value for the boolean. This value will be used if the user does not provide a value. **HIGHLY RECOMMENDED**
|
|
263
|
+
* @param defaultValue {boolean} The default value for the boolean.
|
|
264
|
+
*/
|
|
194
265
|
setDefaultValue(defaultValue) {
|
|
195
266
|
this.defaultValue = defaultValue;
|
|
196
267
|
return this;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/config/Configuration.ts","../../src/config/ConfigurationBuilder.ts"],"sourcesContent":["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 };","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;;;ACAA,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,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,gB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;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":["z"]}
|
|
1
|
+
{"version":3,"sources":["../../src/config/Configuration.ts","../../src/config/ConfigurationBuilder.ts"],"sourcesContent":["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 };","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\r\n /**\r\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.\r\n * @param option { (option: NumberOption) => NumberOption }\r\n * @returns \r\n */\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 /**\r\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.\r\n * @param option { (option: StringOption) => StringOption }\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 /**\r\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.\r\n * @param option { (option: BooleanOption) => BooleanOption }\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 /**\r\n * Set the name of the option. **REQUIRED**\r\n * @param name {string} The name of the option. This is used to reference the option in the configuration file.\r\n */\r\n setName(name: string) {\r\n this.name = name;\r\n return this;\r\n }\r\n\r\n /**\r\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** \r\n * @param displayName {string} The display name of the option. \r\n * @returns \r\n */\r\n setDisplayName(displayName: string) {\r\n this.displayName = displayName;\r\n return this;\r\n }\r\n\r\n /**\r\n * Set the description of the option. This is to show the user a brief description of what this option does. **REQUIRED**\r\n * @param description {string} The description of the option. \r\n * @returns \r\n */\r\n setDescription(description: string) {\r\n this.description = description;\r\n return this;\r\n }\r\n\r\n /**\r\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.\r\n * @param input {unknown} The input to validate\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 /**\r\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. \r\n * @param allowedValues {string[]} An array of allowed values for the string. If the array is empty, any value is allowed.\r\n */\r\n setAllowedValues(allowedValues: string[]): this {\r\n this.allowedValues = allowedValues;\r\n return this;\r\n }\r\n\r\n /**\r\n * Set the default value for the string. This value will be used if the user does not provide a value. **HIGHLY RECOMMENDED**\r\n * @param defaultValue {string} The default value for the string.\r\n */\r\n setDefaultValue(defaultValue: string): this {\r\n this.defaultValue = defaultValue;\r\n return this;\r\n }\r\n\r\n /**\r\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. \r\n * @param minTextLength {number} The minimum text length for the string. \r\n */\r\n setMinTextLength(minTextLength: number): this {\r\n this.minTextLength = minTextLength;\r\n return this;\r\n }\r\n\r\n /**\r\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. \r\n * @param maxTextLength {number} The maximum text length for the string.\r\n */\r\n setMaxTextLength(maxTextLength: number): this {\r\n this.maxTextLength = maxTextLength;\r\n return this;\r\n }\r\n\r\n /**\r\n * Set the input type for the string. This will change how the client renders the input. \r\n * @param inputType {'text' | 'file' | 'password' | 'folder'} The input type for the string. \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\r\n /**\r\n * Set the minimum value for the number. If the user provides a number that is less than this value, the validation will fail.\r\n * @param min {number} The minimum value for the number.\r\n */\r\n setMin(min: number): this {\r\n this.min = min;\r\n return this;\r\n }\r\n\r\n /**\r\n * Set the input type for the number. This will change how the client renders the input. \r\n * @param type {'range' | 'number'} The input type for the number. \r\n */\r\n setInputType(type: 'range' | 'number'): this {\r\n this.inputType = type;\r\n return this;\r\n }\r\n\r\n /**\r\n * Set the maximum value for the number. If the user provides a number that is greater than this value, the validation will fail.\r\n * @param max {number} The maximum value for the number.\r\n */\r\n setMax(max: number): this {\r\n this.max = max;\r\n return this\r\n }\r\n\r\n /**\r\n * Set the default value for the number. This value will be used if the user does not provide a value. **HIGHLY RECOMMENDED**\r\n * @param defaultValue {number} The default value for the number.\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 /**\r\n * Set the default value for the boolean. This value will be used if the user does not provide a value. **HIGHLY RECOMMENDED**\r\n * @param defaultValue {boolean} The default value for the boolean.\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;;;ACAA,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,eAAe,QAAqD;AAClF,SAAO,OAAO,SAAS;AACz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;AAAA,EACjD;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,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":["z"]}
|
|
@@ -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;
|