@pistonite/pure 0.26.5 → 0.26.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/src/fs/FsFileStandaloneImplFileAPI.ts +3 -2
- package/src/fs/FsFileStandaloneImplHandleAPI.ts +6 -5
- package/src/fs/FsImplEntryAPI.ts +1 -4
- package/src/fs/FsImplFileAPI.ts +4 -5
- package/src/fs/FsImplHandleAPI.ts +1 -4
- package/src/fs/FsOpenFile.ts +1 -4
- package/src/fs/FsSave.ts +4 -4
- package/src/log/index.ts +15 -154
- package/src/log/internal.ts +14 -0
- package/src/log/logger.ts +180 -0
- package/src/memory/erc.test.ts +2 -8
- package/src/memory/idgen.ts +1 -1
- package/src/sync/batch.ts +1 -6
- package/src/sync/debounce.ts +1 -3
- package/src/sync/serial.test.ts +1 -3
- package/src/sync/util.ts +1 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pistonite/pure",
|
|
3
|
-
"version": "0.26.
|
|
3
|
+
"version": "0.26.7",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Pure TypeScript libraries for my projects",
|
|
6
6
|
"homepage": "https://github.com/Pistonite/pure",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"vitest": "^3.2.4",
|
|
31
|
-
"mono-dev": "0.2.
|
|
31
|
+
"mono-dev": "0.2.3"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"denque": "^2.1.0"
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ilog } from "../log/internal.ts";
|
|
1
2
|
import { errstr } from "../result";
|
|
2
3
|
|
|
3
4
|
import { fsErr, FsErr, fsFail, type FsVoid, type FsResult } from "./FsError.ts";
|
|
@@ -29,7 +30,7 @@ export class FsFileStandaloneImplFileAPI implements FsFileStandalone {
|
|
|
29
30
|
const data = await this.file.arrayBuffer();
|
|
30
31
|
return { val: new Uint8Array(data) };
|
|
31
32
|
} catch (e) {
|
|
32
|
-
|
|
33
|
+
ilog.error(e);
|
|
33
34
|
return { err: fsFail(errstr(e)) };
|
|
34
35
|
}
|
|
35
36
|
}
|
|
@@ -41,7 +42,7 @@ export class FsFileStandaloneImplFileAPI implements FsFileStandalone {
|
|
|
41
42
|
const data = await this.file.text();
|
|
42
43
|
return { val: data };
|
|
43
44
|
} catch (e) {
|
|
44
|
-
|
|
45
|
+
ilog.error(e);
|
|
45
46
|
return { err: fsFail(errstr(e)) };
|
|
46
47
|
}
|
|
47
48
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ilog } from "../log/internal.ts";
|
|
1
2
|
import { errstr } from "../result";
|
|
2
3
|
|
|
3
4
|
import { fsErr, FsErr, fsFail, type FsVoid, type FsResult } from "./FsError.ts";
|
|
@@ -39,7 +40,7 @@ export class FsFileStandaloneImplHandleAPI implements FsFileStandalone {
|
|
|
39
40
|
});
|
|
40
41
|
return requestedPermission === "granted";
|
|
41
42
|
} catch (e) {
|
|
42
|
-
|
|
43
|
+
ilog.error(e);
|
|
43
44
|
return false;
|
|
44
45
|
}
|
|
45
46
|
}
|
|
@@ -58,7 +59,7 @@ export class FsFileStandaloneImplHandleAPI implements FsFileStandalone {
|
|
|
58
59
|
return { err: fsErr(FsErr.NotFound, "File not found") };
|
|
59
60
|
}
|
|
60
61
|
}
|
|
61
|
-
|
|
62
|
+
ilog.error(e);
|
|
62
63
|
return { err: fsFail(errstr(e)) };
|
|
63
64
|
}
|
|
64
65
|
}
|
|
@@ -79,7 +80,7 @@ export class FsFileStandaloneImplHandleAPI implements FsFileStandalone {
|
|
|
79
80
|
const data = await file.val.arrayBuffer();
|
|
80
81
|
return { val: new Uint8Array(data) };
|
|
81
82
|
} catch (e) {
|
|
82
|
-
|
|
83
|
+
ilog.error(e);
|
|
83
84
|
return { err: fsFail(errstr(e)) };
|
|
84
85
|
}
|
|
85
86
|
}
|
|
@@ -99,7 +100,7 @@ export class FsFileStandaloneImplHandleAPI implements FsFileStandalone {
|
|
|
99
100
|
const data = await file.val.text();
|
|
100
101
|
return { val: data };
|
|
101
102
|
} catch (e) {
|
|
102
|
-
|
|
103
|
+
ilog.error(e);
|
|
103
104
|
return { err: fsFail(errstr(e)) };
|
|
104
105
|
}
|
|
105
106
|
}
|
|
@@ -145,7 +146,7 @@ export class FsFileStandaloneImplHandleAPI implements FsFileStandalone {
|
|
|
145
146
|
};
|
|
146
147
|
}
|
|
147
148
|
}
|
|
148
|
-
|
|
149
|
+
ilog.error(e);
|
|
149
150
|
return { err: fsFail(errstr(e)) };
|
|
150
151
|
}
|
|
151
152
|
}
|
package/src/fs/FsImplEntryAPI.ts
CHANGED
|
@@ -25,10 +25,7 @@ export class FsImplEntryAPI
|
|
|
25
25
|
constructor(root: string, rootEntry: FileSystemDirectoryEntry) {
|
|
26
26
|
this.root = root;
|
|
27
27
|
this.rootEntry = rootEntry;
|
|
28
|
-
this.capabilities = {
|
|
29
|
-
write: false,
|
|
30
|
-
live: true,
|
|
31
|
-
};
|
|
28
|
+
this.capabilities = { write: false, live: true };
|
|
32
29
|
this.mgr = new FsFileMgr();
|
|
33
30
|
}
|
|
34
31
|
|
package/src/fs/FsImplFileAPI.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { ilog } from "../log/internal.ts";
|
|
2
|
+
|
|
1
3
|
import type { FsFile } from "./FsFile.ts";
|
|
2
4
|
import type {
|
|
3
5
|
FsFileSystem,
|
|
@@ -28,10 +30,7 @@ export class FsImplFileAPI
|
|
|
28
30
|
constructor(files: FileList) {
|
|
29
31
|
// this seems to also work for windows
|
|
30
32
|
this.root = files[0].webkitRelativePath.split("/", 1)[0];
|
|
31
|
-
this.capabilities = {
|
|
32
|
-
write: false,
|
|
33
|
-
live: false,
|
|
34
|
-
};
|
|
33
|
+
this.capabilities = { write: false, live: false };
|
|
35
34
|
this.files = {};
|
|
36
35
|
this.directories = {};
|
|
37
36
|
this.mgr = new FsFileMgr();
|
|
@@ -43,7 +42,7 @@ export class FsImplFileAPI
|
|
|
43
42
|
const normalized = fsNormalize(path);
|
|
44
43
|
if (normalized.err) {
|
|
45
44
|
// shouldn't happen since the path is from the File API
|
|
46
|
-
|
|
45
|
+
ilog.error("invalid path: " + path);
|
|
47
46
|
continue;
|
|
48
47
|
}
|
|
49
48
|
this.files[normalized.val] = file;
|
|
@@ -49,10 +49,7 @@ export class FsImplHandleAPI
|
|
|
49
49
|
this.rootHandle = rootHandle;
|
|
50
50
|
this.writeMode = write;
|
|
51
51
|
this.permissionStatus = "prompt";
|
|
52
|
-
this.capabilities = {
|
|
53
|
-
write,
|
|
54
|
-
live: true,
|
|
55
|
-
};
|
|
52
|
+
this.capabilities = { write, live: true };
|
|
56
53
|
this.mgr = new FsFileMgr();
|
|
57
54
|
}
|
|
58
55
|
|
package/src/fs/FsOpenFile.ts
CHANGED
|
@@ -160,10 +160,7 @@ const fsOpenFileWithFileSystemAccessAPI = async (
|
|
|
160
160
|
if (anyMimeType.length) {
|
|
161
161
|
convertedAccept["*/*"] = anyMimeType;
|
|
162
162
|
}
|
|
163
|
-
return {
|
|
164
|
-
description,
|
|
165
|
-
accept: convertedAccept,
|
|
166
|
-
};
|
|
163
|
+
return { description, accept: convertedAccept };
|
|
167
164
|
});
|
|
168
165
|
try {
|
|
169
166
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
package/src/fs/FsSave.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { ilog } from "../log/internal.ts";
|
|
2
|
+
|
|
1
3
|
import { fsFail, type FsVoid } from "./FsError.ts";
|
|
2
4
|
|
|
3
5
|
/** Save (download) a file using Blob */
|
|
@@ -11,7 +13,7 @@ export function fsSave(content: string | Uint8Array, filename: string): FsVoid {
|
|
|
11
13
|
saveAs(blob, filename);
|
|
12
14
|
return {};
|
|
13
15
|
} catch (e) {
|
|
14
|
-
|
|
16
|
+
ilog.error(e);
|
|
15
17
|
return { err: fsFail("save failed") };
|
|
16
18
|
}
|
|
17
19
|
}
|
|
@@ -35,9 +37,7 @@ type SaveAsFn = (
|
|
|
35
37
|
filename?: string,
|
|
36
38
|
options?: SaveAsFnOptions,
|
|
37
39
|
) => void;
|
|
38
|
-
type SaveAsFnOptions = {
|
|
39
|
-
autoBom: boolean;
|
|
40
|
-
};
|
|
40
|
+
type SaveAsFnOptions = { autoBom: boolean };
|
|
41
41
|
|
|
42
42
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
43
43
|
|
package/src/log/index.ts
CHANGED
|
@@ -1,154 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
* be turned on at the global level for debugging.
|
|
17
|
-
*
|
|
18
|
-
* You can also turn off each logger individually or at global level for debugging.
|
|
19
|
-
*
|
|
20
|
-
* Due to the nature of JS, all logging calls, even when turned off, will incur
|
|
21
|
-
* some small runtime overhead. While we could remove debug calls
|
|
22
|
-
* for release build, that's currently not done (and it would require
|
|
23
|
-
* bundler to inline the call to remove the call completely, which might
|
|
24
|
-
* not be the case)
|
|
25
|
-
*
|
|
26
|
-
* @module
|
|
27
|
-
*/
|
|
28
|
-
|
|
29
|
-
import { errstr } from "../result/index.ts";
|
|
30
|
-
|
|
31
|
-
export const LogLevel = {
|
|
32
|
-
Off: 0,
|
|
33
|
-
High: 1,
|
|
34
|
-
Info: 2,
|
|
35
|
-
Debug: 3,
|
|
36
|
-
} as const;
|
|
37
|
-
export type LogLevel = (typeof LogLevel)[keyof typeof LogLevel];
|
|
38
|
-
|
|
39
|
-
let globalLevel: LogLevel = LogLevel.High;
|
|
40
|
-
/**
|
|
41
|
-
* Suppress ALL logging.
|
|
42
|
-
*
|
|
43
|
-
* This overrides logger-level settings
|
|
44
|
-
*/
|
|
45
|
-
export const globalLogOff = () => (globalLevel = 0);
|
|
46
|
-
/**
|
|
47
|
-
* Enable +info logging for ALL loggers
|
|
48
|
-
*
|
|
49
|
-
* This overrides logger-level settings
|
|
50
|
-
*/
|
|
51
|
-
export const globalLogInfo = () => (globalLevel = 2);
|
|
52
|
-
/**
|
|
53
|
-
* Enable +debug logging for ALL loggers
|
|
54
|
-
*
|
|
55
|
-
* This overrides logger-level settings
|
|
56
|
-
*/
|
|
57
|
-
export const globalLogDebug = () => (globalLevel = 3);
|
|
58
|
-
|
|
59
|
-
/** Create a logger creator. Use the factory methods to finish making the logger */
|
|
60
|
-
export const logger = (name: string, color?: string): LoggerFactory => {
|
|
61
|
-
return {
|
|
62
|
-
default: () => new LoggerImpl(name, color, LogLevel.High),
|
|
63
|
-
debug: () => new LoggerImpl(name, color, LogLevel.Debug),
|
|
64
|
-
info: () => new LoggerImpl(name, color, LogLevel.Info),
|
|
65
|
-
off: () => new LoggerImpl(name, color, LogLevel.Off),
|
|
66
|
-
};
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
export type LoggerFactory = {
|
|
70
|
-
/** Standard important logger (warning and errors) */
|
|
71
|
-
default(): Logger;
|
|
72
|
-
/** Enable +info +debug logging for this logger */
|
|
73
|
-
debug(): Logger;
|
|
74
|
-
/** Enable +info logging for this logger */
|
|
75
|
-
info(): Logger;
|
|
76
|
-
/** Stop all logging, including warn and error */
|
|
77
|
-
off(): Logger;
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
export type Logger = {
|
|
81
|
-
/** Log a debug message */
|
|
82
|
-
debug(obj: unknown): void;
|
|
83
|
-
/** Log an info message */
|
|
84
|
-
info(obj: unknown): void;
|
|
85
|
-
/** Log a warning message */
|
|
86
|
-
warn(obj: unknown): void;
|
|
87
|
-
/** Log an error message */
|
|
88
|
-
error(obj: unknown): void;
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
class LoggerImpl implements Logger {
|
|
92
|
-
name: string;
|
|
93
|
-
color: string | undefined;
|
|
94
|
-
level: LogLevel;
|
|
95
|
-
|
|
96
|
-
constructor(name: string, color: string | undefined, level: LogLevel) {
|
|
97
|
-
this.name = name;
|
|
98
|
-
this.color =
|
|
99
|
-
"padding:0 3x;color:white" + (color ? `;background:${color}` : "");
|
|
100
|
-
this.level = level;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
debug(obj: unknown) {
|
|
104
|
-
if (globalLevel !== LogLevel.Debug && this.level !== LogLevel.Debug) {
|
|
105
|
-
return;
|
|
106
|
-
}
|
|
107
|
-
console.log(
|
|
108
|
-
`%cDEBUG%c${this.name}%c ${obj}`,
|
|
109
|
-
"background:gray;color:white;padding:0 3px",
|
|
110
|
-
this.color,
|
|
111
|
-
"color:inherit;background:inherit",
|
|
112
|
-
);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
info(obj: unknown) {
|
|
116
|
-
if (globalLevel < LogLevel.Info && this.level < LogLevel.Info) {
|
|
117
|
-
return;
|
|
118
|
-
}
|
|
119
|
-
console.log(
|
|
120
|
-
`%cINFO%c${this.name}%c ${obj}`,
|
|
121
|
-
"background:green;color:white;padding:0 3px",
|
|
122
|
-
this.color,
|
|
123
|
-
"color:inherit;background:inherit",
|
|
124
|
-
);
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
warn(obj: unknown) {
|
|
128
|
-
if (globalLevel < LogLevel.High || this.level < LogLevel.High) {
|
|
129
|
-
return;
|
|
130
|
-
}
|
|
131
|
-
console.warn(
|
|
132
|
-
`%cWARN%c${this.name}%c ${obj}`,
|
|
133
|
-
"background:orange;color:white;padding:0 3px",
|
|
134
|
-
this.color,
|
|
135
|
-
"color:inherit;background:inherit",
|
|
136
|
-
);
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
error(obj: unknown) {
|
|
140
|
-
if (globalLevel < LogLevel.High || this.level < LogLevel.High) {
|
|
141
|
-
return;
|
|
142
|
-
}
|
|
143
|
-
const msg = errstr(obj);
|
|
144
|
-
console.error(
|
|
145
|
-
`%cERROR%c${this.name}%c ${msg}`,
|
|
146
|
-
"background:orange;color:white;padding:0 3px",
|
|
147
|
-
this.color,
|
|
148
|
-
"color:inherit;background:inherit",
|
|
149
|
-
);
|
|
150
|
-
if (msg !== obj) {
|
|
151
|
-
console.error(obj);
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
}
|
|
1
|
+
export {
|
|
2
|
+
globalLogOff,
|
|
3
|
+
globalLogInfo,
|
|
4
|
+
globalLogDebug,
|
|
5
|
+
logger,
|
|
6
|
+
type LoggerFactory,
|
|
7
|
+
type Logger,
|
|
8
|
+
resettableLogger,
|
|
9
|
+
type ResettableLogger,
|
|
10
|
+
} from "./logger.ts";
|
|
11
|
+
export {
|
|
12
|
+
internalLogOff,
|
|
13
|
+
internalLogDebug,
|
|
14
|
+
internalLogInfo,
|
|
15
|
+
} from "./internal.ts";
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { resettableLogger } from "./logger.ts";
|
|
2
|
+
|
|
3
|
+
const { logger, off, debug, info } = resettableLogger("pure", "gray");
|
|
4
|
+
|
|
5
|
+
export const ilog = logger;
|
|
6
|
+
|
|
7
|
+
/** Set the internal log level of calls in this library to off */
|
|
8
|
+
export const internalLogOff = off;
|
|
9
|
+
|
|
10
|
+
/** Set the internal log level of calls in this library to debug */
|
|
11
|
+
export const internalLogDebug = debug;
|
|
12
|
+
|
|
13
|
+
/** Set the internal log level of calls in this library to info */
|
|
14
|
+
export const internalLogInfo = info;
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Client side log util
|
|
3
|
+
*
|
|
4
|
+
* This is rather simple logging stuff with the primary focus
|
|
5
|
+
* being easy to debug.
|
|
6
|
+
*
|
|
7
|
+
* Use {@link logger} to create a logger with a name and a color,
|
|
8
|
+
* then use one of the {@link LoggerFactory} methods to setup the logging level.
|
|
9
|
+
*
|
|
10
|
+
* There are 3 levels of logging:
|
|
11
|
+
* 1. (Default) Warnings and Errors only
|
|
12
|
+
* 2. Also log info messages
|
|
13
|
+
* 3. Also log debug messages.
|
|
14
|
+
*
|
|
15
|
+
* Each logger can turn on info and debug logging separately, or it can
|
|
16
|
+
* be turned on at the global level for debugging.
|
|
17
|
+
*
|
|
18
|
+
* You can also turn off each logger individually or at global level for debugging.
|
|
19
|
+
*
|
|
20
|
+
* Due to the nature of JS, all logging calls, even when turned off, will incur
|
|
21
|
+
* some small runtime overhead. While we could remove debug calls
|
|
22
|
+
* for release build, that's currently not done (and it would require
|
|
23
|
+
* bundler to inline the call to remove the call completely, which might
|
|
24
|
+
* not be the case)
|
|
25
|
+
*
|
|
26
|
+
* @module
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
import { errstr } from "../result/index.ts";
|
|
30
|
+
|
|
31
|
+
export const LogLevel = { Off: 0, High: 1, Info: 2, Debug: 3 } as const;
|
|
32
|
+
export type LogLevel = (typeof LogLevel)[keyof typeof LogLevel];
|
|
33
|
+
|
|
34
|
+
let globalLevel: LogLevel = LogLevel.High;
|
|
35
|
+
/**
|
|
36
|
+
* Suppress ALL logging.
|
|
37
|
+
*
|
|
38
|
+
* This overrides logger-level settings
|
|
39
|
+
*/
|
|
40
|
+
export const globalLogOff = () => {
|
|
41
|
+
globalLevel = LogLevel.Off;
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Enable +info logging for ALL loggers
|
|
45
|
+
*
|
|
46
|
+
* This overrides logger-level settings
|
|
47
|
+
*/
|
|
48
|
+
export const globalLogInfo = () => {
|
|
49
|
+
globalLevel = LogLevel.Info;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* Enable +debug logging for ALL loggers
|
|
53
|
+
*
|
|
54
|
+
* This overrides logger-level settings
|
|
55
|
+
*/
|
|
56
|
+
export const globalLogDebug = () => {
|
|
57
|
+
globalLevel = LogLevel.Debug;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
/** Create a logger creator. Use the factory methods to finish making the logger */
|
|
61
|
+
export const logger = (name: string, color?: string): LoggerFactory => {
|
|
62
|
+
return {
|
|
63
|
+
default: () => new LoggerImpl(name, color, LogLevel.High),
|
|
64
|
+
debug: () => new LoggerImpl(name, color, LogLevel.Debug),
|
|
65
|
+
info: () => new LoggerImpl(name, color, LogLevel.Info),
|
|
66
|
+
off: () => new LoggerImpl(name, color, LogLevel.Off),
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
/** Create a {@link ResettableLogger} that can be easily reconfigured */
|
|
71
|
+
export const resettableLogger = (
|
|
72
|
+
name: string,
|
|
73
|
+
color?: string,
|
|
74
|
+
): ResettableLogger => {
|
|
75
|
+
const logger = new LoggerImpl(name, color, LogLevel.High);
|
|
76
|
+
return {
|
|
77
|
+
logger,
|
|
78
|
+
debug: () => (logger.level = LogLevel.Debug),
|
|
79
|
+
info: () => (logger.level = LogLevel.Info),
|
|
80
|
+
off: () => (logger.level = LogLevel.Off),
|
|
81
|
+
};
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* A logger whose level can be changed later. Useful for libraries to expose,
|
|
86
|
+
* so users can easily debug calls in the library
|
|
87
|
+
*/
|
|
88
|
+
export type ResettableLogger = {
|
|
89
|
+
logger: Logger;
|
|
90
|
+
debug(): void;
|
|
91
|
+
info(): void;
|
|
92
|
+
off(): void;
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
export type LoggerFactory = {
|
|
96
|
+
/** Standard important logger (warning and errors) */
|
|
97
|
+
default(): Logger;
|
|
98
|
+
/** Enable +info +debug logging for this logger */
|
|
99
|
+
debug(): Logger;
|
|
100
|
+
/** Enable +info logging for this logger */
|
|
101
|
+
info(): Logger;
|
|
102
|
+
/** Stop all logging, including warn and error */
|
|
103
|
+
off(): Logger;
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
export type Logger = {
|
|
107
|
+
/** Log a debug message */
|
|
108
|
+
debug(obj: unknown): void;
|
|
109
|
+
/** Log an info message */
|
|
110
|
+
info(obj: unknown): void;
|
|
111
|
+
/** Log a warning message */
|
|
112
|
+
warn(obj: unknown): void;
|
|
113
|
+
/** Log an error message */
|
|
114
|
+
error(obj: unknown): void;
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
export class LoggerImpl implements Logger {
|
|
118
|
+
name: string;
|
|
119
|
+
color: string | undefined;
|
|
120
|
+
level: LogLevel;
|
|
121
|
+
|
|
122
|
+
constructor(name: string, color: string | undefined, level: LogLevel) {
|
|
123
|
+
this.name = name;
|
|
124
|
+
this.color =
|
|
125
|
+
"padding:0 3x;color:white" + (color ? `;background:${color}` : "");
|
|
126
|
+
this.level = level;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
debug(obj: unknown) {
|
|
130
|
+
if (globalLevel !== LogLevel.Debug && this.level !== LogLevel.Debug) {
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
console.debug(
|
|
134
|
+
`%cDEBUG%c${this.name}%c ${obj}`,
|
|
135
|
+
"background:gray;color:white;padding:0 3px",
|
|
136
|
+
this.color,
|
|
137
|
+
"color:inherit;background:inherit",
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
info(obj: unknown) {
|
|
142
|
+
if (globalLevel < LogLevel.Info && this.level < LogLevel.Info) {
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
console.info(
|
|
146
|
+
`%cINFO%c${this.name}%c ${obj}`,
|
|
147
|
+
"background:green;color:white;padding:0 3px",
|
|
148
|
+
this.color,
|
|
149
|
+
"color:inherit;background:inherit",
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
warn(obj: unknown) {
|
|
154
|
+
if (globalLevel < LogLevel.High || this.level < LogLevel.High) {
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
console.warn(
|
|
158
|
+
`%cWARN%c${this.name}%c ${obj}`,
|
|
159
|
+
"background:orange;color:white;padding:0 3px",
|
|
160
|
+
this.color,
|
|
161
|
+
"color:inherit;background:inherit",
|
|
162
|
+
);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
error(obj: unknown) {
|
|
166
|
+
if (globalLevel < LogLevel.High || this.level < LogLevel.High) {
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
const msg = errstr(obj);
|
|
170
|
+
console.error(
|
|
171
|
+
`%cERROR%c${this.name}%c ${msg}`,
|
|
172
|
+
"background:darkred;color:white;padding:0 3px",
|
|
173
|
+
this.color,
|
|
174
|
+
"color:inherit;background:inherit",
|
|
175
|
+
);
|
|
176
|
+
if (msg !== obj) {
|
|
177
|
+
console.error(obj);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
package/src/memory/erc.test.ts
CHANGED
|
@@ -2,10 +2,7 @@ import { describe, afterEach, expect, it } from "vitest";
|
|
|
2
2
|
|
|
3
3
|
import { type Erc, makeErcType } from "./erc.ts";
|
|
4
4
|
|
|
5
|
-
type Rc = {
|
|
6
|
-
value: string;
|
|
7
|
-
refCount: number;
|
|
8
|
-
};
|
|
5
|
+
type Rc = { value: string; refCount: number };
|
|
9
6
|
const Marker = Symbol("test");
|
|
10
7
|
type Marker = typeof Marker;
|
|
11
8
|
class Allocator {
|
|
@@ -74,10 +71,7 @@ class Allocator {
|
|
|
74
71
|
}
|
|
75
72
|
|
|
76
73
|
allocValue(value: string): number {
|
|
77
|
-
const rc: Rc = {
|
|
78
|
-
value,
|
|
79
|
-
refCount: 1,
|
|
80
|
-
};
|
|
74
|
+
const rc: Rc = { value, refCount: 1 };
|
|
81
75
|
for (let i = 0; i < this.mockMemory.length; i++) {
|
|
82
76
|
if (this.mockMemory[i] === undefined) {
|
|
83
77
|
this.mockMemory[i] = rc;
|
package/src/memory/idgen.ts
CHANGED
package/src/sync/batch.ts
CHANGED
|
@@ -166,12 +166,7 @@ class BatchImpl<TFn extends AnyFn> {
|
|
|
166
166
|
return this.execute(...args);
|
|
167
167
|
}
|
|
168
168
|
const { promise, resolve, reject } = makePromise<AwaitRet<TFn>>();
|
|
169
|
-
this.scheduled.push({
|
|
170
|
-
input: args,
|
|
171
|
-
promise,
|
|
172
|
-
resolve,
|
|
173
|
-
reject,
|
|
174
|
-
});
|
|
169
|
+
this.scheduled.push({ input: args, promise, resolve, reject });
|
|
175
170
|
|
|
176
171
|
return promise;
|
|
177
172
|
}
|
package/src/sync/debounce.ts
CHANGED
|
@@ -120,9 +120,7 @@ export type DebounceConstructor<TFn> = {
|
|
|
120
120
|
|
|
121
121
|
class DebounceImpl<TFn extends AnyFn> {
|
|
122
122
|
private idle: boolean;
|
|
123
|
-
private next?: PromiseHandle<AwaitRet<TFn>> & {
|
|
124
|
-
args: Parameters<TFn>;
|
|
125
|
-
};
|
|
123
|
+
private next?: PromiseHandle<AwaitRet<TFn>> & { args: Parameters<TFn> };
|
|
126
124
|
constructor(
|
|
127
125
|
private fn: TFn,
|
|
128
126
|
private interval: number,
|
package/src/sync/serial.test.ts
CHANGED
|
@@ -47,9 +47,7 @@ test("passing in arguments", async () => {
|
|
|
47
47
|
});
|
|
48
48
|
|
|
49
49
|
test("current serial number", async () => {
|
|
50
|
-
const execute = serial({
|
|
51
|
-
fn: (_, serial) => () => serial,
|
|
52
|
-
});
|
|
50
|
+
const execute = serial({ fn: (_, serial) => () => serial });
|
|
53
51
|
|
|
54
52
|
const one = await execute();
|
|
55
53
|
expect(one).toStrictEqual({ val: 1n });
|
package/src/sync/util.ts
CHANGED
|
@@ -14,11 +14,7 @@ export const makePromise = <T>(): {
|
|
|
14
14
|
"Promise callbacks not set. This is a bug in the JS engine!",
|
|
15
15
|
);
|
|
16
16
|
}
|
|
17
|
-
return {
|
|
18
|
-
promise,
|
|
19
|
-
resolve,
|
|
20
|
-
reject,
|
|
21
|
-
};
|
|
17
|
+
return { promise, resolve, reject };
|
|
22
18
|
};
|
|
23
19
|
|
|
24
20
|
export type PromiseHandle<T> = ReturnType<typeof makePromise<T>>;
|