ogi-addon 1.9.3 → 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 -387
  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 +4 -3
  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 -387
  57. package/build/main.js +0 -1045
  58. package/build/main.js.map +0 -1
@@ -0,0 +1,58 @@
1
+ //#region 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) promise();
16
+ }
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) {
22
+ this.resolved = true;
23
+ this.data = data;
24
+ }
25
+ /**
26
+ * 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.**
27
+ */
28
+ complete() {
29
+ this.resolved = true;
30
+ }
31
+ fail(message) {
32
+ this.resolved = true;
33
+ this.failed = message;
34
+ }
35
+ /**
36
+ * Logs a message to the event. This is useful for debugging and logging information to the user.
37
+ * @param message {string}
38
+ */
39
+ log(message) {
40
+ this.logs.push(message);
41
+ }
42
+ /**
43
+ * 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.
44
+ * @async
45
+ * @param name {string}
46
+ * @param description {string}
47
+ * @param screen {ConfigurationBuilder}
48
+ * @returns {Promise<{ [key: string]: boolean | string | number }>}
49
+ */
50
+ async askForInput(name, description, screen) {
51
+ if (!this.onInputAsked) throw new Error("No input asked callback");
52
+ return await this.onInputAsked(screen, name, description);
53
+ }
54
+ };
55
+
56
+ //#endregion
57
+ export { EventResponse as default };
58
+ //# sourceMappingURL=EventResponse.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EventResponse.mjs","names":[],"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;CACpC,OAAsB;CACtB,WAAoB;CACpB,WAAoB;CACpB,WAAmB;CACnB,OAAiB,EAAE;CACnB,SAA6B;CAC7B;CAMA,YACE,cAKA;AACA,OAAK,eAAe;;CAGtB,AAAO,MAAM,SAA+B;AAC1C,OAAK,WAAW;AAEhB,MAAI,QACF,UAAS;;;;;;CAQb,AAAO,QAAQ,MAAS;AACtB,OAAK,WAAW;AAChB,OAAK,OAAO;;;;;CAMd,AAAO,WAAW;AAChB,OAAK,WAAW;;CAGlB,AAAO,KAAK,SAAiB;AAC3B,OAAK,WAAW;AAChB,OAAK,SAAS;;;;;;CAOhB,AAAO,IAAI,SAAiB;AAC1B,OAAK,KAAK,KAAK,QAAQ;;;;;;;;;;CAWzB,MAAa,YACX,MACA,aACA,QACuD;AACvD,MAAI,CAAC,KAAK,aACR,OAAM,IAAI,MAAM,0BAA0B;AAE5C,SAAO,MAAM,KAAK,aAAa,QAAQ,MAAM,YAAY"}
@@ -0,0 +1,22 @@
1
+ //#region src/SearchEngine.d.ts
2
+ type BaseRequiredFields = {
3
+ name: string;
4
+ manifest?: Record<string, any>;
5
+ };
6
+ type SearchResult = BaseRequiredFields & ({
7
+ downloadType: 'torrent' | 'magnet';
8
+ filename: string;
9
+ downloadURL: string;
10
+ } | {
11
+ downloadType: 'direct';
12
+ files: {
13
+ name: string;
14
+ downloadURL: string;
15
+ headers?: Record<string, string>;
16
+ }[];
17
+ } | {
18
+ downloadType: 'request' | 'task' | 'empty';
19
+ });
20
+ //#endregion
21
+ export { SearchResult as t };
22
+ //# sourceMappingURL=SearchEngine-CRQWXfo6.d.mts.map
@@ -0,0 +1,22 @@
1
+ //#region src/SearchEngine.d.ts
2
+ type BaseRequiredFields = {
3
+ name: string;
4
+ manifest?: Record<string, any>;
5
+ };
6
+ type SearchResult = BaseRequiredFields & ({
7
+ downloadType: 'torrent' | 'magnet';
8
+ filename: string;
9
+ downloadURL: string;
10
+ } | {
11
+ downloadType: 'direct';
12
+ files: {
13
+ name: string;
14
+ downloadURL: string;
15
+ headers?: Record<string, string>;
16
+ }[];
17
+ } | {
18
+ downloadType: 'request' | 'task' | 'empty';
19
+ });
20
+ //#endregion
21
+ export { SearchResult as t };
22
+ //# sourceMappingURL=SearchEngine-DBSUNM4A.d.cts.map
@@ -1,19 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __copyProps = (to, from, except, desc) => {
7
- if (from && typeof from === "object" || typeof from === "function") {
8
- for (let key of __getOwnPropNames(from))
9
- if (!__hasOwnProp.call(to, key) && key !== except)
10
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
- }
12
- return to;
13
- };
14
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
-
16
- // src/SearchEngine.ts
17
- var SearchEngine_exports = {};
18
- module.exports = __toCommonJS(SearchEngine_exports);
19
- //# sourceMappingURL=SearchEngine.cjs.map
@@ -1,20 +1,2 @@
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
+ import { t as SearchResult } from "./SearchEngine-DBSUNM4A.cjs";
2
+ export { SearchResult };
@@ -0,0 +1,2 @@
1
+ import { t as SearchResult } from "./SearchEngine-CRQWXfo6.mjs";
2
+ export { SearchResult };
@@ -0,0 +1 @@
1
+ export { };
@@ -1,374 +1,60 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
-
30
- // src/config/Configuration.ts
31
- var Configuration_exports = {};
32
- __export(Configuration_exports, {
33
- BooleanOption: () => BooleanOption,
34
- Configuration: () => Configuration,
35
- ConfigurationBuilder: () => ConfigurationBuilder,
36
- ConfigurationOption: () => ConfigurationOption,
37
- NumberOption: () => NumberOption,
38
- StringOption: () => StringOption,
39
- isBooleanOption: () => isBooleanOption,
40
- isNumberOption: () => isNumberOption,
41
- isStringOption: () => isStringOption
42
- });
43
- module.exports = __toCommonJS(Configuration_exports);
44
-
45
- // src/config/ConfigurationBuilder.ts
46
- var import_zod = __toESM(require("zod"), 1);
47
- var configValidation = import_zod.default.object({
48
- name: import_zod.default.string().min(1),
49
- displayName: import_zod.default.string().min(1),
50
- description: import_zod.default.string().min(1)
51
- });
52
- function isStringOption(option) {
53
- return option.type === "string";
54
- }
55
- function isNumberOption(option) {
56
- return option.type === "number";
57
- }
58
- function isBooleanOption(option) {
59
- return option.type === "boolean";
60
- }
61
- var ConfigurationBuilder = class {
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
- */
68
- addNumberOption(option) {
69
- let newOption = new NumberOption();
70
- newOption = option(newOption);
71
- this.options.push(newOption);
72
- return this;
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
- */
78
- addStringOption(option) {
79
- let newOption = new StringOption();
80
- newOption = option(newOption);
81
- this.options.push(newOption);
82
- return this;
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
- */
88
- addBooleanOption(option) {
89
- let newOption = new BooleanOption();
90
- newOption = option(newOption);
91
- this.options.push(newOption);
92
- return this;
93
- }
94
- build(includeFunctions) {
95
- let config = {};
96
- this.options.forEach((option) => {
97
- if (!includeFunctions) {
98
- option = JSON.parse(JSON.stringify(option));
99
- const optionData = configValidation.safeParse(option);
100
- if (!optionData.success) {
101
- throw new import_zod.ZodError(optionData.error.errors);
102
- }
103
- config[option.name] = option;
104
- } else {
105
- config[option.name] = option;
106
- }
107
- });
108
- return config;
109
- }
110
- };
111
- var ConfigurationOption = class {
112
- name = "";
113
- defaultValue = "";
114
- displayName = "";
115
- description = "";
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
- */
121
- setName(name) {
122
- this.name = name;
123
- return this;
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
- */
130
- setDisplayName(displayName) {
131
- this.displayName = displayName;
132
- return this;
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
- */
139
- setDescription(description) {
140
- this.description = description;
141
- return this;
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
- */
147
- validate(input) {
148
- throw new Error("Validation code not implemented. Value: " + input);
149
- }
150
- };
151
- var StringOption = class extends ConfigurationOption {
152
- allowedValues = [];
153
- minTextLength = 0;
154
- maxTextLength = Number.MAX_SAFE_INTEGER;
155
- defaultValue = "";
156
- inputType = "text";
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
- */
162
- setAllowedValues(allowedValues) {
163
- this.allowedValues = allowedValues;
164
- return this;
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
- */
170
- setDefaultValue(defaultValue) {
171
- this.defaultValue = defaultValue;
172
- return this;
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
- */
178
- setMinTextLength(minTextLength) {
179
- this.minTextLength = minTextLength;
180
- return this;
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
- */
186
- setMaxTextLength(maxTextLength) {
187
- this.maxTextLength = maxTextLength;
188
- return this;
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
- */
194
- setInputType(inputType) {
195
- this.inputType = inputType;
196
- return this;
197
- }
198
- validate(input) {
199
- if (typeof input !== "string") {
200
- return [false, "Input is not a string"];
201
- }
202
- if (this.allowedValues.length === 0 && input.length !== 0)
203
- return [true, ""];
204
- if (input.length < this.minTextLength || input.length > this.maxTextLength) {
205
- return [
206
- false,
207
- "Input is not within the text length " + this.minTextLength + " and " + this.maxTextLength + " characters (currently " + input.length + " characters)"
208
- ];
209
- }
210
- return [
211
- this.allowedValues.includes(input),
212
- "Input is not an allowed value"
213
- ];
214
- }
215
- };
216
- var NumberOption = class extends ConfigurationOption {
217
- min = 0;
218
- max = Number.MAX_SAFE_INTEGER;
219
- defaultValue = 0;
220
- type = "number";
221
- inputType = "number";
222
- /**
223
- * Set the minimum value for the number. If the user provides a number that is less than this value, the validation will fail.
224
- * @param min {number} The minimum value for the number.
225
- */
226
- setMin(min) {
227
- this.min = min;
228
- return this;
229
- }
230
- /**
231
- * Set the input type for the number. This will change how the client renders the input.
232
- * @param type {'range' | 'number'} The input type for the number.
233
- */
234
- setInputType(type) {
235
- this.inputType = type;
236
- return this;
237
- }
238
- /**
239
- * Set the maximum value for the number. If the user provides a number that is greater than this value, the validation will fail.
240
- * @param max {number} The maximum value for the number.
241
- */
242
- setMax(max) {
243
- this.max = max;
244
- return this;
245
- }
246
- /**
247
- * Set the default value for the number. This value will be used if the user does not provide a value. **HIGHLY RECOMMENDED**
248
- * @param defaultValue {number} The default value for the number.
249
- */
250
- setDefaultValue(defaultValue) {
251
- this.defaultValue = defaultValue;
252
- return this;
253
- }
254
- validate(input) {
255
- if (isNaN(Number(input))) {
256
- return [false, "Input is not a number"];
257
- }
258
- if (Number(input) < this.min || Number(input) > this.max) {
259
- return [
260
- false,
261
- "Input is not within the range of " + this.min + " and " + this.max
262
- ];
263
- }
264
- return [true, ""];
265
- }
266
- };
267
- var BooleanOption = class extends ConfigurationOption {
268
- type = "boolean";
269
- defaultValue = false;
270
- /**
271
- * Set the default value for the boolean. This value will be used if the user does not provide a value. **HIGHLY RECOMMENDED**
272
- * @param defaultValue {boolean} The default value for the boolean.
273
- */
274
- setDefaultValue(defaultValue) {
275
- this.defaultValue = defaultValue;
276
- return this;
277
- }
278
- validate(input) {
279
- if (typeof input !== "boolean") {
280
- return [false, "Input is not a boolean"];
281
- }
282
- return [true, ""];
283
- }
284
- };
1
+ const require_ConfigurationBuilder = require('../ConfigurationBuilder-BSuJ4rSI.cjs');
285
2
 
286
- // src/config/Configuration.ts
3
+ //#region src/config/Configuration.ts
287
4
  var Configuration = class {
288
- storedConfigTemplate;
289
- definiteConfig = {};
290
- constructor(configTemplate) {
291
- this.storedConfigTemplate = configTemplate;
292
- }
293
- updateConfig(config, validate = true) {
294
- this.definiteConfig = config;
295
- if (validate) {
296
- const result = this.validateConfig();
297
- return result;
298
- }
299
- return [true, {}];
300
- }
301
- // provides falsey or truthy value, and an error message if falsey
302
- validateConfig() {
303
- const erroredKeys = /* @__PURE__ */ new Map();
304
- for (const key in this.storedConfigTemplate) {
305
- if (this.definiteConfig[key] === null || this.definiteConfig[key] === void 0) {
306
- console.warn(
307
- "Option " + key + " is not defined. Using default value Value: " + this.storedConfigTemplate[key].defaultValue
308
- );
309
- this.definiteConfig[key] = this.storedConfigTemplate[key].defaultValue;
310
- }
311
- if (this.storedConfigTemplate[key].type !== typeof this.definiteConfig[key]) {
312
- throw new Error("Option " + key + " is not of the correct type");
313
- }
314
- const result = this.storedConfigTemplate[key].validate(
315
- this.definiteConfig[key]
316
- );
317
- if (!result[0]) {
318
- erroredKeys.set(key, result[1]);
319
- }
320
- }
321
- for (const key in this.definiteConfig) {
322
- if (this.storedConfigTemplate[key] === void 0) {
323
- delete this.definiteConfig[key];
324
- console.warn(
325
- "Option " + key + " is not defined in the configuration template. Removing from config."
326
- );
327
- }
328
- }
329
- if (erroredKeys.size > 0) {
330
- return [false, Object.fromEntries(erroredKeys)];
331
- }
332
- return [true, Object.fromEntries(erroredKeys)];
333
- }
334
- getStringValue(optionName) {
335
- if (!this.definiteConfig[optionName] === null) {
336
- throw new Error("Option " + optionName + " is not defined");
337
- }
338
- if (typeof this.definiteConfig[optionName] !== "string") {
339
- throw new Error("Option " + optionName + " is not a string");
340
- }
341
- return this.definiteConfig[optionName];
342
- }
343
- getNumberValue(optionName) {
344
- if (!this.definiteConfig[optionName] === null) {
345
- throw new Error("Option " + optionName + " is not defined");
346
- }
347
- if (typeof this.definiteConfig[optionName] !== "number") {
348
- throw new Error("Option " + optionName + " is not a number");
349
- }
350
- return this.definiteConfig[optionName];
351
- }
352
- getBooleanValue(optionName) {
353
- if (this.definiteConfig[optionName] === null) {
354
- throw new Error("Option " + optionName + " is not defined");
355
- }
356
- if (typeof this.definiteConfig[optionName] !== "boolean") {
357
- throw new Error("Option " + optionName + " is not a boolean");
358
- }
359
- return this.definiteConfig[optionName];
360
- }
5
+ storedConfigTemplate;
6
+ definiteConfig = {};
7
+ constructor(configTemplate) {
8
+ this.storedConfigTemplate = configTemplate;
9
+ }
10
+ updateConfig(config, validate = true) {
11
+ this.definiteConfig = config;
12
+ if (validate) return this.validateConfig();
13
+ return [true, {}];
14
+ }
15
+ validateConfig() {
16
+ const erroredKeys = /* @__PURE__ */ new Map();
17
+ for (const key in this.storedConfigTemplate) {
18
+ if (this.definiteConfig[key] === null || this.definiteConfig[key] === void 0) {
19
+ console.warn("Option " + key + " is not defined. Using default value Value: " + this.storedConfigTemplate[key].defaultValue);
20
+ this.definiteConfig[key] = this.storedConfigTemplate[key].defaultValue;
21
+ }
22
+ if (this.storedConfigTemplate[key].type !== typeof this.definiteConfig[key]) throw new Error("Option " + key + " is not of the correct type");
23
+ const result = this.storedConfigTemplate[key].validate(this.definiteConfig[key]);
24
+ if (!result[0]) erroredKeys.set(key, result[1]);
25
+ }
26
+ for (const key in this.definiteConfig) if (this.storedConfigTemplate[key] === void 0) {
27
+ delete this.definiteConfig[key];
28
+ console.warn("Option " + key + " is not defined in the configuration template. Removing from config.");
29
+ }
30
+ if (erroredKeys.size > 0) return [false, Object.fromEntries(erroredKeys)];
31
+ return [true, Object.fromEntries(erroredKeys)];
32
+ }
33
+ getStringValue(optionName) {
34
+ if (this.definiteConfig[optionName] === null || this.definiteConfig[optionName] === void 0) throw new Error("Option " + optionName + " is not defined");
35
+ if (typeof this.definiteConfig[optionName] !== "string") throw new Error("Option " + optionName + " is not a string");
36
+ return this.definiteConfig[optionName];
37
+ }
38
+ getNumberValue(optionName) {
39
+ if (this.definiteConfig[optionName] === null || this.definiteConfig[optionName] === void 0) throw new Error("Option " + optionName + " is not defined");
40
+ if (typeof this.definiteConfig[optionName] !== "number") throw new Error("Option " + optionName + " is not a number");
41
+ return this.definiteConfig[optionName];
42
+ }
43
+ getBooleanValue(optionName) {
44
+ if (this.definiteConfig[optionName] === null || this.definiteConfig[optionName] === void 0) throw new Error("Option " + optionName + " is not defined");
45
+ if (typeof this.definiteConfig[optionName] !== "boolean") throw new Error("Option " + optionName + " is not a boolean");
46
+ return this.definiteConfig[optionName];
47
+ }
361
48
  };
362
- // Annotate the CommonJS export names for ESM import in node:
363
- 0 && (module.exports = {
364
- BooleanOption,
365
- Configuration,
366
- ConfigurationBuilder,
367
- ConfigurationOption,
368
- NumberOption,
369
- StringOption,
370
- isBooleanOption,
371
- isNumberOption,
372
- isStringOption
373
- });
49
+
50
+ //#endregion
51
+ exports.BooleanOption = require_ConfigurationBuilder.BooleanOption;
52
+ exports.Configuration = Configuration;
53
+ exports.ConfigurationBuilder = require_ConfigurationBuilder.ConfigurationBuilder;
54
+ exports.ConfigurationOption = require_ConfigurationBuilder.ConfigurationOption;
55
+ exports.NumberOption = require_ConfigurationBuilder.NumberOption;
56
+ exports.StringOption = require_ConfigurationBuilder.StringOption;
57
+ exports.isBooleanOption = require_ConfigurationBuilder.isBooleanOption;
58
+ exports.isNumberOption = require_ConfigurationBuilder.isNumberOption;
59
+ exports.isStringOption = require_ConfigurationBuilder.isStringOption;
374
60
  //# sourceMappingURL=Configuration.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/config/Configuration.ts","../../src/config/ConfigurationBuilder.ts"],"sourcesContent":["import {\n ConfigurationFile,\n ConfigurationBuilder,\n BooleanOption,\n ConfigurationOption,\n ConfigurationOptionType,\n NumberOption,\n StringOption,\n isBooleanOption,\n isNumberOption,\n isStringOption,\n} from './ConfigurationBuilder';\n\ninterface DefiniteConfig {\n [key: string]: string | number | boolean;\n}\nexport class Configuration {\n readonly storedConfigTemplate: ConfigurationFile;\n definiteConfig: DefiniteConfig = {};\n constructor(configTemplate: ConfigurationFile) {\n this.storedConfigTemplate = configTemplate;\n }\n\n updateConfig(\n config: DefiniteConfig,\n validate: boolean = true\n ): [boolean, { [key: string]: string }] {\n this.definiteConfig = config;\n if (validate) {\n const result = this.validateConfig();\n return result;\n }\n return [true, {}];\n }\n // provides falsey or truthy value, and an error message if falsey\n private validateConfig(): [boolean, { [key: string]: string }] {\n const erroredKeys = new Map<string, string>();\n for (const key in this.storedConfigTemplate) {\n if (\n this.definiteConfig[key] === null ||\n this.definiteConfig[key] === undefined\n ) {\n console.warn(\n 'Option ' +\n key +\n ' is not defined. Using default value Value: ' +\n this.storedConfigTemplate[key].defaultValue\n );\n this.definiteConfig[key] = this.storedConfigTemplate[key]\n .defaultValue as string | number | boolean;\n }\n if (\n this.storedConfigTemplate[key].type !== typeof this.definiteConfig[key]\n ) {\n throw new Error('Option ' + key + ' is not of the correct type');\n }\n\n const result = this.storedConfigTemplate[key].validate(\n this.definiteConfig[key]\n );\n if (!result[0]) {\n erroredKeys.set(key, result[1]);\n }\n }\n\n for (const key in this.definiteConfig) {\n if (this.storedConfigTemplate[key] === undefined) {\n // remove the key from the definite config\n delete this.definiteConfig[key];\n console.warn(\n 'Option ' +\n key +\n ' is not defined in the configuration template. Removing from config.'\n );\n }\n }\n\n if (erroredKeys.size > 0) {\n return [false, Object.fromEntries(erroredKeys)];\n }\n\n return [true, Object.fromEntries(erroredKeys)];\n }\n\n getStringValue(optionName: string): string {\n if (!this.definiteConfig[optionName] === null) {\n throw new Error('Option ' + optionName + ' is not defined');\n }\n if (typeof this.definiteConfig[optionName] !== 'string') {\n throw new Error('Option ' + optionName + ' is not a string');\n }\n return this.definiteConfig[optionName];\n }\n\n getNumberValue(optionName: string): number {\n if (!this.definiteConfig[optionName] === null) {\n throw new Error('Option ' + optionName + ' is not defined');\n }\n if (typeof this.definiteConfig[optionName] !== 'number') {\n throw new Error('Option ' + optionName + ' is not a number');\n }\n return this.definiteConfig[optionName];\n }\n\n getBooleanValue(optionName: string): boolean {\n if (this.definiteConfig[optionName] === null) {\n throw new Error('Option ' + optionName + ' is not defined');\n }\n if (typeof this.definiteConfig[optionName] !== 'boolean') {\n throw new Error('Option ' + optionName + ' is not a boolean');\n }\n return this.definiteConfig[optionName];\n }\n}\n\nexport {\n ConfigurationFile,\n ConfigurationBuilder,\n BooleanOption,\n ConfigurationOption,\n ConfigurationOptionType,\n NumberOption,\n StringOption,\n isBooleanOption,\n isNumberOption,\n isStringOption,\n};\n","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(\n option: ConfigurationOption\n): option is StringOption {\n return option.type === 'string';\n}\n\nexport function isNumberOption(\n option: ConfigurationOption\n): option is NumberOption {\n return option.type === 'number';\n}\n\nexport function isBooleanOption(\n option: ConfigurationOption\n): 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(\n option: (option: NumberOption) => NumberOption\n ): 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 } 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 (\n input.length < this.minTextLength ||\n input.length > this.maxTextLength\n ) {\n return [\n false,\n 'Input is not within the text length ' +\n this.minTextLength +\n ' and ' +\n this.maxTextLength +\n ' characters (currently ' +\n input.length +\n ' characters)',\n ];\n }\n\n return [\n this.allowedValues.includes(input),\n 'Input is not an allowed value',\n ];\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 [\n false,\n 'Input is not within the range of ' + this.min + ' and ' + this.max,\n ];\n }\n return [true, ''];\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;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,eACd,QACwB;AACxB,SAAO,OAAO,SAAS;AACzB;AAEO,SAAS,eACd,QACwB;AACxB,SAAO,OAAO,SAAS;AACzB;AAEO,SAAS,gBACd,QACyB;AACzB,SAAO,OAAO,SAAS;AACzB;AAEO,IAAM,uBAAN,MAA2B;AAAA,EACxB,UAAiC,CAAC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOnC,gBACL,QACsB;AACtB,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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A6B;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,"file":"Configuration.cjs","names":[],"sources":["../../src/config/Configuration.ts"],"sourcesContent":["import {\n ConfigurationBuilder,\n BooleanOption,\n ConfigurationOption,\n NumberOption,\n StringOption,\n isBooleanOption,\n isNumberOption,\n isStringOption,\n} from './ConfigurationBuilder';\nimport type {\n ConfigurationFile,\n ConfigurationOptionType,\n} from './ConfigurationBuilder';\n\ninterface DefiniteConfig {\n [key: string]: string | number | boolean;\n}\nexport class Configuration {\n readonly storedConfigTemplate: ConfigurationFile;\n definiteConfig: DefiniteConfig = {};\n constructor(configTemplate: ConfigurationFile) {\n this.storedConfigTemplate = configTemplate;\n }\n\n updateConfig(\n config: DefiniteConfig,\n validate: boolean = true\n ): [boolean, { [key: string]: string }] {\n this.definiteConfig = config;\n if (validate) {\n const result = this.validateConfig();\n return result;\n }\n return [true, {}];\n }\n // provides falsey or truthy value, and an error message if falsey\n private validateConfig(): [boolean, { [key: string]: string }] {\n const erroredKeys = new Map<string, string>();\n for (const key in this.storedConfigTemplate) {\n if (\n this.definiteConfig[key] === null ||\n this.definiteConfig[key] === undefined\n ) {\n console.warn(\n 'Option ' +\n key +\n ' is not defined. Using default value Value: ' +\n this.storedConfigTemplate[key].defaultValue\n );\n this.definiteConfig[key] = this.storedConfigTemplate[key]\n .defaultValue as string | number | boolean;\n }\n if (\n this.storedConfigTemplate[key].type !== typeof this.definiteConfig[key]\n ) {\n throw new Error('Option ' + key + ' is not of the correct type');\n }\n\n const result = this.storedConfigTemplate[key].validate(\n this.definiteConfig[key]\n );\n if (!result[0]) {\n erroredKeys.set(key, result[1]);\n }\n }\n\n for (const key in this.definiteConfig) {\n if (this.storedConfigTemplate[key] === undefined) {\n // remove the key from the definite config\n delete this.definiteConfig[key];\n console.warn(\n 'Option ' +\n key +\n ' is not defined in the configuration template. Removing from config.'\n );\n }\n }\n\n if (erroredKeys.size > 0) {\n return [false, Object.fromEntries(erroredKeys)];\n }\n\n return [true, Object.fromEntries(erroredKeys)];\n }\n\n getStringValue(optionName: string): string {\n if (\n this.definiteConfig[optionName] === null ||\n this.definiteConfig[optionName] === undefined\n ) {\n throw new Error('Option ' + optionName + ' is not defined');\n }\n if (typeof this.definiteConfig[optionName] !== 'string') {\n throw new Error('Option ' + optionName + ' is not a string');\n }\n return this.definiteConfig[optionName];\n }\n\n getNumberValue(optionName: string): number {\n if (\n this.definiteConfig[optionName] === null ||\n this.definiteConfig[optionName] === undefined\n ) {\n throw new Error('Option ' + optionName + ' is not defined');\n }\n if (typeof this.definiteConfig[optionName] !== 'number') {\n throw new Error('Option ' + optionName + ' is not a number');\n }\n return this.definiteConfig[optionName];\n }\n\n getBooleanValue(optionName: string): boolean {\n if (\n this.definiteConfig[optionName] === null ||\n this.definiteConfig[optionName] === undefined\n ) {\n throw new Error('Option ' + optionName + ' is not defined');\n }\n if (typeof this.definiteConfig[optionName] !== 'boolean') {\n throw new Error('Option ' + optionName + ' is not a boolean');\n }\n return this.definiteConfig[optionName];\n }\n}\n\nexport {\n ConfigurationBuilder,\n BooleanOption,\n ConfigurationOption,\n NumberOption,\n StringOption,\n isBooleanOption,\n isNumberOption,\n isStringOption,\n};\n\nexport type { ConfigurationFile, ConfigurationOptionType };\n"],"mappings":";;;AAkBA,IAAa,gBAAb,MAA2B;CACzB,AAAS;CACT,iBAAiC,EAAE;CACnC,YAAY,gBAAmC;AAC7C,OAAK,uBAAuB;;CAG9B,aACE,QACA,WAAoB,MACkB;AACtC,OAAK,iBAAiB;AACtB,MAAI,SAEF,QADe,KAAK,gBAAgB;AAGtC,SAAO,CAAC,MAA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