ogi-addon 1.9.2 → 1.9.4

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.
Files changed (58) hide show
  1. package/build/Configuration-CdRZbO6z.d.mts +21 -0
  2. package/build/Configuration-WeOm-F0_.d.cts +21 -0
  3. package/build/ConfigurationBuilder-BSuJ4rSI.cjs +302 -0
  4. package/build/ConfigurationBuilder-BSuJ4rSI.cjs.map +1 -0
  5. package/build/ConfigurationBuilder-BbZDA_xx.d.mts +132 -0
  6. package/build/ConfigurationBuilder-CfHLKMTO.d.cts +132 -0
  7. package/build/EventResponse-CQhmdz3C.d.mts +430 -0
  8. package/build/EventResponse-D1c-Df5W.d.cts +430 -0
  9. package/build/EventResponse.cjs +55 -79
  10. package/build/EventResponse.cjs.map +1 -1
  11. package/build/EventResponse.d.cts +2 -45
  12. package/build/EventResponse.d.mts +2 -0
  13. package/build/EventResponse.mjs +58 -0
  14. package/build/EventResponse.mjs.map +1 -0
  15. package/build/SearchEngine-CRQWXfo6.d.mts +22 -0
  16. package/build/SearchEngine-DBSUNM4A.d.cts +22 -0
  17. package/build/SearchEngine.cjs +0 -19
  18. package/build/SearchEngine.d.cts +2 -20
  19. package/build/SearchEngine.d.mts +2 -0
  20. package/build/SearchEngine.mjs +1 -0
  21. package/build/config/Configuration.cjs +56 -370
  22. package/build/config/Configuration.cjs.map +1 -1
  23. package/build/config/Configuration.d.cts +3 -20
  24. package/build/config/Configuration.d.mts +3 -0
  25. package/build/config/Configuration.mjs +52 -0
  26. package/build/config/Configuration.mjs.map +1 -0
  27. package/build/config/ConfigurationBuilder.cjs +9 -292
  28. package/build/config/ConfigurationBuilder.d.cts +2 -130
  29. package/build/config/ConfigurationBuilder.d.mts +2 -0
  30. package/build/config/ConfigurationBuilder.mjs +221 -0
  31. package/build/config/ConfigurationBuilder.mjs.map +1 -0
  32. package/build/main.cjs +510 -1074
  33. package/build/main.cjs.map +1 -1
  34. package/build/main.d.cts +5 -385
  35. package/build/main.d.mts +5 -0
  36. package/build/main.mjs +510 -0
  37. package/build/main.mjs.map +1 -0
  38. package/package.json +9 -9
  39. package/src/config/Configuration.ts +18 -7
  40. package/src/main.ts +19 -12
  41. package/{tsup.config.js → tsdown.config.js} +2 -1
  42. package/build/EventResponse.d.ts +0 -45
  43. package/build/EventResponse.js +0 -62
  44. package/build/EventResponse.js.map +0 -1
  45. package/build/SearchEngine.cjs.map +0 -1
  46. package/build/SearchEngine.d.ts +0 -20
  47. package/build/SearchEngine.js +0 -1
  48. package/build/SearchEngine.js.map +0 -1
  49. package/build/config/Configuration.d.ts +0 -20
  50. package/build/config/Configuration.js +0 -329
  51. package/build/config/Configuration.js.map +0 -1
  52. package/build/config/ConfigurationBuilder.cjs.map +0 -1
  53. package/build/config/ConfigurationBuilder.d.ts +0 -130
  54. package/build/config/ConfigurationBuilder.js +0 -251
  55. package/build/config/ConfigurationBuilder.js.map +0 -1
  56. package/build/main.d.ts +0 -385
  57. package/build/main.js +0 -1045
  58. package/build/main.js.map +0 -1
@@ -1,15 +1,17 @@
1
1
  import {
2
- ConfigurationFile,
3
2
  ConfigurationBuilder,
4
3
  BooleanOption,
5
4
  ConfigurationOption,
6
- ConfigurationOptionType,
7
5
  NumberOption,
8
6
  StringOption,
9
7
  isBooleanOption,
10
8
  isNumberOption,
11
9
  isStringOption,
12
10
  } from './ConfigurationBuilder';
11
+ import type {
12
+ ConfigurationFile,
13
+ ConfigurationOptionType,
14
+ } from './ConfigurationBuilder';
13
15
 
14
16
  interface DefiniteConfig {
15
17
  [key: string]: string | number | boolean;
@@ -83,7 +85,10 @@ export class Configuration {
83
85
  }
84
86
 
85
87
  getStringValue(optionName: string): string {
86
- if (!this.definiteConfig[optionName] === null) {
88
+ if (
89
+ this.definiteConfig[optionName] === null ||
90
+ this.definiteConfig[optionName] === undefined
91
+ ) {
87
92
  throw new Error('Option ' + optionName + ' is not defined');
88
93
  }
89
94
  if (typeof this.definiteConfig[optionName] !== 'string') {
@@ -93,7 +98,10 @@ export class Configuration {
93
98
  }
94
99
 
95
100
  getNumberValue(optionName: string): number {
96
- if (!this.definiteConfig[optionName] === null) {
101
+ if (
102
+ this.definiteConfig[optionName] === null ||
103
+ this.definiteConfig[optionName] === undefined
104
+ ) {
97
105
  throw new Error('Option ' + optionName + ' is not defined');
98
106
  }
99
107
  if (typeof this.definiteConfig[optionName] !== 'number') {
@@ -103,7 +111,10 @@ export class Configuration {
103
111
  }
104
112
 
105
113
  getBooleanValue(optionName: string): boolean {
106
- if (this.definiteConfig[optionName] === null) {
114
+ if (
115
+ this.definiteConfig[optionName] === null ||
116
+ this.definiteConfig[optionName] === undefined
117
+ ) {
107
118
  throw new Error('Option ' + optionName + ' is not defined');
108
119
  }
109
120
  if (typeof this.definiteConfig[optionName] !== 'boolean') {
@@ -114,14 +125,14 @@ export class Configuration {
114
125
  }
115
126
 
116
127
  export {
117
- ConfigurationFile,
118
128
  ConfigurationBuilder,
119
129
  BooleanOption,
120
130
  ConfigurationOption,
121
- ConfigurationOptionType,
122
131
  NumberOption,
123
132
  StringOption,
124
133
  isBooleanOption,
125
134
  isNumberOption,
126
135
  isStringOption,
127
136
  };
137
+
138
+ export type { ConfigurationFile, ConfigurationOptionType };
package/src/main.ts CHANGED
@@ -2,11 +2,11 @@ import ws, { WebSocket } from 'ws';
2
2
  import events from 'node:events';
3
3
  import {
4
4
  ConfigurationBuilder,
5
- ConfigurationFile,
6
5
  } from './config/ConfigurationBuilder';
6
+ import type { ConfigurationFile } from './config/ConfigurationBuilder';
7
7
  import { Configuration } from './config/Configuration';
8
8
  import EventResponse from './EventResponse';
9
- import { SearchResult } from './SearchEngine';
9
+ import type { SearchResult } from './SearchEngine';
10
10
  import Fuse, { IFuseOptions } from 'fuse.js';
11
11
 
12
12
  export type OGIAddonEvent =
@@ -49,7 +49,8 @@ export type OGIAddonServerSentEvent =
49
49
  | 'game-details'
50
50
  | 'request-dl'
51
51
  | 'catalog';
52
- export { ConfigurationBuilder, Configuration, EventResponse, SearchResult };
52
+ export { ConfigurationBuilder, Configuration, EventResponse };
53
+ export type { SearchResult };
53
54
  const defaultPort = 7654;
54
55
  import pjson from '../package.json';
55
56
  import { exec, spawn } from 'node:child_process';
@@ -157,18 +158,18 @@ export interface EventListenerTypes {
157
158
  * @returns
158
159
  */
159
160
  search: (
160
- query:
161
+ query: {
162
+ storefront: string;
163
+ appID: number;
164
+ } & (
161
165
  | {
162
- storefront: string;
163
- appID: number;
164
166
  for: 'game' | 'task' | 'all';
165
167
  }
166
168
  | {
167
- storefront: string;
168
- appID: number;
169
169
  for: 'update';
170
170
  libraryInfo: LibraryInfo;
171
- },
171
+ }
172
+ ),
172
173
  event: EventResponse<SearchResult[]>
173
174
  ) => void;
174
175
  /**
@@ -179,8 +180,6 @@ export interface EventListenerTypes {
179
180
  */
180
181
  setup: (
181
182
  data: {
182
- for: 'game' | 'update';
183
- currentLibraryInfo: LibraryInfo | undefined;
184
183
  path: string;
185
184
  type: 'direct' | 'torrent' | 'magnet' | 'empty';
186
185
  name: string;
@@ -192,7 +191,15 @@ export interface EventListenerTypes {
192
191
  appID: number;
193
192
  storefront: string;
194
193
  manifest?: Record<string, unknown>;
195
- },
194
+ } & (
195
+ | {
196
+ for: 'game';
197
+ }
198
+ | {
199
+ for: 'update';
200
+ currentLibraryInfo: LibraryInfo;
201
+ }
202
+ ),
196
203
  event: EventResponse<SetupEventResponse>
197
204
  ) => void;
198
205
 
@@ -1,4 +1,4 @@
1
- import { defineConfig } from 'tsup';
1
+ import { defineConfig } from 'tsdown';
2
2
 
3
3
  export default defineConfig({
4
4
  entry: ['src/**'],
@@ -8,4 +8,5 @@ export default defineConfig({
8
8
  format: ['cjs', 'esm'],
9
9
  dts: true,
10
10
  outDir: 'build',
11
+ target: false,
11
12
  });
@@ -1,45 +0,0 @@
1
- import { ConfigurationBuilder } from './config/ConfigurationBuilder.js';
2
-
3
- declare class EventResponse<T> {
4
- data: T | undefined;
5
- deffered: boolean;
6
- resolved: boolean;
7
- progress: number;
8
- logs: string[];
9
- failed: string | undefined;
10
- onInputAsked?: (screen: ConfigurationBuilder, name: string, description: string) => Promise<{
11
- [key: string]: boolean | string | number;
12
- }>;
13
- constructor(onInputAsked?: (screen: ConfigurationBuilder, name: string, description: string) => Promise<{
14
- [key: string]: boolean | string | number;
15
- }>);
16
- defer(promise?: () => Promise<void>): void;
17
- /**
18
- * 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.**
19
- * @param data {T}
20
- */
21
- resolve(data: T): void;
22
- /**
23
- * 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.**
24
- */
25
- complete(): void;
26
- fail(message: string): void;
27
- /**
28
- * Logs a message to the event. This is useful for debugging and logging information to the user.
29
- * @param message {string}
30
- */
31
- log(message: string): void;
32
- /**
33
- * 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.
34
- * @async
35
- * @param name {string}
36
- * @param description {string}
37
- * @param screen {ConfigurationBuilder}
38
- * @returns {Promise<{ [key: string]: boolean | string | number }>}
39
- */
40
- askForInput(name: string, description: string, screen: ConfigurationBuilder): Promise<{
41
- [key: string]: boolean | string | number;
42
- }>;
43
- }
44
-
45
- export { EventResponse as default };
@@ -1,62 +0,0 @@
1
- // src/EventResponse.ts
2
- var EventResponse = class {
3
- data = void 0;
4
- deffered = false;
5
- resolved = false;
6
- progress = 0;
7
- logs = [];
8
- failed = void 0;
9
- onInputAsked;
10
- constructor(onInputAsked) {
11
- this.onInputAsked = onInputAsked;
12
- }
13
- defer(promise) {
14
- this.deffered = true;
15
- if (promise) {
16
- promise();
17
- }
18
- }
19
- /**
20
- * 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.**
21
- * @param data {T}
22
- */
23
- resolve(data) {
24
- this.resolved = true;
25
- this.data = data;
26
- }
27
- /**
28
- * 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.**
29
- */
30
- complete() {
31
- this.resolved = true;
32
- }
33
- fail(message) {
34
- this.resolved = true;
35
- this.failed = message;
36
- }
37
- /**
38
- * Logs a message to the event. This is useful for debugging and logging information to the user.
39
- * @param message {string}
40
- */
41
- log(message) {
42
- this.logs.push(message);
43
- }
44
- /**
45
- * 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.
46
- * @async
47
- * @param name {string}
48
- * @param description {string}
49
- * @param screen {ConfigurationBuilder}
50
- * @returns {Promise<{ [key: string]: boolean | string | number }>}
51
- */
52
- async askForInput(name, description, screen) {
53
- if (!this.onInputAsked) {
54
- throw new Error("No input asked callback");
55
- }
56
- return await this.onInputAsked(screen, name, description);
57
- }
58
- };
59
- export {
60
- EventResponse as default
61
- };
62
- //# sourceMappingURL=EventResponse.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/EventResponse.ts"],"sourcesContent":["import { ConfigurationBuilder } from './main';\n\nexport default class EventResponse<T> {\n data: T | undefined = undefined;\n deffered: boolean = false;\n resolved: boolean = false;\n progress: number = 0;\n logs: string[] = [];\n failed: string | undefined = undefined;\n onInputAsked?: (\n screen: ConfigurationBuilder,\n name: string,\n description: string\n ) => Promise<{ [key: string]: boolean | string | number }>;\n\n constructor(\n onInputAsked?: (\n screen: ConfigurationBuilder,\n name: string,\n description: string\n ) => Promise<{ [key: string]: boolean | string | number }>\n ) {\n this.onInputAsked = onInputAsked;\n }\n\n public defer(promise?: () => Promise<void>) {\n this.deffered = true;\n // include this to make it easier to use the defer method with async functions\n if (promise) {\n promise();\n }\n }\n\n /**\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.**\n * @param data {T}\n */\n public resolve(data: T) {\n this.resolved = true;\n this.data = data;\n }\n\n /**\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.**\n */\n public complete() {\n this.resolved = true;\n }\n\n public fail(message: string) {\n this.resolved = true;\n this.failed = message;\n }\n\n /**\n * Logs a message to the event. This is useful for debugging and logging information to the user.\n * @param message {string}\n */\n public log(message: string) {\n this.logs.push(message);\n }\n\n /**\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.\n * @async\n * @param name {string}\n * @param description {string}\n * @param screen {ConfigurationBuilder}\n * @returns {Promise<{ [key: string]: boolean | string | number }>}\n */\n public async askForInput(\n name: string,\n description: string,\n screen: ConfigurationBuilder\n ): Promise<{ [key: string]: boolean | string | number }> {\n if (!this.onInputAsked) {\n throw new Error('No input asked callback');\n }\n return await this.onInputAsked(screen, name, description);\n }\n}\n"],"mappings":";AAEA,IAAqB,gBAArB,MAAsC;AAAA,EACpC,OAAsB;AAAA,EACtB,WAAoB;AAAA,EACpB,WAAoB;AAAA,EACpB,WAAmB;AAAA,EACnB,OAAiB,CAAC;AAAA,EAClB,SAA6B;AAAA,EAC7B;AAAA,EAMA,YACE,cAKA;AACA,SAAK,eAAe;AAAA,EACtB;AAAA,EAEO,MAAM,SAA+B;AAC1C,SAAK,WAAW;AAEhB,QAAI,SAAS;AACX,cAAQ;AAAA,IACV;AAAA,EACF;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,EAEO,KAAK,SAAiB;AAC3B,SAAK,WAAW;AAChB,SAAK,SAAS;AAAA,EAChB;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,YACX,MACA,aACA,QACuD;AACvD,QAAI,CAAC,KAAK,cAAc;AACtB,YAAM,IAAI,MAAM,yBAAyB;AAAA,IAC3C;AACA,WAAO,MAAM,KAAK,aAAa,QAAQ,MAAM,WAAW;AAAA,EAC1D;AACF;","names":[]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/SearchEngine.ts"],"sourcesContent":["type BaseRequiredFields = {\n name: string;\n manifest?: Record<string, any>;\n};\n\nexport type SearchResult = BaseRequiredFields &\n (\n | {\n downloadType: 'torrent' | 'magnet';\n filename: string;\n downloadURL: string;\n }\n | {\n downloadType: 'direct';\n files: {\n name: string;\n downloadURL: string;\n headers?: Record<string, string>;\n }[];\n }\n | {\n downloadType: 'request' | 'task' | 'empty';\n }\n );\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
@@ -1,20 +0,0 @@
1
- type BaseRequiredFields = {
2
- name: string;
3
- manifest?: Record<string, any>;
4
- };
5
- type SearchResult = BaseRequiredFields & ({
6
- downloadType: 'torrent' | 'magnet';
7
- filename: string;
8
- downloadURL: string;
9
- } | {
10
- downloadType: 'direct';
11
- files: {
12
- name: string;
13
- downloadURL: string;
14
- headers?: Record<string, string>;
15
- }[];
16
- } | {
17
- downloadType: 'request' | 'task' | 'empty';
18
- });
19
-
20
- export type { SearchResult };
@@ -1 +0,0 @@
1
- //# sourceMappingURL=SearchEngine.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -1,20 +0,0 @@
1
- import { ConfigurationFile } from './ConfigurationBuilder.js';
2
- export { BooleanOption, ConfigurationBuilder, ConfigurationOption, ConfigurationOptionType, NumberOption, StringOption, isBooleanOption, isNumberOption, isStringOption } from './ConfigurationBuilder.js';
3
-
4
- interface DefiniteConfig {
5
- [key: string]: string | number | boolean;
6
- }
7
- declare class Configuration {
8
- readonly storedConfigTemplate: ConfigurationFile;
9
- definiteConfig: DefiniteConfig;
10
- constructor(configTemplate: ConfigurationFile);
11
- updateConfig(config: DefiniteConfig, validate?: boolean): [boolean, {
12
- [key: string]: string;
13
- }];
14
- private validateConfig;
15
- getStringValue(optionName: string): string;
16
- getNumberValue(optionName: string): number;
17
- getBooleanValue(optionName: string): boolean;
18
- }
19
-
20
- export { Configuration, ConfigurationFile };
@@ -1,329 +0,0 @@
1
- // src/config/ConfigurationBuilder.ts
2
- import z, { ZodError } from "zod";
3
- var configValidation = z.object({
4
- name: z.string().min(1),
5
- displayName: z.string().min(1),
6
- description: z.string().min(1)
7
- });
8
- function isStringOption(option) {
9
- return option.type === "string";
10
- }
11
- function isNumberOption(option) {
12
- return option.type === "number";
13
- }
14
- function isBooleanOption(option) {
15
- return option.type === "boolean";
16
- }
17
- var ConfigurationBuilder = class {
18
- options = [];
19
- /**
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
- */
24
- addNumberOption(option) {
25
- let newOption = new NumberOption();
26
- newOption = option(newOption);
27
- this.options.push(newOption);
28
- return this;
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
- */
34
- addStringOption(option) {
35
- let newOption = new StringOption();
36
- newOption = option(newOption);
37
- this.options.push(newOption);
38
- return this;
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
- */
44
- addBooleanOption(option) {
45
- let newOption = new BooleanOption();
46
- newOption = option(newOption);
47
- this.options.push(newOption);
48
- return this;
49
- }
50
- build(includeFunctions) {
51
- let config = {};
52
- this.options.forEach((option) => {
53
- if (!includeFunctions) {
54
- option = JSON.parse(JSON.stringify(option));
55
- const optionData = configValidation.safeParse(option);
56
- if (!optionData.success) {
57
- throw new ZodError(optionData.error.errors);
58
- }
59
- config[option.name] = option;
60
- } else {
61
- config[option.name] = option;
62
- }
63
- });
64
- return config;
65
- }
66
- };
67
- var ConfigurationOption = class {
68
- name = "";
69
- defaultValue = "";
70
- displayName = "";
71
- description = "";
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
- */
77
- setName(name) {
78
- this.name = name;
79
- return this;
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
- */
86
- setDisplayName(displayName) {
87
- this.displayName = displayName;
88
- return this;
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
- */
95
- setDescription(description) {
96
- this.description = description;
97
- return this;
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
- */
103
- validate(input) {
104
- throw new Error("Validation code not implemented. Value: " + input);
105
- }
106
- };
107
- var StringOption = class extends ConfigurationOption {
108
- allowedValues = [];
109
- minTextLength = 0;
110
- maxTextLength = Number.MAX_SAFE_INTEGER;
111
- defaultValue = "";
112
- inputType = "text";
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
- */
118
- setAllowedValues(allowedValues) {
119
- this.allowedValues = allowedValues;
120
- return this;
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
- */
126
- setDefaultValue(defaultValue) {
127
- this.defaultValue = defaultValue;
128
- return this;
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
- */
134
- setMinTextLength(minTextLength) {
135
- this.minTextLength = minTextLength;
136
- return this;
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
- */
142
- setMaxTextLength(maxTextLength) {
143
- this.maxTextLength = maxTextLength;
144
- return this;
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
- */
150
- setInputType(inputType) {
151
- this.inputType = inputType;
152
- return this;
153
- }
154
- validate(input) {
155
- if (typeof input !== "string") {
156
- return [false, "Input is not a string"];
157
- }
158
- if (this.allowedValues.length === 0 && input.length !== 0)
159
- return [true, ""];
160
- if (input.length < this.minTextLength || input.length > this.maxTextLength) {
161
- return [
162
- false,
163
- "Input is not within the text length " + this.minTextLength + " and " + this.maxTextLength + " characters (currently " + input.length + " characters)"
164
- ];
165
- }
166
- return [
167
- this.allowedValues.includes(input),
168
- "Input is not an allowed value"
169
- ];
170
- }
171
- };
172
- var NumberOption = class extends ConfigurationOption {
173
- min = 0;
174
- max = Number.MAX_SAFE_INTEGER;
175
- defaultValue = 0;
176
- type = "number";
177
- inputType = "number";
178
- /**
179
- * Set the minimum value for the number. If the user provides a number that is less than this value, the validation will fail.
180
- * @param min {number} The minimum value for the number.
181
- */
182
- setMin(min) {
183
- this.min = min;
184
- return this;
185
- }
186
- /**
187
- * Set the input type for the number. This will change how the client renders the input.
188
- * @param type {'range' | 'number'} The input type for the number.
189
- */
190
- setInputType(type) {
191
- this.inputType = type;
192
- return this;
193
- }
194
- /**
195
- * Set the maximum value for the number. If the user provides a number that is greater than this value, the validation will fail.
196
- * @param max {number} The maximum value for the number.
197
- */
198
- setMax(max) {
199
- this.max = max;
200
- return this;
201
- }
202
- /**
203
- * Set the default value for the number. This value will be used if the user does not provide a value. **HIGHLY RECOMMENDED**
204
- * @param defaultValue {number} The default value for the number.
205
- */
206
- setDefaultValue(defaultValue) {
207
- this.defaultValue = defaultValue;
208
- return this;
209
- }
210
- validate(input) {
211
- if (isNaN(Number(input))) {
212
- return [false, "Input is not a number"];
213
- }
214
- if (Number(input) < this.min || Number(input) > this.max) {
215
- return [
216
- false,
217
- "Input is not within the range of " + this.min + " and " + this.max
218
- ];
219
- }
220
- return [true, ""];
221
- }
222
- };
223
- var BooleanOption = class extends ConfigurationOption {
224
- type = "boolean";
225
- defaultValue = false;
226
- /**
227
- * Set the default value for the boolean. This value will be used if the user does not provide a value. **HIGHLY RECOMMENDED**
228
- * @param defaultValue {boolean} The default value for the boolean.
229
- */
230
- setDefaultValue(defaultValue) {
231
- this.defaultValue = defaultValue;
232
- return this;
233
- }
234
- validate(input) {
235
- if (typeof input !== "boolean") {
236
- return [false, "Input is not a boolean"];
237
- }
238
- return [true, ""];
239
- }
240
- };
241
-
242
- // src/config/Configuration.ts
243
- var Configuration = class {
244
- storedConfigTemplate;
245
- definiteConfig = {};
246
- constructor(configTemplate) {
247
- this.storedConfigTemplate = configTemplate;
248
- }
249
- updateConfig(config, validate = true) {
250
- this.definiteConfig = config;
251
- if (validate) {
252
- const result = this.validateConfig();
253
- return result;
254
- }
255
- return [true, {}];
256
- }
257
- // provides falsey or truthy value, and an error message if falsey
258
- validateConfig() {
259
- const erroredKeys = /* @__PURE__ */ new Map();
260
- for (const key in this.storedConfigTemplate) {
261
- if (this.definiteConfig[key] === null || this.definiteConfig[key] === void 0) {
262
- console.warn(
263
- "Option " + key + " is not defined. Using default value Value: " + this.storedConfigTemplate[key].defaultValue
264
- );
265
- this.definiteConfig[key] = this.storedConfigTemplate[key].defaultValue;
266
- }
267
- if (this.storedConfigTemplate[key].type !== typeof this.definiteConfig[key]) {
268
- throw new Error("Option " + key + " is not of the correct type");
269
- }
270
- const result = this.storedConfigTemplate[key].validate(
271
- this.definiteConfig[key]
272
- );
273
- if (!result[0]) {
274
- erroredKeys.set(key, result[1]);
275
- }
276
- }
277
- for (const key in this.definiteConfig) {
278
- if (this.storedConfigTemplate[key] === void 0) {
279
- delete this.definiteConfig[key];
280
- console.warn(
281
- "Option " + key + " is not defined in the configuration template. Removing from config."
282
- );
283
- }
284
- }
285
- if (erroredKeys.size > 0) {
286
- return [false, Object.fromEntries(erroredKeys)];
287
- }
288
- return [true, Object.fromEntries(erroredKeys)];
289
- }
290
- getStringValue(optionName) {
291
- if (!this.definiteConfig[optionName] === null) {
292
- throw new Error("Option " + optionName + " is not defined");
293
- }
294
- if (typeof this.definiteConfig[optionName] !== "string") {
295
- throw new Error("Option " + optionName + " is not a string");
296
- }
297
- return this.definiteConfig[optionName];
298
- }
299
- getNumberValue(optionName) {
300
- if (!this.definiteConfig[optionName] === null) {
301
- throw new Error("Option " + optionName + " is not defined");
302
- }
303
- if (typeof this.definiteConfig[optionName] !== "number") {
304
- throw new Error("Option " + optionName + " is not a number");
305
- }
306
- return this.definiteConfig[optionName];
307
- }
308
- getBooleanValue(optionName) {
309
- if (this.definiteConfig[optionName] === null) {
310
- throw new Error("Option " + optionName + " is not defined");
311
- }
312
- if (typeof this.definiteConfig[optionName] !== "boolean") {
313
- throw new Error("Option " + optionName + " is not a boolean");
314
- }
315
- return this.definiteConfig[optionName];
316
- }
317
- };
318
- export {
319
- BooleanOption,
320
- Configuration,
321
- ConfigurationBuilder,
322
- ConfigurationOption,
323
- NumberOption,
324
- StringOption,
325
- isBooleanOption,
326
- isNumberOption,
327
- isStringOption
328
- };
329
- //# sourceMappingURL=Configuration.js.map