@brianbuie/node-kit 0.15.1 → 0.16.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/README.md +203 -197
- package/dist/index.d.mts +47 -520
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +113 -156
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -5
- package/src/Cache.ts +4 -3
- package/src/Dir.ts +19 -19
- package/src/Fetcher.ts +2 -2
- package/src/File.ts +70 -56
- package/src/Format.ts +5 -5
- package/src/Log.test.ts +16 -6
- package/src/Log.ts +58 -98
- package/src/TypeWriter.ts +15 -7
- package/src/snapshot.ts +3 -2
- package/src/timeout.ts +1 -1
package/README.md
CHANGED
|
@@ -14,7 +14,7 @@ npm add @brianbuie/node-kit
|
|
|
14
14
|
import { Fetcher, Log } from '@brianbuie/node-kit';
|
|
15
15
|
```
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
## Extending Config
|
|
18
18
|
|
|
19
19
|
### tsconfig.json
|
|
20
20
|
|
|
@@ -43,6 +43,34 @@ const config = {
|
|
|
43
43
|
export default config;
|
|
44
44
|
```
|
|
45
45
|
|
|
46
|
+
# Changelog
|
|
47
|
+
|
|
48
|
+
## 0.16
|
|
49
|
+
|
|
50
|
+
- `Log` rewritten using [pino](https://github.com/pinojs/pino) under the hood. Will require updates in projects:
|
|
51
|
+
- `message` is still first argument, but second argument should include all details, instead of using an arbitrary number of args
|
|
52
|
+
- Errors should use the `err` key in the details object, instead of passing the error as an argument
|
|
53
|
+
- Dev defaults to `debug` level, prod defaults to `info`, use `LOG_LEVEL=info` env variable
|
|
54
|
+
- Removed `alert` and `notice` levels
|
|
55
|
+
- New `fatal` level above `error`
|
|
56
|
+
- New `trace` level, below `debug`
|
|
57
|
+
- `Dir.txtFiles` renamed from `Dir.textFiles`, for consistency with other file types
|
|
58
|
+
- `JsonFileType` & `NdJsonFileType` no longer user the `snapshot` hack to stringify special objects. Will remove `snapshot` in the future.
|
|
59
|
+
- `FileTypeCsv`
|
|
60
|
+
- Second argument changed from `keys` array to options object (`keys` can be provided as option)
|
|
61
|
+
- Automatic parsing of numbers, booleans, and nulls can be disabled (`parseNumbers`, `parseBooleans`, `parseNulls`)
|
|
62
|
+
- Removed `@types/node` as peer dependency
|
|
63
|
+
- Added explicit return types for everything
|
|
64
|
+
|
|
65
|
+
## 0.15.1
|
|
66
|
+
|
|
67
|
+
- `Dir` uses YYYYMMDD as default name
|
|
68
|
+
- `File` uses YYYYMMDD-HHmmss as default name
|
|
69
|
+
|
|
70
|
+
## 0.15
|
|
71
|
+
|
|
72
|
+
- `TypeWriter` option for `outFile`, defaults to `[moduleName].types.ts`
|
|
73
|
+
|
|
46
74
|
# API
|
|
47
75
|
|
|
48
76
|
<!--#region ts2md-api-merged-here-->
|
|
@@ -77,8 +105,11 @@ so stale data can still be used if needed.
|
|
|
77
105
|
|
|
78
106
|
```ts
|
|
79
107
|
export class Cache<T> {
|
|
80
|
-
file
|
|
81
|
-
|
|
108
|
+
file: FileTypeJson<{
|
|
109
|
+
savedAt: string;
|
|
110
|
+
data: T;
|
|
111
|
+
}>;
|
|
112
|
+
ttl: Duration;
|
|
82
113
|
constructor(key: string, ttl: number | Duration, initialData?: T)
|
|
83
114
|
write(data: T)
|
|
84
115
|
read(): [
|
|
@@ -88,6 +119,8 @@ export class Cache<T> {
|
|
|
88
119
|
}
|
|
89
120
|
```
|
|
90
121
|
|
|
122
|
+
See also: [FileTypeJson](#class-filetypejson)
|
|
123
|
+
|
|
91
124
|
Links: [API](#api), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
|
|
92
125
|
|
|
93
126
|
---
|
|
@@ -97,28 +130,28 @@ Reference to a specific directory with methods to create and list files.
|
|
|
97
130
|
|
|
98
131
|
```ts
|
|
99
132
|
export class Dir {
|
|
100
|
-
#inputPath;
|
|
133
|
+
#inputPath: string;
|
|
101
134
|
#resolved?: string;
|
|
102
|
-
isTemp;
|
|
135
|
+
isTemp: boolean;
|
|
103
136
|
constructor(inputPath = Format.date("ymd"), options: DirOptions = {})
|
|
104
|
-
get pathUnsafe()
|
|
105
|
-
get path()
|
|
106
|
-
get name()
|
|
107
|
-
dir(subPath = Format.date("ymd"), options: DirOptions = { temp: this.isTemp })
|
|
108
|
-
tempDir(subPath?: string)
|
|
109
|
-
sanitize(filename: string)
|
|
110
|
-
filepath(base: string)
|
|
111
|
-
file(base = Format.date("ymd-hms"))
|
|
137
|
+
get pathUnsafe(): string
|
|
138
|
+
get path(): string
|
|
139
|
+
get name(): string
|
|
140
|
+
dir(subPath = Format.date("ymd"), options: DirOptions = { temp: this.isTemp }): Dir
|
|
141
|
+
tempDir(subPath?: string): Dir
|
|
142
|
+
sanitize(filename: string): string
|
|
143
|
+
filepath(base: string): string
|
|
144
|
+
file(base = Format.date("ymd-hms")): File
|
|
112
145
|
get contents(): (Dir | File)[]
|
|
113
|
-
get dirs()
|
|
114
|
-
get files()
|
|
115
|
-
get videos()
|
|
116
|
-
get images()
|
|
117
|
-
get jsonFiles()
|
|
118
|
-
get ndjsonFiles()
|
|
119
|
-
get csvFiles()
|
|
120
|
-
get
|
|
121
|
-
clear()
|
|
146
|
+
get dirs(): Dir[]
|
|
147
|
+
get files(): File[]
|
|
148
|
+
get videos(): File[]
|
|
149
|
+
get images(): File[]
|
|
150
|
+
get jsonFiles(): File[]
|
|
151
|
+
get ndjsonFiles(): File[]
|
|
152
|
+
get csvFiles(): File[]
|
|
153
|
+
get txtFiles(): File[]
|
|
154
|
+
clear(): void
|
|
122
155
|
}
|
|
123
156
|
```
|
|
124
157
|
|
|
@@ -145,7 +178,7 @@ Argument Details
|
|
|
145
178
|
Deletes the contents of the directory. Only allowed if created with `temp` option set to `true` (or created with `dir.tempDir` method).
|
|
146
179
|
|
|
147
180
|
```ts
|
|
148
|
-
clear()
|
|
181
|
+
clear(): void
|
|
149
182
|
```
|
|
150
183
|
|
|
151
184
|
### Method dir
|
|
@@ -153,9 +186,9 @@ clear()
|
|
|
153
186
|
Create a new Dir inside the current Dir
|
|
154
187
|
|
|
155
188
|
```ts
|
|
156
|
-
dir(subPath = Format.date("ymd"), options: DirOptions = { temp: this.isTemp })
|
|
189
|
+
dir(subPath = Format.date("ymd"), options: DirOptions = { temp: this.isTemp }): Dir
|
|
157
190
|
```
|
|
158
|
-
See also: [DirOptions](#type-diroptions), [Format](#class-format), [temp](#variable-temp)
|
|
191
|
+
See also: [Dir](#class-dir), [DirOptions](#type-diroptions), [Format](#class-format), [temp](#variable-temp)
|
|
159
192
|
|
|
160
193
|
Argument Details
|
|
161
194
|
|
|
@@ -178,14 +211,14 @@ const child = folder.dir('path/to/dir');
|
|
|
178
211
|
Create a new file in this directory. Filename defaults to `YYYYMMDD-HHMMSS` if not provided
|
|
179
212
|
|
|
180
213
|
```ts
|
|
181
|
-
file(base = Format.date("ymd-hms"))
|
|
214
|
+
file(base = Format.date("ymd-hms")): File
|
|
182
215
|
```
|
|
183
|
-
See also: [Format](#class-format)
|
|
216
|
+
See also: [File](#class-file), [Format](#class-format)
|
|
184
217
|
|
|
185
218
|
### Method filepath
|
|
186
219
|
|
|
187
220
|
```ts
|
|
188
|
-
filepath(base: string)
|
|
221
|
+
filepath(base: string): string
|
|
189
222
|
```
|
|
190
223
|
|
|
191
224
|
Argument Details
|
|
@@ -206,8 +239,9 @@ const filepath = folder.resolve('file.json');
|
|
|
206
239
|
Creates a new temp directory inside current Dir
|
|
207
240
|
|
|
208
241
|
```ts
|
|
209
|
-
tempDir(subPath?: string)
|
|
242
|
+
tempDir(subPath?: string): Dir
|
|
210
243
|
```
|
|
244
|
+
See also: [Dir](#class-dir)
|
|
211
245
|
|
|
212
246
|
Argument Details
|
|
213
247
|
|
|
@@ -227,13 +261,13 @@ Includes basic methods for requesting and parsing responses
|
|
|
227
261
|
|
|
228
262
|
```ts
|
|
229
263
|
export class Fetcher {
|
|
230
|
-
defaultOptions;
|
|
264
|
+
defaultOptions: FetchOptions;
|
|
231
265
|
constructor(opts: FetchOptions = {})
|
|
232
266
|
buildUrl(route: Route, opts: FetchOptions = {}): [
|
|
233
267
|
URL,
|
|
234
268
|
string
|
|
235
269
|
]
|
|
236
|
-
buildHeaders(route: Route, opts: FetchOptions = {})
|
|
270
|
+
buildHeaders(route: Route, opts: FetchOptions = {}): HeadersInit & Record<string, string>
|
|
237
271
|
buildRequest(route: Route, opts: FetchOptions = {}): [
|
|
238
272
|
Request,
|
|
239
273
|
FetchOptions,
|
|
@@ -267,7 +301,7 @@ See also: [FetchOptions](#type-fetchoptions), [Route](#type-route)
|
|
|
267
301
|
Merges options to get headers. Useful when extending the Fetcher class to add custom auth.
|
|
268
302
|
|
|
269
303
|
```ts
|
|
270
|
-
buildHeaders(route: Route, opts: FetchOptions = {})
|
|
304
|
+
buildHeaders(route: Route, opts: FetchOptions = {}): HeadersInit & Record<string, string>
|
|
271
305
|
```
|
|
272
306
|
See also: [FetchOptions](#type-fetchoptions), [Route](#type-route)
|
|
273
307
|
|
|
@@ -327,33 +361,35 @@ Represents a file on the file system. If the file doesn't exist, it is created t
|
|
|
327
361
|
|
|
328
362
|
```ts
|
|
329
363
|
export class File {
|
|
330
|
-
path;
|
|
331
|
-
root;
|
|
332
|
-
dir;
|
|
333
|
-
base;
|
|
334
|
-
name;
|
|
335
|
-
ext;
|
|
336
|
-
type;
|
|
364
|
+
path: string;
|
|
365
|
+
root: string;
|
|
366
|
+
dir: string;
|
|
367
|
+
base: string;
|
|
368
|
+
name: string;
|
|
369
|
+
ext: string;
|
|
370
|
+
type?: string;
|
|
337
371
|
constructor(filepath: string)
|
|
338
|
-
#resolve(filepath: string)
|
|
339
|
-
get exists()
|
|
372
|
+
#resolve(filepath: string): string
|
|
373
|
+
get exists(): boolean
|
|
340
374
|
get stats(): Partial<fs.Stats>
|
|
341
|
-
delete()
|
|
342
|
-
read()
|
|
343
|
-
lines()
|
|
344
|
-
get readStream()
|
|
345
|
-
get writeStream()
|
|
346
|
-
write(contents: string | ReadableStream)
|
|
347
|
-
append(lines: string | string[])
|
|
348
|
-
json<T>(contents?: T)
|
|
349
|
-
static get json()
|
|
350
|
-
ndjson<T extends object>(lines?: T | T[])
|
|
351
|
-
static get ndjson()
|
|
352
|
-
async csv<T extends object>(rows?: T[],
|
|
353
|
-
static get csv()
|
|
375
|
+
delete(): void
|
|
376
|
+
read(): string | undefined
|
|
377
|
+
lines(): string[]
|
|
378
|
+
get readStream(): fs.ReadStream | Readable
|
|
379
|
+
get writeStream(): fs.WriteStream
|
|
380
|
+
write(contents: string | ReadableStream): void | Promise<void>
|
|
381
|
+
append(lines: string | string[]): void
|
|
382
|
+
json<T>(contents?: T): FileTypeJson<T>
|
|
383
|
+
static get json(): typeof FileTypeJson
|
|
384
|
+
ndjson<T extends object>(lines?: T | T[]): FileTypeNdjson<T>
|
|
385
|
+
static get ndjson(): typeof FileTypeNdjson
|
|
386
|
+
async csv<T extends object>(rows?: T[], options?: FileTypeCsvOptions<T>): Promise<FileTypeCsv<T>>
|
|
387
|
+
static get csv(): typeof FileTypeCsv
|
|
354
388
|
}
|
|
355
389
|
```
|
|
356
390
|
|
|
391
|
+
See also: [FileTypeCsv](#class-filetypecsv), [FileTypeJson](#class-filetypejson), [FileTypeNdjson](#class-filetypendjson)
|
|
392
|
+
|
|
357
393
|
<details>
|
|
358
394
|
|
|
359
395
|
<summary>Class File Details</summary>
|
|
@@ -364,14 +400,15 @@ creates file if it doesn't exist, appends string or array of strings as new line
|
|
|
364
400
|
File always ends with '\n', so contents don't need to be read before appending
|
|
365
401
|
|
|
366
402
|
```ts
|
|
367
|
-
append(lines: string | string[])
|
|
403
|
+
append(lines: string | string[]): void
|
|
368
404
|
```
|
|
369
405
|
|
|
370
406
|
### Method csv
|
|
371
407
|
|
|
372
408
|
```ts
|
|
373
|
-
async csv<T extends object>(rows?: T[],
|
|
409
|
+
async csv<T extends object>(rows?: T[], options?: FileTypeCsvOptions<T>): Promise<FileTypeCsv<T>>
|
|
374
410
|
```
|
|
411
|
+
See also: [FileTypeCsv](#class-filetypecsv)
|
|
375
412
|
|
|
376
413
|
Returns
|
|
377
414
|
|
|
@@ -391,14 +428,15 @@ await file.write([{ col: 'val2' }, { col: 'val3' }]); // ✅ Writes multiple row
|
|
|
391
428
|
Deletes the file if it exists
|
|
392
429
|
|
|
393
430
|
```ts
|
|
394
|
-
delete()
|
|
431
|
+
delete(): void
|
|
395
432
|
```
|
|
396
433
|
|
|
397
434
|
### Method json
|
|
398
435
|
|
|
399
436
|
```ts
|
|
400
|
-
json<T>(contents?: T)
|
|
437
|
+
json<T>(contents?: T): FileTypeJson<T>
|
|
401
438
|
```
|
|
439
|
+
See also: [FileTypeJson](#class-filetypejson)
|
|
402
440
|
|
|
403
441
|
Returns
|
|
404
442
|
|
|
@@ -420,7 +458,7 @@ file.write({ something: 'else' }) // ✅ data is typed as object
|
|
|
420
458
|
### Method lines
|
|
421
459
|
|
|
422
460
|
```ts
|
|
423
|
-
lines()
|
|
461
|
+
lines(): string[]
|
|
424
462
|
```
|
|
425
463
|
|
|
426
464
|
Returns
|
|
@@ -430,8 +468,9 @@ lines as strings, removes trailing '\n'
|
|
|
430
468
|
### Method ndjson
|
|
431
469
|
|
|
432
470
|
```ts
|
|
433
|
-
ndjson<T extends object>(lines?: T | T[])
|
|
471
|
+
ndjson<T extends object>(lines?: T | T[]): FileTypeNdjson<T>
|
|
434
472
|
```
|
|
473
|
+
See also: [FileTypeNdjson](#class-filetypendjson)
|
|
435
474
|
|
|
436
475
|
Returns
|
|
437
476
|
|
|
@@ -440,7 +479,7 @@ FileTypeNdjson adaptor for current File, adds '.ndjson' extension if not present
|
|
|
440
479
|
### Method read
|
|
441
480
|
|
|
442
481
|
```ts
|
|
443
|
-
read()
|
|
482
|
+
read(): string | undefined
|
|
444
483
|
```
|
|
445
484
|
|
|
446
485
|
Returns
|
|
@@ -458,23 +497,25 @@ A generic file adaptor, extended by specific file type implementations
|
|
|
458
497
|
|
|
459
498
|
```ts
|
|
460
499
|
export class FileType {
|
|
461
|
-
file;
|
|
500
|
+
file: File;
|
|
462
501
|
constructor(filepath: string, contents?: string)
|
|
463
|
-
get path()
|
|
464
|
-
get root()
|
|
465
|
-
get dir()
|
|
466
|
-
get base()
|
|
467
|
-
get name()
|
|
468
|
-
get ext()
|
|
469
|
-
get type()
|
|
470
|
-
get exists()
|
|
471
|
-
get stats()
|
|
472
|
-
delete()
|
|
473
|
-
get readStream()
|
|
474
|
-
get writeStream()
|
|
502
|
+
get path(): string
|
|
503
|
+
get root(): string
|
|
504
|
+
get dir(): string
|
|
505
|
+
get base(): string
|
|
506
|
+
get name(): string
|
|
507
|
+
get ext(): string
|
|
508
|
+
get type(): string | undefined
|
|
509
|
+
get exists(): boolean
|
|
510
|
+
get stats(): Partial<fs.Stats>
|
|
511
|
+
delete(): void
|
|
512
|
+
get readStream(): fs.ReadStream | Readable
|
|
513
|
+
get writeStream(): fs.WriteStream
|
|
475
514
|
}
|
|
476
515
|
```
|
|
477
516
|
|
|
517
|
+
See also: [File](#class-file)
|
|
518
|
+
|
|
478
519
|
Links: [API](#api), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
|
|
479
520
|
|
|
480
521
|
---
|
|
@@ -485,10 +526,11 @@ Input rows as objects, keys are used as column headers
|
|
|
485
526
|
|
|
486
527
|
```ts
|
|
487
528
|
export class FileTypeCsv<Row extends object> extends FileType {
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
529
|
+
options: FileTypeCsvOptions<Row>;
|
|
530
|
+
constructor(filepath: string, options: FileTypeCsvOptions<Row> = {})
|
|
531
|
+
async write(rows: Row[]): Promise<void>
|
|
532
|
+
#parseVal(val: string): string | number | boolean | null
|
|
533
|
+
async read(): Promise<Row[]>
|
|
492
534
|
}
|
|
493
535
|
```
|
|
494
536
|
|
|
@@ -500,7 +542,7 @@ Links: [API](#api), [Classes](#classes), [Functions](#functions), [Types](#types
|
|
|
500
542
|
## Class: FileTypeJson
|
|
501
543
|
|
|
502
544
|
A .json file that maintains data type when reading/writing.
|
|
503
|
-
> ⚠️ This is mildly unsafe,
|
|
545
|
+
> ⚠️ This is mildly unsafe, json files should be validated at runtime!
|
|
504
546
|
|
|
505
547
|
Examples
|
|
506
548
|
|
|
@@ -518,8 +560,8 @@ file.write({ something: 'else' }) // ✅ data is typed as object
|
|
|
518
560
|
```ts
|
|
519
561
|
export class FileTypeJson<T> extends FileType {
|
|
520
562
|
constructor(filepath: string, contents?: T)
|
|
521
|
-
read()
|
|
522
|
-
write(contents: T)
|
|
563
|
+
read(): T | undefined
|
|
564
|
+
write(contents: T): void
|
|
523
565
|
}
|
|
524
566
|
```
|
|
525
567
|
|
|
@@ -535,8 +577,8 @@ New-line delimited json file (.ndjson)
|
|
|
535
577
|
```ts
|
|
536
578
|
export class FileTypeNdjson<T extends object> extends FileType {
|
|
537
579
|
constructor(filepath: string, lines?: T | T[])
|
|
538
|
-
append(lines: T | T[])
|
|
539
|
-
lines()
|
|
580
|
+
append(lines: T | T[]): void
|
|
581
|
+
lines(): T[]
|
|
540
582
|
}
|
|
541
583
|
```
|
|
542
584
|
|
|
@@ -551,11 +593,11 @@ Helpers for formatting dates, times, and numbers as strings
|
|
|
551
593
|
|
|
552
594
|
```ts
|
|
553
595
|
export class Format {
|
|
554
|
-
static date(formatStr: "iso" | "ymd" | "ymd-hm" | "ymd-hms" | "h:m:s" | string = "iso", d: DateArg<Date> = new Date())
|
|
555
|
-
static round(n: number, places = 0)
|
|
556
|
-
static plural(amount: number, singular: string, multiple?: string)
|
|
557
|
-
static ms(ms: number, style?: "digital")
|
|
558
|
-
static bytes(b: number)
|
|
596
|
+
static date(formatStr: "iso" | "ymd" | "ymd-hm" | "ymd-hms" | "h:m:s" | string = "iso", d: DateArg<Date> = new Date()): string
|
|
597
|
+
static round(n: number, places = 0): string
|
|
598
|
+
static plural(amount: number, singular: string, multiple?: string): string
|
|
599
|
+
static ms(ms: number, style?: "digital"): string
|
|
600
|
+
static bytes(b: number): string
|
|
559
601
|
}
|
|
560
602
|
```
|
|
561
603
|
|
|
@@ -568,7 +610,7 @@ export class Format {
|
|
|
568
610
|
date-fns format() with some shortcuts
|
|
569
611
|
|
|
570
612
|
```ts
|
|
571
|
-
static date(formatStr: "iso" | "ymd" | "ymd-hm" | "ymd-hms" | "h:m:s" | string = "iso", d: DateArg<Date> = new Date())
|
|
613
|
+
static date(formatStr: "iso" | "ymd" | "ymd-hm" | "ymd-hms" | "h:m:s" | string = "iso", d: DateArg<Date> = new Date()): string
|
|
572
614
|
```
|
|
573
615
|
|
|
574
616
|
Argument Details
|
|
@@ -593,7 +635,7 @@ Format.date('h:m:s') // '13:56:45'
|
|
|
593
635
|
Make millisecond durations actually readable (eg "123ms", "3.56s", "1m 34s", "3h 24m", "2d 4h")
|
|
594
636
|
|
|
595
637
|
```ts
|
|
596
|
-
static ms(ms: number, style?: "digital")
|
|
638
|
+
static ms(ms: number, style?: "digital"): string
|
|
597
639
|
```
|
|
598
640
|
|
|
599
641
|
Argument Details
|
|
@@ -608,7 +650,7 @@ Argument Details
|
|
|
608
650
|
Round a number to a specific set of places
|
|
609
651
|
|
|
610
652
|
```ts
|
|
611
|
-
static round(n: number, places = 0)
|
|
653
|
+
static round(n: number, places = 0): string
|
|
612
654
|
```
|
|
613
655
|
|
|
614
656
|
</details>
|
|
@@ -618,125 +660,60 @@ Links: [API](#api), [Classes](#classes), [Functions](#functions), [Types](#types
|
|
|
618
660
|
---
|
|
619
661
|
## Class: Log
|
|
620
662
|
|
|
663
|
+
Wrapper for [pino](https://github.com/pinojs/pino)
|
|
664
|
+
Levels: fatal, error, warn, info, debug, trace
|
|
665
|
+
Use `LOG_LEVL=info` to limit what's printed to console
|
|
666
|
+
Use `Log.configure` to customize the pino instance
|
|
667
|
+
|
|
621
668
|
```ts
|
|
622
669
|
export class Log {
|
|
623
|
-
static
|
|
624
|
-
static #
|
|
625
|
-
static
|
|
626
|
-
static
|
|
627
|
-
static
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
static
|
|
632
|
-
static
|
|
633
|
-
static
|
|
634
|
-
static
|
|
635
|
-
static info(...input: unknown[])
|
|
636
|
-
static debug(...input: unknown[])
|
|
670
|
+
static #logger?: Logger;
|
|
671
|
+
static #options: LogOptions;
|
|
672
|
+
static createLogger(): Logger
|
|
673
|
+
static configure(options: LogOptions = {}): void
|
|
674
|
+
static #getLogger(): Logger
|
|
675
|
+
static #write(level: LogLevel, message: string, details?: LogDetails): void
|
|
676
|
+
static trace(message: string, details?: LogDetails): void
|
|
677
|
+
static debug(message: string, details?: LogDetails): void
|
|
678
|
+
static info(message: string, details?: LogDetails): void
|
|
679
|
+
static warn(message: string, details?: LogDetails): void
|
|
680
|
+
static error(message: string, details?: LogDetails): void
|
|
681
|
+
static fatal(message: string, details?: LogDetails): void
|
|
637
682
|
}
|
|
638
683
|
```
|
|
639
684
|
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
<summary>Class Log Details</summary>
|
|
643
|
-
|
|
644
|
-
### Method
|
|
645
|
-
|
|
646
|
-
Gcloud parses JSON in stdout
|
|
647
|
-
|
|
648
|
-
```ts
|
|
649
|
-
static #toGcloud(entry: Entry)
|
|
650
|
-
```
|
|
651
|
-
|
|
652
|
-
### Method
|
|
653
|
-
|
|
654
|
-
Includes colors and better inspection for logging during dev
|
|
655
|
-
|
|
656
|
-
```ts
|
|
657
|
-
static #toConsole(entry: Entry, color: ChalkInstance)
|
|
658
|
-
```
|
|
659
|
-
|
|
660
|
-
### Method alert
|
|
661
|
-
|
|
662
|
-
Events that require action or attention immediately
|
|
663
|
-
|
|
664
|
-
```ts
|
|
665
|
-
static alert(...input: unknown[])
|
|
666
|
-
```
|
|
667
|
-
|
|
668
|
-
### Method debug
|
|
669
|
-
|
|
670
|
-
Debug or trace information
|
|
671
|
-
|
|
672
|
-
```ts
|
|
673
|
-
static debug(...input: unknown[])
|
|
674
|
-
```
|
|
675
|
-
|
|
676
|
-
### Method error
|
|
677
|
-
|
|
678
|
-
Events that cause problems
|
|
679
|
-
|
|
680
|
-
```ts
|
|
681
|
-
static error(...input: unknown[])
|
|
682
|
-
```
|
|
683
|
-
|
|
684
|
-
### Method info
|
|
685
|
-
|
|
686
|
-
Routine information, such as ongoing status or performance
|
|
687
|
-
|
|
688
|
-
```ts
|
|
689
|
-
static info(...input: unknown[])
|
|
690
|
-
```
|
|
691
|
-
|
|
692
|
-
### Method notice
|
|
685
|
+
See also: [LogDetails](#type-logdetails), [LogLevel](#type-loglevel), [LogOptions](#type-logoptions)
|
|
693
686
|
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
```ts
|
|
697
|
-
static notice(...input: unknown[])
|
|
698
|
-
```
|
|
699
|
-
|
|
700
|
-
### Method prepare
|
|
701
|
-
|
|
702
|
-
Handle first argument being a string or an object with a 'message' prop
|
|
687
|
+
Links: [API](#api), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
|
|
703
688
|
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
message?: string;
|
|
707
|
-
details: unknown[];
|
|
708
|
-
}
|
|
709
|
-
```
|
|
689
|
+
---
|
|
690
|
+
## Class: TypeWriter
|
|
710
691
|
|
|
711
|
-
|
|
692
|
+
Wrapper for [quicktype-core](https://github.com/glideapps/quicktype)
|
|
712
693
|
|
|
713
|
-
|
|
694
|
+
Example
|
|
714
695
|
|
|
715
696
|
```ts
|
|
716
|
-
|
|
697
|
+
const group = new TypeWriter('Group');
|
|
698
|
+
await types.addMember('Thing', [{ a: 1 }, { a: 2, b: 1 }]);
|
|
699
|
+
await types.toFile();
|
|
700
|
+
// type def for `Thing` saved in `types/Group.types.ts`
|
|
717
701
|
```
|
|
718
702
|
|
|
719
|
-
</details>
|
|
720
|
-
|
|
721
|
-
Links: [API](#api), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
|
|
722
|
-
|
|
723
|
-
---
|
|
724
|
-
## Class: TypeWriter
|
|
725
|
-
|
|
726
703
|
```ts
|
|
727
704
|
export class TypeWriter {
|
|
728
|
-
moduleName;
|
|
705
|
+
moduleName: string;
|
|
729
706
|
input = qt.jsonInputForTargetLanguage("typescript");
|
|
730
|
-
outDir;
|
|
731
|
-
outFile;
|
|
732
|
-
qtSettings
|
|
707
|
+
outDir: string;
|
|
708
|
+
outFile: string;
|
|
709
|
+
qtSettings: Partial<qt.Options>;
|
|
733
710
|
constructor(moduleName: string, settings: {
|
|
734
711
|
outDir?: string;
|
|
735
712
|
outFile?: string;
|
|
736
713
|
} & Partial<qt.Options> = {})
|
|
737
|
-
async addMember(name: string, _samples: any[])
|
|
738
|
-
async toString()
|
|
739
|
-
async toFile()
|
|
714
|
+
async addMember(name: string, _samples: any[]): Promise<void>
|
|
715
|
+
async toString(): Promise<string>
|
|
716
|
+
async toFile(): Promise<void>
|
|
740
717
|
}
|
|
741
718
|
```
|
|
742
719
|
|
|
@@ -749,7 +726,7 @@ export class TypeWriter {
|
|
|
749
726
|
function toString() { [native code] }
|
|
750
727
|
|
|
751
728
|
```ts
|
|
752
|
-
async toString()
|
|
729
|
+
async toString(): Promise<string>
|
|
753
730
|
```
|
|
754
731
|
|
|
755
732
|
</details>
|
|
@@ -770,9 +747,6 @@ Links: [API](#api), [Classes](#classes), [Functions](#functions), [Types](#types
|
|
|
770
747
|
|
|
771
748
|
## Function: snapshot
|
|
772
749
|
|
|
773
|
-
Allows special objects (Error, Headers, Set) to be included in JSON.stringify output.
|
|
774
|
-
Functions are removed
|
|
775
|
-
|
|
776
750
|
```ts
|
|
777
751
|
export function snapshot(i: unknown, max = 50, depth = 0): any
|
|
778
752
|
```
|
|
@@ -783,7 +757,7 @@ Links: [API](#api), [Classes](#classes), [Functions](#functions), [Types](#types
|
|
|
783
757
|
## Function: timeout
|
|
784
758
|
|
|
785
759
|
```ts
|
|
786
|
-
export async function timeout(ms: number)
|
|
760
|
+
export async function timeout(ms: number): Promise<void>
|
|
787
761
|
```
|
|
788
762
|
|
|
789
763
|
Links: [API](#api), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
|
|
@@ -795,6 +769,9 @@ Links: [API](#api), [Classes](#classes), [Functions](#functions), [Types](#types
|
|
|
795
769
|
| --- |
|
|
796
770
|
| [DirOptions](#type-diroptions) |
|
|
797
771
|
| [FetchOptions](#type-fetchoptions) |
|
|
772
|
+
| [LogDetails](#type-logdetails) |
|
|
773
|
+
| [LogLevel](#type-loglevel) |
|
|
774
|
+
| [LogOptions](#type-logoptions) |
|
|
798
775
|
| [Query](#type-query) |
|
|
799
776
|
| [Route](#type-route) |
|
|
800
777
|
|
|
@@ -833,6 +810,35 @@ See also: [Query](#type-query), [timeout](#function-timeout)
|
|
|
833
810
|
|
|
834
811
|
Links: [API](#api), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
|
|
835
812
|
|
|
813
|
+
---
|
|
814
|
+
## Type: LogDetails
|
|
815
|
+
|
|
816
|
+
```ts
|
|
817
|
+
export type LogDetails = Record<string, unknown>
|
|
818
|
+
```
|
|
819
|
+
|
|
820
|
+
Links: [API](#api), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
|
|
821
|
+
|
|
822
|
+
---
|
|
823
|
+
## Type: LogLevel
|
|
824
|
+
|
|
825
|
+
```ts
|
|
826
|
+
export type LogLevel = "trace" | "debug" | "info" | "warn" | "error" | "fatal"
|
|
827
|
+
```
|
|
828
|
+
|
|
829
|
+
Links: [API](#api), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
|
|
830
|
+
|
|
831
|
+
---
|
|
832
|
+
## Type: LogOptions
|
|
833
|
+
|
|
834
|
+
```ts
|
|
835
|
+
export type LogOptions = pino.LoggerOptions & {
|
|
836
|
+
environment?: string;
|
|
837
|
+
}
|
|
838
|
+
```
|
|
839
|
+
|
|
840
|
+
Links: [API](#api), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
|
|
841
|
+
|
|
836
842
|
---
|
|
837
843
|
## Type: Query
|
|
838
844
|
|
|
@@ -893,13 +899,13 @@ Links: [API](#api), [Classes](#classes), [Functions](#functions), [Types](#types
|
|
|
893
899
|
Typecheck and run all tests from `*.test.ts` files
|
|
894
900
|
|
|
895
901
|
```
|
|
896
|
-
|
|
902
|
+
npm run test
|
|
897
903
|
```
|
|
898
904
|
|
|
899
905
|
Format with Prettier, generate API docs for this Readme
|
|
900
906
|
|
|
901
907
|
```
|
|
902
|
-
|
|
908
|
+
npm run build
|
|
903
909
|
```
|
|
904
910
|
|
|
905
911
|
Release a new version
|