@radheim/util 0.0.0-stage → 2.4.3
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/dist/abort.d.ts +1 -0
- package/dist/abort.js +8 -0
- package/dist/activity-calendar.d.ts +21 -0
- package/dist/activity-calendar.js +42 -0
- package/dist/artifact.d.ts +4 -0
- package/dist/artifact.js +85 -0
- package/dist/base64.d.ts +4 -0
- package/dist/base64.js +24 -0
- package/dist/binary.d.ts +7 -0
- package/dist/binary.js +34 -0
- package/dist/bom.d.ts +22 -0
- package/dist/bom.js +36 -0
- package/dist/cross-spawn-spawner.d.ts +9 -0
- package/dist/cross-spawn-spawner.js +548 -0
- package/dist/duration.d.ts +2 -0
- package/dist/duration.js +22 -0
- package/dist/effect/app-node-platform.d.ts +13 -0
- package/dist/effect/app-node-platform.js +29 -0
- package/dist/effect/app-node.d.ts +16 -0
- package/dist/effect/app-node.js +8 -0
- package/dist/effect/layer-node.d.ts +178 -0
- package/dist/effect/layer-node.js +248 -0
- package/dist/effect-flock.d.ts +31 -0
- package/dist/effect-flock.js +186 -0
- package/dist/encode.d.ts +4 -0
- package/dist/encode.js +38 -0
- package/dist/execute-output.d.ts +10 -0
- package/dist/execute-output.js +22 -0
- package/dist/flock.d.ts +28 -0
- package/dist/flock.js +267 -0
- package/dist/fs-util.d.ts +54 -0
- package/dist/fs-util.js +200 -0
- package/dist/glob.d.ts +18 -0
- package/dist/glob.js +29 -0
- package/dist/global-roots.d.ts +8 -0
- package/dist/global-roots.js +17 -0
- package/dist/global-roots.workerd.d.ts +7 -0
- package/dist/global-roots.workerd.js +15 -0
- package/dist/global.d.ts +30 -0
- package/dist/global.js +54 -0
- package/dist/hash.d.ts +4 -0
- package/dist/hash.js +12 -0
- package/dist/heap-snapshot.d.ts +19 -0
- package/dist/heap-snapshot.js +38 -0
- package/dist/no-timeout-fetch.d.ts +1 -0
- package/dist/no-timeout-fetch.js +4 -0
- package/dist/npm-config.d.ts +4 -0
- package/dist/npm-config.js +34 -0
- package/dist/npm.d.ts +45 -0
- package/dist/npm.js +441 -0
- package/dist/observability/logging.d.ts +14 -0
- package/dist/observability/logging.js +151 -0
- package/dist/observability/otlp.d.ts +19 -0
- package/dist/observability/otlp.js +63 -0
- package/dist/observability/shared.d.ts +1 -0
- package/dist/observability/shared.js +7 -0
- package/dist/observability/tracing.d.ts +2 -0
- package/dist/observability/tracing.js +3 -0
- package/dist/observability.d.ts +13 -0
- package/dist/observability.js +37 -0
- package/dist/open.d.ts +2 -0
- package/dist/open.js +10 -0
- package/dist/patch.d.ts +43 -0
- package/dist/patch.js +332 -0
- package/dist/path.d.ts +20 -0
- package/dist/path.js +134 -0
- package/dist/process-signal.d.ts +5 -0
- package/dist/process-signal.js +22 -0
- package/dist/process.d.ts +54 -0
- package/dist/process.js +167 -0
- package/dist/qr.d.ts +15 -0
- package/dist/qr.js +295 -0
- package/dist/record.d.ts +2 -0
- package/dist/record.js +2 -0
- package/dist/retry.d.ts +8 -0
- package/dist/retry.js +45 -0
- package/dist/runtime/import.bun.d.ts +2 -0
- package/dist/runtime/import.bun.js +8 -0
- package/dist/runtime/import.node.d.ts +2 -0
- package/dist/runtime/import.node.js +62 -0
- package/dist/runtime/import.workerd.d.ts +2 -0
- package/dist/runtime/import.workerd.js +7 -0
- package/dist/runtime-import.d.ts +1 -0
- package/dist/runtime-import.js +1 -0
- package/dist/session-mention.d.ts +11 -0
- package/dist/session-mention.js +18 -0
- package/dist/session-title-fallback.d.ts +16 -0
- package/dist/session-title-fallback.js +23 -0
- package/dist/session-turn.d.ts +37 -0
- package/dist/session-turn.js +56 -0
- package/dist/teardown.d.ts +8 -0
- package/dist/teardown.js +16 -0
- package/dist/text-boundary.d.ts +11 -0
- package/dist/text-boundary.js +22 -0
- package/dist/uuid.d.ts +1 -0
- package/dist/uuid.js +14 -0
- package/package.json +71 -4
- package/README.md +0 -3
package/dist/abort.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function abort(controller: AbortController | undefined): void;
|
package/dist/abort.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// `controller.abort()` makes a new DOMException that records the caller's stack, and V8 keeps every frame's function
|
|
2
|
+
// and closure alive until something reads `.stack`. Aborting from a Solid cleanup or update then pins the whole batch
|
|
3
|
+
// it ran in, disposed computations and detached DOM included, for as long as the signal is reachable. This reason is
|
|
4
|
+
// made once, so its stack holds only this module's load.
|
|
5
|
+
const reason = new DOMException("signal is aborted without reason", "AbortError");
|
|
6
|
+
export function abort(controller) {
|
|
7
|
+
controller?.abort(reason);
|
|
8
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export declare function activityCalendar(input: {
|
|
2
|
+
activity: readonly {
|
|
3
|
+
date: string;
|
|
4
|
+
steps: number;
|
|
5
|
+
}[];
|
|
6
|
+
from: number;
|
|
7
|
+
to: number;
|
|
8
|
+
maxWeeks: number;
|
|
9
|
+
}): {
|
|
10
|
+
weeks: {
|
|
11
|
+
date: string;
|
|
12
|
+
steps: number;
|
|
13
|
+
level: number;
|
|
14
|
+
}[][];
|
|
15
|
+
months: {
|
|
16
|
+
week: number;
|
|
17
|
+
label: string;
|
|
18
|
+
span: number;
|
|
19
|
+
}[];
|
|
20
|
+
clipped: boolean;
|
|
21
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export function activityCalendar(input) {
|
|
2
|
+
// Extract local dates first, then use UTC ordinals so DST cannot add or drop cells.
|
|
3
|
+
const ordinal = (time) => {
|
|
4
|
+
const date = new Date(time);
|
|
5
|
+
return Date.UTC(date.getFullYear(), date.getMonth(), date.getDate()) / 86_400_000;
|
|
6
|
+
};
|
|
7
|
+
const from = ordinal(input.from);
|
|
8
|
+
const to = ordinal(input.to - 1);
|
|
9
|
+
const monday = from - ((new Date(from * 86_400_000).getUTCDay() + 6) % 7);
|
|
10
|
+
const total = input.to <= input.from ? 0 : Math.floor((to - monday) / 7) + 1;
|
|
11
|
+
const count = Math.min(total, 53, Math.max(1, Math.floor(input.maxWeeks)));
|
|
12
|
+
const start = monday + Math.max(0, total - count) * 7;
|
|
13
|
+
const values = new Map(input.activity.map((day) => [day.date, day.steps]));
|
|
14
|
+
const levels = [...new Set([...values.values()].filter((steps) => steps > 0))].sort((a, b) => a - b);
|
|
15
|
+
const weeks = Array.from({ length: count }, (_, week) => Array.from({ length: 7 }, (_, day) => {
|
|
16
|
+
const date = start + week * 7 + day;
|
|
17
|
+
const key = new Date(date * 86_400_000).toISOString().slice(0, 10);
|
|
18
|
+
const steps = values.get(key) ?? 0;
|
|
19
|
+
return {
|
|
20
|
+
date: key,
|
|
21
|
+
steps,
|
|
22
|
+
level: date < from || date > to
|
|
23
|
+
? -1
|
|
24
|
+
: steps === 0
|
|
25
|
+
? 0
|
|
26
|
+
: Math.max(1, Math.ceil(((levels.indexOf(steps) + 1) / levels.length) * 4)),
|
|
27
|
+
};
|
|
28
|
+
}));
|
|
29
|
+
const formatter = new Intl.DateTimeFormat("en-US", { month: "short", timeZone: "UTC" });
|
|
30
|
+
// Thursday identifies the month owning most of a week; partial edge weeks stay inside the range.
|
|
31
|
+
const months = weeks
|
|
32
|
+
.map((_, week) => ({
|
|
33
|
+
week,
|
|
34
|
+
label: formatter.format(Math.min(to, Math.max(from, start + week * 7 + 3)) * 86_400_000),
|
|
35
|
+
}))
|
|
36
|
+
.filter((month, index, months) => index === 0 || month.label !== months[index - 1].label);
|
|
37
|
+
return {
|
|
38
|
+
weeks,
|
|
39
|
+
months: months.map((month, index) => ({ ...month, span: (months[index + 1]?.week ?? count) - month.week })),
|
|
40
|
+
clipped: count < total,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/** How the app shows a file, from its extension. */
|
|
2
|
+
export type ArtifactKind = "image" | "svg" | "audio" | "video" | "pdf" | "html" | "markdown" | "mermaid" | "table" | "font" | "document" | "spreadsheet" | "presentation" | "text";
|
|
3
|
+
export declare function artifactMime(path: string): string | undefined;
|
|
4
|
+
export declare function artifactKind(path: string): ArtifactKind;
|
package/dist/artifact.js
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
const officeKinds = new Map([
|
|
2
|
+
["application/vnd.openxmlformats-officedocument.wordprocessingml.document", "document"],
|
|
3
|
+
["application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "spreadsheet"],
|
|
4
|
+
["application/vnd.openxmlformats-officedocument.presentationml.presentation", "presentation"],
|
|
5
|
+
]);
|
|
6
|
+
const mimes = new Map([
|
|
7
|
+
["png", "image/png"],
|
|
8
|
+
["jpg", "image/jpeg"],
|
|
9
|
+
["jpeg", "image/jpeg"],
|
|
10
|
+
["gif", "image/gif"],
|
|
11
|
+
["webp", "image/webp"],
|
|
12
|
+
["avif", "image/avif"],
|
|
13
|
+
["bmp", "image/bmp"],
|
|
14
|
+
["ico", "image/x-icon"],
|
|
15
|
+
["tif", "image/tiff"],
|
|
16
|
+
["tiff", "image/tiff"],
|
|
17
|
+
["heic", "image/heic"],
|
|
18
|
+
["svg", "image/svg+xml"],
|
|
19
|
+
["mp3", "audio/mpeg"],
|
|
20
|
+
["wav", "audio/wav"],
|
|
21
|
+
["ogg", "audio/ogg"],
|
|
22
|
+
["oga", "audio/ogg"],
|
|
23
|
+
["m4a", "audio/mp4"],
|
|
24
|
+
["aac", "audio/aac"],
|
|
25
|
+
["flac", "audio/flac"],
|
|
26
|
+
["opus", "audio/ogg"],
|
|
27
|
+
["weba", "audio/webm"],
|
|
28
|
+
["mp4", "video/mp4"],
|
|
29
|
+
["m4v", "video/mp4"],
|
|
30
|
+
["webm", "video/webm"],
|
|
31
|
+
["mov", "video/quicktime"],
|
|
32
|
+
["ogv", "video/ogg"],
|
|
33
|
+
["mkv", "video/x-matroska"],
|
|
34
|
+
["pdf", "application/pdf"],
|
|
35
|
+
["html", "text/html"],
|
|
36
|
+
["htm", "text/html"],
|
|
37
|
+
["md", "text/markdown"],
|
|
38
|
+
["markdown", "text/markdown"],
|
|
39
|
+
["mdx", "text/markdown"],
|
|
40
|
+
["mmd", "text/vnd.mermaid"],
|
|
41
|
+
["mermaid", "text/vnd.mermaid"],
|
|
42
|
+
["csv", "text/csv"],
|
|
43
|
+
["tsv", "text/tab-separated-values"],
|
|
44
|
+
["ttf", "font/ttf"],
|
|
45
|
+
["otf", "font/otf"],
|
|
46
|
+
["woff", "font/woff"],
|
|
47
|
+
["woff2", "font/woff2"],
|
|
48
|
+
["docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document"],
|
|
49
|
+
["xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"],
|
|
50
|
+
["pptx", "application/vnd.openxmlformats-officedocument.presentationml.presentation"],
|
|
51
|
+
]);
|
|
52
|
+
function artifactExtension(path) {
|
|
53
|
+
const name = path.split(/[\\/]/).pop() ?? "";
|
|
54
|
+
const index = name.lastIndexOf(".");
|
|
55
|
+
if (index <= 0)
|
|
56
|
+
return "";
|
|
57
|
+
return name.slice(index + 1).toLowerCase();
|
|
58
|
+
}
|
|
59
|
+
export function artifactMime(path) {
|
|
60
|
+
return mimes.get(artifactExtension(path));
|
|
61
|
+
}
|
|
62
|
+
export function artifactKind(path) {
|
|
63
|
+
const mime = artifactMime(path);
|
|
64
|
+
if (!mime)
|
|
65
|
+
return "text";
|
|
66
|
+
if (mime === "image/svg+xml")
|
|
67
|
+
return "svg";
|
|
68
|
+
if (mime === "application/pdf")
|
|
69
|
+
return "pdf";
|
|
70
|
+
if (mime === "text/html")
|
|
71
|
+
return "html";
|
|
72
|
+
if (mime === "text/markdown")
|
|
73
|
+
return "markdown";
|
|
74
|
+
if (mime === "text/vnd.mermaid")
|
|
75
|
+
return "mermaid";
|
|
76
|
+
if (mime === "text/csv" || mime === "text/tab-separated-values")
|
|
77
|
+
return "table";
|
|
78
|
+
if (mime.startsWith("image/"))
|
|
79
|
+
return "image";
|
|
80
|
+
if (mime.startsWith("audio/"))
|
|
81
|
+
return "audio";
|
|
82
|
+
if (mime.startsWith("font/"))
|
|
83
|
+
return "font";
|
|
84
|
+
return officeKinds.get(mime) ?? "video";
|
|
85
|
+
}
|
package/dist/base64.d.ts
ADDED
package/dist/base64.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// The native codecs (Chromium 140, Firefox 133, Safari 18.2) run about 100 times faster than a string round trip. The
|
|
2
|
+
// type libraries declare them, but older web browsers lack them, so each is read as possibly missing first.
|
|
3
|
+
const nativeEncode = Uint8Array.prototype.toBase64;
|
|
4
|
+
const nativeDecode = Uint8Array.fromBase64;
|
|
5
|
+
/** Encodes bytes as standard base64. */
|
|
6
|
+
export function bytesToBase64(bytes) {
|
|
7
|
+
if (nativeEncode)
|
|
8
|
+
return bytes.toBase64();
|
|
9
|
+
const parts = [];
|
|
10
|
+
for (let index = 0; index < bytes.length; index += 0x8000) {
|
|
11
|
+
parts.push(String.fromCharCode(...bytes.subarray(index, index + 0x8000)));
|
|
12
|
+
}
|
|
13
|
+
return btoa(parts.join(""));
|
|
14
|
+
}
|
|
15
|
+
/** Decodes standard base64 into bytes. */
|
|
16
|
+
export function base64ToBytes(value) {
|
|
17
|
+
if (nativeDecode)
|
|
18
|
+
return Uint8Array.fromBase64(value);
|
|
19
|
+
const binary = atob(value);
|
|
20
|
+
const bytes = new Uint8Array(binary.length);
|
|
21
|
+
for (let index = 0; index < binary.length; index++)
|
|
22
|
+
bytes[index] = binary.charCodeAt(index);
|
|
23
|
+
return bytes;
|
|
24
|
+
}
|
package/dist/binary.d.ts
ADDED
package/dist/binary.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export var Binary;
|
|
2
|
+
(function (Binary) {
|
|
3
|
+
function search(array, id, compare) {
|
|
4
|
+
let left = 0;
|
|
5
|
+
let right = array.length - 1;
|
|
6
|
+
while (left <= right) {
|
|
7
|
+
const middle = Math.floor((left + right) / 2);
|
|
8
|
+
const value = compare(array[middle]);
|
|
9
|
+
if (value === id)
|
|
10
|
+
return { found: true, index: middle };
|
|
11
|
+
if (value < id)
|
|
12
|
+
left = middle + 1;
|
|
13
|
+
else
|
|
14
|
+
right = middle - 1;
|
|
15
|
+
}
|
|
16
|
+
return { found: false, index: left };
|
|
17
|
+
}
|
|
18
|
+
Binary.search = search;
|
|
19
|
+
function insert(array, item, compare) {
|
|
20
|
+
const id = compare(item);
|
|
21
|
+
let left = 0;
|
|
22
|
+
let right = array.length;
|
|
23
|
+
while (left < right) {
|
|
24
|
+
const middle = Math.floor((left + right) / 2);
|
|
25
|
+
if (compare(array[middle]) < id)
|
|
26
|
+
left = middle + 1;
|
|
27
|
+
else
|
|
28
|
+
right = middle;
|
|
29
|
+
}
|
|
30
|
+
array.splice(left, 0, item);
|
|
31
|
+
return array;
|
|
32
|
+
}
|
|
33
|
+
Binary.insert = insert;
|
|
34
|
+
})(Binary || (Binary = {}));
|
package/dist/bom.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export * as Bom from "./bom.js";
|
|
2
|
+
import { Effect } from "effect";
|
|
3
|
+
import type { FSUtil } from "./fs-util.js";
|
|
4
|
+
export declare function split(text: string): {
|
|
5
|
+
bom: boolean;
|
|
6
|
+
text: string;
|
|
7
|
+
};
|
|
8
|
+
export declare function join(text: string, bom: boolean): string;
|
|
9
|
+
export declare function has(content: Uint8Array): boolean;
|
|
10
|
+
export declare function decodeBytes(content: Uint8Array): {
|
|
11
|
+
bom: boolean;
|
|
12
|
+
text: string;
|
|
13
|
+
};
|
|
14
|
+
export declare function syncBytes(content: Uint8Array, bom: boolean): {
|
|
15
|
+
text: string;
|
|
16
|
+
bytes: Uint8Array<ArrayBuffer> | undefined;
|
|
17
|
+
};
|
|
18
|
+
export declare const readFile: (fs: FSUtil.Interface, filepath: string) => Effect.Effect<{
|
|
19
|
+
bom: boolean;
|
|
20
|
+
text: string;
|
|
21
|
+
}, import("effect/PlatformError").PlatformError, never>;
|
|
22
|
+
export declare const syncFile: (fs: FSUtil.Interface, filepath: string, bom: boolean) => Effect.Effect<string, FSUtil.Error, never>;
|
package/dist/bom.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export * as Bom from "./bom.js";
|
|
2
|
+
import { Effect } from "effect";
|
|
3
|
+
const code = 0xfeff;
|
|
4
|
+
const value = String.fromCharCode(code);
|
|
5
|
+
export function split(text) {
|
|
6
|
+
const stripped = text.replace(/^\uFEFF+/, "");
|
|
7
|
+
return { bom: stripped.length !== text.length, text: stripped };
|
|
8
|
+
}
|
|
9
|
+
export function join(text, bom) {
|
|
10
|
+
const stripped = split(text).text;
|
|
11
|
+
return bom ? value + stripped : stripped;
|
|
12
|
+
}
|
|
13
|
+
export function has(content) {
|
|
14
|
+
return content[0] === 0xef && content[1] === 0xbb && content[2] === 0xbf;
|
|
15
|
+
}
|
|
16
|
+
export function decodeBytes(content) {
|
|
17
|
+
return split(decode(content));
|
|
18
|
+
}
|
|
19
|
+
export function syncBytes(content, bom) {
|
|
20
|
+
const decoded = decode(content);
|
|
21
|
+
const current = split(decoded);
|
|
22
|
+
const canonical = bom ? value + current.text : current.text;
|
|
23
|
+
return { text: current.text, bytes: decoded === canonical ? undefined : new TextEncoder().encode(canonical) };
|
|
24
|
+
}
|
|
25
|
+
export const readFile = Effect.fn("Bom.readFile")(function* (fs, filepath) {
|
|
26
|
+
return decodeBytes(yield* fs.readFile(filepath));
|
|
27
|
+
});
|
|
28
|
+
export const syncFile = Effect.fn("Bom.syncFile")(function* (fs, filepath, bom) {
|
|
29
|
+
const synced = syncBytes(yield* fs.readFile(filepath), bom);
|
|
30
|
+
if (synced.bytes)
|
|
31
|
+
yield* fs.writeWithDirs(filepath, synced.bytes);
|
|
32
|
+
return synced.text;
|
|
33
|
+
});
|
|
34
|
+
function decode(content) {
|
|
35
|
+
return new TextDecoder("utf-8", { ignoreBOM: true }).decode(content);
|
|
36
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ChildProcessSpawner } from "effect/process/ChildProcessSpawner";
|
|
2
|
+
/** Closing a child's scope escalates to SIGKILL after this, unless the command sets its own `forceKillAfter`. */
|
|
3
|
+
export declare const RELEASE_FORCE_KILL_AFTER = "3 seconds";
|
|
4
|
+
export declare class KilledBySignal extends Error {
|
|
5
|
+
readonly signal: NodeJS.Signals;
|
|
6
|
+
constructor(signal: NodeJS.Signals);
|
|
7
|
+
}
|
|
8
|
+
export declare const node: import("./effect/layer-node.js").Provider<ChildProcessSpawner, never, import("./effect/layer-node.js").Tag<"global">, true>;
|
|
9
|
+
export * as CrossSpawnSpawner from "./cross-spawn-spawner.js";
|