@gesslar/toolkit 0.5.0 → 0.7.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/package.json +8 -8
- package/src/lib/Collection.js +132 -17
- package/src/lib/Contract.js +1 -1
- package/src/lib/Data.js +27 -18
- package/src/lib/DirectoryObject.js +1 -1
- package/src/lib/FS.js +10 -0
- package/src/lib/Glog.js +27 -10
- package/src/lib/Logger.js +3 -0
- package/src/lib/Sass.js +6 -1
- package/src/lib/Tantrum.js +43 -0
- package/src/lib/TypeSpec.js +11 -7
- package/src/lib/Util.js +82 -0
- package/src/lib/Valid.js +24 -6
- package/src/types/Collection.d.ts +6 -1
- package/src/types/Contract.d.ts +27 -27
- package/src/types/Data.d.ts +23 -23
- package/src/types/FS.d.ts +3 -3
- package/src/types/Glog.d.ts +302 -49
- package/src/types/Sass.d.ts +1 -1
- package/src/types/Schemer.d.ts +29 -29
- package/src/types/Tantrum.d.ts +10 -10
- package/src/types/Term.d.ts +1 -1
- package/src/types/Terms.d.ts +21 -21
- package/src/types/Type.d.ts +1 -1
- package/src/types/Util.d.ts +20 -2
- package/src/types/index.d.ts +17 -23
- package/src/types/index.d.ts.map +1 -0
- package/src/types/lib/Cache.d.ts +28 -0
- package/src/types/lib/Cache.d.ts.map +1 -0
- package/src/types/lib/Collection.d.ts +246 -0
- package/src/types/lib/Collection.d.ts.map +1 -0
- package/src/types/lib/Contract.d.ts +72 -0
- package/src/types/lib/Contract.d.ts.map +1 -0
- package/src/types/lib/Data.d.ts +189 -0
- package/src/types/lib/Data.d.ts.map +1 -0
- package/src/types/lib/DirectoryObject.d.ts +148 -0
- package/src/types/lib/DirectoryObject.d.ts.map +1 -0
- package/src/types/lib/FS.d.ts +70 -0
- package/src/types/lib/FS.d.ts.map +1 -0
- package/src/types/lib/FileObject.d.ts +189 -0
- package/src/types/lib/FileObject.d.ts.map +1 -0
- package/src/types/lib/Glog.d.ts +113 -0
- package/src/types/lib/Glog.d.ts.map +1 -0
- package/src/types/lib/Logger.d.ts +46 -0
- package/src/types/lib/Logger.d.ts.map +1 -0
- package/src/types/lib/Sass.d.ts +62 -0
- package/src/types/lib/Sass.d.ts.map +1 -0
- package/src/types/lib/Schemer.d.ts +23 -0
- package/src/types/lib/Schemer.d.ts.map +1 -0
- package/src/types/lib/Tantrum.d.ts +50 -0
- package/src/types/lib/Tantrum.d.ts.map +1 -0
- package/src/types/lib/Term.d.ts +103 -0
- package/src/types/lib/Term.d.ts.map +1 -0
- package/src/types/lib/Terms.d.ts +24 -0
- package/src/types/lib/Terms.d.ts.map +1 -0
- package/src/types/lib/TypeSpec.d.ts +92 -0
- package/src/types/lib/TypeSpec.d.ts.map +1 -0
- package/src/types/lib/Util.d.ts +197 -0
- package/src/types/lib/Util.d.ts.map +1 -0
- package/src/types/lib/Valid.d.ts +33 -0
- package/src/types/lib/Valid.d.ts.map +1 -0
- package/src/lib/Action.js +0 -283
- package/src/lib/ActionBuilder.js +0 -144
- package/src/lib/ActionRunner.js +0 -79
- package/src/lib/Hooks.js +0 -194
- package/src/lib/Piper.js +0 -155
package/src/types/Glog.d.ts
CHANGED
|
@@ -1,92 +1,345 @@
|
|
|
1
1
|
// Implementation: ../lib/Glog.js
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
* Color configuration object for log levels.
|
|
5
|
+
* Uses \@gesslar/colours format strings.
|
|
6
|
+
*/
|
|
7
|
+
export interface LoggerColours {
|
|
8
|
+
debug: [string, string, string, string, string]
|
|
9
|
+
info: string
|
|
10
|
+
warn: string
|
|
11
|
+
error: string
|
|
12
|
+
reset: string
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Configuration options for Glog instance creation.
|
|
17
|
+
*/
|
|
18
|
+
export interface GlogOptions {
|
|
19
|
+
/** Logger name (appears in composed messages) */
|
|
20
|
+
name?: string
|
|
21
|
+
/** Debug level (0-5, alias for logLevel) */
|
|
22
|
+
debugLevel?: number
|
|
23
|
+
/** Log level (0-5) */
|
|
24
|
+
logLevel?: number
|
|
25
|
+
/** Message prefix */
|
|
26
|
+
prefix?: string
|
|
27
|
+
/** Custom colors configuration */
|
|
28
|
+
colors?: LoggerColours
|
|
29
|
+
/** Enable stack trace extraction */
|
|
30
|
+
stackTrace?: boolean
|
|
31
|
+
/** Environment type ('extension' for VSCode integration) */
|
|
32
|
+
env?: string
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Enhanced global logging utility combining simple logging with advanced Logger features.
|
|
8
37
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
38
|
+
* Glog can be used in multiple ways:
|
|
39
|
+
* 1. Simple function call: `Glog(data)` or `Glog(2, "debug message")`
|
|
40
|
+
* 2. Configured instance: `new Glog(options)`
|
|
41
|
+
* 3. Fluent setup: `Glog.create().withName("App").withColors()`
|
|
42
|
+
* 4. Traditional logger: `logger.debug("message", level)`
|
|
11
43
|
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
44
|
+
* Features:
|
|
45
|
+
* - Log level filtering (0-5)
|
|
46
|
+
* - Custom prefixes for message organization
|
|
47
|
+
* - Color support via \@gesslar/colours
|
|
48
|
+
* - Traditional logger methods (debug, info, warn, error, success)
|
|
49
|
+
* - Template literal color formatting
|
|
50
|
+
* - VSCode extension integration
|
|
51
|
+
* - Static and instance usage patterns
|
|
14
52
|
*
|
|
15
53
|
* @example
|
|
16
54
|
* ```typescript
|
|
17
55
|
* import { Glog } from '@gesslar/toolkit'
|
|
18
56
|
*
|
|
19
|
-
* //
|
|
57
|
+
* // Simple usage with static configuration
|
|
20
58
|
* Glog.setLogLevel(3).setLogPrefix('[MyApp]')
|
|
59
|
+
* Glog(0, 'Critical error!')
|
|
60
|
+
* Glog(2, 'Debug info:', data)
|
|
21
61
|
*
|
|
22
|
-
* //
|
|
23
|
-
* Glog(
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
* Glog('Simple message') // Level 0 by default
|
|
62
|
+
* // Instance usage with configuration
|
|
63
|
+
* const logger = new Glog({ name: 'API', logLevel: 2 })
|
|
64
|
+
* logger.debug('Processing request', 1)
|
|
65
|
+
* logger.info('Request completed')
|
|
66
|
+
* logger.error('Request failed')
|
|
28
67
|
*
|
|
29
|
-
* //
|
|
30
|
-
* Glog.
|
|
31
|
-
*
|
|
68
|
+
* // Fluent instance creation
|
|
69
|
+
* const log = Glog.create()
|
|
70
|
+
* .withName('Database')
|
|
71
|
+
* .withLogLevel(3)
|
|
72
|
+
* .withColors()
|
|
32
73
|
*
|
|
33
|
-
* //
|
|
34
|
-
*
|
|
35
|
-
*
|
|
74
|
+
* // Color template literals
|
|
75
|
+
* logger.colorize`{success}Operation completed{/} in {bold}${time}ms{/}`
|
|
76
|
+
* logger.success('All tests passed!')
|
|
36
77
|
* ```
|
|
37
|
-
*
|
|
38
|
-
* @remarks
|
|
39
|
-
* The proxy implementation allows Glog to be called directly as a function
|
|
40
|
-
* while still providing static methods for configuration. This makes it
|
|
41
|
-
* extremely convenient for quick logging without ceremony.
|
|
42
78
|
*/
|
|
43
|
-
|
|
79
|
+
declare class Glog {
|
|
80
|
+
/** Current static log level (0-5) */
|
|
81
|
+
static logLevel: number
|
|
82
|
+
/** Current static log prefix */
|
|
83
|
+
static logPrefix: string
|
|
84
|
+
/** Current static color configuration */
|
|
85
|
+
static colors: LoggerColours | null
|
|
86
|
+
/** Whether stack traces are enabled globally */
|
|
87
|
+
static stackTrace: boolean
|
|
88
|
+
/** Global logger name */
|
|
89
|
+
static name: string
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Create a new Glog instance with optional configuration.
|
|
93
|
+
*
|
|
94
|
+
* @param options - Configuration options
|
|
95
|
+
*/
|
|
96
|
+
constructor(options?: GlogOptions)
|
|
97
|
+
|
|
98
|
+
// === STATIC CONFIGURATION METHODS ===
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Set the global log prefix for all messages.
|
|
102
|
+
*
|
|
103
|
+
* @param prefix - Prefix string to prepend to messages
|
|
104
|
+
* @returns The Glog class for chaining
|
|
105
|
+
*/
|
|
106
|
+
static setLogPrefix(prefix: string): typeof Glog
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Set the global log level threshold.
|
|
110
|
+
* Messages with levels higher than this are filtered out.
|
|
111
|
+
*
|
|
112
|
+
* @param level - Log level (0-5, automatically clamped)
|
|
113
|
+
* @returns The Glog class for chaining
|
|
114
|
+
*/
|
|
115
|
+
static setLogLevel(level: number): typeof Glog
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Set the global logger name.
|
|
119
|
+
*
|
|
120
|
+
* @param name - Logger name
|
|
121
|
+
* @returns The Glog class for chaining
|
|
122
|
+
*/
|
|
123
|
+
static withName(name: string): typeof Glog
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Configure global color settings.
|
|
127
|
+
*
|
|
128
|
+
* @param colors - Color configuration (defaults to loggerColours)
|
|
129
|
+
* @returns The Glog class for chaining
|
|
130
|
+
*/
|
|
131
|
+
static withColors(colors?: LoggerColours): typeof Glog
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Enable or disable global stack trace extraction.
|
|
135
|
+
*
|
|
136
|
+
* @param enabled - Whether to enable stack traces (default: true)
|
|
137
|
+
* @returns The Glog class for chaining
|
|
138
|
+
*/
|
|
139
|
+
static withStackTrace(enabled?: boolean): typeof Glog
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Create a new Glog instance (fluent factory method).
|
|
143
|
+
*
|
|
144
|
+
* @param options - Configuration options
|
|
145
|
+
* @returns New Glog instance
|
|
146
|
+
*/
|
|
147
|
+
static create(options?: GlogOptions): Glog
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Log a colorized message using template literals (static).
|
|
151
|
+
*
|
|
152
|
+
* @param strings - Template strings
|
|
153
|
+
* @param values - Template values
|
|
154
|
+
*/
|
|
155
|
+
static colorize(strings: TemplateStringsArray, ...values: unknown[]): void
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Log a success message with green color (static).
|
|
159
|
+
*
|
|
160
|
+
* @param message - Success message
|
|
161
|
+
* @param args - Additional arguments
|
|
162
|
+
*/
|
|
163
|
+
static success(message: string, ...args: unknown[]): void
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Set a color alias for convenient usage.
|
|
167
|
+
*
|
|
168
|
+
* @param alias - Alias name
|
|
169
|
+
* @param colorCode - Color code (e.g., "{F196}" or "{<B}")
|
|
170
|
+
* @returns The Glog class for chaining
|
|
171
|
+
*/
|
|
172
|
+
static setAlias(alias: string, colorCode: string): typeof Glog
|
|
173
|
+
|
|
174
|
+
// === INSTANCE CONFIGURATION METHODS ===
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Set instance options.
|
|
178
|
+
*
|
|
179
|
+
* @param options - Configuration options
|
|
180
|
+
* @returns This instance for chaining
|
|
181
|
+
*/
|
|
182
|
+
setOptions(options: GlogOptions): this
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Set instance logger name (fluent).
|
|
186
|
+
*
|
|
187
|
+
* @param name - Logger name
|
|
188
|
+
* @returns This instance for chaining
|
|
189
|
+
*/
|
|
190
|
+
withName(name: string): this
|
|
191
|
+
|
|
44
192
|
/**
|
|
45
|
-
*
|
|
46
|
-
* The prefix helps identify the source of log messages in complex
|
|
47
|
-
* applications with multiple components.
|
|
193
|
+
* Set instance log level (fluent).
|
|
48
194
|
*
|
|
49
|
-
* @param
|
|
50
|
-
* @returns
|
|
195
|
+
* @param level - Log level (0-5)
|
|
196
|
+
* @returns This instance for chaining
|
|
51
197
|
*/
|
|
52
|
-
|
|
198
|
+
withLogLevel(level: number): this
|
|
53
199
|
|
|
54
200
|
/**
|
|
55
|
-
*
|
|
56
|
-
* Messages with a level higher than this threshold will be filtered out.
|
|
57
|
-
* Log levels range from 0 (critical) to 5 (verbose debug).
|
|
201
|
+
* Set instance prefix (fluent).
|
|
58
202
|
*
|
|
59
|
-
* @param
|
|
60
|
-
* @returns
|
|
203
|
+
* @param prefix - Message prefix
|
|
204
|
+
* @returns This instance for chaining
|
|
61
205
|
*/
|
|
62
|
-
|
|
206
|
+
withPrefix(prefix: string): this
|
|
63
207
|
|
|
64
208
|
/**
|
|
65
|
-
*
|
|
66
|
-
*
|
|
209
|
+
* Configure instance colors (fluent).
|
|
210
|
+
*
|
|
211
|
+
* @param colors - Color configuration (defaults to loggerColours)
|
|
212
|
+
* @returns This instance for chaining
|
|
213
|
+
*/
|
|
214
|
+
withColors(colors?: LoggerColours): this
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Enable or disable instance stack trace extraction (fluent).
|
|
218
|
+
*
|
|
219
|
+
* @param enabled - Whether to enable stack traces (default: true)
|
|
220
|
+
* @returns This instance for chaining
|
|
221
|
+
*/
|
|
222
|
+
withStackTrace(enabled?: boolean): this
|
|
223
|
+
|
|
224
|
+
// === INSTANCE PROPERTIES ===
|
|
225
|
+
|
|
226
|
+
/** Instance logger name */
|
|
227
|
+
get name(): string
|
|
228
|
+
|
|
229
|
+
/** Instance debug/log level */
|
|
230
|
+
get debugLevel(): number
|
|
231
|
+
|
|
232
|
+
/** Instance configuration options */
|
|
233
|
+
get options(): {
|
|
234
|
+
name: string
|
|
235
|
+
debugLevel: number
|
|
236
|
+
prefix: string
|
|
237
|
+
colors: LoggerColours | null
|
|
238
|
+
stackTrace: boolean
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/** Access to colours template function */
|
|
242
|
+
get colours(): any
|
|
243
|
+
|
|
244
|
+
// === INSTANCE LOGGING METHODS ===
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Log a debug message with optional level.
|
|
248
|
+
* Level 0 means debug OFF - use levels 1-4 for debug verbosity.
|
|
249
|
+
* Debug messages only show when logLevel > 0.
|
|
250
|
+
*
|
|
251
|
+
* @param message - Debug message
|
|
252
|
+
* @param level - Debug level (1-4, default: 1)
|
|
253
|
+
* @param arg - Additional arguments
|
|
254
|
+
* @throws {Error} If level < 1 (level 0 = debug OFF, not a valid debug level)
|
|
255
|
+
*/
|
|
256
|
+
debug(message: string, level?: number, ...arg: unknown[]): void
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* Log an informational message.
|
|
260
|
+
*
|
|
261
|
+
* @param message - Info message
|
|
262
|
+
* @param arg - Additional arguments
|
|
263
|
+
*/
|
|
264
|
+
info(message: string, ...arg: unknown[]): void
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* Log a warning message.
|
|
268
|
+
*
|
|
269
|
+
* @param message - Warning message
|
|
270
|
+
* @param arg - Additional arguments
|
|
271
|
+
*/
|
|
272
|
+
warn(message: string, ...arg: unknown[]): void
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* Log an error message.
|
|
276
|
+
*
|
|
277
|
+
* @param message - Error message
|
|
278
|
+
* @param arg - Additional arguments
|
|
279
|
+
*/
|
|
280
|
+
error(message: string, ...arg: unknown[]): void
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* Log a colorized message using template literals (instance).
|
|
284
|
+
*
|
|
285
|
+
* @param strings - Template strings
|
|
286
|
+
* @param values - Template values
|
|
287
|
+
*/
|
|
288
|
+
colorize(strings: TemplateStringsArray, ...values: unknown[]): void
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* Log a success message with green color (instance).
|
|
292
|
+
*
|
|
293
|
+
* @param message - Success message
|
|
294
|
+
* @param args - Additional arguments
|
|
295
|
+
*/
|
|
296
|
+
success(message: string, ...args: unknown[]): void
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* Execute instance logging (supports level filtering).
|
|
67
300
|
*
|
|
68
301
|
* @param args - Log level (optional) followed by message arguments
|
|
69
302
|
*/
|
|
70
|
-
execute(...args:
|
|
303
|
+
execute(...args: unknown[]): void
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* Create a new debug function with tag extraction.
|
|
307
|
+
*
|
|
308
|
+
* @param tag - Tag name (will be replaced by extracted function info)
|
|
309
|
+
* @returns Bound debug function
|
|
310
|
+
*/
|
|
311
|
+
newDebug(tag: string): (message: string, level: number, ...arg: unknown[]) => void
|
|
312
|
+
|
|
313
|
+
/**
|
|
314
|
+
* Extract file and function information from call stack.
|
|
315
|
+
* Simplified implementation returns "caller" by default.
|
|
316
|
+
*
|
|
317
|
+
* @returns Caller information string
|
|
318
|
+
*/
|
|
319
|
+
extractFileFunction(): string
|
|
71
320
|
}
|
|
72
321
|
|
|
73
322
|
/**
|
|
74
|
-
* Callable interface for the proxied Glog
|
|
75
|
-
*
|
|
323
|
+
* Callable interface for the proxied Glog export.
|
|
324
|
+
* The default export is a Proxy that allows both class and function usage.
|
|
76
325
|
*/
|
|
77
326
|
interface GlogCallable {
|
|
78
327
|
/**
|
|
79
328
|
* Log a message with optional level specification.
|
|
329
|
+
* First argument can be a number (level) or part of the message.
|
|
80
330
|
*
|
|
81
331
|
* @param args - Either (level: number, ...messages) or (...messages)
|
|
82
332
|
*/
|
|
83
|
-
(...args:
|
|
333
|
+
(...args: unknown[]): void
|
|
84
334
|
}
|
|
85
335
|
|
|
86
336
|
/**
|
|
87
|
-
* The Glog
|
|
88
|
-
* Can be used
|
|
337
|
+
* The Glog export: a Proxy combining class methods with callable behavior.
|
|
338
|
+
* Can be used as:
|
|
339
|
+
* - A function: `Glog(message)` or `Glog(level, message)`
|
|
340
|
+
* - A class: `new Glog(options)`
|
|
341
|
+
* - Static methods: `Glog.setLogLevel(3)`
|
|
89
342
|
*/
|
|
90
|
-
declare const
|
|
343
|
+
declare const GlogExport: typeof Glog & GlogCallable
|
|
91
344
|
|
|
92
|
-
export default
|
|
345
|
+
export default GlogExport
|
package/src/types/Sass.d.ts
CHANGED
package/src/types/Schemer.d.ts
CHANGED
|
@@ -4,10 +4,10 @@ import type { ValidateFunction, ErrorObject } from 'ajv'
|
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Schemer provides utilities for compiling and validating JSON schemas using AJV.
|
|
7
|
-
*
|
|
7
|
+
*
|
|
8
8
|
* This class serves as a convenient wrapper around AJV (Another JSON Schema Validator)
|
|
9
9
|
* with toolkit-specific enhancements for error reporting and schema compilation.
|
|
10
|
-
*
|
|
10
|
+
*
|
|
11
11
|
* @example
|
|
12
12
|
* ```typescript
|
|
13
13
|
* // Create validator from schema object
|
|
@@ -19,19 +19,19 @@ import type { ValidateFunction, ErrorObject } from 'ajv'
|
|
|
19
19
|
* },
|
|
20
20
|
* required: ["name"]
|
|
21
21
|
* })
|
|
22
|
-
*
|
|
22
|
+
*
|
|
23
23
|
* // Validate data
|
|
24
24
|
* const isValid = validator({ name: "John", age: 30 })
|
|
25
25
|
* ```
|
|
26
|
-
*
|
|
26
|
+
*
|
|
27
27
|
* @example
|
|
28
28
|
* ```typescript
|
|
29
29
|
* // Create validator from file
|
|
30
30
|
* const file = new FileObject("schema.json")
|
|
31
31
|
* const validator = await Schemer.fromFile(file)
|
|
32
32
|
* ```
|
|
33
|
-
*
|
|
34
|
-
* @example
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
35
|
* ```typescript
|
|
36
36
|
* // Get raw AJV validator and format errors
|
|
37
37
|
* const validate = Schemer.getValidator(schema)
|
|
@@ -45,14 +45,14 @@ import type { ValidateFunction, ErrorObject } from 'ajv'
|
|
|
45
45
|
declare class Schemer {
|
|
46
46
|
/**
|
|
47
47
|
* Creates an AJV validator function from a schema file
|
|
48
|
-
*
|
|
48
|
+
*
|
|
49
49
|
* @param file - FileObject pointing to a JSON/YAML schema file
|
|
50
50
|
* @param options - AJV configuration options
|
|
51
51
|
* @returns Promise resolving to AJV validator function
|
|
52
|
-
*
|
|
52
|
+
*
|
|
53
53
|
* @throws {Sass} If file cannot be loaded or schema is invalid
|
|
54
54
|
* @throws {Sass} If file is not a FileObject or options are invalid
|
|
55
|
-
*
|
|
55
|
+
*
|
|
56
56
|
* @example
|
|
57
57
|
* ```typescript
|
|
58
58
|
* const file = new FileObject("user-schema.json")
|
|
@@ -60,7 +60,7 @@ declare class Schemer {
|
|
|
60
60
|
* allErrors: true,
|
|
61
61
|
* verbose: true
|
|
62
62
|
* })
|
|
63
|
-
*
|
|
63
|
+
*
|
|
64
64
|
* const isValid = validator({ name: "John", age: 30 })
|
|
65
65
|
* if (!isValid) {
|
|
66
66
|
* console.log("Errors:", validator.errors)
|
|
@@ -68,20 +68,20 @@ declare class Schemer {
|
|
|
68
68
|
* ```
|
|
69
69
|
*/
|
|
70
70
|
static fromFile(
|
|
71
|
-
file: import('./FileObject.js').default,
|
|
71
|
+
file: import('./FileObject.js').default,
|
|
72
72
|
options?: object
|
|
73
73
|
): Promise<ValidateFunction>
|
|
74
74
|
|
|
75
75
|
/**
|
|
76
76
|
* Creates an AJV validator function from a schema object
|
|
77
|
-
*
|
|
77
|
+
*
|
|
78
78
|
* @param schemaData - JSON schema object to compile
|
|
79
|
-
* @param options - AJV configuration options
|
|
79
|
+
* @param options - AJV configuration options
|
|
80
80
|
* @returns Promise resolving to AJV validator function
|
|
81
|
-
*
|
|
81
|
+
*
|
|
82
82
|
* @throws {Sass} If schema data or options are not plain objects
|
|
83
83
|
* @throws {Sass} If schema compilation fails
|
|
84
|
-
*
|
|
84
|
+
*
|
|
85
85
|
* @example
|
|
86
86
|
* ```typescript
|
|
87
87
|
* const validator = await Schemer.from({
|
|
@@ -91,11 +91,11 @@ declare class Schemer {
|
|
|
91
91
|
* email: { type: "string", format: "email" }
|
|
92
92
|
* },
|
|
93
93
|
* required: ["id", "email"]
|
|
94
|
-
* }, {
|
|
94
|
+
* }, {
|
|
95
95
|
* formats: true,
|
|
96
|
-
* allErrors: true
|
|
96
|
+
* allErrors: true
|
|
97
97
|
* })
|
|
98
|
-
*
|
|
98
|
+
*
|
|
99
99
|
* const isValid = validator({ id: "123", email: "test@example.com" })
|
|
100
100
|
* if (!isValid) {
|
|
101
101
|
* console.log("Errors:", validator.errors)
|
|
@@ -106,11 +106,11 @@ declare class Schemer {
|
|
|
106
106
|
|
|
107
107
|
/**
|
|
108
108
|
* Creates a raw AJV validator function from a schema object
|
|
109
|
-
*
|
|
109
|
+
*
|
|
110
110
|
* @param schema - The JSON schema to compile
|
|
111
111
|
* @param options - AJV configuration options (defaults to {allErrors: true, verbose: true})
|
|
112
112
|
* @returns AJV validator function with .errors property when validation fails
|
|
113
|
-
*
|
|
113
|
+
*
|
|
114
114
|
* @example
|
|
115
115
|
* ```typescript
|
|
116
116
|
* const validate = Schemer.getValidator({
|
|
@@ -118,13 +118,13 @@ declare class Schemer {
|
|
|
118
118
|
* minLength: 1,
|
|
119
119
|
* maxLength: 100
|
|
120
120
|
* })
|
|
121
|
-
*
|
|
121
|
+
*
|
|
122
122
|
* const isValid = validate("Hello World")
|
|
123
123
|
* if (!isValid) {
|
|
124
124
|
* console.log("Errors:", validate.errors)
|
|
125
125
|
* }
|
|
126
126
|
* ```
|
|
127
|
-
*
|
|
127
|
+
*
|
|
128
128
|
* @example
|
|
129
129
|
* ```typescript
|
|
130
130
|
* // Custom AJV options
|
|
@@ -136,21 +136,21 @@ declare class Schemer {
|
|
|
136
136
|
* ```
|
|
137
137
|
*/
|
|
138
138
|
static getValidator(
|
|
139
|
-
schema: object,
|
|
139
|
+
schema: object,
|
|
140
140
|
options?: { allErrors?: boolean; verbose?: boolean; [key: string]: unknown }
|
|
141
141
|
): ValidateFunction
|
|
142
142
|
|
|
143
143
|
/**
|
|
144
144
|
* Formats AJV validation errors into a human-readable report
|
|
145
|
-
*
|
|
145
|
+
*
|
|
146
146
|
* @param errors - Array of AJV error objects from failed validation
|
|
147
147
|
* @returns Formatted error message with helpful details and suggestions
|
|
148
|
-
*
|
|
148
|
+
*
|
|
149
149
|
* @example
|
|
150
150
|
* ```typescript
|
|
151
151
|
* const validate = Schemer.getValidator(schema)
|
|
152
152
|
* const isValid = validate(data)
|
|
153
|
-
*
|
|
153
|
+
*
|
|
154
154
|
* if (!isValid) {
|
|
155
155
|
* const report = Schemer.reportValidationErrors(validate.errors)
|
|
156
156
|
* console.error("Validation failed:")
|
|
@@ -161,14 +161,14 @@ declare class Schemer {
|
|
|
161
161
|
* // ➜ Received value: "string"
|
|
162
162
|
* }
|
|
163
163
|
* ```
|
|
164
|
-
*
|
|
164
|
+
*
|
|
165
165
|
* @example
|
|
166
166
|
* ```typescript
|
|
167
167
|
* // The error report includes helpful details:
|
|
168
168
|
* // - Property paths and error descriptions
|
|
169
169
|
* // - Expected vs actual types
|
|
170
170
|
* // - Missing required fields
|
|
171
|
-
* // - Pattern matching failures
|
|
171
|
+
* // - Pattern matching failures
|
|
172
172
|
* // - Closest matches for enum values
|
|
173
173
|
* // - Unexpected additional properties
|
|
174
174
|
* ```
|
|
@@ -176,4 +176,4 @@ declare class Schemer {
|
|
|
176
176
|
static reportValidationErrors(errors: ErrorObject[] | null | undefined): string
|
|
177
177
|
}
|
|
178
178
|
|
|
179
|
-
export default Schemer
|
|
179
|
+
export default Schemer
|
package/src/types/Tantrum.d.ts
CHANGED
|
@@ -5,17 +5,17 @@ import Sass from './Sass'
|
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Custom aggregate error class that extends AggregateError.
|
|
8
|
-
*
|
|
8
|
+
*
|
|
9
9
|
* Automatically wraps plain Error objects in Sass instances while preserving
|
|
10
10
|
* existing Sass errors, providing consistent formatted reporting for
|
|
11
11
|
* multiple error scenarios.
|
|
12
|
-
*
|
|
12
|
+
*
|
|
13
13
|
* @example
|
|
14
14
|
* ```typescript
|
|
15
15
|
* // Collect multiple errors and throw as a bundle
|
|
16
16
|
* const errors = [new Error("thing 1"), sassError, new Error("thing 3")]
|
|
17
17
|
* throw Tantrum.new("Multiple validation failures", errors)
|
|
18
|
-
*
|
|
18
|
+
*
|
|
19
19
|
* // Later, in error handling:
|
|
20
20
|
* catch (error) {
|
|
21
21
|
* if (error instanceof Tantrum) {
|
|
@@ -28,7 +28,7 @@ export default class Tantrum extends AggregateError {
|
|
|
28
28
|
/**
|
|
29
29
|
* Creates a new Tantrum instance.
|
|
30
30
|
* Plain Error objects are automatically wrapped in Sass instances.
|
|
31
|
-
*
|
|
31
|
+
*
|
|
32
32
|
* @param message - The aggregate error message describing the overall failure
|
|
33
33
|
* @param errors - Array of errors to aggregate (mix of Error and Sass instances allowed)
|
|
34
34
|
*/
|
|
@@ -44,9 +44,9 @@ export default class Tantrum extends AggregateError {
|
|
|
44
44
|
* Reports all aggregated errors to the terminal with formatted output.
|
|
45
45
|
* Shows a header with error count, then delegates to each Sass instance
|
|
46
46
|
* for individual error reporting.
|
|
47
|
-
*
|
|
47
|
+
*
|
|
48
48
|
* @param nerdMode - Whether to include detailed stack traces in output
|
|
49
|
-
*
|
|
49
|
+
*
|
|
50
50
|
* @example
|
|
51
51
|
* ```typescript
|
|
52
52
|
* try {
|
|
@@ -62,20 +62,20 @@ export default class Tantrum extends AggregateError {
|
|
|
62
62
|
/**
|
|
63
63
|
* Factory method to create a Tantrum instance.
|
|
64
64
|
* Follows the same pattern as Sass.new() for consistency.
|
|
65
|
-
*
|
|
65
|
+
*
|
|
66
66
|
* @param message - The aggregate error message
|
|
67
67
|
* @param errors - Array of errors to aggregate
|
|
68
68
|
* @returns New Tantrum instance with all errors wrapped as Sass
|
|
69
|
-
*
|
|
69
|
+
*
|
|
70
70
|
* @example
|
|
71
71
|
* ```typescript
|
|
72
72
|
* // Typical usage pattern
|
|
73
73
|
* throw Tantrum.new("Someone ate all my Runts!", [
|
|
74
74
|
* emptyRuntsBoxError,
|
|
75
|
-
* emptyRuntsBoxError,
|
|
75
|
+
* emptyRuntsBoxError,
|
|
76
76
|
* emptyRuntsBoxError
|
|
77
77
|
* ])
|
|
78
78
|
* ```
|
|
79
79
|
*/
|
|
80
80
|
static new(message: string, errors?: Array<Error | Sass>): Tantrum
|
|
81
|
-
}
|
|
81
|
+
}
|
package/src/types/Term.d.ts
CHANGED