@oh-my-pi-zen/pi-utils 16.3.6-zen.1
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/CHANGELOG.md +245 -0
- package/README.md +36 -0
- package/dist/types/abortable.d.ts +32 -0
- package/dist/types/async.d.ts +6 -0
- package/dist/types/binary.d.ts +17 -0
- package/dist/types/cli.d.ts +117 -0
- package/dist/types/color.d.ts +102 -0
- package/dist/types/dirs.d.ts +260 -0
- package/dist/types/env.d.ts +74 -0
- package/dist/types/fetch-retry.d.ts +94 -0
- package/dist/types/format.d.ts +37 -0
- package/dist/types/frontmatter.d.ts +25 -0
- package/dist/types/fs-error.d.ts +31 -0
- package/dist/types/glob.d.ts +28 -0
- package/dist/types/index.d.ts +35 -0
- package/dist/types/json-parse.d.ts +48 -0
- package/dist/types/json.d.ts +4 -0
- package/dist/types/logger.d.ts +83 -0
- package/dist/types/loop-phase.d.ts +10 -0
- package/dist/types/mermaid-ascii.d.ts +11 -0
- package/dist/types/mime.d.ts +29 -0
- package/dist/types/module-timer.d.ts +1 -0
- package/dist/types/path-tree.d.ts +76 -0
- package/dist/types/path.d.ts +2 -0
- package/dist/types/peek-file.d.ts +29 -0
- package/dist/types/postmortem.d.ts +37 -0
- package/dist/types/procmgr.d.ts +29 -0
- package/dist/types/prompt.d.ts +18 -0
- package/dist/types/ptree.d.ts +108 -0
- package/dist/types/ring.d.ts +93 -0
- package/dist/types/runtime-install.d.ts +68 -0
- package/dist/types/sanitize-text.d.ts +29 -0
- package/dist/types/snowflake.d.ts +25 -0
- package/dist/types/stream.d.ts +68 -0
- package/dist/types/tab-spacing.d.ts +24 -0
- package/dist/types/temp.d.ts +17 -0
- package/dist/types/timing-buffer.d.ts +22 -0
- package/dist/types/tls-fetch.d.ts +37 -0
- package/dist/types/type-guards.d.ts +3 -0
- package/dist/types/vendor/mermaid-ascii/ascii/ansi.d.ts +41 -0
- package/dist/types/vendor/mermaid-ascii/ascii/canvas.d.ts +89 -0
- package/dist/types/vendor/mermaid-ascii/ascii/class-diagram.d.ts +7 -0
- package/dist/types/vendor/mermaid-ascii/ascii/converter.d.ts +12 -0
- package/dist/types/vendor/mermaid-ascii/ascii/draw.d.ts +66 -0
- package/dist/types/vendor/mermaid-ascii/ascii/edge-bundling.d.ts +48 -0
- package/dist/types/vendor/mermaid-ascii/ascii/edge-routing.d.ts +43 -0
- package/dist/types/vendor/mermaid-ascii/ascii/er-diagram.d.ts +7 -0
- package/dist/types/vendor/mermaid-ascii/ascii/grid.d.ts +56 -0
- package/dist/types/vendor/mermaid-ascii/ascii/index.d.ts +65 -0
- package/dist/types/vendor/mermaid-ascii/ascii/multiline-utils.d.ts +27 -0
- package/dist/types/vendor/mermaid-ascii/ascii/pathfinder.d.ts +17 -0
- package/dist/types/vendor/mermaid-ascii/ascii/sequence.d.ts +7 -0
- package/dist/types/vendor/mermaid-ascii/ascii/shapes/circle.d.ts +11 -0
- package/dist/types/vendor/mermaid-ascii/ascii/shapes/corners.d.ts +34 -0
- package/dist/types/vendor/mermaid-ascii/ascii/shapes/diamond.d.ts +11 -0
- package/dist/types/vendor/mermaid-ascii/ascii/shapes/hexagon.d.ts +11 -0
- package/dist/types/vendor/mermaid-ascii/ascii/shapes/index.d.ts +26 -0
- package/dist/types/vendor/mermaid-ascii/ascii/shapes/rectangle.d.ts +31 -0
- package/dist/types/vendor/mermaid-ascii/ascii/shapes/rounded.d.ts +11 -0
- package/dist/types/vendor/mermaid-ascii/ascii/shapes/special.d.ts +59 -0
- package/dist/types/vendor/mermaid-ascii/ascii/shapes/stadium.d.ts +17 -0
- package/dist/types/vendor/mermaid-ascii/ascii/shapes/state.d.ts +30 -0
- package/dist/types/vendor/mermaid-ascii/ascii/shapes/types.d.ts +55 -0
- package/dist/types/vendor/mermaid-ascii/ascii/types.d.ts +206 -0
- package/dist/types/vendor/mermaid-ascii/ascii/validate.d.ts +51 -0
- package/dist/types/vendor/mermaid-ascii/ascii/xychart.d.ts +2 -0
- package/dist/types/vendor/mermaid-ascii/class/parser.d.ts +6 -0
- package/dist/types/vendor/mermaid-ascii/class/types.d.ts +102 -0
- package/dist/types/vendor/mermaid-ascii/er/parser.d.ts +6 -0
- package/dist/types/vendor/mermaid-ascii/er/types.d.ts +76 -0
- package/dist/types/vendor/mermaid-ascii/index.d.ts +1 -0
- package/dist/types/vendor/mermaid-ascii/multiline-utils.d.ts +9 -0
- package/dist/types/vendor/mermaid-ascii/parser.d.ts +7 -0
- package/dist/types/vendor/mermaid-ascii/sequence/parser.d.ts +6 -0
- package/dist/types/vendor/mermaid-ascii/sequence/types.d.ts +130 -0
- package/dist/types/vendor/mermaid-ascii/text-metrics.d.ts +21 -0
- package/dist/types/vendor/mermaid-ascii/types.d.ts +114 -0
- package/dist/types/vendor/mermaid-ascii/xychart/colors.d.ts +25 -0
- package/dist/types/vendor/mermaid-ascii/xychart/parser.d.ts +6 -0
- package/dist/types/vendor/mermaid-ascii/xychart/types.d.ts +145 -0
- package/dist/types/which.d.ts +37 -0
- package/dist/types/worker-host.d.ts +47 -0
- package/package.json +62 -0
- package/src/abortable.ts +109 -0
- package/src/async.ts +50 -0
- package/src/binary.ts +50 -0
- package/src/cli.ts +457 -0
- package/src/color.ts +302 -0
- package/src/dirs.ts +925 -0
- package/src/env.ts +226 -0
- package/src/fetch-retry.ts +355 -0
- package/src/format.ts +113 -0
- package/src/frontmatter.ts +162 -0
- package/src/fs-error.ts +56 -0
- package/src/glob.ts +189 -0
- package/src/index.ts +55 -0
- package/src/json-parse.ts +612 -0
- package/src/json.ts +10 -0
- package/src/logger.ts +672 -0
- package/src/loop-phase.ts +49 -0
- package/src/mermaid-ascii.ts +31 -0
- package/src/mime.ts +159 -0
- package/src/module-timer.ts +148 -0
- package/src/path-tree.ts +147 -0
- package/src/path.ts +28 -0
- package/src/peek-file.ts +188 -0
- package/src/postmortem.ts +222 -0
- package/src/procmgr.ts +195 -0
- package/src/prompt.ts +562 -0
- package/src/ptree.ts +395 -0
- package/src/ring.ts +169 -0
- package/src/runtime-install.ts +372 -0
- package/src/sanitize-text.ts +96 -0
- package/src/snowflake.ts +121 -0
- package/src/stream.ts +432 -0
- package/src/tab-spacing.ts +336 -0
- package/src/temp.ts +134 -0
- package/src/timing-buffer.ts +47 -0
- package/src/tls-fetch.ts +178 -0
- package/src/type-guards.ts +11 -0
- package/src/vendor/mermaid-ascii/NOTICE +33 -0
- package/src/vendor/mermaid-ascii/ascii/ansi.ts +409 -0
- package/src/vendor/mermaid-ascii/ascii/canvas.ts +476 -0
- package/src/vendor/mermaid-ascii/ascii/class-diagram.ts +699 -0
- package/src/vendor/mermaid-ascii/ascii/converter.ts +271 -0
- package/src/vendor/mermaid-ascii/ascii/draw.ts +1382 -0
- package/src/vendor/mermaid-ascii/ascii/edge-bundling.ts +328 -0
- package/src/vendor/mermaid-ascii/ascii/edge-routing.ts +297 -0
- package/src/vendor/mermaid-ascii/ascii/er-diagram.ts +441 -0
- package/src/vendor/mermaid-ascii/ascii/grid.ts +578 -0
- package/src/vendor/mermaid-ascii/ascii/index.ts +187 -0
- package/src/vendor/mermaid-ascii/ascii/multiline-utils.ts +78 -0
- package/src/vendor/mermaid-ascii/ascii/pathfinder.ts +215 -0
- package/src/vendor/mermaid-ascii/ascii/sequence.ts +460 -0
- package/src/vendor/mermaid-ascii/ascii/shapes/circle.ts +27 -0
- package/src/vendor/mermaid-ascii/ascii/shapes/corners.ts +127 -0
- package/src/vendor/mermaid-ascii/ascii/shapes/diamond.ts +27 -0
- package/src/vendor/mermaid-ascii/ascii/shapes/hexagon.ts +27 -0
- package/src/vendor/mermaid-ascii/ascii/shapes/index.ts +101 -0
- package/src/vendor/mermaid-ascii/ascii/shapes/rectangle.ts +175 -0
- package/src/vendor/mermaid-ascii/ascii/shapes/rounded.ts +27 -0
- package/src/vendor/mermaid-ascii/ascii/shapes/special.ts +296 -0
- package/src/vendor/mermaid-ascii/ascii/shapes/stadium.ts +114 -0
- package/src/vendor/mermaid-ascii/ascii/shapes/state.ts +192 -0
- package/src/vendor/mermaid-ascii/ascii/shapes/types.ts +73 -0
- package/src/vendor/mermaid-ascii/ascii/types.ts +273 -0
- package/src/vendor/mermaid-ascii/ascii/validate.ts +120 -0
- package/src/vendor/mermaid-ascii/ascii/xychart.ts +875 -0
- package/src/vendor/mermaid-ascii/class/parser.ts +290 -0
- package/src/vendor/mermaid-ascii/class/types.ts +121 -0
- package/src/vendor/mermaid-ascii/er/parser.ts +181 -0
- package/src/vendor/mermaid-ascii/er/types.ts +91 -0
- package/src/vendor/mermaid-ascii/index.ts +14 -0
- package/src/vendor/mermaid-ascii/multiline-utils.ts +30 -0
- package/src/vendor/mermaid-ascii/parser.ts +645 -0
- package/src/vendor/mermaid-ascii/sequence/parser.ts +207 -0
- package/src/vendor/mermaid-ascii/sequence/types.ts +146 -0
- package/src/vendor/mermaid-ascii/text-metrics.ts +71 -0
- package/src/vendor/mermaid-ascii/types.ts +164 -0
- package/src/vendor/mermaid-ascii/xychart/colors.ts +140 -0
- package/src/vendor/mermaid-ascii/xychart/parser.ts +115 -0
- package/src/vendor/mermaid-ascii/xychart/types.ts +150 -0
- package/src/which.ts +232 -0
- package/src/worker-host.ts +92 -0
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Replace the active log transports. Pass `console: true, file: false` for
|
|
3
|
+
* long-running services (the auth broker, etc.) that want their structured
|
|
4
|
+
* logs piped into a process supervisor instead of the rotating file.
|
|
5
|
+
*/
|
|
6
|
+
export declare function setTransports(opts: {
|
|
7
|
+
console?: boolean;
|
|
8
|
+
file?: boolean | string;
|
|
9
|
+
}): void;
|
|
10
|
+
/**
|
|
11
|
+
* Log an error message.
|
|
12
|
+
* @param message - The message to log.
|
|
13
|
+
* @param context - The context to log.
|
|
14
|
+
*/
|
|
15
|
+
export declare function error(message: string, context?: Record<string, unknown>): void;
|
|
16
|
+
/**
|
|
17
|
+
* Log a warning message.
|
|
18
|
+
* @param message - The message to log.
|
|
19
|
+
* @param context - The context to log.
|
|
20
|
+
*/
|
|
21
|
+
export declare function warn(message: string, context?: Record<string, unknown>): void;
|
|
22
|
+
/**
|
|
23
|
+
* Log an informational message.
|
|
24
|
+
* @param message - The message to log.
|
|
25
|
+
* @param context - The context to log.
|
|
26
|
+
*/
|
|
27
|
+
export declare function info(message: string, context?: Record<string, unknown>): void;
|
|
28
|
+
/**
|
|
29
|
+
* Log a debug message.
|
|
30
|
+
* @param message - The message to log.
|
|
31
|
+
* @param context - The context to log.
|
|
32
|
+
*/
|
|
33
|
+
export declare function debug(message: string, context?: Record<string, unknown>): void;
|
|
34
|
+
/**
|
|
35
|
+
* Streaming startup markers, enabled by `PI_DEBUG_STARTUP`. Unlike the
|
|
36
|
+
* PI_TIMING tree (printed only after startup completes), these write one
|
|
37
|
+
* synchronous stderr line as each phase begins/ends, so a hard hang still
|
|
38
|
+
* shows the last phase that started. `fs.writeSync(2)` is used deliberately:
|
|
39
|
+
* it cannot be reordered or buffered past a synchronous block of the event
|
|
40
|
+
* loop (dlopen, sync fs on a dead mount, spawnSync).
|
|
41
|
+
*/
|
|
42
|
+
export declare function startupMarker(text: string): void;
|
|
43
|
+
export declare function timingModeIncludes(option: "full" | "x"): boolean;
|
|
44
|
+
export declare function shouldExitAfterTimings(): boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Print collected timings as an indented tree.
|
|
47
|
+
* Each span shows wall duration; parents with children also show "(self)" for unattributed time.
|
|
48
|
+
* Sibling spans are sorted by start time. Spans whose intervals overlap with siblings ran in parallel.
|
|
49
|
+
*/
|
|
50
|
+
export declare function printTimings(): void;
|
|
51
|
+
/**
|
|
52
|
+
* Begin recording startup timings under a new root span.
|
|
53
|
+
* Idempotent: a second call while already recording is a no-op, so an explicit
|
|
54
|
+
* starter (main.ts) and any future early starter can coexist.
|
|
55
|
+
*/
|
|
56
|
+
export declare function startTiming(): void;
|
|
57
|
+
/**
|
|
58
|
+
* Record an externally-measured span as a leaf child of the active span (or root
|
|
59
|
+
* when no span is active). Used by {@link spliceModuleLoadBuffer} to fold
|
|
60
|
+
* preload-captured module windows into the tree.
|
|
61
|
+
*/
|
|
62
|
+
export declare function recordModuleLoadSpan(path: string, start: number, durationMs: number, bodyMs?: number, imports?: string[]): void;
|
|
63
|
+
/**
|
|
64
|
+
* End timing window and clear buffers.
|
|
65
|
+
*/
|
|
66
|
+
export declare function endTiming(): void;
|
|
67
|
+
/**
|
|
68
|
+
* Ops of the currently-open span chain (root → deepest), following the most
|
|
69
|
+
* recently started unfinished child at each level. Lets a startup watchdog
|
|
70
|
+
* name the phase a stalled startup is stuck in.
|
|
71
|
+
*/
|
|
72
|
+
export declare function openSpanPath(): string[];
|
|
73
|
+
/**
|
|
74
|
+
* Time a span. Three forms:
|
|
75
|
+
* time(op) — point event (zero-duration breadcrumb)
|
|
76
|
+
* time(op, fn, ...args) — wrap fn in a span; returns fn's return value (sync or Promise)
|
|
77
|
+
*
|
|
78
|
+
* Spans nest hierarchically via AsyncLocalStorage: a child started inside another span's fn
|
|
79
|
+
* (even across awaits) becomes that span's child. Parallel children are recorded as siblings
|
|
80
|
+
* with overlapping intervals.
|
|
81
|
+
*/
|
|
82
|
+
export declare function time(op: string): void;
|
|
83
|
+
export declare function time<T, A extends unknown[]>(op: string, fn: (...args: A) => T, ...args: A): T;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare function pushLoopPhase(label: string): void;
|
|
2
|
+
export declare function popLoopPhase(): void;
|
|
3
|
+
export declare function currentLoopPhase(): string | undefined;
|
|
4
|
+
/**
|
|
5
|
+
* Phase to blame for a just-detected loop block: the live top phase if one is
|
|
6
|
+
* still held, else the most recent phase pushed since the last call. Clears the
|
|
7
|
+
* recent slot so a block in a later, phase-less interval is not misattributed
|
|
8
|
+
* to a phase that already finished.
|
|
9
|
+
*/
|
|
10
|
+
export declare function takeRecentLoopPhase(): string | undefined;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type AsciiRenderOptions } from "./vendor/mermaid-ascii";
|
|
2
|
+
export type { AsciiRenderOptions as MermaidAsciiRenderOptions };
|
|
3
|
+
export declare function renderMermaidAscii(source: string, options?: AsciiRenderOptions): string;
|
|
4
|
+
export declare function renderMermaidAsciiSafe(source: string, options?: AsciiRenderOptions): string | null;
|
|
5
|
+
/**
|
|
6
|
+
* Extract mermaid code blocks from markdown text.
|
|
7
|
+
*/
|
|
8
|
+
export declare function extractMermaidBlocks(markdown: string): {
|
|
9
|
+
source: string;
|
|
10
|
+
hash: bigint | number;
|
|
11
|
+
}[];
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export declare const SUPPORTED_IMAGE_MIME_TYPES: Set<string>;
|
|
2
|
+
export type ImageMetadata = {
|
|
3
|
+
mimeType: "image/png";
|
|
4
|
+
width?: number;
|
|
5
|
+
height?: number;
|
|
6
|
+
channels?: number;
|
|
7
|
+
hasAlpha?: boolean;
|
|
8
|
+
} | {
|
|
9
|
+
mimeType: "image/jpeg";
|
|
10
|
+
width?: number;
|
|
11
|
+
height?: number;
|
|
12
|
+
channels?: number;
|
|
13
|
+
hasAlpha?: false;
|
|
14
|
+
} | {
|
|
15
|
+
mimeType: "image/gif";
|
|
16
|
+
width?: number;
|
|
17
|
+
height?: number;
|
|
18
|
+
channels?: 3;
|
|
19
|
+
hasAlpha?: never;
|
|
20
|
+
} | {
|
|
21
|
+
mimeType: "image/webp";
|
|
22
|
+
width?: number;
|
|
23
|
+
height?: number;
|
|
24
|
+
channels?: number;
|
|
25
|
+
hasAlpha?: boolean;
|
|
26
|
+
};
|
|
27
|
+
export declare function parseImageMetadata(header: Uint8Array): ImageMetadata | null;
|
|
28
|
+
export declare function readImageMetadataSync(filePath: string, maxBytes?: number): ImageMetadata | null;
|
|
29
|
+
export declare function readImageMetadata(filePath: string, maxBytes?: number): Promise<ImageMetadata | null>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Multi-level path tree shared by grouped file listings (find / grep / ast tools)
|
|
3
|
+
* and compaction file-operation lists.
|
|
4
|
+
*
|
|
5
|
+
* Flat path lists used to group by the *immediate* parent directory and print the
|
|
6
|
+
* full directory path in every header. For results spread across a deep tree — or
|
|
7
|
+
* rooted outside cwd, where paths stay absolute — that repeated the shared prefix
|
|
8
|
+
* on every line. The tree below folds single-child directory chains (so the common
|
|
9
|
+
* prefix collapses into one header) and nests the rest, charging the model one
|
|
10
|
+
* token per path segment instead of one per file.
|
|
11
|
+
*/
|
|
12
|
+
/** True for `scheme://…` entries that have no meaningful directory structure. */
|
|
13
|
+
export declare function isUrlLikePath(filePath: string): boolean;
|
|
14
|
+
export interface PathTreeNode {
|
|
15
|
+
/** Direct file leaves, in first-seen order. */
|
|
16
|
+
files: Array<{
|
|
17
|
+
name: string;
|
|
18
|
+
key: string;
|
|
19
|
+
}>;
|
|
20
|
+
/** Dedup set for `files` (a glob can surface the same path twice on retry). */
|
|
21
|
+
fileNames: Set<string>;
|
|
22
|
+
/** Child directories, in first-seen order. */
|
|
23
|
+
subdirs: Array<{
|
|
24
|
+
name: string;
|
|
25
|
+
node: PathTreeNode;
|
|
26
|
+
}>;
|
|
27
|
+
/** Dedup index for `subdirs`. */
|
|
28
|
+
dirIndex: Map<string, PathTreeNode>;
|
|
29
|
+
}
|
|
30
|
+
export interface PathTreeInput {
|
|
31
|
+
/** Path string; absolute, cwd-relative, or url-like. Backslashes are normalized. */
|
|
32
|
+
path: string;
|
|
33
|
+
/** Whether the leaf itself is a directory (trailing-slash match from find). */
|
|
34
|
+
isDir: boolean;
|
|
35
|
+
/** Opaque key carried onto file events for section lookup. Defaults to `path`. */
|
|
36
|
+
key?: string;
|
|
37
|
+
}
|
|
38
|
+
/** One node emitted while walking the tree: a folded directory or a file leaf. */
|
|
39
|
+
export interface GroupedTreeEvent {
|
|
40
|
+
kind: "dir" | "file";
|
|
41
|
+
/** 0-based nesting depth (root children are depth 0). */
|
|
42
|
+
depth: number;
|
|
43
|
+
/** Folded chain for dirs (e.g. `a/b/c`, no trailing slash); basename for files. */
|
|
44
|
+
name: string;
|
|
45
|
+
/** File key for `kind === "file"`; empty string for directories. */
|
|
46
|
+
key: string;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Build a directory tree from a flat list of paths. URL-like entries are kept
|
|
50
|
+
* whole as root-level file leaves (they have no meaningful directory structure).
|
|
51
|
+
* Absolute paths carry a leading empty segment so they share a common `/` root
|
|
52
|
+
* and fold like any other prefix.
|
|
53
|
+
*/
|
|
54
|
+
export declare function buildPathTree(entries: Iterable<PathTreeInput>): PathTreeNode;
|
|
55
|
+
/**
|
|
56
|
+
* Depth-first walk yielding directory and file events. Directories collapse their
|
|
57
|
+
* single-child chains (`a` → `a/b` → `a/b/c`) so a shared prefix becomes one
|
|
58
|
+
* header. Each node's direct files are emitted before its subdirectories, keeping
|
|
59
|
+
* a file unambiguously attached to the header above it.
|
|
60
|
+
*/
|
|
61
|
+
export declare function walkPathTree(node: PathTreeNode, depth?: number): Generator<GroupedTreeEvent>;
|
|
62
|
+
/**
|
|
63
|
+
* Render a flat path list as a grouped, prefix-folded directory tree without
|
|
64
|
+
* per-file bodies (find-tool output shape, also used by compaction `<files>`
|
|
65
|
+
* lists). Single-child directory chains fold into one header (`# a/b/c/`),
|
|
66
|
+
* each level adds one `#`, and files are listed bare under the deepest
|
|
67
|
+
* directory header that owns them. Trailing-slash entries are directory
|
|
68
|
+
* leaves and keep their slash in the header.
|
|
69
|
+
*
|
|
70
|
+
* `annotate` receives each file's full original path and its return value is
|
|
71
|
+
* appended verbatim to the file line (e.g. ` (RW)`).
|
|
72
|
+
*
|
|
73
|
+
* Order follows the input: a directory appears when its first member is
|
|
74
|
+
* emitted, and a node's own files precede its subdirectories.
|
|
75
|
+
*/
|
|
76
|
+
export declare function formatGroupedPaths(paths: readonly string[], annotate?: (path: string) => string): string;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Synchronously reads up to `maxBytes` from the start of `filePath` and returns `op(header)`.
|
|
3
|
+
* If the file is shorter, `header` is only the bytes actually read.
|
|
4
|
+
*/
|
|
5
|
+
export declare function peekFileSync<T>(filePath: string, maxBytes: number, op: (header: Uint8Array) => T): T;
|
|
6
|
+
/**
|
|
7
|
+
* Like {@link peekFileSync} but uses async I/O.
|
|
8
|
+
*/
|
|
9
|
+
export declare function peekFile<T>(filePath: string, maxBytes: number, op: (header: Uint8Array) => T): Promise<T>;
|
|
10
|
+
/**
|
|
11
|
+
* Read up to the last `maxBytes` of `filePath` and pass that slice to `op`.
|
|
12
|
+
*
|
|
13
|
+
* The tail mirror of {@link peekFile}: same pooled-buffer strategy (no per-call
|
|
14
|
+
* allocation for small reads), but the read is positioned at `size - len` so the
|
|
15
|
+
* window ends at EOF. When the file is shorter than `maxBytes`, the whole file is
|
|
16
|
+
* returned. A multi-byte codepoint straddling the leading cut decodes to a
|
|
17
|
+
* replacement char — callers that parse line-oriented tails drop the partial
|
|
18
|
+
* leading line anyway.
|
|
19
|
+
*/
|
|
20
|
+
export declare function peekFileTail<T>(filePath: string, maxBytes: number, op: (tail: Uint8Array) => T): Promise<T>;
|
|
21
|
+
/**
|
|
22
|
+
* Read up to the first `prefixBytes` and last `suffixBytes` of `filePath`, then
|
|
23
|
+
* pass both slices to `op`.
|
|
24
|
+
*
|
|
25
|
+
* Uses a single open/stat sequence. When the whole file fits in the head window,
|
|
26
|
+
* the tail is sliced from the already-read head bytes instead of issuing a
|
|
27
|
+
* second read.
|
|
28
|
+
*/
|
|
29
|
+
export declare function peekFileEnds<T>(filePath: string, prefixBytes: number, suffixBytes: number, op: (head: Uint8Array, tail: Uint8Array) => T): Promise<T>;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export declare enum Reason {
|
|
2
|
+
PRE_EXIT = "pre_exit",// Pre-exit phase (not used by default)
|
|
3
|
+
EXIT = "exit",// Normal process exit
|
|
4
|
+
SIGINT = "sigint",// Ctrl-C or SIGINT
|
|
5
|
+
SIGTERM = "sigterm",// SIGTERM
|
|
6
|
+
SIGHUP = "sighup",// SIGHUP
|
|
7
|
+
UNCAUGHT_EXCEPTION = "uncaught_exception",// Fatal exception
|
|
8
|
+
UNHANDLED_REJECTION = "unhandled_rejection",// Unhandled promise rejection
|
|
9
|
+
MANUAL = "manual"
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Detect an EPIPE rejection that originated from an IPC `send()` to a worker
|
|
13
|
+
* subprocess (`syscall: "send"`), as opposed to a stdin/stdout pipe write
|
|
14
|
+
* (`syscall: "write"`). Only the IPC-send path can break an optional worker
|
|
15
|
+
* subsystem without affecting the main process, so only this shape is safe to
|
|
16
|
+
* swallow at the global `unhandledRejection` level. See issue #2997.
|
|
17
|
+
*/
|
|
18
|
+
export declare function isIpcSendEpipe(err: Error): boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Register a process cleanup callback, to be run on shutdown, signal, or fatal error.
|
|
21
|
+
*
|
|
22
|
+
* Returns a Callback instance that can be used to cancel (unregister) or manually clean up.
|
|
23
|
+
* If register is called after cleanup already began, invokes callback on a microtask.
|
|
24
|
+
*/
|
|
25
|
+
export declare function register(id: string, callback: (reason: Reason) => void | Promise<void>): () => void;
|
|
26
|
+
/**
|
|
27
|
+
* Runs all cleanup callbacks without exiting.
|
|
28
|
+
* Use this in workers or when you need to clean up but continue execution.
|
|
29
|
+
*/
|
|
30
|
+
export declare function cleanup(): Promise<void>;
|
|
31
|
+
/**
|
|
32
|
+
* Runs all cleanup callbacks and exits.
|
|
33
|
+
*
|
|
34
|
+
* In main thread: waits for stdout drain, then calls process.exit().
|
|
35
|
+
* In workers: runs cleanup only (process.exit would kill entire process).
|
|
36
|
+
*/
|
|
37
|
+
export declare function quit(code?: number): Promise<void>;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { Subprocess } from "bun";
|
|
2
|
+
export interface ShellConfig {
|
|
3
|
+
shell: string;
|
|
4
|
+
args: string[];
|
|
5
|
+
env: Record<string, string>;
|
|
6
|
+
prefix: string | undefined;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Check if a shell binary is executable.
|
|
10
|
+
*/
|
|
11
|
+
export declare function isExecutable(path: string): boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Resolve a basic shell (bash or sh) as fallback.
|
|
14
|
+
*/
|
|
15
|
+
export declare function resolveBasicShell(): string | undefined;
|
|
16
|
+
/**
|
|
17
|
+
* Get shell configuration based on platform.
|
|
18
|
+
* Resolution order:
|
|
19
|
+
* 1. User-specified shellPath in settings.json
|
|
20
|
+
* 2. On Windows: Git Bash in known locations, then bash on PATH
|
|
21
|
+
* 3. On Unix: $SHELL if bash/zsh, then fallback paths
|
|
22
|
+
* 4. Fallback: sh
|
|
23
|
+
*/
|
|
24
|
+
export declare function getShellConfig(customShellPath?: string): ShellConfig;
|
|
25
|
+
/**
|
|
26
|
+
* Check if a process is running.
|
|
27
|
+
*/
|
|
28
|
+
export declare function isPidRunning(pid: number | Subprocess): boolean;
|
|
29
|
+
export declare function onProcessExit(proc: Subprocess | number, abortSignal?: AbortSignal): Promise<boolean>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { HelperDelegate, HelperOptions, Template, TemplateDelegate } from "handlebars";
|
|
2
|
+
export type { HelperDelegate, HelperOptions, Template, TemplateDelegate };
|
|
3
|
+
export type PromptRenderPhase = "pre-render" | "post-render";
|
|
4
|
+
export interface PromptFormatOptions {
|
|
5
|
+
renderPhase?: PromptRenderPhase;
|
|
6
|
+
replaceAsciiSymbols?: boolean;
|
|
7
|
+
normalizeRfc2119?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export declare function format(content: string, options?: PromptFormatOptions): string;
|
|
10
|
+
export interface TemplateContext extends Record<string, unknown> {
|
|
11
|
+
args?: string[];
|
|
12
|
+
ARGUMENTS?: string;
|
|
13
|
+
arguments?: string;
|
|
14
|
+
}
|
|
15
|
+
export declare function registerHelper(name: string, fn: HelperDelegate): void;
|
|
16
|
+
export declare function registerPartial(name: string, fn: Template): void;
|
|
17
|
+
export declare function compile(template: string): (context: TemplateContext) => string;
|
|
18
|
+
export declare function render(template: string, context?: TemplateContext): string;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Process tree management utilities for Bun subprocesses.
|
|
3
|
+
*
|
|
4
|
+
* - Track managed child processes for cleanup on shutdown (postmortem).
|
|
5
|
+
* - Drain stdout/stderr to avoid subprocess pipe deadlocks.
|
|
6
|
+
* - Cross-platform tree kill for process groups (Windows taskkill, Unix -pid).
|
|
7
|
+
* - Convenience helpers: captureText / execText, AbortSignal, timeouts.
|
|
8
|
+
*/
|
|
9
|
+
import type { Spawn, Subprocess } from "bun";
|
|
10
|
+
type InMask = "pipe" | "ignore" | Buffer | Uint8Array | null;
|
|
11
|
+
/** A Bun subprocess with stdout/stderr always piped (stdin may vary). */
|
|
12
|
+
type PipedSubprocess<In extends InMask = InMask> = Subprocess<In, "pipe", "pipe">;
|
|
13
|
+
/**
|
|
14
|
+
* Base for all exceptions representing child process nonzero exit, killed, or
|
|
15
|
+
* cancellation.
|
|
16
|
+
*/
|
|
17
|
+
export declare abstract class Exception extends Error {
|
|
18
|
+
readonly exitCode: number;
|
|
19
|
+
readonly stderr: string;
|
|
20
|
+
constructor(message: string, exitCode: number, stderr: string);
|
|
21
|
+
abstract readonly aborted: boolean;
|
|
22
|
+
}
|
|
23
|
+
/** Exception for nonzero exit codes (not cancellation). */
|
|
24
|
+
export declare class NonZeroExitError extends Exception {
|
|
25
|
+
static readonly MAX_TRACE: number;
|
|
26
|
+
constructor(exitCode: number, stderr: string);
|
|
27
|
+
get aborted(): boolean;
|
|
28
|
+
}
|
|
29
|
+
/** Exception for explicit process abortion (via signal). */
|
|
30
|
+
export declare class AbortError extends Exception {
|
|
31
|
+
readonly reason: unknown;
|
|
32
|
+
constructor(reason: unknown, stderr: string);
|
|
33
|
+
get aborted(): boolean;
|
|
34
|
+
}
|
|
35
|
+
/** Exception for process timeout. */
|
|
36
|
+
export declare class TimeoutError extends AbortError {
|
|
37
|
+
constructor(timeout: number, stderr: string);
|
|
38
|
+
}
|
|
39
|
+
/** Options for waiting for process exit and capturing output. */
|
|
40
|
+
export interface WaitOptions {
|
|
41
|
+
allowNonZero?: boolean;
|
|
42
|
+
allowAbort?: boolean;
|
|
43
|
+
stderr?: "full" | "buffer";
|
|
44
|
+
}
|
|
45
|
+
/** Result from wait and exec. */
|
|
46
|
+
export interface ExecResult {
|
|
47
|
+
stdout: string;
|
|
48
|
+
stderr: string;
|
|
49
|
+
exitCode: number | null;
|
|
50
|
+
ok: boolean;
|
|
51
|
+
exitError?: Exception;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* ChildProcess wraps a managed subprocess, capturing stderr tail, providing
|
|
55
|
+
* cross-platform kill/detach logic plus AbortSignal integration.
|
|
56
|
+
*
|
|
57
|
+
* Stdout is exposed directly from the underlying Bun subprocess; consumers
|
|
58
|
+
* must read it (via text(), wait(), etc.) to prevent pipe deadlock.
|
|
59
|
+
* Stderr is eagerly drained into an internal buffer.
|
|
60
|
+
*/
|
|
61
|
+
export declare class ChildProcess<In extends InMask = InMask> {
|
|
62
|
+
#private;
|
|
63
|
+
readonly proc: PipedSubprocess<In>;
|
|
64
|
+
readonly exposeStderr: boolean;
|
|
65
|
+
constructor(proc: PipedSubprocess<In>, exposeStderr: boolean);
|
|
66
|
+
get pid(): number;
|
|
67
|
+
get exited(): Promise<number>;
|
|
68
|
+
get exitCode(): number | null;
|
|
69
|
+
get exitReason(): Exception | undefined;
|
|
70
|
+
get killed(): boolean;
|
|
71
|
+
get stdin(): Bun.SpawnOptions.WritableToIO<In>;
|
|
72
|
+
/** Raw stdout stream. Must be consumed to prevent pipe deadlock. */
|
|
73
|
+
get stdout(): ReadableStream<Uint8Array<ArrayBuffer>>;
|
|
74
|
+
/** Optional stderr stream (only when requested in spawn options). */
|
|
75
|
+
get stderr(): ReadableStream<Uint8Array<ArrayBufferLike>> | undefined;
|
|
76
|
+
get exitedCleanly(): Promise<number>;
|
|
77
|
+
/** Returns the truncated stderr tail (last 32KB). */
|
|
78
|
+
peekStderr(): string;
|
|
79
|
+
nothrow(): this;
|
|
80
|
+
kill(reason?: Exception): void;
|
|
81
|
+
text(): Promise<string>;
|
|
82
|
+
blob(): Promise<Blob>;
|
|
83
|
+
json(): Promise<unknown>;
|
|
84
|
+
arrayBuffer(): Promise<ArrayBuffer>;
|
|
85
|
+
bytes(): Promise<Uint8Array>;
|
|
86
|
+
wait(opts?: WaitOptions): Promise<ExecResult>;
|
|
87
|
+
attachSignal(signal: AbortSignal): void;
|
|
88
|
+
attachTimeout(ms: number): void;
|
|
89
|
+
[Symbol.dispose](): void;
|
|
90
|
+
}
|
|
91
|
+
/** Options for child spawn. Always pipes stdout/stderr. */
|
|
92
|
+
type ChildSpawnOptions<In extends InMask = InMask> = Omit<Spawn.SpawnOptions<In, "pipe", "pipe">, "stdout" | "stderr" | "detached"> & {
|
|
93
|
+
signal?: AbortSignal;
|
|
94
|
+
detached?: boolean;
|
|
95
|
+
stderr?: "full" | null;
|
|
96
|
+
};
|
|
97
|
+
/** Spawn a child process with piped stdout/stderr. */
|
|
98
|
+
export declare function spawn<In extends InMask = InMask>(cmd: string[], opts?: ChildSpawnOptions<In>): ChildProcess<In>;
|
|
99
|
+
/** Options for exec. */
|
|
100
|
+
export interface ExecOptions extends Omit<ChildSpawnOptions, "stderr" | "stdin">, WaitOptions {
|
|
101
|
+
input?: string | Buffer | Uint8Array;
|
|
102
|
+
}
|
|
103
|
+
/** Spawn, wait, and return captured output. */
|
|
104
|
+
export declare function exec(cmd: string[], opts?: ExecOptions): Promise<ExecResult>;
|
|
105
|
+
type SignalValue = AbortSignal | number | null | undefined;
|
|
106
|
+
/** Combine AbortSignals and timeout values into a single signal. */
|
|
107
|
+
export declare function combineSignals(...signals: SignalValue[]): AbortSignal | undefined;
|
|
108
|
+
export {};
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A fixed-capacity circular buffer that supports efficient push/pop/shift/unshift operations.
|
|
3
|
+
* When the buffer is full, adding new items overwrites the oldest items (FIFO behavior).
|
|
4
|
+
*
|
|
5
|
+
* @template T The type of elements stored in the buffer.
|
|
6
|
+
*/
|
|
7
|
+
export declare class RingBuffer<T> {
|
|
8
|
+
#private;
|
|
9
|
+
readonly capacity: number;
|
|
10
|
+
/**
|
|
11
|
+
* Creates a new ring buffer with the specified capacity.
|
|
12
|
+
*
|
|
13
|
+
* @param capacity - The maximum number of elements the buffer can hold. Must be positive.
|
|
14
|
+
*/
|
|
15
|
+
constructor(capacity: number);
|
|
16
|
+
/**
|
|
17
|
+
* The number of elements currently in the buffer.
|
|
18
|
+
*/
|
|
19
|
+
get length(): number;
|
|
20
|
+
/**
|
|
21
|
+
* Whether the buffer is at full capacity.
|
|
22
|
+
*/
|
|
23
|
+
get isFull(): boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Whether the buffer is empty (contains no elements).
|
|
26
|
+
*/
|
|
27
|
+
get isEmpty(): boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Adds an item to the end of the buffer.
|
|
30
|
+
* If the buffer is full, the oldest item is overwritten and returned.
|
|
31
|
+
*
|
|
32
|
+
* @param item - The item to add.
|
|
33
|
+
* @returns The overwritten item if the buffer was full, otherwise `undefined`.
|
|
34
|
+
*/
|
|
35
|
+
push(item: T): T | undefined;
|
|
36
|
+
/**
|
|
37
|
+
* Removes and returns the first (oldest) item from the buffer.
|
|
38
|
+
*
|
|
39
|
+
* @returns The removed item, or `undefined` if the buffer is empty.
|
|
40
|
+
*/
|
|
41
|
+
shift(): T | undefined;
|
|
42
|
+
/**
|
|
43
|
+
* Removes and returns the last (newest) item from the buffer.
|
|
44
|
+
*
|
|
45
|
+
* @returns The removed item, or `undefined` if the buffer is empty.
|
|
46
|
+
*/
|
|
47
|
+
pop(): T | undefined;
|
|
48
|
+
/**
|
|
49
|
+
* Adds an item to the beginning of the buffer.
|
|
50
|
+
* If the buffer is full, the newest item is overwritten and returned.
|
|
51
|
+
*
|
|
52
|
+
* @param item - The item to add.
|
|
53
|
+
* @returns The overwritten item if the buffer was full, otherwise `undefined`.
|
|
54
|
+
*/
|
|
55
|
+
unshift(item: T): T | undefined;
|
|
56
|
+
/**
|
|
57
|
+
* Returns the element at the specified index without removing it.
|
|
58
|
+
* Supports negative indices (e.g., `-1` for the last element).
|
|
59
|
+
*
|
|
60
|
+
* @param index - The zero-based index, or negative index from the end.
|
|
61
|
+
* @returns The element at the index, or `undefined` if the index is out of bounds.
|
|
62
|
+
*/
|
|
63
|
+
at(index: number): T | undefined;
|
|
64
|
+
/**
|
|
65
|
+
* Returns the first (oldest) element without removing it.
|
|
66
|
+
*
|
|
67
|
+
* @returns The first element, or `undefined` if the buffer is empty.
|
|
68
|
+
*/
|
|
69
|
+
peek(): T | undefined;
|
|
70
|
+
/**
|
|
71
|
+
* Returns the last (newest) element without removing it.
|
|
72
|
+
*
|
|
73
|
+
* @returns The last element, or `undefined` if the buffer is empty.
|
|
74
|
+
*/
|
|
75
|
+
peekBack(): T | undefined;
|
|
76
|
+
/**
|
|
77
|
+
* Removes all elements from the buffer, resetting it to an empty state.
|
|
78
|
+
*/
|
|
79
|
+
clear(): void;
|
|
80
|
+
/**
|
|
81
|
+
* Returns an iterator that yields elements in logical order (oldest to newest).
|
|
82
|
+
* Allows the buffer to be used with `for...of` loops and spread syntax.
|
|
83
|
+
*
|
|
84
|
+
* @yields Elements in FIFO order.
|
|
85
|
+
*/
|
|
86
|
+
[Symbol.iterator](): Iterator<T>;
|
|
87
|
+
/**
|
|
88
|
+
* Creates a new array containing all elements in logical order (oldest to newest).
|
|
89
|
+
*
|
|
90
|
+
* @returns A new array with all buffer elements.
|
|
91
|
+
*/
|
|
92
|
+
toArray(): T[];
|
|
93
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Walk a conditional `exports` target (string, array of fallbacks, or a
|
|
3
|
+
* condition object) and return the first relative path that matches a runtime
|
|
4
|
+
* condition in declaration order. Returns `null` when nothing applies (e.g.
|
|
5
|
+
* an `import`-only entry).
|
|
6
|
+
*/
|
|
7
|
+
export declare function selectConditionalTarget(target: unknown): string | null;
|
|
8
|
+
/**
|
|
9
|
+
* Split a bare specifier into its package name and optional subpath, handling
|
|
10
|
+
* scoped packages (`@scope/name/sub` → `@scope/name` + `sub`).
|
|
11
|
+
*/
|
|
12
|
+
export declare function splitBareSpecifier(specifier: string): {
|
|
13
|
+
packageName: string;
|
|
14
|
+
subpath: string | undefined;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Resolve a bare specifier against an installed `node_modules` directory,
|
|
18
|
+
* honoring `exports` (CommonJS conditions), then `main`, then `index.js`.
|
|
19
|
+
* Returns an absolute file path, or `null` when the package/entry is absent.
|
|
20
|
+
*/
|
|
21
|
+
export declare function resolveRuntimeModule(runtimeNodeModules: string, specifier: string): string | null;
|
|
22
|
+
export interface RuntimeResolverOptions {
|
|
23
|
+
/** Absolute path to the runtime cache's `node_modules`. */
|
|
24
|
+
runtimeNodeModules: string;
|
|
25
|
+
/** Bare specifier → absolute file path overrides (e.g. `sharp` → no-op stub). */
|
|
26
|
+
stubs?: Record<string, string>;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Patch `node:module`'s resolver (idempotently) so bare specifiers that the
|
|
30
|
+
* stock compiled-binary resolver cannot find fall back to the registered
|
|
31
|
+
* runtime caches. Stock resolution is tried first and kept for anything
|
|
32
|
+
* outside the registered roots (bundled imports, node builtins, host or
|
|
33
|
+
* extension trees). Multiple runtime roots may register; they are consulted
|
|
34
|
+
* in registration order.
|
|
35
|
+
*
|
|
36
|
+
* One stock "success" is distrusted: the compiled-binary resolver ignores
|
|
37
|
+
* `main`/`exports` for real-FS packages (Bun #1763), so a package shipping
|
|
38
|
+
* its TS source next to `dist/` (e.g. `@huggingface/hub`'s root `index.ts`)
|
|
39
|
+
* resolves to the wrong file. When the stock hit lands inside a registered
|
|
40
|
+
* runtime root, the manifest-aware resolution wins.
|
|
41
|
+
*/
|
|
42
|
+
export declare function installRuntimeModuleResolver({ runtimeNodeModules, stubs }: RuntimeResolverOptions): void;
|
|
43
|
+
/** Pinned dependency set materialized into a runtime cache directory. */
|
|
44
|
+
export interface RuntimeInstallSpec {
|
|
45
|
+
dependencies: Record<string, string>;
|
|
46
|
+
/** Version pins forced across the whole runtime tree (bun `overrides`), e.g. dislodging a transitive dep. */
|
|
47
|
+
overrides?: Record<string, string>;
|
|
48
|
+
/** Packages whose lifecycle scripts bun may run during the install. */
|
|
49
|
+
trustedDependencies?: string[];
|
|
50
|
+
}
|
|
51
|
+
export type RuntimeInstallPhase = "initiate" | "download" | "done";
|
|
52
|
+
export interface EnsureRuntimeInstalledOptions {
|
|
53
|
+
/** Directory owning the runtime `package.json` + `node_modules`. */
|
|
54
|
+
runtimeDir: string;
|
|
55
|
+
install: RuntimeInstallSpec;
|
|
56
|
+
/** Package whose installed manifest marks the runtime complete; defaults to the first dependency. */
|
|
57
|
+
probePackage?: string;
|
|
58
|
+
/** Phase notifications (progress UI); not emitted when already installed. */
|
|
59
|
+
onPhase?: (phase: RuntimeInstallPhase) => void;
|
|
60
|
+
lockAttempts?: number;
|
|
61
|
+
lockSleepMs?: number;
|
|
62
|
+
}
|
|
63
|
+
export declare function writeRuntimeManifest(runtimeDir: string, install: RuntimeInstallSpec): Promise<void>;
|
|
64
|
+
/**
|
|
65
|
+
* Materialize a pinned dependency set into `runtimeDir` (idempotent,
|
|
66
|
+
* cross-process safe via a lock directory). Returns `runtimeDir`.
|
|
67
|
+
*/
|
|
68
|
+
export declare function ensureRuntimeInstalled(options: EnsureRuntimeInstalledOptions): Promise<string>;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Strip ANSI escape sequences, remove control characters / lone surrogates,
|
|
3
|
+
* and normalize line endings.
|
|
4
|
+
*
|
|
5
|
+
* Bun-native implementation of the former native `sanitizeText` (see
|
|
6
|
+
* `crates/pi-natives/src/text.rs::sanitize_text`). JavaScript strings are
|
|
7
|
+
* already UTF-16 code-unit arrays. `toWellFormed()` handles the uncommon
|
|
8
|
+
* malformed path; when it changes the input, replacement characters are
|
|
9
|
+
* dropped and the normalized result goes through the well-formed sanitizer.
|
|
10
|
+
*
|
|
11
|
+
* Fast path: well-formed input with no controls or ANSI returns the original
|
|
12
|
+
* string after the control probe.
|
|
13
|
+
*/
|
|
14
|
+
export declare function sanitizeText(text: string): string;
|
|
15
|
+
/**
|
|
16
|
+
* Escape the three XML-significant characters (`&`, `<`, `>`) in text destined
|
|
17
|
+
* for an XML/markup element body. Allocation-conscious: returns the input
|
|
18
|
+
* unchanged (same reference) when nothing needs escaping. Quotes are left as-is
|
|
19
|
+
* — use it for element text, not attribute values.
|
|
20
|
+
*/
|
|
21
|
+
export declare function escapeXmlText(input: string): string;
|
|
22
|
+
/**
|
|
23
|
+
* Escape XML-significant characters for an attribute VALUE: the three body
|
|
24
|
+
* characters (`&`, `<`, `>`) plus the double quote (`"` → `"`) that would
|
|
25
|
+
* otherwise close the attribute. Allocation-conscious: returns the input
|
|
26
|
+
* unchanged (same reference) when nothing needs escaping. Use it for attribute
|
|
27
|
+
* values; {@link escapeXmlText} is for element bodies and leaves `"` intact.
|
|
28
|
+
*/
|
|
29
|
+
export declare function escapeXmlAttribute(input: string): string;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
type Snowflake = string & {
|
|
2
|
+
readonly __brand: unique symbol;
|
|
3
|
+
};
|
|
4
|
+
declare namespace Snowflake {
|
|
5
|
+
const PATTERN: RegExp;
|
|
6
|
+
const EPOCH_TIMESTAMP = 1420070400000;
|
|
7
|
+
const MAX_SEQUENCE = 4194303;
|
|
8
|
+
function formatParts(dt: number, seq: number): Snowflake;
|
|
9
|
+
class Source {
|
|
10
|
+
#private;
|
|
11
|
+
constructor(sequence?: number);
|
|
12
|
+
get sequence(): number;
|
|
13
|
+
set sequence(v: number);
|
|
14
|
+
reset(): void;
|
|
15
|
+
generate(timestamp: number): Snowflake;
|
|
16
|
+
}
|
|
17
|
+
function next(timestamp?: number): Snowflake;
|
|
18
|
+
function valid(value: string): value is Snowflake;
|
|
19
|
+
function lowerbound(timelike: Date | number | Snowflake): Snowflake;
|
|
20
|
+
function upperbound(timelike: Date | number | Snowflake): Snowflake;
|
|
21
|
+
function getSequence(value: Snowflake): number;
|
|
22
|
+
function getTimestamp(value: Snowflake): number;
|
|
23
|
+
function getDate(value: Snowflake): Date;
|
|
24
|
+
}
|
|
25
|
+
export { Snowflake };
|