kfg 0.0.1 → 1.0.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/LICENSE +21 -0
- package/README.md +112 -7
- package/dist/index.cjs +1126 -0
- package/dist/index.d.ts +579 -0
- package/dist/index.js +1078 -0
- package/package.json +71 -6
- package/index.ts +0 -1
- package/tsconfig.json +0 -29
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,579 @@
|
|
|
1
|
+
// Generated by dts-bundle-generator v9.5.1
|
|
2
|
+
|
|
3
|
+
import { ArrayOptions, NumberOptions, ObjectOptions, SchemaOptions, Static, StringOptions, TLiteral, TObject, TProperties, TSchema, TUnion, TUnsafe } from '@sinclair/typebox';
|
|
4
|
+
|
|
5
|
+
declare function buildDefaultObject(definition: SchemaDefinition): Record<string, any>;
|
|
6
|
+
declare function deepMerge<T extends object, U extends object>(target: T, source: U): T & U;
|
|
7
|
+
/**
|
|
8
|
+
* The main class for Kfg. It is responsible for loading and managing the configuration.
|
|
9
|
+
* @template D The type of the driver.
|
|
10
|
+
* @template S The type of the schema.
|
|
11
|
+
*/
|
|
12
|
+
export declare class Kfg<D extends KfgDriver<any, any, any>, S extends SchemaDefinition> {
|
|
13
|
+
driver: D;
|
|
14
|
+
schema: S;
|
|
15
|
+
private loaded;
|
|
16
|
+
/**
|
|
17
|
+
* Creates a new instance of Kfg.
|
|
18
|
+
* @param driver The driver to use for loading and saving the configuration.
|
|
19
|
+
* @param schema The schema to use for validating the configuration.
|
|
20
|
+
*/
|
|
21
|
+
constructor(driver: D, schema: S);
|
|
22
|
+
/**
|
|
23
|
+
* Loads the configuration.
|
|
24
|
+
* @param options - The loading options.
|
|
25
|
+
*/
|
|
26
|
+
load(options?: Partial<D["config"]> & {
|
|
27
|
+
/**
|
|
28
|
+
* If true, all schema properties will be treated as optional during validation,
|
|
29
|
+
* except for those marked as `important: true`. This is useful for loading a
|
|
30
|
+
* partial configuration without triggering validation errors for missing values.
|
|
31
|
+
*/
|
|
32
|
+
only_importants?: boolean;
|
|
33
|
+
}): inPromise<D["async"], void>;
|
|
34
|
+
/**
|
|
35
|
+
* Gets a value from the configuration.
|
|
36
|
+
* @param path The path to the value.
|
|
37
|
+
* @returns The value at the given path.
|
|
38
|
+
*/
|
|
39
|
+
get<P extends Paths<StaticSchema<S>>>(path: P): inPromise<D["async"], DeepGet<StaticSchema<S>, P>>;
|
|
40
|
+
/**
|
|
41
|
+
* Checks if a value exists in the configuration.
|
|
42
|
+
* @param paths The paths to the values.
|
|
43
|
+
* @returns True if all values exist, false otherwise.
|
|
44
|
+
*/
|
|
45
|
+
has<P extends Paths<StaticSchema<S>>>(...paths: P[]): inPromise<D["async"], boolean>;
|
|
46
|
+
/**
|
|
47
|
+
* Gets a value from the configuration.
|
|
48
|
+
* @param path The path to the value.
|
|
49
|
+
* @returns The value at the given path.
|
|
50
|
+
*/
|
|
51
|
+
root<P extends RootPaths<StaticSchema<S>>>(path: P): inPromise<D["async"], DeepGet<StaticSchema<S>, P>>;
|
|
52
|
+
/**
|
|
53
|
+
* Sets a value in the configuration.
|
|
54
|
+
* @param path The path to the value.
|
|
55
|
+
* @param value The new value.
|
|
56
|
+
* @param options The options for setting the value.
|
|
57
|
+
*/
|
|
58
|
+
set<P extends Paths<StaticSchema<S>>>(path: P, value: DeepGet<StaticSchema<S>, P>, options?: {
|
|
59
|
+
description?: string;
|
|
60
|
+
}): inPromise<D["async"], void>;
|
|
61
|
+
/**
|
|
62
|
+
* Inserts a partial value into an object in the configuration.
|
|
63
|
+
* @param path The path to the object.
|
|
64
|
+
* @param partial The partial value to insert.
|
|
65
|
+
*/
|
|
66
|
+
insert<P extends RootPaths<StaticSchema<S>>>(path: P, partial: Partial<DeepGet<StaticSchema<S>, P>>): inPromise<D["async"], void>;
|
|
67
|
+
/**
|
|
68
|
+
* Deletes a value from the configuration.
|
|
69
|
+
* @param path The path to the value.
|
|
70
|
+
*/
|
|
71
|
+
del<P extends Paths<StaticSchema<S>>>(path: P): inPromise<D["async"], void>;
|
|
72
|
+
/**
|
|
73
|
+
* Gets the schema for a given path.
|
|
74
|
+
* @param path The path to the schema.
|
|
75
|
+
* @returns The schema at the given path.
|
|
76
|
+
*/
|
|
77
|
+
conf<P extends Paths<StaticSchema<S>>>(path: P): DeepGet<S, P>;
|
|
78
|
+
/**
|
|
79
|
+
* Returns cached data
|
|
80
|
+
* @returns
|
|
81
|
+
*/
|
|
82
|
+
toJSON(): Promise<inPromise<D["async"], StaticSchema<S>>>;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* The base class for all drivers.
|
|
86
|
+
* @template C The type of the driver configuration.
|
|
87
|
+
* @template S The type of the driver store.
|
|
88
|
+
* @template Async The type of the async flag.
|
|
89
|
+
*/
|
|
90
|
+
export declare class KfgDriver<C extends DriverConfig, S extends DriverStore, Async extends boolean> {
|
|
91
|
+
readonly options: KfgDriverOptions<C, S, Async>;
|
|
92
|
+
readonly identify: string;
|
|
93
|
+
async: Async;
|
|
94
|
+
config: C;
|
|
95
|
+
data: Record<string, any>;
|
|
96
|
+
comments?: Record<string, string>;
|
|
97
|
+
private compiledSchema?;
|
|
98
|
+
protected store: S;
|
|
99
|
+
_onLoad?(schema: SchemaDefinition, opts: Partial<C>): inPromise<Async, any>;
|
|
100
|
+
private _onSet?;
|
|
101
|
+
private _onDel?;
|
|
102
|
+
protected buildDefaultObject: typeof buildDefaultObject;
|
|
103
|
+
protected deepMerge: typeof deepMerge;
|
|
104
|
+
/**
|
|
105
|
+
* Creates a new instance of KfgDriver.
|
|
106
|
+
* @param options The driver options.
|
|
107
|
+
*/
|
|
108
|
+
constructor(options: KfgDriverOptions<C, S, Async>);
|
|
109
|
+
/**
|
|
110
|
+
* Loads the configuration.
|
|
111
|
+
* @param schema The schema to use for validating the configuration.
|
|
112
|
+
* @param options The loading options.
|
|
113
|
+
*/
|
|
114
|
+
load(schema: SchemaDefinition, options?: Partial<C>): inPromise<Async, void>;
|
|
115
|
+
/**
|
|
116
|
+
* Gets a value from the configuration.
|
|
117
|
+
* @param path The path to the value.
|
|
118
|
+
* @returns The value at the given path.
|
|
119
|
+
*/
|
|
120
|
+
get<T = StaticSchema<any>, P extends Paths<T> = any>(path: P): inPromise<Async, DeepGet<T, P>>;
|
|
121
|
+
/**
|
|
122
|
+
* Checks if a value exists in the configuration.
|
|
123
|
+
* @param paths The paths to the values.
|
|
124
|
+
* @returns True if all values exist, false otherwise.
|
|
125
|
+
*/
|
|
126
|
+
has<T = StaticSchema<any>, P extends Paths<T> = any>(...paths: P[]): inPromise<Async, boolean>;
|
|
127
|
+
/**
|
|
128
|
+
* Sets a value in the configuration.
|
|
129
|
+
* @param path The path to the value.
|
|
130
|
+
* @param value The new value.
|
|
131
|
+
* @param options The options for setting the value.
|
|
132
|
+
*/
|
|
133
|
+
set<T = StaticSchema<any>, P extends Paths<T> = any>(path: P, value: DeepGet<T, P>, options?: {
|
|
134
|
+
description?: string;
|
|
135
|
+
}): inPromise<Async, void>;
|
|
136
|
+
/**
|
|
137
|
+
* Inserts a partial value into an object in the configuration.
|
|
138
|
+
* @param path The path to the object.
|
|
139
|
+
* @param partial The partial value to insert.
|
|
140
|
+
*/
|
|
141
|
+
insert<T = StaticSchema<any>, P extends RootPaths<T> = any>(path: P, partial: Partial<DeepGet<T, P>>): inPromise<Async, void>;
|
|
142
|
+
/**
|
|
143
|
+
* Deletes a value from the configuration.
|
|
144
|
+
* @param path The path to the value.
|
|
145
|
+
*/
|
|
146
|
+
del<T = StaticSchema<any>, P extends Paths<T> = any>(path: P): inPromise<Async, void>;
|
|
147
|
+
/**
|
|
148
|
+
* Validates the configuration against the schema.
|
|
149
|
+
* @param config The configuration to validate.
|
|
150
|
+
*/
|
|
151
|
+
private validate;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* A class for managing multiple configuration files.
|
|
155
|
+
* @template D The type of the driver.
|
|
156
|
+
* @template S The type of the schema.
|
|
157
|
+
*/
|
|
158
|
+
export declare class KfgFS<D extends KfgDriver<any, any, any>, S extends SchemaDefinition> {
|
|
159
|
+
driver: D;
|
|
160
|
+
schema: S;
|
|
161
|
+
config?: (Partial<D["config"]> & {
|
|
162
|
+
/**
|
|
163
|
+
* If true, all schema properties will be treated as optional during validation,
|
|
164
|
+
* except for those marked as `important: true`. This is useful for loading a
|
|
165
|
+
* partial configuration without triggering validation errors for missing values.
|
|
166
|
+
*/
|
|
167
|
+
only_importants?: boolean;
|
|
168
|
+
}) | undefined;
|
|
169
|
+
private pathFn?;
|
|
170
|
+
/**
|
|
171
|
+
* Creates a new instance of KfgFS.
|
|
172
|
+
* @param driver The driver to use for loading and saving the configurations.
|
|
173
|
+
* @param schema The schema to use for validating the configurations.
|
|
174
|
+
* @param config The configuration options.
|
|
175
|
+
*/
|
|
176
|
+
constructor(driver: D, schema: S, config?: (Partial<D["config"]> & {
|
|
177
|
+
/**
|
|
178
|
+
* If true, all schema properties will be treated as optional during validation,
|
|
179
|
+
* except for those marked as `important: true`. This is useful for loading a
|
|
180
|
+
* partial configuration without triggering validation errors for missing values.
|
|
181
|
+
*/
|
|
182
|
+
only_importants?: boolean;
|
|
183
|
+
}) | undefined);
|
|
184
|
+
/**
|
|
185
|
+
* Initializes the KfgFS instance with a path function.
|
|
186
|
+
* @param pathFn A function that returns the file path for a given ID.
|
|
187
|
+
*/
|
|
188
|
+
init(pathFn: (id: string) => string): void;
|
|
189
|
+
/**
|
|
190
|
+
* Gets the file path for a given ID.
|
|
191
|
+
* @param id The ID of the configuration file.
|
|
192
|
+
* @returns The file path.
|
|
193
|
+
*/
|
|
194
|
+
private getPath;
|
|
195
|
+
/**
|
|
196
|
+
* Gets a file-based configuration for a given ID.
|
|
197
|
+
* @param id The ID of the configuration file.
|
|
198
|
+
* @returns A KfgFileFS instance.
|
|
199
|
+
*/
|
|
200
|
+
file(id: string): inPromise<D["async"], KfgFileFS<D, S>>;
|
|
201
|
+
/**
|
|
202
|
+
* Deletes a configuration file.
|
|
203
|
+
* @param id The ID of the configuration file.
|
|
204
|
+
*/
|
|
205
|
+
del(id: string): void;
|
|
206
|
+
/**
|
|
207
|
+
* Copies a configuration file.
|
|
208
|
+
* @param fromId The ID of the source configuration file.
|
|
209
|
+
* @param toId The ID of the destination configuration file.
|
|
210
|
+
*/
|
|
211
|
+
copy(fromId: string, toId: string): void;
|
|
212
|
+
/**
|
|
213
|
+
* Gets the configuration data for a given ID.
|
|
214
|
+
* @param id The ID of the configuration file.
|
|
215
|
+
* @returns The configuration data.
|
|
216
|
+
*/
|
|
217
|
+
toJSON(id: string): inPromise<D["async"], StaticSchema<S>>;
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Represents a file-based configuration that extends the base Kfg class.
|
|
221
|
+
* It is used to manage a single configuration file.
|
|
222
|
+
* @template D The type of the driver.
|
|
223
|
+
* @template S The type of the schema.
|
|
224
|
+
*/
|
|
225
|
+
export declare class KfgFileFS<D extends KfgDriver<any, any, any>, S extends SchemaDefinition> extends Kfg<D, S> {
|
|
226
|
+
readonly filePath: string;
|
|
227
|
+
/**
|
|
228
|
+
* Creates a new instance of KfgFileFS.
|
|
229
|
+
* @param driver The driver to use for loading and saving the configuration.
|
|
230
|
+
* @param schema The schema to use for validating the configuration.
|
|
231
|
+
* @param filePath The path to the configuration file.
|
|
232
|
+
*/
|
|
233
|
+
constructor(driver: D, schema: S, filePath: string);
|
|
234
|
+
/**
|
|
235
|
+
* Loads the configuration from the file.
|
|
236
|
+
* @param options The loading options.
|
|
237
|
+
*/
|
|
238
|
+
load(options?: D["config"] & {
|
|
239
|
+
only_importants?: boolean;
|
|
240
|
+
}): inPromise<D["async"], void>;
|
|
241
|
+
/**
|
|
242
|
+
* Sets a value in the configuration.
|
|
243
|
+
* @param path The path to the value.
|
|
244
|
+
* @param value The new value.
|
|
245
|
+
* @param options The options for setting the value.
|
|
246
|
+
*/
|
|
247
|
+
set<P extends Paths<StaticSchema<S>>>(path: P, value: StaticSchemaWithRelation<DeepGet<StaticSchema<S>, P>>, options?: {
|
|
248
|
+
description?: string;
|
|
249
|
+
}): inPromise<D["async"], void>;
|
|
250
|
+
/**
|
|
251
|
+
* Inserts a partial value into an object in the configuration.
|
|
252
|
+
* @param path The path to the object.
|
|
253
|
+
* @param partial The partial value to insert.
|
|
254
|
+
*/
|
|
255
|
+
insert<P extends Paths<StaticSchema<S>>>(path: P, value: Partial<StaticSchemaWithRelation<DeepGet<StaticSchema<S>, P>>>): inPromise<D["async"], void>;
|
|
256
|
+
/**
|
|
257
|
+
* Gets a value from the configuration.
|
|
258
|
+
* @param path The path to the value.
|
|
259
|
+
* @returns The value at the given path.
|
|
260
|
+
*/
|
|
261
|
+
root<P extends Paths<StaticSchema<S>>>(path: P): inPromise<D["async"], StaticSchemaWithRelation<DeepGet<StaticSchema<S>, P>>>;
|
|
262
|
+
/**
|
|
263
|
+
* Checks if a value exists in the configuration.
|
|
264
|
+
* @param paths The paths to the values.
|
|
265
|
+
* @returns True if all values exist, false otherwise.
|
|
266
|
+
*/
|
|
267
|
+
has<P extends Paths<StaticSchema<S>>>(...paths: P[]): inPromise<D["async"], boolean>;
|
|
268
|
+
/**
|
|
269
|
+
* Gets the schema for a given path.
|
|
270
|
+
* @param path The path to the schema.
|
|
271
|
+
* @returns The schema at the given path.
|
|
272
|
+
*/
|
|
273
|
+
conf<P extends Paths<StaticSchema<S>>>(path: P): DeepGet<S, P>;
|
|
274
|
+
/**
|
|
275
|
+
* Returns cached data
|
|
276
|
+
* @returns
|
|
277
|
+
*/
|
|
278
|
+
toJSON(): inPromise<D["async"], StaticSchemaWithRelation<StaticSchema<S>>>;
|
|
279
|
+
/**
|
|
280
|
+
* Saves the configuration to the file.
|
|
281
|
+
*/
|
|
282
|
+
save(): inPromise<D["async"], void>;
|
|
283
|
+
/**
|
|
284
|
+
* Gets the related configurations for a many-to-many relation.
|
|
285
|
+
* @param path The path to the relation.
|
|
286
|
+
* @returns An array of related configurations.
|
|
287
|
+
*/
|
|
288
|
+
getMany<P extends RelationPaths<S>>(path: P): inPromise<D["async"], DeepGet<StaticSchema<S>, P> | undefined>;
|
|
289
|
+
/**
|
|
290
|
+
* Gets the related configuration for a one-to-one relation.
|
|
291
|
+
* @param path The path to the relation.
|
|
292
|
+
* @returns The related configuration.
|
|
293
|
+
*/
|
|
294
|
+
getJoin<P extends RelationPaths<S>>(path: P): inPromise<D["async"], KfgFileFS<any, any> | undefined>;
|
|
295
|
+
/**
|
|
296
|
+
* Returns the file path of the configuration.
|
|
297
|
+
*/
|
|
298
|
+
toString(): string;
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* @deprecated Use KfgFS instead.
|
|
302
|
+
*/
|
|
303
|
+
export declare const ConfigFS: typeof KfgFS;
|
|
304
|
+
/**
|
|
305
|
+
* @deprecated Use Kfg instead.
|
|
306
|
+
*/
|
|
307
|
+
export declare const ConfigJS: typeof Kfg;
|
|
308
|
+
/**
|
|
309
|
+
* @deprecated Use KfgDriver instead.
|
|
310
|
+
*/
|
|
311
|
+
export declare const ConfigJSDriver: typeof KfgDriver;
|
|
312
|
+
/**
|
|
313
|
+
* @deprecated Use KfgFileFS instead.
|
|
314
|
+
*/
|
|
315
|
+
export declare const FileFSConfigJS: typeof KfgFileFS;
|
|
316
|
+
/**
|
|
317
|
+
* A symbol used to identify a one-to-one relation in a schema.
|
|
318
|
+
*/
|
|
319
|
+
export declare const KFS_JOIN_SYMBOL: unique symbol;
|
|
320
|
+
/**
|
|
321
|
+
* A symbol used to identify a many-to-many relation in a schema.
|
|
322
|
+
*/
|
|
323
|
+
export declare const KFS_MANY_SYMBOL: unique symbol;
|
|
324
|
+
/**
|
|
325
|
+
* A helper object for creating schema definitions with custom metadata.
|
|
326
|
+
* Includes both PascalCase and camelCase versions of helpers.
|
|
327
|
+
*/
|
|
328
|
+
export declare const c: {
|
|
329
|
+
string: <TDefault extends string>(options?: StringOptions & CustomOptions<TDefault>) => import("@sinclair/typebox").TString;
|
|
330
|
+
number: <TDefault extends number>(options?: NumberOptions & CustomOptions<TDefault>) => import("@sinclair/typebox").TNumber;
|
|
331
|
+
boolean: <TDefault extends boolean>(options?: Omit<SchemaOptions, "default"> & CustomOptions<TDefault>) => import("@sinclair/typebox").TBoolean;
|
|
332
|
+
object: <Properties extends TProperties, TDefault extends Record<string, any>>(properties: Properties, options?: ObjectOptions & CustomOptions<TDefault>) => import("@sinclair/typebox").TObject<Properties>;
|
|
333
|
+
array: <Schema extends TSchema, TDefault extends any[]>(items: Schema, options?: ArrayOptions & CustomOptions<TDefault>) => import("@sinclair/typebox").TArray<Schema>;
|
|
334
|
+
record: <K extends TSchema, V extends TSchema, TDefault extends Record<string, any>>(key: K, value: V, options?: Omit<SchemaOptions, "default"> & CustomOptions<TDefault>) => import("@sinclair/typebox").TRecordOrObject<K, V>;
|
|
335
|
+
enum: <T extends readonly (string | number)[] | object, TValues = T extends readonly (infer U)[] ? U : T extends object ? T[keyof T] : never>(values: T, options?: CustomOptions<TValues> & Omit<SchemaOptions, "default">) => TUnion<TLiteral<TValues>[]>;
|
|
336
|
+
ip: <TDefault extends string>(options?: StringOptions & CustomOptions<TDefault>) => import("@sinclair/typebox").TString;
|
|
337
|
+
ipv6: <TDefault extends string>(options?: StringOptions & CustomOptions<TDefault>) => import("@sinclair/typebox").TString;
|
|
338
|
+
email: <TDefault extends string>(options?: StringOptions & CustomOptions<TDefault>) => import("@sinclair/typebox").TString;
|
|
339
|
+
url: <TDefault extends string>(options?: StringOptions & CustomOptions<TDefault>) => import("@sinclair/typebox").TString;
|
|
340
|
+
any: () => import("@sinclair/typebox").TAny;
|
|
341
|
+
optional: <Schema extends TSchema>(schema: Schema) => Schema extends import("@sinclair/typebox").TOptional<infer S extends TSchema> ? import("@sinclair/typebox").TOptional<S> : import("@sinclair/typebox").Ensure<import("@sinclair/typebox").TOptional<Schema>>;
|
|
342
|
+
random: (options?: NumberOptions & {
|
|
343
|
+
max?: number;
|
|
344
|
+
}) => import("@sinclair/typebox").TNumber;
|
|
345
|
+
/** Creates a String schema. */
|
|
346
|
+
String: <TDefault extends string>(options?: StringOptions & CustomOptions<TDefault>) => import("@sinclair/typebox").TString;
|
|
347
|
+
/** Creates a Number schema. */
|
|
348
|
+
Number: <TDefault extends number>(options?: NumberOptions & CustomOptions<TDefault>) => import("@sinclair/typebox").TNumber;
|
|
349
|
+
/** Creates a Boolean schema. */
|
|
350
|
+
Boolean: <TDefault extends boolean>(options?: Omit<SchemaOptions, "default"> & CustomOptions<TDefault>) => import("@sinclair/typebox").TBoolean;
|
|
351
|
+
/** Creates an Object schema. */
|
|
352
|
+
Object: <Properties extends TProperties, TDefault extends Record<string, any>>(properties: Properties, options?: ObjectOptions & CustomOptions<TDefault>) => import("@sinclair/typebox").TObject<Properties>;
|
|
353
|
+
/** Creates an Array schema. */
|
|
354
|
+
Array: <Schema extends TSchema, TDefault extends any[]>(items: Schema, options?: ArrayOptions & CustomOptions<TDefault>) => import("@sinclair/typebox").TArray<Schema>;
|
|
355
|
+
/** Creates a Record schema. */
|
|
356
|
+
Record: <K extends TSchema, V extends TSchema, TDefault extends Record<string, any>>(key: K, value: V, options?: Omit<SchemaOptions, "default"> & CustomOptions<TDefault>) => import("@sinclair/typebox").TRecordOrObject<K, V>;
|
|
357
|
+
/** Creates a Union of Literals from a string array, const array, or a TypeScript enum. */
|
|
358
|
+
Enum: <T extends readonly (string | number)[] | object, TValues = T extends readonly (infer U)[] ? U : T extends object ? T[keyof T] : never>(values: T, options?: CustomOptions<TValues> & Omit<SchemaOptions, "default">) => TUnion<TLiteral<TValues>[]>;
|
|
359
|
+
/** Creates a string schema with 'ipv4' format. */
|
|
360
|
+
IP: <TDefault extends string>(options?: StringOptions & CustomOptions<TDefault>) => import("@sinclair/typebox").TString;
|
|
361
|
+
/** Creates a string schema with 'ipv6' format. */
|
|
362
|
+
IPv6: <TDefault extends string>(options?: StringOptions & CustomOptions<TDefault>) => import("@sinclair/typebox").TString;
|
|
363
|
+
/** Creates a string schema with 'email' format. */
|
|
364
|
+
Email: <TDefault extends string>(options?: StringOptions & CustomOptions<TDefault>) => import("@sinclair/typebox").TString;
|
|
365
|
+
/** Creates a string schema with 'uri' format. */
|
|
366
|
+
URL: <TDefault extends string>(options?: StringOptions & CustomOptions<TDefault>) => import("@sinclair/typebox").TString;
|
|
367
|
+
/** Creates an Any schema. */
|
|
368
|
+
Any: () => import("@sinclair/typebox").TAny;
|
|
369
|
+
/** Creates an Optional schema. */
|
|
370
|
+
Optional: <Schema extends TSchema>(schema: Schema) => Schema extends import("@sinclair/typebox").TOptional<infer S extends TSchema> ? import("@sinclair/typebox").TOptional<S> : import("@sinclair/typebox").Ensure<import("@sinclair/typebox").TOptional<Schema>>;
|
|
371
|
+
/** Creates a Number schema that defaults to a random value if not provided. */
|
|
372
|
+
Random: (options?: NumberOptions & {
|
|
373
|
+
max?: number;
|
|
374
|
+
}) => import("@sinclair/typebox").TNumber;
|
|
375
|
+
};
|
|
376
|
+
export declare const cfs: {
|
|
377
|
+
/**
|
|
378
|
+
* Creates a many-to-many relation in a schema.
|
|
379
|
+
* @param kfgFs The KfgFS instance to relate to.
|
|
380
|
+
* @param options The schema options.
|
|
381
|
+
*/
|
|
382
|
+
many: <T extends KfgFS<any, any>>(kfgFs: T, options?: SchemaOptions) => import("@sinclair/typebox").TUnsafe<KfgFileFS<T["driver"], T["schema"]>[]>;
|
|
383
|
+
join: <T extends KfgFS<any, any>>(kfgFs: T, options?: SchemaOptions & {
|
|
384
|
+
fk: string;
|
|
385
|
+
}) => import("@sinclair/typebox").TUnsafe<KfgFileFS<T["driver"], T["schema"]>>;
|
|
386
|
+
};
|
|
387
|
+
/**
|
|
388
|
+
* A driver for loading configuration from environment variables and .env files.
|
|
389
|
+
*/
|
|
390
|
+
export declare const envDriver: KfgDriver<{
|
|
391
|
+
path: string;
|
|
392
|
+
}, DriverStore, false>;
|
|
393
|
+
/**
|
|
394
|
+
* A driver for loading configuration from JSON files.
|
|
395
|
+
*/
|
|
396
|
+
export declare const jsonDriver: KfgDriver<{
|
|
397
|
+
path: string;
|
|
398
|
+
keyroot: boolean;
|
|
399
|
+
}, DriverStore, false>;
|
|
400
|
+
export declare const k: {
|
|
401
|
+
string: <TDefault extends string>(options?: StringOptions & CustomOptions<TDefault>) => import("@sinclair/typebox").TString;
|
|
402
|
+
number: <TDefault extends number>(options?: NumberOptions & CustomOptions<TDefault>) => import("@sinclair/typebox").TNumber;
|
|
403
|
+
boolean: <TDefault extends boolean>(options?: Omit<SchemaOptions, "default"> & CustomOptions<TDefault>) => import("@sinclair/typebox").TBoolean;
|
|
404
|
+
object: <Properties extends TProperties, TDefault extends Record<string, any>>(properties: Properties, options?: ObjectOptions & CustomOptions<TDefault>) => import("@sinclair/typebox").TObject<Properties>;
|
|
405
|
+
array: <Schema extends TSchema, TDefault extends any[]>(items: Schema, options?: ArrayOptions & CustomOptions<TDefault>) => import("@sinclair/typebox").TArray<Schema>;
|
|
406
|
+
record: <K extends TSchema, V extends TSchema, TDefault extends Record<string, any>>(key: K, value: V, options?: Omit<SchemaOptions, "default"> & CustomOptions<TDefault>) => import("@sinclair/typebox").TRecordOrObject<K, V>;
|
|
407
|
+
enum: <T extends readonly (string | number)[] | object, TValues = T extends readonly (infer U)[] ? U : T extends object ? T[keyof T] : never>(values: T, options?: CustomOptions<TValues> & Omit<SchemaOptions, "default">) => TUnion<TLiteral<TValues>[]>;
|
|
408
|
+
ip: <TDefault extends string>(options?: StringOptions & CustomOptions<TDefault>) => import("@sinclair/typebox").TString;
|
|
409
|
+
ipv6: <TDefault extends string>(options?: StringOptions & CustomOptions<TDefault>) => import("@sinclair/typebox").TString;
|
|
410
|
+
email: <TDefault extends string>(options?: StringOptions & CustomOptions<TDefault>) => import("@sinclair/typebox").TString;
|
|
411
|
+
url: <TDefault extends string>(options?: StringOptions & CustomOptions<TDefault>) => import("@sinclair/typebox").TString;
|
|
412
|
+
any: () => import("@sinclair/typebox").TAny;
|
|
413
|
+
optional: <Schema extends TSchema>(schema: Schema) => Schema extends import("@sinclair/typebox").TOptional<infer S extends TSchema> ? import("@sinclair/typebox").TOptional<S> : import("@sinclair/typebox").Ensure<import("@sinclair/typebox").TOptional<Schema>>;
|
|
414
|
+
random: (options?: NumberOptions & {
|
|
415
|
+
max?: number;
|
|
416
|
+
}) => import("@sinclair/typebox").TNumber;
|
|
417
|
+
/** Creates a String schema. */
|
|
418
|
+
String: <TDefault extends string>(options?: StringOptions & CustomOptions<TDefault>) => import("@sinclair/typebox").TString;
|
|
419
|
+
/** Creates a Number schema. */
|
|
420
|
+
Number: <TDefault extends number>(options?: NumberOptions & CustomOptions<TDefault>) => import("@sinclair/typebox").TNumber;
|
|
421
|
+
/** Creates a Boolean schema. */
|
|
422
|
+
Boolean: <TDefault extends boolean>(options?: Omit<SchemaOptions, "default"> & CustomOptions<TDefault>) => import("@sinclair/typebox").TBoolean;
|
|
423
|
+
/** Creates an Object schema. */
|
|
424
|
+
Object: <Properties extends TProperties, TDefault extends Record<string, any>>(properties: Properties, options?: ObjectOptions & CustomOptions<TDefault>) => import("@sinclair/typebox").TObject<Properties>;
|
|
425
|
+
/** Creates an Array schema. */
|
|
426
|
+
Array: <Schema extends TSchema, TDefault extends any[]>(items: Schema, options?: ArrayOptions & CustomOptions<TDefault>) => import("@sinclair/typebox").TArray<Schema>;
|
|
427
|
+
/** Creates a Record schema. */
|
|
428
|
+
Record: <K extends TSchema, V extends TSchema, TDefault extends Record<string, any>>(key: K, value: V, options?: Omit<SchemaOptions, "default"> & CustomOptions<TDefault>) => import("@sinclair/typebox").TRecordOrObject<K, V>;
|
|
429
|
+
/** Creates a Union of Literals from a string array, const array, or a TypeScript enum. */
|
|
430
|
+
Enum: <T extends readonly (string | number)[] | object, TValues = T extends readonly (infer U)[] ? U : T extends object ? T[keyof T] : never>(values: T, options?: CustomOptions<TValues> & Omit<SchemaOptions, "default">) => TUnion<TLiteral<TValues>[]>;
|
|
431
|
+
/** Creates a string schema with 'ipv4' format. */
|
|
432
|
+
IP: <TDefault extends string>(options?: StringOptions & CustomOptions<TDefault>) => import("@sinclair/typebox").TString;
|
|
433
|
+
/** Creates a string schema with 'ipv6' format. */
|
|
434
|
+
IPv6: <TDefault extends string>(options?: StringOptions & CustomOptions<TDefault>) => import("@sinclair/typebox").TString;
|
|
435
|
+
/** Creates a string schema with 'email' format. */
|
|
436
|
+
Email: <TDefault extends string>(options?: StringOptions & CustomOptions<TDefault>) => import("@sinclair/typebox").TString;
|
|
437
|
+
/** Creates a string schema with 'uri' format. */
|
|
438
|
+
URL: <TDefault extends string>(options?: StringOptions & CustomOptions<TDefault>) => import("@sinclair/typebox").TString;
|
|
439
|
+
/** Creates an Any schema. */
|
|
440
|
+
Any: () => import("@sinclair/typebox").TAny;
|
|
441
|
+
/** Creates an Optional schema. */
|
|
442
|
+
Optional: <Schema extends TSchema>(schema: Schema) => Schema extends import("@sinclair/typebox").TOptional<infer S extends TSchema> ? import("@sinclair/typebox").TOptional<S> : import("@sinclair/typebox").Ensure<import("@sinclair/typebox").TOptional<Schema>>;
|
|
443
|
+
/** Creates a Number schema that defaults to a random value if not provided. */
|
|
444
|
+
Random: (options?: NumberOptions & {
|
|
445
|
+
max?: number;
|
|
446
|
+
}) => import("@sinclair/typebox").TNumber;
|
|
447
|
+
};
|
|
448
|
+
export declare const kfs: {
|
|
449
|
+
/**
|
|
450
|
+
* Creates a many-to-many relation in a schema.
|
|
451
|
+
* @param kfgFs The KfgFS instance to relate to.
|
|
452
|
+
* @param options The schema options.
|
|
453
|
+
*/
|
|
454
|
+
many: <T extends KfgFS<any, any>>(kfgFs: T, options?: SchemaOptions) => import("@sinclair/typebox").TUnsafe<KfgFileFS<T["driver"], T["schema"]>[]>;
|
|
455
|
+
join: <T extends KfgFS<any, any>>(kfgFs: T, options?: SchemaOptions & {
|
|
456
|
+
fk: string;
|
|
457
|
+
}) => import("@sinclair/typebox").TUnsafe<KfgFileFS<T["driver"], T["schema"]>>;
|
|
458
|
+
};
|
|
459
|
+
/**
|
|
460
|
+
* Custom metadata properties that can be added to a schema.
|
|
461
|
+
*/
|
|
462
|
+
export interface CustomOptions<Default = any> {
|
|
463
|
+
description?: string;
|
|
464
|
+
default?: Default;
|
|
465
|
+
important?: boolean;
|
|
466
|
+
initial_save?: boolean;
|
|
467
|
+
prop?: string;
|
|
468
|
+
refines?: ((value: unknown) => boolean | string)[];
|
|
469
|
+
}
|
|
470
|
+
/**
|
|
471
|
+
* Represents the options of a driver.
|
|
472
|
+
* @template C The type of the driver configuration.
|
|
473
|
+
* @template S The type of the driver store.
|
|
474
|
+
* @template A The type of the async flag.
|
|
475
|
+
*/
|
|
476
|
+
export interface KfgDriverOptions<C extends DriverConfig, S extends DriverStore, A extends boolean> {
|
|
477
|
+
identify: string;
|
|
478
|
+
async: A;
|
|
479
|
+
config: C;
|
|
480
|
+
getEnvKeyForPath?: (path: string) => string;
|
|
481
|
+
onLoad?: DriverOnLoad<C, S, A>;
|
|
482
|
+
onSet?: DriverOnSet<C, S, A>;
|
|
483
|
+
onDel?: DriverOnDel<C, S, A>;
|
|
484
|
+
}
|
|
485
|
+
/**
|
|
486
|
+
* Gets the type of a value at a given path in an object.
|
|
487
|
+
* @template T The type of the object.
|
|
488
|
+
* @template P The path to the value.
|
|
489
|
+
*/
|
|
490
|
+
export type DeepGet<T, P extends string> = P extends `${infer K}.${infer R}` ? K extends keyof T ? DeepGet<T[K], R> : never : P extends keyof T ? T[P] : never;
|
|
491
|
+
/**
|
|
492
|
+
* Represents the configuration of a driver.
|
|
493
|
+
*/
|
|
494
|
+
export type DriverConfig = Record<string, unknown>;
|
|
495
|
+
/**
|
|
496
|
+
* Represents the onDel method of a driver.
|
|
497
|
+
* @template C The type of the driver configuration.
|
|
498
|
+
* @template S The type of the driver store.
|
|
499
|
+
* @template A The type of the async flag.
|
|
500
|
+
*/
|
|
501
|
+
export type DriverOnDel<C extends DriverConfig, S extends DriverStore, A extends boolean> = (this: KfgDriver<C, S, A>, key: string) => inPromise<A, void>;
|
|
502
|
+
/**
|
|
503
|
+
* Represents the onLoad method of a driver.
|
|
504
|
+
* @template C The type of the driver configuration.
|
|
505
|
+
* @template S The type of the driver store.
|
|
506
|
+
* @template A The type of the async flag.
|
|
507
|
+
*/
|
|
508
|
+
export type DriverOnLoad<C extends DriverConfig, S extends DriverStore, A extends boolean> = (this: KfgDriver<C, S, A>, schema: SchemaDefinition, opts: Partial<C>) => inPromise<A, any>;
|
|
509
|
+
/**
|
|
510
|
+
* Represents the onSet method of a driver.
|
|
511
|
+
* @template C The type of the driver configuration.
|
|
512
|
+
* @template S The type of the driver store.
|
|
513
|
+
* @template A The type of the async flag.
|
|
514
|
+
*/
|
|
515
|
+
export type DriverOnSet<C extends DriverConfig, S extends DriverStore, A extends boolean> = (this: KfgDriver<C, S, A>, key: string, value: unknown, options?: {
|
|
516
|
+
description?: string;
|
|
517
|
+
}) => inPromise<A, void>;
|
|
518
|
+
/**
|
|
519
|
+
* Represents the store of a driver.
|
|
520
|
+
*/
|
|
521
|
+
export type DriverStore = Record<string, unknown>;
|
|
522
|
+
/**
|
|
523
|
+
* Represents a path to a value in an object.
|
|
524
|
+
* @template T The type of the object.
|
|
525
|
+
*/
|
|
526
|
+
export type Paths<T> = T extends object ? {
|
|
527
|
+
[K in keyof T]: K extends string ? T[K] extends ReadonlyArray<any> ? K : T[K] extends object ? `${K}.${Paths<T[K]>}` | K : K : never;
|
|
528
|
+
}[keyof T] : never;
|
|
529
|
+
/**
|
|
530
|
+
* Represents the paths to the relations in a schema.
|
|
531
|
+
* @template S The type of the schema.
|
|
532
|
+
*/
|
|
533
|
+
export type RelationPaths<S extends SchemaDefinition> = S extends TSchema ? never : {
|
|
534
|
+
[K in keyof S]: S[K] extends TUnsafe<KfgFileFS<any, any>> | TUnsafe<KfgFileFS<any, any>[]> ? K : S[K] extends SchemaDefinition ? `${K & string}.${RelationPaths<S[K]>}` : never;
|
|
535
|
+
}[keyof S];
|
|
536
|
+
/**
|
|
537
|
+
* Represents a path to a value in an object.
|
|
538
|
+
* @template T The type of the object.
|
|
539
|
+
*/
|
|
540
|
+
export type RootPaths<T> = T extends object ? {
|
|
541
|
+
[K in keyof T]: K extends string ? T[K] extends ReadonlyArray<any> ? K : T[K] extends object ? K | `${K}.${RootPaths<T[K]>}` : never : never;
|
|
542
|
+
}[keyof T] : never;
|
|
543
|
+
/**
|
|
544
|
+
* A recursive type representing the user-friendly schema definition.
|
|
545
|
+
*/
|
|
546
|
+
export type SchemaDefinition = TSchema | {
|
|
547
|
+
[key: string]: SchemaDefinition;
|
|
548
|
+
};
|
|
549
|
+
/**
|
|
550
|
+
* A mapped type que converte um SchemaDefinition em tipo estático TypeScript.
|
|
551
|
+
* Agora com suporte a arrays do TypeBox.
|
|
552
|
+
*/
|
|
553
|
+
export type StaticSchema<T> = T extends {
|
|
554
|
+
type: "array";
|
|
555
|
+
items: infer I;
|
|
556
|
+
} ? StaticSchema<I>[] : T extends TSchema ? Static<T> : T extends SchemaDefinition ? {
|
|
557
|
+
-readonly [K in keyof T]: StaticSchema<T[K]>;
|
|
558
|
+
} : never;
|
|
559
|
+
/**
|
|
560
|
+
* Represents the static schema with relations.
|
|
561
|
+
* @template S The type of the schema.
|
|
562
|
+
*/
|
|
563
|
+
export type StaticSchemaWithRelation<S> = S extends TSchema ? StaticSchema<S> : {
|
|
564
|
+
[K in keyof S]: S[K] extends KfgFileFS<any, any> ? string : S[K] extends KfgFileFS<any, any>[] ? string[] : StaticSchemaWithRelation<S[K]>;
|
|
565
|
+
};
|
|
566
|
+
/**
|
|
567
|
+
* Represents a value that can be a promise or a plain value.
|
|
568
|
+
* @template Async The type of the async flag.
|
|
569
|
+
* @template Result The type of the result.
|
|
570
|
+
*/
|
|
571
|
+
export type inPromise<Async extends boolean, Result> = Async extends true ? Promise<Result> : Result;
|
|
572
|
+
|
|
573
|
+
export {
|
|
574
|
+
SchemaOptions,
|
|
575
|
+
TObject,
|
|
576
|
+
TSchema,
|
|
577
|
+
};
|
|
578
|
+
|
|
579
|
+
export {};
|