@brianbuie/node-kit 0.15.0 → 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 +209 -202
- package/dist/index.d.mts +52 -525
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +187 -230
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -5
- package/src/Cache.ts +4 -3
- package/src/Dir.test.ts +11 -0
- package/src/Dir.ts +24 -23
- 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,32 +130,32 @@ 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;
|
|
103
|
-
constructor(inputPath
|
|
104
|
-
get pathUnsafe()
|
|
105
|
-
get path()
|
|
106
|
-
get name()
|
|
107
|
-
dir(subPath
|
|
108
|
-
tempDir(subPath
|
|
109
|
-
sanitize(filename: string)
|
|
110
|
-
filepath(base: string)
|
|
111
|
-
file(base
|
|
135
|
+
isTemp: boolean;
|
|
136
|
+
constructor(inputPath = Format.date("ymd"), options: DirOptions = {})
|
|
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
|
|
|
125
|
-
See also: [DirOptions](#type-diroptions), [File](#class-file), [temp](#variable-temp)
|
|
158
|
+
See also: [DirOptions](#type-diroptions), [File](#class-file), [Format](#class-format), [temp](#variable-temp)
|
|
126
159
|
|
|
127
160
|
<details>
|
|
128
161
|
|
|
@@ -131,9 +164,9 @@ See also: [DirOptions](#type-diroptions), [File](#class-file), [temp](#variable-
|
|
|
131
164
|
### Constructor
|
|
132
165
|
|
|
133
166
|
```ts
|
|
134
|
-
constructor(inputPath
|
|
167
|
+
constructor(inputPath = Format.date("ymd"), options: DirOptions = {})
|
|
135
168
|
```
|
|
136
|
-
See also: [DirOptions](#type-diroptions)
|
|
169
|
+
See also: [DirOptions](#type-diroptions), [Format](#class-format)
|
|
137
170
|
|
|
138
171
|
Argument Details
|
|
139
172
|
|
|
@@ -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
|
|
189
|
+
dir(subPath = Format.date("ymd"), options: DirOptions = { temp: this.isTemp }): Dir
|
|
157
190
|
```
|
|
158
|
-
See also: [DirOptions](#type-diroptions), [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
|
|
|
@@ -175,16 +208,17 @@ const child = folder.dir('path/to/dir');
|
|
|
175
208
|
|
|
176
209
|
### Method file
|
|
177
210
|
|
|
178
|
-
Create a new file in this directory
|
|
211
|
+
Create a new file in this directory. Filename defaults to `YYYYMMDD-HHMMSS` if not provided
|
|
179
212
|
|
|
180
213
|
```ts
|
|
181
|
-
file(base
|
|
214
|
+
file(base = Format.date("ymd-hms")): File
|
|
182
215
|
```
|
|
216
|
+
See also: [File](#class-file), [Format](#class-format)
|
|
183
217
|
|
|
184
218
|
### Method filepath
|
|
185
219
|
|
|
186
220
|
```ts
|
|
187
|
-
filepath(base: string)
|
|
221
|
+
filepath(base: string): string
|
|
188
222
|
```
|
|
189
223
|
|
|
190
224
|
Argument Details
|
|
@@ -197,7 +231,7 @@ Example
|
|
|
197
231
|
```ts
|
|
198
232
|
const folder = new Dir('example');
|
|
199
233
|
const filepath = folder.resolve('file.json');
|
|
200
|
-
// 'example/file.json'
|
|
234
|
+
// '/path/to/example/file.json'
|
|
201
235
|
```
|
|
202
236
|
|
|
203
237
|
### Method tempDir
|
|
@@ -205,8 +239,9 @@ const filepath = folder.resolve('file.json');
|
|
|
205
239
|
Creates a new temp directory inside current Dir
|
|
206
240
|
|
|
207
241
|
```ts
|
|
208
|
-
tempDir(subPath
|
|
242
|
+
tempDir(subPath?: string): Dir
|
|
209
243
|
```
|
|
244
|
+
See also: [Dir](#class-dir)
|
|
210
245
|
|
|
211
246
|
Argument Details
|
|
212
247
|
|
|
@@ -226,13 +261,13 @@ Includes basic methods for requesting and parsing responses
|
|
|
226
261
|
|
|
227
262
|
```ts
|
|
228
263
|
export class Fetcher {
|
|
229
|
-
defaultOptions;
|
|
264
|
+
defaultOptions: FetchOptions;
|
|
230
265
|
constructor(opts: FetchOptions = {})
|
|
231
266
|
buildUrl(route: Route, opts: FetchOptions = {}): [
|
|
232
267
|
URL,
|
|
233
268
|
string
|
|
234
269
|
]
|
|
235
|
-
buildHeaders(route: Route, opts: FetchOptions = {})
|
|
270
|
+
buildHeaders(route: Route, opts: FetchOptions = {}): HeadersInit & Record<string, string>
|
|
236
271
|
buildRequest(route: Route, opts: FetchOptions = {}): [
|
|
237
272
|
Request,
|
|
238
273
|
FetchOptions,
|
|
@@ -266,7 +301,7 @@ See also: [FetchOptions](#type-fetchoptions), [Route](#type-route)
|
|
|
266
301
|
Merges options to get headers. Useful when extending the Fetcher class to add custom auth.
|
|
267
302
|
|
|
268
303
|
```ts
|
|
269
|
-
buildHeaders(route: Route, opts: FetchOptions = {})
|
|
304
|
+
buildHeaders(route: Route, opts: FetchOptions = {}): HeadersInit & Record<string, string>
|
|
270
305
|
```
|
|
271
306
|
See also: [FetchOptions](#type-fetchoptions), [Route](#type-route)
|
|
272
307
|
|
|
@@ -326,33 +361,35 @@ Represents a file on the file system. If the file doesn't exist, it is created t
|
|
|
326
361
|
|
|
327
362
|
```ts
|
|
328
363
|
export class File {
|
|
329
|
-
path;
|
|
330
|
-
root;
|
|
331
|
-
dir;
|
|
332
|
-
base;
|
|
333
|
-
name;
|
|
334
|
-
ext;
|
|
335
|
-
type;
|
|
364
|
+
path: string;
|
|
365
|
+
root: string;
|
|
366
|
+
dir: string;
|
|
367
|
+
base: string;
|
|
368
|
+
name: string;
|
|
369
|
+
ext: string;
|
|
370
|
+
type?: string;
|
|
336
371
|
constructor(filepath: string)
|
|
337
|
-
#resolve(filepath: string)
|
|
338
|
-
get exists()
|
|
372
|
+
#resolve(filepath: string): string
|
|
373
|
+
get exists(): boolean
|
|
339
374
|
get stats(): Partial<fs.Stats>
|
|
340
|
-
delete()
|
|
341
|
-
read()
|
|
342
|
-
lines()
|
|
343
|
-
get readStream()
|
|
344
|
-
get writeStream()
|
|
345
|
-
write(contents: string | ReadableStream)
|
|
346
|
-
append(lines: string | string[])
|
|
347
|
-
json<T>(contents?: T)
|
|
348
|
-
static get json()
|
|
349
|
-
ndjson<T extends object>(lines?: T | T[])
|
|
350
|
-
static get ndjson()
|
|
351
|
-
async csv<T extends object>(rows?: T[],
|
|
352
|
-
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
|
|
353
388
|
}
|
|
354
389
|
```
|
|
355
390
|
|
|
391
|
+
See also: [FileTypeCsv](#class-filetypecsv), [FileTypeJson](#class-filetypejson), [FileTypeNdjson](#class-filetypendjson)
|
|
392
|
+
|
|
356
393
|
<details>
|
|
357
394
|
|
|
358
395
|
<summary>Class File Details</summary>
|
|
@@ -363,14 +400,15 @@ creates file if it doesn't exist, appends string or array of strings as new line
|
|
|
363
400
|
File always ends with '\n', so contents don't need to be read before appending
|
|
364
401
|
|
|
365
402
|
```ts
|
|
366
|
-
append(lines: string | string[])
|
|
403
|
+
append(lines: string | string[]): void
|
|
367
404
|
```
|
|
368
405
|
|
|
369
406
|
### Method csv
|
|
370
407
|
|
|
371
408
|
```ts
|
|
372
|
-
async csv<T extends object>(rows?: T[],
|
|
409
|
+
async csv<T extends object>(rows?: T[], options?: FileTypeCsvOptions<T>): Promise<FileTypeCsv<T>>
|
|
373
410
|
```
|
|
411
|
+
See also: [FileTypeCsv](#class-filetypecsv)
|
|
374
412
|
|
|
375
413
|
Returns
|
|
376
414
|
|
|
@@ -390,14 +428,15 @@ await file.write([{ col: 'val2' }, { col: 'val3' }]); // ✅ Writes multiple row
|
|
|
390
428
|
Deletes the file if it exists
|
|
391
429
|
|
|
392
430
|
```ts
|
|
393
|
-
delete()
|
|
431
|
+
delete(): void
|
|
394
432
|
```
|
|
395
433
|
|
|
396
434
|
### Method json
|
|
397
435
|
|
|
398
436
|
```ts
|
|
399
|
-
json<T>(contents?: T)
|
|
437
|
+
json<T>(contents?: T): FileTypeJson<T>
|
|
400
438
|
```
|
|
439
|
+
See also: [FileTypeJson](#class-filetypejson)
|
|
401
440
|
|
|
402
441
|
Returns
|
|
403
442
|
|
|
@@ -419,7 +458,7 @@ file.write({ something: 'else' }) // ✅ data is typed as object
|
|
|
419
458
|
### Method lines
|
|
420
459
|
|
|
421
460
|
```ts
|
|
422
|
-
lines()
|
|
461
|
+
lines(): string[]
|
|
423
462
|
```
|
|
424
463
|
|
|
425
464
|
Returns
|
|
@@ -429,8 +468,9 @@ lines as strings, removes trailing '\n'
|
|
|
429
468
|
### Method ndjson
|
|
430
469
|
|
|
431
470
|
```ts
|
|
432
|
-
ndjson<T extends object>(lines?: T | T[])
|
|
471
|
+
ndjson<T extends object>(lines?: T | T[]): FileTypeNdjson<T>
|
|
433
472
|
```
|
|
473
|
+
See also: [FileTypeNdjson](#class-filetypendjson)
|
|
434
474
|
|
|
435
475
|
Returns
|
|
436
476
|
|
|
@@ -439,7 +479,7 @@ FileTypeNdjson adaptor for current File, adds '.ndjson' extension if not present
|
|
|
439
479
|
### Method read
|
|
440
480
|
|
|
441
481
|
```ts
|
|
442
|
-
read()
|
|
482
|
+
read(): string | undefined
|
|
443
483
|
```
|
|
444
484
|
|
|
445
485
|
Returns
|
|
@@ -457,23 +497,25 @@ A generic file adaptor, extended by specific file type implementations
|
|
|
457
497
|
|
|
458
498
|
```ts
|
|
459
499
|
export class FileType {
|
|
460
|
-
file;
|
|
500
|
+
file: File;
|
|
461
501
|
constructor(filepath: string, contents?: string)
|
|
462
|
-
get path()
|
|
463
|
-
get root()
|
|
464
|
-
get dir()
|
|
465
|
-
get base()
|
|
466
|
-
get name()
|
|
467
|
-
get ext()
|
|
468
|
-
get type()
|
|
469
|
-
get exists()
|
|
470
|
-
get stats()
|
|
471
|
-
delete()
|
|
472
|
-
get readStream()
|
|
473
|
-
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
|
|
474
514
|
}
|
|
475
515
|
```
|
|
476
516
|
|
|
517
|
+
See also: [File](#class-file)
|
|
518
|
+
|
|
477
519
|
Links: [API](#api), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
|
|
478
520
|
|
|
479
521
|
---
|
|
@@ -484,10 +526,11 @@ Input rows as objects, keys are used as column headers
|
|
|
484
526
|
|
|
485
527
|
```ts
|
|
486
528
|
export class FileTypeCsv<Row extends object> extends FileType {
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
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[]>
|
|
491
534
|
}
|
|
492
535
|
```
|
|
493
536
|
|
|
@@ -499,7 +542,7 @@ Links: [API](#api), [Classes](#classes), [Functions](#functions), [Types](#types
|
|
|
499
542
|
## Class: FileTypeJson
|
|
500
543
|
|
|
501
544
|
A .json file that maintains data type when reading/writing.
|
|
502
|
-
> ⚠️ This is mildly unsafe,
|
|
545
|
+
> ⚠️ This is mildly unsafe, json files should be validated at runtime!
|
|
503
546
|
|
|
504
547
|
Examples
|
|
505
548
|
|
|
@@ -517,8 +560,8 @@ file.write({ something: 'else' }) // ✅ data is typed as object
|
|
|
517
560
|
```ts
|
|
518
561
|
export class FileTypeJson<T> extends FileType {
|
|
519
562
|
constructor(filepath: string, contents?: T)
|
|
520
|
-
read()
|
|
521
|
-
write(contents: T)
|
|
563
|
+
read(): T | undefined
|
|
564
|
+
write(contents: T): void
|
|
522
565
|
}
|
|
523
566
|
```
|
|
524
567
|
|
|
@@ -534,8 +577,8 @@ New-line delimited json file (.ndjson)
|
|
|
534
577
|
```ts
|
|
535
578
|
export class FileTypeNdjson<T extends object> extends FileType {
|
|
536
579
|
constructor(filepath: string, lines?: T | T[])
|
|
537
|
-
append(lines: T | T[])
|
|
538
|
-
lines()
|
|
580
|
+
append(lines: T | T[]): void
|
|
581
|
+
lines(): T[]
|
|
539
582
|
}
|
|
540
583
|
```
|
|
541
584
|
|
|
@@ -550,11 +593,11 @@ Helpers for formatting dates, times, and numbers as strings
|
|
|
550
593
|
|
|
551
594
|
```ts
|
|
552
595
|
export class Format {
|
|
553
|
-
static date(formatStr: "iso" | "ymd" | "ymd-hm" | "ymd-hms" | "h:m:s" | string = "iso", d: DateArg<Date> = new Date())
|
|
554
|
-
static round(n: number, places = 0)
|
|
555
|
-
static plural(amount: number, singular: string, multiple?: string)
|
|
556
|
-
static ms(ms: number, style?: "digital")
|
|
557
|
-
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
|
|
558
601
|
}
|
|
559
602
|
```
|
|
560
603
|
|
|
@@ -567,7 +610,7 @@ export class Format {
|
|
|
567
610
|
date-fns format() with some shortcuts
|
|
568
611
|
|
|
569
612
|
```ts
|
|
570
|
-
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
|
|
571
614
|
```
|
|
572
615
|
|
|
573
616
|
Argument Details
|
|
@@ -592,7 +635,7 @@ Format.date('h:m:s') // '13:56:45'
|
|
|
592
635
|
Make millisecond durations actually readable (eg "123ms", "3.56s", "1m 34s", "3h 24m", "2d 4h")
|
|
593
636
|
|
|
594
637
|
```ts
|
|
595
|
-
static ms(ms: number, style?: "digital")
|
|
638
|
+
static ms(ms: number, style?: "digital"): string
|
|
596
639
|
```
|
|
597
640
|
|
|
598
641
|
Argument Details
|
|
@@ -607,7 +650,7 @@ Argument Details
|
|
|
607
650
|
Round a number to a specific set of places
|
|
608
651
|
|
|
609
652
|
```ts
|
|
610
|
-
static round(n: number, places = 0)
|
|
653
|
+
static round(n: number, places = 0): string
|
|
611
654
|
```
|
|
612
655
|
|
|
613
656
|
</details>
|
|
@@ -617,125 +660,60 @@ Links: [API](#api), [Classes](#classes), [Functions](#functions), [Types](#types
|
|
|
617
660
|
---
|
|
618
661
|
## Class: Log
|
|
619
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
|
+
|
|
620
668
|
```ts
|
|
621
669
|
export class Log {
|
|
622
|
-
static
|
|
623
|
-
static #
|
|
624
|
-
static
|
|
625
|
-
static
|
|
626
|
-
static
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
static
|
|
631
|
-
static
|
|
632
|
-
static
|
|
633
|
-
static
|
|
634
|
-
static info(...input: unknown[])
|
|
635
|
-
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
|
|
636
682
|
}
|
|
637
683
|
```
|
|
638
684
|
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
<summary>Class Log Details</summary>
|
|
642
|
-
|
|
643
|
-
### Method
|
|
644
|
-
|
|
645
|
-
Gcloud parses JSON in stdout
|
|
646
|
-
|
|
647
|
-
```ts
|
|
648
|
-
static #toGcloud(entry: Entry)
|
|
649
|
-
```
|
|
650
|
-
|
|
651
|
-
### Method
|
|
652
|
-
|
|
653
|
-
Includes colors and better inspection for logging during dev
|
|
654
|
-
|
|
655
|
-
```ts
|
|
656
|
-
static #toConsole(entry: Entry, color: ChalkInstance)
|
|
657
|
-
```
|
|
658
|
-
|
|
659
|
-
### Method alert
|
|
660
|
-
|
|
661
|
-
Events that require action or attention immediately
|
|
662
|
-
|
|
663
|
-
```ts
|
|
664
|
-
static alert(...input: unknown[])
|
|
665
|
-
```
|
|
666
|
-
|
|
667
|
-
### Method debug
|
|
668
|
-
|
|
669
|
-
Debug or trace information
|
|
670
|
-
|
|
671
|
-
```ts
|
|
672
|
-
static debug(...input: unknown[])
|
|
673
|
-
```
|
|
674
|
-
|
|
675
|
-
### Method error
|
|
676
|
-
|
|
677
|
-
Events that cause problems
|
|
678
|
-
|
|
679
|
-
```ts
|
|
680
|
-
static error(...input: unknown[])
|
|
681
|
-
```
|
|
682
|
-
|
|
683
|
-
### Method info
|
|
684
|
-
|
|
685
|
-
Routine information, such as ongoing status or performance
|
|
686
|
-
|
|
687
|
-
```ts
|
|
688
|
-
static info(...input: unknown[])
|
|
689
|
-
```
|
|
690
|
-
|
|
691
|
-
### Method notice
|
|
685
|
+
See also: [LogDetails](#type-logdetails), [LogLevel](#type-loglevel), [LogOptions](#type-logoptions)
|
|
692
686
|
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
```ts
|
|
696
|
-
static notice(...input: unknown[])
|
|
697
|
-
```
|
|
698
|
-
|
|
699
|
-
### Method prepare
|
|
700
|
-
|
|
701
|
-
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)
|
|
702
688
|
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
message?: string;
|
|
706
|
-
details: unknown[];
|
|
707
|
-
}
|
|
708
|
-
```
|
|
689
|
+
---
|
|
690
|
+
## Class: TypeWriter
|
|
709
691
|
|
|
710
|
-
|
|
692
|
+
Wrapper for [quicktype-core](https://github.com/glideapps/quicktype)
|
|
711
693
|
|
|
712
|
-
|
|
694
|
+
Example
|
|
713
695
|
|
|
714
696
|
```ts
|
|
715
|
-
|
|
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`
|
|
716
701
|
```
|
|
717
702
|
|
|
718
|
-
</details>
|
|
719
|
-
|
|
720
|
-
Links: [API](#api), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
|
|
721
|
-
|
|
722
|
-
---
|
|
723
|
-
## Class: TypeWriter
|
|
724
|
-
|
|
725
703
|
```ts
|
|
726
704
|
export class TypeWriter {
|
|
727
|
-
moduleName;
|
|
705
|
+
moduleName: string;
|
|
728
706
|
input = qt.jsonInputForTargetLanguage("typescript");
|
|
729
|
-
outDir;
|
|
730
|
-
outFile;
|
|
731
|
-
qtSettings
|
|
707
|
+
outDir: string;
|
|
708
|
+
outFile: string;
|
|
709
|
+
qtSettings: Partial<qt.Options>;
|
|
732
710
|
constructor(moduleName: string, settings: {
|
|
733
711
|
outDir?: string;
|
|
734
712
|
outFile?: string;
|
|
735
713
|
} & Partial<qt.Options> = {})
|
|
736
|
-
async addMember(name: string, _samples: any[])
|
|
737
|
-
async toString()
|
|
738
|
-
async toFile()
|
|
714
|
+
async addMember(name: string, _samples: any[]): Promise<void>
|
|
715
|
+
async toString(): Promise<string>
|
|
716
|
+
async toFile(): Promise<void>
|
|
739
717
|
}
|
|
740
718
|
```
|
|
741
719
|
|
|
@@ -748,7 +726,7 @@ export class TypeWriter {
|
|
|
748
726
|
function toString() { [native code] }
|
|
749
727
|
|
|
750
728
|
```ts
|
|
751
|
-
async toString()
|
|
729
|
+
async toString(): Promise<string>
|
|
752
730
|
```
|
|
753
731
|
|
|
754
732
|
</details>
|
|
@@ -769,9 +747,6 @@ Links: [API](#api), [Classes](#classes), [Functions](#functions), [Types](#types
|
|
|
769
747
|
|
|
770
748
|
## Function: snapshot
|
|
771
749
|
|
|
772
|
-
Allows special objects (Error, Headers, Set) to be included in JSON.stringify output.
|
|
773
|
-
Functions are removed
|
|
774
|
-
|
|
775
750
|
```ts
|
|
776
751
|
export function snapshot(i: unknown, max = 50, depth = 0): any
|
|
777
752
|
```
|
|
@@ -782,7 +757,7 @@ Links: [API](#api), [Classes](#classes), [Functions](#functions), [Types](#types
|
|
|
782
757
|
## Function: timeout
|
|
783
758
|
|
|
784
759
|
```ts
|
|
785
|
-
export async function timeout(ms: number)
|
|
760
|
+
export async function timeout(ms: number): Promise<void>
|
|
786
761
|
```
|
|
787
762
|
|
|
788
763
|
Links: [API](#api), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
|
|
@@ -794,6 +769,9 @@ Links: [API](#api), [Classes](#classes), [Functions](#functions), [Types](#types
|
|
|
794
769
|
| --- |
|
|
795
770
|
| [DirOptions](#type-diroptions) |
|
|
796
771
|
| [FetchOptions](#type-fetchoptions) |
|
|
772
|
+
| [LogDetails](#type-logdetails) |
|
|
773
|
+
| [LogLevel](#type-loglevel) |
|
|
774
|
+
| [LogOptions](#type-logoptions) |
|
|
797
775
|
| [Query](#type-query) |
|
|
798
776
|
| [Route](#type-route) |
|
|
799
777
|
|
|
@@ -832,6 +810,35 @@ See also: [Query](#type-query), [timeout](#function-timeout)
|
|
|
832
810
|
|
|
833
811
|
Links: [API](#api), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
|
|
834
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
|
+
|
|
835
842
|
---
|
|
836
843
|
## Type: Query
|
|
837
844
|
|
|
@@ -892,13 +899,13 @@ Links: [API](#api), [Classes](#classes), [Functions](#functions), [Types](#types
|
|
|
892
899
|
Typecheck and run all tests from `*.test.ts` files
|
|
893
900
|
|
|
894
901
|
```
|
|
895
|
-
|
|
902
|
+
npm run test
|
|
896
903
|
```
|
|
897
904
|
|
|
898
905
|
Format with Prettier, generate API docs for this Readme
|
|
899
906
|
|
|
900
907
|
```
|
|
901
|
-
|
|
908
|
+
npm run build
|
|
902
909
|
```
|
|
903
910
|
|
|
904
911
|
Release a new version
|