@brianbuie/node-kit 0.12.5 → 0.13.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 +64 -35
- package/dist/index.d.mts +41 -22
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +44 -28
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -2
- package/src/Cache.ts +2 -2
- package/src/Dir.test.ts +28 -8
- package/src/Dir.ts +20 -21
- package/src/Fetcher.ts +4 -4
- package/src/File.test.ts +3 -3
- package/src/Log.ts +22 -3
- package/src/TypeWriter.ts +1 -1
- package/src/index.ts +1 -1
- package/src/snapshot.ts +4 -4
- package/src/timeout.ts +1 -1
- package/tsconfig.json +1 -0
package/README.md
CHANGED
|
@@ -63,7 +63,6 @@ Links: [API](#api), [Classes](#classes), [Functions](#functions), [Types](#types
|
|
|
63
63
|
| [FileTypeNdjson](#class-filetypendjson) |
|
|
64
64
|
| [Format](#class-format) |
|
|
65
65
|
| [Log](#class-log) |
|
|
66
|
-
| [TempDir](#class-tempdir) |
|
|
67
66
|
| [TypeWriter](#class-typewriter) |
|
|
68
67
|
|
|
69
68
|
Links: [API](#api), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
|
|
@@ -95,24 +94,26 @@ Links: [API](#api), [Classes](#classes), [Functions](#functions), [Types](#types
|
|
|
95
94
|
## Class: Dir
|
|
96
95
|
|
|
97
96
|
Reference to a specific directory with methods to create and list files.
|
|
98
|
-
Default path: '.'
|
|
99
|
-
> Created on file system the first time .path is read or any methods are used
|
|
100
97
|
|
|
101
98
|
```ts
|
|
102
99
|
export class Dir {
|
|
103
100
|
#inputPath;
|
|
104
101
|
#resolved?: string;
|
|
105
|
-
|
|
102
|
+
isTemp;
|
|
103
|
+
constructor(inputPath: string, options: DirOptions = {})
|
|
106
104
|
get path()
|
|
107
|
-
dir(subPath: string)
|
|
105
|
+
dir(subPath: string, options: DirOptions = { temp: this.isTemp })
|
|
108
106
|
tempDir(subPath: string)
|
|
109
107
|
sanitize(filename: string)
|
|
110
108
|
filepath(base: string)
|
|
111
109
|
file(base: string)
|
|
112
110
|
get files()
|
|
111
|
+
clear()
|
|
113
112
|
}
|
|
114
113
|
```
|
|
115
114
|
|
|
115
|
+
See also: [DirOptions](#type-diroptions), [temp](#variable-temp)
|
|
116
|
+
|
|
116
117
|
<details>
|
|
117
118
|
|
|
118
119
|
<summary>Class Dir Details</summary>
|
|
@@ -120,8 +121,9 @@ export class Dir {
|
|
|
120
121
|
### Constructor
|
|
121
122
|
|
|
122
123
|
```ts
|
|
123
|
-
constructor(inputPath =
|
|
124
|
+
constructor(inputPath: string, options: DirOptions = {})
|
|
124
125
|
```
|
|
126
|
+
See also: [DirOptions](#type-diroptions)
|
|
125
127
|
|
|
126
128
|
Argument Details
|
|
127
129
|
|
|
@@ -133,13 +135,16 @@ Argument Details
|
|
|
133
135
|
Create a new Dir inside the current Dir
|
|
134
136
|
|
|
135
137
|
```ts
|
|
136
|
-
dir(subPath: string)
|
|
138
|
+
dir(subPath: string, options: DirOptions = { temp: this.isTemp })
|
|
137
139
|
```
|
|
140
|
+
See also: [DirOptions](#type-diroptions), [temp](#variable-temp)
|
|
138
141
|
|
|
139
142
|
Argument Details
|
|
140
143
|
|
|
141
144
|
+ **subPath**
|
|
142
145
|
+ joined with parent Dir's path to make new Dir
|
|
146
|
+
+ **options**
|
|
147
|
+
+ include `{ temp: true }` to enable the `.clear()` method. If current Dir is temporary, child directories will also be temporary.
|
|
143
148
|
|
|
144
149
|
Example
|
|
145
150
|
|
|
@@ -171,7 +176,7 @@ const filepath = folder.resolve('file.json');
|
|
|
171
176
|
|
|
172
177
|
### Method tempDir
|
|
173
178
|
|
|
174
|
-
Creates a new
|
|
179
|
+
Creates a new temp directory inside current Dir
|
|
175
180
|
|
|
176
181
|
```ts
|
|
177
182
|
tempDir(subPath: string)
|
|
@@ -591,6 +596,7 @@ export class Log {
|
|
|
591
596
|
message?: string;
|
|
592
597
|
details: unknown[];
|
|
593
598
|
}
|
|
599
|
+
static alert(...input: unknown[])
|
|
594
600
|
static error(...input: unknown[])
|
|
595
601
|
static warn(...input: unknown[])
|
|
596
602
|
static notice(...input: unknown[])
|
|
@@ -619,54 +625,63 @@ Includes colors and better inspection for logging during dev
|
|
|
619
625
|
static #toConsole(entry: Entry, color: ChalkInstance)
|
|
620
626
|
```
|
|
621
627
|
|
|
622
|
-
### Method
|
|
628
|
+
### Method alert
|
|
623
629
|
|
|
624
|
-
|
|
630
|
+
Events that require action or attention immediately
|
|
625
631
|
|
|
626
632
|
```ts
|
|
627
|
-
static
|
|
633
|
+
static alert(...input: unknown[])
|
|
628
634
|
```
|
|
629
635
|
|
|
630
|
-
### Method
|
|
636
|
+
### Method debug
|
|
631
637
|
|
|
632
|
-
|
|
638
|
+
Debug or trace information
|
|
633
639
|
|
|
634
640
|
```ts
|
|
635
|
-
static
|
|
636
|
-
message?: string;
|
|
637
|
-
details: unknown[];
|
|
638
|
-
}
|
|
641
|
+
static debug(...input: unknown[])
|
|
639
642
|
```
|
|
640
643
|
|
|
641
|
-
|
|
644
|
+
### Method error
|
|
642
645
|
|
|
643
|
-
|
|
646
|
+
Events that cause problems
|
|
644
647
|
|
|
645
|
-
|
|
646
|
-
|
|
648
|
+
```ts
|
|
649
|
+
static error(...input: unknown[])
|
|
650
|
+
```
|
|
647
651
|
|
|
648
|
-
|
|
649
|
-
|
|
652
|
+
### Method info
|
|
653
|
+
|
|
654
|
+
Routine information, such as ongoing status or performance
|
|
650
655
|
|
|
651
656
|
```ts
|
|
652
|
-
|
|
653
|
-
constructor(inputPath = `./.temp`)
|
|
654
|
-
clear()
|
|
655
|
-
}
|
|
657
|
+
static info(...input: unknown[])
|
|
656
658
|
```
|
|
657
659
|
|
|
658
|
-
|
|
660
|
+
### Method notice
|
|
659
661
|
|
|
660
|
-
|
|
662
|
+
Normal but significant events, such as start up, shut down, or a configuration change
|
|
661
663
|
|
|
662
|
-
|
|
664
|
+
```ts
|
|
665
|
+
static notice(...input: unknown[])
|
|
666
|
+
```
|
|
663
667
|
|
|
664
|
-
### Method
|
|
668
|
+
### Method prepare
|
|
665
669
|
|
|
666
|
-
|
|
670
|
+
Handle first argument being a string or an object with a 'message' prop
|
|
667
671
|
|
|
668
672
|
```ts
|
|
669
|
-
|
|
673
|
+
static prepare(...input: unknown[]): {
|
|
674
|
+
message?: string;
|
|
675
|
+
details: unknown[];
|
|
676
|
+
}
|
|
677
|
+
```
|
|
678
|
+
|
|
679
|
+
### Method warn
|
|
680
|
+
|
|
681
|
+
Events that might cause problems
|
|
682
|
+
|
|
683
|
+
```ts
|
|
684
|
+
static warn(...input: unknown[])
|
|
670
685
|
```
|
|
671
686
|
|
|
672
687
|
</details>
|
|
@@ -721,8 +736,8 @@ Links: [API](#api), [Classes](#classes), [Functions](#functions), [Types](#types
|
|
|
721
736
|
|
|
722
737
|
## Function: snapshot
|
|
723
738
|
|
|
724
|
-
Allows special objects (Error, Headers, Set) to be included in JSON.stringify output
|
|
725
|
-
|
|
739
|
+
Allows special objects (Error, Headers, Set) to be included in JSON.stringify output.
|
|
740
|
+
Functions are removed
|
|
726
741
|
|
|
727
742
|
```ts
|
|
728
743
|
export function snapshot(i: unknown, max = 50, depth = 0): any
|
|
@@ -744,6 +759,7 @@ Links: [API](#api), [Classes](#classes), [Functions](#functions), [Types](#types
|
|
|
744
759
|
|
|
745
760
|
| |
|
|
746
761
|
| --- |
|
|
762
|
+
| [DirOptions](#type-diroptions) |
|
|
747
763
|
| [FetchOptions](#type-fetchoptions) |
|
|
748
764
|
| [Query](#type-query) |
|
|
749
765
|
| [Route](#type-route) |
|
|
@@ -752,6 +768,19 @@ Links: [API](#api), [Classes](#classes), [Functions](#functions), [Types](#types
|
|
|
752
768
|
|
|
753
769
|
---
|
|
754
770
|
|
|
771
|
+
## Type: DirOptions
|
|
772
|
+
|
|
773
|
+
```ts
|
|
774
|
+
export type DirOptions = {
|
|
775
|
+
temp?: boolean;
|
|
776
|
+
}
|
|
777
|
+
```
|
|
778
|
+
|
|
779
|
+
See also: [temp](#variable-temp)
|
|
780
|
+
|
|
781
|
+
Links: [API](#api), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
|
|
782
|
+
|
|
783
|
+
---
|
|
755
784
|
## Type: FetchOptions
|
|
756
785
|
|
|
757
786
|
```ts
|
package/dist/index.d.mts
CHANGED
|
@@ -141,36 +141,45 @@ declare class FileTypeCsv<Row extends object> extends FileType {
|
|
|
141
141
|
}
|
|
142
142
|
//#endregion
|
|
143
143
|
//#region src/Dir.d.ts
|
|
144
|
+
type DirOptions = {
|
|
145
|
+
temp?: boolean;
|
|
146
|
+
};
|
|
144
147
|
/**
|
|
145
148
|
* Reference to a specific directory with methods to create and list files.
|
|
146
|
-
*
|
|
147
|
-
*
|
|
149
|
+
* @param inputPath
|
|
150
|
+
* The path of the directory, created on file system the first time `.path` is read or any methods are used
|
|
151
|
+
* @param options
|
|
152
|
+
* include `{ temp: true }` to enable the `.clear()` method
|
|
148
153
|
*/
|
|
149
154
|
declare class Dir {
|
|
150
155
|
#private;
|
|
156
|
+
isTemp: boolean;
|
|
151
157
|
/**
|
|
152
158
|
* @param path can be relative to workspace or absolute
|
|
153
159
|
*/
|
|
154
|
-
constructor(inputPath?:
|
|
160
|
+
constructor(inputPath: string, options?: DirOptions);
|
|
155
161
|
/**
|
|
156
162
|
* The path of this Dir instance. Created on file system the first time this property is read/used.
|
|
157
163
|
*/
|
|
158
164
|
get path(): string;
|
|
159
165
|
/**
|
|
160
166
|
* Create a new Dir inside the current Dir
|
|
161
|
-
* @param subPath
|
|
167
|
+
* @param subPath
|
|
168
|
+
* joined with parent Dir's path to make new Dir
|
|
169
|
+
* @param options
|
|
170
|
+
* include `{ temp: true }` to enable the `.clear()` method. If current Dir is temporary, child directories will also be temporary.
|
|
162
171
|
* @example
|
|
163
172
|
* const folder = new Dir('example');
|
|
164
173
|
* // folder.path = '/path/to/cwd/example'
|
|
165
174
|
* const child = folder.dir('path/to/dir');
|
|
166
175
|
* // child.path = '/path/to/cwd/example/path/to/dir'
|
|
167
176
|
*/
|
|
168
|
-
dir(subPath: string):
|
|
177
|
+
dir(subPath: string, options?: DirOptions): this;
|
|
169
178
|
/**
|
|
170
|
-
* Creates a new
|
|
179
|
+
* Creates a new temp directory inside current Dir
|
|
171
180
|
* @param subPath joined with parent Dir's path to make new TempDir
|
|
172
181
|
*/
|
|
173
|
-
tempDir(subPath: string):
|
|
182
|
+
tempDir(subPath: string): this;
|
|
174
183
|
sanitize(filename: string): string;
|
|
175
184
|
/**
|
|
176
185
|
* @param base - The file base (name and extension)
|
|
@@ -182,22 +191,16 @@ declare class Dir {
|
|
|
182
191
|
filepath(base: string): string;
|
|
183
192
|
file(base: string): File;
|
|
184
193
|
get files(): File[];
|
|
194
|
+
clear(): void;
|
|
185
195
|
}
|
|
186
196
|
/**
|
|
187
|
-
*
|
|
188
|
-
* Default path: `./.temp`
|
|
197
|
+
* Current working directory
|
|
189
198
|
*/
|
|
190
|
-
declare
|
|
191
|
-
constructor(inputPath?: string);
|
|
192
|
-
/**
|
|
193
|
-
* > ⚠️ Warning! This deletes the directory!
|
|
194
|
-
*/
|
|
195
|
-
clear(): void;
|
|
196
|
-
}
|
|
199
|
+
declare const cwd: Dir;
|
|
197
200
|
/**
|
|
198
201
|
* ./.temp in current working directory
|
|
199
202
|
*/
|
|
200
|
-
declare const temp:
|
|
203
|
+
declare const temp: Dir;
|
|
201
204
|
//#endregion
|
|
202
205
|
//#region src/Cache.d.ts
|
|
203
206
|
/**
|
|
@@ -335,19 +338,35 @@ declare class Log {
|
|
|
335
338
|
details: unknown[];
|
|
336
339
|
};
|
|
337
340
|
/**
|
|
338
|
-
*
|
|
341
|
+
* Events that require action or attention immediately
|
|
342
|
+
*/
|
|
343
|
+
static alert(...input: unknown[]): Entry;
|
|
344
|
+
/**
|
|
345
|
+
* Events that cause problems
|
|
346
|
+
*/
|
|
347
|
+
static error(...input: unknown[]): Entry;
|
|
348
|
+
/**
|
|
349
|
+
* Events that might cause problems
|
|
339
350
|
*/
|
|
340
|
-
static error(...input: unknown[]): void;
|
|
341
351
|
static warn(...input: unknown[]): Entry;
|
|
352
|
+
/**
|
|
353
|
+
* Normal but significant events, such as start up, shut down, or a configuration change
|
|
354
|
+
*/
|
|
342
355
|
static notice(...input: unknown[]): Entry;
|
|
356
|
+
/**
|
|
357
|
+
* Routine information, such as ongoing status or performance
|
|
358
|
+
*/
|
|
343
359
|
static info(...input: unknown[]): Entry;
|
|
360
|
+
/**
|
|
361
|
+
* Debug or trace information
|
|
362
|
+
*/
|
|
344
363
|
static debug(...input: unknown[]): Entry;
|
|
345
364
|
}
|
|
346
365
|
//#endregion
|
|
347
366
|
//#region src/snapshot.d.ts
|
|
348
367
|
/**
|
|
349
|
-
* Allows special objects (Error, Headers, Set) to be included in JSON.stringify output
|
|
350
|
-
*
|
|
368
|
+
* Allows special objects (Error, Headers, Set) to be included in JSON.stringify output.
|
|
369
|
+
* Functions are removed
|
|
351
370
|
*/
|
|
352
371
|
declare function snapshot(i: unknown, max?: number, depth?: number): any;
|
|
353
372
|
//#endregion
|
|
@@ -807,5 +826,5 @@ declare class TypeWriter {
|
|
|
807
826
|
toFile(): Promise<void>;
|
|
808
827
|
}
|
|
809
828
|
//#endregion
|
|
810
|
-
export { Cache, Dir, type FetchOptions, Fetcher, File, FileType, FileTypeCsv, FileTypeJson, FileTypeNdjson, Format, Log, type Query, type Route,
|
|
829
|
+
export { Cache, Dir, type DirOptions, type FetchOptions, Fetcher, File, FileType, FileTypeCsv, FileTypeJson, FileTypeNdjson, Format, Log, type Query, type Route, TypeWriter, cwd, snapshot, temp, timeout };
|
|
811
830
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/File.ts","../src/Dir.ts","../src/Cache.ts","../src/Fetcher.ts","../src/Format.ts","../src/Log.ts","../src/sn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AAA,YAAU,GAAA,QAAA,CAAA;MAEhB,SAAA,aAAA,6DAAA,CAAA,gBAAA,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAIsE,kBAAA,4DAAA,CAAA,sBAAA,CAAA;MAAX,SAAA,6DAAA,CAAA,WAAA,CAAA;MAgBnB,eAAA,4DAAA,CAAA,aAAA,CAAA;MAK/B,UAAA,0DAAA,CAAA,iBAAA,EAAA;QAUF,SAAA,MAAA,EAAA,KAAA;QAAA,SAAA,KAAA,EAAA,IAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MA/BoD,QAAQ,EAAA,CAAG;4CAgB9B;cAK/B;YAUF"}
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/File.ts","../src/Dir.ts","../src/Cache.ts","../src/Fetcher.ts","../src/Format.ts","../src/Log.ts","../src/snapshot.ts","../src/timeout.ts","../src/TypeWriter.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;;;;;;;cAWa,IAAA;;;;;;;;;;EAAA,IAAA,KAAI,CAAA,CAAA,EAwBF,OAxBE,CAwBM,EAAA,CAAG,KAxBT,CAAA;EAwBS;;;EA0BV,MAAA,CAAA,CAAA,EAAA,IAAA;EAIC;;;EAgCI,IAAA,CAAA,CAAA,EAAA,MAAA,GAAA,SAAA;EAAC;;;EAea,KAAA,CAAA,CAAA,EAAA,MAAA,EAAA;EAAI,IAAA,UAAA,CAAA,CAAA,EAnDvB,EAAA,CAAA,UAmDuB,GAnDvB,QAmDuB;EAAG,IAAA,WAAA,CAAA,CAAA,EA/CzB,EAAA,C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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAIsE,UAAA,0DAAA,CAAA,iBAAA,EAAA;QAAX,SAAA,MAAA,EAAA,KAAA;QAgBnB,SAAA,KAAA,EAAA,IAAA;MAK/B,CAAA,EAAA,OAAA,GAAA,QAAA,CAAA;MAUF,iBAAA,6DAAA,CAAA,oBAAA,CAAA;MAAA,YAAA,0DAAA,CAAA,eAAA,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MA/BoD,QAAQ,EAAA,CAAG;4CAgB9B;cAK/B;YAUF"}
|
package/dist/index.mjs
CHANGED
|
@@ -15,8 +15,8 @@ import * as qt from "quicktype-core";
|
|
|
15
15
|
|
|
16
16
|
//#region src/snapshot.ts
|
|
17
17
|
/**
|
|
18
|
-
* Allows special objects (Error, Headers, Set) to be included in JSON.stringify output
|
|
19
|
-
*
|
|
18
|
+
* Allows special objects (Error, Headers, Set) to be included in JSON.stringify output.
|
|
19
|
+
* Functions are removed
|
|
20
20
|
*/
|
|
21
21
|
function snapshot(i, max = 50, depth = 0) {
|
|
22
22
|
if (Array.isArray(i)) {
|
|
@@ -286,17 +286,21 @@ var FileTypeCsv = class extends FileType {
|
|
|
286
286
|
//#region src/Dir.ts
|
|
287
287
|
/**
|
|
288
288
|
* Reference to a specific directory with methods to create and list files.
|
|
289
|
-
*
|
|
290
|
-
*
|
|
289
|
+
* @param inputPath
|
|
290
|
+
* The path of the directory, created on file system the first time `.path` is read or any methods are used
|
|
291
|
+
* @param options
|
|
292
|
+
* include `{ temp: true }` to enable the `.clear()` method
|
|
291
293
|
*/
|
|
292
|
-
var Dir = class
|
|
294
|
+
var Dir = class {
|
|
293
295
|
#inputPath;
|
|
294
296
|
#resolved;
|
|
297
|
+
isTemp;
|
|
295
298
|
/**
|
|
296
299
|
* @param path can be relative to workspace or absolute
|
|
297
300
|
*/
|
|
298
|
-
constructor(inputPath =
|
|
301
|
+
constructor(inputPath, options = {}) {
|
|
299
302
|
this.#inputPath = inputPath;
|
|
303
|
+
this.isTemp = Boolean(options.temp);
|
|
300
304
|
}
|
|
301
305
|
/**
|
|
302
306
|
* The path of this Dir instance. Created on file system the first time this property is read/used.
|
|
@@ -310,22 +314,25 @@ var Dir = class Dir {
|
|
|
310
314
|
}
|
|
311
315
|
/**
|
|
312
316
|
* Create a new Dir inside the current Dir
|
|
313
|
-
* @param subPath
|
|
317
|
+
* @param subPath
|
|
318
|
+
* joined with parent Dir's path to make new Dir
|
|
319
|
+
* @param options
|
|
320
|
+
* include `{ temp: true }` to enable the `.clear()` method. If current Dir is temporary, child directories will also be temporary.
|
|
314
321
|
* @example
|
|
315
322
|
* const folder = new Dir('example');
|
|
316
323
|
* // folder.path = '/path/to/cwd/example'
|
|
317
324
|
* const child = folder.dir('path/to/dir');
|
|
318
325
|
* // child.path = '/path/to/cwd/example/path/to/dir'
|
|
319
326
|
*/
|
|
320
|
-
dir(subPath) {
|
|
321
|
-
return new
|
|
327
|
+
dir(subPath, options = { temp: this.isTemp }) {
|
|
328
|
+
return new this.constructor(path.join(this.path, subPath), options);
|
|
322
329
|
}
|
|
323
330
|
/**
|
|
324
|
-
* Creates a new
|
|
331
|
+
* Creates a new temp directory inside current Dir
|
|
325
332
|
* @param subPath joined with parent Dir's path to make new TempDir
|
|
326
333
|
*/
|
|
327
334
|
tempDir(subPath) {
|
|
328
|
-
return
|
|
335
|
+
return this.dir(subPath, { temp: true });
|
|
329
336
|
}
|
|
330
337
|
sanitize(filename) {
|
|
331
338
|
return sanitizeFilename(filename.replace("https://", "").replace("www.", ""), { replacement: "_" }).slice(-200);
|
|
@@ -346,19 +353,8 @@ var Dir = class Dir {
|
|
|
346
353
|
get files() {
|
|
347
354
|
return fs.readdirSync(this.path).map((filename) => this.file(filename));
|
|
348
355
|
}
|
|
349
|
-
};
|
|
350
|
-
/**
|
|
351
|
-
* Extends Dir class with method to `clear()` contents.
|
|
352
|
-
* Default path: `./.temp`
|
|
353
|
-
*/
|
|
354
|
-
var TempDir = class extends Dir {
|
|
355
|
-
constructor(inputPath = `./.temp`) {
|
|
356
|
-
super(inputPath);
|
|
357
|
-
}
|
|
358
|
-
/**
|
|
359
|
-
* > ⚠️ Warning! This deletes the directory!
|
|
360
|
-
*/
|
|
361
356
|
clear() {
|
|
357
|
+
if (!this.isTemp) throw new Error("Dir is not temporary");
|
|
362
358
|
fs.rmSync(this.path, {
|
|
363
359
|
recursive: true,
|
|
364
360
|
force: true
|
|
@@ -386,7 +382,7 @@ var Cache = class {
|
|
|
386
382
|
file;
|
|
387
383
|
ttl;
|
|
388
384
|
constructor(key, ttl, initialData) {
|
|
389
|
-
this.file = new
|
|
385
|
+
this.file = new Dir(".cache", { temp: true }).file(key).json();
|
|
390
386
|
this.ttl = typeof ttl === "number" ? { minutes: ttl } : ttl;
|
|
391
387
|
if (initialData) this.write(initialData);
|
|
392
388
|
}
|
|
@@ -643,33 +639,53 @@ var Log = class Log {
|
|
|
643
639
|
return { details: input };
|
|
644
640
|
}
|
|
645
641
|
/**
|
|
646
|
-
*
|
|
642
|
+
* Events that require action or attention immediately
|
|
643
|
+
*/
|
|
644
|
+
static alert(...input) {
|
|
645
|
+
return this.#log({
|
|
646
|
+
severity: "ALERT",
|
|
647
|
+
color: chalk.bgRed
|
|
648
|
+
}, ...input);
|
|
649
|
+
}
|
|
650
|
+
/**
|
|
651
|
+
* Events that cause problems
|
|
647
652
|
*/
|
|
648
653
|
static error(...input) {
|
|
649
|
-
|
|
654
|
+
return this.#log({
|
|
650
655
|
severity: "ERROR",
|
|
651
656
|
color: chalk.red
|
|
652
657
|
}, ...input);
|
|
653
|
-
throw new Error(message);
|
|
654
658
|
}
|
|
659
|
+
/**
|
|
660
|
+
* Events that might cause problems
|
|
661
|
+
*/
|
|
655
662
|
static warn(...input) {
|
|
656
663
|
return this.#log({
|
|
657
664
|
severity: "WARNING",
|
|
658
665
|
color: chalk.yellow
|
|
659
666
|
}, ...input);
|
|
660
667
|
}
|
|
668
|
+
/**
|
|
669
|
+
* Normal but significant events, such as start up, shut down, or a configuration change
|
|
670
|
+
*/
|
|
661
671
|
static notice(...input) {
|
|
662
672
|
return this.#log({
|
|
663
673
|
severity: "NOTICE",
|
|
664
674
|
color: chalk.cyan
|
|
665
675
|
}, ...input);
|
|
666
676
|
}
|
|
677
|
+
/**
|
|
678
|
+
* Routine information, such as ongoing status or performance
|
|
679
|
+
*/
|
|
667
680
|
static info(...input) {
|
|
668
681
|
return this.#log({
|
|
669
682
|
severity: "INFO",
|
|
670
683
|
color: chalk.white
|
|
671
684
|
}, ...input);
|
|
672
685
|
}
|
|
686
|
+
/**
|
|
687
|
+
* Debug or trace information
|
|
688
|
+
*/
|
|
673
689
|
static debug(...input) {
|
|
674
690
|
return this.#log({
|
|
675
691
|
severity: "DEBUG",
|
|
@@ -730,5 +746,5 @@ var TypeWriter = class {
|
|
|
730
746
|
};
|
|
731
747
|
|
|
732
748
|
//#endregion
|
|
733
|
-
export { Cache, Dir, Fetcher, File, FileType, FileTypeCsv, FileTypeJson, FileTypeNdjson, Format, Log,
|
|
749
|
+
export { Cache, Dir, Fetcher, File, FileType, FileTypeCsv, FileTypeJson, FileTypeNdjson, Format, Log, TypeWriter, cwd, snapshot, temp, timeout };
|
|
734
750
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["output: Record<string, any>","obj: Record<string, any>","parsed: Row[]","#parseVal","#inputPath","#resolved","params: [string, string][]","timeout","#toGcloud","#toConsole","#log","entry: Entry"],"sources":["../src/snapshot.ts","../src/File.ts","../src/Dir.ts","../src/Cache.ts","../src/Fetcher.ts","../src/Format.ts","../src/Log.ts","../src/timeout.ts","../src/TypeWriter.ts"],"sourcesContent":["import { isObjectLike } from 'lodash-es';\n\n/**\n * Allows special objects (Error, Headers, Set) to be included in JSON.stringify output\n * functions are removed\n */\nexport function snapshot(i: unknown, max = 50, depth = 0): any {\n if (Array.isArray(i)) {\n if (depth === max) return [];\n return i.map((c) => snapshot(c, max, depth + 1));\n }\n if (typeof i === 'function') return undefined;\n if (!isObjectLike(i)) return i;\n\n if (depth === max) return {};\n let output: Record<string, any> = {};\n // @ts-ignore If it has an 'entries' function, use that for looping (eg. Set, Map, Headers)\n if (typeof i.entries === 'function') {\n // @ts-ignore\n for (let [k, v] of i.entries()) {\n output[k] = snapshot(v, max, depth + 1);\n }\n return output;\n }\n\n // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Enumerability_and_ownership_of_properties\n\n // Get Enumerable, inherited properties\n const obj: Record<string, any> = i!;\n for (let key in obj) {\n output[key] = snapshot(obj[key], max, depth + 1);\n }\n\n // Get Non-enumberable, own properties\n Object.getOwnPropertyNames(obj).forEach((key) => {\n output[key] = snapshot(obj[key], max, depth + 1);\n });\n\n return output;\n}\n","import * as fs from 'node:fs';\nimport * as path from 'node:path';\nimport { Readable } from 'node:stream';\nimport { finished } from 'node:stream/promises';\nimport mime from 'mime-types';\nimport { writeToStream, parseStream } from 'fast-csv';\nimport { snapshot } from './snapshot.ts';\n\n/**\n * Represents a file on the file system. If the file doesn't exist, it is created the first time it is written to.\n */\nexport class File {\n path;\n root;\n dir;\n base;\n name;\n ext;\n type;\n\n constructor(filepath: string) {\n this.path = path.resolve(filepath);\n const { root, dir, base, ext, name } = path.parse(this.path);\n this.root = root;\n this.dir = dir;\n this.base = base;\n this.name = name;\n this.ext = ext;\n this.type = mime.lookup(ext) || undefined;\n }\n\n get exists() {\n return fs.existsSync(this.path);\n }\n\n get stats(): Partial<fs.Stats> {\n return this.exists ? fs.statSync(this.path) : {};\n }\n\n /**\n * Deletes the file if it exists\n */\n delete() {\n fs.rmSync(this.path, { force: true });\n }\n\n /**\n * @returns the contents of the file as a string, or undefined if the file doesn't exist\n */\n read() {\n return this.exists ? fs.readFileSync(this.path, 'utf8') : undefined;\n }\n\n /**\n * @returns lines as strings, removes trailing '\\n'\n */\n lines() {\n const contents = (this.read() || '').split('\\n');\n return contents.at(-1)?.length ? contents : contents.slice(0, contents.length - 1);\n }\n\n get readStream() {\n return this.exists ? fs.createReadStream(this.path) : Readable.from([]);\n }\n\n get writeStream() {\n fs.mkdirSync(this.dir, { recursive: true });\n return fs.createWriteStream(this.path);\n }\n\n write(contents: string | ReadableStream) {\n fs.mkdirSync(this.dir, { recursive: true });\n if (typeof contents === 'string') return fs.writeFileSync(this.path, contents);\n if (contents instanceof ReadableStream) return finished(Readable.from(contents).pipe(this.writeStream));\n throw new Error(`Invalid content type: ${typeof contents}`);\n }\n\n /**\n * creates file if it doesn't exist, appends string or array of strings as new lines.\n * File always ends with '\\n', so contents don't need to be read before appending\n */\n append(lines: string | string[]) {\n if (!this.exists) this.write('');\n const contents = Array.isArray(lines) ? lines.join('\\n') : lines;\n fs.appendFileSync(this.path, contents + '\\n');\n }\n\n /**\n * @returns FileTypeJson adaptor for current File, adds '.json' extension if not present.\n * @example\n * const file = new File('./data').json({ key: 'val' }); // FileTypeJson<{ key: string; }>\n * console.log(file.path) // '/path/to/cwd/data.json'\n * file.write({ something: 'else' }) // ❌ property 'something' doesn't exist on type { key: string; }\n * @example\n * const file = new File('./data').json<object>({ key: 'val' }); // FileTypeJson<object>\n * file.write({ something: 'else' }) // ✅ data is typed as object\n */\n json<T>(contents?: T) {\n return new FileTypeJson<T>(this.path, contents);\n }\n\n /**\n * @example\n * const file = new File.json('data.json', { key: 'val' }); // FileTypeJson<{ key: string; }>\n */\n static get json() {\n return FileTypeJson;\n }\n\n /**\n * @returns FileTypeNdjson adaptor for current File, adds '.ndjson' extension if not present.\n */\n ndjson<T extends object>(lines?: T | T[]) {\n return new FileTypeNdjson<T>(this.path, lines);\n }\n /**\n * @example\n * const file = new File.ndjson('log', { key: 'val' }); // FileTypeNdjson<{ key: string; }>\n * console.log(file.path) // /path/to/cwd/log.ndjson\n */\n static get ndjson() {\n return FileTypeNdjson;\n }\n\n /**\n * @returns FileTypeCsv adaptor for current File, adds '.csv' extension if not present.\n * @example\n * const file = await new File('a').csv([{ col: 'val' }, { col: 'val2' }]); // FileTypeCsv<{ col: string; }>\n * await file.write([ { col2: 'val2' } ]); // ❌ 'col2' doesn't exist on type { col: string; }\n * await file.write({ col: 'val' }); // ✅ Writes one row\n * await file.write([{ col: 'val2' }, { col: 'val3' }]); // ✅ Writes multiple rows\n */\n async csv<T extends object>(rows?: T[], keys?: (keyof T)[]) {\n const csvFile = new FileTypeCsv<T>(this.path);\n if (rows) await csvFile.write(rows, keys);\n return csvFile;\n }\n\n static get csv() {\n return FileTypeCsv;\n }\n}\n\n/**\n * A generic file adaptor, extended by specific file type implementations\n */\nexport class FileType {\n file;\n\n constructor(filepath: string, contents?: string) {\n this.file = new File(filepath);\n if (contents) this.file.write(contents);\n }\n\n get path() {\n return this.file.path;\n }\n\n get root() {\n return this.file.root;\n }\n\n get dir() {\n return this.file.dir;\n }\n\n get base() {\n return this.file.base;\n }\n\n get name() {\n return this.file.name;\n }\n\n get ext() {\n return this.file.ext;\n }\n\n get type() {\n return this.file.type;\n }\n\n get exists() {\n return this.file.exists;\n }\n\n get stats() {\n return this.file.stats;\n }\n\n delete() {\n this.file.delete();\n }\n\n get readStream() {\n return this.file.readStream;\n }\n\n get writeStream() {\n return this.file.writeStream;\n }\n}\n\n/**\n * A .json file that maintains data type when reading/writing.\n * > ⚠️ This is mildly unsafe, important/foreign json files should be validated at runtime!\n * @example\n * const file = new FileTypeJson('./data', { key: 'val' }); // FileTypeJson<{ key: string; }>\n * console.log(file.path) // '/path/to/cwd/data.json'\n * file.write({ something: 'else' }) // ❌ property 'something' doesn't exist on type { key: string; }\n * @example\n * const file = new FileTypeJson<object>('./data', { key: 'val' }); // FileTypeJson<object>\n * file.write({ something: 'else' }) // ✅ data is typed as object\n */\nexport class FileTypeJson<T> extends FileType {\n constructor(filepath: string, contents?: T) {\n super(filepath.endsWith('.json') ? filepath : filepath + '.json');\n if (contents) this.write(contents);\n }\n\n read() {\n const contents = this.file.read();\n return contents ? (JSON.parse(contents) as T) : undefined;\n }\n\n write(contents: T) {\n this.file.write(JSON.stringify(snapshot(contents), null, 2));\n }\n}\n\n/**\n * New-line delimited json file (.ndjson)\n * @see https://jsonltools.com/ndjson-format-specification\n */\nexport class FileTypeNdjson<T extends object> extends FileType {\n constructor(filepath: string, lines?: T | T[]) {\n super(filepath.endsWith('.ndjson') ? filepath : filepath + '.ndjson');\n if (lines) this.append(lines);\n }\n\n append(lines: T | T[]) {\n this.file.append(\n Array.isArray(lines) ? lines.map(l => JSON.stringify(snapshot(l))) : JSON.stringify(snapshot(lines)),\n );\n }\n\n lines() {\n return this.file.lines().map(l => JSON.parse(l) as T);\n }\n}\n\ntype Key<T extends object> = keyof T;\n\n/**\n * Comma separated values (.csv).\n * Input rows as objects, keys are used as column headers\n */\nexport class FileTypeCsv<Row extends object> extends FileType {\n constructor(filepath: string) {\n super(filepath.endsWith('.csv') ? filepath : filepath + '.csv');\n }\n\n async write(rows: Row[], keys?: Key<Row>[]) {\n const headerSet = new Set<Key<Row>>();\n if (keys) {\n for (const key of keys) headerSet.add(key);\n } else {\n for (const row of rows) {\n for (const key in row) headerSet.add(key);\n }\n }\n const headers = Array.from(headerSet);\n const outRows = rows.map(row => headers.map(key => row[key]));\n return finished(writeToStream(this.file.writeStream, [headers, ...outRows]));\n }\n\n #parseVal(val: string) {\n if (val.toLowerCase() === 'false') return false;\n if (val.toLowerCase() === 'true') return true;\n if (val.length === 0) return null;\n if (/^[\\.0-9]+$/.test(val)) return Number(val);\n return val;\n }\n\n async read() {\n return new Promise<Row[]>((resolve, reject) => {\n const parsed: Row[] = [];\n parseStream(this.file.readStream, { headers: true })\n .on('data', (raw: Record<Key<Row>, string>) => {\n parsed.push(\n Object.entries(raw).reduce(\n (all, [key, val]) => ({\n ...all,\n [key]: this.#parseVal(val as string),\n }),\n {} as Row,\n ),\n );\n })\n .on('error', e => reject(e))\n .on('end', () => resolve(parsed));\n });\n }\n}\n","import * as fs from 'node:fs';\nimport * as path from 'node:path';\nimport sanitizeFilename from 'sanitize-filename';\nimport { File } from './File.ts';\n\n/**\n * Reference to a specific directory with methods to create and list files.\n * Default path: '.'\n * > Created on file system the first time .path is read or any methods are used\n */\nexport class Dir {\n #inputPath;\n #resolved?: string;\n\n /**\n * @param path can be relative to workspace or absolute\n */\n constructor(inputPath = '.') {\n this.#inputPath = inputPath;\n }\n\n /**\n * The path of this Dir instance. Created on file system the first time this property is read/used.\n */\n get path() {\n if (!this.#resolved) {\n this.#resolved = path.resolve(this.#inputPath);\n fs.mkdirSync(this.#resolved, { recursive: true });\n }\n return this.#resolved;\n }\n\n /**\n * Create a new Dir inside the current Dir\n * @param subPath joined with parent Dir's path to make new Dir\n * @example\n * const folder = new Dir('example');\n * // folder.path = '/path/to/cwd/example'\n * const child = folder.dir('path/to/dir');\n * // child.path = '/path/to/cwd/example/path/to/dir'\n */\n dir(subPath: string) {\n return new Dir(path.join(this.path, subPath));\n }\n\n /**\n * Creates a new TempDir inside current Dir\n * @param subPath joined with parent Dir's path to make new TempDir\n */\n tempDir(subPath: string) {\n return new TempDir(path.join(this.path, subPath));\n }\n\n sanitize(filename: string) {\n const notUrl = filename.replace('https://', '').replace('www.', '');\n return sanitizeFilename(notUrl, { replacement: '_' }).slice(-200);\n }\n\n /**\n * @param base - The file base (name and extension)\n * @example\n * const folder = new Dir('example');\n * const filepath = folder.resolve('file.json');\n * // 'example/file.json'\n */\n filepath(base: string) {\n return path.resolve(this.path, this.sanitize(base));\n }\n\n file(base: string) {\n return new File(this.filepath(base));\n }\n\n get files() {\n return fs.readdirSync(this.path).map(filename => this.file(filename));\n }\n}\n\n/**\n * Extends Dir class with method to `clear()` contents.\n * Default path: `./.temp`\n */\nexport class TempDir extends Dir {\n constructor(inputPath = `./.temp`) {\n super(inputPath);\n }\n\n /**\n * > ⚠️ Warning! This deletes the directory!\n */\n clear() {\n fs.rmSync(this.path, { recursive: true, force: true });\n fs.mkdirSync(this.path, { recursive: true });\n }\n}\n\n/**\n * Current working directory\n */\nexport const cwd = new Dir('./');\n/**\n * ./.temp in current working directory\n */\nexport const temp = cwd.tempDir('.temp');\n","import { type Duration, isAfter, add } from 'date-fns';\nimport { TempDir } from './Dir.ts';\n\n/**\n * Save data to a local file with an expiration.\n * Fresh/stale data is returned with a flag for if it's fresh or not,\n * so stale data can still be used if needed.\n */\nexport class Cache<T> {\n file;\n ttl;\n\n constructor(key: string, ttl: number | Duration, initialData?: T) {\n const dir = new TempDir('.cache');\n this.file = dir.file(key).json<{ savedAt: string; data: T }>();\n this.ttl = typeof ttl === 'number' ? { minutes: ttl } : ttl;\n if (initialData) this.write(initialData);\n }\n\n write(data: T) {\n this.file.write({ savedAt: new Date().toUTCString(), data });\n }\n\n read(): [T | undefined, boolean] {\n const { savedAt, data } = this.file.read() || {};\n const isFresh = Boolean(savedAt && isAfter(add(savedAt, this.ttl), new Date()));\n return [data, isFresh];\n }\n}\n","import { merge } from 'lodash-es';\nimport extractDomain from 'extract-domain';\n\nexport type Route = string | URL;\n\ntype QueryVal = string | number | boolean | null | undefined;\nexport type Query = Record<string, QueryVal | QueryVal[]>;\n\nexport type FetchOptions = RequestInit & {\n base?: string;\n query?: Query;\n headers?: Record<string, string>;\n data?: any;\n timeout?: number;\n retries?: number;\n retryDelay?: number;\n};\n\n/**\n * Fetcher provides a quick way to set up a basic API connection\n * with options applied to every request.\n * Includes basic methods for requesting and parsing responses\n */\nexport class Fetcher {\n defaultOptions;\n\n constructor(opts: FetchOptions = {}) {\n this.defaultOptions = {\n timeout: 60000,\n retries: 0,\n retryDelay: 3000,\n ...opts,\n };\n }\n\n /**\n * Build URL with URLSearchParams if query is provided.\n * Also returns domain, to help with cookies\n */\n buildUrl(route: Route, opts: FetchOptions = {}): [URL, string] {\n const mergedOptions = merge({}, this.defaultOptions, opts);\n const params: [string, string][] = [];\n Object.entries(mergedOptions.query || {}).forEach(([key, val]) => {\n if (val === undefined) return;\n if (Array.isArray(val)) {\n val.forEach((v) => {\n params.push([key, `${v}`]);\n });\n } else {\n params.push([key, `${val}`]);\n }\n });\n const search = params.length > 0 ? '?' + new URLSearchParams(params).toString() : '';\n const url = new URL(route + search, this.defaultOptions.base);\n const domain = extractDomain(url.href) as string;\n return [url, domain];\n }\n\n /**\n * Merges options to get headers. Useful when extending the Fetcher class to add custom auth.\n */\n buildHeaders(route: Route, opts: FetchOptions = {}) {\n const { headers } = merge({}, this.defaultOptions, opts);\n return headers || {};\n }\n\n /**\n * Builds request, merging defaultOptions and provided options.\n * Includes Abort signal for timeout\n */\n buildRequest(route: Route, opts: FetchOptions = {}): [Request, FetchOptions, string] {\n const mergedOptions = merge({}, this.defaultOptions, opts);\n const { query, data, timeout, retries, ...init } = mergedOptions;\n init.headers = this.buildHeaders(route, mergedOptions);\n if (data) {\n init.headers['content-type'] = init.headers['content-type'] || 'application/json';\n init.method = init.method || 'POST';\n init.body = JSON.stringify(data);\n }\n if (timeout) {\n init.signal = AbortSignal.timeout(timeout);\n }\n const [url, domain] = this.buildUrl(route, mergedOptions);\n const req = new Request(url, init);\n return [req, mergedOptions, domain];\n }\n\n /**\n * Builds and performs the request, merging provided options with defaultOptions.\n * If `opts.data` is provided, method is updated to POST, content-type json, data is stringified in the body.\n * Retries on local or network error, with increasing backoff.\n */\n async fetch(route: Route, opts: FetchOptions = {}): Promise<[Response, Request]> {\n const [_req, options] = this.buildRequest(route, opts);\n const maxAttempts = (options.retries || 0) + 1;\n let attempt = 0;\n while (attempt < maxAttempts) {\n attempt++;\n const [req] = this.buildRequest(route, opts);\n const res = await fetch(req)\n .then((r) => {\n if (!r.ok) throw new Error(r.statusText);\n return r;\n })\n .catch(async (error) => {\n if (attempt < maxAttempts) {\n const wait = attempt * 3000;\n console.warn(`${req.method} ${req.url} (attempt ${attempt} of ${maxAttempts})`, error);\n await new Promise((resolve) => setTimeout(resolve, wait));\n } else {\n throw new Error(error);\n }\n });\n if (res) return [res, req];\n }\n throw new Error(`Failed to fetch ${_req.url}`);\n }\n\n async fetchText(route: Route, opts: FetchOptions = {}): Promise<[string, Response, Request]> {\n return this.fetch(route, opts).then(async ([res, req]) => {\n const text = await res.text();\n return [text, res, req];\n });\n }\n\n async fetchJson<T>(route: Route, opts: FetchOptions = {}): Promise<[T, Response, Request]> {\n return this.fetchText(route, opts).then(([txt, res, req]) => [JSON.parse(txt) as T, res, req]);\n }\n}\n","import { format, formatISO, type DateArg, type Duration } from 'date-fns';\nimport formatDuration from 'format-duration';\n\n/**\n * Helpers for formatting dates, times, and numbers as strings\n */\nexport class Format {\n /**\n * date-fns format() with some shortcuts\n * @param formatStr the format to use\n * @param date the date to format, default `new Date()`\n * @example\n * Format.date('iso') // '2026-04-08T13:56:45Z'\n * Format.date('ymd') // '20260408'\n * Format.date('ymd-hm') // '20260408-1356'\n * Format.date('ymd-hms') // '20260408-135645'\n * Format.date('h:m:s') // '13:56:45'\n * @see more format options https://date-fns.org/v4.1.0/docs/format\n */\n static date(\n formatStr: 'iso' | 'ymd' | 'ymd-hm' | 'ymd-hms' | 'h:m:s' | string = 'iso',\n d: DateArg<Date> = new Date(),\n ) {\n if (formatStr === 'iso') return formatISO(d);\n if (formatStr === 'ymd') return format(d, 'yyyyMMdd');\n if (formatStr === 'ymd-hm') return format(d, 'yyyyMMdd-HHmm');\n if (formatStr === 'ymd-hms') return format(d, 'yyyyMMdd-HHmmss');\n if (formatStr === 'h:m:s') return format(d, 'HH:mm:ss');\n return format(d, formatStr);\n }\n\n /**\n * Round a number to a specific set of places\n */\n static round(n: number, places = 0) {\n return new Intl.NumberFormat('en-US', { maximumFractionDigits: places }).format(n);\n }\n\n static plural(amount: number, singular: string, multiple?: string) {\n return amount === 1 ? `${amount} ${singular}` : `${amount} ${multiple || singular + 's'}`;\n }\n\n /**\n * Make millisecond durations actually readable (eg \"123ms\", \"3.56s\", \"1m 34s\", \"3h 24m\", \"2d 4h\")\n * @param ms milliseconds\n * @param style 'digital' to output as 'HH:MM:SS'\n * @see details on 'digital' format https://github.com/ungoldman/format-duration\n * @see waiting on `Intl.DurationFormat({ style: 'digital' })` types https://github.com/microsoft/TypeScript/issues/60608\n */\n static ms(ms: number, style?: 'digital') {\n if (style === 'digital') return formatDuration(ms, { leading: true });\n if (ms < 1000) return `${this.round(ms)}ms`;\n const s = ms / 1000;\n if (s < 60) return `${this.round(s, 2)}s`;\n const m = Math.floor(s / 60);\n if (m < 60) return `${m}m ${Math.floor(s) % 60}s`;\n const h = Math.floor(m / 60);\n if (h < 24) return `${h}h ${m % 60}m`;\n const d = Math.floor(h / 24);\n return `${d}d ${h % 24}h`;\n }\n\n static bytes(b: number) {\n const labels = ['b', 'KB', 'MB', 'GB', 'TB'];\n let factor = 0;\n while (b >= 1024 && labels[factor + 1]) {\n b = b / 1024;\n factor++;\n }\n return `${this.round(b, 2)} ${labels[factor]}`;\n }\n}\n","import { inspect } from 'node:util';\nimport { isObjectLike } from 'lodash-es';\nimport chalk, { type ChalkInstance } from 'chalk';\nimport { snapshot } from './snapshot.ts';\nimport { Format } from './Format.ts';\n\ntype Severity = 'DEFAULT' | 'DEBUG' | 'INFO' | 'NOTICE' | 'WARNING' | 'ERROR' | 'CRITICAL' | 'ALERT' | 'EMERGENCY';\n\ntype Options = {\n severity: Severity;\n color: ChalkInstance;\n};\n\ntype Entry = {\n message?: string;\n severity: Severity;\n stack?: string;\n details?: unknown[];\n};\n\nexport class Log {\n static getStack() {\n const details = { stack: '' };\n // replaces details.stack with current stack trace, excluding this Log.getStack call\n Error.captureStackTrace(details, Log.getStack);\n // remove 'Error' on first line\n return details.stack\n .split('\\n')\n .map(l => l.trim())\n .filter(l => l !== 'Error');\n }\n\n /**\n * Gcloud parses JSON in stdout\n */\n static #toGcloud(entry: Entry) {\n const details = entry.details?.length === 1 ? entry.details[0] : entry.details;\n const output = { ...entry, details, stack: entry.stack || this.getStack() };\n console.log(JSON.stringify(snapshot(output)));\n }\n\n /**\n * Includes colors and better inspection for logging during dev\n */\n static #toConsole(entry: Entry, color: ChalkInstance) {\n if (entry.message) console.log(color(`${Format.date('h:m:s')} [${entry.severity}] ${entry.message}`));\n entry.details?.forEach(detail => {\n console.log(inspect(detail, { depth: 10, breakLength: 100, compact: true, colors: true }));\n });\n }\n\n static #log({ severity, color }: Options, ...input: unknown[]) {\n const { message, details } = this.prepare(...input);\n const entry: Entry = { message, severity, details };\n // https://cloud.google.com/run/docs/container-contract#env-vars\n const isGcloud = process.env.K_SERVICE !== undefined || process.env.CLOUD_RUN_JOB !== undefined;\n if (isGcloud) {\n this.#toGcloud(entry);\n } else {\n this.#toConsole(entry, color);\n }\n return entry;\n }\n\n /**\n * Handle first argument being a string or an object with a 'message' prop\n */\n static prepare(...input: unknown[]): { message?: string; details: unknown[] } {\n let [firstArg, ...rest] = input;\n // First argument is a string, use that as the message\n if (typeof firstArg === 'string') {\n return { message: firstArg, details: rest };\n }\n // First argument is an object with a `message` property\n // @ts-ignore\n if (isObjectLike(firstArg) && typeof firstArg['message'] === 'string') {\n const { message, ...firstDetails } = firstArg as { message: string };\n return { message, details: [firstDetails, ...rest] };\n }\n // No message found, log all args as details\n return { details: input };\n }\n\n /**\n * Logs error details before throwing\n */\n static error(...input: unknown[]) {\n const { message } = this.#log({ severity: 'ERROR', color: chalk.red }, ...input);\n throw new Error(message);\n }\n\n static warn(...input: unknown[]) {\n return this.#log({ severity: 'WARNING', color: chalk.yellow }, ...input);\n }\n\n static notice(...input: unknown[]) {\n return this.#log({ severity: 'NOTICE', color: chalk.cyan }, ...input);\n }\n\n static info(...input: unknown[]) {\n return this.#log({ severity: 'INFO', color: chalk.white }, ...input);\n }\n\n static debug(...input: unknown[]) {\n return this.#log({ severity: 'DEBUG', color: chalk.gray }, ...input);\n }\n}\n","export async function timeout(ms: number) {\n return new Promise((resolve) => {\n setTimeout(resolve, ms);\n });\n}\n","import * as fs from 'node:fs';\nimport { merge } from 'lodash-es';\nimport * as qt from 'quicktype-core';\n\nexport class TypeWriter {\n moduleName;\n input = qt.jsonInputForTargetLanguage('typescript');\n outDir;\n qtSettings;\n\n constructor(moduleName: string, settings: { outDir?: string } & Partial<qt.Options> = {}) {\n this.moduleName = moduleName;\n const { outDir, ...qtSettings } = settings;\n this.outDir = outDir || './types';\n const defaultSettings = {\n lang: 'typescript',\n rendererOptions: {\n 'just-types': true,\n 'prefer-types': true,\n },\n inferEnums: false,\n inferDateTimes: false,\n };\n this.qtSettings = merge(defaultSettings, qtSettings);\n }\n\n async addMember(name: string, _samples: any[]) {\n const samples = _samples.map((s) => (typeof s === 'string' ? s : JSON.stringify(s)));\n await this.input.addSource({ name, samples });\n }\n\n async toString() {\n const inputData = new qt.InputData();\n inputData.addInput(this.input);\n const result = await qt.quicktype({\n inputData,\n ...this.qtSettings,\n });\n return result.lines.join('\\n');\n }\n\n async toFile() {\n const result = await this.toString();\n fs.mkdirSync(this.outDir, { recursive: true });\n fs.writeFileSync(`${this.outDir}/${this.moduleName}.d.ts`, result);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAMA,SAAgB,SAAS,GAAY,MAAM,IAAI,QAAQ,GAAQ;AAC7D,KAAI,MAAM,QAAQ,EAAE,EAAE;AACpB,MAAI,UAAU,IAAK,QAAO,EAAE;AAC5B,SAAO,EAAE,KAAK,MAAM,SAAS,GAAG,KAAK,QAAQ,EAAE,CAAC;;AAElD,KAAI,OAAO,MAAM,WAAY,QAAO;AACpC,KAAI,CAAC,aAAa,EAAE,CAAE,QAAO;AAE7B,KAAI,UAAU,IAAK,QAAO,EAAE;CAC5B,IAAIA,SAA8B,EAAE;AAEpC,KAAI,OAAO,EAAE,YAAY,YAAY;AAEnC,OAAK,IAAI,CAAC,GAAG,MAAM,EAAE,SAAS,CAC5B,QAAO,KAAK,SAAS,GAAG,KAAK,QAAQ,EAAE;AAEzC,SAAO;;CAMT,MAAMC,MAA2B;AACjC,MAAK,IAAI,OAAO,IACd,QAAO,OAAO,SAAS,IAAI,MAAM,KAAK,QAAQ,EAAE;AAIlD,QAAO,oB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U;AAUxB,OAAK,aAAa,MATM;GACtB,MAAM;GACN,iBAAiB;IACf,cAAc;IACd,gBAAgB;IACjB;GACD,YAAY;GACZ,gBAAgB;GACjB,EACwC,WAAW;;CAGtD,MAAM,UAAU,MAAc,UAAiB;EAC7C,MAAM,UAAU,SAAS,KAAK,MAAO,OAAO,MAAM,WAAW,IAAI,KAAK,UAAU,EAAE,CAAE;AACpF,QAAM,KAAK,MAAM,UAAU;GAAE;GAAM;GAAS,CAAC;;CAG/C,MAAM,WAAW;EACf,MAAM,YAAY,IAAI,GAAG,WAAW;AACpC,YAAU,SAAS,KAAK,MAAM;AAK9B,UAJe,MAAM,GAAG,UAAU;GAChC;GACA,GAAG,KAAK;GACT,CAAC,EACY,MAAM,KAAK,KAAK;;CAGhC,MAAM,SAAS;EACb,MAAM,SAAS,MAAM,KAAK,UAAU;AACpC,KAAG,UAAU,KAAK,QAAQ,EAAE,WAAW,MAAM,CAAC;AAC9C,KAAG,cAAc,GAAG,KAAK,OAAO,GAAG,KAAK,WAAW,QAAQ,OAAO"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["output: Record<string, any>","obj: Record<string, any>","parsed: Row[]","#parseVal","#inputPath","#resolved","params: [string, string][]","timeout","#toGcloud","#toConsole","#log","entry: Entry"],"sources":["../src/snapshot.ts","../src/File.ts","../src/Dir.ts","../src/Cache.ts","../src/Fetcher.ts","../src/Format.ts","../src/Log.ts","../src/timeout.ts","../src/TypeWriter.ts"],"sourcesContent":["import { isObjectLike } from 'lodash-es';\n\n/**\n * Allows special objects (Error, Headers, Set) to be included in JSON.stringify output.\n * Functions are removed\n */\nexport function snapshot(i: unknown, max = 50, depth = 0): any {\n if (Array.isArray(i)) {\n if (depth === max) return [];\n return i.map(c => snapshot(c, max, depth + 1));\n }\n if (typeof i === 'function') return undefined;\n if (!isObjectLike(i)) return i;\n\n if (depth === max) return {};\n let output: Record<string, any> = {};\n // @ts-ignore If it has an 'entries' function, use that for looping (eg. Set, Map, Headers)\n if (typeof i.entries === 'function') {\n // @ts-ignore\n for (let [k, v] of i.entries()) {\n output[k] = snapshot(v, max, depth + 1);\n }\n return output;\n }\n\n // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Enumerability_and_ownership_of_properties\n\n // Get Enumerable, inherited properties\n const obj: Record<string, any> = i!;\n for (let key in obj) {\n output[key] = snapshot(obj[key], max, depth + 1);\n }\n\n // Get Non-enumberable, own properties\n Object.getOwnPropertyNames(obj).forEach(key => {\n output[key] = snapshot(obj[key], max, depth + 1);\n });\n\n return output;\n}\n","import * as fs from 'node:fs';\nimport * as path from 'node:path';\nimport { Readable } from 'node:stream';\nimport { finished } from 'node:stream/promises';\nimport mime from 'mime-types';\nimport { writeToStream, parseStream } from 'fast-csv';\nimport { snapshot } from './snapshot.ts';\n\n/**\n * Represents a file on the file system. If the file doesn't exist, it is created the first time it is written to.\n */\nexport class File {\n path;\n root;\n dir;\n base;\n name;\n ext;\n type;\n\n constructor(filepath: string) {\n this.path = path.resolve(filepath);\n const { root, dir, base, ext, name } = path.parse(this.path);\n this.root = root;\n this.dir = dir;\n this.base = base;\n this.name = name;\n this.ext = ext;\n this.type = mime.lookup(ext) || undefined;\n }\n\n get exists() {\n return fs.existsSync(this.path);\n }\n\n get stats(): Partial<fs.Stats> {\n return this.exists ? fs.statSync(this.path) : {};\n }\n\n /**\n * Deletes the file if it exists\n */\n delete() {\n fs.rmSync(this.path, { force: true });\n }\n\n /**\n * @returns the contents of the file as a string, or undefined if the file doesn't exist\n */\n read() {\n return this.exists ? fs.readFileSync(this.path, 'utf8') : undefined;\n }\n\n /**\n * @returns lines as strings, removes trailing '\\n'\n */\n lines() {\n const contents = (this.read() || '').split('\\n');\n return contents.at(-1)?.length ? contents : contents.slice(0, contents.length - 1);\n }\n\n get readStream() {\n return this.exists ? fs.createReadStream(this.path) : Readable.from([]);\n }\n\n get writeStream() {\n fs.mkdirSync(this.dir, { recursive: true });\n return fs.createWriteStream(this.path);\n }\n\n write(contents: string | ReadableStream) {\n fs.mkdirSync(this.dir, { recursive: true });\n if (typeof contents === 'string') return fs.writeFileSync(this.path, contents);\n if (contents instanceof ReadableStream) return finished(Readable.from(contents).pipe(this.writeStream));\n throw new Error(`Invalid content type: ${typeof contents}`);\n }\n\n /**\n * creates file if it doesn't exist, appends string or array of strings as new lines.\n * File always ends with '\\n', so contents don't need to be read before appending\n */\n append(lines: string | string[]) {\n if (!this.exists) this.write('');\n const contents = Array.isArray(lines) ? lines.join('\\n') : lines;\n fs.appendFileSync(this.path, contents + '\\n');\n }\n\n /**\n * @returns FileTypeJson adaptor for current File, adds '.json' extension if not present.\n * @example\n * const file = new File('./data').json({ key: 'val' }); // FileTypeJson<{ key: string; }>\n * console.log(file.path) // '/path/to/cwd/data.json'\n * file.write({ something: 'else' }) // ❌ property 'something' doesn't exist on type { key: string; }\n * @example\n * const file = new File('./data').json<object>({ key: 'val' }); // FileTypeJson<object>\n * file.write({ something: 'else' }) // ✅ data is typed as object\n */\n json<T>(contents?: T) {\n return new FileTypeJson<T>(this.path, contents);\n }\n\n /**\n * @example\n * const file = new File.json('data.json', { key: 'val' }); // FileTypeJson<{ key: string; }>\n */\n static get json() {\n return FileTypeJson;\n }\n\n /**\n * @returns FileTypeNdjson adaptor for current File, adds '.ndjson' extension if not present.\n */\n ndjson<T extends object>(lines?: T | T[]) {\n return new FileTypeNdjson<T>(this.path, lines);\n }\n /**\n * @example\n * const file = new File.ndjson('log', { key: 'val' }); // FileTypeNdjson<{ key: string; }>\n * console.log(file.path) // /path/to/cwd/log.ndjson\n */\n static get ndjson() {\n return FileTypeNdjson;\n }\n\n /**\n * @returns FileTypeCsv adaptor for current File, adds '.csv' extension if not present.\n * @example\n * const file = await new File('a').csv([{ col: 'val' }, { col: 'val2' }]); // FileTypeCsv<{ col: string; }>\n * await file.write([ { col2: 'val2' } ]); // ❌ 'col2' doesn't exist on type { col: string; }\n * await file.write({ col: 'val' }); // ✅ Writes one row\n * await file.write([{ col: 'val2' }, { col: 'val3' }]); // ✅ Writes multiple rows\n */\n async csv<T extends object>(rows?: T[], keys?: (keyof T)[]) {\n const csvFile = new FileTypeCsv<T>(this.path);\n if (rows) await csvFile.write(rows, keys);\n return csvFile;\n }\n\n static get csv() {\n return FileTypeCsv;\n }\n}\n\n/**\n * A generic file adaptor, extended by specific file type implementations\n */\nexport class FileType {\n file;\n\n constructor(filepath: string, contents?: string) {\n this.file = new File(filepath);\n if (contents) this.file.write(contents);\n }\n\n get path() {\n return this.file.path;\n }\n\n get root() {\n return this.file.root;\n }\n\n get dir() {\n return this.file.dir;\n }\n\n get base() {\n return this.file.base;\n }\n\n get name() {\n return this.file.name;\n }\n\n get ext() {\n return this.file.ext;\n }\n\n get type() {\n return this.file.type;\n }\n\n get exists() {\n return this.file.exists;\n }\n\n get stats() {\n return this.file.stats;\n }\n\n delete() {\n this.file.delete();\n }\n\n get readStream() {\n return this.file.readStream;\n }\n\n get writeStream() {\n return this.file.writeStream;\n }\n}\n\n/**\n * A .json file that maintains data type when reading/writing.\n * > ⚠️ This is mildly unsafe, important/foreign json files should be validated at runtime!\n * @example\n * const file = new FileTypeJson('./data', { key: 'val' }); // FileTypeJson<{ key: string; }>\n * console.log(file.path) // '/path/to/cwd/data.json'\n * file.write({ something: 'else' }) // ❌ property 'something' doesn't exist on type { key: string; }\n * @example\n * const file = new FileTypeJson<object>('./data', { key: 'val' }); // FileTypeJson<object>\n * file.write({ something: 'else' }) // ✅ data is typed as object\n */\nexport class FileTypeJson<T> extends FileType {\n constructor(filepath: string, contents?: T) {\n super(filepath.endsWith('.json') ? filepath : filepath + '.json');\n if (contents) this.write(contents);\n }\n\n read() {\n const contents = this.file.read();\n return contents ? (JSON.parse(contents) as T) : undefined;\n }\n\n write(contents: T) {\n this.file.write(JSON.stringify(snapshot(contents), null, 2));\n }\n}\n\n/**\n * New-line delimited json file (.ndjson)\n * @see https://jsonltools.com/ndjson-format-specification\n */\nexport class FileTypeNdjson<T extends object> extends FileType {\n constructor(filepath: string, lines?: T | T[]) {\n super(filepath.endsWith('.ndjson') ? filepath : filepath + '.ndjson');\n if (lines) this.append(lines);\n }\n\n append(lines: T | T[]) {\n this.file.append(\n Array.isArray(lines) ? lines.map(l => JSON.stringify(snapshot(l))) : JSON.stringify(snapshot(lines)),\n );\n }\n\n lines() {\n return this.file.lines().map(l => JSON.parse(l) as T);\n }\n}\n\ntype Key<T extends object> = keyof T;\n\n/**\n * Comma separated values (.csv).\n * Input rows as objects, keys are used as column headers\n */\nexport class FileTypeCsv<Row extends object> extends FileType {\n constructor(filepath: string) {\n super(filepath.endsWith('.csv') ? filepath : filepath + '.csv');\n }\n\n async write(rows: Row[], keys?: Key<Row>[]) {\n const headerSet = new Set<Key<Row>>();\n if (keys) {\n for (const key of keys) headerSet.add(key);\n } else {\n for (const row of rows) {\n for (const key in row) headerSet.add(key);\n }\n }\n const headers = Array.from(headerSet);\n const outRows = rows.map(row => headers.map(key => row[key]));\n return finished(writeToStream(this.file.writeStream, [headers, ...outRows]));\n }\n\n #parseVal(val: string) {\n if (val.toLowerCase() === 'false') return false;\n if (val.toLowerCase() === 'true') return true;\n if (val.length === 0) return null;\n if (/^[\\.0-9]+$/.test(val)) return Number(val);\n return val;\n }\n\n async read() {\n return new Promise<Row[]>((resolve, reject) => {\n const parsed: Row[] = [];\n parseStream(this.file.readStream, { headers: true })\n .on('data', (raw: Record<Key<Row>, string>) => {\n parsed.push(\n Object.entries(raw).reduce(\n (all, [key, val]) => ({\n ...all,\n [key]: this.#parseVal(val as string),\n }),\n {} as Row,\n ),\n );\n })\n .on('error', e => reject(e))\n .on('end', () => resolve(parsed));\n });\n }\n}\n","import * as fs from 'node:fs';\nimport * as path from 'node:path';\nimport sanitizeFilename from 'sanitize-filename';\nimport { File } from './File.ts';\n\nexport type DirOptions = {\n temp?: boolean;\n};\n\n/**\n * Reference to a specific directory with methods to create and list files.\n * @param inputPath\n * The path of the directory, created on file system the first time `.path` is read or any methods are used\n * @param options\n * include `{ temp: true }` to enable the `.clear()` method\n */\nexport class Dir {\n #inputPath;\n #resolved?: string;\n isTemp;\n\n /**\n * @param path can be relative to workspace or absolute\n */\n constructor(inputPath: string, options: DirOptions = {}) {\n this.#inputPath = inputPath;\n this.isTemp = Boolean(options.temp);\n }\n\n /**\n * The path of this Dir instance. Created on file system the first time this property is read/used.\n */\n get path() {\n if (!this.#resolved) {\n this.#resolved = path.resolve(this.#inputPath);\n fs.mkdirSync(this.#resolved, { recursive: true });\n }\n return this.#resolved;\n }\n\n /**\n * Create a new Dir inside the current Dir\n * @param subPath\n * joined with parent Dir's path to make new Dir\n * @param options\n * include `{ temp: true }` to enable the `.clear()` method. If current Dir is temporary, child directories will also be temporary.\n * @example\n * const folder = new Dir('example');\n * // folder.path = '/path/to/cwd/example'\n * const child = folder.dir('path/to/dir');\n * // child.path = '/path/to/cwd/example/path/to/dir'\n */\n dir(subPath: string, options: DirOptions = { temp: this.isTemp }) {\n return new (this.constructor as typeof Dir)(path.join(this.path, subPath), options) as this;\n }\n\n /**\n * Creates a new temp directory inside current Dir\n * @param subPath joined with parent Dir's path to make new TempDir\n */\n tempDir(subPath: string) {\n return this.dir(subPath, { temp: true });\n }\n\n sanitize(filename: string) {\n const notUrl = filename.replace('https://', '').replace('www.', '');\n return sanitizeFilename(notUrl, { replacement: '_' }).slice(-200);\n }\n\n /**\n * @param base - The file base (name and extension)\n * @example\n * const folder = new Dir('example');\n * const filepath = folder.resolve('file.json');\n * // 'example/file.json'\n */\n filepath(base: string) {\n return path.resolve(this.path, this.sanitize(base));\n }\n\n file(base: string) {\n return new File(this.filepath(base));\n }\n\n get files() {\n return fs.readdirSync(this.path).map(filename => this.file(filename));\n }\n\n clear() {\n if (!this.isTemp) throw new Error('Dir is not temporary');\n fs.rmSync(this.path, { recursive: true, force: true });\n fs.mkdirSync(this.path, { recursive: true });\n }\n}\n\n/**\n * Current working directory\n */\nexport const cwd = new Dir('./');\n/**\n * ./.temp in current working directory\n */\nexport const temp = cwd.tempDir('.temp');\n","import { type Duration, isAfter, add } from 'date-fns';\nimport { Dir } from './Dir.ts';\n\n/**\n * Save data to a local file with an expiration.\n * Fresh/stale data is returned with a flag for if it's fresh or not,\n * so stale data can still be used if needed.\n */\nexport class Cache<T> {\n file;\n ttl;\n\n constructor(key: string, ttl: number | Duration, initialData?: T) {\n const dir = new Dir('.cache', { temp: true });\n this.file = dir.file(key).json<{ savedAt: string; data: T }>();\n this.ttl = typeof ttl === 'number' ? { minutes: ttl } : ttl;\n if (initialData) this.write(initialData);\n }\n\n write(data: T) {\n this.file.write({ savedAt: new Date().toUTCString(), data });\n }\n\n read(): [T | undefined, boolean] {\n const { savedAt, data } = this.file.read() || {};\n const isFresh = Boolean(savedAt && isAfter(add(savedAt, this.ttl), new Date()));\n return [data, isFresh];\n }\n}\n","import { merge } from 'lodash-es';\nimport extractDomain from 'extract-domain';\n\nexport type Route = string | URL;\n\ntype QueryVal = string | number | boolean | null | undefined;\nexport type Query = Record<string, QueryVal | QueryVal[]>;\n\nexport type FetchOptions = RequestInit & {\n base?: string;\n query?: Query;\n headers?: Record<string, string>;\n data?: any;\n timeout?: number;\n retries?: number;\n retryDelay?: number;\n};\n\n/**\n * Fetcher provides a quick way to set up a basic API connection\n * with options applied to every request.\n * Includes basic methods for requesting and parsing responses\n */\nexport class Fetcher {\n defaultOptions;\n\n constructor(opts: FetchOptions = {}) {\n this.defaultOptions = {\n timeout: 60000,\n retries: 0,\n retryDelay: 3000,\n ...opts,\n };\n }\n\n /**\n * Build URL with URLSearchParams if query is provided.\n * Also returns domain, to help with cookies\n */\n buildUrl(route: Route, opts: FetchOptions = {}): [URL, string] {\n const mergedOptions = merge({}, this.defaultOptions, opts);\n const params: [string, string][] = [];\n Object.entries(mergedOptions.query || {}).forEach(([key, val]) => {\n if (val === undefined) return;\n if (Array.isArray(val)) {\n val.forEach(v => {\n params.push([key, `${v}`]);\n });\n } else {\n params.push([key, `${val}`]);\n }\n });\n const search = params.length > 0 ? '?' + new URLSearchParams(params).toString() : '';\n const url = new URL(route + search, this.defaultOptions.base);\n const domain = extractDomain(url.href) as string;\n return [url, domain];\n }\n\n /**\n * Merges options to get headers. Useful when extending the Fetcher class to add custom auth.\n */\n buildHeaders(route: Route, opts: FetchOptions = {}) {\n const { headers } = merge({}, this.defaultOptions, opts);\n return headers || {};\n }\n\n /**\n * Builds request, merging defaultOptions and provided options.\n * Includes Abort signal for timeout\n */\n buildRequest(route: Route, opts: FetchOptions = {}): [Request, FetchOptions, string] {\n const mergedOptions = merge({}, this.defaultOptions, opts);\n const { query, data, timeout, retries, ...init } = mergedOptions;\n init.headers = this.buildHeaders(route, mergedOptions);\n if (data) {\n init.headers['content-type'] = init.headers['content-type'] || 'application/json';\n init.method = init.method || 'POST';\n init.body = JSON.stringify(data);\n }\n if (timeout) {\n init.signal = AbortSignal.timeout(timeout);\n }\n const [url, domain] = this.buildUrl(route, mergedOptions);\n const req = new Request(url, init);\n return [req, mergedOptions, domain];\n }\n\n /**\n * Builds and performs the request, merging provided options with defaultOptions.\n * If `opts.data` is provided, method is updated to POST, content-type json, data is stringified in the body.\n * Retries on local or network error, with increasing backoff.\n */\n async fetch(route: Route, opts: FetchOptions = {}): Promise<[Response, Request]> {\n const [_req, options] = this.buildRequest(route, opts);\n const maxAttempts = (options.retries || 0) + 1;\n let attempt = 0;\n while (attempt < maxAttempts) {\n attempt++;\n const [req] = this.buildRequest(route, opts);\n const res = await fetch(req)\n .then(r => {\n if (!r.ok) throw new Error(r.statusText);\n return r;\n })\n .catch(async error => {\n if (attempt < maxAttempts) {\n const wait = attempt * 3000;\n console.warn(`${req.method} ${req.url} (attempt ${attempt} of ${maxAttempts})`, error);\n await new Promise(resolve => setTimeout(resolve, wait));\n } else {\n throw new Error(error);\n }\n });\n if (res) return [res, req];\n }\n throw new Error(`Failed to fetch ${_req.url}`);\n }\n\n async fetchText(route: Route, opts: FetchOptions = {}): Promise<[string, Response, Request]> {\n return this.fetch(route, opts).then(async ([res, req]) => {\n const text = await res.text();\n return [text, res, req];\n });\n }\n\n async fetchJson<T>(route: Route, opts: FetchOptions = {}): Promise<[T, Response, Request]> {\n return this.fetchText(route, opts).then(([txt, res, req]) => [JSON.parse(txt) as T, res, req]);\n }\n}\n","import { format, formatISO, type DateArg, type Duration } from 'date-fns';\nimport formatDuration from 'format-duration';\n\n/**\n * Helpers for formatting dates, times, and numbers as strings\n */\nexport class Format {\n /**\n * date-fns format() with some shortcuts\n * @param formatStr the format to use\n * @param date the date to format, default `new Date()`\n * @example\n * Format.date('iso') // '2026-04-08T13:56:45Z'\n * Format.date('ymd') // '20260408'\n * Format.date('ymd-hm') // '20260408-1356'\n * Format.date('ymd-hms') // '20260408-135645'\n * Format.date('h:m:s') // '13:56:45'\n * @see more format options https://date-fns.org/v4.1.0/docs/format\n */\n static date(\n formatStr: 'iso' | 'ymd' | 'ymd-hm' | 'ymd-hms' | 'h:m:s' | string = 'iso',\n d: DateArg<Date> = new Date(),\n ) {\n if (formatStr === 'iso') return formatISO(d);\n if (formatStr === 'ymd') return format(d, 'yyyyMMdd');\n if (formatStr === 'ymd-hm') return format(d, 'yyyyMMdd-HHmm');\n if (formatStr === 'ymd-hms') return format(d, 'yyyyMMdd-HHmmss');\n if (formatStr === 'h:m:s') return format(d, 'HH:mm:ss');\n return format(d, formatStr);\n }\n\n /**\n * Round a number to a specific set of places\n */\n static round(n: number, places = 0) {\n return new Intl.NumberFormat('en-US', { maximumFractionDigits: places }).format(n);\n }\n\n static plural(amount: number, singular: string, multiple?: string) {\n return amount === 1 ? `${amount} ${singular}` : `${amount} ${multiple || singular + 's'}`;\n }\n\n /**\n * Make millisecond durations actually readable (eg \"123ms\", \"3.56s\", \"1m 34s\", \"3h 24m\", \"2d 4h\")\n * @param ms milliseconds\n * @param style 'digital' to output as 'HH:MM:SS'\n * @see details on 'digital' format https://github.com/ungoldman/format-duration\n * @see waiting on `Intl.DurationFormat({ style: 'digital' })` types https://github.com/microsoft/TypeScript/issues/60608\n */\n static ms(ms: number, style?: 'digital') {\n if (style === 'digital') return formatDuration(ms, { leading: true });\n if (ms < 1000) return `${this.round(ms)}ms`;\n const s = ms / 1000;\n if (s < 60) return `${this.round(s, 2)}s`;\n const m = Math.floor(s / 60);\n if (m < 60) return `${m}m ${Math.floor(s) % 60}s`;\n const h = Math.floor(m / 60);\n if (h < 24) return `${h}h ${m % 60}m`;\n const d = Math.floor(h / 24);\n return `${d}d ${h % 24}h`;\n }\n\n static bytes(b: number) {\n const labels = ['b', 'KB', 'MB', 'GB', 'TB'];\n let factor = 0;\n while (b >= 1024 && labels[factor + 1]) {\n b = b / 1024;\n factor++;\n }\n return `${this.round(b, 2)} ${labels[factor]}`;\n }\n}\n","import { inspect } from 'node:util';\nimport { isObjectLike } from 'lodash-es';\nimport chalk, { type ChalkInstance } from 'chalk';\nimport { snapshot } from './snapshot.ts';\nimport { Format } from './Format.ts';\n\n// https://docs.cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry#logseverity\ntype Severity = 'DEFAULT' | 'DEBUG' | 'INFO' | 'NOTICE' | 'WARNING' | 'ERROR' | 'CRITICAL' | 'ALERT' | 'EMERGENCY';\n\ntype Options = {\n severity: Severity;\n color: ChalkInstance;\n};\n\ntype Entry = {\n message?: string;\n severity: Severity;\n stack?: string;\n details?: unknown[];\n};\n\nexport class Log {\n static getStack() {\n const details = { stack: '' };\n // replaces details.stack with current stack trace, excluding this Log.getStack call\n Error.captureStackTrace(details, Log.getStack);\n // remove 'Error' on first line\n return details.stack\n .split('\\n')\n .map(l => l.trim())\n .filter(l => l !== 'Error');\n }\n\n /**\n * Gcloud parses JSON in stdout\n */\n static #toGcloud(entry: Entry) {\n const details = entry.details?.length === 1 ? entry.details[0] : entry.details;\n const output = { ...entry, details, stack: entry.stack || this.getStack() };\n console.log(JSON.stringify(snapshot(output)));\n }\n\n /**\n * Includes colors and better inspection for logging during dev\n */\n static #toConsole(entry: Entry, color: ChalkInstance) {\n if (entry.message) console.log(color(`${Format.date('h:m:s')} [${entry.severity}] ${entry.message}`));\n entry.details?.forEach(detail => {\n console.log(inspect(detail, { depth: 10, breakLength: 100, compact: true, colors: true }));\n });\n }\n\n static #log({ severity, color }: Options, ...input: unknown[]) {\n const { message, details } = this.prepare(...input);\n const entry: Entry = { message, severity, details };\n // https://cloud.google.com/run/docs/container-contract#env-vars\n const isGcloud = process.env.K_SERVICE !== undefined || process.env.CLOUD_RUN_JOB !== undefined;\n if (isGcloud) {\n this.#toGcloud(entry);\n } else {\n this.#toConsole(entry, color);\n }\n return entry;\n }\n\n /**\n * Handle first argument being a string or an object with a 'message' prop\n */\n static prepare(...input: unknown[]): { message?: string; details: unknown[] } {\n let [firstArg, ...rest] = input;\n // First argument is a string, use that as the message\n if (typeof firstArg === 'string') {\n return { message: firstArg, details: rest };\n }\n // First argument is an object with a `message` property\n // @ts-ignore\n if (isObjectLike(firstArg) && typeof firstArg['message'] === 'string') {\n const { message, ...firstDetails } = firstArg as { message: string };\n return { message, details: [firstDetails, ...rest] };\n }\n // No message found, log all args as details\n return { details: input };\n }\n\n /**\n * Events that require action or attention immediately\n */\n static alert(...input: unknown[]) {\n return this.#log({ severity: 'ALERT', color: chalk.bgRed }, ...input);\n }\n\n /**\n * Events that cause problems\n */\n static error(...input: unknown[]) {\n return this.#log({ severity: 'ERROR', color: chalk.red }, ...input);\n }\n\n /**\n * Events that might cause problems\n */\n static warn(...input: unknown[]) {\n return this.#log({ severity: 'WARNING', color: chalk.yellow }, ...input);\n }\n\n /**\n * Normal but significant events, such as start up, shut down, or a configuration change\n */\n static notice(...input: unknown[]) {\n return this.#log({ severity: 'NOTICE', color: chalk.cyan }, ...input);\n }\n\n /**\n * Routine information, such as ongoing status or performance\n */\n static info(...input: unknown[]) {\n return this.#log({ severity: 'INFO', color: chalk.white }, ...input);\n }\n\n /**\n * Debug or trace information\n */\n static debug(...input: unknown[]) {\n return this.#log({ severity: 'DEBUG', color: chalk.gray }, ...input);\n }\n}\n","export async function timeout(ms: number) {\n return new Promise(resolve => {\n setTimeout(resolve, ms);\n });\n}\n","import * as fs from 'node:fs';\nimport { merge } from 'lodash-es';\nimport * as qt from 'quicktype-core';\n\nexport class TypeWriter {\n moduleName;\n input = qt.jsonInputForTargetLanguage('typescript');\n outDir;\n qtSettings;\n\n constructor(moduleName: string, settings: { outDir?: string } & Partial<qt.Options> = {}) {\n this.moduleName = moduleName;\n const { outDir, ...qtSettings } = settings;\n this.outDir = outDir || './types';\n const defaultSettings = {\n lang: 'typescript',\n rendererOptions: {\n 'just-types': true,\n 'prefer-types': true,\n },\n inferEnums: false,\n inferDateTimes: false,\n };\n this.qtSettings = merge(defaultSettings, qtSettings);\n }\n\n async addMember(name: string, _samples: any[]) {\n const samples = _samples.map(s => (typeof s === 'string' ? s : JSON.stringify(s)));\n await this.input.addSource({ name, samples });\n }\n\n async toString() {\n const inputData = new qt.InputData();\n inputData.addInput(this.input);\n const result = await qt.quicktype({\n inputData,\n ...this.qtSettings,\n });\n return result.lines.join('\\n');\n }\n\n async toFile() {\n const result = await this.toString();\n fs.mkdirSync(this.outDir, { recursive: true });\n fs.writeFileSync(`${this.outDir}/${this.moduleName}.d.ts`, result);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAMA,SAAgB,SAAS,GAAY,MAAM,IAAI,QAAQ,GAAQ;AAC7D,KAAI,MAAM,QAAQ,EAAE,EAAE;AACpB,MAAI,UAAU,IAAK,QAAO,EAAE;AAC5B,SAAO,EAAE,KAAI,MAAK,SAAS,GAAG,KAAK,QAAQ,EAAE,CAAC;;AAEhD,KAAI,OAAO,MAAM,WAAY,QAAO;AACpC,KAAI,CAAC,aAAa,EAAE,CAAE,QAAO;AAE7B,KAAI,UAAU,IAAK,QAAO,EAAE;CAC5B,IAAIA,SAA8B,EAAE;AAEpC,KAAI,OAAO,EAAE,YAAY,YAAY;AAEnC,OAAK,IAAI,CAAC,GAAG,MAAM,EAAE,SAAS,CAC5B,QAAO,KAAK,SAAS,GAAG,KAAK,QAAQ,EAAE;AAEzC,SAAO;;CAMT,MAAMC,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C3HxE,eAAsB,QAAQ,IAAY;AACxC,QAAO,IAAI,SAAQ,YAAW;AAC5B,aAAW,SAAS,GAAG;GACvB;;;;;ACCJ,IAAa,aAAb,MAAwB;CACtB;CACA,QAAQ,GAAG,2BAA2B,aAAa;CACnD;CACA;CAEA,YAAY,YAAoB,WAAsD,EAAE,EAAE;AACxF,OAAK,aAAa;EAClB,MAAM,EAAE,QAAQ,GAAG,eAAe;AAClC,OAAK,SAAS,UAAU;AAUxB,OAAK,aAAa,MATM;GACtB,MAAM;GACN,iBAAiB;IACf,cAAc;IACd,gBAAgB;IACjB;GACD,YAAY;GACZ,gBAAgB;GACjB,EACwC,WAAW;;CAGtD,MAAM,UAAU,MAAc,UAAiB;EAC7C,MAAM,UAAU,SAAS,KAAI,MAAM,OAAO,MAAM,WAAW,IAAI,KAAK,UAAU,EAAE,CAAE;AAClF,QAAM,KAAK,MAAM,UAAU;GAAE;GAAM;GAAS,CAAC;;CAG/C,MAAM,WAAW;EACf,MAAM,YAAY,IAAI,GAAG,WAAW;AACpC,YAAU,SAAS,KAAK,MAAM;AAK9B,UAJe,MAAM,GAAG,UAAU;GAChC;GACA,GAAG,KAAK;GACT,CAAC,EACY,MAAM,KAAK,KAAK;;CAGhC,MAAM,SAAS;EACb,MAAM,SAAS,MAAM,KAAK,UAAU;AACpC,KAAG,UAAU,KAAK,QAAQ,EAAE,WAAW,MAAM,CAAC;AAC9C,KAAG,cAAc,GAAG,KAAK,OAAO,GAAG,KAAK,WAAW,QAAQ,OAAO"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@brianbuie/node-kit",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0",
|
|
4
4
|
"license": "ISC",
|
|
5
5
|
"description": "Basic tools for Node.js projects",
|
|
6
6
|
"author": "Brian Buie <brian@buie.dev>",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"url": "git+https://github.com/brianbuie/node-kit.git"
|
|
10
10
|
},
|
|
11
11
|
"scripts": {
|
|
12
|
-
"build": "tsdown &&
|
|
12
|
+
"build": "prettier . -w && tsdown && ts2md --firstHeadingLevel=1",
|
|
13
13
|
"test": "tsc && node --test \"src/*.test.ts\" --quiet",
|
|
14
14
|
"preversion": "npm test && npm run build",
|
|
15
15
|
"postversion": "git push --follow-tags"
|
|
@@ -45,6 +45,7 @@
|
|
|
45
45
|
"sanitize-filename": "^1.6.3"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
|
+
"prettier": "^3.7.4",
|
|
48
49
|
"ts2md": "^0.2.8",
|
|
49
50
|
"tsdown": "^0.16.6",
|
|
50
51
|
"typescript": "^5.9.3"
|
package/src/Cache.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type Duration, isAfter, add } from 'date-fns';
|
|
2
|
-
import {
|
|
2
|
+
import { Dir } from './Dir.ts';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Save data to a local file with an expiration.
|
|
@@ -11,7 +11,7 @@ export class Cache<T> {
|
|
|
11
11
|
ttl;
|
|
12
12
|
|
|
13
13
|
constructor(key: string, ttl: number | Duration, initialData?: T) {
|
|
14
|
-
const dir = new
|
|
14
|
+
const dir = new Dir('.cache', { temp: true });
|
|
15
15
|
this.file = dir.file(key).json<{ savedAt: string; data: T }>();
|
|
16
16
|
this.ttl = typeof ttl === 'number' ? { minutes: ttl } : ttl;
|
|
17
17
|
if (initialData) this.write(initialData);
|
package/src/Dir.test.ts
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
import { describe, it } from 'node:test';
|
|
2
2
|
import assert from 'node:assert';
|
|
3
|
-
import
|
|
4
|
-
import { Dir, TempDir, temp } from './Dir.ts';
|
|
3
|
+
import { temp, Dir, type DirOptions } from './Dir.ts';
|
|
5
4
|
|
|
6
5
|
describe('Dir', () => {
|
|
7
6
|
const testDir = temp.dir('dir-test');
|
|
8
7
|
|
|
9
|
-
console.log(path.join('/dir1', '/dir2', 'dir3'));
|
|
10
|
-
|
|
11
8
|
it('Sanitizes filenames', () => {
|
|
12
9
|
const name = testDir.sanitize(':/something/else.json');
|
|
13
10
|
assert(!name.includes('/'));
|
|
@@ -21,14 +18,19 @@ describe('Dir', () => {
|
|
|
21
18
|
assert(sub.path.includes(subPath));
|
|
22
19
|
});
|
|
23
20
|
|
|
24
|
-
it('.tempDir returns
|
|
21
|
+
it('.tempDir returns temporary directory', () => {
|
|
25
22
|
const sub = testDir.tempDir('example');
|
|
26
|
-
assert(sub
|
|
23
|
+
assert(sub.isTemp);
|
|
27
24
|
});
|
|
28
25
|
|
|
29
|
-
it('.dir()
|
|
26
|
+
it('.dir() makes relative paths', () => {
|
|
30
27
|
assert(testDir.dir('/').path.includes(testDir.path));
|
|
31
|
-
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('.isTemp flows down to child Dirs', () => {
|
|
31
|
+
const base = testDir.tempDir('temp-by-default');
|
|
32
|
+
const child = base.dir('child');
|
|
33
|
+
assert(child.isTemp);
|
|
32
34
|
});
|
|
33
35
|
|
|
34
36
|
it('Resolves filenames in folder', () => {
|
|
@@ -36,4 +38,22 @@ describe('Dir', () => {
|
|
|
36
38
|
assert(txt.includes(testDir.path));
|
|
37
39
|
assert(txt.includes('test.txt'));
|
|
38
40
|
});
|
|
41
|
+
|
|
42
|
+
it('is extendable and chains methods correctly', () => {
|
|
43
|
+
class Example extends Dir {
|
|
44
|
+
get jsonFiles() {
|
|
45
|
+
return this.files.filter(f => f.ext === '.json');
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
const testRoot = testDir.tempDir('extendable');
|
|
49
|
+
const test = new Example(testRoot.path);
|
|
50
|
+
const child = test.dir('child');
|
|
51
|
+
assert(child instanceof Example);
|
|
52
|
+
child.file('child.json').json({});
|
|
53
|
+
assert(child.jsonFiles.length === 1);
|
|
54
|
+
const childTemp = child.tempDir('temp-child');
|
|
55
|
+
assert(childTemp instanceof Example);
|
|
56
|
+
childTemp.file('child-temp').json({});
|
|
57
|
+
assert(childTemp.jsonFiles.length === 1);
|
|
58
|
+
});
|
|
39
59
|
});
|
package/src/Dir.ts
CHANGED
|
@@ -3,20 +3,28 @@ import * as path from 'node:path';
|
|
|
3
3
|
import sanitizeFilename from 'sanitize-filename';
|
|
4
4
|
import { File } from './File.ts';
|
|
5
5
|
|
|
6
|
+
export type DirOptions = {
|
|
7
|
+
temp?: boolean;
|
|
8
|
+
};
|
|
9
|
+
|
|
6
10
|
/**
|
|
7
11
|
* Reference to a specific directory with methods to create and list files.
|
|
8
|
-
*
|
|
9
|
-
*
|
|
12
|
+
* @param inputPath
|
|
13
|
+
* The path of the directory, created on file system the first time `.path` is read or any methods are used
|
|
14
|
+
* @param options
|
|
15
|
+
* include `{ temp: true }` to enable the `.clear()` method
|
|
10
16
|
*/
|
|
11
17
|
export class Dir {
|
|
12
18
|
#inputPath;
|
|
13
19
|
#resolved?: string;
|
|
20
|
+
isTemp;
|
|
14
21
|
|
|
15
22
|
/**
|
|
16
23
|
* @param path can be relative to workspace or absolute
|
|
17
24
|
*/
|
|
18
|
-
constructor(inputPath =
|
|
25
|
+
constructor(inputPath: string, options: DirOptions = {}) {
|
|
19
26
|
this.#inputPath = inputPath;
|
|
27
|
+
this.isTemp = Boolean(options.temp);
|
|
20
28
|
}
|
|
21
29
|
|
|
22
30
|
/**
|
|
@@ -32,23 +40,26 @@ export class Dir {
|
|
|
32
40
|
|
|
33
41
|
/**
|
|
34
42
|
* Create a new Dir inside the current Dir
|
|
35
|
-
* @param subPath
|
|
43
|
+
* @param subPath
|
|
44
|
+
* joined with parent Dir's path to make new Dir
|
|
45
|
+
* @param options
|
|
46
|
+
* include `{ temp: true }` to enable the `.clear()` method. If current Dir is temporary, child directories will also be temporary.
|
|
36
47
|
* @example
|
|
37
48
|
* const folder = new Dir('example');
|
|
38
49
|
* // folder.path = '/path/to/cwd/example'
|
|
39
50
|
* const child = folder.dir('path/to/dir');
|
|
40
51
|
* // child.path = '/path/to/cwd/example/path/to/dir'
|
|
41
52
|
*/
|
|
42
|
-
dir(subPath: string) {
|
|
43
|
-
return new Dir(path.join(this.path, subPath));
|
|
53
|
+
dir(subPath: string, options: DirOptions = { temp: this.isTemp }) {
|
|
54
|
+
return new (this.constructor as typeof Dir)(path.join(this.path, subPath), options) as this;
|
|
44
55
|
}
|
|
45
56
|
|
|
46
57
|
/**
|
|
47
|
-
* Creates a new
|
|
58
|
+
* Creates a new temp directory inside current Dir
|
|
48
59
|
* @param subPath joined with parent Dir's path to make new TempDir
|
|
49
60
|
*/
|
|
50
61
|
tempDir(subPath: string) {
|
|
51
|
-
return
|
|
62
|
+
return this.dir(subPath, { temp: true });
|
|
52
63
|
}
|
|
53
64
|
|
|
54
65
|
sanitize(filename: string) {
|
|
@@ -74,21 +85,9 @@ export class Dir {
|
|
|
74
85
|
get files() {
|
|
75
86
|
return fs.readdirSync(this.path).map(filename => this.file(filename));
|
|
76
87
|
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* Extends Dir class with method to `clear()` contents.
|
|
81
|
-
* Default path: `./.temp`
|
|
82
|
-
*/
|
|
83
|
-
export class TempDir extends Dir {
|
|
84
|
-
constructor(inputPath = `./.temp`) {
|
|
85
|
-
super(inputPath);
|
|
86
|
-
}
|
|
87
88
|
|
|
88
|
-
/**
|
|
89
|
-
* > ⚠️ Warning! This deletes the directory!
|
|
90
|
-
*/
|
|
91
89
|
clear() {
|
|
90
|
+
if (!this.isTemp) throw new Error('Dir is not temporary');
|
|
92
91
|
fs.rmSync(this.path, { recursive: true, force: true });
|
|
93
92
|
fs.mkdirSync(this.path, { recursive: true });
|
|
94
93
|
}
|
package/src/Fetcher.ts
CHANGED
|
@@ -43,7 +43,7 @@ export class Fetcher {
|
|
|
43
43
|
Object.entries(mergedOptions.query || {}).forEach(([key, val]) => {
|
|
44
44
|
if (val === undefined) return;
|
|
45
45
|
if (Array.isArray(val)) {
|
|
46
|
-
val.forEach(
|
|
46
|
+
val.forEach(v => {
|
|
47
47
|
params.push([key, `${v}`]);
|
|
48
48
|
});
|
|
49
49
|
} else {
|
|
@@ -98,15 +98,15 @@ export class Fetcher {
|
|
|
98
98
|
attempt++;
|
|
99
99
|
const [req] = this.buildRequest(route, opts);
|
|
100
100
|
const res = await fetch(req)
|
|
101
|
-
.then(
|
|
101
|
+
.then(r => {
|
|
102
102
|
if (!r.ok) throw new Error(r.statusText);
|
|
103
103
|
return r;
|
|
104
104
|
})
|
|
105
|
-
.catch(async
|
|
105
|
+
.catch(async error => {
|
|
106
106
|
if (attempt < maxAttempts) {
|
|
107
107
|
const wait = attempt * 3000;
|
|
108
108
|
console.warn(`${req.method} ${req.url} (attempt ${attempt} of ${maxAttempts})`, error);
|
|
109
|
-
await new Promise(
|
|
109
|
+
await new Promise(resolve => setTimeout(resolve, wait));
|
|
110
110
|
} else {
|
|
111
111
|
throw new Error(error);
|
|
112
112
|
}
|
package/src/File.test.ts
CHANGED
|
@@ -17,7 +17,7 @@ const thing = {
|
|
|
17
17
|
describe('File', () => {
|
|
18
18
|
it('Handles request body as stream input', async () => {
|
|
19
19
|
const img = testDir.file('image.jpg');
|
|
20
|
-
await fetch('https://testingbot.com/free-online-tools/random-avatar/300').then(
|
|
20
|
+
await fetch('https://testingbot.com/free-online-tools/random-avatar/300').then(res => {
|
|
21
21
|
if (!res.body) throw new Error('No response body');
|
|
22
22
|
return img.write(res.body);
|
|
23
23
|
});
|
|
@@ -74,7 +74,7 @@ describe('FileTypeNdjson', () => {
|
|
|
74
74
|
assert(file.lines().length === 2);
|
|
75
75
|
file.append(thing);
|
|
76
76
|
assert(file.lines().length === 3);
|
|
77
|
-
file.lines().forEach(
|
|
77
|
+
file.lines().forEach(line => {
|
|
78
78
|
assert.deepStrictEqual(line, thing);
|
|
79
79
|
});
|
|
80
80
|
});
|
|
@@ -93,7 +93,7 @@ describe('FileTypeCsv', () => {
|
|
|
93
93
|
const things = [thing, thing, thing];
|
|
94
94
|
const file = await testDir.file('csv-data').csv(things);
|
|
95
95
|
const parsed = await file.read();
|
|
96
|
-
parsed.forEach(
|
|
96
|
+
parsed.forEach(row => {
|
|
97
97
|
assert.deepEqual(row, thing);
|
|
98
98
|
});
|
|
99
99
|
});
|
package/src/Log.ts
CHANGED
|
@@ -4,6 +4,7 @@ import chalk, { type ChalkInstance } from 'chalk';
|
|
|
4
4
|
import { snapshot } from './snapshot.ts';
|
|
5
5
|
import { Format } from './Format.ts';
|
|
6
6
|
|
|
7
|
+
// https://docs.cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry#logseverity
|
|
7
8
|
type Severity = 'DEFAULT' | 'DEBUG' | 'INFO' | 'NOTICE' | 'WARNING' | 'ERROR' | 'CRITICAL' | 'ALERT' | 'EMERGENCY';
|
|
8
9
|
|
|
9
10
|
type Options = {
|
|
@@ -82,25 +83,43 @@ export class Log {
|
|
|
82
83
|
}
|
|
83
84
|
|
|
84
85
|
/**
|
|
85
|
-
*
|
|
86
|
+
* Events that require action or attention immediately
|
|
87
|
+
*/
|
|
88
|
+
static alert(...input: unknown[]) {
|
|
89
|
+
return this.#log({ severity: 'ALERT', color: chalk.bgRed }, ...input);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Events that cause problems
|
|
86
94
|
*/
|
|
87
95
|
static error(...input: unknown[]) {
|
|
88
|
-
|
|
89
|
-
throw new Error(message);
|
|
96
|
+
return this.#log({ severity: 'ERROR', color: chalk.red }, ...input);
|
|
90
97
|
}
|
|
91
98
|
|
|
99
|
+
/**
|
|
100
|
+
* Events that might cause problems
|
|
101
|
+
*/
|
|
92
102
|
static warn(...input: unknown[]) {
|
|
93
103
|
return this.#log({ severity: 'WARNING', color: chalk.yellow }, ...input);
|
|
94
104
|
}
|
|
95
105
|
|
|
106
|
+
/**
|
|
107
|
+
* Normal but significant events, such as start up, shut down, or a configuration change
|
|
108
|
+
*/
|
|
96
109
|
static notice(...input: unknown[]) {
|
|
97
110
|
return this.#log({ severity: 'NOTICE', color: chalk.cyan }, ...input);
|
|
98
111
|
}
|
|
99
112
|
|
|
113
|
+
/**
|
|
114
|
+
* Routine information, such as ongoing status or performance
|
|
115
|
+
*/
|
|
100
116
|
static info(...input: unknown[]) {
|
|
101
117
|
return this.#log({ severity: 'INFO', color: chalk.white }, ...input);
|
|
102
118
|
}
|
|
103
119
|
|
|
120
|
+
/**
|
|
121
|
+
* Debug or trace information
|
|
122
|
+
*/
|
|
104
123
|
static debug(...input: unknown[]) {
|
|
105
124
|
return this.#log({ severity: 'DEBUG', color: chalk.gray }, ...input);
|
|
106
125
|
}
|
package/src/TypeWriter.ts
CHANGED
|
@@ -25,7 +25,7 @@ export class TypeWriter {
|
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
async addMember(name: string, _samples: any[]) {
|
|
28
|
-
const samples = _samples.map(
|
|
28
|
+
const samples = _samples.map(s => (typeof s === 'string' ? s : JSON.stringify(s)));
|
|
29
29
|
await this.input.addSource({ name, samples });
|
|
30
30
|
}
|
|
31
31
|
|
package/src/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { Dir,
|
|
1
|
+
export { Dir, type DirOptions, temp, cwd } from './Dir.ts';
|
|
2
2
|
export { Cache } from './Cache.ts';
|
|
3
3
|
export { Fetcher, type Route, type Query, type FetchOptions } from './Fetcher.ts';
|
|
4
4
|
export { File, FileType, FileTypeJson, FileTypeNdjson, FileTypeCsv } from './File.ts';
|
package/src/snapshot.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { isObjectLike } from 'lodash-es';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* Allows special objects (Error, Headers, Set) to be included in JSON.stringify output
|
|
5
|
-
*
|
|
4
|
+
* Allows special objects (Error, Headers, Set) to be included in JSON.stringify output.
|
|
5
|
+
* Functions are removed
|
|
6
6
|
*/
|
|
7
7
|
export function snapshot(i: unknown, max = 50, depth = 0): any {
|
|
8
8
|
if (Array.isArray(i)) {
|
|
9
9
|
if (depth === max) return [];
|
|
10
|
-
return i.map(
|
|
10
|
+
return i.map(c => snapshot(c, max, depth + 1));
|
|
11
11
|
}
|
|
12
12
|
if (typeof i === 'function') return undefined;
|
|
13
13
|
if (!isObjectLike(i)) return i;
|
|
@@ -32,7 +32,7 @@ export function snapshot(i: unknown, max = 50, depth = 0): any {
|
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
// Get Non-enumberable, own properties
|
|
35
|
-
Object.getOwnPropertyNames(obj).forEach(
|
|
35
|
+
Object.getOwnPropertyNames(obj).forEach(key => {
|
|
36
36
|
output[key] = snapshot(obj[key], max, depth + 1);
|
|
37
37
|
});
|
|
38
38
|
|
package/src/timeout.ts
CHANGED