@gesslar/toolkit 1.5.0 → 1.6.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.
Files changed (46) hide show
  1. package/package.json +2 -2
  2. package/src/browser/lib/Data.js +0 -7
  3. package/src/browser/lib/Disposer.js +1 -24
  4. package/src/browser/lib/Util.js +1 -11
  5. package/src/types/browser/lib/Data.d.ts.map +1 -1
  6. package/src/types/browser/lib/Disposer.d.ts +0 -6
  7. package/src/types/browser/lib/Disposer.d.ts.map +1 -1
  8. package/src/types/browser/lib/Util.d.ts +0 -1
  9. package/src/types/browser/lib/Util.d.ts.map +1 -1
  10. package/src/browser/lib/Hook.js +0 -82
  11. package/src/browser/lib/test.js +0 -25
  12. package/src/browser/lib/test2.js +0 -46
  13. package/src/types/Cache.d.ts +0 -30
  14. package/src/types/Collection.d.ts +0 -321
  15. package/src/types/Contract.d.ts +0 -162
  16. package/src/types/Data.d.ts +0 -175
  17. package/src/types/DirectoryObject.d.ts +0 -135
  18. package/src/types/FS.d.ts +0 -40
  19. package/src/types/FileObject.d.ts +0 -388
  20. package/src/types/Glog.d.ts +0 -345
  21. package/src/types/Sass.d.ts +0 -24
  22. package/src/types/Schemer.d.ts +0 -179
  23. package/src/types/Tantrum.d.ts +0 -81
  24. package/src/types/Term.d.ts +0 -16
  25. package/src/types/Terms.d.ts +0 -145
  26. package/src/types/Type.d.ts +0 -26
  27. package/src/types/Util.d.ts +0 -275
  28. package/src/types/Valid.d.ts +0 -13
  29. package/src/types/browser/lib/Disposable.d.ts +0 -35
  30. package/src/types/browser/lib/Disposable.d.ts.map +0 -10
  31. package/src/types/browser/lib/Hook.d.ts +0 -11
  32. package/src/types/browser/lib/Hook.d.ts.map +0 -1
  33. package/src/types/browser/lib/test.d.ts +0 -2
  34. package/src/types/browser/lib/test.d.ts.map +0 -1
  35. package/src/types/browser/lib/test2.d.ts +0 -2
  36. package/src/types/browser/lib/test2.d.ts.map +0 -1
  37. package/src/types/lib/Chide.d.ts +0 -37
  38. package/src/types/lib/Chide.d.ts.map +0 -1
  39. package/src/types/lib/Collection.d.ts +0 -246
  40. package/src/types/lib/Collection.d.ts.map +0 -1
  41. package/src/types/lib/Data.d.ts +0 -206
  42. package/src/types/lib/Data.d.ts.map +0 -1
  43. package/src/types/lib/Disposable.d.ts +0 -33
  44. package/src/types/lib/Disposable.d.ts.map +0 -10
  45. package/src/types/lib/TypeSpec.d.ts +0 -92
  46. package/src/types/lib/TypeSpec.d.ts.map +0 -1
@@ -1,345 +0,0 @@
1
- // Implementation: ../lib/Glog.js
2
-
3
- /**
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.
37
- *
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)`
43
- *
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
52
- *
53
- * @example
54
- * ```typescript
55
- * import { Glog } from '@gesslar/toolkit'
56
- *
57
- * // Simple usage with static configuration
58
- * Glog.setLogLevel(3).setLogPrefix('[MyApp]')
59
- * Glog(0, 'Critical error!')
60
- * Glog(2, 'Debug info:', data)
61
- *
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')
67
- *
68
- * // Fluent instance creation
69
- * const log = Glog.create()
70
- * .withName('Database')
71
- * .withLogLevel(3)
72
- * .withColors()
73
- *
74
- * // Color template literals
75
- * logger.colorize`{success}Operation completed{/} in {bold}${time}ms{/}`
76
- * logger.success('All tests passed!')
77
- * ```
78
- */
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
-
192
- /**
193
- * Set instance log level (fluent).
194
- *
195
- * @param level - Log level (0-5)
196
- * @returns This instance for chaining
197
- */
198
- withLogLevel(level: number): this
199
-
200
- /**
201
- * Set instance prefix (fluent).
202
- *
203
- * @param prefix - Message prefix
204
- * @returns This instance for chaining
205
- */
206
- withPrefix(prefix: string): this
207
-
208
- /**
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).
300
- *
301
- * @param args - Log level (optional) followed by message arguments
302
- */
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
320
- }
321
-
322
- /**
323
- * Callable interface for the proxied Glog export.
324
- * The default export is a Proxy that allows both class and function usage.
325
- */
326
- interface GlogCallable {
327
- /**
328
- * Log a message with optional level specification.
329
- * First argument can be a number (level) or part of the message.
330
- *
331
- * @param args - Either (level: number, ...messages) or (...messages)
332
- */
333
- (...args: unknown[]): void
334
- }
335
-
336
- /**
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)`
342
- */
343
- declare const GlogExport: typeof Glog & GlogCallable
344
-
345
- export default GlogExport
@@ -1,24 +0,0 @@
1
- // Implementation: ../lib/Sass.js
2
- // Type definitions for Sass error class
3
-
4
- /**
5
- * Custom error class for toolkit errors.
6
- */
7
- export default class Sass extends Error {
8
- constructor(message: string, ...arg: Array<any>)
9
-
10
- /** Array of trace messages */
11
- readonly trace: Array<string>
12
-
13
- /** Add a trace message and return this instance for chaining */
14
- addTrace(message: string): this
15
-
16
- /** Report the error to the terminal */
17
- report(nerdMode?: boolean): void
18
-
19
- /** Create a Sass from an existing Error object */
20
- static from(error: Error, message: string): Sass
21
-
22
- /** Factory method to create or enhance Sass instances */
23
- static new(message: string, error?: Error | Sass): Sass
24
- }
@@ -1,179 +0,0 @@
1
- // Implementation: ../lib/Schemer.js
2
-
3
- import type { ValidateFunction, ErrorObject } from 'ajv'
4
-
5
- /**
6
- * Schemer provides utilities for compiling and validating JSON schemas using AJV.
7
- *
8
- * This class serves as a convenient wrapper around AJV (Another JSON Schema Validator)
9
- * with toolkit-specific enhancements for error reporting and schema compilation.
10
- *
11
- * @example
12
- * ```typescript
13
- * // Create validator from schema object
14
- * const validator = await Schemer.from({
15
- * type: "object",
16
- * properties: {
17
- * name: { type: "string" },
18
- * age: { type: "number", minimum: 0 }
19
- * },
20
- * required: ["name"]
21
- * })
22
- *
23
- * // Validate data
24
- * const isValid = validator({ name: "John", age: 30 })
25
- * ```
26
- *
27
- * @example
28
- * ```typescript
29
- * // Create validator from file
30
- * const file = new FileObject("schema.json")
31
- * const validator = await Schemer.fromFile(file)
32
- * ```
33
- *
34
- * @example
35
- * ```typescript
36
- * // Get raw AJV validator and format errors
37
- * const validate = Schemer.getValidator(schema)
38
- * const isValid = validate(data)
39
- * if (!isValid) {
40
- * const errorReport = Schemer.reportValidationErrors(validate.errors)
41
- * console.error("Validation failed:", errorReport)
42
- * }
43
- * ```
44
- */
45
- declare class Schemer {
46
- /**
47
- * Creates an AJV validator function from a schema file
48
- *
49
- * @param file - FileObject pointing to a JSON/YAML schema file
50
- * @param options - AJV configuration options
51
- * @returns Promise resolving to AJV validator function
52
- *
53
- * @throws {Sass} If file cannot be loaded or schema is invalid
54
- * @throws {Sass} If file is not a FileObject or options are invalid
55
- *
56
- * @example
57
- * ```typescript
58
- * const file = new FileObject("user-schema.json")
59
- * const validator = await Schemer.fromFile(file, {
60
- * allErrors: true,
61
- * verbose: true
62
- * })
63
- *
64
- * const isValid = validator({ name: "John", age: 30 })
65
- * if (!isValid) {
66
- * console.log("Errors:", validator.errors)
67
- * }
68
- * ```
69
- */
70
- static fromFile(
71
- file: import('./FileObject.js').default,
72
- options?: object
73
- ): Promise<ValidateFunction>
74
-
75
- /**
76
- * Creates an AJV validator function from a schema object
77
- *
78
- * @param schemaData - JSON schema object to compile
79
- * @param options - AJV configuration options
80
- * @returns Promise resolving to AJV validator function
81
- *
82
- * @throws {Sass} If schema data or options are not plain objects
83
- * @throws {Sass} If schema compilation fails
84
- *
85
- * @example
86
- * ```typescript
87
- * const validator = await Schemer.from({
88
- * type: "object",
89
- * properties: {
90
- * id: { type: "string", format: "uuid" },
91
- * email: { type: "string", format: "email" }
92
- * },
93
- * required: ["id", "email"]
94
- * }, {
95
- * formats: true,
96
- * allErrors: true
97
- * })
98
- *
99
- * const isValid = validator({ id: "123", email: "test@example.com" })
100
- * if (!isValid) {
101
- * console.log("Errors:", validator.errors)
102
- * }
103
- * ```
104
- */
105
- static from(schemaData?: object, options?: object): Promise<ValidateFunction>
106
-
107
- /**
108
- * Creates a raw AJV validator function from a schema object
109
- *
110
- * @param schema - The JSON schema to compile
111
- * @param options - AJV configuration options (defaults to {allErrors: true, verbose: true})
112
- * @returns AJV validator function with .errors property when validation fails
113
- *
114
- * @example
115
- * ```typescript
116
- * const validate = Schemer.getValidator({
117
- * type: "string",
118
- * minLength: 1,
119
- * maxLength: 100
120
- * })
121
- *
122
- * const isValid = validate("Hello World")
123
- * if (!isValid) {
124
- * console.log("Errors:", validate.errors)
125
- * }
126
- * ```
127
- *
128
- * @example
129
- * ```typescript
130
- * // Custom AJV options
131
- * const validate = Schemer.getValidator(schema, {
132
- * allErrors: false,
133
- * verbose: false,
134
- * strict: true
135
- * })
136
- * ```
137
- */
138
- static getValidator(
139
- schema: object,
140
- options?: { allErrors?: boolean; verbose?: boolean; [key: string]: unknown }
141
- ): ValidateFunction
142
-
143
- /**
144
- * Formats AJV validation errors into a human-readable report
145
- *
146
- * @param errors - Array of AJV error objects from failed validation
147
- * @returns Formatted error message with helpful details and suggestions
148
- *
149
- * @example
150
- * ```typescript
151
- * const validate = Schemer.getValidator(schema)
152
- * const isValid = validate(data)
153
- *
154
- * if (!isValid) {
155
- * const report = Schemer.reportValidationErrors(validate.errors)
156
- * console.error("Validation failed:")
157
- * console.error(report)
158
- * // Output:
159
- * // - "(root)" must be object
160
- * // ➜ Expected type: object
161
- * // ➜ Received value: "string"
162
- * }
163
- * ```
164
- *
165
- * @example
166
- * ```typescript
167
- * // The error report includes helpful details:
168
- * // - Property paths and error descriptions
169
- * // - Expected vs actual types
170
- * // - Missing required fields
171
- * // - Pattern matching failures
172
- * // - Closest matches for enum values
173
- * // - Unexpected additional properties
174
- * ```
175
- */
176
- static reportValidationErrors(errors: ErrorObject[] | null | undefined): string
177
- }
178
-
179
- export default Schemer
@@ -1,81 +0,0 @@
1
- // Implementation: ../lib/Tantrum.js
2
- // Type definitions for Tantrum aggregate error class
3
-
4
- import Sass from './Sass'
5
-
6
- /**
7
- * Custom aggregate error class that extends AggregateError.
8
- *
9
- * Automatically wraps plain Error objects in Sass instances while preserving
10
- * existing Sass errors, providing consistent formatted reporting for
11
- * multiple error scenarios.
12
- *
13
- * @example
14
- * ```typescript
15
- * // Collect multiple errors and throw as a bundle
16
- * const errors = [new Error("thing 1"), sassError, new Error("thing 3")]
17
- * throw Tantrum.new("Multiple validation failures", errors)
18
- *
19
- * // Later, in error handling:
20
- * catch (error) {
21
- * if (error instanceof Tantrum) {
22
- * error.report() // Reports all errors with Sass formatting
23
- * }
24
- * }
25
- * ```
26
- */
27
- export default class Tantrum extends AggregateError {
28
- /**
29
- * Creates a new Tantrum instance.
30
- * Plain Error objects are automatically wrapped in Sass instances.
31
- *
32
- * @param message - The aggregate error message describing the overall failure
33
- * @param errors - Array of errors to aggregate (mix of Error and Sass instances allowed)
34
- */
35
- constructor(message: string, errors?: Array<Error | Sass>)
36
-
37
- /** Name of the error class */
38
- readonly name: 'Tantrum'
39
-
40
- /** Array of aggregated errors (all wrapped as Sass instances) */
41
- readonly errors: Array<Sass>
42
-
43
- /**
44
- * Reports all aggregated errors to the terminal with formatted output.
45
- * Shows a header with error count, then delegates to each Sass instance
46
- * for individual error reporting.
47
- *
48
- * @param nerdMode - Whether to include detailed stack traces in output
49
- *
50
- * @example
51
- * ```typescript
52
- * try {
53
- * throw Tantrum.new("Batch failed", [error1, error2])
54
- * } catch (tantrum) {
55
- * tantrum.report() // User-friendly output
56
- * tantrum.report(true) // Includes full stack traces
57
- * }
58
- * ```
59
- */
60
- report(nerdMode?: boolean): void
61
-
62
- /**
63
- * Factory method to create a Tantrum instance.
64
- * Follows the same pattern as Sass.new() for consistency.
65
- *
66
- * @param message - The aggregate error message
67
- * @param errors - Array of errors to aggregate
68
- * @returns New Tantrum instance with all errors wrapped as Sass
69
- *
70
- * @example
71
- * ```typescript
72
- * // Typical usage pattern
73
- * throw Tantrum.new("Someone ate all my Runts!", [
74
- * emptyRuntsBoxError,
75
- * emptyRuntsBoxError,
76
- * emptyRuntsBoxError
77
- * ])
78
- * ```
79
- */
80
- static new(message: string, errors?: Array<Error | Sass>): Tantrum
81
- }
@@ -1,16 +0,0 @@
1
- // Implementation: ../lib/Term.js
2
- // Type definitions for Term utility class
3
-
4
- export default class Term {
5
- static log(...arg: Array<unknown>): void
6
- static info(...arg: Array<unknown>): void
7
- static warn(...arg: Array<unknown>): void
8
- static error(...arg: Array<unknown>): void
9
- static debug(...arg: Array<unknown>): void
10
- static status(args: string | Array<string | [string, string]>, options?: { silent?: boolean }): void
11
- static terminalMessage(argList: string | Array<string | [string, string] | [string, string, string]>): string
12
- static terminalBracket(parts: [string, string, [string, string]?]): string
13
- static resetTerminal(): Promise<void>
14
- static clearLines(num: number): Promise<void>
15
- static directWrite(output: string): Promise<void>
16
- }